First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
851
sites/all/modules/civicrm/CRM/Batch/BAO/Batch.php
Normal file
851
sites/all/modules/civicrm/CRM/Batch/BAO/Batch.php
Normal file
|
@ -0,0 +1,851 @@
|
|||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Batch BAO class.
|
||||
*/
|
||||
class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch {
|
||||
|
||||
/**
|
||||
* Cache for the current batch object.
|
||||
*/
|
||||
static $_batch = NULL;
|
||||
|
||||
/**
|
||||
* Not sure this is the best way to do this. Depends on how exportFinancialBatch() below gets called.
|
||||
* Maybe a parameter to that function is better.
|
||||
*/
|
||||
static $_exportFormat = NULL;
|
||||
|
||||
/**
|
||||
* Create a new batch.
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return object
|
||||
* $batch batch object
|
||||
*/
|
||||
public static function create(&$params) {
|
||||
$op = 'edit';
|
||||
$batchId = CRM_Utils_Array::value('id', $params);
|
||||
if (!$batchId) {
|
||||
$op = 'create';
|
||||
$params['name'] = CRM_Utils_String::titleToVar($params['title']);
|
||||
}
|
||||
CRM_Utils_Hook::pre($op, 'Batch', $batchId, $params);
|
||||
$batch = new CRM_Batch_DAO_Batch();
|
||||
$batch->copyValues($params);
|
||||
$batch->save();
|
||||
|
||||
CRM_Utils_Hook::post($op, 'Batch', $batch->id, $batch);
|
||||
|
||||
return $batch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the information about the batch.
|
||||
*
|
||||
* @param array $params
|
||||
* (reference ) an assoc array of name/value pairs.
|
||||
* @param array $defaults
|
||||
* (reference ) an assoc array to hold the flattened values.
|
||||
*
|
||||
* @return array
|
||||
* CRM_Batch_BAO_Batch object on success, null otherwise
|
||||
*/
|
||||
public static function retrieve(&$params, &$defaults) {
|
||||
$batch = new CRM_Batch_DAO_Batch();
|
||||
$batch->copyValues($params);
|
||||
if ($batch->find(TRUE)) {
|
||||
CRM_Core_DAO::storeValues($batch, $defaults);
|
||||
return $batch;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get profile id associated with the batch type.
|
||||
*
|
||||
* @param int $batchTypeId
|
||||
* Batch type id.
|
||||
*
|
||||
* @return int
|
||||
* $profileId profile id
|
||||
*/
|
||||
public static function getProfileId($batchTypeId) {
|
||||
//retrieve the profile specific to batch type
|
||||
switch ($batchTypeId) {
|
||||
case 1:
|
||||
case 3:
|
||||
//batch profile used for pledges
|
||||
$profileName = "contribution_batch_entry";
|
||||
break;
|
||||
|
||||
case 2:
|
||||
//batch profile used for memberships
|
||||
$profileName = "membership_batch_entry";
|
||||
break;
|
||||
}
|
||||
|
||||
// get and return the profile id
|
||||
return CRM_Core_DAO::getFieldValue('CRM_Core_BAO_UFGroup', $profileName, 'id', 'name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate batch name.
|
||||
*
|
||||
* @return string
|
||||
* batch name
|
||||
*/
|
||||
public static function generateBatchName() {
|
||||
$sql = "SELECT max(id) FROM civicrm_batch";
|
||||
$batchNo = CRM_Core_DAO::singleValueQuery($sql) + 1;
|
||||
return ts('Batch %1', array(1 => $batchNo)) . ': ' . date('Y-m-d');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete batch entry.
|
||||
*
|
||||
* @param int $batchId
|
||||
* Batch id.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function deleteBatch($batchId) {
|
||||
// delete entry from batch table
|
||||
CRM_Utils_Hook::pre('delete', 'Batch', $batchId, CRM_Core_DAO::$_nullArray);
|
||||
$batch = new CRM_Batch_DAO_Batch();
|
||||
$batch->id = $batchId;
|
||||
$batch->delete();
|
||||
CRM_Utils_Hook::post('delete', 'Batch', $batch->id, $batch);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper for ajax batch selector.
|
||||
*
|
||||
* @param array $params
|
||||
* Associated array for params record id.
|
||||
*
|
||||
* @return array
|
||||
* associated array of batch list
|
||||
*/
|
||||
public static function getBatchListSelector(&$params) {
|
||||
// format the params
|
||||
$params['offset'] = ($params['page'] - 1) * $params['rp'];
|
||||
$params['rowCount'] = $params['rp'];
|
||||
$params['sort'] = CRM_Utils_Array::value('sortBy', $params);
|
||||
|
||||
// get batches
|
||||
$batches = self::getBatchList($params);
|
||||
|
||||
// get batch totals for open batches
|
||||
$fetchTotals = array();
|
||||
$batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id', array('labelColumn' => 'name'));
|
||||
$batchStatus = array(
|
||||
array_search('Open', $batchStatus),
|
||||
array_search('Reopened', $batchStatus),
|
||||
);
|
||||
if ($params['context'] == 'financialBatch') {
|
||||
foreach ($batches as $id => $batch) {
|
||||
if (in_array($batch['status_id'], $batchStatus)) {
|
||||
$fetchTotals[] = $id;
|
||||
}
|
||||
}
|
||||
}
|
||||
$totals = self::batchTotals($fetchTotals);
|
||||
|
||||
// add count
|
||||
$params['total'] = self::getBatchCount($params);
|
||||
|
||||
// format params and add links
|
||||
$batchList = array();
|
||||
|
||||
foreach ($batches as $id => $value) {
|
||||
$batch = array();
|
||||
if ($params['context'] == 'financialBatch') {
|
||||
$batch['check'] = $value['check'];
|
||||
}
|
||||
$batch['batch_name'] = $value['title'];
|
||||
$batch['total'] = '';
|
||||
$batch['payment_instrument'] = $value['payment_instrument'];
|
||||
$batch['item_count'] = CRM_Utils_Array::value('item_count', $value);
|
||||
$batch['type'] = CRM_Utils_Array::value('batch_type', $value);
|
||||
if (!empty($value['total'])) {
|
||||
// CRM-21205
|
||||
$batch['total'] = CRM_Utils_Money::format($value['total'], $value['currency']);
|
||||
}
|
||||
|
||||
// Compare totals with actuals
|
||||
if (isset($totals[$id])) {
|
||||
$batch['item_count'] = self::displayTotals($totals[$id]['item_count'], $batch['item_count']);
|
||||
$batch['total'] = self::displayTotals(CRM_Utils_Money::format($totals[$id]['total']), $batch['total']);
|
||||
}
|
||||
$batch['status'] = $value['batch_status'];
|
||||
$batch['created_by'] = $value['created_by'];
|
||||
$batch['links'] = $value['action'];
|
||||
$batchList[$id] = $batch;
|
||||
}
|
||||
return $batchList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of batches.
|
||||
*
|
||||
* @param array $params
|
||||
* Associated array for params.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getBatchList(&$params) {
|
||||
$apiParams = self::whereClause($params);
|
||||
|
||||
if (!empty($params['rowCount']) && is_numeric($params['rowCount'])
|
||||
&& is_numeric($params['offset']) && $params['rowCount'] > 0
|
||||
) {
|
||||
$apiParams['options'] = array('offset' => $params['offset'], 'limit' => $params['rowCount']);
|
||||
}
|
||||
$apiParams['options']['sort'] = 'id DESC';
|
||||
if (!empty($params['sort'])) {
|
||||
$apiParams['options']['sort'] = CRM_Utils_Type::escape($params['sort'], 'String');
|
||||
}
|
||||
|
||||
$return = array(
|
||||
"id",
|
||||
"name",
|
||||
"title",
|
||||
"description",
|
||||
"created_date",
|
||||
"status_id",
|
||||
"modified_id",
|
||||
"modified_date",
|
||||
"type_id",
|
||||
"mode_id",
|
||||
"total",
|
||||
"item_count",
|
||||
"exported_date",
|
||||
"payment_instrument_id",
|
||||
"created_id.sort_name",
|
||||
"created_id",
|
||||
);
|
||||
$apiParams['return'] = $return;
|
||||
$batches = civicrm_api3('Batch', 'get', $apiParams);
|
||||
$obj = new CRM_Batch_BAO_Batch();
|
||||
if (!empty($params['context'])) {
|
||||
$links = $obj->links($params['context']);
|
||||
}
|
||||
else {
|
||||
$links = $obj->links();
|
||||
}
|
||||
|
||||
$batchTypes = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'type_id');
|
||||
$batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id');
|
||||
$batchStatusByName = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id', array('labelColumn' => 'name'));
|
||||
$paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
|
||||
|
||||
$results = array();
|
||||
foreach ($batches['values'] as $values) {
|
||||
$newLinks = $links;
|
||||
$action = array_sum(array_keys($newLinks));
|
||||
|
||||
if ($values['status_id'] == array_search('Closed', $batchStatusByName) && $params['context'] != 'financialBatch') {
|
||||
$newLinks = array();
|
||||
}
|
||||
elseif ($params['context'] == 'financialBatch') {
|
||||
$values['check'] = "<input type='checkbox' id='check_" .
|
||||
$values['id'] .
|
||||
"' name='check_" .
|
||||
$values['id'] .
|
||||
"' value='1' data-status_id='" .
|
||||
$values['status_id'] . "' class='select-row'></input>";
|
||||
|
||||
switch ($batchStatusByName[$values['status_id']]) {
|
||||
case 'Open':
|
||||
case 'Reopened':
|
||||
CRM_Utils_Array::remove($newLinks, 'reopen', 'download');
|
||||
break;
|
||||
|
||||
case 'Closed':
|
||||
CRM_Utils_Array::remove($newLinks, 'close', 'edit', 'download');
|
||||
break;
|
||||
|
||||
case 'Exported':
|
||||
CRM_Utils_Array::remove($newLinks, 'close', 'edit', 'reopen', 'export');
|
||||
}
|
||||
if (!CRM_Batch_BAO_Batch::checkBatchPermission('edit', $values['created_id'])) {
|
||||
CRM_Utils_Array::remove($newLinks, 'edit');
|
||||
}
|
||||
if (!CRM_Batch_BAO_Batch::checkBatchPermission('close', $values['created_id'])) {
|
||||
CRM_Utils_Array::remove($newLinks, 'close', 'export');
|
||||
}
|
||||
if (!CRM_Batch_BAO_Batch::checkBatchPermission('reopen', $values['created_id'])) {
|
||||
CRM_Utils_Array::remove($newLinks, 'reopen');
|
||||
}
|
||||
if (!CRM_Batch_BAO_Batch::checkBatchPermission('export', $values['created_id'])) {
|
||||
CRM_Utils_Array::remove($newLinks, 'export', 'download');
|
||||
}
|
||||
if (!CRM_Batch_BAO_Batch::checkBatchPermission('delete', $values['created_id'])) {
|
||||
CRM_Utils_Array::remove($newLinks, 'delete');
|
||||
}
|
||||
}
|
||||
if (!empty($values['type_id'])) {
|
||||
$values['batch_type'] = $batchTypes[$values['type_id']];
|
||||
}
|
||||
$values['batch_status'] = $batchStatus[$values['status_id']];
|
||||
$values['created_by'] = $values['created_id.sort_name'];
|
||||
$values['payment_instrument'] = '';
|
||||
if (!empty($values['payment_instrument_id'])) {
|
||||
$values['payment_instrument'] = $paymentInstrument[$values['payment_instrument_id']];
|
||||
}
|
||||
$tokens = array('id' => $values['id'], 'status' => $values['status_id']);
|
||||
if ($values['status_id'] == array_search('Exported', $batchStatusByName)) {
|
||||
$aid = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Export Accounting Batch');
|
||||
$activityParams = array('source_record_id' => $values['id'], 'activity_type_id' => $aid);
|
||||
$exportActivity = CRM_Activity_BAO_Activity::retrieve($activityParams, $val);
|
||||
$fid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_EntityFile', $exportActivity->id, 'file_id', 'entity_id');
|
||||
$tokens = array_merge(array('eid' => $exportActivity->id, 'fid' => $fid), $tokens);
|
||||
}
|
||||
$values['action'] = CRM_Core_Action::formLink(
|
||||
$newLinks,
|
||||
$action,
|
||||
$tokens,
|
||||
ts('more'),
|
||||
FALSE,
|
||||
'batch.selector.row',
|
||||
'Batch',
|
||||
$values['id']
|
||||
);
|
||||
// CRM-21205
|
||||
$values['currency'] = CRM_Core_DAO::singleValueQuery("
|
||||
SELECT GROUP_CONCAT(DISTINCT ft.currency)
|
||||
FROM civicrm_batch batch
|
||||
JOIN civicrm_entity_batch eb
|
||||
ON batch.id = eb.batch_id
|
||||
JOIN civicrm_financial_trxn ft
|
||||
ON eb.entity_id = ft.id
|
||||
WHERE batch.id = %1
|
||||
GROUP BY batch.id
|
||||
", array(1 => array($values['id'], 'Positive')));
|
||||
$results[$values['id']] = $values;
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get count of batches.
|
||||
*
|
||||
* @param array $params
|
||||
* Associated array for params.
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public static function getBatchCount(&$params) {
|
||||
$apiParams = self::whereClause($params);
|
||||
return civicrm_api3('Batch', 'getCount', $apiParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format where clause for getting lists of batches.
|
||||
*
|
||||
* @param array $params
|
||||
* Associated array for params.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function whereClause($params) {
|
||||
$clauses = array();
|
||||
// Exclude data-entry batches
|
||||
$batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id', array('labelColumn' => 'name'));
|
||||
if (empty($params['status_id'])) {
|
||||
$clauses['status_id'] = array('NOT IN' => array("Data Entry"));
|
||||
}
|
||||
|
||||
$return = array(
|
||||
"id",
|
||||
"name",
|
||||
"title",
|
||||
"description",
|
||||
"created_date",
|
||||
"status_id",
|
||||
"modified_id",
|
||||
"modified_date",
|
||||
"type_id",
|
||||
"mode_id",
|
||||
"total",
|
||||
"item_count",
|
||||
"exported_date",
|
||||
"payment_instrument_id",
|
||||
"created_id.sort_name",
|
||||
"created_id",
|
||||
);
|
||||
if (!CRM_Core_Permission::check("view all manual batches")) {
|
||||
if (CRM_Core_Permission::check("view own manual batches")) {
|
||||
$loggedInContactId = CRM_Core_Session::singleton()->get('userID');
|
||||
$params['created_id'] = $loggedInContactId;
|
||||
}
|
||||
else {
|
||||
$params['created_id'] = 0;
|
||||
}
|
||||
}
|
||||
foreach ($return as $field) {
|
||||
if (!isset($params[$field])) {
|
||||
continue;
|
||||
}
|
||||
$value = CRM_Utils_Type::escape($params[$field], 'String', FALSE);
|
||||
if (in_array($field, array('name', 'title', 'description', 'created_id.sort_name'))) {
|
||||
$clauses[$field] = array('LIKE' => "%{$value}%");
|
||||
}
|
||||
elseif ($field == 'status_id' && $value == array_search('Open', $batchStatus)) {
|
||||
$clauses['status_id'] = array('IN' => array("Open", 'Reopened'));
|
||||
}
|
||||
else {
|
||||
$clauses[$field] = $value;
|
||||
}
|
||||
}
|
||||
return $clauses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define action links.
|
||||
*
|
||||
* @param null $context
|
||||
*
|
||||
* @return array
|
||||
* array of action links
|
||||
*/
|
||||
public function links($context = NULL) {
|
||||
if ($context == 'financialBatch') {
|
||||
$links = array(
|
||||
'transaction' => array(
|
||||
'name' => ts('Transactions'),
|
||||
'url' => 'civicrm/batchtransaction',
|
||||
'qs' => 'reset=1&bid=%%id%%',
|
||||
'title' => ts('View/Add Transactions to Batch'),
|
||||
),
|
||||
'edit' => array(
|
||||
'name' => ts('Edit'),
|
||||
'url' => 'civicrm/financial/batch',
|
||||
'qs' => 'reset=1&action=update&id=%%id%%&context=1',
|
||||
'title' => ts('Edit Batch'),
|
||||
),
|
||||
'close' => array(
|
||||
'name' => ts('Close'),
|
||||
'title' => ts('Close Batch'),
|
||||
'url' => '#',
|
||||
'extra' => 'rel="close"',
|
||||
),
|
||||
'export' => array(
|
||||
'name' => ts('Export'),
|
||||
'title' => ts('Export Batch'),
|
||||
'url' => '#',
|
||||
'extra' => 'rel="export"',
|
||||
),
|
||||
'reopen' => array(
|
||||
'name' => ts('Re-open'),
|
||||
'title' => ts('Re-open Batch'),
|
||||
'url' => '#',
|
||||
'extra' => 'rel="reopen"',
|
||||
),
|
||||
'delete' => array(
|
||||
'name' => ts('Delete'),
|
||||
'title' => ts('Delete Batch'),
|
||||
'url' => '#',
|
||||
'extra' => 'rel="delete"',
|
||||
),
|
||||
'download' => array(
|
||||
'name' => ts('Download'),
|
||||
'url' => 'civicrm/file',
|
||||
'qs' => 'reset=1&id=%%fid%%&eid=%%eid%%',
|
||||
'title' => ts('Download Batch'),
|
||||
),
|
||||
);
|
||||
}
|
||||
else {
|
||||
$links = array(
|
||||
CRM_Core_Action::COPY => array(
|
||||
'name' => ts('Enter records'),
|
||||
'url' => 'civicrm/batch/entry',
|
||||
'qs' => 'id=%%id%%&reset=1',
|
||||
'title' => ts('Batch Data Entry'),
|
||||
),
|
||||
CRM_Core_Action::UPDATE => array(
|
||||
'name' => ts('Edit'),
|
||||
'url' => 'civicrm/batch',
|
||||
'qs' => 'action=update&id=%%id%%&reset=1',
|
||||
'title' => ts('Edit Batch'),
|
||||
),
|
||||
CRM_Core_Action::DELETE => array(
|
||||
'name' => ts('Delete'),
|
||||
'url' => 'civicrm/batch',
|
||||
'qs' => 'action=delete&id=%%id%%',
|
||||
'title' => ts('Delete Batch'),
|
||||
),
|
||||
);
|
||||
}
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get batch list.
|
||||
*
|
||||
* @return array
|
||||
* all batches excluding batches with data entry in progress
|
||||
*/
|
||||
public static function getBatches() {
|
||||
$dataEntryStatusId = CRM_Core_PseudoConstant::getKey('CRM_Batch_BAO_Batch', 'status_id', 'Data Entry');
|
||||
$query = "SELECT id, title
|
||||
FROM civicrm_batch
|
||||
WHERE item_count >= 1
|
||||
AND status_id != {$dataEntryStatusId}
|
||||
ORDER BY title";
|
||||
|
||||
$batches = array();
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
while ($dao->fetch()) {
|
||||
$batches[$dao->id] = $dao->title;
|
||||
}
|
||||
return $batches;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate sum of all entries in a batch.
|
||||
* Used to validate and update item_count and total when closing an accounting batch
|
||||
*
|
||||
* @param array $batchIds
|
||||
* @return array
|
||||
*/
|
||||
public static function batchTotals($batchIds) {
|
||||
$totals = array_fill_keys($batchIds, array('item_count' => 0, 'total' => 0));
|
||||
if ($batchIds) {
|
||||
$sql = "SELECT eb.batch_id, COUNT(tx.id) AS item_count, SUM(tx.total_amount) AS total
|
||||
FROM civicrm_entity_batch eb
|
||||
INNER JOIN civicrm_financial_trxn tx ON tx.id = eb.entity_id AND eb.entity_table = 'civicrm_financial_trxn'
|
||||
WHERE eb.batch_id IN (" . implode(',', $batchIds) . ")
|
||||
GROUP BY eb.batch_id";
|
||||
$dao = CRM_Core_DAO::executeQuery($sql);
|
||||
while ($dao->fetch()) {
|
||||
$totals[$dao->batch_id] = (array) $dao;
|
||||
}
|
||||
$dao->free();
|
||||
}
|
||||
return $totals;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format markup for comparing two totals.
|
||||
*
|
||||
* @param $actual
|
||||
* calculated total
|
||||
* @param $expected
|
||||
* user-entered total
|
||||
* @return array
|
||||
*/
|
||||
public static function displayTotals($actual, $expected) {
|
||||
$class = 'actual-value';
|
||||
if ($expected && $expected != $actual) {
|
||||
$class .= ' crm-error';
|
||||
}
|
||||
$actualTitle = ts('Current Total');
|
||||
$output = "<span class='$class' title='$actualTitle'>$actual</span>";
|
||||
if ($expected) {
|
||||
$expectedTitle = ts('Expected Total');
|
||||
$output .= " / <span class='expected-value' title='$expectedTitle'>$expected</span>";
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for exporting financial accounts, currently we support CSV and IIF format
|
||||
* @see http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+Specifications+-++Batches#CiviAccountsSpecifications-Batches-%C2%A0Overviewofimplementation
|
||||
*
|
||||
* @param array $batchIds
|
||||
* Associated array of batch ids.
|
||||
* @param string $exportFormat
|
||||
* Export format.
|
||||
*/
|
||||
public static function exportFinancialBatch($batchIds, $exportFormat) {
|
||||
if (empty($batchIds)) {
|
||||
CRM_Core_Error::fatal(ts('No batches were selected.'));
|
||||
return;
|
||||
}
|
||||
if (empty($exportFormat)) {
|
||||
CRM_Core_Error::fatal(ts('No export format selected.'));
|
||||
return;
|
||||
}
|
||||
self::$_exportFormat = $exportFormat;
|
||||
|
||||
// Instantiate appropriate exporter based on user-selected format.
|
||||
$exporterClass = "CRM_Financial_BAO_ExportFormat_" . self::$_exportFormat;
|
||||
if (class_exists($exporterClass)) {
|
||||
$exporter = new $exporterClass();
|
||||
}
|
||||
else {
|
||||
CRM_Core_Error::fatal("Could not locate exporter: $exporterClass");
|
||||
}
|
||||
$export = array();
|
||||
foreach ($batchIds as $batchId) {
|
||||
// export only batches whose status is set to Exported.
|
||||
$result = civicrm_api3('Batch', 'getcount', array(
|
||||
'id' => $batchId,
|
||||
'status_id' => "Exported",
|
||||
));
|
||||
if (!$result) {
|
||||
continue;
|
||||
}
|
||||
$export[$batchId] = $exporter->generateExportQuery($batchId);
|
||||
}
|
||||
if ($export) {
|
||||
$exporter->makeExport($export);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $batchIds
|
||||
* @param $status
|
||||
*/
|
||||
public static function closeReOpen($batchIds = array(), $status) {
|
||||
$batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id');
|
||||
$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');
|
||||
foreach ($batchIds as $key => $value) {
|
||||
$params['id'] = $ids['batchID'] = $value;
|
||||
self::create($params, $ids);
|
||||
}
|
||||
$url = CRM_Utils_System::url('civicrm/financial/financialbatches', "reset=1&batchStatus={$params['status_id']}");
|
||||
CRM_Utils_System::redirect($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve financial items assigned for a batch.
|
||||
*
|
||||
* @param int $entityID
|
||||
* @param array $returnValues
|
||||
* @param bool $notPresent
|
||||
* @param array $params
|
||||
* @param bool $getCount
|
||||
*
|
||||
* @return CRM_Core_DAO
|
||||
*/
|
||||
public static function getBatchFinancialItems($entityID, $returnValues, $notPresent = NULL, $params = NULL, $getCount = FALSE) {
|
||||
if (!$getCount) {
|
||||
if (!empty($params['rowCount']) &&
|
||||
$params['rowCount'] > 0
|
||||
) {
|
||||
$limit = " LIMIT {$params['offset']}, {$params['rowCount']} ";
|
||||
}
|
||||
}
|
||||
// action is taken depending upon the mode
|
||||
$select = 'civicrm_financial_trxn.id ';
|
||||
if (!empty($returnValues)) {
|
||||
$select .= " , " . implode(' , ', $returnValues);
|
||||
}
|
||||
|
||||
$orderBy = " ORDER BY civicrm_financial_trxn.id";
|
||||
if (!empty($params['sort'])) {
|
||||
$orderBy = ' ORDER BY ' . CRM_Utils_Type::escape($params['sort'], 'String');
|
||||
}
|
||||
|
||||
$from = "civicrm_financial_trxn
|
||||
INNER JOIN civicrm_entity_financial_trxn ON civicrm_entity_financial_trxn.financial_trxn_id = civicrm_financial_trxn.id
|
||||
INNER JOIN civicrm_contribution ON (civicrm_contribution.id = civicrm_entity_financial_trxn.entity_id
|
||||
AND civicrm_entity_financial_trxn.entity_table='civicrm_contribution')
|
||||
LEFT JOIN civicrm_entity_batch ON civicrm_entity_batch.entity_table = 'civicrm_financial_trxn'
|
||||
AND civicrm_entity_batch.entity_id = civicrm_financial_trxn.id
|
||||
LEFT JOIN civicrm_financial_type ON civicrm_financial_type.id = civicrm_contribution.financial_type_id
|
||||
LEFT JOIN civicrm_contact contact_a ON contact_a.id = civicrm_contribution.contact_id
|
||||
LEFT JOIN civicrm_contribution_soft ON civicrm_contribution_soft.contribution_id = civicrm_contribution.id
|
||||
";
|
||||
|
||||
$searchFields = array(
|
||||
'sort_name',
|
||||
'financial_type_id',
|
||||
'contribution_page_id',
|
||||
'payment_instrument_id',
|
||||
'contribution_trxn_id',
|
||||
'contribution_source',
|
||||
'contribution_currency_type',
|
||||
'contribution_pay_later',
|
||||
'contribution_recurring',
|
||||
'contribution_test',
|
||||
'contribution_thankyou_date_is_not_null',
|
||||
'contribution_receipt_date_is_not_null',
|
||||
'contribution_pcp_made_through_id',
|
||||
'contribution_pcp_display_in_roll',
|
||||
'contribution_date_relative',
|
||||
'contribution_amount_low',
|
||||
'contribution_amount_high',
|
||||
'contribution_in_honor_of',
|
||||
'contact_tags',
|
||||
'group',
|
||||
'contribution_date_relative',
|
||||
'contribution_date_high',
|
||||
'contribution_date_low',
|
||||
'contribution_check_number',
|
||||
'contribution_status_id',
|
||||
);
|
||||
$values = array();
|
||||
foreach ($searchFields as $field) {
|
||||
if (isset($params[$field])) {
|
||||
$values[$field] = $params[$field];
|
||||
if ($field == 'sort_name') {
|
||||
$from .= " LEFT JOIN civicrm_contact contact_b ON contact_b.id = civicrm_contribution.contact_id
|
||||
LEFT JOIN civicrm_email ON contact_b.id = civicrm_email.contact_id";
|
||||
}
|
||||
if ($field == 'contribution_in_honor_of') {
|
||||
$from .= " LEFT JOIN civicrm_contact contact_b ON contact_b.id = civicrm_contribution.contact_id";
|
||||
}
|
||||
if ($field == 'contact_tags') {
|
||||
$from .= " LEFT JOIN civicrm_entity_tag `civicrm_entity_tag-{$params[$field]}` ON `civicrm_entity_tag-{$params[$field]}`.entity_id = contact_a.id";
|
||||
}
|
||||
if ($field == 'group') {
|
||||
$from .= " LEFT JOIN civicrm_group_contact `civicrm_group_contact-{$params[$field]}` ON contact_a.id = `civicrm_group_contact-{$params[$field]}`.contact_id ";
|
||||
}
|
||||
if ($field == 'contribution_date_relative') {
|
||||
$relativeDate = explode('.', $params[$field]);
|
||||
$date = CRM_Utils_Date::relativeToAbsolute($relativeDate[0], $relativeDate[1]);
|
||||
$values['contribution_date_low'] = $date['from'];
|
||||
$values['contribution_date_high'] = $date['to'];
|
||||
}
|
||||
$searchParams = CRM_Contact_BAO_Query::convertFormValues($values);
|
||||
// @todo the use of defaultReturnProperties means the search will be inefficient
|
||||
// as slow-unneeded properties are included.
|
||||
$query = new CRM_Contact_BAO_Query($searchParams,
|
||||
CRM_Contribute_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_CONTRIBUTE,
|
||||
FALSE
|
||||
), NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTRIBUTE
|
||||
);
|
||||
if ($field == 'contribution_date_high' || $field == 'contribution_date_low') {
|
||||
$query->dateQueryBuilder($params[$field], 'civicrm_contribution', 'contribution_date', 'receive_date', 'Contribution Date');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($query->_where[0])) {
|
||||
$where = implode(' AND ', $query->_where[0]) .
|
||||
" AND civicrm_entity_batch.batch_id IS NULL ";
|
||||
$where = str_replace('civicrm_contribution.payment_instrument_id', 'civicrm_financial_trxn.payment_instrument_id', $where);
|
||||
}
|
||||
else {
|
||||
if (!$notPresent) {
|
||||
$where = " civicrm_entity_batch.batch_id = {$entityID} ";
|
||||
}
|
||||
else {
|
||||
$where = " civicrm_entity_batch.batch_id IS NULL ";
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT {$select}
|
||||
FROM {$from}
|
||||
WHERE {$where}
|
||||
{$orderBy}
|
||||
";
|
||||
|
||||
if (isset($limit)) {
|
||||
$sql .= "{$limit}";
|
||||
}
|
||||
|
||||
$result = CRM_Core_DAO::executeQuery($sql);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get batch names.
|
||||
* @param string $batchIds
|
||||
*
|
||||
* @return array
|
||||
* array of batches
|
||||
*/
|
||||
public static function getBatchNames($batchIds) {
|
||||
$query = 'SELECT id, title
|
||||
FROM civicrm_batch
|
||||
WHERE id IN (' . $batchIds . ')';
|
||||
|
||||
$batches = array();
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
while ($dao->fetch()) {
|
||||
$batches[$dao->id] = $dao->title;
|
||||
}
|
||||
return $batches;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function get batch statuses.
|
||||
*
|
||||
* @param string $batchIds
|
||||
*
|
||||
* @return array
|
||||
* array of batches
|
||||
*/
|
||||
public static function getBatchStatuses($batchIds) {
|
||||
$query = 'SELECT id, status_id
|
||||
FROM civicrm_batch
|
||||
WHERE id IN (' . $batchIds . ')';
|
||||
|
||||
$batches = array();
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
while ($dao->fetch()) {
|
||||
$batches[$dao->id] = $dao->status_id;
|
||||
}
|
||||
return $batches;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to check permission for batch.
|
||||
*
|
||||
* @param string $action
|
||||
* @param int $batchCreatedId
|
||||
* batch created by contact id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function checkBatchPermission($action, $batchCreatedId = NULL) {
|
||||
if (CRM_Core_Permission::check("{$action} all manual batches")) {
|
||||
return TRUE;
|
||||
}
|
||||
if (CRM_Core_Permission::check("{$action} own manual batches")) {
|
||||
$loggedInContactId = CRM_Core_Session::singleton()->get('userID');
|
||||
if ($batchCreatedId == $loggedInContactId) {
|
||||
return TRUE;
|
||||
}
|
||||
elseif (CRM_Utils_System::isNull($batchCreatedId)) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
73
sites/all/modules/civicrm/CRM/Batch/BAO/EntityBatch.php
Normal file
73
sites/all/modules/civicrm/CRM/Batch/BAO/EntityBatch.php
Normal file
|
@ -0,0 +1,73 @@
|
|||
<?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_Batch_BAO_EntityBatch extends CRM_Batch_DAO_EntityBatch {
|
||||
|
||||
/**
|
||||
* Create entity batch entry.
|
||||
*
|
||||
* @param array $params
|
||||
* @return array
|
||||
*/
|
||||
public static function create(&$params) {
|
||||
$op = 'edit';
|
||||
$entityId = CRM_Utils_Array::value('id', $params);
|
||||
if (!$entityId) {
|
||||
$op = 'create';
|
||||
}
|
||||
CRM_Utils_Hook::pre($op, 'EntityBatch', $entityId, $params);
|
||||
$entityBatch = new CRM_Batch_DAO_EntityBatch();
|
||||
$entityBatch->copyValues($params);
|
||||
$entityBatch->save();
|
||||
CRM_Utils_Hook::post($op, 'EntityBatch', $entityBatch->id, $entityBatch);
|
||||
return $entityBatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove entries from entity batch.
|
||||
* @param array|int $params
|
||||
* @return CRM_Batch_DAO_EntityBatch
|
||||
*/
|
||||
public static function del($params) {
|
||||
if (!is_array($params)) {
|
||||
$params = array('id' => $params);
|
||||
}
|
||||
$entityBatch = new CRM_Batch_DAO_EntityBatch();
|
||||
$entityId = CRM_Utils_Array::value('id', $params);
|
||||
CRM_Utils_Hook::pre('delete', 'EntityBatch', $entityId, $params);
|
||||
$entityBatch->copyValues($params);
|
||||
$entityBatch->delete();
|
||||
CRM_Utils_Hook::post('delete', 'EntityBatch', $entityBatch->id, $entityBatch);
|
||||
return $entityBatch;
|
||||
}
|
||||
|
||||
}
|
490
sites/all/modules/civicrm/CRM/Batch/DAO/Batch.php
Normal file
490
sites/all/modules/civicrm/CRM/Batch/DAO/Batch.php
Normal file
|
@ -0,0 +1,490 @@
|
|||
<?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/Batch/Batch.xml
|
||||
* DO NOT EDIT. Generated by CRM_Core_CodeGen
|
||||
* (GenCodeChecksum:a9d49cd47b4a388ca88aa2af363f952d)
|
||||
*/
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
require_once 'CRM/Utils/Type.php';
|
||||
/**
|
||||
* CRM_Batch_DAO_Batch constructor.
|
||||
*/
|
||||
class CRM_Batch_DAO_Batch extends CRM_Core_DAO {
|
||||
/**
|
||||
* Static instance to hold the table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $_tableName = 'civicrm_batch';
|
||||
/**
|
||||
* Should CiviCRM log any modifications to this table in the civicrm_log table.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
static $_log = false;
|
||||
/**
|
||||
* Unique Address ID
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* Variable name/programmatic handle for this batch.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
/**
|
||||
* Friendly Name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $title;
|
||||
/**
|
||||
* Description of this batch set.
|
||||
*
|
||||
* @var text
|
||||
*/
|
||||
public $description;
|
||||
/**
|
||||
* FK to Contact ID
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $created_id;
|
||||
/**
|
||||
* When was this item created
|
||||
*
|
||||
* @var datetime
|
||||
*/
|
||||
public $created_date;
|
||||
/**
|
||||
* FK to Contact ID
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $modified_id;
|
||||
/**
|
||||
* When was this item created
|
||||
*
|
||||
* @var datetime
|
||||
*/
|
||||
public $modified_date;
|
||||
/**
|
||||
* FK to Saved Search ID
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $saved_search_id;
|
||||
/**
|
||||
* fk to Batch Status options in civicrm_option_values
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $status_id;
|
||||
/**
|
||||
* fk to Batch Type options in civicrm_option_values
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $type_id;
|
||||
/**
|
||||
* fk to Batch mode options in civicrm_option_values
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $mode_id;
|
||||
/**
|
||||
* Total amount for this batch.
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $total;
|
||||
/**
|
||||
* Number of items in a batch.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $item_count;
|
||||
/**
|
||||
* fk to Payment Instrument options in civicrm_option_values
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $payment_instrument_id;
|
||||
/**
|
||||
*
|
||||
* @var datetime
|
||||
*/
|
||||
public $exported_date;
|
||||
/**
|
||||
* cache entered data
|
||||
*
|
||||
* @var longtext
|
||||
*/
|
||||
public $data;
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->__table = 'civicrm_batch';
|
||||
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() , 'created_id', 'civicrm_contact', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'modified_id', 'civicrm_contact', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'saved_search_id', 'civicrm_saved_search', '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('Batch ID') ,
|
||||
'description' => 'Unique Address ID',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_batch',
|
||||
'entity' => 'Batch',
|
||||
'bao' => 'CRM_Batch_BAO_Batch',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'name' => array(
|
||||
'name' => 'name',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Batch Name') ,
|
||||
'description' => 'Variable name/programmatic handle for this batch.',
|
||||
'maxlength' => 64,
|
||||
'size' => CRM_Utils_Type::BIG,
|
||||
'table_name' => 'civicrm_batch',
|
||||
'entity' => 'Batch',
|
||||
'bao' => 'CRM_Batch_BAO_Batch',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
'title' => array(
|
||||
'name' => 'title',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Batch Title') ,
|
||||
'description' => 'Friendly Name.',
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_batch',
|
||||
'entity' => 'Batch',
|
||||
'bao' => 'CRM_Batch_BAO_Batch',
|
||||
'localizable' => 1,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
'description' => array(
|
||||
'name' => 'description',
|
||||
'type' => CRM_Utils_Type::T_TEXT,
|
||||
'title' => ts('Batch Description') ,
|
||||
'description' => 'Description of this batch set.',
|
||||
'rows' => 4,
|
||||
'cols' => 80,
|
||||
'table_name' => 'civicrm_batch',
|
||||
'entity' => 'Batch',
|
||||
'bao' => 'CRM_Batch_BAO_Batch',
|
||||
'localizable' => 1,
|
||||
'html' => array(
|
||||
'type' => 'TextArea',
|
||||
) ,
|
||||
) ,
|
||||
'created_id' => array(
|
||||
'name' => 'created_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Batch Created By') ,
|
||||
'description' => 'FK to Contact ID',
|
||||
'table_name' => 'civicrm_batch',
|
||||
'entity' => 'Batch',
|
||||
'bao' => 'CRM_Batch_BAO_Batch',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Contact_DAO_Contact',
|
||||
) ,
|
||||
'created_date' => array(
|
||||
'name' => 'created_date',
|
||||
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
|
||||
'title' => ts('Batch Created Date') ,
|
||||
'description' => 'When was this item created',
|
||||
'table_name' => 'civicrm_batch',
|
||||
'entity' => 'Batch',
|
||||
'bao' => 'CRM_Batch_BAO_Batch',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select Date',
|
||||
) ,
|
||||
) ,
|
||||
'modified_id' => array(
|
||||
'name' => 'modified_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Batch Modified By') ,
|
||||
'description' => 'FK to Contact ID',
|
||||
'table_name' => 'civicrm_batch',
|
||||
'entity' => 'Batch',
|
||||
'bao' => 'CRM_Batch_BAO_Batch',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Contact_DAO_Contact',
|
||||
) ,
|
||||
'modified_date' => array(
|
||||
'name' => 'modified_date',
|
||||
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
|
||||
'title' => ts('Batch Modified Date') ,
|
||||
'description' => 'When was this item created',
|
||||
'table_name' => 'civicrm_batch',
|
||||
'entity' => 'Batch',
|
||||
'bao' => 'CRM_Batch_BAO_Batch',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'saved_search_id' => array(
|
||||
'name' => 'saved_search_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Batch Smart Group') ,
|
||||
'description' => 'FK to Saved Search ID',
|
||||
'table_name' => 'civicrm_batch',
|
||||
'entity' => 'Batch',
|
||||
'bao' => 'CRM_Batch_BAO_Batch',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Contact_DAO_SavedSearch',
|
||||
'html' => array(
|
||||
'type' => 'EntityRef',
|
||||
) ,
|
||||
) ,
|
||||
'status_id' => array(
|
||||
'name' => 'status_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Batch Status') ,
|
||||
'description' => 'fk to Batch Status options in civicrm_option_values',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_batch',
|
||||
'entity' => 'Batch',
|
||||
'bao' => 'CRM_Batch_BAO_Batch',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'optionGroupName' => 'batch_status',
|
||||
'optionEditPath' => 'civicrm/admin/options/batch_status',
|
||||
)
|
||||
) ,
|
||||
'type_id' => array(
|
||||
'name' => 'type_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Batch Type') ,
|
||||
'description' => 'fk to Batch Type options in civicrm_option_values',
|
||||
'table_name' => 'civicrm_batch',
|
||||
'entity' => 'Batch',
|
||||
'bao' => 'CRM_Batch_BAO_Batch',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'optionGroupName' => 'batch_type',
|
||||
'optionEditPath' => 'civicrm/admin/options/batch_type',
|
||||
)
|
||||
) ,
|
||||
'mode_id' => array(
|
||||
'name' => 'mode_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Batch Mode') ,
|
||||
'description' => 'fk to Batch mode options in civicrm_option_values',
|
||||
'table_name' => 'civicrm_batch',
|
||||
'entity' => 'Batch',
|
||||
'bao' => 'CRM_Batch_BAO_Batch',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'optionGroupName' => 'batch_mode',
|
||||
'optionEditPath' => 'civicrm/admin/options/batch_mode',
|
||||
)
|
||||
) ,
|
||||
'total' => array(
|
||||
'name' => 'total',
|
||||
'type' => CRM_Utils_Type::T_MONEY,
|
||||
'title' => ts('Batch Total') ,
|
||||
'description' => 'Total amount for this batch.',
|
||||
'precision' => array(
|
||||
20,
|
||||
2
|
||||
) ,
|
||||
'table_name' => 'civicrm_batch',
|
||||
'entity' => 'Batch',
|
||||
'bao' => 'CRM_Batch_BAO_Batch',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
'item_count' => array(
|
||||
'name' => 'item_count',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Batch Number of Items') ,
|
||||
'description' => 'Number of items in a batch.',
|
||||
'table_name' => 'civicrm_batch',
|
||||
'entity' => 'Batch',
|
||||
'bao' => 'CRM_Batch_BAO_Batch',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
'payment_instrument_id' => array(
|
||||
'name' => 'payment_instrument_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Batch Payment Method') ,
|
||||
'description' => 'fk to Payment Instrument options in civicrm_option_values',
|
||||
'table_name' => 'civicrm_batch',
|
||||
'entity' => 'Batch',
|
||||
'bao' => 'CRM_Batch_BAO_Batch',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'optionGroupName' => 'payment_instrument',
|
||||
'optionEditPath' => 'civicrm/admin/options/payment_instrument',
|
||||
)
|
||||
) ,
|
||||
'exported_date' => array(
|
||||
'name' => 'exported_date',
|
||||
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
|
||||
'title' => ts('Batch Exported Date') ,
|
||||
'table_name' => 'civicrm_batch',
|
||||
'entity' => 'Batch',
|
||||
'bao' => 'CRM_Batch_BAO_Batch',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'data' => array(
|
||||
'name' => 'data',
|
||||
'type' => CRM_Utils_Type::T_LONGTEXT,
|
||||
'title' => ts('Batch Data') ,
|
||||
'description' => 'cache entered data',
|
||||
'table_name' => 'civicrm_batch',
|
||||
'entity' => 'Batch',
|
||||
'bao' => 'CRM_Batch_BAO_Batch',
|
||||
'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 CRM_Core_DAO::getLocaleTableName(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__, 'batch', $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__, 'batch', $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_batch::1::name',
|
||||
) ,
|
||||
);
|
||||
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
|
||||
}
|
||||
}
|
241
sites/all/modules/civicrm/CRM/Batch/DAO/EntityBatch.php
Normal file
241
sites/all/modules/civicrm/CRM/Batch/DAO/EntityBatch.php
Normal file
|
@ -0,0 +1,241 @@
|
|||
<?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/Batch/EntityBatch.xml
|
||||
* DO NOT EDIT. Generated by CRM_Core_CodeGen
|
||||
* (GenCodeChecksum:f96c0410a5561b46d8aba0fce509ef6a)
|
||||
*/
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
require_once 'CRM/Utils/Type.php';
|
||||
/**
|
||||
* CRM_Batch_DAO_EntityBatch constructor.
|
||||
*/
|
||||
class CRM_Batch_DAO_EntityBatch extends CRM_Core_DAO {
|
||||
/**
|
||||
* Static instance to hold the table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $_tableName = 'civicrm_entity_batch';
|
||||
/**
|
||||
* Should CiviCRM log any modifications to this table in the civicrm_log table.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
static $_log = false;
|
||||
/**
|
||||
* primary key
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* physical tablename for entity being joined to file, e.g. civicrm_contact
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $entity_table;
|
||||
/**
|
||||
* FK to entity table specified in entity_table column.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $entity_id;
|
||||
/**
|
||||
* FK to civicrm_batch
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $batch_id;
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->__table = 'civicrm_entity_batch';
|
||||
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() , 'batch_id', 'civicrm_batch', '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('EntityBatch ID') ,
|
||||
'description' => 'primary key',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_entity_batch',
|
||||
'entity' => 'EntityBatch',
|
||||
'bao' => 'CRM_Batch_BAO_EntityBatch',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'entity_table' => array(
|
||||
'name' => 'entity_table',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('EntityBatch Table') ,
|
||||
'description' => 'physical tablename for entity being joined to file, e.g. civicrm_contact',
|
||||
'maxlength' => 64,
|
||||
'size' => CRM_Utils_Type::BIG,
|
||||
'table_name' => 'civicrm_entity_batch',
|
||||
'entity' => 'EntityBatch',
|
||||
'bao' => 'CRM_Batch_BAO_EntityBatch',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'entity_id' => array(
|
||||
'name' => 'entity_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Entity ID') ,
|
||||
'description' => 'FK to entity table specified in entity_table column.',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_entity_batch',
|
||||
'entity' => 'EntityBatch',
|
||||
'bao' => 'CRM_Batch_BAO_EntityBatch',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'batch_id' => array(
|
||||
'name' => 'batch_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Batch ID') ,
|
||||
'description' => 'FK to civicrm_batch',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_entity_batch',
|
||||
'entity' => 'EntityBatch',
|
||||
'bao' => 'CRM_Batch_BAO_EntityBatch',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Batch_DAO_Batch',
|
||||
'pseudoconstant' => array(
|
||||
'table' => 'civicrm_batch',
|
||||
'keyColumn' => 'id',
|
||||
'labelColumn' => 'title',
|
||||
)
|
||||
) ,
|
||||
);
|
||||
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_batch', $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_batch', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of indices
|
||||
*/
|
||||
public static function indices($localize = TRUE) {
|
||||
$indices = array(
|
||||
'index_entity' => array(
|
||||
'name' => 'index_entity',
|
||||
'field' => array(
|
||||
0 => 'entity_table',
|
||||
1 => 'entity_id',
|
||||
) ,
|
||||
'localizable' => false,
|
||||
'sig' => 'civicrm_entity_batch::0::entity_table::entity_id',
|
||||
) ,
|
||||
'UI_batch_entity' => array(
|
||||
'name' => 'UI_batch_entity',
|
||||
'field' => array(
|
||||
0 => 'batch_id',
|
||||
1 => 'entity_id',
|
||||
2 => 'entity_table',
|
||||
) ,
|
||||
'localizable' => false,
|
||||
'unique' => true,
|
||||
'sig' => 'civicrm_entity_batch::1::batch_id::entity_id::entity_table',
|
||||
) ,
|
||||
);
|
||||
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
|
||||
}
|
||||
}
|
120
sites/all/modules/civicrm/CRM/Batch/Form/Batch.php
Normal file
120
sites/all/modules/civicrm/CRM/Batch/Form/Batch.php
Normal file
|
@ -0,0 +1,120 @@
|
|||
<?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 |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for batch entry.
|
||||
*/
|
||||
class CRM_Batch_Form_Batch extends CRM_Admin_Form {
|
||||
|
||||
/**
|
||||
* PreProcess function.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
// Set the user context.
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/batch', "reset=1"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
$attributes = CRM_Core_DAO::getAttribute('CRM_Batch_DAO_Batch');
|
||||
$this->add('text', 'title', ts('Batch Name'), $attributes['name'], TRUE);
|
||||
|
||||
$batchTypes = CRM_Batch_BAO_Batch::buildOptions('type_id');
|
||||
|
||||
$type = $this->add('select', 'type_id', ts('Type'), $batchTypes);
|
||||
|
||||
if ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
$type->freeze();
|
||||
}
|
||||
|
||||
$this->add('textarea', 'description', ts('Description'), $attributes['description']);
|
||||
$this->add('text', 'item_count', ts('Number of Items'), $attributes['item_count'], TRUE);
|
||||
$this->add('text', 'total', ts('Total Amount'), $attributes['total'], TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
|
||||
if ($this->_action & CRM_Core_Action::ADD) {
|
||||
// Set batch name default.
|
||||
$defaults['title'] = CRM_Batch_BAO_Batch::generateBatchName();
|
||||
}
|
||||
else {
|
||||
$defaults = $this->_values;
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
CRM_Core_Session::setStatus("", ts("Batch Deleted"), "success");
|
||||
CRM_Batch_BAO_Batch::deleteBatch($this->_id);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->_id) {
|
||||
$params['id'] = $this->_id;
|
||||
}
|
||||
else {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$params['created_id'] = $session->get('userID');
|
||||
$params['created_date'] = CRM_Utils_Date::processDate(date("Y-m-d"), date("H:i:s"));
|
||||
}
|
||||
|
||||
// always create with data entry status
|
||||
$params['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Batch_BAO_Batch', 'status_id', 'Data Entry');
|
||||
$batch = CRM_Batch_BAO_Batch::create($params);
|
||||
|
||||
// redirect to batch entry page.
|
||||
$session = CRM_Core_Session::singleton();
|
||||
if ($this->_action & CRM_Core_Action::ADD) {
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/batch/entry', "id={$batch->id}&reset=1&action=add"));
|
||||
}
|
||||
else {
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/batch/entry', "id={$batch->id}&reset=1"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
922
sites/all/modules/civicrm/CRM/Batch/Form/Entry.php
Normal file
922
sites/all/modules/civicrm/CRM/Batch/Form/Entry.php
Normal file
|
@ -0,0 +1,922 @@
|
|||
<?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 for batch entry for contributions/memberships.
|
||||
*/
|
||||
class CRM_Batch_Form_Entry extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* Maximum profile fields that will be displayed.
|
||||
*/
|
||||
protected $_rowCount = 1;
|
||||
|
||||
/**
|
||||
* Batch id.
|
||||
*/
|
||||
protected $_batchId;
|
||||
|
||||
/**
|
||||
* Batch information.
|
||||
*/
|
||||
protected $_batchInfo = array();
|
||||
|
||||
/**
|
||||
* Store the profile id associated with the batch type.
|
||||
*/
|
||||
protected $_profileId;
|
||||
|
||||
public $_action;
|
||||
|
||||
public $_mode;
|
||||
|
||||
public $_params;
|
||||
|
||||
/**
|
||||
* When not to reset sort_name.
|
||||
*/
|
||||
protected $_preserveDefault = TRUE;
|
||||
|
||||
/**
|
||||
* Contact fields.
|
||||
*/
|
||||
protected $_contactFields = array();
|
||||
|
||||
/**
|
||||
* Fields array of fields in the batch profile.
|
||||
* (based on the uf_field table data)
|
||||
* (this can't be protected as it is passed into the CRM_Contact_Form_Task_Batch::parseStreetAddress function
|
||||
* (although a future refactoring might hopefully change that so it uses the api & the function is not
|
||||
* required
|
||||
* @var array
|
||||
*/
|
||||
public $_fields = array();
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_batchId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
|
||||
|
||||
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
|
||||
|
||||
if (empty($this->_batchInfo)) {
|
||||
$params = array('id' => $this->_batchId);
|
||||
CRM_Batch_BAO_Batch::retrieve($params, $this->_batchInfo);
|
||||
|
||||
$this->assign('batchTotal', !empty($this->_batchInfo['total']) ? $this->_batchInfo['total'] : NULL);
|
||||
$this->assign('batchType', $this->_batchInfo['type_id']);
|
||||
|
||||
// get the profile id associted with this batch type
|
||||
$this->_profileId = CRM_Batch_BAO_Batch::getProfileId($this->_batchInfo['type_id']);
|
||||
}
|
||||
CRM_Core_Resources::singleton()
|
||||
->addScriptFile('civicrm', 'templates/CRM/Batch/Form/Entry.js', 1, 'html-header')
|
||||
->addSetting(array('batch' => array('type_id' => $this->_batchInfo['type_id'])))
|
||||
->addSetting(array('setting' => array('monetaryThousandSeparator' => CRM_Core_Config::singleton()->monetaryThousandSeparator)))
|
||||
->addSetting(array('setting' => array('monetaryDecimalPoint' => CRM_Core_Config::singleton()->monetaryDecimalPoint)));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Batch ID.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function setBatchID($id) {
|
||||
$this->_batchId = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
if (!$this->_profileId) {
|
||||
CRM_Core_Error::fatal(ts('Profile for bulk data entry is missing.'));
|
||||
}
|
||||
|
||||
$this->addElement('hidden', 'batch_id', $this->_batchId);
|
||||
|
||||
$batchTypes = CRM_Core_Pseudoconstant::get('CRM_Batch_DAO_Batch', 'type_id', array('flip' => 1), 'validate');
|
||||
// get the profile information
|
||||
if ($this->_batchInfo['type_id'] == $batchTypes['Contribution']) {
|
||||
CRM_Utils_System::setTitle(ts('Batch Data Entry for Contributions'));
|
||||
$customFields = CRM_Core_BAO_CustomField::getFields('Contribution');
|
||||
}
|
||||
elseif ($this->_batchInfo['type_id'] == $batchTypes['Membership']) {
|
||||
CRM_Utils_System::setTitle(ts('Batch Data Entry for Memberships'));
|
||||
$customFields = CRM_Core_BAO_CustomField::getFields('Membership');
|
||||
}
|
||||
elseif ($this->_batchInfo['type_id'] == $batchTypes['Pledge Payment']) {
|
||||
CRM_Utils_System::setTitle(ts('Batch Data Entry for Pledge Payments'));
|
||||
$customFields = CRM_Core_BAO_CustomField::getFields('Contribution');
|
||||
}
|
||||
$this->_fields = array();
|
||||
$this->_fields = CRM_Core_BAO_UFGroup::getFields($this->_profileId, FALSE, CRM_Core_Action::VIEW);
|
||||
|
||||
// remove file type field and then limit fields
|
||||
$suppressFields = FALSE;
|
||||
$removehtmlTypes = array('File', 'Autocomplete-Select');
|
||||
foreach ($this->_fields as $name => $field) {
|
||||
if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name) &&
|
||||
in_array($this->_fields[$name]['html_type'], $removehtmlTypes)
|
||||
) {
|
||||
$suppressFields = TRUE;
|
||||
unset($this->_fields[$name]);
|
||||
}
|
||||
|
||||
//fix to reduce size as we are using this field in grid
|
||||
if (is_array($field['attributes']) && $this->_fields[$name]['attributes']['size'] > 19) {
|
||||
//shrink class to "form-text-medium"
|
||||
$this->_fields[$name]['attributes']['size'] = 19;
|
||||
}
|
||||
}
|
||||
|
||||
$this->addFormRule(array('CRM_Batch_Form_Entry', 'formRule'), $this);
|
||||
|
||||
// add the force save button
|
||||
$forceSave = $this->getButtonName('upload', 'force');
|
||||
|
||||
$this->addElement('submit',
|
||||
$forceSave,
|
||||
ts('Ignore Mismatch & Process the Batch?')
|
||||
);
|
||||
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Validate & Process the Batch'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Save & Continue Later'),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$this->assign('rowCount', $this->_batchInfo['item_count'] + 1);
|
||||
|
||||
$fileFieldExists = FALSE;
|
||||
$preserveDefaultsArray = array(
|
||||
'first_name',
|
||||
'last_name',
|
||||
'middle_name',
|
||||
'organization_name',
|
||||
'household_name',
|
||||
);
|
||||
|
||||
$contactTypes = array('Contact', 'Individual', 'Household', 'Organization');
|
||||
$contactReturnProperties = array();
|
||||
$config = CRM_Core_Config::singleton();
|
||||
|
||||
for ($rowNumber = 1; $rowNumber <= $this->_batchInfo['item_count']; $rowNumber++) {
|
||||
$this->addEntityRef("primary_contact_id[{$rowNumber}]", '', array(
|
||||
'create' => TRUE,
|
||||
'placeholder' => ts('- select -'),
|
||||
));
|
||||
|
||||
// special field specific to membership batch udpate
|
||||
if ($this->_batchInfo['type_id'] == 2) {
|
||||
$options = array(
|
||||
1 => ts('Add Membership'),
|
||||
2 => ts('Renew Membership'),
|
||||
);
|
||||
$this->add('select', "member_option[$rowNumber]", '', $options);
|
||||
}
|
||||
if ($this->_batchInfo['type_id'] == $batchTypes['Pledge Payment']) {
|
||||
$options = array('' => '-select-');
|
||||
$optionTypes = array(
|
||||
'1' => ts('Adjust Pledge Payment Schedule?'),
|
||||
'2' => ts('Adjust Total Pledge Amount?'),
|
||||
);
|
||||
$this->add('select', "option_type[$rowNumber]", NULL, $optionTypes);
|
||||
if (!empty($this->_batchId) && !empty($this->_batchInfo['data']) && !empty($rowNumber)) {
|
||||
$dataValues = json_decode($this->_batchInfo['data'], TRUE);
|
||||
if (!empty($dataValues['values']['primary_contact_id'][$rowNumber])) {
|
||||
$pledgeIDs = CRM_Pledge_BAO_Pledge::getContactPledges($dataValues['values']['primary_contact_id'][$rowNumber]);
|
||||
foreach ($pledgeIDs as $pledgeID) {
|
||||
$pledgePayment = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($pledgeID);
|
||||
$options += array($pledgeID => CRM_Utils_Date::customFormat($pledgePayment['schedule_date'], '%m/%d/%Y') . ', ' . $pledgePayment['amount'] . ' ' . $pledgePayment['currency']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->add('select', "open_pledges[$rowNumber]", '', $options);
|
||||
}
|
||||
|
||||
foreach ($this->_fields as $name => $field) {
|
||||
if (in_array($field['field_type'], $contactTypes)) {
|
||||
$fld = explode('-', $field['name']);
|
||||
$contactReturnProperties[$field['name']] = $fld[0];
|
||||
}
|
||||
CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, NULL, FALSE, FALSE, $rowNumber);
|
||||
|
||||
if (in_array($field['name'], $preserveDefaultsArray)) {
|
||||
$this->_preserveDefault = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CRM-19477: Display Error for Batch Sizes Exceeding php.ini max_input_vars
|
||||
// Notes: $this->_elementIndex gives an approximate count of the variables being sent
|
||||
// An offset value is set to deal with additional vars that are likely passed.
|
||||
// There may be a more accurate way to do this...
|
||||
$offset = 50; // set an offset to account for other vars we are not counting
|
||||
if ((count($this->_elementIndex) + $offset) > ini_get("max_input_vars")) {
|
||||
CRM_Core_Error::fatal(ts('Batch size is too large. Increase value of php.ini setting "max_input_vars" (current val = ' . ini_get("max_input_vars") . ')'));
|
||||
}
|
||||
|
||||
$this->assign('fields', $this->_fields);
|
||||
CRM_Core_Resources::singleton()
|
||||
->addSetting(array(
|
||||
'contact' => array(
|
||||
'return' => implode(',', $contactReturnProperties),
|
||||
'fieldmap' => array_flip($contactReturnProperties),
|
||||
),
|
||||
));
|
||||
|
||||
// don't set the status message when form is submitted.
|
||||
$buttonName = $this->controller->getButtonName('submit');
|
||||
|
||||
if ($suppressFields && $buttonName != '_qf_Entry_next') {
|
||||
CRM_Core_Session::setStatus(ts("File or Autocomplete-Select type field(s) in the selected profile are not supported for Update multiple records."), ts('Some Fields Excluded'), 'info');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Form validations.
|
||||
*
|
||||
* @param array $params
|
||||
* Posted values of the form.
|
||||
* @param array $files
|
||||
* List of errors to be posted back to the form.
|
||||
* @param \CRM_Batch_Form_Entry $self
|
||||
* Form object.
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($params, $files, $self) {
|
||||
$errors = array();
|
||||
$batchTypes = CRM_Core_Pseudoconstant::get('CRM_Batch_DAO_Batch', 'type_id', array('flip' => 1), 'validate');
|
||||
$fields = array(
|
||||
'total_amount' => ts('Amount'),
|
||||
'financial_type' => ts('Financial Type'),
|
||||
'payment_instrument' => ts('Payment Method'),
|
||||
);
|
||||
|
||||
//CRM-16480 if contact is selected, validate financial type and amount field.
|
||||
foreach ($params['field'] as $key => $value) {
|
||||
if (isset($value['trxn_id'])) {
|
||||
if (0 < CRM_Core_DAO::singleValueQuery('SELECT id FROM civicrm_contribution WHERE trxn_id = %1', array(1 => array($value['trxn_id'], 'String')))) {
|
||||
$errors["field[$key][trxn_id]"] = ts('Transaction ID must be unique within the database');
|
||||
}
|
||||
}
|
||||
foreach ($fields as $field => $label) {
|
||||
if (!empty($params['primary_contact_id'][$key]) && empty($value[$field])) {
|
||||
$errors["field[$key][$field]"] = ts('%1 is a required field.', array(1 => $label));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($params['_qf_Entry_upload_force'])) {
|
||||
if (!empty($errors)) {
|
||||
return $errors;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
$batchTotal = 0;
|
||||
foreach ($params['field'] as $key => $value) {
|
||||
$batchTotal += $value['total_amount'];
|
||||
|
||||
//validate for soft credit fields
|
||||
if (!empty($params['soft_credit_contact_id'][$key]) && empty($params['soft_credit_amount'][$key])) {
|
||||
$errors["soft_credit_amount[$key]"] = ts('Please enter the soft credit amount.');
|
||||
}
|
||||
if (!empty($params['soft_credit_amount']) && !empty($params['soft_credit_amount'][$key]) && CRM_Utils_Rule::cleanMoney(CRM_Utils_Array::value($key, $params['soft_credit_amount'])) > CRM_Utils_Rule::cleanMoney($value['total_amount'])) {
|
||||
$errors["soft_credit_amount[$key]"] = ts('Soft credit amount should not be greater than the total amount');
|
||||
}
|
||||
|
||||
//membership type is required for membership batch entry
|
||||
if ($self->_batchInfo['type_id'] == $batchTypes['Membership']) {
|
||||
if (empty($value['membership_type'][1])) {
|
||||
$errors["field[$key][membership_type]"] = ts('Membership type is a required field.');
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($self->_batchInfo['type_id'] == $batchTypes['Pledge Payment']) {
|
||||
foreach (array_unique($params["open_pledges"]) as $value) {
|
||||
if (!empty($value)) {
|
||||
$duplicateRows = array_keys($params["open_pledges"], $value);
|
||||
}
|
||||
if (!empty($duplicateRows) && count($duplicateRows) > 1) {
|
||||
foreach ($duplicateRows as $key) {
|
||||
$errors["open_pledges[$key]"] = ts('You can not record two payments for the same pledge in a single batch.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((string) $batchTotal != $self->_batchInfo['total']) {
|
||||
$self->assign('batchAmountMismatch', TRUE);
|
||||
$errors['_qf_defaults'] = ts('Total for amounts entered below does not match the expected batch total.');
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
return $errors;
|
||||
}
|
||||
|
||||
$self->assign('batchAmountMismatch', FALSE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override default cancel action.
|
||||
*/
|
||||
public function cancelAction() {
|
||||
// redirect to batch listing
|
||||
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/batch', 'reset=1'));
|
||||
CRM_Utils_System::civiExit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
if (empty($this->_fields)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// for add mode set smart defaults
|
||||
if ($this->_action & CRM_Core_Action::ADD) {
|
||||
$currentDate = date('Y-m-d H-i-s');
|
||||
|
||||
$completeStatus = CRM_Contribute_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed');
|
||||
$specialFields = array(
|
||||
'join_date' => date('Y-m-d'),
|
||||
'receive_date' => $currentDate,
|
||||
'contribution_status_id' => $completeStatus,
|
||||
);
|
||||
|
||||
for ($rowNumber = 1; $rowNumber <= $this->_batchInfo['item_count']; $rowNumber++) {
|
||||
foreach ($specialFields as $key => $value) {
|
||||
$defaults['field'][$rowNumber][$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// get the cached info from data column of civicrm_batch
|
||||
$data = CRM_Core_DAO::getFieldValue('CRM_Batch_BAO_Batch', $this->_batchId, 'data');
|
||||
$defaults = json_decode($data, TRUE);
|
||||
$defaults = $defaults['values'];
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
$params['actualBatchTotal'] = 0;
|
||||
|
||||
// get the profile information
|
||||
$batchTypes = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'type_id', array('flip' => 1), 'validate');
|
||||
if (in_array($this->_batchInfo['type_id'], array($batchTypes['Pledge Payment'], $batchTypes['Contribution']))) {
|
||||
$this->processContribution($params);
|
||||
}
|
||||
elseif ($this->_batchInfo['type_id'] == $batchTypes['Membership']) {
|
||||
$this->processMembership($params);
|
||||
}
|
||||
|
||||
// update batch to close status
|
||||
$paramValues = array(
|
||||
'id' => $this->_batchId,
|
||||
// close status
|
||||
'status_id' => CRM_Core_PseudoConstant::getKey('CRM_Batch_BAO_Batch', 'status_id', 'Closed'),
|
||||
'total' => $params['actualBatchTotal'],
|
||||
);
|
||||
|
||||
CRM_Batch_BAO_Batch::create($paramValues);
|
||||
|
||||
// set success status
|
||||
CRM_Core_Session::setStatus("", ts("Batch Processed."), "success");
|
||||
|
||||
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/batch', 'reset=1'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Process contribution records.
|
||||
*
|
||||
* @param array $params
|
||||
* Associated array of submitted values.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function processContribution(&$params) {
|
||||
|
||||
// get the price set associated with offline contribution record.
|
||||
$priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_contribution_amount', 'id', 'name');
|
||||
$this->_priceSet = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId));
|
||||
$priceFieldID = CRM_Price_BAO_PriceSet::getOnlyPriceFieldID($this->_priceSet);
|
||||
$priceFieldValueID = CRM_Price_BAO_PriceSet::getOnlyPriceFieldValueID($this->_priceSet);
|
||||
|
||||
if (isset($params['field'])) {
|
||||
foreach ($params['field'] as $key => $value) {
|
||||
// if contact is not selected we should skip the row
|
||||
if (empty($params['primary_contact_id'][$key])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$value['contact_id'] = CRM_Utils_Array::value($key, $params['primary_contact_id']);
|
||||
|
||||
// update contact information
|
||||
$this->updateContactInfo($value);
|
||||
|
||||
//build soft credit params
|
||||
if (!empty($params['soft_credit_contact_id'][$key]) && !empty($params['soft_credit_amount'][$key])) {
|
||||
$value['soft_credit'][$key]['contact_id'] = $params['soft_credit_contact_id'][$key];
|
||||
$value['soft_credit'][$key]['amount'] = CRM_Utils_Rule::cleanMoney($params['soft_credit_amount'][$key]);
|
||||
|
||||
//CRM-15350: if soft-credit-type profile field is disabled or removed then
|
||||
//we choose configured SCT default value
|
||||
if (!empty($params['soft_credit_type'][$key])) {
|
||||
$value['soft_credit'][$key]['soft_credit_type_id'] = $params['soft_credit_type'][$key];
|
||||
}
|
||||
else {
|
||||
$value['soft_credit'][$key]['soft_credit_type_id'] = CRM_Core_OptionGroup::getDefaultValue("soft_credit_type");
|
||||
}
|
||||
}
|
||||
|
||||
// Build PCP params
|
||||
if (!empty($params['pcp_made_through_id'][$key])) {
|
||||
$value['pcp']['pcp_made_through_id'] = $params['pcp_made_through_id'][$key];
|
||||
$value['pcp']['pcp_display_in_roll'] = !empty($params['pcp_display_in_roll'][$key]);
|
||||
if (!empty($params['pcp_roll_nickname'][$key])) {
|
||||
$value['pcp']['pcp_roll_nickname'] = $params['pcp_roll_nickname'][$key];
|
||||
}
|
||||
if (!empty($params['pcp_personal_note'][$key])) {
|
||||
$value['pcp']['pcp_personal_note'] = $params['pcp_personal_note'][$key];
|
||||
}
|
||||
}
|
||||
|
||||
$value['custom'] = CRM_Core_BAO_CustomField::postProcess($value,
|
||||
NULL,
|
||||
'Contribution'
|
||||
);
|
||||
|
||||
if (!empty($value['send_receipt'])) {
|
||||
$value['receipt_date'] = date('Y-m-d His');
|
||||
}
|
||||
// these translations & date handling are required because we are calling BAO directly rather than the api
|
||||
$fieldTranslations = array(
|
||||
'financial_type' => 'financial_type_id',
|
||||
'payment_instrument' => 'payment_instrument_id',
|
||||
'contribution_source' => 'source',
|
||||
'contribution_note' => 'note',
|
||||
|
||||
);
|
||||
foreach ($fieldTranslations as $formField => $baoField) {
|
||||
if (isset($value[$formField])) {
|
||||
$value[$baoField] = $value[$formField];
|
||||
}
|
||||
unset($value[$formField]);
|
||||
}
|
||||
|
||||
$params['actualBatchTotal'] += $value['total_amount'];
|
||||
$value['batch_id'] = $this->_batchId;
|
||||
$value['skipRecentView'] = TRUE;
|
||||
|
||||
// build line item params
|
||||
$this->_priceSet['fields'][$priceFieldID]['options'][$priceFieldValueID]['amount'] = $value['total_amount'];
|
||||
$value['price_' . $priceFieldID] = 1;
|
||||
|
||||
$lineItem = array();
|
||||
CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $value, $lineItem[$priceSetId]);
|
||||
|
||||
// @todo - stop setting amount level in this function & call the CRM_Price_BAO_PriceSet::getAmountLevel
|
||||
// function to get correct amount level consistently. Remove setting of the amount level in
|
||||
// CRM_Price_BAO_PriceSet::processAmount. Extend the unit tests in CRM_Price_BAO_PriceSetTest
|
||||
// to cover all variants.
|
||||
unset($value['amount_level']);
|
||||
|
||||
//CRM-11529 for back office transactions
|
||||
//when financial_type_id is passed in form, update the
|
||||
//line items with the financial type selected in form
|
||||
// @todo - create a price set or price field per financial type & simply choose the appropriate
|
||||
// price field rather than working around the fact that each price_field is supposed to have a financial
|
||||
// type & we are allowing that to be overridden.
|
||||
if (!empty($value['financial_type_id']) && !empty($lineItem[$priceSetId])) {
|
||||
foreach ($lineItem[$priceSetId] as &$values) {
|
||||
$values['financial_type_id'] = $value['financial_type_id'];
|
||||
}
|
||||
}
|
||||
$value['line_item'] = $lineItem;
|
||||
//finally call contribution create for all the magic
|
||||
$contribution = CRM_Contribute_BAO_Contribution::create($value);
|
||||
$batchTypes = CRM_Core_Pseudoconstant::get('CRM_Batch_DAO_Batch', 'type_id', array('flip' => 1), 'validate');
|
||||
if (!empty($this->_batchInfo['type_id']) && ($this->_batchInfo['type_id'] == $batchTypes['Pledge Payment'])) {
|
||||
$adjustTotalAmount = FALSE;
|
||||
if (isset($params['option_type'][$key])) {
|
||||
if ($params['option_type'][$key] == 2) {
|
||||
$adjustTotalAmount = TRUE;
|
||||
}
|
||||
}
|
||||
$pledgeId = $params['open_pledges'][$key];
|
||||
if (is_numeric($pledgeId)) {
|
||||
$result = CRM_Pledge_BAO_PledgePayment::getPledgePayments($pledgeId);
|
||||
$pledgePaymentId = 0;
|
||||
foreach ($result as $key => $values) {
|
||||
if ($values['status'] != 'Completed') {
|
||||
$pledgePaymentId = $values['id'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', $pledgePaymentId, 'contribution_id', $contribution->id);
|
||||
CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeId,
|
||||
array($pledgePaymentId),
|
||||
$contribution->contribution_status_id,
|
||||
NULL,
|
||||
$contribution->total_amount,
|
||||
$adjustTotalAmount
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//process premiums
|
||||
if (!empty($value['product_name'])) {
|
||||
if ($value['product_name'][0] > 0) {
|
||||
list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo();
|
||||
|
||||
$value['hidden_Premium'] = 1;
|
||||
$value['product_option'] = CRM_Utils_Array::value(
|
||||
$value['product_name'][1],
|
||||
$options[$value['product_name'][0]]
|
||||
);
|
||||
|
||||
$premiumParams = array(
|
||||
'product_id' => $value['product_name'][0],
|
||||
'contribution_id' => $contribution->id,
|
||||
'product_option' => $value['product_option'],
|
||||
'quantity' => 1,
|
||||
);
|
||||
CRM_Contribute_BAO_Contribution::addPremium($premiumParams);
|
||||
}
|
||||
}
|
||||
// end of premium
|
||||
|
||||
//send receipt mail.
|
||||
if ($contribution->id && !empty($value['send_receipt'])) {
|
||||
// add the domain email id
|
||||
$domainEmail = CRM_Core_BAO_Domain::getNameAndEmail();
|
||||
$domainEmail = "$domainEmail[0] <$domainEmail[1]>";
|
||||
$value['from_email_address'] = $domainEmail;
|
||||
$value['contribution_id'] = $contribution->id;
|
||||
if (!empty($value['soft_credit'])) {
|
||||
$value = array_merge($value, CRM_Contribute_BAO_ContributionSoft::getSoftContribution($contribution->id));
|
||||
}
|
||||
CRM_Contribute_Form_AdditionalInfo::emailReceipt($this, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process membership records.
|
||||
*
|
||||
* @param array $params
|
||||
* Associated array of submitted values.
|
||||
*
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function processMembership(&$params) {
|
||||
|
||||
// get the price set associated with offline membership
|
||||
$priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_membership_type_amount', 'id', 'name');
|
||||
$this->_priceSet = $priceSets = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId));
|
||||
|
||||
if (isset($params['field'])) {
|
||||
// @todo - most of the wrangling in this function is because the api is not being used, especially date stuff.
|
||||
$customFields = array();
|
||||
foreach ($params['field'] as $key => $value) {
|
||||
// if contact is not selected we should skip the row
|
||||
if (empty($params['primary_contact_id'][$key])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$value['contact_id'] = CRM_Utils_Array::value($key, $params['primary_contact_id']);
|
||||
|
||||
// update contact information
|
||||
$this->updateContactInfo($value);
|
||||
|
||||
$membershipTypeId = $value['membership_type_id'] = $value['membership_type'][1];
|
||||
|
||||
if (!empty($value['send_receipt'])) {
|
||||
$value['receipt_date'] = date('Y-m-d His');
|
||||
}
|
||||
|
||||
if (!empty($value['membership_source'])) {
|
||||
$value['source'] = $value['membership_source'];
|
||||
}
|
||||
|
||||
unset($value['membership_source']);
|
||||
|
||||
//Get the membership status
|
||||
if (!empty($value['membership_status'])) {
|
||||
$value['status_id'] = $value['membership_status'];
|
||||
unset($value['membership_status']);
|
||||
}
|
||||
|
||||
if (empty($customFields)) {
|
||||
// membership type custom data
|
||||
$customFields = CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, $membershipTypeId);
|
||||
|
||||
$customFields = CRM_Utils_Array::crmArrayMerge($customFields,
|
||||
CRM_Core_BAO_CustomField::getFields('Membership',
|
||||
FALSE, FALSE, NULL, NULL, TRUE
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
//check for custom data
|
||||
$value['custom'] = CRM_Core_BAO_CustomField::postProcess($params['field'][$key],
|
||||
$key,
|
||||
'Membership',
|
||||
$membershipTypeId
|
||||
);
|
||||
|
||||
if (!empty($value['financial_type'])) {
|
||||
$value['financial_type_id'] = $value['financial_type'];
|
||||
}
|
||||
|
||||
if (!empty($value['payment_instrument'])) {
|
||||
$value['payment_instrument_id'] = $value['payment_instrument'];
|
||||
}
|
||||
|
||||
// handle soft credit
|
||||
if (!empty($params['soft_credit_contact_id'][$key]) && !empty($params['soft_credit_amount'][$key])) {
|
||||
$value['soft_credit'][$key]['contact_id'] = $params['soft_credit_contact_id'][$key];
|
||||
$value['soft_credit'][$key]['amount'] = CRM_Utils_Rule::cleanMoney($params['soft_credit_amount'][$key]);
|
||||
|
||||
//CRM-15350: if soft-credit-type profile field is disabled or removed then
|
||||
//we choose Gift as default value as per Gift Membership rule
|
||||
if (!empty($params['soft_credit_type'][$key])) {
|
||||
$value['soft_credit'][$key]['soft_credit_type_id'] = $params['soft_credit_type'][$key];
|
||||
}
|
||||
else {
|
||||
$value['soft_credit'][$key]['soft_credit_type_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_ContributionSoft', 'soft_credit_type_id', 'Gift');
|
||||
}
|
||||
}
|
||||
|
||||
$params['actualBatchTotal'] += $value['total_amount'];
|
||||
|
||||
unset($value['financial_type']);
|
||||
unset($value['payment_instrument']);
|
||||
|
||||
$value['batch_id'] = $this->_batchId;
|
||||
$value['skipRecentView'] = TRUE;
|
||||
|
||||
// make entry in line item for contribution
|
||||
|
||||
$editedFieldParams = array(
|
||||
'price_set_id' => $priceSetId,
|
||||
'name' => $value['membership_type'][0],
|
||||
);
|
||||
|
||||
$editedResults = array();
|
||||
CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
|
||||
|
||||
if (!empty($editedResults)) {
|
||||
unset($this->_priceSet['fields']);
|
||||
$this->_priceSet['fields'][$editedResults['id']] = $priceSets['fields'][$editedResults['id']];
|
||||
unset($this->_priceSet['fields'][$editedResults['id']]['options']);
|
||||
$fid = $editedResults['id'];
|
||||
$editedFieldParams = array(
|
||||
'price_field_id' => $editedResults['id'],
|
||||
'membership_type_id' => $value['membership_type_id'],
|
||||
);
|
||||
|
||||
$editedResults = array();
|
||||
CRM_Price_BAO_PriceFieldValue::retrieve($editedFieldParams, $editedResults);
|
||||
$this->_priceSet['fields'][$fid]['options'][$editedResults['id']] = $priceSets['fields'][$fid]['options'][$editedResults['id']];
|
||||
if (!empty($value['total_amount'])) {
|
||||
$this->_priceSet['fields'][$fid]['options'][$editedResults['id']]['amount'] = $value['total_amount'];
|
||||
}
|
||||
|
||||
$fieldID = key($this->_priceSet['fields']);
|
||||
$value['price_' . $fieldID] = $editedResults['id'];
|
||||
|
||||
$lineItem = array();
|
||||
CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'],
|
||||
$value, $lineItem[$priceSetId]
|
||||
);
|
||||
|
||||
//CRM-11529 for backoffice transactions
|
||||
//when financial_type_id is passed in form, update the
|
||||
//lineitems with the financial type selected in form
|
||||
if (!empty($value['financial_type_id']) && !empty($lineItem[$priceSetId])) {
|
||||
foreach ($lineItem[$priceSetId] as &$values) {
|
||||
$values['financial_type_id'] = $value['financial_type_id'];
|
||||
}
|
||||
}
|
||||
|
||||
$value['lineItems'] = $lineItem;
|
||||
$value['processPriceSet'] = TRUE;
|
||||
}
|
||||
// end of contribution related section
|
||||
|
||||
unset($value['membership_type']);
|
||||
|
||||
$value['is_renew'] = FALSE;
|
||||
if (!empty($params['member_option']) && CRM_Utils_Array::value($key, $params['member_option']) == 2) {
|
||||
|
||||
// The following parameter setting may be obsolete.
|
||||
$this->_params = $params;
|
||||
$value['is_renew'] = TRUE;
|
||||
$isPayLater = CRM_Utils_Array::value('is_pay_later', $params);
|
||||
$campaignId = NULL;
|
||||
if (isset($this->_values) && is_array($this->_values) && !empty($this->_values)) {
|
||||
$campaignId = CRM_Utils_Array::value('campaign_id', $this->_params);
|
||||
if (!array_key_exists('campaign_id', $this->_params)) {
|
||||
$campaignId = CRM_Utils_Array::value('campaign_id', $this->_values);
|
||||
}
|
||||
}
|
||||
|
||||
$formDates = array(
|
||||
'end_date' => CRM_Utils_Array::value('membership_end_date', $value),
|
||||
'start_date' => CRM_Utils_Array::value('membership_start_date', $value),
|
||||
);
|
||||
$membershipSource = CRM_Utils_Array::value('source', $value);
|
||||
list($membership) = CRM_Member_BAO_Membership::processMembership(
|
||||
$value['contact_id'], $value['membership_type_id'], FALSE,
|
||||
//$numTerms should be default to 1.
|
||||
NULL, NULL, $value['custom'], 1, NULL, FALSE,
|
||||
NULL, $membershipSource, $isPayLater, $campaignId, $formDates
|
||||
);
|
||||
|
||||
// make contribution entry
|
||||
$contrbutionParams = array_merge($value, array('membership_id' => $membership->id));
|
||||
// @todo - calling this from here is pretty hacky since it is called from membership.create anyway
|
||||
// This form should set the correct params & not call this fn directly.
|
||||
CRM_Member_BAO_Membership::recordMembershipContribution($contrbutionParams);
|
||||
}
|
||||
else {
|
||||
$dateTypes = array(
|
||||
'join_date' => 'joinDate',
|
||||
'membership_start_date' => 'startDate',
|
||||
'membership_end_date' => 'endDate',
|
||||
);
|
||||
|
||||
$dates = array(
|
||||
'join_date',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'reminder_date',
|
||||
);
|
||||
foreach ($dateTypes as $dateField => $dateVariable) {
|
||||
$$dateVariable = CRM_Utils_Date::processDate($value[$dateField]);
|
||||
$fDate[$dateField] = CRM_Utils_Array::value($dateField, $value);
|
||||
}
|
||||
|
||||
$calcDates = array();
|
||||
$calcDates[$membershipTypeId] = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membershipTypeId,
|
||||
$joinDate, $startDate, $endDate
|
||||
);
|
||||
|
||||
foreach ($calcDates as $memType => $calcDate) {
|
||||
foreach ($dates as $d) {
|
||||
//first give priority to form values then calDates.
|
||||
$date = CRM_Utils_Array::value($d, $value);
|
||||
if (!$date) {
|
||||
$date = CRM_Utils_Array::value($d, $calcDate);
|
||||
}
|
||||
|
||||
$value[$d] = CRM_Utils_Date::processDate($date);
|
||||
}
|
||||
}
|
||||
|
||||
unset($value['membership_start_date']);
|
||||
unset($value['membership_end_date']);
|
||||
$ids = array();
|
||||
$membership = CRM_Member_BAO_Membership::create($value, $ids);
|
||||
}
|
||||
|
||||
//process premiums
|
||||
if (!empty($value['product_name'])) {
|
||||
if ($value['product_name'][0] > 0) {
|
||||
list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo();
|
||||
|
||||
$value['hidden_Premium'] = 1;
|
||||
$value['product_option'] = CRM_Utils_Array::value(
|
||||
$value['product_name'][1],
|
||||
$options[$value['product_name'][0]]
|
||||
);
|
||||
|
||||
$premiumParams = array(
|
||||
'product_id' => $value['product_name'][0],
|
||||
'contribution_id' => CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipPayment', $membership->id, 'contribution_id', 'membership_id'),
|
||||
'product_option' => $value['product_option'],
|
||||
'quantity' => 1,
|
||||
);
|
||||
CRM_Contribute_BAO_Contribution::addPremium($premiumParams);
|
||||
}
|
||||
}
|
||||
// end of premium
|
||||
|
||||
//send receipt mail.
|
||||
if ($membership->id && !empty($value['send_receipt'])) {
|
||||
|
||||
// add the domain email id
|
||||
$domainEmail = CRM_Core_BAO_Domain::getNameAndEmail();
|
||||
$domainEmail = "$domainEmail[0] <$domainEmail[1]>";
|
||||
|
||||
$value['from_email_address'] = $domainEmail;
|
||||
$value['membership_id'] = $membership->id;
|
||||
$value['contribution_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipPayment', $membership->id, 'contribution_id', 'membership_id');
|
||||
CRM_Member_Form_Membership::emailReceipt($this, $value, $membership);
|
||||
}
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update contact information.
|
||||
*
|
||||
* @param array $value
|
||||
* Associated array of submitted values.
|
||||
*/
|
||||
private function updateContactInfo(&$value) {
|
||||
$value['preserveDBName'] = $this->_preserveDefault;
|
||||
|
||||
//parse street address, CRM-7768
|
||||
CRM_Contact_Form_Task_Batch::parseStreetAddress($value, $this);
|
||||
|
||||
CRM_Contact_BAO_Contact::createProfileContact($value, $this->_fields,
|
||||
$value['contact_id']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function exists purely for unit testing purposes.
|
||||
*
|
||||
* If you feel tempted to use this in live code then it probably means there is some functionality
|
||||
* that needs to be moved out of the form layer
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function testProcessMembership($params) {
|
||||
return $this->processMembership($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function exists purely for unit testing purposes.
|
||||
*
|
||||
* If you feel tempted to use this in live code then it probably means there is some functionality
|
||||
* that needs to be moved out of the form layer.
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function testProcessContribution($params) {
|
||||
return $this->processContribution($params);
|
||||
}
|
||||
|
||||
}
|
67
sites/all/modules/civicrm/CRM/Batch/Form/Search.php
Normal file
67
sites/all/modules/civicrm/CRM/Batch/Form/Search.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?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_Batch_Form_Search extends CRM_Core_Form {
|
||||
/**
|
||||
* Set default values.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
|
||||
$status = CRM_Utils_Request::retrieve('status', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, 1);
|
||||
|
||||
$defaults['batch_status'] = $status;
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
public function buildQuickForm() {
|
||||
$this->add('text', 'title', ts('Find'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Batch_DAO_Batch', 'title')
|
||||
);
|
||||
|
||||
$this->addButtons(
|
||||
array(
|
||||
array(
|
||||
'type' => 'refresh',
|
||||
'name' => ts('Search'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
parent::buildQuickForm();
|
||||
$this->assign('suppressForm', TRUE);
|
||||
}
|
||||
|
||||
}
|
132
sites/all/modules/civicrm/CRM/Batch/Page/AJAX.php
Normal file
132
sites/all/modules/civicrm/CRM/Batch/Page/AJAX.php
Normal file
|
@ -0,0 +1,132 @@
|
|||
<?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 functions that are called using AJAX.
|
||||
*/
|
||||
class CRM_Batch_Page_AJAX {
|
||||
|
||||
/**
|
||||
* Save record.
|
||||
*/
|
||||
public function batchSave() {
|
||||
// save the entered information in 'data' column
|
||||
$batchId = CRM_Utils_Type::escape($_POST['batch_id'], 'Positive');
|
||||
|
||||
unset($_POST['qfKey']);
|
||||
CRM_Core_DAO::setFieldValue('CRM_Batch_DAO_Batch', $batchId, 'data', json_encode(array('values' => $_POST)));
|
||||
|
||||
CRM_Utils_System::civiExit();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function uses the deprecated v1 datatable api and needs updating. See CRM-16353.
|
||||
* @deprecated
|
||||
*/
|
||||
public static function getBatchList() {
|
||||
$context = isset($_REQUEST['context']) ? CRM_Utils_Type::escape($_REQUEST['context'], 'String') : NULL;
|
||||
if ($context != 'financialBatch') {
|
||||
$sortMapper = array(
|
||||
0 => 'title',
|
||||
1 => 'type_id.label',
|
||||
2 => 'item_count',
|
||||
3 => 'total',
|
||||
4 => 'status_id.label',
|
||||
5 => 'created_id.sort_name',
|
||||
);
|
||||
}
|
||||
else {
|
||||
$sortMapper = array(
|
||||
1 => 'title',
|
||||
2 => 'payment_instrument_id.label',
|
||||
3 => 'item_count',
|
||||
4 => 'total',
|
||||
5 => 'status_id.label',
|
||||
6 => 'created_id.sort_name',
|
||||
);
|
||||
}
|
||||
$sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
|
||||
$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';
|
||||
|
||||
$params = $_REQUEST;
|
||||
if ($sort && $sortOrder) {
|
||||
$params['sortBy'] = $sort . ' ' . $sortOrder;
|
||||
}
|
||||
|
||||
$params['page'] = ($offset / $rowCount) + 1;
|
||||
$params['rp'] = $rowCount;
|
||||
|
||||
if ($context != 'financialBatch') {
|
||||
// data entry status batches
|
||||
$params['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Batch_BAO_Batch', 'status_id', 'Data Entry');
|
||||
}
|
||||
|
||||
$params['context'] = $context;
|
||||
|
||||
// get batch list
|
||||
$batches = CRM_Batch_BAO_Batch::getBatchListSelector($params);
|
||||
|
||||
$iFilteredTotal = $iTotal = $params['total'];
|
||||
|
||||
if ($context == 'financialBatch') {
|
||||
$selectorElements = array(
|
||||
'check',
|
||||
'batch_name',
|
||||
'payment_instrument',
|
||||
'item_count',
|
||||
'total',
|
||||
'status',
|
||||
'created_by',
|
||||
'links',
|
||||
);
|
||||
}
|
||||
else {
|
||||
$selectorElements = array(
|
||||
'batch_name',
|
||||
'type',
|
||||
'item_count',
|
||||
'total',
|
||||
'status',
|
||||
'created_by',
|
||||
'links',
|
||||
);
|
||||
}
|
||||
CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
|
||||
echo CRM_Utils_JSON::encodeDataTableSelector($batches, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
|
||||
CRM_Utils_System::civiExit();
|
||||
}
|
||||
|
||||
}
|
119
sites/all/modules/civicrm/CRM/Batch/Page/Batch.php
Normal file
119
sites/all/modules/civicrm/CRM/Batch/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_Batch_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 action Links.
|
||||
*/
|
||||
public function &links() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name of edit form.
|
||||
*
|
||||
* @return string
|
||||
* Classname of edit form.
|
||||
*/
|
||||
public function editForm() {
|
||||
return 'CRM_Batch_Form_Batch';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get edit form name.
|
||||
*
|
||||
* @return string
|
||||
* name of this page.
|
||||
*/
|
||||
public function editName() {
|
||||
return ts('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_Batch_Form_Search', ts('Search Batches'), CRM_Core_Action::ADD);
|
||||
$form->setEmbedded(TRUE);
|
||||
$form->setParent($this);
|
||||
$form->process();
|
||||
$form->run();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue