Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

37 lines
1.5KB

  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. $document->setReference($this->documentReferenceGenerator->buildReference($orderShop->getSection()->getMerchant(), $document->getType())) ;
  21. $document->setMerchantAddress($merchantAddress);
  22. $document->setBuyerAddress($buyerAddress);
  23. $document->setMerchantAddressText($this->addressSolver->getSummary($merchantAddress));
  24. $document->setBuyerAddressText($this->addressSolver->getSummary($buyerAddress));
  25. $document->addOrderShop($orderShop);
  26. $document->setCreatedBy($orderShop->getUser());
  27. return $document;
  28. }
  29. }