From 48693f7ddc7438cf59100c12184e202a053a9614 Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Mon, 15 Aug 2022 19:38:53 +0000
Subject: [PATCH] Synchronize invoice due date

---
 src/InvoiceSynchronizer.php |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/src/InvoiceSynchronizer.php b/src/InvoiceSynchronizer.php
index 3781f00..3ddf959 100644
--- a/src/InvoiceSynchronizer.php
+++ b/src/InvoiceSynchronizer.php
@@ -78,7 +78,8 @@
 
 		$wFirmaContractorId = $this->getContractorId($invoiceData['clientId']);
 		$payment = Invoices\Payment::create(
-			Payments\PaymentMethod::transfer()
+			Payments\PaymentMethod::transfer(),
+			new \DateTime($invoiceData['dueDate'])
 		);
 
 		if ($wFirmaId) {
@@ -104,6 +105,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;

--
Gitblit v1.10.0