/** * Map civicrm Array to Accounts package field names. * * @param array $invoiceData - require * contribution fields * - line items * - receive date * - source * - contact_id * @param int $accountsID * * @return array|bool * BankTransaction Object/ array as expected by accounts package. */ protected function mapToAccounts($invoiceData, $accountsID) { $lineItems = array(); foreach ($invoiceData['line_items'] as $lineItem) { if ($this->connector_id != 0 && $this->getAccountsContact() && $lineItem['accounts_contact_id'] != $this->getAccountsContact()) { // We have configured the connect to be account specific and we are // dealing with an account not related to this connector. // This can result (intentionally) in some line items being pushed // to one connector and some to another. To avoid this don't put a // contact_id on the connector account. continue; } $lineItems[] = array("Description" => $lineItem['display_name'] . ' ' . str_replace(array(' '), ' ', $lineItem['label']), "Quantity" => $lineItem['qty'], "UnitAmount" => $lineItem['unit_price'], "AccountCode" => !empty($lineItem['accounting_code']) ? $lineItem['accounting_code'] : $this->getDefaultAccountCode()); } $new_invoice = array("Type" => "RECEIVE", "Contact" => array("ContactNumber" => $invoiceData['contact_id']), "Date" => substr($invoiceData['receive_date'], 0, 10), "Status" => "AUTHORISED", "CurrencyCode" => CRM_Core_Config::singleton()->defaultCurrency, "Reference" => $invoiceData['display_name'] . ' ' . $invoiceData['contribution_source'], "LineAmountTypes" => "Inclusive", 'LineItems' => array('LineItem' => $lineItems), 'BankAccount' => array('Code' => $invoiceData['payment_instrument_accounting_code']), 'Url' => CRM_Utils_System::url('civicrm/contact/view/contribution', array('reset' => 1, 'id' => $invoiceData['id'], 'action' => 'view'), TRUE)); if ($accountsID) { $new_invoice['BankTransactionID'] = $accountsID; } $proceed = TRUE; CRM_Accountsync_Hook::accountPushAlterMapped('bank_transaction', $invoiceData, $proceed, $new_invoice); if (!$proceed) { return FALSE; } $this->validatePrerequisites($new_invoice); $new_invoice = array($new_invoice); return $new_invoice; }
/** * AccountContact.get API * * @param array $params * @return array API result descriptor * @throws API_Exception */ function civicrm_api3_account_contact_get($params) { $accountContacts = _civicrm_api3_basic_get('CRM_Accountsync_BAO_AccountContact', $params); if (is_array($accountContacts['values'])) { // e.g when we are dealing with 'getcount we skip this. foreach ($accountContacts['values'] as $id => $accountContact) { if (!empty($accountContacts['values'][$id]['accounts_data'])) { $accountContacts['values'][$id]['accounts_data'] = json_decode($accountContacts['values'][$id]['accounts_data'], TRUE); CRM_Accountsync_Hook::mapAccountsData($accountContacts['values'][$id]['accounts_data'], 'contact', $params['plugin']); } } } return $accountContacts; }
/** * Map CiviCRM array to Accounts package field names. * * @param array $invoiceData - require * contribution fields * - line items * - receive date * - source * - contact_id * @param int $accountsID * * @return array|bool * Contact Object/ array as expected by accounts package */ protected function mapToAccounts($invoiceData, $accountsID) { // Initially Assume that tax is not set up, and all amounts are tax inclusive. $line_amount_types = 'Inclusive'; $lineItems = array(); foreach ($invoiceData['line_items'] as $lineItem) { $lineItems[] = array("Description" => $lineItem['display_name'] . ' ' . str_replace(array(' '), ' ', $lineItem['label']), "Quantity" => $lineItem['qty'], "UnitAmount" => $lineItem['unit_price'], "AccountCode" => !empty($lineItem['accounting_code']) ? $lineItem['accounting_code'] : $this->getDefaultAccountCode()); if (!empty($lineItem['tax_amount'])) { // If we discover a non-zero tax_amount, switch to tax exclusive amounts. $line_amount_types = 'Exclusive'; } } $new_invoice = array("Type" => "ACCREC", "Contact" => array("ContactNumber" => $invoiceData['contact_id']), "Date" => substr($invoiceData['receive_date'], 0, 10), "DueDate" => substr($invoiceData['receive_date'], 0, 10), "Status" => "SUBMITTED", "InvoiceNumber" => $invoiceData['id'], "CurrencyCode" => CRM_Core_Config::singleton()->defaultCurrency, "Reference" => $invoiceData['display_name'] . ' ' . $invoiceData['contribution_source'], "LineAmountTypes" => $line_amount_types, 'LineItems' => array('LineItem' => $lineItems)); $proceed = TRUE; CRM_Accountsync_Hook::accountPushAlterMapped('invoice', $invoiceData, $proceed, $new_invoice); if (!$proceed) { return FALSE; } $this->validatePrerequisites($new_invoice); $new_invoice = array($new_invoice); return $new_invoice; }
/** * Map civicrm Array to Accounts package field names. * * @param array $contact * Contact Array as returned from API * @param $accountsID * * @return array|bool * Contact Object/ array as expected by accounts package */ protected function mapToAccounts($contact, $accountsID) { $new_contact = array("Name" => $contact['display_name'] . " - " . $contact['contact_id'], "FirstName" => $contact['first_name'], "LastName" => $contact['last_name'], "EmailAddress" => CRM_Utils_Rule::email($contact['email']) ? $contact['email'] : '', "ContactNumber" => $contact['contact_id'], "Addresses" => array("Address" => array(array("AddressType" => 'POBOX', "AddressLine1" => $contact['street_address'], "City" => $contact['city'], "PostalCode" => $contact['postal_code']))), "Phones" => array("Phone" => array("PhoneType" => 'DEFAULT', "PhoneNumber" => $contact['phone']))); if (!empty($accountsID)) { $new_contact['ContactID'] = $accountsID; } $proceed = TRUE; CRM_Accountsync_Hook::accountPushAlterMapped('contact', $contact, $proceed, $new_contact); $new_contact = array($new_contact); if (!$proceed) { return FALSE; } return $new_contact; }