Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

39 lines
1.7KB

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