From 071152c77a3d28045a93613135a68d439c47b1eb Mon Sep 17 00:00:00 2001 From: AntonLV Date: Mon, 20 Dec 2021 17:08:56 +0300 Subject: [PATCH] Ticket #3620 - Xero integration module: Tax type. --- modules/boonex/xero/classes/BxXeroApi.php | 23 ++++++++++++++++---- modules/boonex/xero/classes/BxXeroModule.php | 4 ++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/modules/boonex/xero/classes/BxXeroApi.php b/modules/boonex/xero/classes/BxXeroApi.php index 75c715c26f..6d924fdd7e 100644 --- a/modules/boonex/xero/classes/BxXeroApi.php +++ b/modules/boonex/xero/classes/BxXeroApi.php @@ -249,17 +249,32 @@ public function actionAddInvoice($sProfileEmail, $sName, $mixedAmount, $iQuantit $mixedDueDate = new DateTime($mixedDueDate); $fAmount = $mixedAmount; - $fTaxAmount = false; + $fTaxAmount = $sTaxType = false; if(is_array($mixedAmount)) - list($fAmount, $fTaxAmount) = $mixedAmount; + switch(count($mixedAmount)) { + case 2: + list($fAmount, $fTaxAmount) = $mixedAmount; + break; + + case 3: + list($fAmount, $fTaxAmount, $sTaxType) = $mixedAmount; + break; + } + + $sLineAmountType = \XeroAPI\XeroPHP\Models\Accounting\LineAmountTypes::NO_TAX; $oLineItem = new XeroAPI\XeroPHP\Models\Accounting\LineItem; $oLineItem->setDescription($sName) ->setUnitAmount($fAmount) ->setQuantity($iQuantity) ->setAccountCode($sAccount); - if($fTaxAmount !== false) + if($fTaxAmount !== false) { + $sLineAmountType = \XeroAPI\XeroPHP\Models\Accounting\LineAmountTypes::EXCLUSIVE; + $oLineItem->setTaxAmount($fTaxAmount); + } + if($sTaxType !== false) + $oLineItem->setTaxType($sTaxType); $aLineItems = [$oLineItem]; @@ -277,7 +292,7 @@ public function actionAddInvoice($sProfileEmail, $sName, $mixedAmount, $iQuantit ->setLineItems($aLineItems) ->setStatus(XeroAPI\XeroPHP\Models\Accounting\Invoice::STATUS_AUTHORISED) ->setType(XeroAPI\XeroPHP\Models\Accounting\Invoice::TYPE_ACCREC) - ->setLineAmountTypes(\XeroAPI\XeroPHP\Models\Accounting\LineAmountTypes::EXCLUSIVE); + ->setLineAmountTypes($sLineAmountType); $oXeroResponse = $oXeroApi->createInvoices($sTenantId, $oInvoice); if(count($oXeroResponse->getInvoices()) == 1) diff --git a/modules/boonex/xero/classes/BxXeroModule.php b/modules/boonex/xero/classes/BxXeroModule.php index a719ae9d99..c6a0f6c903 100644 --- a/modules/boonex/xero/classes/BxXeroModule.php +++ b/modules/boonex/xero/classes/BxXeroModule.php @@ -176,11 +176,11 @@ public function isContact($sProfileEmail, $bForceCheckApi = false) return $this->_oApi->actionIsContact($sProfileEmail); } - public function addInvoice($sProfileEmail, $sName, $fAmount, $iQuantity, $mixedDueDate) + public function addInvoice($sProfileEmail, $sName, $mixedAmount, $iQuantity, $mixedDueDate) { $CNF = &$this->_oConfig->CNF; - $mixedInvoiceId = $this->_oApi->actionAddInvoice($sProfileEmail, $sName, $fAmount, $iQuantity, $mixedDueDate); + $mixedInvoiceId = $this->_oApi->actionAddInvoice($sProfileEmail, $sName, $mixedAmount, $iQuantity, $mixedDueDate); if(!$mixedInvoiceId) return $mixedInvoiceId;