47 lines
1.4KB

  1. <?php
  2. namespace domain\Document\Document;
  3. use domain\Producer\Producer\ProducerSolver;
  4. use domain\_\AbstractBuilder;
  5. class DocumentBuilder extends AbstractBuilder
  6. {
  7. protected DocumentSolver $documentSolver;
  8. protected DocumentRepository $documentRepository;
  9. protected ProducerSolver $producerSolver;
  10. public function loadDependencies(): void
  11. {
  12. $this->documentSolver = $this->loadService(DocumentSolver::class);
  13. $this->documentRepository = $this->loadService(DocumentRepository::class);
  14. $this->producerSolver = $this->loadService(ProducerSolver::class);
  15. }
  16. public function initDocumentProducer(Document $document): void
  17. {
  18. $document->id_producer = $this->getProducerContextId();
  19. }
  20. public function initTaxCalculationMethod(DocumentInterface $document): void
  21. {
  22. $producerTaxCalculationMethod = $this->producerSolver->getConfig('option_tax_calculation_method');
  23. if ($producerTaxCalculationMethod) {
  24. $document->tax_calculation_method = $producerTaxCalculationMethod;
  25. } else {
  26. $document->tax_calculation_method = Document::TAX_CALCULATION_METHOD_DEFAULT;
  27. }
  28. }
  29. public function initDocumentDate(Document $document)
  30. {
  31. $document->date = date('Y-m-d H:i:s');
  32. }
  33. public function updateDocumentIsSend(Document $document, bool $isSent)
  34. {
  35. $document->is_sent = $isSent;
  36. $this->update($document);
  37. }
  38. }