First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
259
sites/all/modules/civicrm/CRM/Financial/BAO/ExportFormat.php
Normal file
259
sites/all/modules/civicrm/CRM/Financial/BAO/ExportFormat.php
Normal file
|
@ -0,0 +1,259 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for Export Formats
|
||||
* Create a subclass for a specific format.
|
||||
* @see http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+Specifications+-++Batches#CiviAccountsSpecifications-Batches-%C2%A0Overviewofimplementation
|
||||
*/
|
||||
abstract class CRM_Financial_BAO_ExportFormat {
|
||||
|
||||
/**
|
||||
* data which the individual export formats will output in the desired format.
|
||||
* @var array
|
||||
*/
|
||||
protected $_exportParams;
|
||||
|
||||
/**
|
||||
* smarty template.
|
||||
* @var CRM_Core_Smarty
|
||||
*/
|
||||
static protected $_template;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
if (!isset(self::$_template)) {
|
||||
self::$_template = CRM_Core_Smarty::singleton();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to assemble the appropriate subset of financial data for the specific export format.
|
||||
* @param array $exportParams
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function export($exportParams) {
|
||||
$this->_exportParams = $exportParams;
|
||||
return $exportParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports sbatches in $this->_batchIds, and saves to file.
|
||||
*
|
||||
* @param string $fileName - use this file name (if applicable)
|
||||
*/
|
||||
public function output($fileName = NULL) {
|
||||
// Default behaviour, override if needed:
|
||||
self::createActivityExport($this->_batchIds, $fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract function that generates exports, and downloads them as zip file.
|
||||
*
|
||||
* @param $exportDaos array with DAO's for queries to be exported.
|
||||
*/
|
||||
public abstract function makeExport($exportDaos);
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMimeType() {
|
||||
return 'text/plain';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns some kind of identification for your export format.
|
||||
*
|
||||
* This does not really has to be a file extension, you can name your
|
||||
* file as you wish as you override output.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public abstract function getFileExtension();
|
||||
|
||||
/**
|
||||
* @return object
|
||||
*/
|
||||
public static function &getTemplate() {
|
||||
return self::$_template;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $var
|
||||
* @param null $value
|
||||
*/
|
||||
public function assign($var, $value = NULL) {
|
||||
self::$_template->assign($var, $value);
|
||||
}
|
||||
|
||||
/*
|
||||
* This gets called for every item of data being compiled before being sent to the exporter for output.
|
||||
*
|
||||
* Depending on the output format might want to override this, e.g. for IIF tabs need to be escaped etc,
|
||||
* but for CSV it doesn't make sense because php has built in csv output functions.
|
||||
*/
|
||||
/**
|
||||
* @param $s
|
||||
* @param string $type
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public static function format($s, $type = 'string') {
|
||||
if (!empty($s)) {
|
||||
return $s;
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
public function initiateDownload() {
|
||||
$config = CRM_Core_Config::singleton();
|
||||
// zip files if more than one.
|
||||
if (count($this->_downloadFile) > 1) {
|
||||
$zip = $config->customFileUploadDir . 'Financial_Transactions_' . date('YmdHis') . '.zip';
|
||||
$result = $this->createZip($this->_downloadFile, $zip, TRUE);
|
||||
if ($result) {
|
||||
CRM_Utils_System::setHttpHeader('Content-Type', 'application/zip');
|
||||
CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename=' . CRM_Utils_File::cleanFileName(basename($zip)));
|
||||
CRM_Utils_System::setHttpHeader('Content-Length', '' . filesize($zip));
|
||||
ob_clean();
|
||||
flush();
|
||||
readfile($config->customFileUploadDir . CRM_Utils_File::cleanFileName(basename($zip)));
|
||||
unlink($zip); //delete the zip to avoid clutter.
|
||||
CRM_Utils_System::civiExit();
|
||||
}
|
||||
}
|
||||
else {
|
||||
CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain');
|
||||
CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename=' . CRM_Utils_File::cleanFileName(basename($this->_downloadFile[0])));
|
||||
CRM_Utils_System::setHttpHeader('Content-Length', '' . filesize($this->_downloadFile[0]));
|
||||
ob_clean();
|
||||
flush();
|
||||
readfile($config->customFileUploadDir . CRM_Utils_File::cleanFileName(basename($this->_downloadFile[0])));
|
||||
CRM_Utils_System::civiExit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $batchIds
|
||||
* @param string $fileName
|
||||
*
|
||||
* @throws CRM_Core_Exception
|
||||
*/
|
||||
public static function createActivityExport($batchIds, $fileName) {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$values = array();
|
||||
$params = array('id' => $batchIds);
|
||||
CRM_Batch_BAO_Batch::retrieve($params, $values);
|
||||
$createdBy = CRM_Contact_BAO_Contact::displayName($values['created_id']);
|
||||
$modifiedBy = CRM_Contact_BAO_Contact::displayName($values['modified_id']);
|
||||
|
||||
$values['payment_instrument_id'] = '';
|
||||
if (isset($values['payment_instrument_id'])) {
|
||||
$paymentInstrument = array_flip(CRM_Contribute_PseudoConstant::paymentInstrument('label'));
|
||||
$values['payment_instrument_id'] = array_search($values['payment_instrument_id'], $paymentInstrument);
|
||||
}
|
||||
$details = '<p>' . ts('Record:') . ' ' . $values['title'] . '</p><p>' . ts('Description:') . '</p><p>' . ts('Created By:') . " $createdBy" . '</p><p>' . ts('Created Date:') . ' ' . $values['created_date'] . '</p><p>' . ts('Last Modified By:') . ' ' . $modifiedBy . '</p><p>' . ts('Payment Method:') . ' ' . $values['payment_instrument_id'] . '</p>';
|
||||
$subject = '';
|
||||
if (!empty($values['total'])) {
|
||||
$subject .= ts('Total') . '[' . CRM_Utils_Money::format($values['total']) . '],';
|
||||
}
|
||||
if (!empty($values['item_count'])) {
|
||||
$subject .= ' ' . ts('Count') . '[' . $values['item_count'] . '],';
|
||||
}
|
||||
|
||||
// create activity.
|
||||
$subject .= ' ' . ts('Batch') . '[' . $values['title'] . ']';
|
||||
$activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name');
|
||||
$activityParams = array(
|
||||
'activity_type_id' => array_search('Export Accounting Batch', $activityTypes),
|
||||
'subject' => $subject,
|
||||
'status_id' => 2,
|
||||
'activity_date_time' => date('YmdHis'),
|
||||
'source_contact_id' => $session->get('userID'),
|
||||
'source_record_id' => $values['id'],
|
||||
'target_contact_id' => $session->get('userID'),
|
||||
'details' => $details,
|
||||
'attachFile_1' => array(
|
||||
'uri' => $fileName,
|
||||
'type' => 'text/csv',
|
||||
'location' => $fileName,
|
||||
'upload_date' => date('YmdHis'),
|
||||
),
|
||||
);
|
||||
|
||||
CRM_Activity_BAO_Activity::create($activityParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $files
|
||||
* @param null $destination
|
||||
* @param bool $overwrite
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function createZip($files = array(), $destination = NULL, $overwrite = FALSE) {
|
||||
// if the zip file already exists and overwrite is false, return false
|
||||
if (file_exists($destination) && !$overwrite) {
|
||||
return FALSE;
|
||||
}
|
||||
$valid_files = array();
|
||||
if (is_array($files)) {
|
||||
foreach ($files as $file) {
|
||||
// make sure the file exists
|
||||
if (file_exists($file)) {
|
||||
$validFiles[] = $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($validFiles)) {
|
||||
$zip = new ZipArchive();
|
||||
if ($zip->open($destination, $overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== TRUE) {
|
||||
return FALSE;
|
||||
}
|
||||
foreach ($validFiles as $file) {
|
||||
$zip->addFile($file, CRM_Utils_File::cleanFileName(basename($file)));
|
||||
}
|
||||
$zip->close();
|
||||
return file_exists($destination);
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
256
sites/all/modules/civicrm/CRM/Financial/BAO/ExportFormat/CSV.php
Normal file
256
sites/all/modules/civicrm/CRM/Financial/BAO/ExportFormat/CSV.php
Normal file
|
@ -0,0 +1,256 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* @link http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+Specifications+-++Batches#CiviAccountsSpecifications-Batches-%C2%A0Overviewofimplementation
|
||||
*/
|
||||
class CRM_Financial_BAO_ExportFormat_CSV extends CRM_Financial_BAO_ExportFormat {
|
||||
|
||||
/**
|
||||
* For this phase, we always output these records too so that there isn't data
|
||||
* referenced in the journal entries that isn't defined anywhere.
|
||||
*
|
||||
* Possibly in the future this could be selected by the user.
|
||||
*/
|
||||
public static $complementaryTables = array(
|
||||
'ACCNT',
|
||||
'CUST',
|
||||
);
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $exportParams
|
||||
*/
|
||||
public function export($exportParams) {
|
||||
$export = parent::export($exportParams);
|
||||
|
||||
// Save the file in the public directory.
|
||||
$fileName = self::putFile($export);
|
||||
|
||||
foreach (self::$complementaryTables as $rct) {
|
||||
$func = "export{$rct}";
|
||||
$this->$func();
|
||||
}
|
||||
|
||||
$this->output($fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $batchId
|
||||
*
|
||||
* @return Object
|
||||
*/
|
||||
public function generateExportQuery($batchId) {
|
||||
$sql = "SELECT
|
||||
ft.id as financial_trxn_id,
|
||||
ft.trxn_date,
|
||||
fa_to.accounting_code AS to_account_code,
|
||||
fa_to.name AS to_account_name,
|
||||
fa_to.account_type_code AS to_account_type_code,
|
||||
ft.total_amount AS debit_total_amount,
|
||||
ft.trxn_id AS trxn_id,
|
||||
cov.label AS payment_instrument,
|
||||
ft.check_number,
|
||||
c.source AS source,
|
||||
c.id AS contribution_id,
|
||||
c.contact_id AS contact_id,
|
||||
eb.batch_id AS batch_id,
|
||||
ft.currency AS currency,
|
||||
cov_status.label AS status,
|
||||
CASE
|
||||
WHEN efti.entity_id IS NOT NULL
|
||||
THEN efti.amount
|
||||
ELSE eftc.amount
|
||||
END AS amount,
|
||||
fa_from.account_type_code AS credit_account_type_code,
|
||||
fa_from.accounting_code AS credit_account,
|
||||
fa_from.name AS credit_account_name,
|
||||
fac.account_type_code AS from_credit_account_type_code,
|
||||
fac.accounting_code AS from_credit_account,
|
||||
fac.name AS from_credit_account_name,
|
||||
fi.description AS item_description
|
||||
FROM civicrm_entity_batch eb
|
||||
LEFT JOIN civicrm_financial_trxn ft ON (eb.entity_id = ft.id AND eb.entity_table = 'civicrm_financial_trxn')
|
||||
LEFT JOIN civicrm_financial_account fa_to ON fa_to.id = ft.to_financial_account_id
|
||||
LEFT JOIN civicrm_financial_account fa_from ON fa_from.id = ft.from_financial_account_id
|
||||
LEFT JOIN civicrm_option_group cog ON cog.name = 'payment_instrument'
|
||||
LEFT JOIN civicrm_option_value cov ON (cov.value = ft.payment_instrument_id AND cov.option_group_id = cog.id)
|
||||
LEFT JOIN civicrm_entity_financial_trxn eftc ON (eftc.financial_trxn_id = ft.id AND eftc.entity_table = 'civicrm_contribution')
|
||||
LEFT JOIN civicrm_contribution c ON c.id = eftc.entity_id
|
||||
LEFT JOIN civicrm_option_group cog_status ON cog_status.name = 'contribution_status'
|
||||
LEFT JOIN civicrm_option_value cov_status ON (cov_status.value = ft.status_id AND cov_status.option_group_id = cog_status.id)
|
||||
LEFT JOIN civicrm_entity_financial_trxn efti ON (efti.financial_trxn_id = ft.id AND efti.entity_table = 'civicrm_financial_item')
|
||||
LEFT JOIN civicrm_financial_item fi ON fi.id = efti.entity_id
|
||||
LEFT JOIN civicrm_financial_account fac ON fac.id = fi.financial_account_id
|
||||
LEFT JOIN civicrm_financial_account fa ON fa.id = fi.financial_account_id
|
||||
WHERE eb.batch_id = ( %1 )";
|
||||
|
||||
CRM_Utils_Hook::batchQuery($sql);
|
||||
|
||||
$params = array(1 => array($batchId, 'String'));
|
||||
$dao = CRM_Core_DAO::executeQuery($sql, $params);
|
||||
|
||||
return $dao;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $export
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function putFile($export) {
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$fileName = $config->uploadDir . 'Financial_Transactions_' . $this->_batchIds . '_' . date('YmdHis') . '.' . $this->getFileExtension();
|
||||
$this->_downloadFile[] = $config->customFileUploadDir . CRM_Utils_File::cleanFileName(basename($fileName));
|
||||
$out = fopen($fileName, 'w');
|
||||
if (!empty($export['headers'])) {
|
||||
fputcsv($out, $export['headers']);
|
||||
}
|
||||
unset($export['headers']);
|
||||
if (!empty($export)) {
|
||||
foreach ($export as $fields) {
|
||||
fputcsv($out, $fields);
|
||||
}
|
||||
fclose($out);
|
||||
}
|
||||
return $fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format table headers.
|
||||
*
|
||||
* @param array $values
|
||||
* @return array
|
||||
*/
|
||||
public function formatHeaders($values) {
|
||||
$arrayKeys = array_keys($values);
|
||||
$headers = '';
|
||||
if (!empty($arrayKeys)) {
|
||||
foreach ($values[$arrayKeys[0]] as $title => $value) {
|
||||
$headers[] = $title;
|
||||
}
|
||||
}
|
||||
return $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate CSV array for export.
|
||||
*
|
||||
* @param array $export
|
||||
*/
|
||||
public function makeExport($export) {
|
||||
// getting data from admin page
|
||||
$prefixValue = Civi::settings()->get('contribution_invoice_settings');
|
||||
|
||||
foreach ($export as $batchId => $dao) {
|
||||
$financialItems = array();
|
||||
$this->_batchIds = $batchId;
|
||||
|
||||
$batchItems = array();
|
||||
$queryResults = array();
|
||||
|
||||
while ($dao->fetch()) {
|
||||
$creditAccountName = $creditAccountType = $creditAccount = NULL;
|
||||
if ($dao->credit_account) {
|
||||
$creditAccountName = $dao->credit_account_name;
|
||||
$creditAccountType = $dao->credit_account_type_code;
|
||||
$creditAccount = $dao->credit_account;
|
||||
}
|
||||
else {
|
||||
$creditAccountName = $dao->from_credit_account_name;
|
||||
$creditAccountType = $dao->from_credit_account_type_code;
|
||||
$creditAccount = $dao->from_credit_account;
|
||||
}
|
||||
|
||||
$invoiceNo = CRM_Utils_Array::value('invoice_prefix', $prefixValue) . "" . $dao->contribution_id;
|
||||
|
||||
$financialItems[] = array(
|
||||
'Batch ID' => $dao->batch_id,
|
||||
'Invoice No' => $invoiceNo,
|
||||
'Contact ID' => $dao->contact_id,
|
||||
'Financial Trxn ID/Internal ID' => $dao->financial_trxn_id,
|
||||
'Transaction Date' => $dao->trxn_date,
|
||||
'Debit Account' => $dao->to_account_code,
|
||||
'Debit Account Name' => $dao->to_account_name,
|
||||
'Debit Account Type' => $dao->to_account_type_code,
|
||||
'Debit Account Amount (Unsplit)' => $dao->debit_total_amount,
|
||||
'Transaction ID (Unsplit)' => $dao->trxn_id,
|
||||
'Debit amount (Split)' => $dao->amount,
|
||||
'Payment Instrument' => $dao->payment_instrument,
|
||||
'Check Number' => $dao->check_number,
|
||||
'Source' => $dao->source,
|
||||
'Currency' => $dao->currency,
|
||||
'Transaction Status' => $dao->status,
|
||||
'Amount' => $dao->amount,
|
||||
'Credit Account' => $creditAccount,
|
||||
'Credit Account Name' => $creditAccountName,
|
||||
'Credit Account Type' => $creditAccountType,
|
||||
'Item Description' => $dao->item_description,
|
||||
);
|
||||
|
||||
end($financialItems);
|
||||
$batchItems[] = &$financialItems[key($financialItems)];
|
||||
$queryResults[] = get_object_vars($dao);
|
||||
}
|
||||
|
||||
CRM_Utils_Hook::batchItems($queryResults, $batchItems);
|
||||
|
||||
$financialItems['headers'] = self::formatHeaders($financialItems);
|
||||
self::export($financialItems);
|
||||
}
|
||||
parent::initiateDownload();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFileExtension() {
|
||||
return 'csv';
|
||||
}
|
||||
|
||||
public function exportACCNT() {
|
||||
}
|
||||
|
||||
public function exportCUST() {
|
||||
}
|
||||
|
||||
public function exportTRANS() {
|
||||
}
|
||||
|
||||
}
|
389
sites/all/modules/civicrm/CRM/Financial/BAO/ExportFormat/IIF.php
Normal file
389
sites/all/modules/civicrm/CRM/Financial/BAO/ExportFormat/IIF.php
Normal file
|
@ -0,0 +1,389 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* @link http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+Specifications+-++Batches#CiviAccountsSpecifications-Batches-%C2%A0Overviewofimplementation
|
||||
*/
|
||||
class CRM_Financial_BAO_ExportFormat_IIF extends CRM_Financial_BAO_ExportFormat {
|
||||
|
||||
/**
|
||||
* Tab character. Some people's editors replace tabs with spaces so I'm scared to use actual tabs.
|
||||
* Can't set it here using chr() because static. Same thing if a const. So it's set in constructor.
|
||||
*/
|
||||
static $SEPARATOR;
|
||||
|
||||
/**
|
||||
* For this phase, we always output these records too so that there isn't data
|
||||
* referenced in the journal entries that isn't defined anywhere.
|
||||
*
|
||||
* Possibly in the future this could be selected by the user.
|
||||
*/
|
||||
public static $complementaryTables = array(
|
||||
'ACCNT',
|
||||
'CUST',
|
||||
);
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$SEPARATOR = chr(9);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $exportParams
|
||||
*/
|
||||
public function export($exportParams) {
|
||||
parent::export($exportParams);
|
||||
|
||||
foreach (self::$complementaryTables as $rct) {
|
||||
$func = "export{$rct}";
|
||||
$this->$func();
|
||||
}
|
||||
|
||||
// now do general journal entries
|
||||
$this->exportTRANS();
|
||||
|
||||
$this->output();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $fileName
|
||||
*/
|
||||
public function output($fileName = NULL) {
|
||||
$tplFile = $this->getHookedTemplateFileName();
|
||||
$out = self::getTemplate()->fetch($tplFile);
|
||||
$fileName = $this->putFile($out);
|
||||
self::createActivityExport($this->_batchIds, $fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $out
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function putFile($out) {
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$fileName = $config->uploadDir . 'Financial_Transactions_' . $this->_batchIds . '_' . date('YmdHis') . '.' . $this->getFileExtension();
|
||||
$this->_downloadFile[] = $config->customFileUploadDir . CRM_Utils_File::cleanFileName(basename($fileName));
|
||||
$buffer = fopen($fileName, 'w');
|
||||
fwrite($buffer, $out);
|
||||
fclose($buffer);
|
||||
return $fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $batchId
|
||||
*
|
||||
* @return Object
|
||||
*/
|
||||
public function generateExportQuery($batchId) {
|
||||
|
||||
$sql = "SELECT
|
||||
ft.id as financial_trxn_id,
|
||||
ft.trxn_date,
|
||||
ft.total_amount AS debit_total_amount,
|
||||
ft.currency AS currency,
|
||||
ft.trxn_id AS trxn_id,
|
||||
cov.label AS payment_instrument,
|
||||
ft.check_number,
|
||||
fa_from.id AS from_account_id,
|
||||
fa_from.name AS from_account_name,
|
||||
fa_from.accounting_code AS from_account_code,
|
||||
fa_from.financial_account_type_id AS from_account_type_id,
|
||||
fa_from.description AS from_account_description,
|
||||
fa_from.account_type_code AS from_account_type_code,
|
||||
fa_to.id AS to_account_id,
|
||||
fa_to.name AS to_account_name,
|
||||
fa_to.accounting_code AS to_account_code,
|
||||
fa_to.financial_account_type_id AS to_account_type_id,
|
||||
fa_to.account_type_code AS to_account_type_code,
|
||||
fa_to.description AS to_account_description,
|
||||
fi.description AS item_description,
|
||||
contact_from.id AS contact_from_id,
|
||||
contact_from.display_name AS contact_from_name,
|
||||
contact_from.first_name AS contact_from_first_name,
|
||||
contact_from.last_name AS contact_from_last_name,
|
||||
contact_to.id AS contact_to_id,
|
||||
contact_to.display_name AS contact_to_name,
|
||||
contact_to.first_name AS contact_to_first_name,
|
||||
contact_to.last_name AS contact_to_last_name
|
||||
FROM civicrm_entity_batch eb
|
||||
LEFT JOIN civicrm_financial_trxn ft ON (eb.entity_id = ft.id AND eb.entity_table = 'civicrm_financial_trxn')
|
||||
LEFT JOIN civicrm_financial_account fa_from ON fa_from.id = ft.from_financial_account_id
|
||||
LEFT JOIN civicrm_financial_account fa_to ON fa_to.id = ft.to_financial_account_id
|
||||
LEFT JOIN civicrm_option_group cog ON cog.name = 'payment_instrument'
|
||||
LEFT JOIN civicrm_option_value cov ON (cov.value = ft.payment_instrument_id AND cov.option_group_id = cog.id)
|
||||
LEFT JOIN civicrm_contact contact_from ON contact_from.id = fa_from.contact_id
|
||||
LEFT JOIN civicrm_contact contact_to ON contact_to.id = fa_to.contact_id
|
||||
LEFT JOIN civicrm_entity_financial_trxn efti ON (efti.financial_trxn_id = ft.id AND efti.entity_table = 'civicrm_financial_item')
|
||||
LEFT JOIN civicrm_financial_item fi ON fi.id = efti.entity_id
|
||||
WHERE eb.batch_id = ( %1 )";
|
||||
|
||||
$params = array(1 => array($batchId, 'String'));
|
||||
$dao = CRM_Core_DAO::executeQuery($sql, $params);
|
||||
|
||||
return $dao;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $export
|
||||
*/
|
||||
public function makeExport($export) {
|
||||
// Keep running list of accounts and contacts used in this batch, since we need to
|
||||
// include those in the output. Only want to include ones used in the batch, not everything in the db,
|
||||
// since would increase the chance of messing up user's existing Quickbooks entries.
|
||||
foreach ($export as $batchId => $dao) {
|
||||
$accounts = $contacts = $journalEntries = $exportParams = array();
|
||||
$this->_batchIds = $batchId;
|
||||
while ($dao->fetch()) {
|
||||
// add to running list of accounts
|
||||
if (!empty($dao->from_account_id) && !isset($accounts[$dao->from_account_id])) {
|
||||
$accounts[$dao->from_account_id] = array(
|
||||
'name' => $this->format($dao->from_account_name),
|
||||
'account_code' => $this->format($dao->from_account_code),
|
||||
'description' => $this->format($dao->from_account_description),
|
||||
'type' => $this->format($dao->from_account_type_code),
|
||||
);
|
||||
}
|
||||
if (!empty($dao->to_account_id) && !isset($accounts[$dao->to_account_id])) {
|
||||
$accounts[$dao->to_account_id] = array(
|
||||
'name' => $this->format($dao->to_account_name),
|
||||
'account_code' => $this->format($dao->to_account_code),
|
||||
'description' => $this->format($dao->to_account_description),
|
||||
'type' => $this->format($dao->to_account_type_code),
|
||||
);
|
||||
}
|
||||
|
||||
// add to running list of contacts
|
||||
if (!empty($dao->contact_from_id) && !isset($contacts[$dao->contact_from_id])) {
|
||||
$contacts[$dao->contact_from_id] = array(
|
||||
'name' => $this->format($dao->contact_from_name),
|
||||
'first_name' => $this->format($dao->contact_from_first_name),
|
||||
'last_name' => $this->format($dao->contact_from_last_name),
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($dao->contact_to_id) && !isset($contacts[$dao->contact_to_id])) {
|
||||
$contacts[$dao->contact_to_id] = array(
|
||||
'name' => $this->format($dao->contact_to_name),
|
||||
'first_name' => $this->format($dao->contact_to_first_name),
|
||||
'last_name' => $this->format($dao->contact_to_last_name),
|
||||
);
|
||||
}
|
||||
|
||||
// set up the journal entries for this financial trxn
|
||||
$journalEntries[$dao->financial_trxn_id] = array(
|
||||
'to_account' => array(
|
||||
'trxn_date' => $this->format($dao->trxn_date, 'date'),
|
||||
'trxn_id' => $this->format($dao->trxn_id),
|
||||
'account_name' => $this->format($dao->to_account_name),
|
||||
'amount' => $this->format($dao->debit_total_amount, 'money'),
|
||||
'contact_name' => $this->format($dao->contact_to_name),
|
||||
'payment_instrument' => $this->format($dao->payment_instrument),
|
||||
'check_number' => $this->format($dao->check_number),
|
||||
),
|
||||
'splits' => array(),
|
||||
);
|
||||
|
||||
/*
|
||||
* splits has two possibilities depending on FROM account
|
||||
*/
|
||||
if (empty($dao->from_account_id)) {
|
||||
// In this case, split records need to use the individual financial_item account for each item in the trxn
|
||||
$item_sql = "SELECT
|
||||
fa.id AS account_id,
|
||||
fa.name AS account_name,
|
||||
fa.accounting_code AS account_code,
|
||||
fa.description AS account_description,
|
||||
fi.description AS description,
|
||||
fi.id AS financial_item_id,
|
||||
fi.currency AS currency,
|
||||
cov.label AS payment_instrument,
|
||||
ft.check_number AS check_number,
|
||||
fi.transaction_date AS transaction_date,
|
||||
fi.amount AS amount,
|
||||
fa.account_type_code AS account_type_code,
|
||||
contact.id AS contact_id,
|
||||
contact.display_name AS contact_name,
|
||||
contact.first_name AS contact_first_name,
|
||||
contact.last_name AS contact_last_name
|
||||
FROM civicrm_entity_financial_trxn eft
|
||||
LEFT JOIN civicrm_financial_item fi ON eft.entity_id = fi.id
|
||||
LEFT JOIN civicrm_financial_trxn ft ON ft.id = eft.financial_trxn_id
|
||||
LEFT JOIN civicrm_option_group cog ON cog.name = 'payment_instrument'
|
||||
LEFT JOIN civicrm_option_value cov ON (cov.value = ft.payment_instrument_id AND cov.option_group_id = cog.id)
|
||||
LEFT JOIN civicrm_financial_account fa ON fa.id = fi.financial_account_id
|
||||
LEFT JOIN civicrm_contact contact ON contact.id = fi.contact_id
|
||||
WHERE eft.entity_table = 'civicrm_financial_item'
|
||||
AND eft.financial_trxn_id = %1";
|
||||
|
||||
$itemParams = array(1 => array($dao->financial_trxn_id, 'Integer'));
|
||||
|
||||
$itemDAO = CRM_Core_DAO::executeQuery($item_sql, $itemParams);
|
||||
while ($itemDAO->fetch()) {
|
||||
// add to running list of accounts
|
||||
if (!empty($itemDAO->account_id) && !isset($accounts[$itemDAO->account_id])) {
|
||||
$accounts[$itemDAO->account_id] = array(
|
||||
'name' => $this->format($itemDAO->account_name),
|
||||
'account_code' => $this->format($itemDAO->account_code),
|
||||
'description' => $this->format($itemDAO->account_description),
|
||||
'type' => $this->format($itemDAO->account_type_code),
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($itemDAO->contact_id) && !isset($contacts[$itemDAO->contact_id])) {
|
||||
$contacts[$itemDAO->contact_id] = array(
|
||||
'name' => $this->format($itemDAO->contact_name),
|
||||
'first_name' => $this->format($itemDAO->contact_first_name),
|
||||
'last_name' => $this->format($itemDAO->contact_last_name),
|
||||
);
|
||||
}
|
||||
|
||||
// add split line for this item
|
||||
$journalEntries[$dao->financial_trxn_id]['splits'][$itemDAO->financial_item_id] = array(
|
||||
'trxn_date' => $this->format($itemDAO->transaction_date, 'date'),
|
||||
'spl_id' => $this->format($itemDAO->financial_item_id),
|
||||
'account_name' => $this->format($itemDAO->account_name),
|
||||
'amount' => '-' . $this->format($itemDAO->amount, 'money'),
|
||||
'contact_name' => $this->format($itemDAO->contact_name),
|
||||
'payment_instrument' => $this->format($itemDAO->payment_instrument),
|
||||
'description' => $this->format($itemDAO->description),
|
||||
'check_number' => $this->format($itemDAO->check_number),
|
||||
'currency' => $this->format($itemDAO->currency),
|
||||
);
|
||||
} // end items loop
|
||||
$itemDAO->free();
|
||||
}
|
||||
else {
|
||||
// In this case, split record just uses the FROM account from the trxn, and there's only one record here
|
||||
$journalEntries[$dao->financial_trxn_id]['splits'][] = array(
|
||||
'trxn_date' => $this->format($dao->trxn_date, 'date'),
|
||||
'spl_id' => $this->format($dao->financial_trxn_id),
|
||||
'account_name' => $this->format($dao->from_account_name),
|
||||
'amount' => '-' . $this->format($dao->debit_total_amount, 'money'),
|
||||
'contact_name' => $this->format($dao->contact_from_name),
|
||||
'description' => $this->format($dao->item_description),
|
||||
'payment_instrument' => $this->format($dao->payment_instrument),
|
||||
'check_number' => $this->format($dao->check_number),
|
||||
'currency' => $this->format($dao->currency),
|
||||
);
|
||||
}
|
||||
}
|
||||
$exportParams = array(
|
||||
'accounts' => $accounts,
|
||||
'contacts' => $contacts,
|
||||
'journalEntries' => $journalEntries,
|
||||
);
|
||||
self::export($exportParams);
|
||||
}
|
||||
parent::initiateDownload();
|
||||
}
|
||||
|
||||
public function exportACCNT() {
|
||||
self::assign('accounts', $this->_exportParams['accounts']);
|
||||
}
|
||||
|
||||
public function exportCUST() {
|
||||
self::assign('contacts', $this->_exportParams['contacts']);
|
||||
}
|
||||
|
||||
public function exportTRANS() {
|
||||
self::assign('journalEntries', $this->_exportParams['journalEntries']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMimeType() {
|
||||
return 'application/octet-stream';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFileExtension() {
|
||||
return 'iif';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHookedTemplateFileName() {
|
||||
return 'CRM/Financial/ExportFormat/IIF.tpl';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $s
|
||||
* the input string
|
||||
* @param string $type
|
||||
* type can be string, date, or notepad
|
||||
*
|
||||
* @return bool|mixed|string
|
||||
*/
|
||||
public static function format($s, $type = 'string') {
|
||||
// If I remember right there's a couple things:
|
||||
// NOTEPAD field needs to be surrounded by quotes and then get rid of double quotes inside, also newlines should be literal \n, and ditch any ascii 0x0d's.
|
||||
// Date handling has changed over the years. It used to only understand mm/dd/yy but I think now it might depend on your OS settings. Sometimes mm/dd/yyyy works but sometimes it wants yyyy/mm/dd, at least where I had used it.
|
||||
// In all cases need to do something with tabs in the input.
|
||||
|
||||
$s1 = str_replace(self::$SEPARATOR, '\t', $s);
|
||||
switch ($type) {
|
||||
case 'date':
|
||||
$dateFormat = Civi::settings()->get('dateformatFinancialBatch');
|
||||
$sout = CRM_Utils_Date::customFormat($s1, $dateFormat);
|
||||
break;
|
||||
|
||||
case 'money':
|
||||
$sout = CRM_Utils_Money::format($s, NULL, NULL, TRUE);
|
||||
break;
|
||||
|
||||
case 'string':
|
||||
case 'notepad':
|
||||
$s2 = str_replace("\n", '\n', $s1);
|
||||
$s3 = str_replace("\r", '', $s2);
|
||||
$s4 = str_replace('"', "'", $s3);
|
||||
if ($type == 'notepad') {
|
||||
$sout = '"' . $s4 . '"';
|
||||
}
|
||||
else {
|
||||
$sout = $s4;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $sout;
|
||||
}
|
||||
|
||||
}
|
480
sites/all/modules/civicrm/CRM/Financial/BAO/FinancialAccount.php
Normal file
480
sites/all/modules/civicrm/CRM/Financial/BAO/FinancialAccount.php
Normal file
|
@ -0,0 +1,480 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Financial_BAO_FinancialAccount extends CRM_Financial_DAO_FinancialAccount {
|
||||
|
||||
/**
|
||||
* Static holder for the default LT.
|
||||
*/
|
||||
static $_defaultContributionType = NULL;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch object based on array of properties.
|
||||
*
|
||||
* @param array $params
|
||||
* (reference ) an assoc array of name/value pairs.
|
||||
* @param array $defaults
|
||||
* (reference ) an assoc array to hold the flattened values.
|
||||
*
|
||||
* @return CRM_Financial_BAO_FinancialAccount
|
||||
*/
|
||||
public static function retrieve(&$params, &$defaults) {
|
||||
$financialAccount = new CRM_Financial_DAO_FinancialAccount();
|
||||
$financialAccount->copyValues($params);
|
||||
if ($financialAccount->find(TRUE)) {
|
||||
CRM_Core_DAO::storeValues($financialAccount, $defaults);
|
||||
return $financialAccount;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the is_active flag in the db.
|
||||
*
|
||||
* @param int $id
|
||||
* Id of the database record.
|
||||
* @param bool $is_active
|
||||
* Value we want to set the is_active field.
|
||||
*
|
||||
* @return CRM_Core_DAO|null
|
||||
* DAO object on success, null otherwise
|
||||
*/
|
||||
public static function setIsActive($id, $is_active) {
|
||||
return CRM_Core_DAO::setFieldValue('CRM_Financial_DAO_FinancialAccount', $id, 'is_active', $is_active);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the financial types.
|
||||
*
|
||||
* @param array $params
|
||||
* Reference array contains the values submitted by the form.
|
||||
*
|
||||
* @return CRM_Financial_DAO_FinancialAccount
|
||||
*/
|
||||
public static function add(&$params) {
|
||||
if (empty($params['id'])) {
|
||||
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
|
||||
$params['is_deductible'] = CRM_Utils_Array::value('is_deductible', $params, FALSE);
|
||||
$params['is_tax'] = CRM_Utils_Array::value('is_tax', $params, FALSE);
|
||||
$params['is_header_account'] = CRM_Utils_Array::value('is_header_account', $params, FALSE);
|
||||
$params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
|
||||
}
|
||||
if (!empty($params['id'])
|
||||
&& !empty($params['financial_account_type_id'])
|
||||
&& CRM_Financial_BAO_FinancialAccount::validateFinancialAccount(
|
||||
$params['id'],
|
||||
$params['financial_account_type_id']
|
||||
)
|
||||
) {
|
||||
throw new CRM_Core_Exception(ts('You cannot change the account type since this financial account refers to a financial item having an account type of Revenue/Liability.'));
|
||||
}
|
||||
if (!empty($params['is_default'])) {
|
||||
$query = 'UPDATE civicrm_financial_account SET is_default = 0 WHERE financial_account_type_id = %1';
|
||||
$queryParams = array(1 => array($params['financial_account_type_id'], 'Integer'));
|
||||
CRM_Core_DAO::executeQuery($query, $queryParams);
|
||||
}
|
||||
|
||||
// action is taken depending upon the mode
|
||||
$financialAccount = new CRM_Financial_DAO_FinancialAccount();
|
||||
|
||||
// invoke pre hook
|
||||
$op = 'create';
|
||||
if (!empty($params['id'])) {
|
||||
$op = 'edit';
|
||||
}
|
||||
CRM_Utils_Hook::pre($op, 'FinancialAccount', CRM_Utils_Array::value('id', $params), $params);
|
||||
|
||||
if (!empty($params['id'])) {
|
||||
$financialAccount->id = $params['id'];
|
||||
$financialAccount->find(TRUE);
|
||||
}
|
||||
|
||||
$financialAccount->copyValues($params);
|
||||
$financialAccount->save();
|
||||
|
||||
// invoke post hook
|
||||
$op = 'create';
|
||||
if (!empty($params['id'])) {
|
||||
$op = 'edit';
|
||||
}
|
||||
CRM_Utils_Hook::post($op, 'FinancialAccount', $financialAccount->id, $financialAccount);
|
||||
|
||||
return $financialAccount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete financial Types.
|
||||
*
|
||||
* @param int $financialAccountId
|
||||
*/
|
||||
public static function del($financialAccountId) {
|
||||
// checking if financial type is present
|
||||
$check = FALSE;
|
||||
|
||||
//check dependencies
|
||||
$dependency = array(
|
||||
array('Core', 'FinancialTrxn', 'to_financial_account_id'),
|
||||
array('Financial', 'FinancialTypeAccount', 'financial_account_id'),
|
||||
array('Financial', 'FinancialItem', 'financial_account_id'),
|
||||
);
|
||||
foreach ($dependency as $name) {
|
||||
require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_" . $name[0] . "_BAO_" . $name[1]) . ".php";
|
||||
$className = "CRM_{$name[0]}_BAO_{$name[1]}";
|
||||
$bao = new $className();
|
||||
$bao->{$name[2]} = $financialAccountId;
|
||||
if ($bao->find(TRUE)) {
|
||||
$check = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if ($check) {
|
||||
CRM_Core_Session::setStatus(ts('This financial account cannot be deleted since it is being used as a header account. Please remove it from being a header account before trying to delete it again.'));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// delete from financial Type table
|
||||
$financialAccount = new CRM_Financial_DAO_FinancialAccount();
|
||||
$financialAccount->id = $financialAccountId;
|
||||
$financialAccount->delete();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get accounting code for a financial type with account relation Income Account is.
|
||||
*
|
||||
* @param int $financialTypeId
|
||||
*
|
||||
* @return int
|
||||
* accounting code
|
||||
*/
|
||||
public static function getAccountingCode($financialTypeId) {
|
||||
$relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' "));
|
||||
$query = "SELECT cfa.accounting_code
|
||||
FROM civicrm_financial_type cft
|
||||
LEFT JOIN civicrm_entity_financial_account cefa ON cefa.entity_id = cft.id AND cefa.entity_table = 'civicrm_financial_type'
|
||||
LEFT JOIN civicrm_financial_account cfa ON cefa.financial_account_id = cfa.id
|
||||
WHERE cft.id = %1
|
||||
AND account_relationship = %2";
|
||||
$params = array(
|
||||
1 => array($financialTypeId, 'Integer'),
|
||||
2 => array($relationTypeId, 'Integer'),
|
||||
);
|
||||
return CRM_Core_DAO::singleValueQuery($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get AR account.
|
||||
*
|
||||
* @param $financialAccountId
|
||||
* Financial account id.
|
||||
*
|
||||
* @param $financialAccountTypeId
|
||||
* Financial account type id.
|
||||
*
|
||||
* @param string $accountTypeCode
|
||||
* account type code
|
||||
*
|
||||
* @return int
|
||||
* count
|
||||
*/
|
||||
public static function getARAccounts($financialAccountId, $financialAccountTypeId = NULL, $accountTypeCode = 'ar') {
|
||||
if (!$financialAccountTypeId) {
|
||||
$financialAccountTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name LIKE 'Asset' "));
|
||||
}
|
||||
$query = "SELECT count(id) FROM civicrm_financial_account WHERE financial_account_type_id = %1 AND LCASE(account_type_code) = %2
|
||||
AND id != %3 AND is_active = 1;";
|
||||
$params = array(
|
||||
1 => array($financialAccountTypeId, 'Integer'),
|
||||
2 => array(strtolower($accountTypeCode), 'String'),
|
||||
3 => array($financialAccountId, 'Integer'),
|
||||
);
|
||||
return CRM_Core_DAO::singleValueQuery($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Financial Account for a Financial Type Relationship Combo.
|
||||
*
|
||||
* Note that some relationships are optionally configured - so far
|
||||
* Chargeback and Credit / Contra. Since these are the only 2 currently Income
|
||||
* is an appropriate fallback. In future it might make sense to extend the logic.
|
||||
*
|
||||
* Note that we avoid the CRM_Core_PseudoConstant function as it stores one
|
||||
* account per financial type and is unreliable.
|
||||
*
|
||||
* @param int $financialTypeID
|
||||
*
|
||||
* @param string $relationshipType
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getFinancialAccountForFinancialTypeByRelationship($financialTypeID, $relationshipType) {
|
||||
$relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE '{$relationshipType}' "));
|
||||
|
||||
if (!isset(Civi::$statics[__CLASS__]['entity_financial_account'][$financialTypeID][$relationTypeId])) {
|
||||
$accounts = civicrm_api3('EntityFinancialAccount', 'get', array(
|
||||
'entity_id' => $financialTypeID,
|
||||
'entity_table' => 'civicrm_financial_type',
|
||||
));
|
||||
|
||||
foreach ($accounts['values'] as $account) {
|
||||
Civi::$statics[__CLASS__]['entity_financial_account'][$financialTypeID][$account['account_relationship']] = $account['financial_account_id'];
|
||||
}
|
||||
|
||||
$accountRelationships = CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL);
|
||||
|
||||
$incomeAccountRelationshipID = array_search('Income Account is', $accountRelationships);
|
||||
$incomeAccountFinancialAccountID = Civi::$statics[__CLASS__]['entity_financial_account'][$financialTypeID][$incomeAccountRelationshipID];
|
||||
|
||||
foreach (array('Chargeback Account is', 'Credit/Contra Revenue Account is') as $optionalAccountRelationship) {
|
||||
|
||||
$accountRelationshipID = array_search($optionalAccountRelationship, $accountRelationships);
|
||||
if (empty(Civi::$statics[__CLASS__]['entity_financial_account'][$financialTypeID][$accountRelationshipID])) {
|
||||
Civi::$statics[__CLASS__]['entity_financial_account'][$financialTypeID][$accountRelationshipID] = $incomeAccountFinancialAccountID;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['entity_financial_account'][$financialTypeID][$relationTypeId];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Financial Account type relations.
|
||||
*
|
||||
* @param $flip bool
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public static function getfinancialAccountRelations($flip = FALSE) {
|
||||
$params = array('labelColumn' => 'name');
|
||||
$financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id', $params);
|
||||
$accountRelationships = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', $params);
|
||||
$Links = array(
|
||||
'Expense Account is' => 'Expenses',
|
||||
'Accounts Receivable Account is' => 'Asset',
|
||||
'Income Account is' => 'Revenue',
|
||||
'Asset Account is' => 'Asset',
|
||||
'Cost of Sales Account is' => 'Cost of Sales',
|
||||
'Premiums Inventory Account is' => 'Asset',
|
||||
'Discounts Account is' => 'Revenue',
|
||||
'Sales Tax Account is' => 'Liability',
|
||||
'Deferred Revenue Account is' => 'Liability',
|
||||
);
|
||||
if (!$flip) {
|
||||
foreach ($Links as $accountRelation => $accountType) {
|
||||
$financialAccountLinks[array_search($accountRelation, $accountRelationships)] = array_search($accountType, $financialAccountType);
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreach ($Links as $accountRelation => $accountType) {
|
||||
$financialAccountLinks[array_search($accountType, $financialAccountType)][] = array_search($accountRelation, $accountRelationships);
|
||||
}
|
||||
}
|
||||
return $financialAccountLinks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Deferred Financial type.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public static function getDeferredFinancialType() {
|
||||
$deferredFinancialType = array();
|
||||
$query = "SELECT ce.entity_id, cft.name FROM civicrm_entity_financial_account ce
|
||||
INNER JOIN civicrm_financial_type cft ON ce.entity_id = cft.id
|
||||
WHERE ce.entity_table = 'civicrm_financial_type' AND ce.account_relationship = %1 AND cft.is_active = 1";
|
||||
$deferredAccountRel = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Deferred Revenue Account is' "));
|
||||
$queryParams = array(1 => array($deferredAccountRel, 'Integer'));
|
||||
$dao = CRM_Core_DAO::executeQuery($query, $queryParams);
|
||||
while ($dao->fetch()) {
|
||||
$deferredFinancialType[$dao->entity_id] = $dao->name;
|
||||
}
|
||||
return $deferredFinancialType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if financial account is referenced by financial item.
|
||||
*
|
||||
* @param int $financialAccountId
|
||||
*
|
||||
* @param int $financialAccountTypeID
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
*/
|
||||
public static function validateFinancialAccount($financialAccountId, $financialAccountTypeID = NULL) {
|
||||
$sql = "SELECT f.financial_account_type_id FROM civicrm_financial_account f
|
||||
INNER JOIN civicrm_financial_item fi ON fi.financial_account_id = f.id
|
||||
WHERE f.id = %1 AND f.financial_account_type_id IN (%2)
|
||||
LIMIT 1";
|
||||
$params = array('labelColumn' => 'name');
|
||||
$financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id', $params);
|
||||
$params = array(
|
||||
1 => array($financialAccountId, 'Integer'),
|
||||
2 => array(
|
||||
implode(',',
|
||||
array(
|
||||
array_search('Revenue', $financialAccountType),
|
||||
array_search('Liability', $financialAccountType),
|
||||
)
|
||||
),
|
||||
'Text',
|
||||
),
|
||||
);
|
||||
$result = CRM_Core_DAO::singleValueQuery($sql, $params);
|
||||
if ($result && $result != $financialAccountTypeID) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Financial Type has Deferred Revenue account relationship
|
||||
* with Financial Account.
|
||||
*
|
||||
* @param array $params
|
||||
* Holds submitted formvalues and params from api for updating/adding contribution.
|
||||
*
|
||||
* @param int $contributionID
|
||||
* Contribution ID
|
||||
*
|
||||
* @param array $priceSetFields
|
||||
* Array of price fields of a price set.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
*/
|
||||
public static function checkFinancialTypeHasDeferred($params, $contributionID = NULL, $priceSetFields = NULL) {
|
||||
if (!CRM_Contribute_BAO_Contribution::checkContributeSettings('deferred_revenue_enabled')) {
|
||||
return FALSE;
|
||||
}
|
||||
$recognitionDate = CRM_Utils_Array::value('revenue_recognition_date', $params);
|
||||
if (!(!CRM_Utils_System::isNull($recognitionDate)
|
||||
|| ($contributionID && isset($params['prevContribution'])
|
||||
&& !CRM_Utils_System::isNull($params['prevContribution']->revenue_recognition_date)))
|
||||
) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$lineItems = CRM_Utils_Array::value('line_item', $params);
|
||||
$financialTypeID = CRM_Utils_Array::value('financial_type_id', $params);
|
||||
if (!$financialTypeID) {
|
||||
$financialTypeID = $params['prevContribution']->financial_type_id;
|
||||
}
|
||||
if (($contributionID || !empty($params['price_set_id'])) && empty($lineItems)) {
|
||||
if (!$contributionID) {
|
||||
CRM_Price_BAO_PriceSet::processAmount($priceSetFields,
|
||||
$params, $items);
|
||||
}
|
||||
else {
|
||||
$items = CRM_Price_BAO_LineItem::getLineItems($contributionID, 'contribution', TRUE, TRUE, TRUE);
|
||||
}
|
||||
if (!empty($items)) {
|
||||
$lineItems[] = $items;
|
||||
}
|
||||
}
|
||||
$deferredFinancialType = self::getDeferredFinancialType();
|
||||
$isError = FALSE;
|
||||
if (!empty($lineItems)) {
|
||||
foreach ($lineItems as $lineItem) {
|
||||
foreach ($lineItem as $items) {
|
||||
if (!array_key_exists($items['financial_type_id'], $deferredFinancialType)) {
|
||||
$isError = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (!array_key_exists($financialTypeID, $deferredFinancialType)) {
|
||||
$isError = TRUE;
|
||||
}
|
||||
|
||||
if ($isError) {
|
||||
$error = ts('Revenue Recognition Date cannot be processed unless there is a Deferred Revenue account setup for the Financial Type. Please remove Revenue Recognition Date, select a different Financial Type with a Deferred Revenue account setup for it, or setup a Deferred Revenue account for this Financial Type.');
|
||||
throw new CRM_Core_Exception($error);
|
||||
}
|
||||
return $isError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all Deferred Financial Accounts.
|
||||
*
|
||||
*
|
||||
* @return array of Deferred Financial Account
|
||||
*
|
||||
*/
|
||||
public static function getAllDeferredFinancialAccount() {
|
||||
$financialAccount = array();
|
||||
$result = civicrm_api3('EntityFinancialAccount', 'get', array(
|
||||
'sequential' => 1,
|
||||
'return' => array("financial_account_id.id", "financial_account_id.name", "financial_account_id.accounting_code"),
|
||||
'entity_table' => "civicrm_financial_type",
|
||||
'account_relationship' => "Deferred Revenue Account is",
|
||||
));
|
||||
if ($result['count'] > 0) {
|
||||
foreach ($result['values'] as $key => $value) {
|
||||
$financialAccount[$value['financial_account_id.id']] = $value['financial_account_id.name'] . ' (' . $value['financial_account_id.accounting_code'] . ')';
|
||||
}
|
||||
}
|
||||
return $financialAccount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Organization Name associated with Financial Account.
|
||||
*
|
||||
* @param bool $checkPermissions
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public static function getOrganizationNames($checkPermissions = TRUE) {
|
||||
$result = civicrm_api3('FinancialAccount', 'get', array(
|
||||
'return' => array("contact_id.organization_name", "contact_id"),
|
||||
'contact_id.is_deleted' => 0,
|
||||
'options' => array('limit' => 0),
|
||||
'check_permissions' => $checkPermissions,
|
||||
));
|
||||
$organizationNames = array();
|
||||
foreach ($result['values'] as $values) {
|
||||
$organizationNames[$values['contact_id']] = $values['contact_id.organization_name'];
|
||||
}
|
||||
return $organizationNames;
|
||||
}
|
||||
|
||||
}
|
304
sites/all/modules/civicrm/CRM/Financial/BAO/FinancialItem.php
Normal file
304
sites/all/modules/civicrm/CRM/Financial/BAO/FinancialItem.php
Normal file
|
@ -0,0 +1,304 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Financial_BAO_FinancialItem extends CRM_Financial_DAO_FinancialItem {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch object based on array of properties.
|
||||
*
|
||||
* @param array $params
|
||||
* (reference ) an assoc array of name/value pairs.
|
||||
* @param array $defaults
|
||||
* (reference ) an assoc array to hold the flattened values.
|
||||
*
|
||||
* @return CRM_Contribute_BAO_FinancialItem
|
||||
*/
|
||||
public static function retrieve(&$params, &$defaults) {
|
||||
$financialItem = new CRM_Financial_DAO_FinancialItem();
|
||||
$financialItem->copyValues($params);
|
||||
if ($financialItem->find(TRUE)) {
|
||||
CRM_Core_DAO::storeValues($financialItem, $defaults);
|
||||
return $financialItem;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the financial items and financial trxn.
|
||||
*
|
||||
* @param object $lineItem
|
||||
* Line item object.
|
||||
* @param object $contribution
|
||||
* Contribution object.
|
||||
* @param bool $taxTrxnID
|
||||
*
|
||||
* @param int $trxnId
|
||||
*
|
||||
* @return CRM_Financial_DAO_FinancialItem
|
||||
*/
|
||||
public static function add($lineItem, $contribution, $taxTrxnID = FALSE, $trxnId = NULL) {
|
||||
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
|
||||
$financialItemStatus = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialItem', 'status_id');
|
||||
$itemStatus = NULL;
|
||||
if ($contribution->contribution_status_id == array_search('Completed', $contributionStatuses)
|
||||
|| $contribution->contribution_status_id == array_search('Pending refund', $contributionStatuses)
|
||||
) {
|
||||
$itemStatus = array_search('Paid', $financialItemStatus);
|
||||
}
|
||||
elseif ($contribution->contribution_status_id == array_search('Pending', $contributionStatuses)
|
||||
|| $contribution->contribution_status_id == array_search('In Progress', $contributionStatuses)
|
||||
) {
|
||||
$itemStatus = array_search('Unpaid', $financialItemStatus);
|
||||
}
|
||||
elseif ($contribution->contribution_status_id == array_search('Partially paid', $contributionStatuses)) {
|
||||
$itemStatus = array_search('Partially paid', $financialItemStatus);
|
||||
}
|
||||
$params = array(
|
||||
'transaction_date' => CRM_Utils_Date::isoToMysql($contribution->receive_date),
|
||||
'contact_id' => $contribution->contact_id,
|
||||
'amount' => $lineItem->line_total,
|
||||
'currency' => $contribution->currency,
|
||||
'entity_table' => 'civicrm_line_item',
|
||||
'entity_id' => $lineItem->id,
|
||||
'description' => ($lineItem->qty != 1 ? $lineItem->qty . ' of ' : '') . $lineItem->label,
|
||||
'status_id' => $itemStatus,
|
||||
);
|
||||
|
||||
if ($taxTrxnID) {
|
||||
$invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
|
||||
$taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
|
||||
$params['amount'] = $lineItem->tax_amount;
|
||||
$params['description'] = $taxTerm;
|
||||
$accountRelName = 'Sales Tax Account is';
|
||||
}
|
||||
else {
|
||||
$accountRelName = 'Income Account is';
|
||||
if (property_exists($contribution, 'revenue_recognition_date') && !CRM_Utils_System::isNull($contribution->revenue_recognition_date)) {
|
||||
$accountRelName = 'Deferred Revenue Account is';
|
||||
}
|
||||
}
|
||||
if ($lineItem->financial_type_id) {
|
||||
$params['financial_account_id'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount(
|
||||
$lineItem->financial_type_id,
|
||||
$accountRelName
|
||||
);
|
||||
}
|
||||
if (empty($trxnId)) {
|
||||
$trxnId['id'] = CRM_Contribute_BAO_Contribution::$_trxnIDs;
|
||||
if (empty($trxnId['id'])) {
|
||||
$trxn = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution->id, 'ASC', TRUE);
|
||||
$trxnId['id'] = $trxn['financialTrxnId'];
|
||||
}
|
||||
}
|
||||
$financialItem = self::create($params, NULL, $trxnId);
|
||||
return $financialItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the financial Items and financial entity trxn.
|
||||
*
|
||||
* @param array $params
|
||||
* Associated array to create financial items.
|
||||
* @param array $ids
|
||||
* Financial item ids.
|
||||
* @param array $trxnIds
|
||||
* Financial item ids.
|
||||
*
|
||||
* @return CRM_Financial_DAO_FinancialItem
|
||||
*/
|
||||
public static function create(&$params, $ids = NULL, $trxnIds = NULL) {
|
||||
$financialItem = new CRM_Financial_DAO_FinancialItem();
|
||||
|
||||
if (!empty($ids['id'])) {
|
||||
CRM_Utils_Hook::pre('edit', 'FinancialItem', $ids['id'], $params);
|
||||
}
|
||||
else {
|
||||
CRM_Utils_Hook::pre('create', 'FinancialItem', NULL, $params);
|
||||
}
|
||||
|
||||
$financialItem->copyValues($params);
|
||||
if (!empty($ids['id'])) {
|
||||
$financialItem->id = $ids['id'];
|
||||
}
|
||||
|
||||
$financialItem->save();
|
||||
$financialtrxnIDS = CRM_Utils_Array::value('id', $trxnIds);
|
||||
if (!empty($financialtrxnIDS)) {
|
||||
if (!is_array($financialtrxnIDS)) {
|
||||
$financialtrxnIDS = array($financialtrxnIDS);
|
||||
}
|
||||
foreach ($financialtrxnIDS as $tID) {
|
||||
$entity_financial_trxn_params = array(
|
||||
'entity_table' => "civicrm_financial_item",
|
||||
'entity_id' => $financialItem->id,
|
||||
'financial_trxn_id' => $tID,
|
||||
'amount' => $params['amount'],
|
||||
);
|
||||
if (!empty($ids['entityFinancialTrxnId'])) {
|
||||
$entity_financial_trxn_params['id'] = $ids['entityFinancialTrxnId'];
|
||||
}
|
||||
self::createEntityTrxn($entity_financial_trxn_params);
|
||||
}
|
||||
}
|
||||
if (!empty($ids['id'])) {
|
||||
CRM_Utils_Hook::post('edit', 'FinancialItem', $financialItem->id, $financialItem);
|
||||
}
|
||||
else {
|
||||
CRM_Utils_Hook::post('create', 'FinancialItem', $financialItem->id, $financialItem);
|
||||
}
|
||||
return $financialItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes an associative array and creates a entity financial transaction object.
|
||||
*
|
||||
* @param array $params
|
||||
* (reference ) an assoc array of name/value pairs.
|
||||
*
|
||||
* @return CRM_Core_BAO_FinancialTrxn
|
||||
*/
|
||||
public static function createEntityTrxn($params) {
|
||||
$entity_trxn = new CRM_Financial_DAO_EntityFinancialTrxn();
|
||||
$entity_trxn->copyValues($params);
|
||||
$entity_trxn->save();
|
||||
return $entity_trxn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrive entity financial trxn details.
|
||||
*
|
||||
* @param array $params
|
||||
* (reference ) an assoc array of name/value pairs.
|
||||
* @param bool $maxId
|
||||
* To retrive max id.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function retrieveEntityFinancialTrxn($params, $maxId = FALSE) {
|
||||
$financialItem = new CRM_Financial_DAO_EntityFinancialTrxn();
|
||||
$financialItem->copyValues($params);
|
||||
// retrieve last entry from civicrm_entity_financial_trxn
|
||||
if ($maxId) {
|
||||
$financialItem->orderBy('id DESC');
|
||||
$financialItem->limit(1);
|
||||
}
|
||||
$financialItem->find();
|
||||
while ($financialItem->fetch()) {
|
||||
$financialItems[$financialItem->id] = array(
|
||||
'id' => $financialItem->id,
|
||||
'entity_table' => $financialItem->entity_table,
|
||||
'entity_id' => $financialItem->entity_id,
|
||||
'financial_trxn_id' => $financialItem->financial_trxn_id,
|
||||
'amount' => $financialItem->amount,
|
||||
);
|
||||
}
|
||||
if (!empty($financialItems)) {
|
||||
return $financialItems;
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if contact is present in financial_item table.
|
||||
*
|
||||
* CRM-12929
|
||||
*
|
||||
* @param array $contactIds
|
||||
* An array contact id's.
|
||||
*
|
||||
* @param array $error
|
||||
* Error to display.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function checkContactPresent($contactIds, &$error) {
|
||||
if (empty($contactIds)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$allowPermDelete = Civi::settings()->get('allowPermDeleteFinancial');
|
||||
|
||||
if (!$allowPermDelete) {
|
||||
$sql = 'SELECT DISTINCT(cc.id), cc.display_name FROM civicrm_contact cc
|
||||
INNER JOIN civicrm_contribution con ON con.contact_id = cc.id
|
||||
WHERE cc.id IN (' . implode(',', $contactIds) . ') AND con.is_test = 0';
|
||||
$dao = CRM_Core_DAO::executeQuery($sql);
|
||||
if ($dao->N) {
|
||||
while ($dao->fetch()) {
|
||||
$url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid=$dao->id");
|
||||
$not_deleted[$dao->id] = "<a href='$url'>$dao->display_name</a>";
|
||||
}
|
||||
|
||||
$errorStatus = '';
|
||||
if (is_array($error)) {
|
||||
$errorStatus = '<ul><li>' . implode('</li><li>', $not_deleted) . '</li></ul>';
|
||||
}
|
||||
|
||||
$error['_qf_default'] = $errorStatus . ts('This contact(s) can not be permanently deleted because the contact record is linked to one or more live financial transactions. Deleting this contact would result in the loss of financial data.');
|
||||
return $error;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get most relevant previous financial item relating to the line item.
|
||||
*
|
||||
* This function specifically excludes sales tax.
|
||||
*
|
||||
* @param int $entityId
|
||||
*
|
||||
* @return object CRM_Core_DAO
|
||||
*/
|
||||
public static function getPreviousFinancialItem($entityId) {
|
||||
$params = array(
|
||||
'entity_id' => $entityId,
|
||||
'entity_table' => 'civicrm_line_item',
|
||||
'options' => array('limit' => 1, 'sort' => 'id DESC'),
|
||||
);
|
||||
$salesTaxFinancialAccounts = civicrm_api3('FinancialAccount', 'get', array('is_tax' => 1));
|
||||
if ($salesTaxFinancialAccounts['count']) {
|
||||
$params['financial_account_id'] = array('NOT IN' => array_keys($salesTaxFinancialAccounts['values']));
|
||||
}
|
||||
return civicrm_api3('FinancialItem', 'getsingle', $params);
|
||||
}
|
||||
|
||||
}
|
473
sites/all/modules/civicrm/CRM/Financial/BAO/FinancialType.php
Normal file
473
sites/all/modules/civicrm/CRM/Financial/BAO/FinancialType.php
Normal file
|
@ -0,0 +1,473 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Financial_BAO_FinancialType extends CRM_Financial_DAO_FinancialType {
|
||||
|
||||
/**
|
||||
* Static holder for the default LT.
|
||||
*/
|
||||
static $_defaultContributionType = NULL;
|
||||
/**
|
||||
* Static cache holder of available financial types for this session
|
||||
*/
|
||||
static $_availableFinancialTypes = array();
|
||||
/**
|
||||
* Static cache holder of status of ACL-FT enabled/disabled for this session
|
||||
*/
|
||||
static $_statusACLFt = array();
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch object based on array of properties.
|
||||
*
|
||||
* @param array $params
|
||||
* (reference ) an assoc array of name/value pairs.
|
||||
* @param array $defaults
|
||||
* (reference ) an assoc array to hold the flattened values.
|
||||
*
|
||||
* @return CRM_Contribute_BAO_ContributionType
|
||||
*/
|
||||
public static function retrieve(&$params, &$defaults) {
|
||||
$financialType = new CRM_Financial_DAO_FinancialType();
|
||||
$financialType->copyValues($params);
|
||||
if ($financialType->find(TRUE)) {
|
||||
CRM_Core_DAO::storeValues($financialType, $defaults);
|
||||
return $financialType;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the is_active flag in the db.
|
||||
*
|
||||
* @param int $id
|
||||
* Id of the database record.
|
||||
* @param bool $is_active
|
||||
* Value we want to set the is_active field.
|
||||
*
|
||||
* @return Object
|
||||
* DAO object on success, null otherwise
|
||||
*/
|
||||
public static function setIsActive($id, $is_active) {
|
||||
return CRM_Core_DAO::setFieldValue('CRM_Financial_DAO_FinancialType', $id, 'is_active', $is_active);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the financial types.
|
||||
*
|
||||
* @param array $params
|
||||
* Reference array contains the values submitted by the form.
|
||||
* @param array $ids
|
||||
* Reference array contains the id.
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public static function add(&$params, &$ids = array()) {
|
||||
if (empty($params['id'])) {
|
||||
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
|
||||
$params['is_deductible'] = CRM_Utils_Array::value('is_deductible', $params, FALSE);
|
||||
$params['is_reserved'] = CRM_Utils_Array::value('is_reserved', $params, FALSE);
|
||||
}
|
||||
|
||||
// action is taken depending upon the mode
|
||||
$financialType = new CRM_Financial_DAO_FinancialType();
|
||||
$financialType->copyValues($params);
|
||||
if (!empty($ids['financialType'])) {
|
||||
$financialType->id = CRM_Utils_Array::value('financialType', $ids);
|
||||
if (self::isACLFinancialTypeStatus()) {
|
||||
$prevName = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $financialType->id, 'name');
|
||||
if ($prevName != $params['name']) {
|
||||
CRM_Core_Session::setStatus(ts("Changing the name of a Financial Type will result in losing the current permissions associated with that Financial Type.
|
||||
Before making this change you should likely note the existing permissions at Administer > Users and Permissions > Permissions (Access Control),
|
||||
then clicking the Access Control link for your Content Management System, then noting down the permissions for 'CiviCRM: {financial type name} view', etc.
|
||||
Then after making the change of name, reset the permissions to the way they were."), ts('Warning'), 'warning');
|
||||
}
|
||||
}
|
||||
}
|
||||
$financialType->save();
|
||||
// CRM-12470
|
||||
if (empty($ids['financialType']) && empty($params['id'])) {
|
||||
$titles = CRM_Financial_BAO_FinancialTypeAccount::createDefaultFinancialAccounts($financialType);
|
||||
$financialType->titles = $titles;
|
||||
}
|
||||
return $financialType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete financial Types.
|
||||
*
|
||||
* @param int $financialTypeId
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
public static function del($financialTypeId) {
|
||||
$financialType = new CRM_Financial_DAO_FinancialType();
|
||||
$financialType->id = $financialTypeId;
|
||||
$financialType->find(TRUE);
|
||||
// tables to ingore checks for financial_type_id
|
||||
$ignoreTables = array('CRM_Financial_DAO_EntityFinancialAccount');
|
||||
|
||||
// TODO: if (!$financialType->find(true)) {
|
||||
|
||||
// ensure that we have no objects that have an FK to this financial type id TODO: that cannot be null
|
||||
$occurrences = $financialType->findReferences();
|
||||
if ($occurrences) {
|
||||
$tables = array();
|
||||
foreach ($occurrences as $occurrence) {
|
||||
$className = get_class($occurrence);
|
||||
if (!in_array($className, $tables) && !in_array($className, $ignoreTables)) {
|
||||
$tables[] = $className;
|
||||
}
|
||||
}
|
||||
if (!empty($tables)) {
|
||||
$message = ts('The following tables have an entry for this financial type: %1', array('%1' => implode(', ', $tables)));
|
||||
|
||||
$errors = array();
|
||||
$errors['is_error'] = 1;
|
||||
$errors['error_message'] = $message;
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
|
||||
// delete from financial Type table
|
||||
$financialType->delete();
|
||||
|
||||
$entityFinancialType = new CRM_Financial_DAO_EntityFinancialAccount();
|
||||
$entityFinancialType->entity_id = $financialTypeId;
|
||||
$entityFinancialType->entity_table = 'civicrm_financial_type';
|
||||
$entityFinancialType->delete();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch financial type having relationship as Income Account is.
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
* all financial type with income account is relationship
|
||||
*/
|
||||
public static function getIncomeFinancialType() {
|
||||
// Financial Type
|
||||
$financialType = CRM_Contribute_PseudoConstant::financialType();
|
||||
$revenueFinancialType = array();
|
||||
$relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' "));
|
||||
CRM_Core_PseudoConstant::populate(
|
||||
$revenueFinancialType,
|
||||
'CRM_Financial_DAO_EntityFinancialAccount',
|
||||
$all = TRUE,
|
||||
$retrieve = 'entity_id',
|
||||
$filter = NULL,
|
||||
"account_relationship = $relationTypeId AND entity_table = 'civicrm_financial_type' "
|
||||
);
|
||||
|
||||
foreach ($financialType as $key => $financialTypeName) {
|
||||
if (!in_array($key, $revenueFinancialType)
|
||||
|| (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()
|
||||
&& !CRM_Core_Permission::check('add contributions of type ' . $financialTypeName))
|
||||
) {
|
||||
unset($financialType[$key]);
|
||||
}
|
||||
}
|
||||
return $financialType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add permissions for financial types.
|
||||
*
|
||||
* @param array $permissions
|
||||
* @param array $descriptions
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function permissionedFinancialTypes(&$permissions, $descriptions) {
|
||||
if (!self::isACLFinancialTypeStatus()) {
|
||||
return FALSE;
|
||||
}
|
||||
$financialTypes = CRM_Contribute_PseudoConstant::financialType();
|
||||
$prefix = ts('CiviCRM') . ': ';
|
||||
$actions = array('add', 'view', 'edit', 'delete');
|
||||
foreach ($financialTypes as $id => $type) {
|
||||
foreach ($actions as $action) {
|
||||
if ($descriptions) {
|
||||
$permissions[$action . ' contributions of type ' . $type] = array(
|
||||
$prefix . ts($action . ' contributions of type ') . $type,
|
||||
ts(ucfirst($action) . ' contributions of type ') . $type,
|
||||
);
|
||||
}
|
||||
else {
|
||||
$permissions[$action . ' contributions of type ' . $type] = $prefix . ts($action . ' contributions of type ') . $type;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$descriptions) {
|
||||
$permissions['administer CiviCRM Financial Types'] = $prefix . ts('administer CiviCRM Financial Types');
|
||||
}
|
||||
else {
|
||||
$permissions['administer CiviCRM Financial Types'] = array(
|
||||
$prefix . ts('administer CiviCRM Financial Types'),
|
||||
ts('Administer access to Financial Types'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper aroung getAvailableFinancialTypes to get all including disabled FinancialTypes
|
||||
* @param int|string $action
|
||||
* the type of action, can be add, view, edit, delete
|
||||
* @param bool $resetCache
|
||||
* load values from static cache
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAllAvailableFinancialTypes($action = CRM_Core_Action::VIEW, $resetCache = FALSE) {
|
||||
// Flush pseudoconstant cache
|
||||
CRM_Contribute_PseudoConstant::flush('financialType');
|
||||
$thisIsAUselessVariableButSolvesPHPError = NULL;
|
||||
$financialTypes = self::getAvailableFinancialTypes($thisIsAUselessVariableButSolvesPHPError, $action, $resetCache, TRUE);
|
||||
return $financialTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper aroung getAvailableFinancialTypes to get all FinancialTypes Excluding Disabled ones.
|
||||
* @param int|string $action
|
||||
* the type of action, can be add, view, edit, delete
|
||||
* @param bool $resetCache
|
||||
* load values from static cache
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAllEnabledAvailableFinancialTypes($action = CRM_Core_Action::VIEW, $resetCache = FALSE) {
|
||||
$thisIsAUselessVariableButSolvesPHPError = NULL;
|
||||
$financialTypes = self::getAvailableFinancialTypes($thisIsAUselessVariableButSolvesPHPError, $action, $resetCache);
|
||||
return $financialTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available Financial Types.
|
||||
*
|
||||
* @param array $financialTypes
|
||||
* (reference ) an array of financial types
|
||||
* @param int|string $action
|
||||
* the type of action, can be add, view, edit, delete
|
||||
* @param bool $resetCache
|
||||
* load values from static cache
|
||||
* @param bool $includeDisabled
|
||||
* Whether we should load in disabled FinancialTypes or Not
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAvailableFinancialTypes(&$financialTypes = NULL, $action = CRM_Core_Action::VIEW, $resetCache = FALSE, $includeDisabled = FALSE) {
|
||||
if (empty($financialTypes)) {
|
||||
$financialTypes = CRM_Contribute_PseudoConstant::financialType(NULL, $includeDisabled);
|
||||
}
|
||||
if (!self::isACLFinancialTypeStatus()) {
|
||||
return $financialTypes;
|
||||
}
|
||||
$actions = array(
|
||||
CRM_Core_Action::VIEW => 'view',
|
||||
CRM_Core_Action::UPDATE => 'edit',
|
||||
CRM_Core_Action::ADD => 'add',
|
||||
CRM_Core_Action::DELETE => 'delete',
|
||||
);
|
||||
// check cached value
|
||||
if (CRM_Utils_Array::value($action, self::$_availableFinancialTypes) && !$resetCache) {
|
||||
$financialTypes = self::$_availableFinancialTypes[$action];
|
||||
return self::$_availableFinancialTypes[$action];
|
||||
}
|
||||
foreach ($financialTypes as $finTypeId => $type) {
|
||||
if (!CRM_Core_Permission::check($actions[$action] . ' contributions of type ' . $type)) {
|
||||
unset($financialTypes[$finTypeId]);
|
||||
}
|
||||
}
|
||||
self::$_availableFinancialTypes[$action] = $financialTypes;
|
||||
return $financialTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available Membership Types.
|
||||
*
|
||||
* @param array $membershipTypes
|
||||
* (reference ) an array of membership types
|
||||
* @param int|string $action
|
||||
* the type of action, can be add, view, edit, delete
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAvailableMembershipTypes(&$membershipTypes = NULL, $action = CRM_Core_Action::VIEW) {
|
||||
if (empty($membershipTypes)) {
|
||||
$membershipTypes = CRM_Member_PseudoConstant::membershipType();
|
||||
}
|
||||
if (!self::isACLFinancialTypeStatus()) {
|
||||
return $membershipTypes;
|
||||
}
|
||||
$actions = array(
|
||||
CRM_Core_Action::VIEW => 'view',
|
||||
CRM_Core_Action::UPDATE => 'edit',
|
||||
CRM_Core_Action::ADD => 'add',
|
||||
CRM_Core_Action::DELETE => 'delete',
|
||||
);
|
||||
foreach ($membershipTypes as $memTypeId => $type) {
|
||||
$finTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $memTypeId, 'financial_type_id');
|
||||
$finType = CRM_Contribute_PseudoConstant::financialType($finTypeId);
|
||||
if (!CRM_Core_Permission::check($actions[$action] . ' contributions of type ' . $finType)) {
|
||||
unset($membershipTypes[$memTypeId]);
|
||||
}
|
||||
}
|
||||
return $membershipTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to build a permissioned sql where clause based on available financial types.
|
||||
*
|
||||
* @param array $whereClauses
|
||||
* (reference ) an array of clauses
|
||||
* @param string $component
|
||||
* the type of component
|
||||
* @param string $alias
|
||||
* the alias to use
|
||||
*
|
||||
*/
|
||||
public static function buildPermissionedClause(&$whereClauses, $component = NULL, $alias = NULL) {
|
||||
if (!self::isACLFinancialTypeStatus()) {
|
||||
return FALSE;
|
||||
}
|
||||
if (is_array($whereClauses)) {
|
||||
$types = self::getAllEnabledAvailableFinancialTypes();
|
||||
if (empty($types)) {
|
||||
$whereClauses[] = ' ' . $alias . '.financial_type_id IN (0)';
|
||||
}
|
||||
else {
|
||||
$whereClauses[] = ' ' . $alias . '.financial_type_id IN (' . implode(',', array_keys($types)) . ')';
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($component == 'contribution') {
|
||||
$types = self::getAllEnabledAvailableFinancialTypes();
|
||||
$column = "financial_type_id";
|
||||
}
|
||||
if ($component == 'membership') {
|
||||
self::getAvailableMembershipTypes($types, CRM_Core_Action::VIEW);
|
||||
$column = "membership_type_id";
|
||||
}
|
||||
if (!empty($whereClauses)) {
|
||||
$whereClauses .= ' AND ';
|
||||
}
|
||||
if (empty($types)) {
|
||||
$whereClauses .= " civicrm_{$component}.{$column} IN (0)";
|
||||
return;
|
||||
}
|
||||
$whereClauses .= " civicrm_{$component}.{$column} IN (" . implode(',', array_keys($types)) . ")";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to check if lineitems present in a contribution have permissioned FTs.
|
||||
*
|
||||
* @param int $id
|
||||
* contribution id
|
||||
* @param string $op
|
||||
* the mode of operation, can be add, view, edit, delete
|
||||
* @param bool $force
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function checkPermissionedLineItems($id, $op, $force = TRUE) {
|
||||
if (!self::isACLFinancialTypeStatus()) {
|
||||
return TRUE;
|
||||
}
|
||||
$lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($id);
|
||||
$flag = FALSE;
|
||||
foreach ($lineItems as $items) {
|
||||
if (!CRM_Core_Permission::check($op . ' contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) {
|
||||
if ($force) {
|
||||
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
|
||||
break;
|
||||
}
|
||||
$flag = FALSE;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
$flag = TRUE;
|
||||
}
|
||||
}
|
||||
return $flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the logged in user has permission to edit the given financial type.
|
||||
*
|
||||
* This is called when determining if they can edit things like option values
|
||||
* in price sets. At the moment it is not possible to change an option value from
|
||||
* a type you do not have permission to to a type that you do.
|
||||
*
|
||||
* @todo it is currently not possible to edit disabled types if you have ACLs on.
|
||||
* Do ACLs still apply once disabled? That question should be resolved if tackling
|
||||
* that gap.
|
||||
*
|
||||
* @param int $financialTypeID
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function checkPermissionToEditFinancialType($financialTypeID) {
|
||||
if (!self::isACLFinancialTypeStatus()) {
|
||||
return TRUE;
|
||||
}
|
||||
$financialTypes = CRM_Financial_BAO_FinancialType::getAllAvailableFinancialTypes(CRM_Core_Action::UPDATE);
|
||||
return isset($financialTypes[$financialTypeID]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if FT-ACL is turned on or off.
|
||||
*
|
||||
* @todo rename this function e.g isFinancialTypeACLsEnabled.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isACLFinancialTypeStatus() {
|
||||
if (array_key_exists('acl_financial_type', self::$_statusACLFt)) {
|
||||
return self::$_statusACLFt['acl_financial_type'];
|
||||
}
|
||||
$contributeSettings = Civi::settings()->get('contribution_invoice_settings');
|
||||
self::$_statusACLFt['acl_financial_type'] = FALSE;
|
||||
if (CRM_Utils_Array::value('acl_financial_type', $contributeSettings)) {
|
||||
self::$_statusACLFt['acl_financial_type'] = TRUE;
|
||||
}
|
||||
return self::$_statusACLFt['acl_financial_type'];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,274 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Financial_BAO_FinancialTypeAccount extends CRM_Financial_DAO_EntityFinancialAccount {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch object based on array of properties.
|
||||
*
|
||||
* @param array $params
|
||||
* (reference ) an assoc array of name/value pairs.
|
||||
* @param array $defaults
|
||||
* (reference ) an assoc array to hold the flattened values.
|
||||
*
|
||||
* @param array $allValues
|
||||
*
|
||||
* @return CRM_Contribute_BAO_ContributionType
|
||||
*/
|
||||
public static function retrieve(&$params, &$defaults, &$allValues = array()) {
|
||||
$financialTypeAccount = new CRM_Financial_DAO_EntityFinancialAccount();
|
||||
$financialTypeAccount->copyValues($params);
|
||||
$financialTypeAccount->find();
|
||||
while ($financialTypeAccount->fetch()) {
|
||||
CRM_Core_DAO::storeValues($financialTypeAccount, $defaults);
|
||||
$allValues[] = $defaults;
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the financial types.
|
||||
*
|
||||
* @param array $params
|
||||
* Reference array contains the values submitted by the form.
|
||||
* @param array $ids
|
||||
* Reference array contains the id.
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public static function add(&$params, &$ids = NULL) {
|
||||
// action is taken depending upon the mode
|
||||
$financialTypeAccount = new CRM_Financial_DAO_EntityFinancialAccount();
|
||||
if ($params['entity_table'] != 'civicrm_financial_type') {
|
||||
$financialTypeAccount->entity_id = $params['entity_id'];
|
||||
$financialTypeAccount->entity_table = $params['entity_table'];
|
||||
$financialTypeAccount->find(TRUE);
|
||||
}
|
||||
if (!empty($ids['entityFinancialAccount'])) {
|
||||
$financialTypeAccount->id = $ids['entityFinancialAccount'];
|
||||
$financialTypeAccount->find(TRUE);
|
||||
}
|
||||
$financialTypeAccount->copyValues($params);
|
||||
self::validateRelationship($financialTypeAccount);
|
||||
$financialTypeAccount->save();
|
||||
return $financialTypeAccount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete financial Types.
|
||||
*
|
||||
* @param int $financialTypeAccountId
|
||||
* @param int $accountId
|
||||
*
|
||||
*/
|
||||
public static function del($financialTypeAccountId, $accountId = NULL) {
|
||||
// check if financial type is present
|
||||
$check = FALSE;
|
||||
$relationValues = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship');
|
||||
|
||||
$financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_EntityFinancialAccount', $financialTypeAccountId, 'entity_id');
|
||||
// check dependencies
|
||||
// FIXME more table containing financial_type_id to come
|
||||
$dependency = array(
|
||||
array('Contribute', 'Contribution'),
|
||||
array('Contribute', 'ContributionPage'),
|
||||
array('Member', 'MembershipType'),
|
||||
array('Price', 'PriceFieldValue'),
|
||||
array('Grant', 'Grant'),
|
||||
array('Contribute', 'PremiumsProduct'),
|
||||
array('Contribute', 'Product'),
|
||||
array('Price', 'LineItem'),
|
||||
);
|
||||
|
||||
foreach ($dependency as $name) {
|
||||
$daoString = 'CRM_' . $name[0] . '_DAO_' . $name[1];
|
||||
$dao = new $daoString();
|
||||
$dao->financial_type_id = $financialTypeId;
|
||||
if ($dao->find(TRUE)) {
|
||||
$check = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($check) {
|
||||
if ($name[1] == 'PremiumsProduct' || $name[1] == 'Product') {
|
||||
CRM_Core_Session::setStatus(ts('You cannot remove an account with a %1 relationship while the Financial Type is used for a Premium.', array(1 => $relationValues[$financialTypeAccountId])));
|
||||
}
|
||||
else {
|
||||
$accountRelationShipId = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_EntityFinancialAccount', $financialTypeAccountId, 'account_relationship');
|
||||
CRM_Core_Session::setStatus(ts('You cannot remove an account with a %1 relationship because it is being referenced by one or more of the following types of records: Contributions, Contribution Pages, or Membership Types. Consider disabling this type instead if you no longer want it used.', array(1 => $relationValues[$accountRelationShipId])), NULL, 'error');
|
||||
}
|
||||
return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/financial/financialType/accounts', "reset=1&action=browse&aid={$accountId}"));
|
||||
}
|
||||
|
||||
// delete from financial Type table
|
||||
$financialType = new CRM_Financial_DAO_EntityFinancialAccount();
|
||||
$financialType->id = $financialTypeAccountId;
|
||||
$financialType->find(TRUE);
|
||||
$financialType->delete();
|
||||
CRM_Core_Session::setStatus(ts('Unbalanced transactions may be created if you delete the account of type: %1.', array(1 => $relationValues[$financialType->account_relationship])));
|
||||
}
|
||||
|
||||
/**
|
||||
* Financial Account for payment instrument.
|
||||
*
|
||||
* @param int $paymentInstrumentValue
|
||||
* Payment instrument value.
|
||||
*
|
||||
* @return null|int
|
||||
*/
|
||||
public static function getInstrumentFinancialAccount($paymentInstrumentValue) {
|
||||
$paymentInstrument = civicrm_api3('OptionValue', 'getsingle', array(
|
||||
'return' => array("id"),
|
||||
'value' => $paymentInstrumentValue,
|
||||
'option_group_id' => "payment_instrument",
|
||||
));
|
||||
$financialAccountId = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount(
|
||||
$paymentInstrument['id'],
|
||||
NULL,
|
||||
'civicrm_option_value'
|
||||
);
|
||||
return $financialAccountId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create default entity financial accounts
|
||||
* for financial type
|
||||
* CRM-12470
|
||||
*
|
||||
* @param $financialType
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function createDefaultFinancialAccounts($financialType) {
|
||||
$titles = array();
|
||||
$financialAccountTypeID = CRM_Core_OptionGroup::values('financial_account_type', FALSE, FALSE, FALSE, NULL, 'name');
|
||||
$accountRelationship = CRM_Core_OptionGroup::values('account_relationship', FALSE, FALSE, FALSE, NULL, 'name');
|
||||
|
||||
$relationships = array(
|
||||
array_search('Accounts Receivable Account is', $accountRelationship) => array_search('Asset', $financialAccountTypeID),
|
||||
array_search('Expense Account is', $accountRelationship) => array_search('Expenses', $financialAccountTypeID),
|
||||
array_search('Cost of Sales Account is', $accountRelationship) => array_search('Cost of Sales', $financialAccountTypeID),
|
||||
array_search('Income Account is', $accountRelationship) => array_search('Revenue', $financialAccountTypeID),
|
||||
);
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery('SELECT id, financial_account_type_id FROM civicrm_financial_account WHERE name LIKE %1',
|
||||
array(1 => array($financialType->name, 'String'))
|
||||
);
|
||||
$dao->fetch();
|
||||
$existingFinancialAccount = array();
|
||||
if (!$dao->N) {
|
||||
$params = array(
|
||||
'name' => $financialType->name,
|
||||
'contact_id' => CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Domain', CRM_Core_Config::domainID(), 'contact_id'),
|
||||
'financial_account_type_id' => array_search('Revenue', $financialAccountTypeID),
|
||||
'description' => $financialType->description,
|
||||
'account_type_code' => 'INC',
|
||||
'is_active' => 1,
|
||||
);
|
||||
$financialAccount = CRM_Financial_BAO_FinancialAccount::add($params);
|
||||
}
|
||||
else {
|
||||
$existingFinancialAccount[$dao->financial_account_type_id] = $dao->id;
|
||||
}
|
||||
$params = array(
|
||||
'entity_table' => 'civicrm_financial_type',
|
||||
'entity_id' => $financialType->id,
|
||||
);
|
||||
foreach ($relationships as $key => $value) {
|
||||
if (!array_key_exists($value, $existingFinancialAccount)) {
|
||||
if ($accountRelationship[$key] == 'Accounts Receivable Account is') {
|
||||
$params['financial_account_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', 'Accounts Receivable', 'id', 'name');
|
||||
if (!empty($params['financial_account_id'])) {
|
||||
$titles[] = 'Accounts Receivable';
|
||||
}
|
||||
else {
|
||||
$query = "SELECT financial_account_id, name FROM civicrm_entity_financial_account
|
||||
LEFT JOIN civicrm_financial_account ON civicrm_financial_account.id = civicrm_entity_financial_account.financial_account_id
|
||||
WHERE account_relationship = {$key} AND entity_table = 'civicrm_financial_type' LIMIT 1";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
$dao->fetch();
|
||||
$params['financial_account_id'] = $dao->financial_account_id;
|
||||
$titles[] = $dao->name;
|
||||
}
|
||||
}
|
||||
elseif ($accountRelationship[$key] == 'Income Account is' && empty($existingFinancialAccount)) {
|
||||
$params['financial_account_id'] = $financialAccount->id;
|
||||
}
|
||||
else {
|
||||
$query = "SELECT id, name FROM civicrm_financial_account WHERE is_default = 1 AND financial_account_type_id = {$value}";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
$dao->fetch();
|
||||
$params['financial_account_id'] = $dao->id;
|
||||
$titles[] = $dao->name;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$params['financial_account_id'] = $existingFinancialAccount[$value];
|
||||
$titles[] = $financialType->name;
|
||||
}
|
||||
$params['account_relationship'] = $key;
|
||||
self::add($params);
|
||||
}
|
||||
if (!empty($existingFinancialAccount)) {
|
||||
$titles = array();
|
||||
}
|
||||
return $titles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate account relationship with financial account type
|
||||
*
|
||||
* @param obj $financialTypeAccount of CRM_Financial_DAO_EntityFinancialAccount
|
||||
*
|
||||
* @throws CRM_Core_Exception
|
||||
*/
|
||||
public static function validateRelationship($financialTypeAccount) {
|
||||
$financialAccountLinks = CRM_Financial_BAO_FinancialAccount::getfinancialAccountRelations();
|
||||
$financialAccountType = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', $financialTypeAccount->financial_account_id, 'financial_account_type_id');
|
||||
if (CRM_Utils_Array::value($financialTypeAccount->account_relationship, $financialAccountLinks) != $financialAccountType) {
|
||||
$accountRelationships = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship');
|
||||
$params = array(
|
||||
1 => $accountRelationships[$financialTypeAccount->account_relationship],
|
||||
);
|
||||
throw new CRM_Core_Exception(ts("This financial account cannot have '%1' relationship.", $params));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
552
sites/all/modules/civicrm/CRM/Financial/BAO/PaymentProcessor.php
Normal file
552
sites/all/modules/civicrm/CRM/Financial/BAO/PaymentProcessor.php
Normal file
|
@ -0,0 +1,552 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class contains payment processor related functions.
|
||||
*/
|
||||
class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProcessor {
|
||||
/**
|
||||
* Static holder for the default payment processor
|
||||
*/
|
||||
static $_defaultPaymentProcessor = NULL;
|
||||
|
||||
/**
|
||||
* Create Payment Processor.
|
||||
*
|
||||
* @param array $params
|
||||
* Parameters for Processor entity.
|
||||
*
|
||||
* @return CRM_Financial_DAO_PaymentProcessor
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function create($params) {
|
||||
$processor = new CRM_Financial_DAO_PaymentProcessor();
|
||||
$processor->copyValues($params);
|
||||
|
||||
if (empty($params['id'])) {
|
||||
$ppTypeDAO = new CRM_Financial_DAO_PaymentProcessorType();
|
||||
$ppTypeDAO->id = $params['payment_processor_type_id'];
|
||||
if (!$ppTypeDAO->find(TRUE)) {
|
||||
CRM_Core_Error::fatal(ts('Could not find payment processor meta information'));
|
||||
}
|
||||
|
||||
// also copy meta fields from the info DAO
|
||||
$processor->is_recur = $ppTypeDAO->is_recur;
|
||||
$processor->billing_mode = $ppTypeDAO->billing_mode;
|
||||
$processor->class_name = $ppTypeDAO->class_name;
|
||||
$processor->payment_type = $ppTypeDAO->payment_type;
|
||||
}
|
||||
|
||||
$processor->save();
|
||||
// CRM-11826, add entry in civicrm_entity_financial_account
|
||||
// if financial_account_id is not NULL
|
||||
if (!empty($params['financial_account_id'])) {
|
||||
$relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
|
||||
$values = array(
|
||||
'entity_table' => 'civicrm_payment_processor',
|
||||
'entity_id' => $processor->id,
|
||||
'account_relationship' => $relationTypeId,
|
||||
'financial_account_id' => $params['financial_account_id'],
|
||||
);
|
||||
CRM_Financial_BAO_FinancialTypeAccount::add($values);
|
||||
}
|
||||
|
||||
if (isset($params['id']) && isset($params['is_active']) && !isset($params['is_test'])) {
|
||||
// check if is_active has changed & if so update test instance is_active too.
|
||||
$test_id = self::getTestProcessorId($params['id']);
|
||||
$testDAO = new CRM_Financial_DAO_PaymentProcessor();
|
||||
$testDAO->id = $test_id;
|
||||
if ($testDAO->find(TRUE)) {
|
||||
$testDAO->is_active = $params['is_active'];
|
||||
$testDAO->save();
|
||||
}
|
||||
}
|
||||
|
||||
Civi\Payment\System::singleton()->flushProcessors();
|
||||
return $processor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve array of allowed credit cards for this payment processor.
|
||||
* @param interger|null $paymentProcessorID id of processor.
|
||||
* @return array
|
||||
*/
|
||||
public static function getCreditCards($paymentProcessorID = NULL) {
|
||||
if (!empty($paymentProcessorID)) {
|
||||
$processor = new CRM_Financial_DAO_PaymentProcessor();
|
||||
$processor->id = $paymentProcessorID;
|
||||
$processor->find(TRUE);
|
||||
$cards = json_decode($processor->accepted_credit_cards, TRUE);
|
||||
return $cards;
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve DB object based on input parameters.
|
||||
*
|
||||
* It also stores all the retrieved values in the default array.
|
||||
*
|
||||
* @param array $params
|
||||
* (reference ) an assoc array of name/value pairs.
|
||||
* @param array $defaults
|
||||
* (reference ) an assoc array to hold the flattened values.
|
||||
*
|
||||
* @return CRM_Financial_DAO_PaymentProcessor|null
|
||||
* object on success, null otherwise
|
||||
*/
|
||||
public static function retrieve(&$params, &$defaults) {
|
||||
$paymentProcessor = new CRM_Financial_DAO_PaymentProcessor();
|
||||
$paymentProcessor->copyValues($params);
|
||||
if ($paymentProcessor->find(TRUE)) {
|
||||
CRM_Core_DAO::storeValues($paymentProcessor, $defaults);
|
||||
return $paymentProcessor;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the is_active flag in the db.
|
||||
*
|
||||
* @param int $id
|
||||
* Id of the database record.
|
||||
* @param bool $is_active
|
||||
* Value we want to set the is_active field.
|
||||
*
|
||||
* @return CRM_Financial_DAO_PaymentProcessor|null
|
||||
* DAO object on success, null otherwise
|
||||
*
|
||||
*/
|
||||
public static function setIsActive($id, $is_active) {
|
||||
return CRM_Core_DAO::setFieldValue('CRM_Financial_DAO_PaymentProcessor', $id, 'is_active', $is_active);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the default payment processor.
|
||||
*
|
||||
* @return CRM_Financial_DAO_PaymentProcessor|null
|
||||
* The default payment processor object on success,
|
||||
* null otherwise
|
||||
*/
|
||||
public static function &getDefault() {
|
||||
if (self::$_defaultPaymentProcessor == NULL) {
|
||||
$params = array('is_default' => 1);
|
||||
$defaults = array();
|
||||
self::$_defaultPaymentProcessor = self::retrieve($params, $defaults);
|
||||
}
|
||||
return self::$_defaultPaymentProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete payment processor.
|
||||
*
|
||||
* @param int $paymentProcessorID
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public static function del($paymentProcessorID) {
|
||||
if (!$paymentProcessorID) {
|
||||
CRM_Core_Error::fatal(ts('Invalid value passed to delete function.'));
|
||||
}
|
||||
|
||||
$dao = new CRM_Financial_DAO_PaymentProcessor();
|
||||
$dao->id = $paymentProcessorID;
|
||||
if (!$dao->find(TRUE)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$testDAO = new CRM_Financial_DAO_PaymentProcessor();
|
||||
$testDAO->name = $dao->name;
|
||||
$testDAO->is_test = 1;
|
||||
$testDAO->delete();
|
||||
|
||||
$dao->delete();
|
||||
Civi\Payment\System::singleton()->flushProcessors();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the payment processor details.
|
||||
*
|
||||
* This returns an array whereas Civi\Payment\System::singleton->getByID() returns an object.
|
||||
* The object is a key in the array.
|
||||
*
|
||||
* @param int $paymentProcessorID
|
||||
* Payment processor id.
|
||||
* @param string $mode
|
||||
* Payment mode ie test or live.
|
||||
*
|
||||
* @return array
|
||||
* associated array with payment processor related fields
|
||||
*/
|
||||
public static function getPayment($paymentProcessorID, $mode = 'based_on_id') {
|
||||
$capabilities = ($mode == 'test') ? array('TestMode') : array();
|
||||
$processors = self::getPaymentProcessors($capabilities, array($paymentProcessorID));
|
||||
$processor = $processors[$paymentProcessorID];
|
||||
$fields = array(
|
||||
'id',
|
||||
'name',
|
||||
'payment_processor_type_id',
|
||||
'user_name',
|
||||
'password',
|
||||
'signature',
|
||||
'url_site',
|
||||
'url_api',
|
||||
'url_recur',
|
||||
'url_button',
|
||||
'subject',
|
||||
'class_name',
|
||||
'is_recur',
|
||||
'billing_mode',
|
||||
'is_test',
|
||||
'payment_type',
|
||||
'is_default',
|
||||
);
|
||||
// Just to prevent e-Notices elsewhere we set all fields.
|
||||
foreach ($fields as $name) {
|
||||
if (!isset($processor)) {
|
||||
$processor[$name] = NULL;
|
||||
}
|
||||
}
|
||||
$processor['payment_processor_type'] = CRM_Core_PseudoConstant::paymentProcessorType(FALSE,
|
||||
$processor['payment_processor_type_id'], 'name');
|
||||
return $processors[$paymentProcessorID];
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a live processor ID get the test id.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return int
|
||||
* Test payment processor ID.
|
||||
*/
|
||||
public static function getTestProcessorId($id) {
|
||||
$liveProcessorName = civicrm_api3('payment_processor', 'getvalue', array(
|
||||
'id' => $id,
|
||||
'return' => 'name',
|
||||
));
|
||||
return civicrm_api3('payment_processor', 'getvalue', array(
|
||||
'return' => 'id',
|
||||
'name' => $liveProcessorName,
|
||||
'is_test' => 1,
|
||||
'domain_id' => CRM_Core_Config::domainID(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare 2 payment processors to see which should go first based on is_default
|
||||
* (sort function for sortDefaultFirst)
|
||||
* @param array $processor1
|
||||
* @param array $processor2
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function defaultComparison($processor1, $processor2) {
|
||||
$p1 = CRM_Utils_Array::value('is_default', $processor1);
|
||||
$p2 = CRM_Utils_Array::value('is_default', $processor2);
|
||||
if ($p1 == $p2) {
|
||||
return 0;
|
||||
}
|
||||
return ($p1 > $p2) ? -1 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all payment processors as an array of objects.
|
||||
*
|
||||
* @param string|NULL $mode
|
||||
* only return this mode - test|live or NULL for all
|
||||
* @param bool $reset
|
||||
* @param bool $isCurrentDomainOnly
|
||||
* Do we only want to load payment processors associated with the current domain.
|
||||
*
|
||||
* @throws CiviCRM_API3_Exception
|
||||
* @return array
|
||||
*/
|
||||
public static function getAllPaymentProcessors($mode = 'all', $reset = FALSE, $isCurrentDomainOnly = TRUE) {
|
||||
|
||||
$cacheKey = 'CRM_Financial_BAO_Payment_Processor_' . $mode . '_' . CRM_Core_Config::domainID();
|
||||
if (!$reset) {
|
||||
$processors = CRM_Utils_Cache::singleton()->get($cacheKey);
|
||||
if (!empty($processors)) {
|
||||
return $processors;
|
||||
}
|
||||
}
|
||||
|
||||
$retrievalParameters = array(
|
||||
'is_active' => TRUE,
|
||||
'options' => array('sort' => 'is_default DESC, name', 'limit' => 0),
|
||||
'api.payment_processor_type.getsingle' => 1,
|
||||
);
|
||||
if ($isCurrentDomainOnly) {
|
||||
$retrievalParameters['domain_id'] = CRM_Core_Config::domainID();
|
||||
}
|
||||
if ($mode == 'test') {
|
||||
$retrievalParameters['is_test'] = 1;
|
||||
}
|
||||
elseif ($mode == 'live') {
|
||||
$retrievalParameters['is_test'] = 0;
|
||||
}
|
||||
|
||||
$processors = civicrm_api3('payment_processor', 'get', $retrievalParameters);
|
||||
foreach ($processors['values'] as $processor) {
|
||||
$fieldsToProvide = array('user_name', 'password', 'signature', 'subject', 'is_recur');
|
||||
foreach ($fieldsToProvide as $field) {
|
||||
// Prevent e-notices in processor classes when not configured.
|
||||
if (!isset($processor[$field])) {
|
||||
$processors['values'][$processor['id']][$field] = NULL;
|
||||
}
|
||||
}
|
||||
$processors['values'][$processor['id']]['payment_processor_type'] = $processor['payment_processor_type'] = $processors['values'][$processor['id']]['api.payment_processor_type.getsingle']['name'];
|
||||
$processors['values'][$processor['id']]['object'] = Civi\Payment\System::singleton()->getByProcessor($processor);
|
||||
}
|
||||
|
||||
// Add the pay-later pseudo-processor.
|
||||
$processors['values'][0] = array(
|
||||
'object' => new CRM_Core_Payment_Manual(),
|
||||
'id' => 0,
|
||||
'payment_processor_type_id' => 0,
|
||||
// This shouldn't be required but there are still some processors hacked into core with nasty 'if's.
|
||||
'payment_processor_type' => 'Manual',
|
||||
'class_name' => 'Payment_Manual',
|
||||
'name' => 'pay_later',
|
||||
'billing_mode' => '',
|
||||
'is_default' => 0,
|
||||
'payment_instrument_id' => key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1')),
|
||||
// Making this optionally recur would give lots of options -but it should
|
||||
// be a row in the payment processor table before we do that.
|
||||
'is_recur' => FALSE,
|
||||
'is_test' => FALSE,
|
||||
);
|
||||
|
||||
CRM_Utils_Cache::singleton()->set($cacheKey, $processors['values']);
|
||||
|
||||
return $processors['values'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Payment processors with specified capabilities.
|
||||
* Note that both the singleton & the pseudoconstant function have caching so we don't add
|
||||
* arguably this could go on the pseudoconstant class
|
||||
*
|
||||
* @param array $capabilities
|
||||
* capabilities of processor e.g
|
||||
* - BackOffice
|
||||
* - TestMode
|
||||
* - LiveMode
|
||||
* - FutureStartDate
|
||||
*
|
||||
* @param array|bool $ids
|
||||
*
|
||||
* @return array
|
||||
* available processors
|
||||
*/
|
||||
public static function getPaymentProcessors($capabilities = array(), $ids = FALSE) {
|
||||
$testProcessors = in_array('TestMode', $capabilities) ? self::getAllPaymentProcessors('test') : array();
|
||||
if (is_array($ids)) {
|
||||
$processors = self::getAllPaymentProcessors('all', TRUE, FALSE);
|
||||
}
|
||||
else {
|
||||
$processors = self::getAllPaymentProcessors('all', TRUE);
|
||||
}
|
||||
|
||||
if (in_array('TestMode', $capabilities) && is_array($ids)) {
|
||||
$possibleLiveIDs = array_diff($ids, array_keys($testProcessors));
|
||||
foreach ($possibleLiveIDs as $possibleLiveID) {
|
||||
if (isset($processors[$possibleLiveID]) && ($liveProcessorName = $processors[$possibleLiveID]['name']) != FALSE) {
|
||||
foreach ($testProcessors as $index => $testProcessor) {
|
||||
if ($testProcessor['name'] == $liveProcessorName) {
|
||||
$ids[] = $testProcessor['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$processors = $testProcessors;
|
||||
}
|
||||
|
||||
foreach ($processors as $index => $processor) {
|
||||
if (is_array($ids) && !in_array($processor['id'], $ids)) {
|
||||
unset($processors[$index]);
|
||||
continue;
|
||||
}
|
||||
// Invalid processors will store a null value in 'object' (e.g. if not all required config fields are present).
|
||||
// This is determined by calling when loading the processor via the $processorObject->checkConfig() function.
|
||||
if (!is_a($processor['object'], 'CRM_Core_Payment')) {
|
||||
unset($processors[$index]);
|
||||
continue;
|
||||
}
|
||||
foreach ($capabilities as $capability) {
|
||||
if (($processor['object']->supports($capability)) == FALSE) {
|
||||
unset($processors[$index]);
|
||||
continue 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $processors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is there a processor on this site with the specified capability.
|
||||
*
|
||||
* The capabilities are defined on CRM_Core_Payment and can be extended by
|
||||
* processors.
|
||||
*
|
||||
* examples are
|
||||
* - supportsBackOffice
|
||||
* - supportsLiveMode
|
||||
* - supportsFutureRecurDate
|
||||
* - supportsCancelRecurring
|
||||
* - supportsRecurContributionsForPledges
|
||||
*
|
||||
* They are passed as array('BackOffice');
|
||||
*
|
||||
* Details of specific functions are in the docblocks on the CRM_Core_Payment class.
|
||||
*
|
||||
* @param array $capabilities
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasPaymentProcessorSupporting($capabilities = array()) {
|
||||
$result = self::getPaymentProcessors($capabilities);
|
||||
return (!empty($result)) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve payment processor id / info/ object based on component-id.
|
||||
*
|
||||
* @todo function needs revisiting. The whole 'info / obj' thing is an overload. Recommend creating new functions
|
||||
* that are entity specific as there is little shared code specific to obj or info
|
||||
*
|
||||
* Also, it does not accurately derive the processor - for a completed contribution the best place to look is in the
|
||||
* relevant financial_trxn record. For a recurring contribution it is in the contribution_recur table.
|
||||
*
|
||||
* For a membership the relevant contribution_recur should be derived & then resolved as above. The contribution page
|
||||
* is never a reliable place to look as there can be more than one configured. For a pending contribution there is
|
||||
* no way to derive the processor - but hey - what processor? it didn't go through!
|
||||
*
|
||||
* Query for membership might look something like:
|
||||
* SELECT fte.payment_processor_id
|
||||
* FROM civicrm_membership mem
|
||||
* INNER JOIN civicrm_line_item li ON ( mem.id = li.entity_id AND li.entity_table = 'civicrm_membership')
|
||||
* INNER JOIN civicrm_contribution con ON ( li.contribution_id = con.id )
|
||||
* LEFT JOIN civicrm_entity_financial_trxn ft ON ft.entity_id = con.id AND ft.entity_table =
|
||||
* 'civicrm_contribution'
|
||||
* LEFT JOIN civicrm_financial_trxn fte ON fte.id = ft.financial_trxn_id
|
||||
*
|
||||
* @param int $entityID
|
||||
* @param string $component
|
||||
* Component.
|
||||
* @param string $type
|
||||
* Type of payment information to be retrieved.
|
||||
*
|
||||
* @return int|array|object
|
||||
*/
|
||||
public static function getProcessorForEntity($entityID, $component = 'contribute', $type = 'id') {
|
||||
$result = NULL;
|
||||
if (!in_array($component, array(
|
||||
'membership',
|
||||
'contribute',
|
||||
'recur',
|
||||
))
|
||||
) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ($component == 'membership') {
|
||||
$sql = "
|
||||
SELECT cr.payment_processor_id as ppID1, cp.payment_processor as ppID2, con.is_test
|
||||
FROM civicrm_membership mem
|
||||
INNER JOIN civicrm_membership_payment mp ON ( mem.id = mp.membership_id )
|
||||
INNER JOIN civicrm_contribution con ON ( mp.contribution_id = con.id )
|
||||
LEFT JOIN civicrm_contribution_recur cr ON ( mem.contribution_recur_id = cr.id )
|
||||
LEFT JOIN civicrm_contribution_page cp ON ( con.contribution_page_id = cp.id )
|
||||
WHERE mp.membership_id = %1";
|
||||
}
|
||||
elseif ($component == 'contribute') {
|
||||
$sql = "
|
||||
SELECT cr.payment_processor_id as ppID1, cp.payment_processor as ppID2, con.is_test
|
||||
FROM civicrm_contribution con
|
||||
LEFT JOIN civicrm_contribution_recur cr ON ( con.contribution_recur_id = cr.id )
|
||||
LEFT JOIN civicrm_contribution_page cp ON ( con.contribution_page_id = cp.id )
|
||||
WHERE con.id = %1";
|
||||
}
|
||||
elseif ($component == 'recur') {
|
||||
$sql = "
|
||||
SELECT cr.payment_processor_id as ppID1, NULL as ppID2, cr.is_test
|
||||
FROM civicrm_contribution_recur cr
|
||||
WHERE cr.id = %1";
|
||||
}
|
||||
|
||||
// We are interested in a single record.
|
||||
$sql .= ' LIMIT 1';
|
||||
|
||||
$params = array(1 => array($entityID, 'Integer'));
|
||||
$dao = CRM_Core_DAO::executeQuery($sql, $params);
|
||||
|
||||
if (!$dao->fetch()) {
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
$ppID = (isset($dao->ppID1) && $dao->ppID1) ? $dao->ppID1 : (isset($dao->ppID2) ? $dao->ppID2 : NULL);
|
||||
$mode = (isset($dao->is_test) && $dao->is_test) ? 'test' : 'live';
|
||||
if (!$ppID || $type == 'id') {
|
||||
$result = $ppID;
|
||||
}
|
||||
elseif ($type == 'info') {
|
||||
$result = self::getPayment($ppID, $mode);
|
||||
}
|
||||
elseif ($type == 'obj' && is_numeric($ppID)) {
|
||||
try {
|
||||
$paymentProcessor = civicrm_api3('PaymentProcessor', 'getsingle', array('id' => $ppID));
|
||||
}
|
||||
catch (API_Exception $e) {
|
||||
// Unable to load the processor because this function uses an unreliable method to derive it.
|
||||
// The function looks to load the payment processor ID from the contribution page, which
|
||||
// can support multiple processors.
|
||||
}
|
||||
$paymentProcessor['payment_processor_type'] = CRM_Core_PseudoConstant::paymentProcessorType(FALSE, $paymentProcessor['payment_processor_type_id'], 'name');
|
||||
$result = Civi\Payment\System::singleton()->getByProcessor($paymentProcessor);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,213 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Financial_BAO_PaymentProcessorType extends CRM_Financial_DAO_PaymentProcessorType {
|
||||
|
||||
/**
|
||||
* Static holder for the default payment processor.
|
||||
*/
|
||||
static $_defaultPaymentProcessorType = NULL;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch object based on array of properties.
|
||||
*
|
||||
* @param array $params
|
||||
* (reference ) an assoc array of name/value pairs.
|
||||
* @param array $defaults
|
||||
* (reference ) an assoc array to hold the flattened values.
|
||||
*
|
||||
* @return CRM_Core_BAO_LocationType|null
|
||||
* object on success, null otherwise
|
||||
*/
|
||||
public static function retrieve(&$params, &$defaults) {
|
||||
$paymentProcessorType = new CRM_Financial_DAO_PaymentProcessorType();
|
||||
$paymentProcessorType->copyValues($params);
|
||||
if ($paymentProcessorType->find(TRUE)) {
|
||||
CRM_Core_DAO::storeValues($paymentProcessorType, $defaults);
|
||||
return $paymentProcessorType;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the is_active flag in the db.
|
||||
*
|
||||
* @param int $id
|
||||
* Id of the database record.
|
||||
* @param bool $is_active
|
||||
* Value we want to set the is_active field.
|
||||
*
|
||||
* @return Object
|
||||
* DAO object on success, null otherwise
|
||||
*
|
||||
*/
|
||||
public static function setIsActive($id, $is_active) {
|
||||
return CRM_Core_DAO::setFieldValue('CRM_Financial_DAO_PaymentProcessorType', $id, 'is_active', $is_active);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the default payment processor.
|
||||
*
|
||||
* @return object
|
||||
* The default payment processor object on success,
|
||||
* null otherwise
|
||||
*/
|
||||
public static function &getDefault() {
|
||||
if (self::$_defaultPaymentProcessorType == NULL) {
|
||||
$params = array('is_default' => 1);
|
||||
$defaults = array();
|
||||
self::$_defaultPaymentProcessorType = self::retrieve($params, $defaults);
|
||||
}
|
||||
return self::$_defaultPaymentProcessorType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the payment-processor type in the db
|
||||
*
|
||||
* @param array $params
|
||||
* (reference ) an assoc array of name/value pairs.
|
||||
*
|
||||
* @throws Exception
|
||||
* @return CRM_Financial_DAO_PaymentProcessorType
|
||||
*/
|
||||
public static function create(&$params) {
|
||||
$paymentProcessorType = new CRM_Financial_DAO_PaymentProcessorType();
|
||||
$paymentProcessorType->copyValues($params);
|
||||
|
||||
/* @codingStandardsIgnoreStart
|
||||
// adapted from CRM_Core_Extensions_Payment::install
|
||||
foreach (array(
|
||||
'class_name',
|
||||
'title',
|
||||
'name',
|
||||
'description',
|
||||
'user_name_label',
|
||||
'password_label',
|
||||
'signature_label',
|
||||
'subject_label',
|
||||
'url_site_default',
|
||||
'url_api_default',
|
||||
'url_recur_default',
|
||||
'url_site_test_default',
|
||||
'url_api_test_default',
|
||||
'url_recur_test_default',
|
||||
'url_button_default',
|
||||
'url_button_test_default',
|
||||
'billing_mode',
|
||||
'is_recur',
|
||||
'payment_type'
|
||||
) as $trimmable) {
|
||||
if (isset($paymentProcessorType->{$trimmable})) {
|
||||
$paymentProcessorType->{$trimmable} = trim($paymentProcessorType->{$trimmable});
|
||||
}
|
||||
}
|
||||
@codingStandardsIgnoreEnd */
|
||||
|
||||
if (isset($paymentProcessorType->billing_mode)) {
|
||||
// ugh unidirectional manipulation
|
||||
if (!is_numeric($paymentProcessorType->billing_mode)) {
|
||||
$billingModes = array_flip(self::buildOptions('billing_mode'));
|
||||
if (array_key_exists($paymentProcessorType->billing_mode, $billingModes)) {
|
||||
$paymentProcessorType->billing_mode = $billingModes[$paymentProcessorType->billing_mode];
|
||||
}
|
||||
}
|
||||
if (!array_key_exists($paymentProcessorType->billing_mode, self::buildOptions('billing_mode'))) {
|
||||
throw new Exception("Unrecognized billing_mode");
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME handle is_default
|
||||
if (!empty($paymentProcessorType->id)) {
|
||||
$ppByName = self::getAllPaymentProcessorTypes('name');
|
||||
if (array_key_exists($paymentProcessorType->name, $ppByName)) {
|
||||
if ($ppByName[$paymentProcessorType->name] != $paymentProcessorType->id) {
|
||||
CRM_Core_Error::fatal('This payment processor type already exists.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $paymentProcessorType->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete payment processor.
|
||||
*
|
||||
* @param int $paymentProcessorTypeId
|
||||
* ID of the processor to be deleted.
|
||||
*
|
||||
* @return bool|NULL
|
||||
*/
|
||||
public static function del($paymentProcessorTypeId) {
|
||||
$query = "
|
||||
SELECT pp.id processor_id
|
||||
FROM civicrm_payment_processor pp, civicrm_payment_processor_type ppt
|
||||
WHERE pp.payment_processor_type_id = ppt.id AND ppt.id = %1";
|
||||
|
||||
$params = array(1 => array($paymentProcessorTypeId, 'Integer'));
|
||||
$dao = CRM_Core_DAO::executeQuery($query, $params);
|
||||
|
||||
if ($dao->fetch()) {
|
||||
CRM_Core_Session::setStatus(ts('There is a Payment Processor associated with selected Payment Processor type, hence it can not be deleted.'), ts('Deletion Error'), 'error');
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$paymentProcessorType = new CRM_Financial_DAO_PaymentProcessorType();
|
||||
$paymentProcessorType->id = $paymentProcessorTypeId;
|
||||
if ($paymentProcessorType->delete()) {
|
||||
CRM_Core_Session::setStatus(ts('Selected Payment Processor type has been deleted.<br/>'), '', 'success');
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attr
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static private function getAllPaymentProcessorTypes($attr) {
|
||||
$ppt = array();
|
||||
$dao = new CRM_Financial_DAO_PaymentProcessorType();
|
||||
$dao->find();
|
||||
while ($dao->fetch()) {
|
||||
$ppt[$dao->$attr] = $dao->id;
|
||||
}
|
||||
return $ppt;
|
||||
}
|
||||
|
||||
}
|
238
sites/all/modules/civicrm/CRM/Financial/DAO/Currency.php
Normal file
238
sites/all/modules/civicrm/CRM/Financial/DAO/Currency.php
Normal file
|
@ -0,0 +1,238 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
/**
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*
|
||||
* Generated from xml/schema/CRM/Financial/Currency.xml
|
||||
* DO NOT EDIT. Generated by CRM_Core_CodeGen
|
||||
* (GenCodeChecksum:8cf9dbd2493448f02e1173d686b98fbb)
|
||||
*/
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
require_once 'CRM/Utils/Type.php';
|
||||
/**
|
||||
* CRM_Financial_DAO_Currency constructor.
|
||||
*/
|
||||
class CRM_Financial_DAO_Currency extends CRM_Core_DAO {
|
||||
/**
|
||||
* Static instance to hold the table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $_tableName = 'civicrm_currency';
|
||||
/**
|
||||
* Should CiviCRM log any modifications to this table in the civicrm_log table.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
static $_log = true;
|
||||
/**
|
||||
* Currency Id
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* Currency Name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
/**
|
||||
* Currency Symbol
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $symbol;
|
||||
/**
|
||||
* Numeric currency code
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $numeric_code;
|
||||
/**
|
||||
* Full currency name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $full_name;
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->__table = 'civicrm_currency';
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* Returns all the column names of this table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &fields() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
|
||||
Civi::$statics[__CLASS__]['fields'] = array(
|
||||
'id' => array(
|
||||
'name' => 'id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Currency ID') ,
|
||||
'description' => 'Currency Id',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_currency',
|
||||
'entity' => 'Currency',
|
||||
'bao' => 'CRM_Financial_DAO_Currency',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'name' => array(
|
||||
'name' => 'name',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Currency') ,
|
||||
'description' => 'Currency Name',
|
||||
'maxlength' => 64,
|
||||
'size' => CRM_Utils_Type::BIG,
|
||||
'import' => true,
|
||||
'where' => 'civicrm_currency.name',
|
||||
'headerPattern' => '',
|
||||
'dataPattern' => '',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_currency',
|
||||
'entity' => 'Currency',
|
||||
'bao' => 'CRM_Financial_DAO_Currency',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
'symbol' => array(
|
||||
'name' => 'symbol',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Currency Symbol') ,
|
||||
'description' => 'Currency Symbol',
|
||||
'maxlength' => 8,
|
||||
'size' => CRM_Utils_Type::EIGHT,
|
||||
'table_name' => 'civicrm_currency',
|
||||
'entity' => 'Currency',
|
||||
'bao' => 'CRM_Financial_DAO_Currency',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
'numeric_code' => array(
|
||||
'name' => 'numeric_code',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Currency Numeric Code') ,
|
||||
'description' => 'Numeric currency code',
|
||||
'maxlength' => 3,
|
||||
'size' => CRM_Utils_Type::FOUR,
|
||||
'import' => true,
|
||||
'where' => 'civicrm_currency.numeric_code',
|
||||
'headerPattern' => '',
|
||||
'dataPattern' => '',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_currency',
|
||||
'entity' => 'Currency',
|
||||
'bao' => 'CRM_Financial_DAO_Currency',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'full_name' => array(
|
||||
'name' => 'full_name',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Full Currency Name') ,
|
||||
'description' => 'Full currency name',
|
||||
'maxlength' => 64,
|
||||
'size' => CRM_Utils_Type::BIG,
|
||||
'table_name' => 'civicrm_currency',
|
||||
'entity' => 'Currency',
|
||||
'bao' => 'CRM_Financial_DAO_Currency',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
);
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fields'];
|
||||
}
|
||||
/**
|
||||
* Return a mapping from field-name to the corresponding key (as used in fields()).
|
||||
*
|
||||
* @return array
|
||||
* Array(string $name => string $uniqueName).
|
||||
*/
|
||||
static function &fieldKeys() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
|
||||
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fieldKeys'];
|
||||
}
|
||||
/**
|
||||
* Returns the names of this table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function getTableName() {
|
||||
return self::$_tableName;
|
||||
}
|
||||
/**
|
||||
* Returns if this table needs to be logged
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function getLog() {
|
||||
return self::$_log;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be imported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &import($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'currency', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be exported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &export($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'currency', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of indices
|
||||
*/
|
||||
public static function indices($localize = TRUE) {
|
||||
$indices = array();
|
||||
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,265 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
/**
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*
|
||||
* Generated from xml/schema/CRM/Financial/EntityFinancialAccount.xml
|
||||
* DO NOT EDIT. Generated by CRM_Core_CodeGen
|
||||
* (GenCodeChecksum:b9e9a095e5a6631dd7104828d40ec55a)
|
||||
*/
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
require_once 'CRM/Utils/Type.php';
|
||||
/**
|
||||
* CRM_Financial_DAO_EntityFinancialAccount constructor.
|
||||
*/
|
||||
class CRM_Financial_DAO_EntityFinancialAccount extends CRM_Core_DAO {
|
||||
/**
|
||||
* Static instance to hold the table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $_tableName = 'civicrm_entity_financial_account';
|
||||
/**
|
||||
* Should CiviCRM log any modifications to this table in the civicrm_log table.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
static $_log = true;
|
||||
/**
|
||||
* ID
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* Links to an entity_table like civicrm_financial_type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $entity_table;
|
||||
/**
|
||||
* Links to an id in the entity_table, such as vid in civicrm_financial_type
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $entity_id;
|
||||
/**
|
||||
* FK to a new civicrm_option_value (account_relationship)
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $account_relationship;
|
||||
/**
|
||||
* FK to the financial_account_id
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $financial_account_id;
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->__table = 'civicrm_entity_financial_account';
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* Returns foreign keys and entity references.
|
||||
*
|
||||
* @return array
|
||||
* [CRM_Core_Reference_Interface]
|
||||
*/
|
||||
static function getReferenceColumns() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['links'])) {
|
||||
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'financial_account_id', 'civicrm_financial_account', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName() , 'entity_id', NULL, 'id', 'entity_table');
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['links'];
|
||||
}
|
||||
/**
|
||||
* Returns all the column names of this table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &fields() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
|
||||
Civi::$statics[__CLASS__]['fields'] = array(
|
||||
'id' => array(
|
||||
'name' => 'id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Entity Financial Account ID') ,
|
||||
'description' => 'ID',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_entity_financial_account',
|
||||
'entity' => 'EntityFinancialAccount',
|
||||
'bao' => 'CRM_Financial_DAO_EntityFinancialAccount',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'entity_table' => array(
|
||||
'name' => 'entity_table',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Entity Table') ,
|
||||
'description' => 'Links to an entity_table like civicrm_financial_type',
|
||||
'required' => true,
|
||||
'maxlength' => 64,
|
||||
'size' => CRM_Utils_Type::BIG,
|
||||
'import' => true,
|
||||
'where' => 'civicrm_entity_financial_account.entity_table',
|
||||
'headerPattern' => '',
|
||||
'dataPattern' => '',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_entity_financial_account',
|
||||
'entity' => 'EntityFinancialAccount',
|
||||
'bao' => 'CRM_Financial_DAO_EntityFinancialAccount',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'entity_id' => array(
|
||||
'name' => 'entity_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Entity ID') ,
|
||||
'description' => 'Links to an id in the entity_table, such as vid in civicrm_financial_type',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_entity_financial_account',
|
||||
'entity' => 'EntityFinancialAccount',
|
||||
'bao' => 'CRM_Financial_DAO_EntityFinancialAccount',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'account_relationship' => array(
|
||||
'name' => 'account_relationship',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Account Relationship') ,
|
||||
'description' => 'FK to a new civicrm_option_value (account_relationship)',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_entity_financial_account',
|
||||
'entity' => 'EntityFinancialAccount',
|
||||
'bao' => 'CRM_Financial_DAO_EntityFinancialAccount',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'optionGroupName' => 'account_relationship',
|
||||
'optionEditPath' => 'civicrm/admin/options/account_relationship',
|
||||
)
|
||||
) ,
|
||||
'financial_account_id' => array(
|
||||
'name' => 'financial_account_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Financial Account') ,
|
||||
'description' => 'FK to the financial_account_id',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_entity_financial_account',
|
||||
'entity' => 'EntityFinancialAccount',
|
||||
'bao' => 'CRM_Financial_DAO_EntityFinancialAccount',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Financial_DAO_FinancialAccount',
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'table' => 'civicrm_financial_account',
|
||||
'keyColumn' => 'id',
|
||||
'labelColumn' => 'name',
|
||||
)
|
||||
) ,
|
||||
);
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fields'];
|
||||
}
|
||||
/**
|
||||
* Return a mapping from field-name to the corresponding key (as used in fields()).
|
||||
*
|
||||
* @return array
|
||||
* Array(string $name => string $uniqueName).
|
||||
*/
|
||||
static function &fieldKeys() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
|
||||
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fieldKeys'];
|
||||
}
|
||||
/**
|
||||
* Returns the names of this table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function getTableName() {
|
||||
return self::$_tableName;
|
||||
}
|
||||
/**
|
||||
* Returns if this table needs to be logged
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function getLog() {
|
||||
return self::$_log;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be imported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &import($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'entity_financial_account', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be exported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &export($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'entity_financial_account', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of indices
|
||||
*/
|
||||
public static function indices($localize = TRUE) {
|
||||
$indices = array(
|
||||
'index_entity_id_entity_table_account_relationship' => array(
|
||||
'name' => 'index_entity_id_entity_table_account_relationship',
|
||||
'field' => array(
|
||||
0 => 'entity_id',
|
||||
1 => 'entity_table',
|
||||
2 => 'account_relationship',
|
||||
) ,
|
||||
'localizable' => false,
|
||||
'unique' => true,
|
||||
'sig' => 'civicrm_entity_financial_account::1::entity_id::entity_table::account_relationship',
|
||||
) ,
|
||||
);
|
||||
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,259 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
/**
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*
|
||||
* Generated from xml/schema/CRM/Financial/EntityFinancialTrxn.xml
|
||||
* DO NOT EDIT. Generated by CRM_Core_CodeGen
|
||||
* (GenCodeChecksum:8650c2685e9d125bed6f9b65ce208621)
|
||||
*/
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
require_once 'CRM/Utils/Type.php';
|
||||
/**
|
||||
* CRM_Financial_DAO_EntityFinancialTrxn constructor.
|
||||
*/
|
||||
class CRM_Financial_DAO_EntityFinancialTrxn extends CRM_Core_DAO {
|
||||
/**
|
||||
* Static instance to hold the table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $_tableName = 'civicrm_entity_financial_trxn';
|
||||
/**
|
||||
* Should CiviCRM log any modifications to this table in the civicrm_log table.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
static $_log = false;
|
||||
/**
|
||||
* ID
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* May contain civicrm_financial_item, civicrm_contribution, civicrm_financial_trxn, civicrm_grant, etc
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $entity_table;
|
||||
/**
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $entity_id;
|
||||
/**
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $financial_trxn_id;
|
||||
/**
|
||||
* allocated amount of transaction to this entity
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $amount;
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->__table = 'civicrm_entity_financial_trxn';
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* Returns foreign keys and entity references.
|
||||
*
|
||||
* @return array
|
||||
* [CRM_Core_Reference_Interface]
|
||||
*/
|
||||
static function getReferenceColumns() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['links'])) {
|
||||
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'financial_trxn_id', 'civicrm_financial_trxn', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName() , 'entity_id', NULL, 'id', 'entity_table');
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['links'];
|
||||
}
|
||||
/**
|
||||
* Returns all the column names of this table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &fields() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
|
||||
Civi::$statics[__CLASS__]['fields'] = array(
|
||||
'id' => array(
|
||||
'name' => 'id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Entity Financial Transaction ID') ,
|
||||
'description' => 'ID',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_entity_financial_trxn',
|
||||
'entity' => 'EntityFinancialTrxn',
|
||||
'bao' => 'CRM_Financial_DAO_EntityFinancialTrxn',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'entity_table' => array(
|
||||
'name' => 'entity_table',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Entity Table') ,
|
||||
'description' => 'May contain civicrm_financial_item, civicrm_contribution, civicrm_financial_trxn, civicrm_grant, etc',
|
||||
'required' => true,
|
||||
'maxlength' => 64,
|
||||
'size' => CRM_Utils_Type::BIG,
|
||||
'import' => true,
|
||||
'where' => 'civicrm_entity_financial_trxn.entity_table',
|
||||
'headerPattern' => '',
|
||||
'dataPattern' => '',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_entity_financial_trxn',
|
||||
'entity' => 'EntityFinancialTrxn',
|
||||
'bao' => 'CRM_Financial_DAO_EntityFinancialTrxn',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'entity_id' => array(
|
||||
'name' => 'entity_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Entity ID') ,
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_entity_financial_trxn',
|
||||
'entity' => 'EntityFinancialTrxn',
|
||||
'bao' => 'CRM_Financial_DAO_EntityFinancialTrxn',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'financial_trxn_id' => array(
|
||||
'name' => 'financial_trxn_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Financial Transaction Id') ,
|
||||
'table_name' => 'civicrm_entity_financial_trxn',
|
||||
'entity' => 'EntityFinancialTrxn',
|
||||
'bao' => 'CRM_Financial_DAO_EntityFinancialTrxn',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Financial_DAO_FinancialTrxn',
|
||||
) ,
|
||||
'amount' => array(
|
||||
'name' => 'amount',
|
||||
'type' => CRM_Utils_Type::T_MONEY,
|
||||
'title' => ts('Amount') ,
|
||||
'description' => 'allocated amount of transaction to this entity',
|
||||
'required' => true,
|
||||
'precision' => array(
|
||||
20,
|
||||
2
|
||||
) ,
|
||||
'import' => true,
|
||||
'where' => 'civicrm_entity_financial_trxn.amount',
|
||||
'headerPattern' => '/amount/i',
|
||||
'dataPattern' => '/^\d+(\.\d{2})?$/',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_entity_financial_trxn',
|
||||
'entity' => 'EntityFinancialTrxn',
|
||||
'bao' => 'CRM_Financial_DAO_EntityFinancialTrxn',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
);
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fields'];
|
||||
}
|
||||
/**
|
||||
* Return a mapping from field-name to the corresponding key (as used in fields()).
|
||||
*
|
||||
* @return array
|
||||
* Array(string $name => string $uniqueName).
|
||||
*/
|
||||
static function &fieldKeys() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
|
||||
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fieldKeys'];
|
||||
}
|
||||
/**
|
||||
* Returns the names of this table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function getTableName() {
|
||||
return self::$_tableName;
|
||||
}
|
||||
/**
|
||||
* Returns if this table needs to be logged
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function getLog() {
|
||||
return self::$_log;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be imported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &import($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'entity_financial_trxn', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be exported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &export($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'entity_financial_trxn', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of indices
|
||||
*/
|
||||
public static function indices($localize = TRUE) {
|
||||
$indices = array(
|
||||
'UI_entity_financial_trxn_entity_table' => array(
|
||||
'name' => 'UI_entity_financial_trxn_entity_table',
|
||||
'field' => array(
|
||||
0 => 'entity_table',
|
||||
) ,
|
||||
'localizable' => false,
|
||||
'sig' => 'civicrm_entity_financial_trxn::0::entity_table',
|
||||
) ,
|
||||
'UI_entity_financial_trxn_entity_id' => array(
|
||||
'name' => 'UI_entity_financial_trxn_entity_id',
|
||||
'field' => array(
|
||||
0 => 'entity_id',
|
||||
) ,
|
||||
'localizable' => false,
|
||||
'sig' => 'civicrm_entity_financial_trxn::0::entity_id',
|
||||
) ,
|
||||
);
|
||||
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
|
||||
}
|
||||
}
|
429
sites/all/modules/civicrm/CRM/Financial/DAO/FinancialAccount.php
Normal file
429
sites/all/modules/civicrm/CRM/Financial/DAO/FinancialAccount.php
Normal file
|
@ -0,0 +1,429 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
/**
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*
|
||||
* Generated from xml/schema/CRM/Financial/FinancialAccount.xml
|
||||
* DO NOT EDIT. Generated by CRM_Core_CodeGen
|
||||
* (GenCodeChecksum:4b1497d1607b10f8eec89c101665cd1d)
|
||||
*/
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
require_once 'CRM/Utils/Type.php';
|
||||
/**
|
||||
* CRM_Financial_DAO_FinancialAccount constructor.
|
||||
*/
|
||||
class CRM_Financial_DAO_FinancialAccount extends CRM_Core_DAO {
|
||||
/**
|
||||
* Static instance to hold the table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $_tableName = 'civicrm_financial_account';
|
||||
/**
|
||||
* Should CiviCRM log any modifications to this table in the civicrm_log table.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
static $_log = true;
|
||||
/**
|
||||
* ID
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* Financial Account Name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
/**
|
||||
* FK to Contact ID that is responsible for the funds in this account
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $contact_id;
|
||||
/**
|
||||
* pseudo FK into civicrm_option_value.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $financial_account_type_id;
|
||||
/**
|
||||
* Optional value for mapping monies owed and received to accounting system codes.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $accounting_code;
|
||||
/**
|
||||
* Optional value for mapping account types to accounting system account categories (QuickBooks Account Type Codes for example).
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $account_type_code;
|
||||
/**
|
||||
* Financial Type Description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $description;
|
||||
/**
|
||||
* Parent ID in account hierarchy
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $parent_id;
|
||||
/**
|
||||
* Is this a header account which does not allow transactions to be posted against it directly, but only to its sub-accounts?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_header_account;
|
||||
/**
|
||||
* Is this account tax-deductible?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_deductible;
|
||||
/**
|
||||
* Is this account for taxes?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_tax;
|
||||
/**
|
||||
* The percentage of the total_amount that is due for this tax.
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $tax_rate;
|
||||
/**
|
||||
* Is this a predefined system object?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_reserved;
|
||||
/**
|
||||
* Is this property active?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_active;
|
||||
/**
|
||||
* Is this account the default one (or default tax one) for its financial_account_type?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_default;
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->__table = 'civicrm_financial_account';
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* Returns foreign keys and entity references.
|
||||
*
|
||||
* @return array
|
||||
* [CRM_Core_Reference_Interface]
|
||||
*/
|
||||
static function getReferenceColumns() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['links'])) {
|
||||
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'contact_id', 'civicrm_contact', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'parent_id', 'civicrm_financial_account', 'id');
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['links'];
|
||||
}
|
||||
/**
|
||||
* Returns all the column names of this table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &fields() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
|
||||
Civi::$statics[__CLASS__]['fields'] = array(
|
||||
'id' => array(
|
||||
'name' => 'id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Financial Account ID') ,
|
||||
'description' => 'ID',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_financial_account',
|
||||
'entity' => 'FinancialAccount',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialAccount',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'name' => array(
|
||||
'name' => 'name',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Financial Account Name') ,
|
||||
'description' => 'Financial Account Name.',
|
||||
'required' => true,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_financial_account',
|
||||
'entity' => 'FinancialAccount',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialAccount',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'financial_account_contact_id' => array(
|
||||
'name' => 'contact_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Contact ID') ,
|
||||
'description' => 'FK to Contact ID that is responsible for the funds in this account',
|
||||
'table_name' => 'civicrm_financial_account',
|
||||
'entity' => 'FinancialAccount',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialAccount',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Contact_DAO_Contact',
|
||||
) ,
|
||||
'financial_account_type_id' => array(
|
||||
'name' => 'financial_account_type_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Financial Account Type') ,
|
||||
'description' => 'pseudo FK into civicrm_option_value.',
|
||||
'required' => true,
|
||||
'default' => '3',
|
||||
'table_name' => 'civicrm_financial_account',
|
||||
'entity' => 'FinancialAccount',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialAccount',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'optionGroupName' => 'financial_account_type',
|
||||
'optionEditPath' => 'civicrm/admin/options/financial_account_type',
|
||||
)
|
||||
) ,
|
||||
'accounting_code' => array(
|
||||
'name' => 'accounting_code',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Accounting Code') ,
|
||||
'description' => 'Optional value for mapping monies owed and received to accounting system codes.',
|
||||
'maxlength' => 64,
|
||||
'size' => CRM_Utils_Type::BIG,
|
||||
'export' => true,
|
||||
'where' => 'civicrm_financial_account.accounting_code',
|
||||
'headerPattern' => '',
|
||||
'dataPattern' => '',
|
||||
'table_name' => 'civicrm_financial_account',
|
||||
'entity' => 'FinancialAccount',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialAccount',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'account_type_code' => array(
|
||||
'name' => 'account_type_code',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Account Type Code') ,
|
||||
'description' => 'Optional value for mapping account types to accounting system account categories (QuickBooks Account Type Codes for example).',
|
||||
'maxlength' => 64,
|
||||
'size' => CRM_Utils_Type::BIG,
|
||||
'export' => true,
|
||||
'where' => 'civicrm_financial_account.account_type_code',
|
||||
'headerPattern' => '',
|
||||
'dataPattern' => '',
|
||||
'table_name' => 'civicrm_financial_account',
|
||||
'entity' => 'FinancialAccount',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialAccount',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'description' => array(
|
||||
'name' => 'description',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Financial Account Description') ,
|
||||
'description' => 'Financial Type Description.',
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_financial_account',
|
||||
'entity' => 'FinancialAccount',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialAccount',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'parent_id' => array(
|
||||
'name' => 'parent_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Financial Account Parent') ,
|
||||
'description' => 'Parent ID in account hierarchy',
|
||||
'table_name' => 'civicrm_financial_account',
|
||||
'entity' => 'FinancialAccount',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialAccount',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Financial_DAO_FinancialAccount',
|
||||
) ,
|
||||
'is_header_account' => array(
|
||||
'name' => 'is_header_account',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Header Financial Account?') ,
|
||||
'description' => 'Is this a header account which does not allow transactions to be posted against it directly, but only to its sub-accounts?',
|
||||
'table_name' => 'civicrm_financial_account',
|
||||
'entity' => 'FinancialAccount',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialAccount',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'is_deductible' => array(
|
||||
'name' => 'is_deductible',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Deductible Financial Account?') ,
|
||||
'description' => 'Is this account tax-deductible?',
|
||||
'default' => '1',
|
||||
'table_name' => 'civicrm_financial_account',
|
||||
'entity' => 'FinancialAccount',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialAccount',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'is_tax' => array(
|
||||
'name' => 'is_tax',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Tax Financial Account?') ,
|
||||
'description' => 'Is this account for taxes?',
|
||||
'table_name' => 'civicrm_financial_account',
|
||||
'entity' => 'FinancialAccount',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialAccount',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'tax_rate' => array(
|
||||
'name' => 'tax_rate',
|
||||
'type' => CRM_Utils_Type::T_MONEY,
|
||||
'title' => ts('Financial Account Tax Rate') ,
|
||||
'description' => 'The percentage of the total_amount that is due for this tax.',
|
||||
'precision' => array(
|
||||
10,
|
||||
8
|
||||
) ,
|
||||
'table_name' => 'civicrm_financial_account',
|
||||
'entity' => 'FinancialAccount',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialAccount',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'is_reserved' => array(
|
||||
'name' => 'is_reserved',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Reserved Financial Account?') ,
|
||||
'description' => 'Is this a predefined system object?',
|
||||
'table_name' => 'civicrm_financial_account',
|
||||
'entity' => 'FinancialAccount',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialAccount',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'is_active' => array(
|
||||
'name' => 'is_active',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Financial Account is Active') ,
|
||||
'description' => 'Is this property active?',
|
||||
'table_name' => 'civicrm_financial_account',
|
||||
'entity' => 'FinancialAccount',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialAccount',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'is_default' => array(
|
||||
'name' => 'is_default',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Default Financial Account') ,
|
||||
'description' => 'Is this account the default one (or default tax one) for its financial_account_type?',
|
||||
'table_name' => 'civicrm_financial_account',
|
||||
'entity' => 'FinancialAccount',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialAccount',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
);
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fields'];
|
||||
}
|
||||
/**
|
||||
* Return a mapping from field-name to the corresponding key (as used in fields()).
|
||||
*
|
||||
* @return array
|
||||
* Array(string $name => string $uniqueName).
|
||||
*/
|
||||
static function &fieldKeys() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
|
||||
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fieldKeys'];
|
||||
}
|
||||
/**
|
||||
* Returns the names of this table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function getTableName() {
|
||||
return self::$_tableName;
|
||||
}
|
||||
/**
|
||||
* Returns if this table needs to be logged
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function getLog() {
|
||||
return self::$_log;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be imported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &import($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'financial_account', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be exported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &export($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'financial_account', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of indices
|
||||
*/
|
||||
public static function indices($localize = TRUE) {
|
||||
$indices = array(
|
||||
'UI_name' => array(
|
||||
'name' => 'UI_name',
|
||||
'field' => array(
|
||||
0 => 'name',
|
||||
) ,
|
||||
'localizable' => false,
|
||||
'unique' => true,
|
||||
'sig' => 'civicrm_financial_account::1::name',
|
||||
) ,
|
||||
);
|
||||
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
|
||||
}
|
||||
}
|
400
sites/all/modules/civicrm/CRM/Financial/DAO/FinancialItem.php
Normal file
400
sites/all/modules/civicrm/CRM/Financial/DAO/FinancialItem.php
Normal file
|
@ -0,0 +1,400 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
/**
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*
|
||||
* Generated from xml/schema/CRM/Financial/FinancialItem.xml
|
||||
* DO NOT EDIT. Generated by CRM_Core_CodeGen
|
||||
* (GenCodeChecksum:95e199969f4ff93ccae635fb7e0d30f2)
|
||||
*/
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
require_once 'CRM/Utils/Type.php';
|
||||
/**
|
||||
* CRM_Financial_DAO_FinancialItem constructor.
|
||||
*/
|
||||
class CRM_Financial_DAO_FinancialItem extends CRM_Core_DAO {
|
||||
/**
|
||||
* Static instance to hold the table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $_tableName = 'civicrm_financial_item';
|
||||
/**
|
||||
* Should CiviCRM log any modifications to this table in the civicrm_log table.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
static $_log = true;
|
||||
/**
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* Date and time the item was created
|
||||
*
|
||||
* @var timestamp
|
||||
*/
|
||||
public $created_date;
|
||||
/**
|
||||
* Date and time of the source transaction
|
||||
*
|
||||
* @var datetime
|
||||
*/
|
||||
public $transaction_date;
|
||||
/**
|
||||
* FK to Contact ID of contact the item is from
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $contact_id;
|
||||
/**
|
||||
* Human readable description of this item, to ease display without lookup of source item.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $description;
|
||||
/**
|
||||
* Total amount of this item
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $amount;
|
||||
/**
|
||||
* Currency for the amount
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $currency;
|
||||
/**
|
||||
* FK to civicrm_financial_account
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $financial_account_id;
|
||||
/**
|
||||
* Payment status: test, paid, part_paid, unpaid (if empty assume unpaid)
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $status_id;
|
||||
/**
|
||||
* The table providing the source of this item such as civicrm_line_item
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $entity_table;
|
||||
/**
|
||||
* The specific source item that is responsible for the creation of this financial_item
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $entity_id;
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->__table = 'civicrm_financial_item';
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* Returns foreign keys and entity references.
|
||||
*
|
||||
* @return array
|
||||
* [CRM_Core_Reference_Interface]
|
||||
*/
|
||||
static function getReferenceColumns() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['links'])) {
|
||||
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'contact_id', 'civicrm_contact', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'financial_account_id', 'civicrm_financial_account', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName() , 'entity_id', NULL, 'id', 'entity_table');
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['links'];
|
||||
}
|
||||
/**
|
||||
* Returns all the column names of this table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &fields() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
|
||||
Civi::$statics[__CLASS__]['fields'] = array(
|
||||
'id' => array(
|
||||
'name' => 'id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Financial Item ID') ,
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_financial_item',
|
||||
'entity' => 'FinancialItem',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialItem',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'created_date' => array(
|
||||
'name' => 'created_date',
|
||||
'type' => CRM_Utils_Type::T_TIMESTAMP,
|
||||
'title' => ts('Financial Item Created Date') ,
|
||||
'description' => 'Date and time the item was created',
|
||||
'required' => true,
|
||||
'default' => 'CURRENT_TIMESTAMP',
|
||||
'table_name' => 'civicrm_financial_item',
|
||||
'entity' => 'FinancialItem',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialItem',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'transaction_date' => array(
|
||||
'name' => 'transaction_date',
|
||||
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
|
||||
'title' => ts('Financial Item Transaction Date') ,
|
||||
'description' => 'Date and time of the source transaction',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_financial_item',
|
||||
'entity' => 'FinancialItem',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialItem',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'contact_id' => array(
|
||||
'name' => 'contact_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Financial Item Contact ID') ,
|
||||
'description' => 'FK to Contact ID of contact the item is from',
|
||||
'required' => true,
|
||||
'export' => true,
|
||||
'where' => 'civicrm_financial_item.contact_id',
|
||||
'headerPattern' => '',
|
||||
'dataPattern' => '',
|
||||
'table_name' => 'civicrm_financial_item',
|
||||
'entity' => 'FinancialItem',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialItem',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Contact_DAO_Contact',
|
||||
) ,
|
||||
'description' => array(
|
||||
'name' => 'description',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Financial Item Description') ,
|
||||
'description' => 'Human readable description of this item, to ease display without lookup of source item.',
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_financial_item',
|
||||
'entity' => 'FinancialItem',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialItem',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'amount' => array(
|
||||
'name' => 'amount',
|
||||
'type' => CRM_Utils_Type::T_MONEY,
|
||||
'title' => ts('Amount') ,
|
||||
'description' => 'Total amount of this item',
|
||||
'required' => true,
|
||||
'precision' => array(
|
||||
20,
|
||||
2
|
||||
) ,
|
||||
'table_name' => 'civicrm_financial_item',
|
||||
'entity' => 'FinancialItem',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialItem',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'currency' => array(
|
||||
'name' => 'currency',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Financial Item Currency') ,
|
||||
'description' => 'Currency for the amount',
|
||||
'maxlength' => 3,
|
||||
'size' => CRM_Utils_Type::FOUR,
|
||||
'export' => true,
|
||||
'where' => 'civicrm_financial_item.currency',
|
||||
'headerPattern' => '',
|
||||
'dataPattern' => '',
|
||||
'table_name' => 'civicrm_financial_item',
|
||||
'entity' => 'FinancialItem',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialItem',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'table' => 'civicrm_currency',
|
||||
'keyColumn' => 'name',
|
||||
'labelColumn' => 'full_name',
|
||||
'nameColumn' => 'name',
|
||||
)
|
||||
) ,
|
||||
'financial_account_id' => array(
|
||||
'name' => 'financial_account_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Financial Account ID') ,
|
||||
'description' => 'FK to civicrm_financial_account',
|
||||
'table_name' => 'civicrm_financial_item',
|
||||
'entity' => 'FinancialItem',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialItem',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Financial_DAO_FinancialAccount',
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'table' => 'civicrm_financial_account',
|
||||
'keyColumn' => 'id',
|
||||
'labelColumn' => 'name',
|
||||
)
|
||||
) ,
|
||||
'status_id' => array(
|
||||
'name' => 'status_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Financial Item Status ID') ,
|
||||
'description' => 'Payment status: test, paid, part_paid, unpaid (if empty assume unpaid)',
|
||||
'export' => true,
|
||||
'where' => 'civicrm_financial_item.status_id',
|
||||
'headerPattern' => '',
|
||||
'dataPattern' => '',
|
||||
'table_name' => 'civicrm_financial_item',
|
||||
'entity' => 'FinancialItem',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialItem',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'optionGroupName' => 'financial_item_status',
|
||||
'optionEditPath' => 'civicrm/admin/options/financial_item_status',
|
||||
)
|
||||
) ,
|
||||
'entity_table' => array(
|
||||
'name' => 'entity_table',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Entity Table') ,
|
||||
'description' => 'The table providing the source of this item such as civicrm_line_item',
|
||||
'maxlength' => 64,
|
||||
'size' => CRM_Utils_Type::BIG,
|
||||
'table_name' => 'civicrm_financial_item',
|
||||
'entity' => 'FinancialItem',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialItem',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'entity_id' => array(
|
||||
'name' => 'entity_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Entity ID') ,
|
||||
'description' => 'The specific source item that is responsible for the creation of this financial_item',
|
||||
'table_name' => 'civicrm_financial_item',
|
||||
'entity' => 'FinancialItem',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialItem',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
);
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fields'];
|
||||
}
|
||||
/**
|
||||
* Return a mapping from field-name to the corresponding key (as used in fields()).
|
||||
*
|
||||
* @return array
|
||||
* Array(string $name => string $uniqueName).
|
||||
*/
|
||||
static function &fieldKeys() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
|
||||
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fieldKeys'];
|
||||
}
|
||||
/**
|
||||
* Returns the names of this table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function getTableName() {
|
||||
return self::$_tableName;
|
||||
}
|
||||
/**
|
||||
* Returns if this table needs to be logged
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function getLog() {
|
||||
return self::$_log;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be imported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &import($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'financial_item', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be exported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &export($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'financial_item', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of indices
|
||||
*/
|
||||
public static function indices($localize = TRUE) {
|
||||
$indices = array(
|
||||
'IX_created_date' => array(
|
||||
'name' => 'IX_created_date',
|
||||
'field' => array(
|
||||
0 => 'created_date',
|
||||
) ,
|
||||
'localizable' => false,
|
||||
'sig' => 'civicrm_financial_item::0::created_date',
|
||||
) ,
|
||||
'IX_transaction_date' => array(
|
||||
'name' => 'IX_transaction_date',
|
||||
'field' => array(
|
||||
0 => 'transaction_date',
|
||||
) ,
|
||||
'localizable' => false,
|
||||
'sig' => 'civicrm_financial_item::0::transaction_date',
|
||||
) ,
|
||||
'index_entity_id_entity_table' => array(
|
||||
'name' => 'index_entity_id_entity_table',
|
||||
'field' => array(
|
||||
0 => 'entity_id',
|
||||
1 => 'entity_table',
|
||||
) ,
|
||||
'localizable' => false,
|
||||
'sig' => 'civicrm_financial_item::0::entity_id::entity_table',
|
||||
) ,
|
||||
);
|
||||
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
|
||||
}
|
||||
}
|
541
sites/all/modules/civicrm/CRM/Financial/DAO/FinancialTrxn.php
Normal file
541
sites/all/modules/civicrm/CRM/Financial/DAO/FinancialTrxn.php
Normal file
|
@ -0,0 +1,541 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
/**
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*
|
||||
* Generated from xml/schema/CRM/Financial/FinancialTrxn.xml
|
||||
* DO NOT EDIT. Generated by CRM_Core_CodeGen
|
||||
* (GenCodeChecksum:21185c4929ef1a8d126c72733cc7ad1d)
|
||||
*/
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
require_once 'CRM/Utils/Type.php';
|
||||
/**
|
||||
* CRM_Financial_DAO_FinancialTrxn constructor.
|
||||
*/
|
||||
class CRM_Financial_DAO_FinancialTrxn extends CRM_Core_DAO {
|
||||
/**
|
||||
* Static instance to hold the table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $_tableName = 'civicrm_financial_trxn';
|
||||
/**
|
||||
* Should CiviCRM log any modifications to this table in the civicrm_log table.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
static $_log = true;
|
||||
/**
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* FK to financial_account table.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $from_financial_account_id;
|
||||
/**
|
||||
* FK to financial_financial_account table.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $to_financial_account_id;
|
||||
/**
|
||||
* date transaction occurred
|
||||
*
|
||||
* @var datetime
|
||||
*/
|
||||
public $trxn_date;
|
||||
/**
|
||||
* amount of transaction
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $total_amount;
|
||||
/**
|
||||
* actual processor fee if known - may be 0.
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $fee_amount;
|
||||
/**
|
||||
* actual funds transfer amount. total less fees. if processor does not report actual fee during transaction, this is set to total_amount.
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $net_amount;
|
||||
/**
|
||||
* 3 character string, value from config setting or input via user.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $currency;
|
||||
/**
|
||||
* Is this entry either a payment or a reversal of a payment?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_payment;
|
||||
/**
|
||||
* Transaction id supplied by external processor. This may not be unique.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $trxn_id;
|
||||
/**
|
||||
* processor result code
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $trxn_result_code;
|
||||
/**
|
||||
* pseudo FK to civicrm_option_value of contribution_status_id option_group
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $status_id;
|
||||
/**
|
||||
* Payment Processor for this financial transaction
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $payment_processor_id;
|
||||
/**
|
||||
* FK to payment_instrument option group values
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $payment_instrument_id;
|
||||
/**
|
||||
* FK to accept_creditcard option group values
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $card_type_id;
|
||||
/**
|
||||
* Check number
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $check_number;
|
||||
/**
|
||||
* Last 4 digits of credit card
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $pan_truncation;
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->__table = 'civicrm_financial_trxn';
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* Returns foreign keys and entity references.
|
||||
*
|
||||
* @return array
|
||||
* [CRM_Core_Reference_Interface]
|
||||
*/
|
||||
static function getReferenceColumns() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['links'])) {
|
||||
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'from_financial_account_id', 'civicrm_financial_account', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'to_financial_account_id', 'civicrm_financial_account', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'payment_processor_id', 'civicrm_payment_processor', 'id');
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['links'];
|
||||
}
|
||||
/**
|
||||
* Returns all the column names of this table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &fields() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
|
||||
Civi::$statics[__CLASS__]['fields'] = array(
|
||||
'id' => array(
|
||||
'name' => 'id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Financial Transaction ID') ,
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_financial_trxn',
|
||||
'entity' => 'FinancialTrxn',
|
||||
'bao' => 'CRM_Financial_DAO_FinancialTrxn',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'from_financial_account_id' => array(
|
||||
'name' => 'from_financial_account_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Financial Transaction From Account') ,
|
||||
'description' => 'FK to financial_account table.',
|
||||
'table_name' => 'civicrm_financial_trxn',
|
||||
'entity' => 'FinancialTrxn',
|
||||
'bao' => 'CRM_Financial_DAO_FinancialTrxn',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Financial_DAO_FinancialAccount',
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'table' => 'civicrm_financial_account',
|
||||
'keyColumn' => 'id',
|
||||
'labelColumn' => 'name',
|
||||
)
|
||||
) ,
|
||||
'to_financial_account_id' => array(
|
||||
'name' => 'to_financial_account_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Financial Transaction To Account') ,
|
||||
'description' => 'FK to financial_financial_account table.',
|
||||
'table_name' => 'civicrm_financial_trxn',
|
||||
'entity' => 'FinancialTrxn',
|
||||
'bao' => 'CRM_Financial_DAO_FinancialTrxn',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Financial_DAO_FinancialAccount',
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'table' => 'civicrm_financial_account',
|
||||
'keyColumn' => 'id',
|
||||
'labelColumn' => 'name',
|
||||
)
|
||||
) ,
|
||||
'trxn_date' => array(
|
||||
'name' => 'trxn_date',
|
||||
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
|
||||
'title' => ts('Financial Transaction Date') ,
|
||||
'description' => 'date transaction occurred',
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_financial_trxn',
|
||||
'entity' => 'FinancialTrxn',
|
||||
'bao' => 'CRM_Financial_DAO_FinancialTrxn',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select Date',
|
||||
'formatType' => 'activityDateTime',
|
||||
) ,
|
||||
) ,
|
||||
'total_amount' => array(
|
||||
'name' => 'total_amount',
|
||||
'type' => CRM_Utils_Type::T_MONEY,
|
||||
'title' => ts('Financial Total Amount') ,
|
||||
'description' => 'amount of transaction',
|
||||
'required' => true,
|
||||
'precision' => array(
|
||||
20,
|
||||
2
|
||||
) ,
|
||||
'table_name' => 'civicrm_financial_trxn',
|
||||
'entity' => 'FinancialTrxn',
|
||||
'bao' => 'CRM_Financial_DAO_FinancialTrxn',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'fee_amount' => array(
|
||||
'name' => 'fee_amount',
|
||||
'type' => CRM_Utils_Type::T_MONEY,
|
||||
'title' => ts('Financial Fee Amount') ,
|
||||
'description' => 'actual processor fee if known - may be 0.',
|
||||
'precision' => array(
|
||||
20,
|
||||
2
|
||||
) ,
|
||||
'table_name' => 'civicrm_financial_trxn',
|
||||
'entity' => 'FinancialTrxn',
|
||||
'bao' => 'CRM_Financial_DAO_FinancialTrxn',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'net_amount' => array(
|
||||
'name' => 'net_amount',
|
||||
'type' => CRM_Utils_Type::T_MONEY,
|
||||
'title' => ts('Financial Net Amount') ,
|
||||
'description' => 'actual funds transfer amount. total less fees. if processor does not report actual fee during transaction, this is set to total_amount.',
|
||||
'precision' => array(
|
||||
20,
|
||||
2
|
||||
) ,
|
||||
'table_name' => 'civicrm_financial_trxn',
|
||||
'entity' => 'FinancialTrxn',
|
||||
'bao' => 'CRM_Financial_DAO_FinancialTrxn',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'currency' => array(
|
||||
'name' => 'currency',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Financial Currency') ,
|
||||
'description' => '3 character string, value from config setting or input via user.',
|
||||
'maxlength' => 3,
|
||||
'size' => CRM_Utils_Type::FOUR,
|
||||
'import' => true,
|
||||
'where' => 'civicrm_financial_trxn.currency',
|
||||
'headerPattern' => '/cur(rency)?/i',
|
||||
'dataPattern' => '/^[A-Z]{3}$/',
|
||||
'export' => true,
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_financial_trxn',
|
||||
'entity' => 'FinancialTrxn',
|
||||
'bao' => 'CRM_Financial_DAO_FinancialTrxn',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'table' => 'civicrm_currency',
|
||||
'keyColumn' => 'name',
|
||||
'labelColumn' => 'full_name',
|
||||
'nameColumn' => 'name',
|
||||
)
|
||||
) ,
|
||||
'is_payment' => array(
|
||||
'name' => 'is_payment',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Is Payment?') ,
|
||||
'description' => 'Is this entry either a payment or a reversal of a payment?',
|
||||
'import' => true,
|
||||
'where' => 'civicrm_financial_trxn.is_payment',
|
||||
'headerPattern' => '',
|
||||
'dataPattern' => '',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_financial_trxn',
|
||||
'entity' => 'FinancialTrxn',
|
||||
'bao' => 'CRM_Financial_DAO_FinancialTrxn',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'trxn_id' => array(
|
||||
'name' => 'trxn_id',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Transaction ID') ,
|
||||
'description' => 'Transaction id supplied by external processor. This may not be unique.',
|
||||
'maxlength' => 255,
|
||||
'size' => 10,
|
||||
'table_name' => 'civicrm_financial_trxn',
|
||||
'entity' => 'FinancialTrxn',
|
||||
'bao' => 'CRM_Financial_DAO_FinancialTrxn',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
'trxn_result_code' => array(
|
||||
'name' => 'trxn_result_code',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Transaction Result Code') ,
|
||||
'description' => 'processor result code',
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_financial_trxn',
|
||||
'entity' => 'FinancialTrxn',
|
||||
'bao' => 'CRM_Financial_DAO_FinancialTrxn',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'status_id' => array(
|
||||
'name' => 'status_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Financial Transaction Status Id') ,
|
||||
'description' => 'pseudo FK to civicrm_option_value of contribution_status_id option_group',
|
||||
'import' => true,
|
||||
'where' => 'civicrm_financial_trxn.status_id',
|
||||
'headerPattern' => '/status/i',
|
||||
'dataPattern' => '',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_financial_trxn',
|
||||
'entity' => 'FinancialTrxn',
|
||||
'bao' => 'CRM_Financial_DAO_FinancialTrxn',
|
||||
'localizable' => 0,
|
||||
'pseudoconstant' => array(
|
||||
'optionGroupName' => 'contribution_status',
|
||||
'optionEditPath' => 'civicrm/admin/options/contribution_status',
|
||||
)
|
||||
) ,
|
||||
'payment_processor_id' => array(
|
||||
'name' => 'payment_processor_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Payment Processor') ,
|
||||
'description' => 'Payment Processor for this financial transaction',
|
||||
'table_name' => 'civicrm_financial_trxn',
|
||||
'entity' => 'FinancialTrxn',
|
||||
'bao' => 'CRM_Financial_DAO_FinancialTrxn',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Financial_DAO_PaymentProcessor',
|
||||
) ,
|
||||
'financial_trxn_payment_instrument_id' => array(
|
||||
'name' => 'payment_instrument_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Payment Method') ,
|
||||
'description' => 'FK to payment_instrument option group values',
|
||||
'table_name' => 'civicrm_financial_trxn',
|
||||
'entity' => 'FinancialTrxn',
|
||||
'bao' => 'CRM_Financial_DAO_FinancialTrxn',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'optionGroupName' => 'payment_instrument',
|
||||
'optionEditPath' => 'civicrm/admin/options/payment_instrument',
|
||||
)
|
||||
) ,
|
||||
'financial_trxn_card_type_id' => array(
|
||||
'name' => 'card_type_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Card Type ID') ,
|
||||
'description' => 'FK to accept_creditcard option group values',
|
||||
'table_name' => 'civicrm_financial_trxn',
|
||||
'entity' => 'FinancialTrxn',
|
||||
'bao' => 'CRM_Financial_DAO_FinancialTrxn',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'optionGroupName' => 'accept_creditcard',
|
||||
'optionEditPath' => 'civicrm/admin/options/accept_creditcard',
|
||||
)
|
||||
) ,
|
||||
'financial_trxn_check_number' => array(
|
||||
'name' => 'check_number',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Check Number') ,
|
||||
'description' => 'Check number',
|
||||
'maxlength' => 255,
|
||||
'size' => 6,
|
||||
'table_name' => 'civicrm_financial_trxn',
|
||||
'entity' => 'FinancialTrxn',
|
||||
'bao' => 'CRM_Financial_DAO_FinancialTrxn',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
'financial_trxn_pan_truncation' => array(
|
||||
'name' => 'pan_truncation',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Pan Truncation') ,
|
||||
'description' => 'Last 4 digits of credit card',
|
||||
'maxlength' => 4,
|
||||
'size' => 4,
|
||||
'table_name' => 'civicrm_financial_trxn',
|
||||
'entity' => 'FinancialTrxn',
|
||||
'bao' => 'CRM_Financial_DAO_FinancialTrxn',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
);
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fields'];
|
||||
}
|
||||
/**
|
||||
* Return a mapping from field-name to the corresponding key (as used in fields()).
|
||||
*
|
||||
* @return array
|
||||
* Array(string $name => string $uniqueName).
|
||||
*/
|
||||
static function &fieldKeys() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
|
||||
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fieldKeys'];
|
||||
}
|
||||
/**
|
||||
* Returns the names of this table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function getTableName() {
|
||||
return self::$_tableName;
|
||||
}
|
||||
/**
|
||||
* Returns if this table needs to be logged
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function getLog() {
|
||||
return self::$_log;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be imported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &import($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'financial_trxn', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be exported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &export($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'financial_trxn', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of indices
|
||||
*/
|
||||
public static function indices($localize = TRUE) {
|
||||
$indices = array(
|
||||
'UI_ftrxn_trxn_id' => array(
|
||||
'name' => 'UI_ftrxn_trxn_id',
|
||||
'field' => array(
|
||||
0 => 'trxn_id',
|
||||
) ,
|
||||
'localizable' => false,
|
||||
'sig' => 'civicrm_financial_trxn::0::trxn_id',
|
||||
) ,
|
||||
'UI_ftrxn_payment_instrument_id' => array(
|
||||
'name' => 'UI_ftrxn_payment_instrument_id',
|
||||
'field' => array(
|
||||
0 => 'payment_instrument_id',
|
||||
) ,
|
||||
'localizable' => false,
|
||||
'sig' => 'civicrm_financial_trxn::0::payment_instrument_id',
|
||||
) ,
|
||||
'UI_ftrxn_check_number' => array(
|
||||
'name' => 'UI_ftrxn_check_number',
|
||||
'field' => array(
|
||||
0 => 'check_number',
|
||||
) ,
|
||||
'localizable' => false,
|
||||
'sig' => 'civicrm_financial_trxn::0::check_number',
|
||||
) ,
|
||||
);
|
||||
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
|
||||
}
|
||||
}
|
248
sites/all/modules/civicrm/CRM/Financial/DAO/FinancialType.php
Normal file
248
sites/all/modules/civicrm/CRM/Financial/DAO/FinancialType.php
Normal file
|
@ -0,0 +1,248 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
/**
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*
|
||||
* Generated from xml/schema/CRM/Financial/FinancialType.xml
|
||||
* DO NOT EDIT. Generated by CRM_Core_CodeGen
|
||||
* (GenCodeChecksum:9d787931917508983d68631821eea721)
|
||||
*/
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
require_once 'CRM/Utils/Type.php';
|
||||
/**
|
||||
* CRM_Financial_DAO_FinancialType constructor.
|
||||
*/
|
||||
class CRM_Financial_DAO_FinancialType extends CRM_Core_DAO {
|
||||
/**
|
||||
* Static instance to hold the table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $_tableName = 'civicrm_financial_type';
|
||||
/**
|
||||
* Should CiviCRM log any modifications to this table in the civicrm_log table.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
static $_log = true;
|
||||
/**
|
||||
* ID of original financial_type so you can search this table by the financial_type.id and then select the relevant version based on the timestamp
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* Financial Type Name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
/**
|
||||
* Financial Type Description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $description;
|
||||
/**
|
||||
* Is this financial type tax-deductible? If true, contributions of this type may be fully OR partially deductible - non-deductible amount is stored in the Contribution record.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_deductible;
|
||||
/**
|
||||
* Is this a predefined system object?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_reserved;
|
||||
/**
|
||||
* Is this property active?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_active;
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->__table = 'civicrm_financial_type';
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* Returns all the column names of this table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &fields() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
|
||||
Civi::$statics[__CLASS__]['fields'] = array(
|
||||
'id' => array(
|
||||
'name' => 'id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Financial Type ID') ,
|
||||
'description' => 'ID of original financial_type so you can search this table by the financial_type.id and then select the relevant version based on the timestamp',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_financial_type',
|
||||
'entity' => 'FinancialType',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'financial_type' => array(
|
||||
'name' => 'name',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Financial Type') ,
|
||||
'description' => 'Financial Type Name.',
|
||||
'required' => true,
|
||||
'maxlength' => 64,
|
||||
'size' => CRM_Utils_Type::BIG,
|
||||
'import' => true,
|
||||
'where' => 'civicrm_financial_type.name',
|
||||
'headerPattern' => '/(finan(cial)?)?type/i',
|
||||
'dataPattern' => '/donation|member|campaign/i',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_financial_type',
|
||||
'entity' => 'FinancialType',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'description' => array(
|
||||
'name' => 'description',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Description') ,
|
||||
'description' => 'Financial Type Description.',
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_financial_type',
|
||||
'entity' => 'FinancialType',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'is_deductible' => array(
|
||||
'name' => 'is_deductible',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Is Tax Deductible?') ,
|
||||
'description' => 'Is this financial type tax-deductible? If true, contributions of this type may be fully OR partially deductible - non-deductible amount is stored in the Contribution record.',
|
||||
'default' => '1',
|
||||
'table_name' => 'civicrm_financial_type',
|
||||
'entity' => 'FinancialType',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'is_reserved' => array(
|
||||
'name' => 'is_reserved',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Financial Type is Reserved?') ,
|
||||
'description' => 'Is this a predefined system object?',
|
||||
'table_name' => 'civicrm_financial_type',
|
||||
'entity' => 'FinancialType',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'is_active' => array(
|
||||
'name' => 'is_active',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Financial Type Is Active?') ,
|
||||
'description' => 'Is this property active?',
|
||||
'table_name' => 'civicrm_financial_type',
|
||||
'entity' => 'FinancialType',
|
||||
'bao' => 'CRM_Financial_BAO_FinancialType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
);
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fields'];
|
||||
}
|
||||
/**
|
||||
* Return a mapping from field-name to the corresponding key (as used in fields()).
|
||||
*
|
||||
* @return array
|
||||
* Array(string $name => string $uniqueName).
|
||||
*/
|
||||
static function &fieldKeys() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
|
||||
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fieldKeys'];
|
||||
}
|
||||
/**
|
||||
* Returns the names of this table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function getTableName() {
|
||||
return self::$_tableName;
|
||||
}
|
||||
/**
|
||||
* Returns if this table needs to be logged
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function getLog() {
|
||||
return self::$_log;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be imported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &import($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'financial_type', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be exported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &export($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'financial_type', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of indices
|
||||
*/
|
||||
public static function indices($localize = TRUE) {
|
||||
$indices = array(
|
||||
'UI_id' => array(
|
||||
'name' => 'UI_id',
|
||||
'field' => array(
|
||||
0 => 'id',
|
||||
) ,
|
||||
'localizable' => false,
|
||||
'unique' => true,
|
||||
'sig' => 'civicrm_financial_type::1::id',
|
||||
) ,
|
||||
);
|
||||
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
|
||||
}
|
||||
}
|
560
sites/all/modules/civicrm/CRM/Financial/DAO/PaymentProcessor.php
Normal file
560
sites/all/modules/civicrm/CRM/Financial/DAO/PaymentProcessor.php
Normal file
|
@ -0,0 +1,560 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
/**
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*
|
||||
* Generated from xml/schema/CRM/Financial/PaymentProcessor.xml
|
||||
* DO NOT EDIT. Generated by CRM_Core_CodeGen
|
||||
* (GenCodeChecksum:223b44e4b9e2994f724d2dbd79f575e4)
|
||||
*/
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
require_once 'CRM/Utils/Type.php';
|
||||
/**
|
||||
* CRM_Financial_DAO_PaymentProcessor constructor.
|
||||
*/
|
||||
class CRM_Financial_DAO_PaymentProcessor extends CRM_Core_DAO {
|
||||
/**
|
||||
* Static instance to hold the table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $_tableName = 'civicrm_payment_processor';
|
||||
/**
|
||||
* Should CiviCRM log any modifications to this table in the civicrm_log table.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
static $_log = false;
|
||||
/**
|
||||
* Payment Processor ID
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* Which Domain is this match entry for
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $domain_id;
|
||||
/**
|
||||
* Payment Processor Name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
/**
|
||||
* Payment Processor Description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $description;
|
||||
/**
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $payment_processor_type_id;
|
||||
/**
|
||||
* Is this processor active?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_active;
|
||||
/**
|
||||
* Is this processor the default?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_default;
|
||||
/**
|
||||
* Is this processor for a test site?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_test;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $user_name;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $password;
|
||||
/**
|
||||
*
|
||||
* @var text
|
||||
*/
|
||||
public $signature;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $url_site;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $url_api;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $url_recur;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $url_button;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subject;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $class_name;
|
||||
/**
|
||||
* Billing Mode (deprecated)
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $billing_mode;
|
||||
/**
|
||||
* Can process recurring contributions
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_recur;
|
||||
/**
|
||||
* Payment Type: Credit or Debit (deprecated)
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $payment_type;
|
||||
/**
|
||||
* Payment Instrument ID
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $payment_instrument_id;
|
||||
/**
|
||||
* array of accepted credit card types
|
||||
*
|
||||
* @var text
|
||||
*/
|
||||
public $accepted_credit_cards;
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->__table = 'civicrm_payment_processor';
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* Returns foreign keys and entity references.
|
||||
*
|
||||
* @return array
|
||||
* [CRM_Core_Reference_Interface]
|
||||
*/
|
||||
static function getReferenceColumns() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['links'])) {
|
||||
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'domain_id', 'civicrm_domain', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'payment_processor_type_id', 'civicrm_payment_processor_type', 'id');
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['links'];
|
||||
}
|
||||
/**
|
||||
* Returns all the column names of this table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &fields() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
|
||||
Civi::$statics[__CLASS__]['fields'] = array(
|
||||
'id' => array(
|
||||
'name' => 'id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Payment Processor ID') ,
|
||||
'description' => 'Payment Processor ID',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_payment_processor',
|
||||
'entity' => 'PaymentProcessor',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'domain_id' => array(
|
||||
'name' => 'domain_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Payment Processor Domain') ,
|
||||
'description' => 'Which Domain is this match entry for',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_payment_processor',
|
||||
'entity' => 'PaymentProcessor',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Core_DAO_Domain',
|
||||
'pseudoconstant' => array(
|
||||
'table' => 'civicrm_domain',
|
||||
'keyColumn' => 'id',
|
||||
'labelColumn' => 'name',
|
||||
)
|
||||
) ,
|
||||
'name' => array(
|
||||
'name' => 'name',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Payment Processor') ,
|
||||
'description' => 'Payment Processor Name.',
|
||||
'maxlength' => 64,
|
||||
'size' => CRM_Utils_Type::BIG,
|
||||
'table_name' => 'civicrm_payment_processor',
|
||||
'entity' => 'PaymentProcessor',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
'description' => array(
|
||||
'name' => 'description',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Processor Description') ,
|
||||
'description' => 'Payment Processor Description.',
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_processor',
|
||||
'entity' => 'PaymentProcessor',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'payment_processor_type_id' => array(
|
||||
'name' => 'payment_processor_type_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Payment Processor Type ID') ,
|
||||
'table_name' => 'civicrm_payment_processor',
|
||||
'entity' => 'PaymentProcessor',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Financial_DAO_PaymentProcessorType',
|
||||
'pseudoconstant' => array(
|
||||
'table' => 'civicrm_payment_processor_type',
|
||||
'keyColumn' => 'id',
|
||||
'labelColumn' => 'title',
|
||||
)
|
||||
) ,
|
||||
'is_active' => array(
|
||||
'name' => 'is_active',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Processor is Active?') ,
|
||||
'description' => 'Is this processor active?',
|
||||
'table_name' => 'civicrm_payment_processor',
|
||||
'entity' => 'PaymentProcessor',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'is_default' => array(
|
||||
'name' => 'is_default',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Processor Is Default?') ,
|
||||
'description' => 'Is this processor the default?',
|
||||
'table_name' => 'civicrm_payment_processor',
|
||||
'entity' => 'PaymentProcessor',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'is_test' => array(
|
||||
'name' => 'is_test',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Is Test Processor?') ,
|
||||
'description' => 'Is this processor for a test site?',
|
||||
'table_name' => 'civicrm_payment_processor',
|
||||
'entity' => 'PaymentProcessor',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'user_name' => array(
|
||||
'name' => 'user_name',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('User Name') ,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_processor',
|
||||
'entity' => 'PaymentProcessor',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
'password' => array(
|
||||
'name' => 'password',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Password') ,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_processor',
|
||||
'entity' => 'PaymentProcessor',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Password',
|
||||
) ,
|
||||
) ,
|
||||
'signature' => array(
|
||||
'name' => 'signature',
|
||||
'type' => CRM_Utils_Type::T_TEXT,
|
||||
'title' => ts('Signature') ,
|
||||
'rows' => 4,
|
||||
'cols' => 40,
|
||||
'table_name' => 'civicrm_payment_processor',
|
||||
'entity' => 'PaymentProcessor',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'TextArea',
|
||||
) ,
|
||||
) ,
|
||||
'url_site' => array(
|
||||
'name' => 'url_site',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Site URL') ,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_processor',
|
||||
'entity' => 'PaymentProcessor',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
'url_api' => array(
|
||||
'name' => 'url_api',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('API URL') ,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_processor',
|
||||
'entity' => 'PaymentProcessor',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
'url_recur' => array(
|
||||
'name' => 'url_recur',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Recurring Payments URL') ,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_processor',
|
||||
'entity' => 'PaymentProcessor',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
'url_button' => array(
|
||||
'name' => 'url_button',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Button URL') ,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_processor',
|
||||
'entity' => 'PaymentProcessor',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
'subject' => array(
|
||||
'name' => 'subject',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Subject') ,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_processor',
|
||||
'entity' => 'PaymentProcessor',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
'class_name' => array(
|
||||
'name' => 'class_name',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Suffix for PHP class name implementation') ,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_processor',
|
||||
'entity' => 'PaymentProcessor',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'billing_mode' => array(
|
||||
'name' => 'billing_mode',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Processor Billing Mode') ,
|
||||
'description' => 'Billing Mode (deprecated)',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_payment_processor',
|
||||
'entity' => 'PaymentProcessor',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'is_recur' => array(
|
||||
'name' => 'is_recur',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Processor Supports Recurring?') ,
|
||||
'description' => 'Can process recurring contributions',
|
||||
'table_name' => 'civicrm_payment_processor',
|
||||
'entity' => 'PaymentProcessor',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'payment_type' => array(
|
||||
'name' => 'payment_type',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Payment Type') ,
|
||||
'description' => 'Payment Type: Credit or Debit (deprecated)',
|
||||
'default' => '1',
|
||||
'table_name' => 'civicrm_payment_processor',
|
||||
'entity' => 'PaymentProcessor',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'payment_instrument_id' => array(
|
||||
'name' => 'payment_instrument_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Payment Method') ,
|
||||
'description' => 'Payment Instrument ID',
|
||||
'default' => '1',
|
||||
'table_name' => 'civicrm_payment_processor',
|
||||
'entity' => 'PaymentProcessor',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
|
||||
'localizable' => 0,
|
||||
'pseudoconstant' => array(
|
||||
'optionGroupName' => 'payment_instrument',
|
||||
'optionEditPath' => 'civicrm/admin/options/payment_instrument',
|
||||
)
|
||||
) ,
|
||||
'accepted_credit_cards' => array(
|
||||
'name' => 'accepted_credit_cards',
|
||||
'type' => CRM_Utils_Type::T_TEXT,
|
||||
'title' => ts('Accepted Credit Cards') ,
|
||||
'description' => 'array of accepted credit card types',
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_payment_processor',
|
||||
'entity' => 'PaymentProcessor',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
);
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fields'];
|
||||
}
|
||||
/**
|
||||
* Return a mapping from field-name to the corresponding key (as used in fields()).
|
||||
*
|
||||
* @return array
|
||||
* Array(string $name => string $uniqueName).
|
||||
*/
|
||||
static function &fieldKeys() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
|
||||
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fieldKeys'];
|
||||
}
|
||||
/**
|
||||
* Returns the names of this table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function getTableName() {
|
||||
return self::$_tableName;
|
||||
}
|
||||
/**
|
||||
* Returns if this table needs to be logged
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function getLog() {
|
||||
return self::$_log;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be imported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &import($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'payment_processor', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be exported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &export($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'payment_processor', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of indices
|
||||
*/
|
||||
public static function indices($localize = TRUE) {
|
||||
$indices = array(
|
||||
'UI_name_test_domain_id' => array(
|
||||
'name' => 'UI_name_test_domain_id',
|
||||
'field' => array(
|
||||
0 => 'name',
|
||||
1 => 'is_test',
|
||||
2 => 'domain_id',
|
||||
) ,
|
||||
'localizable' => false,
|
||||
'unique' => true,
|
||||
'sig' => 'civicrm_payment_processor::1::name::is_test::domain_id',
|
||||
) ,
|
||||
);
|
||||
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,528 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
/**
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*
|
||||
* Generated from xml/schema/CRM/Financial/PaymentProcessorType.xml
|
||||
* DO NOT EDIT. Generated by CRM_Core_CodeGen
|
||||
* (GenCodeChecksum:b47064fa57473507062b1e69983ccc52)
|
||||
*/
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
require_once 'CRM/Utils/Type.php';
|
||||
/**
|
||||
* CRM_Financial_DAO_PaymentProcessorType constructor.
|
||||
*/
|
||||
class CRM_Financial_DAO_PaymentProcessorType extends CRM_Core_DAO {
|
||||
/**
|
||||
* Static instance to hold the table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $_tableName = 'civicrm_payment_processor_type';
|
||||
/**
|
||||
* Should CiviCRM log any modifications to this table in the civicrm_log table.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
static $_log = false;
|
||||
/**
|
||||
* Payment Processor Type ID
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* Payment Processor Name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
/**
|
||||
* Payment Processor Name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $title;
|
||||
/**
|
||||
* Payment Processor Description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $description;
|
||||
/**
|
||||
* Is this processor active?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_active;
|
||||
/**
|
||||
* Is this processor the default?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_default;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $user_name_label;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $password_label;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $signature_label;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subject_label;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $class_name;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $url_site_default;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $url_api_default;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $url_recur_default;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $url_button_default;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $url_site_test_default;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $url_api_test_default;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $url_recur_test_default;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $url_button_test_default;
|
||||
/**
|
||||
* Billing Mode (deprecated)
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $billing_mode;
|
||||
/**
|
||||
* Can process recurring contributions
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_recur;
|
||||
/**
|
||||
* Payment Type: Credit or Debit (deprecated)
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $payment_type;
|
||||
/**
|
||||
* Payment Instrument ID
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $payment_instrument_id;
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->__table = 'civicrm_payment_processor_type';
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* Returns all the column names of this table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &fields() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
|
||||
Civi::$statics[__CLASS__]['fields'] = array(
|
||||
'id' => array(
|
||||
'name' => 'id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Payment Processor Type ID') ,
|
||||
'description' => 'Payment Processor Type ID',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_payment_processor_type',
|
||||
'entity' => 'PaymentProcessorType',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'name' => array(
|
||||
'name' => 'name',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Payment Processor variable name to be used in code') ,
|
||||
'description' => 'Payment Processor Name.',
|
||||
'maxlength' => 64,
|
||||
'size' => CRM_Utils_Type::BIG,
|
||||
'table_name' => 'civicrm_payment_processor_type',
|
||||
'entity' => 'PaymentProcessorType',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'title' => array(
|
||||
'name' => 'title',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Payment Processor Title') ,
|
||||
'description' => 'Payment Processor Name.',
|
||||
'maxlength' => 127,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_processor_type',
|
||||
'entity' => 'PaymentProcessorType',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'description' => array(
|
||||
'name' => 'description',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Processor Type Description') ,
|
||||
'description' => 'Payment Processor Description.',
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_processor_type',
|
||||
'entity' => 'PaymentProcessorType',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'is_active' => array(
|
||||
'name' => 'is_active',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Processor Type Is Active?') ,
|
||||
'description' => 'Is this processor active?',
|
||||
'table_name' => 'civicrm_payment_processor_type',
|
||||
'entity' => 'PaymentProcessorType',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'is_default' => array(
|
||||
'name' => 'is_default',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Processor Type is Default?') ,
|
||||
'description' => 'Is this processor the default?',
|
||||
'table_name' => 'civicrm_payment_processor_type',
|
||||
'entity' => 'PaymentProcessorType',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'user_name_label' => array(
|
||||
'name' => 'user_name_label',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Label for User Name if used') ,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_processor_type',
|
||||
'entity' => 'PaymentProcessorType',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'password_label' => array(
|
||||
'name' => 'password_label',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Label for password') ,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_processor_type',
|
||||
'entity' => 'PaymentProcessorType',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'signature_label' => array(
|
||||
'name' => 'signature_label',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Label for Signature') ,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_processor_type',
|
||||
'entity' => 'PaymentProcessorType',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'subject_label' => array(
|
||||
'name' => 'subject_label',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Label for Subject') ,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_processor_type',
|
||||
'entity' => 'PaymentProcessorType',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'class_name' => array(
|
||||
'name' => 'class_name',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Suffix for PHP class name implementation') ,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_processor_type',
|
||||
'entity' => 'PaymentProcessorType',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'url_site_default' => array(
|
||||
'name' => 'url_site_default',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Default Live Site URL') ,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_processor_type',
|
||||
'entity' => 'PaymentProcessorType',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'url_api_default' => array(
|
||||
'name' => 'url_api_default',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Default API Site URL') ,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_processor_type',
|
||||
'entity' => 'PaymentProcessorType',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'url_recur_default' => array(
|
||||
'name' => 'url_recur_default',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Default Live Recurring Payments URL') ,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_processor_type',
|
||||
'entity' => 'PaymentProcessorType',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'url_button_default' => array(
|
||||
'name' => 'url_button_default',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Default Live Button URL') ,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_processor_type',
|
||||
'entity' => 'PaymentProcessorType',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'url_site_test_default' => array(
|
||||
'name' => 'url_site_test_default',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Default Test Site URL') ,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_processor_type',
|
||||
'entity' => 'PaymentProcessorType',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'url_api_test_default' => array(
|
||||
'name' => 'url_api_test_default',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Default Test API URL') ,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_processor_type',
|
||||
'entity' => 'PaymentProcessorType',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'url_recur_test_default' => array(
|
||||
'name' => 'url_recur_test_default',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Default Test Recurring Payment URL') ,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_processor_type',
|
||||
'entity' => 'PaymentProcessorType',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'url_button_test_default' => array(
|
||||
'name' => 'url_button_test_default',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Default Test Button URL') ,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_processor_type',
|
||||
'entity' => 'PaymentProcessorType',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'billing_mode' => array(
|
||||
'name' => 'billing_mode',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Billing Mode') ,
|
||||
'description' => 'Billing Mode (deprecated)',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_payment_processor_type',
|
||||
'entity' => 'PaymentProcessorType',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'callback' => 'CRM_Core_SelectValues::billingMode',
|
||||
)
|
||||
) ,
|
||||
'is_recur' => array(
|
||||
'name' => 'is_recur',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Processor Type Supports Recurring?') ,
|
||||
'description' => 'Can process recurring contributions',
|
||||
'table_name' => 'civicrm_payment_processor_type',
|
||||
'entity' => 'PaymentProcessorType',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'payment_type' => array(
|
||||
'name' => 'payment_type',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Processor Type Payment Type') ,
|
||||
'description' => 'Payment Type: Credit or Debit (deprecated)',
|
||||
'default' => '1',
|
||||
'table_name' => 'civicrm_payment_processor_type',
|
||||
'entity' => 'PaymentProcessorType',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'payment_instrument_id' => array(
|
||||
'name' => 'payment_instrument_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Payment Method') ,
|
||||
'description' => 'Payment Instrument ID',
|
||||
'default' => '1',
|
||||
'table_name' => 'civicrm_payment_processor_type',
|
||||
'entity' => 'PaymentProcessorType',
|
||||
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
|
||||
'localizable' => 0,
|
||||
'pseudoconstant' => array(
|
||||
'optionGroupName' => 'payment_instrument',
|
||||
'optionEditPath' => 'civicrm/admin/options/payment_instrument',
|
||||
)
|
||||
) ,
|
||||
);
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fields'];
|
||||
}
|
||||
/**
|
||||
* Return a mapping from field-name to the corresponding key (as used in fields()).
|
||||
*
|
||||
* @return array
|
||||
* Array(string $name => string $uniqueName).
|
||||
*/
|
||||
static function &fieldKeys() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
|
||||
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fieldKeys'];
|
||||
}
|
||||
/**
|
||||
* Returns the names of this table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function getTableName() {
|
||||
return self::$_tableName;
|
||||
}
|
||||
/**
|
||||
* Returns if this table needs to be logged
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function getLog() {
|
||||
return self::$_log;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be imported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &import($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'payment_processor_type', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be exported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &export($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'payment_processor_type', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of indices
|
||||
*/
|
||||
public static function indices($localize = TRUE) {
|
||||
$indices = array(
|
||||
'UI_name' => array(
|
||||
'name' => 'UI_name',
|
||||
'field' => array(
|
||||
0 => 'name',
|
||||
) ,
|
||||
'localizable' => false,
|
||||
'unique' => true,
|
||||
'sig' => 'civicrm_payment_processor_type::1::name',
|
||||
) ,
|
||||
);
|
||||
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
|
||||
}
|
||||
}
|
374
sites/all/modules/civicrm/CRM/Financial/DAO/PaymentToken.php
Normal file
374
sites/all/modules/civicrm/CRM/Financial/DAO/PaymentToken.php
Normal file
|
@ -0,0 +1,374 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
/**
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*
|
||||
* Generated from xml/schema/CRM/Financial/PaymentToken.xml
|
||||
* DO NOT EDIT. Generated by CRM_Core_CodeGen
|
||||
* (GenCodeChecksum:6b3810f34b7a2c1aacecfb67f1d09b42)
|
||||
*/
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
require_once 'CRM/Utils/Type.php';
|
||||
/**
|
||||
* CRM_Financial_DAO_PaymentToken constructor.
|
||||
*/
|
||||
class CRM_Financial_DAO_PaymentToken extends CRM_Core_DAO {
|
||||
/**
|
||||
* Static instance to hold the table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $_tableName = 'civicrm_payment_token';
|
||||
/**
|
||||
* Should CiviCRM log any modifications to this table in the civicrm_log table.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
static $_log = false;
|
||||
/**
|
||||
* Payment Token ID
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* FK to Contact ID for the owner of the token
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $contact_id;
|
||||
/**
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $payment_processor_id;
|
||||
/**
|
||||
* Externally provided token string
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $token;
|
||||
/**
|
||||
* Date created
|
||||
*
|
||||
* @var timestamp
|
||||
*/
|
||||
public $created_date;
|
||||
/**
|
||||
* Contact ID of token creator
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $created_id;
|
||||
/**
|
||||
* Date this token expires
|
||||
*
|
||||
* @var datetime
|
||||
*/
|
||||
public $expiry_date;
|
||||
/**
|
||||
* Email at the time of token creation. Useful for fraud forensics
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $email;
|
||||
/**
|
||||
* Billing first name at the time of token creation. Useful for fraud forensics
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $billing_first_name;
|
||||
/**
|
||||
* Billing middle name at the time of token creation. Useful for fraud forensics
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $billing_middle_name;
|
||||
/**
|
||||
* Billing last name at the time of token creation. Useful for fraud forensics
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $billing_last_name;
|
||||
/**
|
||||
* Holds the part of the card number or account details that may be retained or displayed
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $masked_account_number;
|
||||
/**
|
||||
* IP used when creating the token. Useful for fraud forensics
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $ip_address;
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->__table = 'civicrm_payment_token';
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* Returns foreign keys and entity references.
|
||||
*
|
||||
* @return array
|
||||
* [CRM_Core_Reference_Interface]
|
||||
*/
|
||||
static function getReferenceColumns() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['links'])) {
|
||||
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'contact_id', 'civicrm_contact', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'payment_processor_id', 'civicrm_payment_processor', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'created_id', 'civicrm_contact', 'id');
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['links'];
|
||||
}
|
||||
/**
|
||||
* Returns all the column names of this table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &fields() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
|
||||
Civi::$statics[__CLASS__]['fields'] = array(
|
||||
'payment_token_id' => array(
|
||||
'name' => 'id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Payment Token ID') ,
|
||||
'description' => 'Payment Token ID',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_payment_token',
|
||||
'entity' => 'PaymentToken',
|
||||
'bao' => 'CRM_Financial_DAO_PaymentToken',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'contact_id' => array(
|
||||
'name' => 'contact_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Contact ID') ,
|
||||
'description' => 'FK to Contact ID for the owner of the token',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_payment_token',
|
||||
'entity' => 'PaymentToken',
|
||||
'bao' => 'CRM_Financial_DAO_PaymentToken',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Contact_DAO_Contact',
|
||||
) ,
|
||||
'payment_processor_id' => array(
|
||||
'name' => 'payment_processor_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Payment Processor ID') ,
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_payment_token',
|
||||
'entity' => 'PaymentToken',
|
||||
'bao' => 'CRM_Financial_DAO_PaymentToken',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Financial_DAO_PaymentProcessor',
|
||||
) ,
|
||||
'token' => array(
|
||||
'name' => 'token',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Token') ,
|
||||
'description' => 'Externally provided token string',
|
||||
'required' => true,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_token',
|
||||
'entity' => 'PaymentToken',
|
||||
'bao' => 'CRM_Financial_DAO_PaymentToken',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'created_date' => array(
|
||||
'name' => 'created_date',
|
||||
'type' => CRM_Utils_Type::T_TIMESTAMP,
|
||||
'title' => ts('Created Date') ,
|
||||
'description' => 'Date created',
|
||||
'default' => 'CURRENT_TIMESTAMP',
|
||||
'table_name' => 'civicrm_payment_token',
|
||||
'entity' => 'PaymentToken',
|
||||
'bao' => 'CRM_Financial_DAO_PaymentToken',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'created_id' => array(
|
||||
'name' => 'created_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Created ID') ,
|
||||
'description' => 'Contact ID of token creator',
|
||||
'table_name' => 'civicrm_payment_token',
|
||||
'entity' => 'PaymentToken',
|
||||
'bao' => 'CRM_Financial_DAO_PaymentToken',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Contact_DAO_Contact',
|
||||
) ,
|
||||
'expiry_date' => array(
|
||||
'name' => 'expiry_date',
|
||||
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
|
||||
'title' => ts('Expiry Date') ,
|
||||
'description' => 'Date this token expires',
|
||||
'table_name' => 'civicrm_payment_token',
|
||||
'entity' => 'PaymentToken',
|
||||
'bao' => 'CRM_Financial_DAO_PaymentToken',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'email' => array(
|
||||
'name' => 'email',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Email') ,
|
||||
'description' => 'Email at the time of token creation. Useful for fraud forensics',
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_token',
|
||||
'entity' => 'PaymentToken',
|
||||
'bao' => 'CRM_Financial_DAO_PaymentToken',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'billing_first_name' => array(
|
||||
'name' => 'billing_first_name',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Billing First Name') ,
|
||||
'description' => 'Billing first name at the time of token creation. Useful for fraud forensics',
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_token',
|
||||
'entity' => 'PaymentToken',
|
||||
'bao' => 'CRM_Financial_DAO_PaymentToken',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'billing_middle_name' => array(
|
||||
'name' => 'billing_middle_name',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Billing Middle Name') ,
|
||||
'description' => 'Billing middle name at the time of token creation. Useful for fraud forensics',
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_token',
|
||||
'entity' => 'PaymentToken',
|
||||
'bao' => 'CRM_Financial_DAO_PaymentToken',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'billing_last_name' => array(
|
||||
'name' => 'billing_last_name',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Billing Last Name') ,
|
||||
'description' => 'Billing last name at the time of token creation. Useful for fraud forensics',
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_token',
|
||||
'entity' => 'PaymentToken',
|
||||
'bao' => 'CRM_Financial_DAO_PaymentToken',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'masked_account_number' => array(
|
||||
'name' => 'masked_account_number',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Masked Account Number') ,
|
||||
'description' => 'Holds the part of the card number or account details that may be retained or displayed',
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_token',
|
||||
'entity' => 'PaymentToken',
|
||||
'bao' => 'CRM_Financial_DAO_PaymentToken',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'ip_address' => array(
|
||||
'name' => 'ip_address',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('IP Address') ,
|
||||
'description' => 'IP used when creating the token. Useful for fraud forensics',
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_payment_token',
|
||||
'entity' => 'PaymentToken',
|
||||
'bao' => 'CRM_Financial_DAO_PaymentToken',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
);
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fields'];
|
||||
}
|
||||
/**
|
||||
* Return a mapping from field-name to the corresponding key (as used in fields()).
|
||||
*
|
||||
* @return array
|
||||
* Array(string $name => string $uniqueName).
|
||||
*/
|
||||
static function &fieldKeys() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
|
||||
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fieldKeys'];
|
||||
}
|
||||
/**
|
||||
* Returns the names of this table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function getTableName() {
|
||||
return self::$_tableName;
|
||||
}
|
||||
/**
|
||||
* Returns if this table needs to be logged
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function getLog() {
|
||||
return self::$_log;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be imported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &import($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'payment_token', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be exported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &export($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'payment_token', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of indices
|
||||
*/
|
||||
public static function indices($localize = TRUE) {
|
||||
$indices = array();
|
||||
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,219 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for Financial Type
|
||||
*/
|
||||
class CRM_Financial_Form_BatchTransaction extends CRM_Contribute_Form {
|
||||
static $_links = NULL;
|
||||
static $_entityID;
|
||||
|
||||
/**
|
||||
* Batch status.
|
||||
* @var
|
||||
*/
|
||||
protected $_batchStatusId;
|
||||
|
||||
/**
|
||||
* Batch status name.
|
||||
* @string
|
||||
*/
|
||||
protected $_batchStatus;
|
||||
|
||||
public function preProcess() {
|
||||
// This reuses some styles from search forms
|
||||
CRM_Core_Resources::singleton()->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header');
|
||||
|
||||
self::$_entityID = CRM_Utils_Request::retrieve('bid', 'Positive') ? CRM_Utils_Request::retrieve('bid', 'Positive') : CRM_Utils_Array::value('batch_id', $_POST);
|
||||
$this->assign('entityID', self::$_entityID);
|
||||
if (isset(self::$_entityID)) {
|
||||
$this->_batchStatusId = CRM_Core_DAO::getFieldValue('CRM_Batch_BAO_Batch', self::$_entityID, 'status_id');
|
||||
$batchStatuses = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id', array('labelColumn' => 'name', 'condition' => " v.value={$this->_batchStatusId}"));
|
||||
$this->_batchStatus = $batchStatuses[$this->_batchStatusId];
|
||||
$this->assign('statusID', $this->_batchStatusId);
|
||||
$this->assign('batchStatus', $this->_batchStatus);
|
||||
$validStatus = FALSE;
|
||||
if (in_array($this->_batchStatus, array('Open', 'Reopened'))) {
|
||||
$validStatus = TRUE;
|
||||
}
|
||||
$this->assign('validStatus', $validStatus);
|
||||
$this->_values = civicrm_api3('Batch', 'getSingle', array('id' => self::$_entityID));
|
||||
$batchTitle = CRM_Core_DAO::getFieldValue('CRM_Batch_BAO_Batch', self::$_entityID, 'title');
|
||||
CRM_Utils_System::setTitle(ts('Accounting Batch - %1', array(1 => $batchTitle)));
|
||||
|
||||
$columnHeaders = array(
|
||||
'created_by' => ts('Created By'),
|
||||
'status' => ts('Status'),
|
||||
'description' => ts('Description'),
|
||||
'payment_instrument' => ts('Payment Method'),
|
||||
'item_count' => ts('Expected Number of Items'),
|
||||
'assigned_item_count' => ts('Actual Number of Items'),
|
||||
'total' => ts('Expected Total Amount'),
|
||||
'assigned_total' => ts('Actual Total Amount'),
|
||||
'opened_date' => ts('Opened'),
|
||||
);
|
||||
$this->assign('columnHeaders', $columnHeaders);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
if ($this->_batchStatus == 'Closed') {
|
||||
$this->add('submit', 'export_batch', ts('Export Batch'));
|
||||
}
|
||||
|
||||
// do not build rest of form unless it is open/reopened batch
|
||||
if (!in_array($this->_batchStatus, array('Open', 'Reopened'))) {
|
||||
return;
|
||||
}
|
||||
|
||||
parent::buildQuickForm();
|
||||
if (CRM_Batch_BAO_Batch::checkBatchPermission('close', $this->_values['created_id'])) {
|
||||
$this->add('submit', 'close_batch', ts('Close Batch'));
|
||||
if (CRM_Batch_BAO_Batch::checkBatchPermission('export', $this->_values['created_id'])) {
|
||||
$this->add('submit', 'export_batch', ts('Close & Export Batch'));
|
||||
}
|
||||
}
|
||||
|
||||
// text for sort_name
|
||||
$this->addElement('text',
|
||||
'sort_name',
|
||||
ts('Contributor Name or Email'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact',
|
||||
'sort_name'
|
||||
)
|
||||
);
|
||||
|
||||
$this->_group = CRM_Core_PseudoConstant::nestedGroup();
|
||||
|
||||
// multiselect for groups
|
||||
if ($this->_group) {
|
||||
$this->add('select', 'group', ts('Groups'), $this->_group, FALSE,
|
||||
array('id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2')
|
||||
);
|
||||
}
|
||||
$contactTags = CRM_Core_BAO_Tag::getTags();
|
||||
|
||||
if ($contactTags) {
|
||||
$this->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE,
|
||||
array('id' => 'contact_tags', 'multiple' => 'multiple', 'class' => 'crm-select2')
|
||||
);
|
||||
}
|
||||
CRM_Contribute_BAO_Query::buildSearchForm($this);
|
||||
$this->addElement('checkbox', 'toggleSelects', NULL, NULL);
|
||||
|
||||
$this->add('select',
|
||||
'trans_remove',
|
||||
ts('Task'),
|
||||
array('' => ts('- actions -')) + array('Remove' => ts('Remove from Batch')));
|
||||
|
||||
$this->add('submit', 'rSubmit', ts('Go'),
|
||||
array(
|
||||
'class' => 'crm-form-submit',
|
||||
'id' => 'GoRemove',
|
||||
));
|
||||
|
||||
self::$_entityID = CRM_Utils_Request::retrieve('bid', 'Positive');
|
||||
|
||||
$this->addButtons(
|
||||
array(
|
||||
array(
|
||||
'type' => 'submit',
|
||||
'name' => ts('Search'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement('checkbox', 'toggleSelect', NULL, NULL);
|
||||
$this->add('select',
|
||||
'trans_assign',
|
||||
ts('Task'),
|
||||
array('' => ts('- actions -')) + array('Assign' => ts('Assign to Batch')));
|
||||
|
||||
$this->add('submit', 'submit', ts('Go'),
|
||||
array(
|
||||
'class' => 'crm-form-submit',
|
||||
'id' => 'Go',
|
||||
));
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
|
||||
$this->addElement('hidden', 'batch_id', self::$_entityID);
|
||||
|
||||
$this->add('text', 'name', ts('Batch Name'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default values for the form.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
// do not setdefault unless it is open/reopened batch
|
||||
if (!in_array($this->_batchStatus, array('Open', 'Reopened'))) {
|
||||
return;
|
||||
}
|
||||
if (isset(self::$_entityID)) {
|
||||
$paymentInstrumentID = CRM_Core_DAO::getFieldValue('CRM_Batch_BAO_Batch', self::$_entityID, 'payment_instrument_id');
|
||||
$defaults['payment_instrument_id'] = $paymentInstrumentID;
|
||||
$this->assign('paymentInstrumentID', $paymentInstrumentID);
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action links.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function &links() {
|
||||
if (!(self::$_links)) {
|
||||
self::$_links = array(
|
||||
'view' => array(
|
||||
'name' => ts('View'),
|
||||
'url' => 'civicrm/contact/view/contribution',
|
||||
'qs' => 'reset=1&id=%%contid%%&cid=%%cid%%&action=view&context=contribution&selectedChild=contribute',
|
||||
'title' => ts('View Contribution'),
|
||||
),
|
||||
'assign' => array(
|
||||
'name' => ts('Assign'),
|
||||
'ref' => 'disable-action',
|
||||
'title' => ts('Assign Transaction'),
|
||||
'extra' => 'onclick = "assignRemove( %%id%%,\'' . 'assign' . '\' );"',
|
||||
),
|
||||
);
|
||||
}
|
||||
return self::$_links;
|
||||
}
|
||||
|
||||
}
|
181
sites/all/modules/civicrm/CRM/Financial/Form/Export.php
Normal file
181
sites/all/modules/civicrm/CRM/Financial/Form/Export.php
Normal file
|
@ -0,0 +1,181 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to delete a group of
|
||||
* contributions. This class provides functionality for the actual
|
||||
* deletion.
|
||||
*/
|
||||
class CRM_Financial_Form_Export extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The financial batch id, used when editing the field
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_id;
|
||||
|
||||
/**
|
||||
* Financial batch ids.
|
||||
*/
|
||||
protected $_batchIds = array();
|
||||
|
||||
/**
|
||||
* Export status id.
|
||||
*/
|
||||
protected $_exportStatusId;
|
||||
|
||||
/**
|
||||
* Export format.
|
||||
*/
|
||||
protected $_exportFormat;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
|
||||
|
||||
// this mean it's a batch action
|
||||
if (!$this->_id) {
|
||||
if (!empty($_GET['batch_id'])) {
|
||||
// validate batch ids
|
||||
$batchIds = explode(',', $_GET['batch_id']);
|
||||
foreach ($batchIds as $batchId) {
|
||||
CRM_Utils_Type::validate($batchId, 'Positive');
|
||||
}
|
||||
|
||||
$this->_batchIds = $_GET['batch_id'];
|
||||
$this->set('batchIds', $this->_batchIds);
|
||||
}
|
||||
else {
|
||||
$this->_batchIds = $this->get('batchIds');
|
||||
}
|
||||
if (!empty($_GET['export_format']) && in_array($_GET['export_format'], array('IIF', 'CSV'))) {
|
||||
$this->_exportFormat = $_GET['export_format'];
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->_batchIds = $this->_id;
|
||||
}
|
||||
|
||||
$allBatchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id');
|
||||
$this->_exportStatusId = CRM_Utils_Array::key('Exported', $allBatchStatus);
|
||||
|
||||
// check if batch status is valid, do not allow exported batches to export again
|
||||
$batchStatus = CRM_Batch_BAO_Batch::getBatchStatuses($this->_batchIds);
|
||||
|
||||
foreach ($batchStatus as $batchStatusId) {
|
||||
if ($batchStatusId == $this->_exportStatusId) {
|
||||
$url = CRM_Core_Session::singleton()->readUserContext();
|
||||
CRM_Core_Error::statusBounce(ts('You cannot export batches which have already been exported.'), $url);
|
||||
}
|
||||
}
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/financial/financialbatches',
|
||||
"reset=1&batchStatus={$this->_exportStatusId}"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
// this mean it's a batch action
|
||||
if (!empty($this->_batchIds)) {
|
||||
$batchNames = CRM_Batch_BAO_Batch::getBatchNames($this->_batchIds);
|
||||
$this->assign('batchNames', $batchNames);
|
||||
// Skip building the form if we already have batches and an export format
|
||||
if ($this->_exportFormat) {
|
||||
$this->postProcess();
|
||||
}
|
||||
}
|
||||
|
||||
$optionTypes = array(
|
||||
'IIF' => ts('Export to IIF'),
|
||||
'CSV' => ts('Export to CSV'),
|
||||
);
|
||||
|
||||
$this->addRadio('export_format', NULL, $optionTypes, NULL, '<br/>', TRUE);
|
||||
|
||||
$this->addButtons(
|
||||
array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Export Batch'),
|
||||
'spacing' => ' ',
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
if (!$this->_exportFormat) {
|
||||
$params = $this->exportValues();
|
||||
$this->_exportFormat = $params['export_format'];
|
||||
}
|
||||
|
||||
if ($this->_id) {
|
||||
$batchIds = array($this->_id);
|
||||
}
|
||||
elseif (!empty($this->_batchIds)) {
|
||||
$batchIds = explode(',', $this->_batchIds);
|
||||
}
|
||||
// Recalculate totals
|
||||
$totals = CRM_Batch_BAO_Batch::batchTotals($batchIds);
|
||||
|
||||
// build batch params
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$batchParams['modified_date'] = date('YmdHis');
|
||||
$batchParams['modified_id'] = $session->get('userID');
|
||||
$batchParams['status_id'] = $this->_exportStatusId;
|
||||
|
||||
foreach ($batchIds as $batchId) {
|
||||
$batchParams['id'] = $batchId;
|
||||
// Update totals
|
||||
$batchParams = array_merge($batchParams, $totals[$batchId]);
|
||||
CRM_Batch_BAO_Batch::create($batchParams);
|
||||
}
|
||||
|
||||
CRM_Batch_BAO_Batch::exportFinancialBatch($batchIds, $this->_exportFormat);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,209 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for Financial Account
|
||||
*/
|
||||
class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form {
|
||||
|
||||
/**
|
||||
* Flag if its a AR account type.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_isARFlag = FALSE;
|
||||
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
if ($this->_id) {
|
||||
$params = array(
|
||||
'id' => $this->_id,
|
||||
);
|
||||
$financialAccount = CRM_Financial_BAO_FinancialAccount::retrieve($params, CRM_Core_DAO::$_nullArray);
|
||||
$financialAccountTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name LIKE 'Asset' "));
|
||||
if ($financialAccount->financial_account_type_id == $financialAccountTypeId
|
||||
&& strtolower($financialAccount->account_type_code) == 'ar'
|
||||
&& !CRM_Financial_BAO_FinancialAccount::getARAccounts($this->_id, $financialAccountTypeId)
|
||||
) {
|
||||
$this->_isARFlag = TRUE;
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
$msg = ts("The selected financial account cannot be deleted because at least one Accounts Receivable type account is required (to ensure that accounting transactions are in balance).");
|
||||
CRM_Core_Error::statusBounce($msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
$this->setPageTitle(ts('Financial Account'));
|
||||
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
$attributes = CRM_Core_DAO::getAttribute('CRM_Financial_DAO_FinancialAccount');
|
||||
$this->add('text', 'name', ts('Name'), $attributes['name'], TRUE);
|
||||
$this->addRule('name', ts('A financial type with this name already exists. Please select another name.'),
|
||||
'objectExists', array('CRM_Financial_DAO_FinancialAccount', $this->_id));
|
||||
|
||||
$this->add('text', 'description', ts('Description'), $attributes['description']);
|
||||
$this->add('text', 'accounting_code', ts('Accounting Code'), $attributes['accounting_code']);
|
||||
$elementAccounting = $this->add('text', 'account_type_code', ts('Account Type Code'), $attributes['account_type_code']);
|
||||
$this->addEntityRef('contact_id', ts('Owner'), array(
|
||||
'api' => array('params' => array('contact_type' => 'Organization')),
|
||||
'create' => TRUE,
|
||||
));
|
||||
$this->add('text', 'tax_rate', ts('Tax Rate'), $attributes['tax_rate']);
|
||||
$this->add('checkbox', 'is_deductible', ts('Tax-Deductible?'));
|
||||
$elementActive = $this->add('checkbox', 'is_active', ts('Enabled?'));
|
||||
$this->add('checkbox', 'is_tax', ts('Is Tax?'));
|
||||
|
||||
$element = $this->add('checkbox', 'is_default', ts('Default?'));
|
||||
// CRM-12470 freeze is default if is_default is set
|
||||
if ($this->_id && CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', $this->_id, 'is_default')) {
|
||||
$element->freeze();
|
||||
}
|
||||
|
||||
$financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id');
|
||||
if (!empty($financialAccountType)) {
|
||||
$element = $this->add('select', 'financial_account_type_id', ts('Financial Account Type'),
|
||||
array('' => '- select -') + $financialAccountType, TRUE, array('class' => 'crm-select2 huge'));
|
||||
if ($this->_isARFlag) {
|
||||
$element->freeze();
|
||||
$elementAccounting->freeze();
|
||||
$elementActive->freeze();
|
||||
}
|
||||
elseif ($this->_id && CRM_Financial_BAO_FinancialAccount::validateFinancialAccount($this->_id)) {
|
||||
$element->freeze();
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_action == CRM_Core_Action::UPDATE &&
|
||||
CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', $this->_id, 'is_reserved')
|
||||
) {
|
||||
$this->freeze(array('name', 'description', 'is_active'));
|
||||
}
|
||||
$this->addFormRule(array('CRM_Financial_Form_FinancialAccount', 'formRule'), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $values
|
||||
* posted values of the form
|
||||
* @param $files
|
||||
* @param $self
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($values, $files, $self) {
|
||||
$errorMsg = array();
|
||||
$financialAccountTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name LIKE 'Liability' "));
|
||||
if (isset($values['is_tax'])) {
|
||||
if ($values['financial_account_type_id'] != $financialAccountTypeId) {
|
||||
$errorMsg['financial_account_type_id'] = ts('Taxable accounts should have Financial Account Type set to Liability.');
|
||||
}
|
||||
if (CRM_Utils_Array::value('tax_rate', $values) == NULL) {
|
||||
$errorMsg['tax_rate'] = ts('Please enter value for tax rate');
|
||||
}
|
||||
}
|
||||
if ((CRM_Utils_Array::value('tax_rate', $values) != NULL)) {
|
||||
if ($values['tax_rate'] < 0 || $values['tax_rate'] >= 100) {
|
||||
$errorMsg['tax_rate'] = ts('Tax Rate Should be between 0 - 100');
|
||||
}
|
||||
}
|
||||
if ($self->_action & CRM_Core_Action::UPDATE) {
|
||||
if (!(isset($values['is_tax']))) {
|
||||
$relationshipId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Sales Tax Account is' "));
|
||||
$params = array(
|
||||
'financial_account_id' => $self->_id,
|
||||
'account_relationship' => $relationshipId,
|
||||
);
|
||||
$result = CRM_Financial_BAO_FinancialTypeAccount::retrieve($params, $defaults);
|
||||
if ($result) {
|
||||
$errorMsg['is_tax'] = ts('Is Tax? must be set for this financial account');
|
||||
}
|
||||
}
|
||||
}
|
||||
return CRM_Utils_Array::crmIsEmptyArray($errorMsg) ? TRUE : $errorMsg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
* the default values are retrieved from the database.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = parent::setDefaultValues();
|
||||
if ($this->_action & CRM_Core_Action::ADD) {
|
||||
$defaults['contact_id'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Domain', CRM_Core_Config::domainID(), 'contact_id');
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*/
|
||||
public function postProcess() {
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
if (CRM_Financial_BAO_FinancialAccount::del($this->_id)) {
|
||||
CRM_Core_Session::setStatus(ts('Selected Financial Account has been deleted.'));
|
||||
}
|
||||
else {
|
||||
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/financial/financialAccount', "reset=1&action=browse"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
// store the submitted values in an array
|
||||
$params = $this->exportValues();
|
||||
|
||||
if ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
$params['id'] = $this->_id;
|
||||
}
|
||||
|
||||
$financialAccount = CRM_Financial_BAO_FinancialAccount::add($params);
|
||||
CRM_Core_Session::setStatus(ts('The Financial Account \'%1\' has been saved.', array(1 => $financialAccount->name)), ts('Saved'), 'success');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
302
sites/all/modules/civicrm/CRM/Financial/Form/FinancialBatch.php
Normal file
302
sites/all/modules/civicrm/CRM/Financial/Form/FinancialBatch.php
Normal file
|
@ -0,0 +1,302 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for Accounting Batch
|
||||
*/
|
||||
class CRM_Financial_Form_FinancialBatch extends CRM_Contribute_Form {
|
||||
|
||||
/**
|
||||
* The financial batch id, used when editing the field
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_id;
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$context = CRM_Utils_Request::retrieve('context', 'String', $this);
|
||||
$this->set("context", $context);
|
||||
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
|
||||
parent::preProcess();
|
||||
$session = CRM_Core_Session::singleton();
|
||||
if ($this->_id) {
|
||||
$permissions = array(
|
||||
CRM_Core_Action::UPDATE => array(
|
||||
'permission' => array(
|
||||
'edit own manual batches',
|
||||
'edit all manual batches',
|
||||
),
|
||||
'actionName' => 'edit',
|
||||
),
|
||||
CRM_Core_Action::DELETE => array(
|
||||
'permission' => array(
|
||||
'delete own manual batches',
|
||||
'delete all manual batches',
|
||||
),
|
||||
'actionName' => 'delete',
|
||||
),
|
||||
);
|
||||
|
||||
$createdID = CRM_Core_DAO::getFieldValue('CRM_Batch_DAO_Batch', $this->_id, 'created_id');
|
||||
if (!empty($permissions[$this->_action])) {
|
||||
$this->checkPermissions($this->_action, $permissions[$this->_action]['permission'], $createdID, $session->get('userID'), $permissions[$this->_action]['actionName']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
$this->setPageTitle(ts('Financial Batch'));
|
||||
if (!empty($this->_id)) {
|
||||
$this->_title = CRM_Core_DAO::getFieldValue('CRM_Batch_DAO_Batch', $this->_id, 'title');
|
||||
CRM_Utils_System::setTitle($this->_title . ' - ' . ts('Accounting Batch'));
|
||||
$this->assign('batchTitle', $this->_title);
|
||||
$contactID = CRM_Core_DAO::getFieldValue('CRM_Batch_DAO_Batch', $this->_id, 'created_id');
|
||||
$contactName = CRM_Contact_BAO_Contact::displayName($contactID);
|
||||
$this->assign('contactName', $contactName);
|
||||
}
|
||||
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
|
||||
$this->addButtons(
|
||||
array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Save'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Save and New'),
|
||||
'subName' => 'new',
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
if ($this->_action & CRM_Core_Action::UPDATE && $this->_id) {
|
||||
$batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id');
|
||||
|
||||
// unset exported status
|
||||
$exportedStatusId = CRM_Utils_Array::key('Exported', $batchStatus);
|
||||
unset($batchStatus[$exportedStatusId]);
|
||||
$this->add('select', 'status_id', ts('Batch Status'), array('' => ts('- select -')) + $batchStatus, TRUE);
|
||||
$this->freeze(array('status_id'));
|
||||
}
|
||||
|
||||
$attributes = CRM_Core_DAO::getAttribute('CRM_Batch_DAO_Batch');
|
||||
|
||||
$this->add('text', 'title', ts('Batch Name'), $attributes['name'], TRUE);
|
||||
|
||||
$this->add('textarea', 'description', ts('Description'), $attributes['description']);
|
||||
|
||||
$this->add('select', 'payment_instrument_id', ts('Payment Method'),
|
||||
array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(),
|
||||
FALSE
|
||||
);
|
||||
|
||||
$this->add('text', 'total', ts('Total Amount'), $attributes['total']);
|
||||
|
||||
$this->add('text', 'item_count', ts('Number of Transactions'), $attributes['item_count']);
|
||||
$this->addFormRule(array('CRM_Financial_Form_FinancialBatch', 'formRule'), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form. Note that in edit/view mode
|
||||
* the default values are retrieved from the database.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = parent::setDefaultValues();
|
||||
|
||||
if ($this->_id) {
|
||||
$this->assign('modified_date', $defaults['modified_date']);
|
||||
$this->assign('created_date', $defaults['created_date']);
|
||||
}
|
||||
else {
|
||||
// set batch name default
|
||||
$defaults['title'] = CRM_Batch_BAO_Batch::generateBatchName();
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $values
|
||||
* @param $files
|
||||
* @param $self
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($values, $files, $self) {
|
||||
$errors = array();
|
||||
if (!empty($values['contact_name']) && !is_numeric($values['created_id'])) {
|
||||
$errors['contact_name'] = ts('Please select a valid contact.');
|
||||
}
|
||||
if ($values['item_count'] && (!is_numeric($values['item_count']) || $values['item_count'] < 1)) {
|
||||
$errors['item_count'] = ts('Number of Transactions should a positive number');
|
||||
}
|
||||
if ($values['total'] && (!is_numeric($values['total']) || $values['total'] <= 0)) {
|
||||
$errors['total'] = ts('Total Amount should be a positive number');
|
||||
}
|
||||
if (!empty($values['created_date']) && date('Y-m-d') < date('Y-m-d', strtotime($values['created_date']))) {
|
||||
$errors['created_date'] = ts('Created date cannot be greater than current date');
|
||||
}
|
||||
$batchName = $values['title'];
|
||||
if (!CRM_Core_DAO::objectExists($batchName, 'CRM_Batch_DAO_Batch', $self->_id)) {
|
||||
$errors['title'] = ts('This name already exists in database. Batch names must be unique.');
|
||||
}
|
||||
return CRM_Utils_Array::crmIsEmptyArray($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$params = $this->exportValues();
|
||||
$batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id');
|
||||
if ($this->_id) {
|
||||
$params['id'] = $this->_id;
|
||||
}
|
||||
|
||||
// store the submitted values in an array
|
||||
$params['modified_date'] = date('YmdHis');
|
||||
$params['modified_id'] = $session->get('userID');
|
||||
if (!empty($params['created_date'])) {
|
||||
$params['created_date'] = CRM_Utils_Date::processDate($params['created_date']);
|
||||
}
|
||||
|
||||
if ($this->_action & CRM_Core_Action::ADD) {
|
||||
$batchMode = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'mode_id', array('labelColumn' => 'name'));
|
||||
$params['mode_id'] = CRM_Utils_Array::key('Manual Batch', $batchMode);
|
||||
$params['status_id'] = CRM_Utils_Array::key('Open', $batchStatus);
|
||||
$params['created_date'] = date('YmdHis');
|
||||
if (empty($params['created_id'])) {
|
||||
$params['created_id'] = $session->get('userID');
|
||||
}
|
||||
$details = "{$params['title']} batch has been created by this contact.";
|
||||
$activityTypeName = 'Create Batch';
|
||||
}
|
||||
elseif ($this->_action & CRM_Core_Action::UPDATE && $this->_id) {
|
||||
$details = "{$params['title']} batch has been edited by this contact.";
|
||||
if (CRM_Utils_Array::value($params['status_id'], $batchStatus) == 'Closed') {
|
||||
$details = "{$params['title']} batch has been closed by this contact.";
|
||||
}
|
||||
$activityTypeName = 'Edit Batch';
|
||||
}
|
||||
|
||||
$batch = CRM_Batch_BAO_Batch::create($params);
|
||||
|
||||
//set batch id
|
||||
$this->_id = $batch->id;
|
||||
|
||||
$activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name');
|
||||
|
||||
// create activity.
|
||||
$activityParams = array(
|
||||
'activity_type_id' => array_search($activityTypeName, $activityTypes),
|
||||
'subject' => $batch->title . "- Batch",
|
||||
'status_id' => 2,
|
||||
'priority_id' => 2,
|
||||
'activity_date_time' => date('YmdHis'),
|
||||
'source_contact_id' => $session->get('userID'),
|
||||
'source_contact_qid' => $session->get('userID'),
|
||||
'details' => $details,
|
||||
);
|
||||
|
||||
CRM_Activity_BAO_Activity::create($activityParams);
|
||||
|
||||
$buttonName = $this->controller->getButtonName();
|
||||
|
||||
$context = $this->get("context");
|
||||
if ($batch->title) {
|
||||
CRM_Core_Session::setStatus(ts("'%1' batch has been saved.", array(1 => $batch->title)), ts('Saved'), 'success');
|
||||
}
|
||||
if ($buttonName == $this->getButtonName('next', 'new') & $this->_action == CRM_Core_Action::UPDATE) {
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/financial/batch',
|
||||
"reset=1&action=add&context=1"));
|
||||
}
|
||||
elseif ($buttonName == $this->getButtonName('next', 'new')) {
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/financial/batch',
|
||||
"reset=1&action=add"));
|
||||
}
|
||||
elseif (CRM_Utils_Array::value($batch->status_id, $batchStatus) == 'Closed') {
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm', 'reset=1'));
|
||||
}
|
||||
elseif (($buttonName == $this->getButtonName('next') & $this->_action == CRM_Core_Action::UPDATE) ||
|
||||
($buttonName == $this->getButtonName('next') & $this->_action == CRM_Core_Action::ADD & $context == 1)
|
||||
) {
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/financial/financialbatches',
|
||||
"reset=1&batchStatus=1"));
|
||||
}
|
||||
else {
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/batchtransaction',
|
||||
"reset=1&bid={$batch->id}"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param $action
|
||||
* @param $permissions
|
||||
* @param int $createdID
|
||||
* @param int $userContactID
|
||||
* @param string $actionName
|
||||
*
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public function checkPermissions($action, $permissions, $createdID, $userContactID, $actionName) {
|
||||
if ((CRM_Core_Permission::check($permissions[0]) || CRM_Core_Permission::check($permissions[1]))) {
|
||||
if (CRM_Core_Permission::check($permissions[0]) && $userContactID != $createdID && !CRM_Core_Permission::check($permissions[1])) {
|
||||
CRM_Core_Error::statusBounce(ts('You dont have permission to %1 this batch'), array(1 => $actionName));
|
||||
}
|
||||
}
|
||||
else {
|
||||
CRM_Core_Error::statusBounce(ts('You dont have permission to %1 this batch'), array(1 => $actionName));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
134
sites/all/modules/civicrm/CRM/Financial/Form/FinancialType.php
Normal file
134
sites/all/modules/civicrm/CRM/Financial/Form/FinancialType.php
Normal file
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for Financial Type
|
||||
*/
|
||||
class CRM_Financial_Form_FinancialType extends CRM_Contribute_Form {
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*/
|
||||
public function preProcess() {
|
||||
// Check permission for Financial Type when ACL-FT is enabled
|
||||
if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()
|
||||
&& !CRM_Core_Permission::check('administer CiviCRM Financial Types')
|
||||
) {
|
||||
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
|
||||
}
|
||||
parent::preProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
$this->setPageTitle(ts('Financial Type'));
|
||||
|
||||
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
|
||||
if ($this->_id) {
|
||||
$this->_title = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $this->_id, 'name');
|
||||
}
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
return;
|
||||
}
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
$this->add('text', 'name', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Financial_DAO_FinancialType', 'name'), TRUE);
|
||||
|
||||
$this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Financial_DAO_FinancialType', 'description'));
|
||||
|
||||
$this->add('checkbox', 'is_deductible', ts('Tax-Deductible?'), CRM_Core_DAO::getAttribute('CRM_Financial_DAO_FinancialType', 'is_deductible'));
|
||||
$this->add('checkbox', 'is_active', ts('Enabled?'), CRM_Core_DAO::getAttribute('CRM_Financial_DAO_FinancialType', 'is_active'));
|
||||
$this->add('checkbox', 'is_reserved', ts('Reserved?'), CRM_Core_DAO::getAttribute('CRM_Financial_DAO_FinancialType', 'is_reserved'));
|
||||
if ($this->_action == CRM_Core_Action::UPDATE) {
|
||||
$this->assign('aid', $this->_id);
|
||||
}
|
||||
if ($this->_action == CRM_Core_Action::UPDATE && CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $this->_id, 'is_reserved', 'vid')) {
|
||||
$this->freeze(array('is_active'));
|
||||
}
|
||||
|
||||
$this->addRule('name', ts('A financial type with this name already exists. Please select another name.'), 'objectExists',
|
||||
array('CRM_Financial_DAO_FinancialType', $this->_id)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*/
|
||||
public function postProcess() {
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
$errors = CRM_Financial_BAO_FinancialType::del($this->_id);
|
||||
if (!empty($errors)) {
|
||||
CRM_Core_Error::statusBounce($errors['error_message'], CRM_Utils_System::url('civicrm/admin/financial/financialType', "reset=1&action=browse"), ts('Cannot Delete'));
|
||||
}
|
||||
CRM_Core_Session::setStatus(ts('Selected financial type has been deleted.'), ts('Record Deleted'), 'success');
|
||||
}
|
||||
else {
|
||||
$params = $ids = array();
|
||||
// store the submitted values in an array
|
||||
$params = $this->exportValues();
|
||||
|
||||
if ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
$ids['financialType'] = $this->_id;
|
||||
}
|
||||
|
||||
$financialType = CRM_Financial_BAO_FinancialType::add($params, $ids);
|
||||
if ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
$url = CRM_Utils_System::url('civicrm/admin/financial/financialType', 'reset=1&action=browse');
|
||||
CRM_Core_Session::setStatus(ts('The financial type "%1" has been updated.', array(1 => $financialType->name)), ts('Saved'), 'success');
|
||||
}
|
||||
else {
|
||||
$url = CRM_Utils_System::url('civicrm/admin/financial/financialType/accounts', 'reset=1&action=browse&aid=' . $financialType->id);
|
||||
$statusArray = array(
|
||||
1 => $financialType->name,
|
||||
2 => $financialType->name,
|
||||
3 => CRM_Utils_Array::value(0, $financialType->titles),
|
||||
4 => CRM_Utils_Array::value(1, $financialType->titles),
|
||||
5 => CRM_Utils_Array::value(2, $financialType->titles),
|
||||
);
|
||||
if (empty($financialType->titles)) {
|
||||
$text = ts('Your Financial "%1" Type has been created and assigned to an existing financial account with the same title. You should review the assigned account and determine whether additional account relationships are needed.', $statusArray);
|
||||
}
|
||||
else {
|
||||
$text = ts('Your Financial "%1" Type has been created, along with a corresponding income account "%2". That income account, along with standard financial accounts "%3", "%4" and "%5" have been linked to the financial type. You may edit or replace those relationships here.', $statusArray);
|
||||
}
|
||||
CRM_Core_Session::setStatus($text, ts('Saved'), 'success', array('expires' => 0));
|
||||
}
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->replaceUserContext($url);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,326 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for Financial Type Account
|
||||
*/
|
||||
class CRM_Financial_Form_FinancialTypeAccount extends CRM_Contribute_Form {
|
||||
|
||||
/**
|
||||
* The financial type id saved to the session for an update.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_aid;
|
||||
|
||||
/**
|
||||
* The financial type accounts id, used when editing the field
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_id;
|
||||
|
||||
/**
|
||||
* The name of the BAO object for this form.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_BAOName;
|
||||
|
||||
/**
|
||||
* Flag if its a AR account type.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_isARFlag = FALSE;
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_aid = CRM_Utils_Request::retrieve('aid', 'Positive', $this);
|
||||
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
|
||||
|
||||
if (!$this->_id && ($this->_action & CRM_Core_Action::UPDATE)) {
|
||||
$this->_id = CRM_Utils_Type::escape($this->_id, 'Positive');
|
||||
}
|
||||
$url = CRM_Utils_System::url('civicrm/admin/financial/financialType/accounts',
|
||||
"reset=1&action=browse&aid={$this->_aid}");
|
||||
|
||||
$this->_BAOName = 'CRM_Financial_BAO_FinancialTypeAccount';
|
||||
if ($this->_aid && ($this->_action & CRM_Core_Action::ADD)) {
|
||||
$this->_title = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $this->_aid, 'name');
|
||||
CRM_Utils_System::setTitle($this->_title . ' - ' . ts('Financial Accounts'));
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->pushUserContext($url);
|
||||
}
|
||||
// CRM-12492
|
||||
if (!($this->_action & CRM_Core_Action::ADD)) {
|
||||
$relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
|
||||
$accountRelationship = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_EntityFinancialAccount', $this->_id, 'account_relationship');
|
||||
if ($accountRelationship == $relationTypeId) {
|
||||
$this->_isARFlag = TRUE;
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
CRM_Core_Session::setStatus(ts("Selected financial type account with 'Accounts Receivable Account is' account relationship cannot be deleted."),
|
||||
'', 'error');
|
||||
CRM_Utils_System::redirect($url);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($this->_id) {
|
||||
$financialAccount = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_EntityFinancialAccount', $this->_id, 'financial_account_id');
|
||||
$fieldTitle = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', $financialAccount, 'name');
|
||||
CRM_Utils_System::setTitle($fieldTitle . ' - ' . ts('Financial Type Accounts'));
|
||||
}
|
||||
|
||||
$breadCrumb = array(
|
||||
array(
|
||||
'title' => ts('Financial Type Accounts'),
|
||||
'url' => $url,
|
||||
),
|
||||
);
|
||||
CRM_Utils_System::appendBreadCrumb($breadCrumb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
$this->setPageTitle(ts('Financial Type Account'));
|
||||
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($this->_id)) {
|
||||
$params = array('id' => $this->_id);
|
||||
CRM_Financial_BAO_FinancialTypeAccount::retrieve($params, $defaults);
|
||||
$this->setDefaults($defaults);
|
||||
$financialAccountTitle = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', $defaults['financial_account_id'], 'name');
|
||||
}
|
||||
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
|
||||
if ($this->_action == CRM_Core_Action::UPDATE) {
|
||||
$this->assign('aid', $this->_id);
|
||||
// hidden field to catch the group id in profile
|
||||
$this->add('hidden', 'financial_type_id', $this->_aid);
|
||||
|
||||
// hidden field to catch the field id in profile
|
||||
$this->add('hidden', 'account_type_id', $this->_id);
|
||||
}
|
||||
$params['orderColumn'] = 'label';
|
||||
$AccountTypeRelationship = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', $params);
|
||||
if (!empty($AccountTypeRelationship)) {
|
||||
$element = $this->add('select',
|
||||
'account_relationship',
|
||||
ts('Financial Account Relationship'),
|
||||
array('select' => ts('- Select Financial Account Relationship -')) + $AccountTypeRelationship,
|
||||
TRUE
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->_isARFlag) {
|
||||
$element->freeze();
|
||||
}
|
||||
|
||||
if ($this->_action == CRM_Core_Action::ADD) {
|
||||
if (!empty($this->_submitValues['account_relationship']) || !empty($this->_submitValues['financial_account_id'])) {
|
||||
$financialAccountType = CRM_Financial_BAO_FinancialAccount::getfinancialAccountRelations();
|
||||
$financialAccountType = CRM_Utils_Array::value($this->_submitValues['account_relationship'], $financialAccountType);
|
||||
$result = CRM_Contribute_PseudoConstant::financialAccount(NULL, $financialAccountType);
|
||||
|
||||
$financialAccountSelect = array('' => ts('- select -')) + $result;
|
||||
}
|
||||
else {
|
||||
$financialAccountSelect = array(
|
||||
'select' => ts('- select -'),
|
||||
) + CRM_Contribute_PseudoConstant::financialAccount();
|
||||
}
|
||||
}
|
||||
if ($this->_action == CRM_Core_Action::UPDATE) {
|
||||
$financialAccountType = CRM_Financial_BAO_FinancialAccount::getfinancialAccountRelations();
|
||||
$financialAccountType = $financialAccountType[$this->_defaultValues['account_relationship']];
|
||||
$result = CRM_Contribute_PseudoConstant::financialAccount(NULL, $financialAccountType);
|
||||
|
||||
$financialAccountSelect = array('' => ts('- select -')) + $result;
|
||||
}
|
||||
|
||||
$this->add('select',
|
||||
'financial_account_id',
|
||||
ts('Financial Account'),
|
||||
$financialAccountSelect,
|
||||
TRUE
|
||||
);
|
||||
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Save'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Save and New'),
|
||||
'subName' => 'new',
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
$this->addFormRule(array('CRM_Financial_Form_FinancialTypeAccount', 'formRule'), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $values
|
||||
* posted values of the form
|
||||
* @param $files
|
||||
* @param $self
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($values, $files, $self) {
|
||||
$errorMsg = array();
|
||||
$errorFlag = FALSE;
|
||||
if ($self->_action == CRM_Core_Action::DELETE) {
|
||||
$relationValues = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship');
|
||||
if (CRM_Utils_Array::value('financial_account_id', $values) != 'select') {
|
||||
if ($relationValues[$values['account_relationship']] == 'Premiums Inventory Account is' || $relationValues[$values['account_relationship']] == 'Cost of Sales Account is') {
|
||||
$premiumsProduct = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_PremiumsProduct', $values['financial_type_id'], 'product_id', 'financial_type_id');
|
||||
$product = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Product', $values['financial_type_id'], 'name', 'financial_type_id');
|
||||
if (!empty($premiumsProduct) || !empty($product)) {
|
||||
$errorMsg['account_relationship'] = 'You cannot remove ' . $relationValues[$values['account_relationship']] . ' relationship while the Financial Type is used for a Premium.';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CRM_Utils_Array::value('account_relationship', $values) == 'select') {
|
||||
$errorMsg['account_relationship'] = 'Financial Account relationship is a required field.';
|
||||
}
|
||||
if (CRM_Utils_Array::value('financial_account_id', $values) == 'select') {
|
||||
$errorMsg['financial_account_id'] = 'Financial Account is a required field.';
|
||||
}
|
||||
if (!empty($values['account_relationship']) && !empty($values['financial_account_id'])) {
|
||||
$params = array(
|
||||
'account_relationship' => $values['account_relationship'],
|
||||
'entity_id' => $self->_aid,
|
||||
'entity_table' => 'civicrm_financial_type',
|
||||
);
|
||||
$defaults = array();
|
||||
if ($self->_action == CRM_Core_Action::ADD) {
|
||||
$relationshipId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Sales Tax Account is' "));
|
||||
$isTax = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', $values['financial_account_id'], 'is_tax');
|
||||
if ($values['account_relationship'] == $relationshipId) {
|
||||
if (!($isTax)) {
|
||||
$errorMsg['financial_account_id'] = ts('Is Tax? must be set for respective financial account');
|
||||
}
|
||||
}
|
||||
$result = CRM_Financial_BAO_FinancialTypeAccount::retrieve($params, $defaults);
|
||||
if ($result) {
|
||||
$errorFlag = TRUE;
|
||||
}
|
||||
}
|
||||
if ($self->_action == CRM_Core_Action::UPDATE) {
|
||||
if ($values['account_relationship'] == $self->_defaultValues['account_relationship'] && $values['financial_account_id'] == $self->_defaultValues['financial_account_id']) {
|
||||
$errorFlag = FALSE;
|
||||
}
|
||||
else {
|
||||
$params['financial_account_id'] = $values['financial_account_id'];
|
||||
$result = CRM_Financial_BAO_FinancialTypeAccount::retrieve($params, $defaults);
|
||||
if ($result) {
|
||||
$errorFlag = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($errorFlag) {
|
||||
$errorMsg['account_relationship'] = ts('This account relationship already exits');
|
||||
}
|
||||
}
|
||||
return CRM_Utils_Array::crmIsEmptyArray($errorMsg) ? TRUE : $errorMsg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*/
|
||||
public function postProcess() {
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
CRM_Financial_BAO_FinancialTypeAccount::del($this->_id, $this->_aid);
|
||||
CRM_Core_Session::setStatus(ts('Selected financial type account has been deleted.'));
|
||||
}
|
||||
else {
|
||||
$params = $ids = array();
|
||||
// store the submitted values in an array
|
||||
$params = $this->exportValues();
|
||||
|
||||
if ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
$ids['entityFinancialAccount'] = $this->_id;
|
||||
}
|
||||
if ($this->_action & CRM_Core_Action::ADD || $this->_action & CRM_Core_Action::UPDATE) {
|
||||
$params['financial_account_id'] = $this->_submitValues['financial_account_id'];
|
||||
}
|
||||
$params['entity_table'] = 'civicrm_financial_type';
|
||||
if ($this->_action & CRM_Core_Action::ADD) {
|
||||
$params['entity_id'] = $this->_aid;
|
||||
}
|
||||
try {
|
||||
$financialTypeAccount = CRM_Financial_BAO_FinancialTypeAccount::add($params, $ids);
|
||||
CRM_Core_Session::setStatus(ts('The financial type Account has been saved.'), ts('Saved'), 'success');
|
||||
}
|
||||
catch (CRM_Core_Exception $e) {
|
||||
CRM_Core_Error::statusBounce($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$buttonName = $this->controller->getButtonName();
|
||||
$session = CRM_Core_Session::singleton();
|
||||
|
||||
if ($buttonName == $this->getButtonName('next', 'new')) {
|
||||
CRM_Core_Session::setStatus(ts(' You can add another Financial Account Type.'));
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/financial/financialType/accounts',
|
||||
"reset=1&action=add&aid={$this->_aid}"));
|
||||
}
|
||||
else {
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/financial/financialType/accounts',
|
||||
"reset=1&action=browse&aid={$this->_aid}"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
125
sites/all/modules/civicrm/CRM/Financial/Form/Payment.php
Normal file
125
sites/all/modules/civicrm/CRM/Financial/Form/Payment.php
Normal file
|
@ -0,0 +1,125 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Financial_Form_Payment extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $_paymentProcessorID;
|
||||
protected $currency;
|
||||
|
||||
public $_values = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $_paymentProcessor;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $isBackOffice = FALSE;
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
$this->_values['custom_pre_id'] = CRM_Utils_Request::retrieve('pre_profile_id', 'Integer', $this);
|
||||
|
||||
$this->_paymentProcessorID = CRM_Utils_Request::retrieve('processor_id', 'Integer', CRM_Core_DAO::$_nullObject,
|
||||
TRUE);
|
||||
$this->currency = CRM_Utils_Request::retrieve('currency', 'String', CRM_Core_DAO::$_nullObject,
|
||||
TRUE);
|
||||
|
||||
$this->paymentInstrumentID = CRM_Utils_Request::retrieve('payment_instrument_id', 'Integer');
|
||||
$this->isBackOffice = CRM_Utils_Request::retrieve('is_back_office', 'Integer');
|
||||
|
||||
$this->assignBillingType();
|
||||
|
||||
$this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($this->_paymentProcessorID);
|
||||
|
||||
CRM_Core_Payment_ProcessorForm::preProcess($this);
|
||||
|
||||
self::addCreditCardJs($this->_paymentProcessorID);
|
||||
|
||||
$this->assign('paymentProcessorID', $this->_paymentProcessorID);
|
||||
$this->assign('currency', $this->currency);
|
||||
|
||||
$this->assign('suppressForm', TRUE);
|
||||
$this->controller->_generateQFKey = FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrency() {
|
||||
return $this->currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build quickForm.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
CRM_Core_Payment_ProcessorForm::buildQuickForm($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$contactID = $this->getContactID();
|
||||
CRM_Core_Payment_Form::setDefaultValues($this, $contactID);
|
||||
return $this->_defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add JS to show icons for the accepted credit cards.
|
||||
*
|
||||
* @param int $paymentProcessorID
|
||||
* @param string $region
|
||||
*/
|
||||
public static function addCreditCardJs($paymentProcessorID = NULL, $region = 'billing-block') {
|
||||
$creditCards = CRM_Financial_BAO_PaymentProcessor::getCreditCards($paymentProcessorID);
|
||||
$creditCardTypes = CRM_Core_Payment_Form::getCreditCardCSSNames($creditCards);
|
||||
CRM_Core_Resources::singleton()
|
||||
// CRM-20516: add BillingBlock script on billing-block region
|
||||
// to support this feature in payment form snippet too.
|
||||
->addScriptFile('civicrm', 'templates/CRM/Core/BillingBlock.js', 10, $region, FALSE)
|
||||
// workaround for CRM-13634
|
||||
// ->addSetting(array('config' => array('creditCardTypes' => $creditCardTypes)));
|
||||
->addScript('CRM.config.creditCardTypes = ' . json_encode($creditCardTypes) . ';', '-9999', $region);
|
||||
}
|
||||
|
||||
}
|
317
sites/all/modules/civicrm/CRM/Financial/Form/PaymentEdit.php
Normal file
317
sites/all/modules/civicrm/CRM/Financial/Form/PaymentEdit.php
Normal file
|
@ -0,0 +1,317 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Financial_Form_PaymentEdit extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The id of the financial trxn.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_id;
|
||||
|
||||
/**
|
||||
* The id of the related contribution ID
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_contributionID;
|
||||
|
||||
/**
|
||||
* The variable which holds the information of a financial transaction
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_values;
|
||||
|
||||
/**
|
||||
* Explicitly declare the form context.
|
||||
*/
|
||||
public function getDefaultContext() {
|
||||
return 'create';
|
||||
}
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_action = CRM_Core_Action::UPDATE;
|
||||
parent::preProcess();
|
||||
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
|
||||
$this->assign('id', $this->_id);
|
||||
$this->_contributionID = CRM_Utils_Request::retrieve('contribution_id', 'Positive', $this);
|
||||
|
||||
$this->_values = civicrm_api3('FinancialTrxn', 'getsingle', array('id' => $this->_id));
|
||||
if (!empty($this->_values['payment_processor_id'])) {
|
||||
CRM_Core_Error::statusBounce(ts('You cannot update this payment'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
return $this->_values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build quickForm.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
CRM_Utils_System::setTitle(ts('Update Payment details'));
|
||||
|
||||
$paymentFields = $this->getPaymentFields();
|
||||
$this->assign('paymentFields', $paymentFields);
|
||||
foreach ($paymentFields as $name => $paymentField) {
|
||||
if (!empty($paymentField['add_field'])) {
|
||||
$attributes = array(
|
||||
'entity' => 'FinancialTrxn',
|
||||
'name' => $name,
|
||||
);
|
||||
$this->addField($name, $attributes, $paymentField['is_required']);
|
||||
}
|
||||
else {
|
||||
$this->add($paymentField['htmlType'],
|
||||
$name,
|
||||
$paymentField['title'],
|
||||
$paymentField['attributes'],
|
||||
$paymentField['is_required']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('currency', CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_Currency', $this->_values['currency'], 'symbol', 'name'));
|
||||
$this->addFormRule(array(__CLASS__, 'formRule'), $this);
|
||||
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'submit',
|
||||
'name' => ts('Update'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Global form rule.
|
||||
*
|
||||
* @param array $fields
|
||||
* The input form values.
|
||||
* @param array $files
|
||||
* The uploaded files if any.
|
||||
* @param $self
|
||||
*
|
||||
* @return bool|array
|
||||
* true if no errors, else array of errors
|
||||
*/
|
||||
public static function formRule($fields, $files, $self) {
|
||||
$errors = array();
|
||||
|
||||
// if Credit Card is chosen and pan_truncation is not NULL ensure that it's value is numeric else throw validation error
|
||||
if (CRM_Core_PseudoConstant::getName('CRM_Financial_DAO_FinancialTrxn', 'payment_instrument_id', $fields['payment_instrument_id']) == 'Credit Card' &&
|
||||
!empty($fields['pan_truncation']) &&
|
||||
!CRM_Utils_Rule::numeric($fields['pan_truncation'])
|
||||
) {
|
||||
$errors['pan_truncation'] = ts('Please enter a valid Card Number');
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = array(
|
||||
'id' => $this->_id,
|
||||
'payment_instrument_id' => $this->_submitValues['payment_instrument_id'],
|
||||
'trxn_id' => CRM_Utils_Array::value('trxn_id', $this->_submitValues),
|
||||
'trxn_date' => CRM_Utils_Array::value('trxn_date', $this->_submitValues, date('YmdHis')),
|
||||
);
|
||||
|
||||
$paymentInstrumentName = CRM_Core_PseudoConstant::getName('CRM_Financial_DAO_FinancialTrxn', 'payment_instrument_id', $params['payment_instrument_id']);
|
||||
if ($paymentInstrumentName == 'Credit Card') {
|
||||
$params['card_type_id'] = CRM_Utils_Array::value('card_type_id', $this->_submitValues);
|
||||
$params['pan_truncation'] = CRM_Utils_Array::value('pan_truncation', $this->_submitValues);
|
||||
}
|
||||
elseif ($paymentInstrumentName == 'Check') {
|
||||
$params['check_number'] = CRM_Utils_Array::value('check_number', $this->_submitValues);
|
||||
}
|
||||
|
||||
$this->submit($params);
|
||||
|
||||
CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper function to process form submission
|
||||
*
|
||||
* @param array $submittedValues
|
||||
*
|
||||
*/
|
||||
protected function submit($submittedValues) {
|
||||
// if payment instrument is changed then
|
||||
// 1. Record a new reverse financial transaction with old payment instrument
|
||||
// 2. Record a new financial transaction with new payment instrument
|
||||
// 3. Add EntityFinancialTrxn records to relate with corresponding financial item and contribution
|
||||
if ($submittedValues['payment_instrument_id'] != $this->_values['payment_instrument_id']) {
|
||||
$previousFinanciaTrxn = $this->_values;
|
||||
$newFinancialTrxn = $submittedValues;
|
||||
unset($previousFinanciaTrxn['id'], $newFinancialTrxn['id']);
|
||||
$previousFinanciaTrxn['trxn_date'] = CRM_Utils_Array::value('trxn_date', $submittedValues, date('YmdHis'));
|
||||
$previousFinanciaTrxn['total_amount'] = -$previousFinanciaTrxn['total_amount'];
|
||||
$previousFinanciaTrxn['net_amount'] = -$previousFinanciaTrxn['net_amount'];
|
||||
$previousFinanciaTrxn['fee_amount'] = -$previousFinanciaTrxn['fee_amount'];
|
||||
$previousFinanciaTrxn['contribution_id'] = $newFinancialTrxn['contribution_id'] = $this->_contributionID;
|
||||
|
||||
$newFinancialTrxn['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($submittedValues['payment_instrument_id']);
|
||||
foreach (array('total_amount', 'fee_amount', 'net_amount', 'currency', 'is_payment', 'status_id') as $fieldName) {
|
||||
$newFinancialTrxn[$fieldName] = $this->_values[$fieldName];
|
||||
}
|
||||
|
||||
foreach (array($previousFinanciaTrxn, $newFinancialTrxn) as $financialTrxnParams) {
|
||||
civicrm_api3('FinancialTrxn', 'create', $financialTrxnParams);
|
||||
$trxnParams = array(
|
||||
'total_amount' => $financialTrxnParams['total_amount'],
|
||||
'contribution_id' => $this->_contributionID,
|
||||
);
|
||||
$contributionTotalAmount = CRM_Core_DAO::getFieldValue('CRM_Contribute_BAO_Contribution', $this->_contributionID, 'total_amount');
|
||||
CRM_Contribute_BAO_Contribution::assignProportionalLineItems($trxnParams, $submittedValues['id'], $contributionTotalAmount);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// simply update the financial trxn
|
||||
civicrm_api3('FinancialTrxn', 'create', $submittedValues);
|
||||
}
|
||||
|
||||
self::updateRelatedContribution($submittedValues, $this->_contributionID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for unit testing the post process submit function.
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function testSubmit($params) {
|
||||
$this->_id = $params['id'];
|
||||
$this->_contributionID = $params['contribution_id'];
|
||||
$this->_values = civicrm_api3('FinancialTrxn', 'getsingle', array('id' => $params['id']));
|
||||
|
||||
$this->submit($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to update contribution's check_number and trxn_id by
|
||||
* concatenating values from financial trxn's check_number and trxn_id respectively
|
||||
*
|
||||
* @param array $params
|
||||
* @param int $contributionID
|
||||
*/
|
||||
public static function updateRelatedContribution($params, $contributionID) {
|
||||
$contributionDAO = new CRM_Contribute_DAO_Contribution();
|
||||
$contributionDAO->id = $contributionID;
|
||||
$contributionDAO->find(TRUE);
|
||||
|
||||
foreach (array('trxn_id', 'check_number') as $fieldName) {
|
||||
if (!empty($params[$fieldName])) {
|
||||
if (!empty($contributionDAO->$fieldName)) {
|
||||
$values = explode(',', $contributionDAO->$fieldName);
|
||||
// if submitted check_number or trxn_id value is
|
||||
// already present then ignore else add to $values array
|
||||
if (!in_array($params[$fieldName], $values)) {
|
||||
$values[] = $params[$fieldName];
|
||||
}
|
||||
$contributionDAO->$fieldName = implode(',', $values);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$contributionDAO->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get payment fields
|
||||
*/
|
||||
public function getPaymentFields() {
|
||||
$paymentFields = array(
|
||||
'payment_instrument_id' => array(
|
||||
'is_required' => TRUE,
|
||||
'add_field' => TRUE,
|
||||
),
|
||||
'check_number' => array(
|
||||
'is_required' => FALSE,
|
||||
'add_field' => TRUE,
|
||||
),
|
||||
// @TODO we need to show card type icon in place of select field
|
||||
'card_type_id' => array(
|
||||
'is_required' => FALSE,
|
||||
'add_field' => TRUE,
|
||||
),
|
||||
'pan_truncation' => array(
|
||||
'is_required' => FALSE,
|
||||
'add_field' => TRUE,
|
||||
),
|
||||
'trxn_id' => array(
|
||||
'add_field' => TRUE,
|
||||
'is_required' => FALSE,
|
||||
),
|
||||
'trxn_date' => array(
|
||||
'htmlType' => 'datepicker',
|
||||
'name' => 'trxn_date',
|
||||
'title' => ts('Transaction Date'),
|
||||
'is_required' => TRUE,
|
||||
'attributes' => array(
|
||||
'date' => 'yyyy-mm-dd',
|
||||
'time' => 24,
|
||||
),
|
||||
),
|
||||
'total_amount' => array(
|
||||
'htmlType' => 'text',
|
||||
'name' => 'total_amount',
|
||||
'title' => ts('Total Amount'),
|
||||
'is_required' => TRUE,
|
||||
'attributes' => array(
|
||||
'readonly' => TRUE,
|
||||
'size' => 6,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return $paymentFields;
|
||||
}
|
||||
|
||||
}
|
143
sites/all/modules/civicrm/CRM/Financial/Form/Search.php
Normal file
143
sites/all/modules/civicrm/CRM/Financial/Form/Search.php
Normal file
|
@ -0,0 +1,143 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* @todo Add comments if possible.
|
||||
*/
|
||||
class CRM_Financial_Form_Search extends CRM_Core_Form {
|
||||
|
||||
public $_batchStatus;
|
||||
|
||||
public function preProcess() {
|
||||
$this->_batchStatus = CRM_Utils_Request::retrieve('batchStatus', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, NULL);
|
||||
$this->assign('batchStatus', $this->_batchStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
$status = CRM_Utils_Request::retrieve('status', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, 1);
|
||||
$defaults['batch_update'] = $status;
|
||||
if ($this->_batchStatus) {
|
||||
$defaults['status_id'] = $this->_batchStatus;
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
public function buildQuickForm() {
|
||||
CRM_Core_Resources::singleton()
|
||||
->addScriptFile('civicrm', 'packages/jquery/plugins/jquery.redirect.min.js', 0, 'html-header');
|
||||
$attributes = CRM_Core_DAO::getAttribute('CRM_Batch_DAO_Batch');
|
||||
$attributes['total']['class'] = $attributes['item_count']['class'] = 'number';
|
||||
$this->add('text', 'title', ts('Batch Name'), $attributes['title']);
|
||||
|
||||
$batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id', array('labelColumn' => 'name'));
|
||||
$this->add(
|
||||
'select',
|
||||
'status_id',
|
||||
ts('Batch Status'),
|
||||
array(
|
||||
'' => ts('- any -'),
|
||||
array_search('Open', $batchStatus) => ts('Open'),
|
||||
array_search('Closed', $batchStatus) => ts('Closed'),
|
||||
array_search('Exported', $batchStatus) => ts('Exported'),
|
||||
),
|
||||
FALSE
|
||||
);
|
||||
|
||||
$this->add(
|
||||
'select',
|
||||
'payment_instrument_id',
|
||||
ts('Payment Method'),
|
||||
array('' => ts('- any -')) + CRM_Contribute_PseudoConstant::paymentInstrument(),
|
||||
FALSE
|
||||
);
|
||||
|
||||
$this->add('text', 'total', ts('Total Amount'), $attributes['total']);
|
||||
|
||||
$this->add('text', 'item_count', ts('Number of Items'), $attributes['item_count']);
|
||||
$this->add('text', 'sort_name', ts('Created By'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
|
||||
|
||||
$this->assign('elements', array('status_id', 'title', 'sort_name', 'payment_instrument_id', 'item_count', 'total'));
|
||||
$this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('class' => 'select-rows'));
|
||||
$batchAction = array(
|
||||
'reopen' => ts('Re-open'),
|
||||
'close' => ts('Close'),
|
||||
'export' => ts('Export'),
|
||||
'delete' => ts('Delete'),
|
||||
);
|
||||
|
||||
foreach ($batchAction as $action => $ignore) {
|
||||
if (!CRM_Batch_BAO_Batch::checkBatchPermission($action)) {
|
||||
unset($batchAction[$action]);
|
||||
}
|
||||
}
|
||||
$this->add('select',
|
||||
'batch_update',
|
||||
ts('Task'),
|
||||
array('' => ts('- actions -')) + $batchAction);
|
||||
|
||||
$this->add('submit', 'submit', ts('Go'),
|
||||
array(
|
||||
'class' => 'crm-form-submit',
|
||||
'id' => 'Go',
|
||||
));
|
||||
|
||||
$this->addButtons(
|
||||
array(
|
||||
array(
|
||||
'type' => 'refresh',
|
||||
'name' => ts('Search'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
)
|
||||
);
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
|
||||
public function postProcess() {
|
||||
$batchIds = array();
|
||||
foreach ($_POST as $key => $value) {
|
||||
if (substr($key, 0, 6) == "check_") {
|
||||
$batch = explode("_", $key);
|
||||
$batchIds[] = $batch[1];
|
||||
}
|
||||
}
|
||||
if (!empty($_POST['batch_update'])) {
|
||||
CRM_Batch_BAO_Batch::closeReOpen($batchIds, $_POST['batch_update']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
547
sites/all/modules/civicrm/CRM/Financial/Page/AJAX.php
Normal file
547
sites/all/modules/civicrm/CRM/Financial/Page/AJAX.php
Normal file
|
@ -0,0 +1,547 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class contains all the function that are called using AJAX
|
||||
*/
|
||||
class CRM_Financial_Page_AJAX {
|
||||
|
||||
/**
|
||||
* get financial accounts of required account relationship.
|
||||
* $financialAccountType array with key account relationship and value financial account type option groups
|
||||
*
|
||||
* @param $config
|
||||
*/
|
||||
public static function jqFinancial($config) {
|
||||
if (!isset($_GET['_value']) ||
|
||||
empty($_GET['_value'])
|
||||
) {
|
||||
CRM_Utils_System::civiExit();
|
||||
}
|
||||
$defaultId = NULL;
|
||||
if ($_GET['_value'] == 'select') {
|
||||
$result = CRM_Contribute_PseudoConstant::financialAccount();
|
||||
}
|
||||
else {
|
||||
$financialAccountType = CRM_Financial_BAO_FinancialAccount::getfinancialAccountRelations();
|
||||
$financialAccountType = CRM_Utils_Array::value($_GET['_value'], $financialAccountType);
|
||||
$result = CRM_Contribute_PseudoConstant::financialAccount(NULL, $financialAccountType);
|
||||
if ($financialAccountType) {
|
||||
$defaultId = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_financial_account WHERE is_default = 1 AND financial_account_type_id = $financialAccountType");
|
||||
}
|
||||
}
|
||||
$elements = array(
|
||||
array(
|
||||
'name' => ts('- select -'),
|
||||
'value' => 'select',
|
||||
),
|
||||
);
|
||||
|
||||
if (!empty($result)) {
|
||||
foreach ($result as $id => $name) {
|
||||
$selectedArray = array();
|
||||
if ($id == $defaultId) {
|
||||
$selectedArray['selected'] = 'Selected';
|
||||
}
|
||||
$elements[] = array(
|
||||
'name' => $name,
|
||||
'value' => $id,
|
||||
) + $selectedArray;
|
||||
}
|
||||
}
|
||||
CRM_Utils_JSON::output($elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $config
|
||||
*/
|
||||
public static function jqFinancialRelation($config) {
|
||||
if (!isset($_GET['_value']) ||
|
||||
empty($_GET['_value'])
|
||||
) {
|
||||
CRM_Utils_System::civiExit();
|
||||
}
|
||||
|
||||
if ($_GET['_value'] != 'select') {
|
||||
$financialAccountType = CRM_Financial_BAO_FinancialAccount::getfinancialAccountRelations(TRUE);
|
||||
$financialAccountId = CRM_Utils_Request::retrieve('_value', 'Positive');
|
||||
$financialAccountTypeId = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', $financialAccountId, 'financial_account_type_id');
|
||||
}
|
||||
$params['orderColumn'] = 'label';
|
||||
$result = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', $params);
|
||||
|
||||
$elements = array(
|
||||
array(
|
||||
'name' => ts('- Select Financial Account Relationship -'),
|
||||
'value' => 'select',
|
||||
),
|
||||
);
|
||||
|
||||
$countResult = count($financialAccountType[$financialAccountTypeId]);
|
||||
if (!empty($result)) {
|
||||
foreach ($result as $id => $name) {
|
||||
if (in_array($id, $financialAccountType[$financialAccountTypeId]) && $_GET['_value'] != 'select') {
|
||||
if ($countResult != 1) {
|
||||
$elements[] = array(
|
||||
'name' => $name,
|
||||
'value' => $id,
|
||||
);
|
||||
}
|
||||
else {
|
||||
$elements[] = array(
|
||||
'name' => $name,
|
||||
'value' => $id,
|
||||
'selected' => 'Selected',
|
||||
);
|
||||
}
|
||||
}
|
||||
elseif ($_GET['_value'] == 'select') {
|
||||
$elements[] = array(
|
||||
'name' => $name,
|
||||
'value' => $id,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
CRM_Utils_JSON::output($elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $config
|
||||
*/
|
||||
public static function jqFinancialType($config) {
|
||||
if (!isset($_GET['_value']) ||
|
||||
empty($_GET['_value'])
|
||||
) {
|
||||
CRM_Utils_System::civiExit();
|
||||
}
|
||||
$productId = CRM_Utils_Request::retrieve('_value', 'Positive');
|
||||
$elements = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Product', $productId, 'financial_type_id');
|
||||
CRM_Utils_JSON::output($elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to perform action on batch records.
|
||||
*/
|
||||
public static function assignRemove() {
|
||||
$op = CRM_Utils_Type::escape($_POST['op'], 'String');
|
||||
$recordBAO = CRM_Utils_Type::escape($_POST['recordBAO'], 'String');
|
||||
foreach ($_POST['records'] as $record) {
|
||||
$recordID = CRM_Utils_Type::escape($record, 'Positive', FALSE);
|
||||
if ($recordID) {
|
||||
$records[] = $recordID;
|
||||
}
|
||||
}
|
||||
|
||||
$entityID = CRM_Utils_Request::retrieve('entityID', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST');
|
||||
$methods = array(
|
||||
'assign' => 'create',
|
||||
'remove' => 'del',
|
||||
'reopen' => 'create',
|
||||
'close' => 'create',
|
||||
'delete' => 'deleteBatch',
|
||||
);
|
||||
if ($op == 'close') {
|
||||
$totals = CRM_Batch_BAO_Batch::batchTotals($records);
|
||||
}
|
||||
$response = array('status' => 'record-updated-fail');
|
||||
// first munge and clean the recordBAO and get rid of any non alpha numeric characters
|
||||
$recordBAO = CRM_Utils_String::munge($recordBAO);
|
||||
$recordClass = explode('_', $recordBAO);
|
||||
// make sure recordClass is in the CRM namespace and
|
||||
// at least 3 levels deep
|
||||
if ($recordClass[0] == 'CRM' && count($recordClass) >= 3) {
|
||||
foreach ($records as $recordID) {
|
||||
$params = array();
|
||||
switch ($op) {
|
||||
case 'assign':
|
||||
case 'remove':
|
||||
$recordPID = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $recordID, 'payment_instrument_id');
|
||||
$batchPID = CRM_Core_DAO::getFieldValue('CRM_Batch_DAO_Batch', $entityID, 'payment_instrument_id');
|
||||
$paymentInstrument = CRM_Core_PseudoConstant::getLabel('CRM_Batch_BAO_Batch', 'payment_instrument_id', $batchPID);
|
||||
if ($op == 'remove' || ($recordPID == $batchPID && $op == 'assign') || !isset($batchPID)) {
|
||||
$params = array(
|
||||
'entity_id' => $recordID,
|
||||
'entity_table' => 'civicrm_financial_trxn',
|
||||
'batch_id' => $entityID,
|
||||
);
|
||||
}
|
||||
else {
|
||||
$response = array('status' => ts("This batch is configured to include only transactions using %1 payment method. If you want to include other transactions, please edit the batch first and modify the Payment Method.", array(1 => $paymentInstrument)));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'close':
|
||||
// Update totals when closing a batch
|
||||
$params = $totals[$recordID];
|
||||
case 'reopen':
|
||||
$status = $op == 'close' ? 'Closed' : 'Reopened';
|
||||
$batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id', array('labelColumn' => 'name'));
|
||||
$params['status_id'] = CRM_Utils_Array::key($status, $batchStatus);
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$params['modified_date'] = date('YmdHis');
|
||||
$params['modified_id'] = $session->get('userID');
|
||||
$params['id'] = $recordID;
|
||||
break;
|
||||
|
||||
case 'export':
|
||||
CRM_Utils_System::redirect("civicrm/financial/batch/export?reset=1&id=$recordID");
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$params = $recordID;
|
||||
break;
|
||||
}
|
||||
|
||||
if (method_exists($recordBAO, $methods[$op]) & !empty($params)) {
|
||||
$updated = call_user_func_array(array($recordBAO, $methods[$op]), array(&$params));
|
||||
if ($updated) {
|
||||
$redirectStatus = $updated->status_id;
|
||||
if ($batchStatus[$updated->status_id] == "Reopened") {
|
||||
$redirectStatus = array_search("Open", $batchStatus);
|
||||
}
|
||||
$response = array(
|
||||
'status' => 'record-updated-success',
|
||||
'status_id' => $redirectStatus,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
CRM_Utils_JSON::output($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function uses the deprecated v1 datatable api and needs updating. See CRM-16353.
|
||||
* @deprecated
|
||||
*
|
||||
* @return string|wtf??
|
||||
*/
|
||||
public static function getFinancialTransactionsList() {
|
||||
$sortMapper = array(
|
||||
0 => '',
|
||||
1 => '',
|
||||
2 => 'sort_name',
|
||||
3 => 'amount',
|
||||
4 => 'trxn_id',
|
||||
5 => 'transaction_date',
|
||||
6 => 'receive_date',
|
||||
7 => 'payment_method',
|
||||
8 => 'status',
|
||||
9 => 'name',
|
||||
);
|
||||
|
||||
$sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
|
||||
$return = isset($_REQUEST['return']) ? CRM_Utils_Type::escape($_REQUEST['return'], 'Boolean') : FALSE;
|
||||
$offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
|
||||
$rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
|
||||
$sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL;
|
||||
$sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
|
||||
$context = isset($_REQUEST['context']) ? CRM_Utils_Type::escape($_REQUEST['context'], 'String') : NULL;
|
||||
$entityID = isset($_REQUEST['entityID']) ? CRM_Utils_Type::escape($_REQUEST['entityID'], 'String') : NULL;
|
||||
$notPresent = isset($_REQUEST['notPresent']) ? CRM_Utils_Type::escape($_REQUEST['notPresent'], 'String') : NULL;
|
||||
$statusID = isset($_REQUEST['statusID']) ? CRM_Utils_Type::escape($_REQUEST['statusID'], 'String') : NULL;
|
||||
$search = isset($_REQUEST['search']) ? TRUE : FALSE;
|
||||
|
||||
$params = $_POST;
|
||||
if ($sort && $sortOrder) {
|
||||
$params['sortBy'] = $sort . ' ' . $sortOrder;
|
||||
}
|
||||
|
||||
$returnvalues = array(
|
||||
'civicrm_financial_trxn.payment_instrument_id as payment_method',
|
||||
'civicrm_contribution.contact_id as contact_id',
|
||||
'civicrm_contribution.id as contributionID',
|
||||
'contact_a.sort_name',
|
||||
'civicrm_financial_trxn.total_amount as amount',
|
||||
'civicrm_financial_trxn.trxn_id as trxn_id',
|
||||
'contact_a.contact_type',
|
||||
'contact_a.contact_sub_type',
|
||||
'civicrm_financial_trxn.trxn_date as transaction_date',
|
||||
'civicrm_contribution.receive_date as receive_date',
|
||||
'civicrm_financial_type.name',
|
||||
'civicrm_financial_trxn.currency as currency',
|
||||
'civicrm_financial_trxn.status_id as status',
|
||||
'civicrm_financial_trxn.check_number as check_number',
|
||||
);
|
||||
|
||||
$columnHeader = array(
|
||||
'contact_type' => '',
|
||||
'sort_name' => ts('Contact Name'),
|
||||
'amount' => ts('Amount'),
|
||||
'trxn_id' => ts('Trxn ID'),
|
||||
'transaction_date' => ts('Transaction Date'),
|
||||
'receive_date' => ts('Received'),
|
||||
'payment_method' => ts('Payment Method'),
|
||||
'status' => ts('Status'),
|
||||
'name' => ts('Type'),
|
||||
);
|
||||
|
||||
if ($sort && $sortOrder) {
|
||||
$params['sortBy'] = $sort . ' ' . $sortOrder;
|
||||
}
|
||||
|
||||
$params['page'] = ($offset / $rowCount) + 1;
|
||||
$params['rp'] = $rowCount;
|
||||
|
||||
$params['context'] = $context;
|
||||
$params['offset'] = ($params['page'] - 1) * $params['rp'];
|
||||
$params['rowCount'] = $params['rp'];
|
||||
$params['sort'] = CRM_Utils_Array::value('sortBy', $params);
|
||||
$params['total'] = 0;
|
||||
|
||||
// get batch list
|
||||
if (isset($notPresent)) {
|
||||
$financialItem = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues, $notPresent, $params);
|
||||
if ($search) {
|
||||
$unassignedTransactions = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues, $notPresent, $params, TRUE);
|
||||
}
|
||||
else {
|
||||
$unassignedTransactions = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues, $notPresent, NULL, TRUE);
|
||||
}
|
||||
while ($unassignedTransactions->fetch()) {
|
||||
$unassignedTransactionsCount[] = $unassignedTransactions->id;
|
||||
}
|
||||
if (!empty($unassignedTransactionsCount)) {
|
||||
$params['total'] = count($unassignedTransactionsCount);
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
$financialItem = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues, NULL, $params);
|
||||
$assignedTransactions = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues);
|
||||
while ($assignedTransactions->fetch()) {
|
||||
$assignedTransactionsCount[] = $assignedTransactions->id;
|
||||
}
|
||||
if (!empty($assignedTransactionsCount)) {
|
||||
$params['total'] = count($assignedTransactionsCount);
|
||||
}
|
||||
}
|
||||
$financialitems = array();
|
||||
if ($statusID) {
|
||||
$batchStatuses = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id', array('labelColumn' => 'name', 'condition' => " v.value={$statusID}"));
|
||||
$batchStatus = $batchStatuses[$statusID];
|
||||
}
|
||||
while ($financialItem->fetch()) {
|
||||
$row[$financialItem->id] = array();
|
||||
foreach ($columnHeader as $columnKey => $columnValue) {
|
||||
if ($financialItem->contact_sub_type && $columnKey == 'contact_type') {
|
||||
$row[$financialItem->id][$columnKey] = $financialItem->contact_sub_type;
|
||||
continue;
|
||||
}
|
||||
$row[$financialItem->id][$columnKey] = $financialItem->$columnKey;
|
||||
if ($columnKey == 'sort_name' && $financialItem->$columnKey && $financialItem->contact_id) {
|
||||
$url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid=" . $financialItem->contact_id);
|
||||
$row[$financialItem->id][$columnKey] = '<a href=' . $url . '>' . $financialItem->$columnKey . '</a>';
|
||||
}
|
||||
elseif ($columnKey == 'payment_method' && $financialItem->$columnKey) {
|
||||
$row[$financialItem->id][$columnKey] = CRM_Core_PseudoConstant::getLabel('CRM_Batch_BAO_Batch', 'payment_instrument_id', $financialItem->$columnKey);
|
||||
if ($row[$financialItem->id][$columnKey] == 'Check') {
|
||||
$checkNumber = $financialItem->check_number ? ' (' . $financialItem->check_number . ')' : '';
|
||||
$row[$financialItem->id][$columnKey] = $row[$financialItem->id][$columnKey] . $checkNumber;
|
||||
}
|
||||
}
|
||||
elseif ($columnKey == 'amount' && $financialItem->$columnKey) {
|
||||
$row[$financialItem->id][$columnKey] = CRM_Utils_Money::format($financialItem->$columnKey, $financialItem->currency);
|
||||
}
|
||||
elseif ($columnKey == 'transaction_date' && $financialItem->$columnKey) {
|
||||
$row[$financialItem->id][$columnKey] = CRM_Utils_Date::customFormat($financialItem->$columnKey);
|
||||
}
|
||||
elseif ($columnKey == 'receive_date' && $financialItem->$columnKey) {
|
||||
$row[$financialItem->id][$columnKey] = CRM_Utils_Date::customFormat($financialItem->$columnKey);
|
||||
}
|
||||
elseif ($columnKey == 'status' && $financialItem->$columnKey) {
|
||||
$row[$financialItem->id][$columnKey] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $financialItem->$columnKey);
|
||||
}
|
||||
}
|
||||
if (isset($batchStatus) && in_array($batchStatus, array('Open', 'Reopened'))) {
|
||||
if (isset($notPresent)) {
|
||||
$js = "enableActions('x')";
|
||||
$row[$financialItem->id]['check'] = "<input type='checkbox' id='mark_x_" . $financialItem->id . "' name='mark_x_" . $financialItem->id . "' value='1' onclick={$js}></input>";
|
||||
$row[$financialItem->id]['action'] = CRM_Core_Action::formLink(
|
||||
CRM_Financial_Form_BatchTransaction::links(),
|
||||
NULL,
|
||||
array(
|
||||
'id' => $financialItem->id,
|
||||
'contid' => $financialItem->contributionID,
|
||||
'cid' => $financialItem->contact_id,
|
||||
),
|
||||
ts('more'),
|
||||
FALSE,
|
||||
'financialItem.batch.row',
|
||||
'FinancialItem',
|
||||
$financialItem->id
|
||||
);
|
||||
}
|
||||
else {
|
||||
$js = "enableActions('y')";
|
||||
$row[$financialItem->id]['check'] = "<input type='checkbox' id='mark_y_" . $financialItem->id . "' name='mark_y_" . $financialItem->id . "' value='1' onclick={$js}></input>";
|
||||
$row[$financialItem->id]['action'] = CRM_Core_Action::formLink(
|
||||
CRM_Financial_Page_BatchTransaction::links(),
|
||||
NULL,
|
||||
array(
|
||||
'id' => $financialItem->id,
|
||||
'contid' => $financialItem->contributionID,
|
||||
'cid' => $financialItem->contact_id,
|
||||
),
|
||||
ts('more'),
|
||||
FALSE,
|
||||
'financialItem.batch.row',
|
||||
'FinancialItem',
|
||||
$financialItem->id
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$row[$financialItem->id]['check'] = NULL;
|
||||
$tempBAO = new CRM_Financial_Page_BatchTransaction();
|
||||
$links = $tempBAO->links();
|
||||
unset($links['remove']);
|
||||
$row[$financialItem->id]['action'] = CRM_Core_Action::formLink(
|
||||
$links,
|
||||
NULL,
|
||||
array(
|
||||
'id' => $financialItem->id,
|
||||
'contid' => $financialItem->contributionID,
|
||||
'cid' => $financialItem->contact_id,
|
||||
),
|
||||
ts('more'),
|
||||
FALSE,
|
||||
'financialItem.batch.row',
|
||||
'FinancialItem',
|
||||
$financialItem->id
|
||||
);
|
||||
}
|
||||
if ($financialItem->contact_id) {
|
||||
$row[$financialItem->id]['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage(CRM_Utils_Array::value('contact_sub_type', $row[$financialItem->id]) ? $row[$financialItem->id]['contact_sub_type'] : CRM_Utils_Array::value('contact_type', $row[$financialItem->id]), FALSE, $financialItem->contact_id);
|
||||
}
|
||||
$financialitems = $row;
|
||||
}
|
||||
|
||||
$iFilteredTotal = $iTotal = $params['total'];
|
||||
$selectorElements = array(
|
||||
'check',
|
||||
'contact_type',
|
||||
'sort_name',
|
||||
'amount',
|
||||
'trxn_id',
|
||||
'transaction_date',
|
||||
'receive_date',
|
||||
'payment_method',
|
||||
'status',
|
||||
'name',
|
||||
'action',
|
||||
);
|
||||
|
||||
if ($return) {
|
||||
return CRM_Utils_JSON::encodeDataTableSelector($financialitems, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
|
||||
}
|
||||
CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
|
||||
echo CRM_Utils_JSON::encodeDataTableSelector($financialitems, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
|
||||
CRM_Utils_System::civiExit();
|
||||
}
|
||||
|
||||
public static function bulkAssignRemove() {
|
||||
$checkIDs = $_REQUEST['ID'];
|
||||
$entityID = CRM_Utils_Type::escape($_REQUEST['entityID'], 'String');
|
||||
$action = CRM_Utils_Type::escape($_REQUEST['action'], 'String');
|
||||
foreach ($checkIDs as $key => $value) {
|
||||
if ((substr($value, 0, 7) == "mark_x_" && $action == 'Assign') || (substr($value, 0, 7) == "mark_y_" && $action == 'Remove')) {
|
||||
$contributions = explode("_", $value);
|
||||
$cIDs[] = $contributions[2];
|
||||
}
|
||||
}
|
||||
|
||||
$batchPID = CRM_Core_DAO::getFieldValue('CRM_Batch_DAO_Batch', $entityID, 'payment_instrument_id');
|
||||
$paymentInstrument = CRM_Core_PseudoConstant::getLabel('CRM_Batch_BAO_Batch', 'payment_instrument_id', $batchPID);
|
||||
foreach ($cIDs as $key => $value) {
|
||||
$recordPID = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $value, 'payment_instrument_id');
|
||||
if ($action == 'Remove' || ($recordPID == $batchPID && $action == 'Assign') || !isset($batchPID)) {
|
||||
$params = array(
|
||||
'entity_id' => $value,
|
||||
'entity_table' => 'civicrm_financial_trxn',
|
||||
'batch_id' => $entityID,
|
||||
);
|
||||
if ($action == 'Assign') {
|
||||
$updated = CRM_Batch_BAO_EntityBatch::create($params);
|
||||
}
|
||||
else {
|
||||
$updated = CRM_Batch_BAO_EntityBatch::del($params);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($updated) {
|
||||
$status = array('status' => 'record-updated-success');
|
||||
}
|
||||
else {
|
||||
$status = array('status' => ts("This batch is configured to include only transactions using %1 payment method. If you want to include other transactions, please edit the batch first and modify the Payment Method.", array(1 => $paymentInstrument)));
|
||||
}
|
||||
CRM_Utils_JSON::output($status);
|
||||
}
|
||||
|
||||
public static function getBatchSummary() {
|
||||
$batchID = CRM_Utils_Type::escape($_REQUEST['batchID'], 'String');
|
||||
$params = array('id' => $batchID);
|
||||
|
||||
$batchSummary = self::makeBatchSummary($batchID, $params);
|
||||
|
||||
CRM_Utils_JSON::output($batchSummary);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an array of the batch's summary and returns array to parent getBatchSummary() function.
|
||||
*
|
||||
* @param $batchID
|
||||
* @param $params
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function makeBatchSummary($batchID, $params) {
|
||||
$batchInfo = CRM_Batch_BAO_Batch::retrieve($params, $value);
|
||||
$batchTotals = CRM_Batch_BAO_Batch::batchTotals(array($batchID));
|
||||
$batchSummary = array(
|
||||
'created_by' => CRM_Contact_BAO_Contact::displayName($batchInfo->created_id),
|
||||
'status' => CRM_Core_PseudoConstant::getLabel('CRM_Batch_BAO_Batch', 'status_id', $batchInfo->status_id),
|
||||
'description' => $batchInfo->description,
|
||||
'payment_instrument' => CRM_Core_PseudoConstant::getLabel('CRM_Batch_BAO_Batch', 'payment_instrument_id', $batchInfo->payment_instrument_id),
|
||||
'item_count' => $batchInfo->item_count,
|
||||
'assigned_item_count' => $batchTotals[$batchID]['item_count'],
|
||||
'total' => CRM_Utils_Money::format($batchInfo->total),
|
||||
'assigned_total' => CRM_Utils_Money::format($batchTotals[$batchID]['total']),
|
||||
'opened_date' => CRM_Utils_Date::customFormat($batchInfo->created_date),
|
||||
);
|
||||
|
||||
return $batchSummary;
|
||||
}
|
||||
|
||||
}
|
119
sites/all/modules/civicrm/CRM/Financial/Page/Batch.php
Normal file
119
sites/all/modules/civicrm/CRM/Financial/Page/Batch.php
Normal file
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Page for displaying list of current batches
|
||||
*/
|
||||
class CRM_Financial_Page_Batch extends CRM_Core_Page_Basic {
|
||||
|
||||
/**
|
||||
* The action links that we need to display for the browse screen
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_links = NULL;
|
||||
|
||||
/**
|
||||
* Get BAO Name.
|
||||
*
|
||||
* @return string
|
||||
* Classname of BAO.
|
||||
*/
|
||||
public function getBAOName() {
|
||||
return 'CRM_Batch_BAO_Batch';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get links.
|
||||
*/
|
||||
public function &links() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name of edit form.
|
||||
*
|
||||
* @return string
|
||||
* Classname of edit form.
|
||||
*/
|
||||
public function editForm() {
|
||||
return 'CRM_Financial_Form_FinancialBatch';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get edit form name.
|
||||
*
|
||||
* @return string
|
||||
* name of this page.
|
||||
*/
|
||||
public function editName() {
|
||||
return ts('Accounting Batch Processing');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user context.
|
||||
*
|
||||
* @param null $mode
|
||||
*
|
||||
* @return string
|
||||
* user context.
|
||||
*/
|
||||
public function userContext($mode = NULL) {
|
||||
return CRM_Utils_System::currentPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Browse all entities.
|
||||
*/
|
||||
public function browse() {
|
||||
$status = CRM_Utils_Request::retrieve('status', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, 1);
|
||||
$this->assign('status', $status);
|
||||
$this->search();
|
||||
}
|
||||
|
||||
public function search() {
|
||||
if ($this->_action & (CRM_Core_Action::ADD |
|
||||
CRM_Core_Action::UPDATE |
|
||||
CRM_Core_Action::DELETE
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$form = new CRM_Core_Controller_Simple('CRM_Financial_Form_Search', ts('Search Batches'), CRM_Core_Action::ADD);
|
||||
$form->setEmbedded(TRUE);
|
||||
$form->setParent($this);
|
||||
$form->process();
|
||||
$form->run();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,150 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Page for displaying list of financial batches
|
||||
*/
|
||||
class CRM_Financial_Page_BatchTransaction extends CRM_Core_Page_Basic {
|
||||
/**
|
||||
* The action links that we need to display for the browse screen.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_links = NULL;
|
||||
static $_entityID;
|
||||
|
||||
static $_columnHeader = NULL;
|
||||
static $_returnvalues = NULL;
|
||||
|
||||
/**
|
||||
* Get BAO Name.
|
||||
*
|
||||
* @return string
|
||||
* Classname of BAO.
|
||||
*/
|
||||
public function getBAOName() {
|
||||
return 'CRM_Batch_BAO_Batch';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action Links.
|
||||
*
|
||||
* @return array
|
||||
* (reference) of action links
|
||||
*/
|
||||
public function &links() {
|
||||
if (!(self::$_links)) {
|
||||
self::$_links = array(
|
||||
'view' => array(
|
||||
'name' => ts('View'),
|
||||
'url' => 'civicrm/contact/view/contribution',
|
||||
'qs' => 'reset=1&id=%%contid%%&cid=%%cid%%&action=view&context=contribution&selectedChild=contribute',
|
||||
'title' => ts('View Contribution'),
|
||||
),
|
||||
'remove' => array(
|
||||
'name' => ts('Remove'),
|
||||
'title' => ts('Remove Transaction'),
|
||||
'extra' => 'onclick = "assignRemove( %%id%%,\'' . 'remove' . '\' );"',
|
||||
),
|
||||
);
|
||||
}
|
||||
return self::$_links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the page.
|
||||
*
|
||||
* This method is called after the page is created. It checks for the
|
||||
* type of action and executes that action.
|
||||
* Finally it calls the parent's run method.
|
||||
*/
|
||||
public function run() {
|
||||
// get the requested action
|
||||
$action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); // default to 'browse'
|
||||
|
||||
// assign vars to templates
|
||||
$this->assign('action', $action);
|
||||
|
||||
self::$_entityID = CRM_Utils_Request::retrieve('bid', 'Positive');
|
||||
$statusID = NULL;
|
||||
if (isset(self::$_entityID)) {
|
||||
$statusID = CRM_Core_DAO::getFieldValue('CRM_Batch_BAO_Batch', self::$_entityID, 'status_id');
|
||||
}
|
||||
$breadCrumb
|
||||
= array(
|
||||
array(
|
||||
'title' => ts('Accounting Batches'),
|
||||
'url' => CRM_Utils_System::url('civicrm/financial/financialbatches',
|
||||
"reset=1&batchStatus=$statusID"),
|
||||
),
|
||||
);
|
||||
|
||||
CRM_Utils_System::appendBreadCrumb($breadCrumb);
|
||||
$this->edit($action, self::$_entityID);
|
||||
return parent::run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name of edit form.
|
||||
*
|
||||
* @return string
|
||||
* Classname of edit form.
|
||||
*/
|
||||
public function editForm() {
|
||||
return 'CRM_Financial_Form_BatchTransaction';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get edit form name.
|
||||
*
|
||||
* @return string
|
||||
* name of this page.
|
||||
*/
|
||||
public function editName() {
|
||||
return 'Batch';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user context.
|
||||
*
|
||||
* @param null $mode
|
||||
*
|
||||
* @return string
|
||||
* user context.
|
||||
*/
|
||||
public function userContext($mode = NULL) {
|
||||
return 'civicrm/batchtransaction';
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,168 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Page for displaying list of financial types
|
||||
*/
|
||||
class CRM_Financial_Page_FinancialAccount extends CRM_Core_Page_Basic {
|
||||
|
||||
public $useLivePageJS = TRUE;
|
||||
/**
|
||||
* The action links that we need to display for the browse screen.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_links = NULL;
|
||||
|
||||
/**
|
||||
* Get BAO Name.
|
||||
*
|
||||
* @return string
|
||||
* Classname of BAO.
|
||||
*/
|
||||
public function getBAOName() {
|
||||
return 'CRM_Financial_BAO_FinancialAccount';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action Links.
|
||||
*
|
||||
* @return array
|
||||
* (reference) of action links
|
||||
*/
|
||||
public function &links() {
|
||||
if (!(self::$_links)) {
|
||||
self::$_links = array(
|
||||
CRM_Core_Action::UPDATE => array(
|
||||
'name' => ts('Edit'),
|
||||
'url' => 'civicrm/admin/financial/financialAccount',
|
||||
'qs' => 'action=update&id=%%id%%&reset=1',
|
||||
'title' => ts('Edit Financial Type'),
|
||||
),
|
||||
CRM_Core_Action::DISABLE => array(
|
||||
'name' => ts('Disable'),
|
||||
'ref' => 'crm-enable-disable',
|
||||
'title' => ts('Disable Financial Type'),
|
||||
),
|
||||
CRM_Core_Action::ENABLE => array(
|
||||
'name' => ts('Enable'),
|
||||
'ref' => 'crm-enable-disable',
|
||||
'title' => ts('Enable Financial Type'),
|
||||
),
|
||||
CRM_Core_Action::DELETE => array(
|
||||
'name' => ts('Delete'),
|
||||
'url' => 'civicrm/admin/financial/financialAccount',
|
||||
'qs' => 'action=delete&id=%%id%%',
|
||||
'title' => ts('Delete Financial Type'),
|
||||
),
|
||||
);
|
||||
}
|
||||
return self::$_links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Browse all custom data groups.
|
||||
*/
|
||||
public function browse() {
|
||||
// get all custom groups sorted by weight
|
||||
$contributionType = array();
|
||||
$dao = new CRM_Financial_DAO_FinancialAccount();
|
||||
$dao->orderBy('financial_account_type_id, name');
|
||||
$dao->find();
|
||||
$financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id');
|
||||
|
||||
while ($dao->fetch()) {
|
||||
$contributionType[$dao->id] = array();
|
||||
CRM_Core_DAO::storeValues($dao, $contributionType[$dao->id]);
|
||||
$contributionType[$dao->id]['financial_account_type_id'] = $financialAccountType[$dao->financial_account_type_id];
|
||||
// form all action links
|
||||
$action = array_sum(array_keys($this->links()));
|
||||
|
||||
// update enable/disable links depending on if it is is_reserved or is_active
|
||||
if ($dao->is_reserved) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
if ($dao->is_active) {
|
||||
$action -= CRM_Core_Action::ENABLE;
|
||||
}
|
||||
else {
|
||||
$action -= CRM_Core_Action::DISABLE;
|
||||
}
|
||||
}
|
||||
|
||||
$contributionType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action,
|
||||
array('id' => $dao->id),
|
||||
ts('more'),
|
||||
FALSE,
|
||||
'financialAccount.manage.action',
|
||||
'FinancialAccount',
|
||||
$dao->id
|
||||
);
|
||||
}
|
||||
$this->assign('rows', $contributionType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name of edit form.
|
||||
*
|
||||
* @return string
|
||||
* Classname of edit form.
|
||||
*/
|
||||
public function editForm() {
|
||||
return 'CRM_Financial_Form_FinancialAccount';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get edit form name.
|
||||
*
|
||||
* @return string
|
||||
* name of this page.
|
||||
*/
|
||||
public function editName() {
|
||||
return 'Financial Types';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user context.
|
||||
*
|
||||
* @param null $mode
|
||||
*
|
||||
* @return string
|
||||
* user context.
|
||||
*/
|
||||
public function userContext($mode = NULL) {
|
||||
return 'civicrm/admin/financial/financialAccount';
|
||||
}
|
||||
|
||||
}
|
146
sites/all/modules/civicrm/CRM/Financial/Page/FinancialBatch.php
Normal file
146
sites/all/modules/civicrm/CRM/Financial/Page/FinancialBatch.php
Normal file
|
@ -0,0 +1,146 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Page for displaying list of financial types
|
||||
*/
|
||||
class CRM_Financial_Page_FinancialBatch extends CRM_Core_Page_Basic {
|
||||
|
||||
/**
|
||||
* The action links that we need to display for the browse screen.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_links = NULL;
|
||||
|
||||
/**
|
||||
* Get BAO Name.
|
||||
*
|
||||
* @return string
|
||||
* classname of BAO.
|
||||
*/
|
||||
public function getBAOName() {
|
||||
return 'CRM_Batch_BAO_Batch';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action Links.
|
||||
*
|
||||
* @return array
|
||||
* (reference) of action links
|
||||
*/
|
||||
public function &links() {
|
||||
if (!(self::$_links)) {
|
||||
self::$_links = array();
|
||||
}
|
||||
return self::$_links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the page.
|
||||
*
|
||||
* This method is called after the page is created. It checks for the
|
||||
* type of action and executes that action.
|
||||
* Finally it calls the parent's run method.
|
||||
*/
|
||||
public function run() {
|
||||
$context = CRM_Utils_Request::retrieve('context', 'String', $this);
|
||||
$this->set("context", $context);
|
||||
|
||||
$id = $this->getIdAndAction();
|
||||
|
||||
// what action to take ?
|
||||
if ($this->_action & (CRM_Core_Action::UPDATE |
|
||||
CRM_Core_Action::ADD |
|
||||
CRM_Core_Action::CLOSE |
|
||||
CRM_Core_Action::REOPEN |
|
||||
CRM_Core_Action::EXPORT)
|
||||
) {
|
||||
$this->edit($this->_action, $id);
|
||||
}
|
||||
// parent run
|
||||
return CRM_Core_Page::run();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get name of edit form.
|
||||
*
|
||||
* @return string
|
||||
* classname of edit form.
|
||||
*/
|
||||
public function editForm() {
|
||||
return 'CRM_Financial_Form_FinancialBatch';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get edit form name.
|
||||
*
|
||||
* @return string
|
||||
* name of this page.
|
||||
*/
|
||||
public function editName() {
|
||||
return 'Accounting Batch';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user context.
|
||||
*
|
||||
* Redirect to civicrm home page when clicked on cancel button
|
||||
*
|
||||
* @param null $mode
|
||||
*
|
||||
* @return string
|
||||
* user context.
|
||||
*/
|
||||
public function userContext($mode = NULL) {
|
||||
$context = $this->get("context");
|
||||
if ($mode == CRM_Core_Action::UPDATE || ($mode = CRM_Core_Action::ADD & isset($context))) {
|
||||
return "civicrm/financial/financialbatches";
|
||||
}
|
||||
return 'civicrm';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $mode
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function userContextParams($mode = NULL) {
|
||||
$context = $this->get("context");
|
||||
if ($mode == CRM_Core_Action::UPDATE || ($mode = CRM_Core_Action::ADD & isset($context))) {
|
||||
return "reset=1&batchStatus={$context}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
199
sites/all/modules/civicrm/CRM/Financial/Page/FinancialType.php
Normal file
199
sites/all/modules/civicrm/CRM/Financial/Page/FinancialType.php
Normal file
|
@ -0,0 +1,199 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Page for displaying list of financial types
|
||||
*/
|
||||
class CRM_Financial_Page_FinancialType extends CRM_Core_Page_Basic {
|
||||
|
||||
public $useLivePageJS = TRUE;
|
||||
/**
|
||||
* The action links that we need to display for the browse screen.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_links = NULL;
|
||||
|
||||
/**
|
||||
* Get BAO Name.
|
||||
*
|
||||
* @return string
|
||||
* Classname of BAO.
|
||||
*/
|
||||
public function getBAOName() {
|
||||
return 'CRM_Financial_BAO_FinancialType';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action Links.
|
||||
*
|
||||
* @return array
|
||||
* (reference) of action links
|
||||
*/
|
||||
public function &links() {
|
||||
if (!(self::$_links)) {
|
||||
self::$_links = array(
|
||||
CRM_Core_Action::BROWSE => array(
|
||||
'name' => ts('Accounts'),
|
||||
'url' => 'civicrm/admin/financial/financialType/accounts',
|
||||
'qs' => 'reset=1&action=browse&aid=%%id%%',
|
||||
'title' => ts('Accounts'),
|
||||
),
|
||||
CRM_Core_Action::UPDATE => array(
|
||||
'name' => ts('Edit'),
|
||||
'url' => 'civicrm/admin/financial/financialType',
|
||||
'qs' => 'action=update&id=%%id%%&reset=1',
|
||||
'title' => ts('Edit Financial Type'),
|
||||
),
|
||||
CRM_Core_Action::DISABLE => array(
|
||||
'name' => ts('Disable'),
|
||||
'ref' => 'crm-enable-disable',
|
||||
'title' => ts('Disable Financial Type'),
|
||||
),
|
||||
CRM_Core_Action::ENABLE => array(
|
||||
'name' => ts('Enable'),
|
||||
'ref' => 'crm-enable-disable',
|
||||
'title' => ts('Enable Financial Type'),
|
||||
),
|
||||
CRM_Core_Action::DELETE => array(
|
||||
'name' => ts('Delete'),
|
||||
'url' => 'civicrm/admin/financial/financialType',
|
||||
'qs' => 'action=delete&id=%%id%%',
|
||||
'title' => ts('Delete Financial Type'),
|
||||
),
|
||||
);
|
||||
}
|
||||
return self::$_links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Browse all financial types.
|
||||
*/
|
||||
public function browse() {
|
||||
// Check permission for Financial Type when ACL-FT is enabled
|
||||
if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()
|
||||
&& !CRM_Core_Permission::check('administer CiviCRM Financial Types')
|
||||
) {
|
||||
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
|
||||
}
|
||||
// get all financial types sorted by weight
|
||||
$financialType = array();
|
||||
$dao = new CRM_Financial_DAO_FinancialType();
|
||||
$dao->orderBy('name');
|
||||
$dao->find();
|
||||
|
||||
while ($dao->fetch()) {
|
||||
$financialType[$dao->id] = array();
|
||||
CRM_Core_DAO::storeValues($dao, $financialType[$dao->id]);
|
||||
$defaults = $financialAccountId = array();
|
||||
$financialAccounts = CRM_Contribute_PseudoConstant::financialAccount();
|
||||
$financialAccountIds = array();
|
||||
|
||||
$params['entity_id'] = $dao->id;
|
||||
$params['entity_table'] = 'civicrm_financial_type';
|
||||
CRM_Financial_BAO_FinancialTypeAccount::retrieve($params, CRM_Core_DAO::$_nullArray, $financialAccountIds);
|
||||
|
||||
foreach ($financialAccountIds as $key => $values) {
|
||||
if (!empty($financialAccounts[$values['financial_account_id']])) {
|
||||
$financialAccountId[$values['financial_account_id']] = CRM_Utils_Array::value(
|
||||
$values['financial_account_id'], $financialAccounts);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($financialAccountId)) {
|
||||
$financialType[$dao->id]['financial_account'] = implode(',', $financialAccountId);
|
||||
}
|
||||
|
||||
// form all action links
|
||||
$action = array_sum(array_keys($this->links()));
|
||||
|
||||
// update enable/disable links depending on if it is is_reserved or is_active
|
||||
if ($dao->is_reserved) {
|
||||
$action -= CRM_Core_Action::ENABLE;
|
||||
$action -= CRM_Core_Action::DISABLE;
|
||||
$action -= CRM_Core_Action::DELETE;
|
||||
}
|
||||
else {
|
||||
if ($dao->is_active) {
|
||||
$action -= CRM_Core_Action::ENABLE;
|
||||
}
|
||||
else {
|
||||
$action -= CRM_Core_Action::DISABLE;
|
||||
}
|
||||
}
|
||||
|
||||
$financialType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action,
|
||||
array('id' => $dao->id),
|
||||
ts('more'),
|
||||
FALSE,
|
||||
'financialType.manage.action',
|
||||
'FinancialType',
|
||||
$dao->id
|
||||
);
|
||||
}
|
||||
$this->assign('rows', $financialType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name of edit form.
|
||||
*
|
||||
* @return string
|
||||
* Classname of edit form.
|
||||
*/
|
||||
public function editForm() {
|
||||
return 'CRM_Financial_Form_FinancialType';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get edit form name.
|
||||
*
|
||||
* @return string
|
||||
* name of this page.
|
||||
*/
|
||||
public function editName() {
|
||||
return 'Financial Types';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user context.
|
||||
*
|
||||
* @param null $mode
|
||||
*
|
||||
* @return string
|
||||
* user context.
|
||||
*/
|
||||
public function userContext($mode = NULL) {
|
||||
return 'civicrm/admin/financial/financialType';
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,213 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Page for displaying list of financial type accounts
|
||||
*/
|
||||
class CRM_Financial_Page_FinancialTypeAccount extends CRM_Core_Page {
|
||||
/**
|
||||
* The action links that we need to display for the browse screen.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_links = NULL;
|
||||
|
||||
/**
|
||||
* The account id that we need to display for the browse screen.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_aid = NULL;
|
||||
|
||||
/**
|
||||
* Get BAO Name.
|
||||
*
|
||||
* @return string
|
||||
* Classname of BAO.
|
||||
*/
|
||||
public function getBAOName() {
|
||||
return 'CRM_Financial_BAO_FinancialTypeAccount';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action Links.
|
||||
*
|
||||
* @return array
|
||||
* (reference) of action links
|
||||
*/
|
||||
public function &links() {
|
||||
if (!(self::$_links)) {
|
||||
self::$_links = array(
|
||||
CRM_Core_Action::UPDATE => array(
|
||||
'name' => ts('Edit'),
|
||||
'url' => 'civicrm/admin/financial/financialType/accounts',
|
||||
'qs' => 'action=update&id=%%id%%&aid=%%aid%%&reset=1',
|
||||
'title' => ts('Edit Financial Type Account'),
|
||||
),
|
||||
CRM_Core_Action::DELETE => array(
|
||||
'name' => ts('Delete'),
|
||||
'url' => 'civicrm/admin/financial/financialType/accounts',
|
||||
'qs' => 'action=delete&id=%%id%%&aid=%%aid%%',
|
||||
'title' => ts('Delete Financial Type Account'),
|
||||
),
|
||||
);
|
||||
}
|
||||
return self::$_links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the page.
|
||||
*
|
||||
* This method is called after the page is created. It checks for the
|
||||
* type of action and executes that action.
|
||||
* Finally it calls the parent's run method.
|
||||
*/
|
||||
public function run() {
|
||||
// get the requested action
|
||||
$action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); // default to 'browse'
|
||||
|
||||
// assign vars to templates
|
||||
$this->assign('action', $action);
|
||||
$id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);
|
||||
$this->_aid = CRM_Utils_Request::retrieve('aid', 'Positive', $this, FALSE, 0);
|
||||
|
||||
// what action to take ?
|
||||
if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) {
|
||||
$this->edit($action, $id);
|
||||
}
|
||||
else {
|
||||
$this->browse($action, $id);
|
||||
}
|
||||
|
||||
// parent run
|
||||
return parent::run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Browse all Financial Type Account data.
|
||||
*/
|
||||
public function browse() {
|
||||
// get all Financial Type Account data sorted by weight
|
||||
$financialType = array();
|
||||
$params = array();
|
||||
$dao = new CRM_Financial_DAO_EntityFinancialAccount();
|
||||
$params['entity_id'] = $this->_aid;
|
||||
$params['entity_table'] = 'civicrm_financial_type';
|
||||
if ($this->_aid) {
|
||||
$relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
|
||||
$this->_title = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $this->_aid, 'name');
|
||||
CRM_Utils_System::setTitle($this->_title . ' - ' . ts('Assigned Financial Accounts'));
|
||||
$financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id');
|
||||
$accountRelationship = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship');
|
||||
$dao->copyValues($params);
|
||||
$dao->find();
|
||||
while ($dao->fetch()) {
|
||||
$financialType[$dao->id] = array();
|
||||
CRM_Core_DAO::storeValues($dao, $financialType[$dao->id]);
|
||||
|
||||
$params = array('id' => $dao->financial_account_id);
|
||||
$defaults = array();
|
||||
$financialAccount = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults);
|
||||
if (!empty($financialAccount)) {
|
||||
$financialType[$dao->id]['financial_account'] = $financialAccount->name;
|
||||
$financialType[$dao->id]['accounting_code'] = $financialAccount->accounting_code;
|
||||
$financialType[$dao->id]['account_type_code'] = $financialAccount->account_type_code;
|
||||
$financialType[$dao->id]['is_active'] = $financialAccount->is_active;
|
||||
if (!empty($financialAccount->contact_id)) {
|
||||
$financialType[$dao->id]['owned_by'] = CRM_Contact_BAO_Contact::displayName($financialAccount->contact_id);
|
||||
}
|
||||
if (!empty($financialAccount->financial_account_type_id)) {
|
||||
$optionGroupName = 'financial_account_type';
|
||||
$financialType[$dao->id]['financial_account_type'] = CRM_Utils_Array::value($financialAccount->financial_account_type_id, $financialAccountType);
|
||||
|
||||
}
|
||||
if (!empty($dao->account_relationship)) {
|
||||
$optionGroupName = 'account_relationship';
|
||||
$financialType[$dao->id]['account_relationship'] = CRM_Utils_Array::value($dao->account_relationship, $accountRelationship);
|
||||
}
|
||||
}
|
||||
// form all action links
|
||||
$action = array_sum(array_keys($this->links()));
|
||||
$links = self::links();
|
||||
|
||||
// CRM-12492
|
||||
if ($dao->account_relationship == $relationTypeId) {
|
||||
unset($links[CRM_Core_Action::DELETE]);
|
||||
}
|
||||
$financialType[$dao->id]['action'] = CRM_Core_Action::formLink($links, $action,
|
||||
array(
|
||||
'id' => $dao->id,
|
||||
'aid' => $dao->entity_id,
|
||||
),
|
||||
ts('more'),
|
||||
FALSE,
|
||||
'financialTypeAccount.manage.action',
|
||||
'FinancialTypeAccount',
|
||||
$dao->id
|
||||
);
|
||||
}
|
||||
$this->assign('rows', $financialType);
|
||||
$this->assign('aid', $this->_aid);
|
||||
$this->assign('financialTypeTitle', $this->_title);
|
||||
}
|
||||
else {
|
||||
CRM_Core_Error::fatal();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit CiviCRM Financial Type Account data.
|
||||
*
|
||||
* editing would involved modifying existing financial Account Type + adding data
|
||||
* to new financial Account Type.
|
||||
*
|
||||
* @param string $action
|
||||
* The action to be invoked.
|
||||
*/
|
||||
public function edit($action) {
|
||||
// create a simple controller for editing CiviCRM Profile data
|
||||
$controller = new CRM_Core_Controller_Simple('CRM_Financial_Form_FinancialTypeAccount', ts('Financial Account Types'), $action);
|
||||
|
||||
// set the userContext stack
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/financial/financialType/accounts',
|
||||
'reset=1&action=browse&aid=' . $this->_aid));
|
||||
$controller->set('aid', $this->_aid);
|
||||
|
||||
$controller->setEmbedded(TRUE);
|
||||
$controller->process();
|
||||
$controller->run();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue