|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function synchronizeDistribution(string $date): array |
|
|
public function synchronizeDistribution(string $date): array |
|
|
{ |
|
|
{ |
|
|
$apiVersion = $this->producerSolver->getConfig('tiller_api_version'); |
|
|
|
|
|
$return = []; |
|
|
$return = []; |
|
|
|
|
|
|
|
|
if($this->tillerActivated) { |
|
|
if($this->tillerActivated) { |
|
|
|
|
|
|
|
|
'conditions' => OrderRepositoryQuery::getSqlFilterIsValid() |
|
|
'conditions' => OrderRepositoryQuery::getSqlFilterIsValid() |
|
|
]); |
|
|
]); |
|
|
|
|
|
|
|
|
$strDate = date('Y-m-d\T12:i:s+0000', strtotime($date) + 1); |
|
|
|
|
|
$datetime = new \DateTime(date('Y-m-d 12:i:s', strtotime($date))); |
|
|
|
|
|
|
|
|
|
|
|
if ($orders && count($orders)) { |
|
|
if ($orders && count($orders)) { |
|
|
foreach ($orders as $order) { |
|
|
foreach ($orders as $order) { |
|
|
$this->orderBuilder->initOrder($order); |
|
|
|
|
|
$lines = []; |
|
|
|
|
|
foreach ($order->productOrder as $productOrder) { |
|
|
|
|
|
// v3 |
|
|
|
|
|
if($apiVersion == 'v3') { |
|
|
|
|
|
$amount = round($this->productOrderSolver->getPriceWithTax($productOrder) * 100); |
|
|
|
|
|
|
|
|
|
|
|
// classique |
|
|
|
|
|
if(is_int($productOrder->quantity)) { |
|
|
|
|
|
$quantity = $productOrder->quantity; |
|
|
|
|
|
} |
|
|
|
|
|
// vrac |
|
|
|
|
|
else { |
|
|
|
|
|
$amount = $amount * $productOrder->quantity; |
|
|
|
|
|
$quantity = 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$lines[] = [ |
|
|
|
|
|
'name' => $productOrder->product->name, |
|
|
|
|
|
'unitPrice' => [ |
|
|
|
|
|
'amount' => $amount, |
|
|
|
|
|
], |
|
|
|
|
|
'taxRate' => $productOrder->taxRate->value * 100, |
|
|
|
|
|
'quantity' => $quantity |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
// v2 |
|
|
|
|
|
else { |
|
|
|
|
|
$lines[] = [ |
|
|
|
|
|
'name' => $productOrder->product->name, |
|
|
|
|
|
'price' => $this->productOrderSolver->getPriceWithTax($productOrder) * 100 * $productOrder->quantity, |
|
|
|
|
|
'tax' => $productOrder->taxRate->value * 100, |
|
|
|
|
|
'date' => $strDate, |
|
|
|
|
|
'quantity' => $productOrder->quantity |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$res = $this->synchronizeOrder($order); |
|
|
|
|
|
if($res) { |
|
|
|
|
|
$return[] = $res; |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$typePaymentTiller = ''; |
|
|
|
|
|
if ($order->mean_payment == MeanPayment::MONEY) { |
|
|
|
|
|
$typePaymentTiller = 'CASH'; |
|
|
|
|
|
} |
|
|
|
|
|
if ($order->mean_payment == MeanPayment::CREDIT_CARD |
|
|
|
|
|
|| $order->mean_payment == MeanPayment::CREDIT |
|
|
|
|
|
|| $order->mean_payment == MeanPayment::TRANSFER |
|
|
|
|
|
|| $order->mean_payment == MeanPayment::OTHER) { |
|
|
|
|
|
$typePaymentTiller = 'CARD'; |
|
|
|
|
|
} |
|
|
|
|
|
if ($order->mean_payment == MeanPayment::CHEQUE) { |
|
|
|
|
|
$typePaymentTiller = 'BANK_CHECK'; |
|
|
|
|
|
} |
|
|
|
|
|
if (!strlen($typePaymentTiller) || !$order->mean_payment) { |
|
|
|
|
|
$typePaymentTiller = 'CASH'; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return $return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (!$this->isSynchronized($date, $order->id)) { |
|
|
|
|
|
// v3 |
|
|
|
|
|
if($apiVersion == 'v3') { |
|
|
|
|
|
|
|
|
|
|
|
$payments = []; |
|
|
|
|
|
$amountPayment = round($this->orderSolver->getOrderAmountWithTax($order, Order::AMOUNT_PAID) * 100); |
|
|
|
|
|
if($amountPayment) { |
|
|
|
|
|
$payments[] = [ |
|
|
|
|
|
'externalId' => ''.$order->id, |
|
|
|
|
|
'amount' => $amountPayment |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public function synchronizeOrder(Order $order, bool $force = false) |
|
|
|
|
|
{ |
|
|
|
|
|
$apiVersion = $this->producerSolver->getConfig('tiller_api_version'); |
|
|
|
|
|
$date = $order->distribution->date; |
|
|
|
|
|
$strDate = date('Y-m-d\T12:i:s+0000', strtotime($date) + 1); |
|
|
|
|
|
$datetime = new \DateTime(date('Y-m-d 12:i:s', strtotime($date))); |
|
|
|
|
|
$this->orderBuilder->initOrder($order); |
|
|
|
|
|
$lines = []; |
|
|
|
|
|
|
|
|
$returnTiller = $this->tillerClient->postOrder([ |
|
|
|
|
|
'externalId' => ''.$order->id, |
|
|
|
|
|
'purchaseRequestType' => 'clickAndCollect', |
|
|
|
|
|
'date' => $datetime->format(\DateTime::ATOM), |
|
|
|
|
|
'order' => [ |
|
|
|
|
|
'currencyCode' => 'EUR', |
|
|
|
|
|
'itemLines' => $lines, |
|
|
|
|
|
'payments' => $payments |
|
|
|
|
|
] |
|
|
|
|
|
]); |
|
|
|
|
|
} |
|
|
|
|
|
// v2 |
|
|
|
|
|
else { |
|
|
|
|
|
$returnTiller = $this->tillerClient->postOrder([ |
|
|
|
|
|
'externalId' => $order->id, |
|
|
|
|
|
'type' => 1, |
|
|
|
|
|
'status' => 'IN_PROGRESS', |
|
|
|
|
|
'openDate' => $strDate, |
|
|
|
|
|
'closeDate' => $strDate, |
|
|
|
|
|
'lines' => $lines, |
|
|
|
|
|
'payments' => [ |
|
|
|
|
|
[ |
|
|
|
|
|
'type' => $typePaymentTiller, |
|
|
|
|
|
'amount' => $this->orderSolver->getOrderAmountWithTax( |
|
|
|
|
|
$order, |
|
|
|
|
|
Order::AMOUNT_PAID |
|
|
|
|
|
) * 100, |
|
|
|
|
|
'status' => 'ACCEPTED', |
|
|
|
|
|
'date' => $strDate |
|
|
|
|
|
] |
|
|
|
|
|
] |
|
|
|
|
|
]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
foreach ($order->productOrder as $productOrder) { |
|
|
|
|
|
// v3 |
|
|
|
|
|
if($apiVersion == 'v3') { |
|
|
|
|
|
$amount = round($this->productOrderSolver->getPriceWithTax($productOrder) * 100); |
|
|
|
|
|
|
|
|
$returnTillerObject = json_decode($returnTiller); |
|
|
|
|
|
if($apiVersion == 'v3') { |
|
|
|
|
|
$order->tiller_external_id = '' . $returnTillerObject->referenceId; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
$order->tiller_external_id = '' . $returnTillerObject->id; |
|
|
|
|
|
} |
|
|
|
|
|
$order->save(); |
|
|
|
|
|
|
|
|
// classique |
|
|
|
|
|
if(is_int($productOrder->quantity)) { |
|
|
|
|
|
$quantity = $productOrder->quantity; |
|
|
|
|
|
} |
|
|
|
|
|
// vrac |
|
|
|
|
|
else { |
|
|
|
|
|
$amount = $amount * $productOrder->quantity; |
|
|
|
|
|
$quantity = 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$return[] = $returnTiller; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$lines[] = [ |
|
|
|
|
|
'name' => $productOrder->product->name, |
|
|
|
|
|
'unitPrice' => [ |
|
|
|
|
|
'amount' => $amount, |
|
|
|
|
|
], |
|
|
|
|
|
'taxRate' => $productOrder->taxRate->value * 100, |
|
|
|
|
|
'quantity' => $quantity |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
// v2 |
|
|
|
|
|
else { |
|
|
|
|
|
$lines[] = [ |
|
|
|
|
|
'name' => $productOrder->product->name, |
|
|
|
|
|
'price' => $this->productOrderSolver->getPriceWithTax($productOrder) * 100 * $productOrder->quantity, |
|
|
|
|
|
'tax' => $productOrder->taxRate->value * 100, |
|
|
|
|
|
'date' => $strDate, |
|
|
|
|
|
'quantity' => $productOrder->quantity |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$typePaymentTiller = ''; |
|
|
|
|
|
if ($order->mean_payment == MeanPayment::MONEY) { |
|
|
|
|
|
$typePaymentTiller = 'CASH'; |
|
|
|
|
|
} |
|
|
|
|
|
if ($order->mean_payment == MeanPayment::CREDIT_CARD |
|
|
|
|
|
|| $order->mean_payment == MeanPayment::CREDIT |
|
|
|
|
|
|| $order->mean_payment == MeanPayment::TRANSFER |
|
|
|
|
|
|| $order->mean_payment == MeanPayment::OTHER) { |
|
|
|
|
|
$typePaymentTiller = 'CARD'; |
|
|
|
|
|
} |
|
|
|
|
|
if ($order->mean_payment == MeanPayment::CHEQUE) { |
|
|
|
|
|
$typePaymentTiller = 'BANK_CHECK'; |
|
|
|
|
|
} |
|
|
|
|
|
if (!strlen($typePaymentTiller) || !$order->mean_payment) { |
|
|
|
|
|
$typePaymentTiller = 'CASH'; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!$this->isSynchronized($date, $order->id) || $force) { |
|
|
|
|
|
// v3 |
|
|
|
|
|
if($apiVersion == 'v3') { |
|
|
|
|
|
$payments = []; |
|
|
|
|
|
$amountPayment = round($this->orderSolver->getOrderAmountWithTax($order, Order::AMOUNT_PAID) * 100); |
|
|
|
|
|
if($amountPayment) { |
|
|
|
|
|
$payments[] = [ |
|
|
|
|
|
'externalId' => ''.$order->id, |
|
|
|
|
|
'amount' => $amountPayment |
|
|
|
|
|
]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$returnTiller = $this->tillerClient->postOrder([ |
|
|
|
|
|
'externalId' => ''.$order->id, |
|
|
|
|
|
'purchaseRequestType' => 'clickAndCollect', |
|
|
|
|
|
'date' => $datetime->format(\DateTime::ATOM), |
|
|
|
|
|
'order' => [ |
|
|
|
|
|
'currencyCode' => 'EUR', |
|
|
|
|
|
'itemLines' => $lines, |
|
|
|
|
|
'payments' => $payments |
|
|
|
|
|
] |
|
|
|
|
|
]); |
|
|
|
|
|
} |
|
|
|
|
|
// v2 |
|
|
|
|
|
else { |
|
|
|
|
|
$returnTiller = $this->tillerClient->postOrder([ |
|
|
|
|
|
'externalId' => $order->id, |
|
|
|
|
|
'type' => 1, |
|
|
|
|
|
'status' => 'IN_PROGRESS', |
|
|
|
|
|
'openDate' => $strDate, |
|
|
|
|
|
'closeDate' => $strDate, |
|
|
|
|
|
'lines' => $lines, |
|
|
|
|
|
'payments' => [ |
|
|
|
|
|
[ |
|
|
|
|
|
'type' => $typePaymentTiller, |
|
|
|
|
|
'amount' => $this->orderSolver->getOrderAmountWithTax( |
|
|
|
|
|
$order, |
|
|
|
|
|
Order::AMOUNT_PAID |
|
|
|
|
|
) * 100, |
|
|
|
|
|
'status' => 'ACCEPTED', |
|
|
|
|
|
'date' => $strDate |
|
|
|
|
|
] |
|
|
|
|
|
] |
|
|
|
|
|
]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$returnTillerObject = json_decode($returnTiller); |
|
|
|
|
|
if($apiVersion == 'v3') { |
|
|
|
|
|
$order->tiller_external_id = '' . $returnTillerObject->referenceId; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
$order->tiller_external_id = '' . $returnTillerObject->id; |
|
|
} |
|
|
} |
|
|
|
|
|
$order->save(); |
|
|
|
|
|
|
|
|
|
|
|
return $returnTiller; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $return; |
|
|
|
|
|
|
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function isSynchronized($date, $idOrder = null): bool |
|
|
public function isSynchronized($date, $idOrder = null): bool |