Jacek Kowalski
2022-08-15 279758dc82cc4993e90d948b86234b0f1339ba2f
src/InvoiceSynchronizer.php
@@ -6,15 +6,7 @@
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);
@@ -55,7 +47,7 @@
         [$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();
@@ -78,7 +70,8 @@
      $wFirmaContractorId = $this->getContractorId($invoiceData['clientId']);
      $payment = Invoices\Payment::create(
         Payments\PaymentMethod::transfer()
         Payments\PaymentMethod::transfer(),
         new \DateTime($invoiceData['dueDate'])
      );
      if ($wFirmaId) {
@@ -104,6 +97,12 @@
      /** @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;