| | |
| | | use \Webit\WFirmaSDK\Invoices as Invoices; |
| | | use \Webit\WFirmaSDK\Payments as Payments; |
| | | |
| | | class InvoiceSynchronizer { |
| | | protected $wfirma; |
| | | protected $helper; |
| | | |
| | | function __construct(\Webit\WFirmaSDK\Entity\ModuleApiFactory $wFirmaApi, UcrmHelper $ucrmHelper) { |
| | | $this->wfirma = $wFirmaApi; |
| | | $this->helper = $ucrmHelper; |
| | | } |
| | | |
| | | class InvoiceSynchronizer extends Synchronizer { |
| | | function getContractorId($clientId, $synchronize = TRUE) { |
| | | if ($synchronize) { |
| | | $synchronizer = new ContractorSynchronizer($this->wfirma, $this->helper); |
| | |
| | | [$c2->name(), $c2->unit(), $c2->count(), $c2->price(), $c2->vat(), $c2->discount()]; |
| | | } |
| | | |
| | | function synchronize($ucrmInvoiceId) { |
| | | function synchronize(int $ucrmInvoiceId) { |
| | | $crm = $this->helper->getApi(); |
| | | $wFirmaInvoices = $this->wfirma->invoicesApi(); |
| | | |
| | |
| | | |
| | | $wFirmaContractorId = $this->getContractorId($invoiceData['clientId']); |
| | | $payment = Invoices\Payment::create( |
| | | Payments\PaymentMethod::transfer() |
| | | Payments\PaymentMethod::transfer(), |
| | | new \DateTime($invoiceData['dueDate']) |
| | | ); |
| | | |
| | | if ($wFirmaId) { |
| | |
| | | /** @var \Webit\WFirmaSDK\Invoices\Invoice $invoice */ |
| | | $changed = FALSE; |
| | | |
| | | if ($invoice->payment()->paymentMethod() != $payment->paymentMethod() |
| | | || $invoice->payment()->paymentDate() != $payment->paymentDate()) { |
| | | $invoice->changePayment($payment); |
| | | $changed = TRUE; |
| | | } |
| | | |
| | | if ($invoice->priceType() != Invoices\PriceType::brutto()) { |
| | | $invoice->changePriceType(Invoices\PriceType::brutto()); |
| | | $changed = TRUE; |