diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml
index 91741f4..c5371da 100644
--- a/.idea/dataSources.xml
+++ b/.idea/dataSources.xml
@@ -14,7 +14,7 @@
true
DDEV generated data source
org.mariadb.jdbc.Driver
- jdbc:mariadb://127.0.0.1:32768/db?user=db&password=db
+ jdbc:mariadb://127.0.0.1:32770/db?user=db&password=db
$ProjectFileDir$
diff --git a/src/Entity/Order.php b/src/Entity/Order.php
index 2fa55f9..d80a0cd 100644
--- a/src/Entity/Order.php
+++ b/src/Entity/Order.php
@@ -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;
+ }
}
\ No newline at end of file
diff --git a/src/Helper/Hiltes.php b/src/Helper/Hiltes.php
index 87958d6..8203d2b 100644
--- a/src/Helper/Hiltes.php
+++ b/src/Helper/Hiltes.php
@@ -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'],
- "BranchNumber" => 8, #Die Filialnummer
- "ShopNumber" => 1, #Die Shopnummer
- "DistributionChannel" => 5, #Der Vertriebskanal
+ '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;
}
}
diff --git a/src/Repository/OrderRepository.php b/src/Repository/OrderRepository.php
index 573a241..4090f99 100644
--- a/src/Repository/OrderRepository.php
+++ b/src/Repository/OrderRepository.php
@@ -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());