|
@@ -7,6 +7,8 @@ use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
|
|
|
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
|
|
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
|
|
|
use App\ApiResources\Dolibarr\DolibarrAccount;
|
|
use App\ApiResources\Dolibarr\DolibarrAccount;
|
|
|
use App\ApiResources\Dolibarr\DolibarrBill;
|
|
use App\ApiResources\Dolibarr\DolibarrBill;
|
|
|
|
|
+use App\ApiResources\Dolibarr\DolibarrContract;
|
|
|
|
|
+use App\ApiResources\Dolibarr\DolibarrContractLine;
|
|
|
use App\Service\Dolibarr\DolibarrService;
|
|
use App\Service\Dolibarr\DolibarrService;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -15,6 +17,13 @@ use App\Service\Dolibarr\DolibarrService;
|
|
|
*/
|
|
*/
|
|
|
final class DolibarrAccountDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface
|
|
final class DolibarrAccountDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface
|
|
|
{
|
|
{
|
|
|
|
|
+ const PRODUCT_MAPPING = [
|
|
|
|
|
+ 1 => 'PRODUCT_ARTIST', # OT Artist
|
|
|
|
|
+ 2 => 'PRODUCT_ARTIST_PREMIUM', # OT Artist Premium
|
|
|
|
|
+ 3 => 'PRODUCT_SCHOOL', # OT School Standard
|
|
|
|
|
+ 4 => 'PRODUCT_SCHOOL_PREMIUM', # OT School Premium
|
|
|
|
|
+ 5 => 'PRODUCT_MANAGER', # OT Manager
|
|
|
|
|
+ ];
|
|
|
private DolibarrService $dolibarrService;
|
|
private DolibarrService $dolibarrService;
|
|
|
|
|
|
|
|
public function __construct(
|
|
public function __construct(
|
|
@@ -38,20 +47,48 @@ final class DolibarrAccountDataProvider implements ItemDataProviderInterface, Re
|
|
|
$dolibarrAccount->setOrganizationId($id);
|
|
$dolibarrAccount->setOrganizationId($id);
|
|
|
$dolibarrAccount->setSocId((int)$accountData['id']);
|
|
$dolibarrAccount->setSocId((int)$accountData['id']);
|
|
|
$dolibarrAccount->setClientNumber($accountData['code_client']);
|
|
$dolibarrAccount->setClientNumber($accountData['code_client']);
|
|
|
- $dolibarrAccount->setProduct($accountData['array_options']['options_2iopen_software_used']);
|
|
|
|
|
- // $dolibarrAccount->setSmsCredit();
|
|
|
|
|
- // $dolibarrAccount->setServices($accountData['code_client']);
|
|
|
|
|
|
|
+ if ($accountData['array_options']['options_2iopen_software_used']) {
|
|
|
|
|
+ $dolibarrAccount->setProduct(
|
|
|
|
|
+ self::PRODUCT_MAPPING[(int)$accountData['array_options']['options_2iopen_software_used']]
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Get active contract and services
|
|
|
|
|
+ $contractData = $this->dolibarrService->getActiveContract($dolibarrAccount->getSocId());
|
|
|
|
|
+ if ($contractData !== null) {
|
|
|
|
|
+ $contract = new DolibarrContract();
|
|
|
|
|
+ $contract->setRef($contractData['ref']);
|
|
|
|
|
+ $contract->setSocId((int)$contractData['socid']);
|
|
|
|
|
|
|
|
|
|
+ foreach ($contractData['lines'] as $lineData) {
|
|
|
|
|
+ $line = new DolibarrContractLine();
|
|
|
|
|
+ $line->setId((int)$lineData['id']);
|
|
|
|
|
+ $line->setContractId((int)$lineData['fk_contrat']);
|
|
|
|
|
+ $line->setServiceRef($lineData['product_ref']);
|
|
|
|
|
+ $line->setServiceLabel($lineData['product_label']);
|
|
|
|
|
+ $line->setDateStart(new \DateTime(date('c', $lineData['date_start'])));
|
|
|
|
|
+ $line->setDateEnd(new \DateTime(date('c', $lineData['date_end'])));
|
|
|
|
|
+ $contract->addLine($line);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $dolibarrAccount->setContract($contract);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // get bills
|
|
|
$billsData = $this->dolibarrService->getBills($dolibarrAccount->getSocId());
|
|
$billsData = $this->dolibarrService->getBills($dolibarrAccount->getSocId());
|
|
|
foreach ($billsData as $billData) {
|
|
foreach ($billsData as $billData) {
|
|
|
$bill = new DolibarrBill();
|
|
$bill = new DolibarrBill();
|
|
|
- $bill->setBillId((int)$billData['id']);
|
|
|
|
|
|
|
+ $bill->setId((int)$billData['id']);
|
|
|
$bill->setSocId($dolibarrAccount->getSocId());
|
|
$bill->setSocId($dolibarrAccount->getSocId());
|
|
|
- $bill->setAmount((float)$billData['total_ttc']);
|
|
|
|
|
- $bill->setDate($billData['date']);
|
|
|
|
|
|
|
+ $bill->setTaxExcludedAmount((float)$billData['total_ht']);
|
|
|
|
|
+ $bill->setTaxIncludedAmount((float)$billData['total_ttc']);
|
|
|
|
|
+ $bill->setDate(new \DateTime(date('c', $billData['date'])));
|
|
|
$bill->setPaid((bool)$billData['paye']);
|
|
$bill->setPaid((bool)$billData['paye']);
|
|
|
$dolibarrAccount->addBill($bill);
|
|
$dolibarrAccount->addBill($bill);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // $dolibarrAccount->setSmsCredit();
|
|
|
|
|
+
|
|
|
return $dolibarrAccount;
|
|
return $dolibarrAccount;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|