|
|
@@ -6,10 +6,7 @@ namespace App\DataProvider\Dolibarr;
|
|
|
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
|
|
|
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
|
|
|
use App\ApiResources\Dolibarr\DolibarrAccount;
|
|
|
-use App\ApiResources\Dolibarr\DolibarrBill;
|
|
|
-use App\ApiResources\Dolibarr\DolibarrContract;
|
|
|
-use App\ApiResources\Dolibarr\DolibarrContractLine;
|
|
|
-use App\Service\Dolibarr\DolibarrService;
|
|
|
+use App\Service\Dolibarr\DolibarrAccountCreator;
|
|
|
|
|
|
/**
|
|
|
* Custom provider pour les DolibarrAccounts récupérés via l'api dolibarr
|
|
|
@@ -17,21 +14,11 @@ use App\Service\Dolibarr\DolibarrService;
|
|
|
*/
|
|
|
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;
|
|
|
|
|
|
public function __construct(
|
|
|
- DolibarrService $dolibarrService,
|
|
|
+ private DolibarrAccountCreator $dolibarrAccountCreator,
|
|
|
)
|
|
|
- {
|
|
|
- $this->dolibarrService = $dolibarrService;
|
|
|
- }
|
|
|
+ {}
|
|
|
|
|
|
public function supports(string $resourceClass, string $operationName = null, array $context = []): bool
|
|
|
{
|
|
|
@@ -40,54 +27,6 @@ final class DolibarrAccountDataProvider implements ItemDataProviderInterface, Re
|
|
|
|
|
|
public function getItem(string $resourceClass, $id, string $operationName = null, array $context = []): ?DolibarrAccount
|
|
|
{
|
|
|
- $dolibarrAccount = new DolibarrAccount();
|
|
|
-
|
|
|
- $accountData = $this->dolibarrService->getSociety($id);
|
|
|
-
|
|
|
- $dolibarrAccount->setOrganizationId($id);
|
|
|
- $dolibarrAccount->setSocId((int)$accountData['id']);
|
|
|
- $dolibarrAccount->setClientNumber($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());
|
|
|
- foreach ($billsData as $billData) {
|
|
|
- $bill = new DolibarrBill();
|
|
|
- $bill->setId((int)$billData['id']);
|
|
|
- $bill->setRef($billData['ref']);
|
|
|
- $bill->setSocId($dolibarrAccount->getSocId());
|
|
|
- $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']);
|
|
|
- $dolibarrAccount->addBill($bill);
|
|
|
- }
|
|
|
-
|
|
|
- return $dolibarrAccount;
|
|
|
+ return $this->dolibarrAccountCreator->getDolibarrAccount($id);
|
|
|
}
|
|
|
}
|