예제 #1
0
 /**
  * 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;
 }
예제 #2
0
파일: Invoice.php 프로젝트: kidaa30/yes
 /**
  * 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;
 }
예제 #3
0
파일: Contact.php 프로젝트: kidaa30/yes
 /**
  * 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;
 }