No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

DocumentBuilder.php 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace Lc\CaracoleBundle\Builder\File;
  3. use Lc\CaracoleBundle\Model\File\DocumentInterface;
  4. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  5. use Lc\CaracoleBundle\Generator\DocumentReferenceGenerator;
  6. use Lc\CaracoleBundle\Solver\Address\AddressSolver;
  7. class DocumentBuilder
  8. {
  9. protected DocumentReferenceGenerator $documentReferenceGenerator;
  10. protected AddressSolver $addressSolver;
  11. public function __construct(DocumentReferenceGenerator $documentReferenceGenerator, AddressSolver $addressSolver)
  12. {
  13. $this->documentReferenceGenerator = $documentReferenceGenerator;
  14. $this->addressSolver = $addressSolver;
  15. }
  16. public function initFromOrderShop(DocumentInterface $document, OrderShopInterface $orderShop) :DocumentInterface
  17. {
  18. $merchantAddress = $orderShop->getSection()->getMerchant()->getAddress();
  19. $buyerAddress = $orderShop->getInvoiceAddress();
  20. // @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
  21. $document->setReference($this->documentReferenceGenerator->buildReference($orderShop->getSection()->getMerchant(), $document->getType(), $orderShop)) ;
  22. $document->setMerchantAddress($merchantAddress);
  23. $document->setBuyerAddress($buyerAddress);
  24. $document->setMerchantAddressText($this->addressSolver->getSummary($merchantAddress));
  25. $document->setBuyerAddressText($this->addressSolver->getSummary($buyerAddress));
  26. $document->addOrderShop($orderShop);
  27. $document->setCreatedBy($orderShop->getUser());
  28. return $document;
  29. }
  30. }