|
- <?php
-
- namespace Lc\CaracoleBundle\Builder\File;
-
- use Lc\CaracoleBundle\Model\File\DocumentInterface;
- use Lc\CaracoleBundle\Model\File\DocumentModel;
- use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
- use Lc\CaracoleBundle\Generator\DocumentReferenceGenerator;
- use Lc\CaracoleBundle\Solver\Address\AddressSolver;
-
- class DocumentBuilder
- {
- protected DocumentReferenceGenerator $documentReferenceGenerator;
- protected AddressSolver $addressSolver;
-
- public function __construct(DocumentReferenceGenerator $documentReferenceGenerator, AddressSolver $addressSolver)
- {
- $this->documentReferenceGenerator = $documentReferenceGenerator;
- $this->addressSolver = $addressSolver;
- }
-
- public function initFromOrderShop(DocumentInterface $document, OrderShopInterface $orderShop) :DocumentInterface
- {
- $merchantAddress = $orderShop->getSection()->getMerchant()->getAddress();
- $buyerAddress = $orderShop->getInvoiceAddress();
- //TODO a discuter, doit on garder le lien avec merchant pr la référence ou le mettre par section ? Est-ce que le nom de cette fonction est approprié. on fait une invoice et ça s'appele initFromOrderShop
- $document->setReference($this->documentReferenceGenerator->buildReference($orderShop->getSection()->getMerchant(), $document->getType())) ;
-
- $document->setMerchantAddress($merchantAddress);
- $document->setBuyerAddress($buyerAddress);
- $document->setMerchantAddressText($this->addressSolver->getSummary($merchantAddress));
- $document->setBuyerAddressText($this->addressSolver->getSummary($buyerAddress));
- $document->addOrderShop($orderShop);
- $document->setCreatedBy($orderShop->getUser());
-
- return $document;
- }
-
- }
|