|
|
@@ -8,6 +8,7 @@ use App\ApiResources\Dolibarr\DolibarrAccount;
|
|
|
use App\ApiResources\Dolibarr\DolibarrBill;
|
|
|
use App\ApiResources\Dolibarr\DolibarrContract;
|
|
|
use App\ApiResources\Dolibarr\DolibarrContractLine;
|
|
|
+use App\ApiResources\Dolibarr\DolibarrOrder;
|
|
|
use App\Service\Dolibarr\DolibarrApiService;
|
|
|
|
|
|
class DolibarrAccountBuilder
|
|
|
@@ -44,6 +45,13 @@ class DolibarrAccountBuilder
|
|
|
$dolibarrAccount->setContract($contract);
|
|
|
}
|
|
|
|
|
|
+ // get last order (if any)
|
|
|
+ $lastOrderData = $this->dolibarrApiService->getLastOrder($dolibarrAccount->getSocId());
|
|
|
+ if ($lastOrderData !== null) {
|
|
|
+ $order = $this->createDolibarrOrder($lastOrderData);
|
|
|
+ $dolibarrAccount->setOrder($order);
|
|
|
+ }
|
|
|
+
|
|
|
// get bills
|
|
|
$billsData = $this->dolibarrApiService->getBills($dolibarrAccount->getSocId());
|
|
|
foreach ($billsData as $billData) {
|
|
|
@@ -113,6 +121,20 @@ class DolibarrAccountBuilder
|
|
|
->setDateEnd(new \DateTime(date('c', (int) $lineData['date_end'])));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param array<mixed> $orderData
|
|
|
+ *
|
|
|
+ * @throws \Exception
|
|
|
+ */
|
|
|
+ public function createDolibarrOrder(array $orderData): DolibarrOrder
|
|
|
+ {
|
|
|
+ $order = new DolibarrOrder();
|
|
|
+
|
|
|
+ return $order->setId((int) $orderData['id'])
|
|
|
+ ->setRef($orderData['ref'])
|
|
|
+ ->setDate(new \DateTime(date('c', (int) $orderData['date_validation'])));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param array<mixed> $billData
|
|
|
*
|