Skip to content

Commit

Permalink
Ticket #3620 - Xero integration module.
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLV committed Dec 15, 2021
1 parent 3b84261 commit 36a22a7
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 7 deletions.
27 changes: 25 additions & 2 deletions modules/boonex/xero/classes/BxXeroApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,11 @@ public function actionAddInvoice($sProfileEmail, $sName, $mixedAmount, $iQuantit
$aLineItems = [$oLineItem];

$oContact = $this->actionGetContact($sProfileEmail);
$sContactId = $oContact->getContactId();
if(!$oContact)
return false;

$oInvoiceContact = new XeroAPI\XeroPHP\Models\Accounting\Contact;
$oInvoiceContact->setContactId($sContactId);
$oInvoiceContact->setContactId($oContact->getContactId());

$oInvoice = new XeroAPI\XeroPHP\Models\Accounting\Invoice;
$oInvoice->setReference('Ref-' . $this->_getRandNum())
Expand Down Expand Up @@ -334,6 +335,28 @@ public function actionGetInvoice($sId, $iUnitDp = 2)
return $mixedResult;
}

public function sendInvoice($sInvoiceId)
{
$mixedApi = $this->_getApiObject();
if($mixedApi === false)
return false;

list($sTenantId, $oXeroApi) = $mixedApi;

$bResult = true;
try {
$oRequestEmpty = new XeroAPI\XeroPHP\Models\Accounting\RequestEmpty;

$oXeroApi->emailInvoice($sTenantId, $sInvoiceId, $oRequestEmpty);
}
catch (Exception $oException) {
$this->_oLog->write('Send Invoice: ' . $oException->getMessage());
$bResult = false;
}

return $bResult;
}

protected function _getProvider()
{
if(empty($this->_oProvider))
Expand Down
3 changes: 2 additions & 1 deletion modules/boonex/xero/classes/BxXeroConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ public function __construct($aModule)
'PARAM_CLIENT_SECRET' => 'bx_xero_client_secret',
'PARAM_REDIRECT_URL' => 'bx_xero_redirect_url',
'PARAM_WEBHOOK_KEY' => 'bx_xero_webhook_key',
'PARAM_INVOICE_SEND' => 'bx_xero_invoice_send',
);

$this->_aJsClasses = array(
'main' => 'BxXeroMain',
);
Expand Down
22 changes: 18 additions & 4 deletions modules/boonex/xero/classes/BxXeroModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,17 @@ public function serviceAddContact($iProfileId)
return $this->_oApi->actionAddContact($iProfileId, $sProfileName, $sProfileEmail);
}

public function serviceAddInvoce($iProfileId, $sName, $fAmount, $iQuantity = 1, $sDueDate = false)
public function serviceAddInvoce($iProfileId, $sName, $mixedAmount, $iQuantity = 1, $mixedDueDate = false)
{
$oProfile = BxDolProfile::getInstance($iProfileId);
if(!$oProfile)
return false;

$sProfileEmail = $oProfile->getAccountObject()->getEmail();
return $this->_oApi->actionAddInvoice($sProfileEmail, $sName, $fAmount, $iQuantity, $sDueDate);
return $this->addInvoice($sProfileEmail, $sName, $mixedAmount, $iQuantity, $mixedDueDate);
}

public function serviceAddInvoceAuto($iProfileId, $sName, $fAmount, $iQuantity = 1, $mixedDueDate = false)
public function serviceAddInvoceAuto($iProfileId, $sName, $mixedAmount, $iQuantity = 1, $mixedDueDate = false)
{
$oProfile = BxDolProfile::getInstance($iProfileId);
if(!$oProfile)
Expand All @@ -156,7 +156,7 @@ public function serviceAddInvoceAuto($iProfileId, $sName, $fAmount, $iQuantity =
return false;
}

return $this->_oApi->actionAddInvoice($sProfileEmail, $sName, $fAmount, $iQuantity, $mixedDueDate);
return $this->addInvoice($sProfileEmail, $sName, $mixedAmount, $iQuantity, $mixedDueDate);
}


Expand All @@ -175,6 +175,20 @@ public function isContact($sProfileEmail, $bForceCheckApi = false)

return $this->_oApi->actionIsContact($sProfileEmail);
}

public function addInvoice($sProfileEmail, $sName, $fAmount, $iQuantity, $mixedDueDate)
{
$CNF = &$this->_oConfig->CNF;

$mixedInvoiceId = $this->_oApi->actionAddInvoice($sProfileEmail, $sName, $fAmount, $iQuantity, $mixedDueDate);
if(!$mixedInvoiceId)
return $mixedInvoiceId;

if(getParam($CNF['PARAM_INVOICE_SEND']) == 'on')
$this->_oApi->sendInvoice($mixedInvoiceId);

return $mixedInvoiceId;
}


/*
Expand Down
4 changes: 4 additions & 0 deletions modules/boonex/xero/install/langs/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<!-- Options -->
<string name="_bx_xero_options_category_hidden"><![CDATA[Hidden]]></string>
<string name="_bx_xero_options_category_general"><![CDATA[General]]></string>
<string name="_bx_xero_options_category_invoice"><![CDATA[Invoices]]></string>

<string name="_bx_xero_option_token"><![CDATA[Access token]]></string>
<string name="_bx_xero_option_expires"><![CDATA[Access token expiration time]]></string>
Expand All @@ -17,7 +18,10 @@
<string name="_bx_xero_option_redirect_url"><![CDATA[Redirect URL]]></string>
<string name="_bx_xero_option_webhook_url"><![CDATA[Webhook URL]]></string>
<string name="_bx_xero_option_webhook_key"><![CDATA[Webhook Key]]></string>

<string name="_bx_xero_option_invoice_send"><![CDATA[Send an invoice via email just after creation.]]></string>

<!-- Pages -->
<!--
<string name="_bx_xero_page_block_title_system_"><![CDATA[]]></string>
<string name="_bx_xero_page_block_title_"><![CDATA[]]></string>
Expand Down
7 changes: 7 additions & 0 deletions modules/boonex/xero/install/sql/enable.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `e
('bx_xero_webhook_url', '{site_url}m/xero/webhook', @iCategId, '_bx_xero_option_webhook_url', 'value', '', '', '', 40),
('bx_xero_webhook_key', '', @iCategId, '_bx_xero_option_webhook_key', 'digit', '', '', '', 42);

INSERT INTO `sys_options_categories` (`type_id`, `name`, `caption`, `order`)
VALUES (@iTypeId, 'bx_xero_invoice', '_bx_xero_options_category_invoice', 20);
SET @iCategId = LAST_INSERT_ID();

INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `extra`, `check`, `check_error`, `order`) VALUES
('bx_xero_invoice_send', 'on', @iCategId, '_bx_xero_option_invoice_send', 'checkbox', '', '', '', 10);


-- ALERTS
INSERT INTO `sys_alerts_handlers` (`name`, `class`, `file`, `service_call`) VALUES
Expand Down

0 comments on commit 36a22a7

Please sign in to comment.