add hiltes log on Order

This commit is contained in:
Marko 2024-03-25 17:37:11 +01:00
parent 13d199768e
commit 9dbe5e5de7
No known key found for this signature in database
4 changed files with 64 additions and 52 deletions

View File

@ -14,7 +14,7 @@
<configured-by-url>true</configured-by-url>
<remarks>DDEV generated data source</remarks>
<jdbc-driver>org.mariadb.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mariadb://127.0.0.1:32768/db?user=db&amp;password=db</jdbc-url>
<jdbc-url>jdbc:mariadb://127.0.0.1:32770/db?user=db&amp;password=db</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>

View File

@ -41,6 +41,9 @@ class Order
#[ORM\Column(name: 'change_date', type: Types::DATETIME_MUTABLE, nullable: true, options: ['default' => 'CURRENT_TIMESTAMP'])]
private ?DateTimeInterface $changeDate = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $hiltes = null;
public function getId(): ?int
{
return $this->id;
@ -93,4 +96,16 @@ class Order
return $this;
}
public function getHiltes(): ?string
{
return $this->hiltes;
}
public function setHiltes(?string $hiltes): static
{
$this->hiltes = $hiltes;
return $this;
}
}

View File

@ -82,7 +82,11 @@ class Hiltes
if ($order) {
//foreach ($orders as $order) {
if ($order->getStatus() != 2) return false;
if ($order->getStatus() != 2) {
$this->logger->error('Order not ready for export ' . $order->getOrderId());
return false;
}
$tA = $order->getData()[0];#json_decode($order->getData());
#dump($tA);
@ -94,12 +98,14 @@ class Hiltes
$tA['orderdate'] = gmdate('Y-m-d\TH:i:s.v\Z', time());
}
#****
#*** Aufbau des Arrays ******************************
$arr = array(
'SalesDate' => $tA['orderdate'],
'File' => array(
"BranchNumber" => 8, #Die Filialnummer
"ShopNumber" => 1, #Die Shopnummer
"SalesDate" => $tA['orderdate'], #Das Umsatzdatu
"DistributionChannel" => 5, #Der Vertriebskanal
),
'SaleList' => array(),
'CustomerList' => array(),
);
@ -133,17 +139,18 @@ class Hiltes
$v['AchievedSalesPrice'] = round(str_replace(',', '.', $v['CalculatedSellingPrice']), 2);
$arr['SaleList'][] = array(
"OrderNumber" => $tA['externOrderId'], #X
"SalesLabel" => 'Ean',#$v['sku'],#X
"SalesLabelNumber" => $SalesNumber,#X
"SalesGoodsGroupNumber" => $SalesGoodsGroupNumber,
"SizeDescription" => '',#"string",
#"SizeDescription" => '',#"string",
"CustomerNumber" => $tA['kundenummer'],
"TypeOfEstate" => 0,
#"TypeOfEstate" => 0,
"Amount" => $v['menge'],#X
"CalculatedSellingPrice" => $v['CalculatedSellingPrice'], #X Kalkulierter Verkaufspreis
"AchievedSalesPrice" => $v['AchievedSalesPrice'], #X Erzielter Verkaufspreis
"TransactionType" => "Sale", #X Die Vorgangsart Sale=Verkauf Exchange=Umtausch / Storno
"ReceiptNumber" => $tA['externOrderId'], #Die Belegnummer
"ReceiptNumber" => substr($order->getOrderId(), 3), #Die Belegnummer
"DateOfSale" => $tA['orderdate'],#X das Verkaufsdatum mit Verkaufszeit
"PaymentMethod" => 'Invoice',#X "CreditCard",
"Currency" => 'EUR',#X "string",
@ -162,45 +169,18 @@ class Hiltes
"AddressZipCode" => $tA['plz'], "string",
"AddressStreet" => $tA['strasse'],#"string",
"AddressCountry" => substr($tA['land'], 0, 3),#"string",
#*** Nicht nötig
#"CardNumber" => 0,
#"SalutionNumber" => 0,
#"PostOfficeBox" => '',#"string",
#"PostOfficeBoxZipCode" => '',#"string",
#"Title" => '',#"string",
#"PhoneNumber1" => '',#"string",
#"PhoneNumber2" => '',#"string",
#"FaxNumber" => '',#"string",
#"BirthDay" => '',#"2023-09-14T11:54:26.708Z",
#"Gender" => 'Male',
#"EmailAddress" => '',#"string",
#"Discount" => 0,
#"Limit" => 0,
#"LockMark" => 'Unblocked',
#"DubiousMark" => 'Undubious',
#"DubiousText" => '',#"string",
#"DirectDebit" => '',#true,
#"BankName1" => '',#"string",
#"BankAccountNumber1" => '',#"string",
#"BankCodeNumber1" => '',#"string",
#"BankName2" => '',#"string",
#"BankAccountNumber2" => '',#"string",
#"BankCodeNumber2" => '',#"string",
#"BankName3" => '',#"string",
#"BankAccountNumber3" => '',#"string",
#"BankCodeNumber3" => '',#"string",
#"CreditcardNumber1" => '',#"string",
#"CreditcardNumber2" => '',#"string",
#"CreditcardNumber3" => '',#"string",
#"CreditcardNumber4" => '',#"string",
#"ChangeIndicator" => '',#true,
#"Newsletter" => '',#true,
#"Password" => '',#"string",
#"AdBan" => '',#true
);
$data = $this->createJson($arr);
return $this->sendOrderToHiltes($data);
//$data = $this->createJson($arr);
$this->logger->info(var_export($arr, 1));
try {
return $this->sendOrderToHiltes($arr);
} catch (\Exception $e) {
$this->logger->error('Send Order Error ' . $e->getMessage() . __LINE__);
return false;
}
}
}
@ -290,18 +270,19 @@ class Hiltes
if (!empty($data['SaleList'])) {
foreach ($data['SaleList'] as $v) {
$arr['SaleList'][] = array(
"OrderNumber" => $v['OrderNumber'],
"SalesLabel" => $v['SalesLabel'], #Das Etikettkennzeichen
"SalesLabelNumber" => $v['SalesLabelNumber'], #Etikettennummer
"SalesGoodsGroupNumber" => $v['SalesGoodsGroupNumber'],
#"SizeDescription" => $v['SizeDescription'],
#"CustomerNumber" => $v['CustomerNumber'],
#"TypeOfEstate" => $v['TypeOfEstate'],
"Amount" => $v['Amount'],
"CalculatedSellingPrice" => $v['CalculatedSellingPrice'],
"AchievedSalesPrice" => $v['AchievedSalesPrice'],
"TransactionType" => $v['TransactionType'],
#"ReceiptNumber" => $v['ReceiptNumber'],
"DateOfSale" => $data['SalesDate'],#"2023-09-14T11:54:26.708Z",
"ReceiptNumber" => $v['ReceiptNumber'],
"DateOfSale" => $v['SalesDate'],#"2023-09-14T11:54:26.708Z",
"PaymentMethod" => $v['PaymentMethod'],
"Currency" => $v['Currency'],
"Unit" => $v['Unit'],
@ -364,6 +345,7 @@ class Hiltes
/**
* @param $data
* @return bool
* @throws \Exception
*/
public function sendOrderToHiltes($data): bool
{
@ -372,18 +354,30 @@ class Hiltes
$param = $data;
//dump($param);
$r = $this->sendToHiltes($url, $param, true);
//$r = true;
if ($r === false) {
$this->logger->error('Send Order Error ' . $r . __LINE__);
$this->logger->error('Send Order Error ' . __LINE__);
return false;
}
$t = json_decode($r, true);
try {
$order = $this->orderRepository->findOneBy(array('orderId' => $data['SaleList'][0]['OrderNumber']));
$order->setStatus(3);
$order->setHiltes(var_export($r, 1));
$this->orderRepository->update($order, true);
} catch (\Exception $exception) {
$this->logger->error('Send Order Error ' . $exception->getMessage() . __LINE__);
return false;
}
if ($t['Success']) {
return true;
} else {
$this->logger->error('Send Order Error ' . var_dump($t['Message']) . __LINE__);
$this->logger->error('Send Order Error ' . var_export($t['errors'], 1) . __LINE__);
return false;
}
}

View File

@ -3,6 +3,7 @@
namespace App\Repository;
use App\Entity\Order;
use DateTime;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Exception;
@ -24,6 +25,7 @@ class OrderRepository extends ServiceEntityRepository
public function save(Order $entity, bool $flush = false): void
{
$entity->setChangeDate(new DateTime());
$this->getEntityManager()->persist($entity);
if ($flush) {
@ -46,6 +48,7 @@ class OrderRepository extends ServiceEntityRepository
public function update(Order $entity, bool $flush = false): void
{
$order = $this->getEntityManager()->find(Order::class, $entity->getId());
$order->setChangeDate(new DateTime());
if (!$order) {
throw $this->createNotFoundException('Order not found: ' . $entity->getId());