Commit f9c0a2ed authored by Monish Deb's avatar Monish Deb
Browse files

Refactored task actions

parent c4825c57
......@@ -440,4 +440,20 @@ class CRM_Grant_BAO_GrantPayment extends CRM_Grant_DAO_GrantPayment {
return $summary;
}
public static function actions() {
$params = $_GET;
if ($params['action'] == CRM_Grant_BAO_GrantPayment::STOP) {
$dao = new CRM_Grant_DAO_GrantPayment();
$dao->id = $params['id'];
$dao->payment_status_id = CRM_Core_PseudoConstant::getKey('CRM_Grant_BAO_GrantPayment', 'payment_status_id', 'Stopped');
$dao->save();
CRM_Core_Session::setStatus(ts('Selected Grant Payment has been stopped successfully'));
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/grant/payment/search', '_qf_PaymentSearch_display=true&force=1&qfKey=' . $params['key']));
}
elseif ($params['action'] == CRM_Grant_BAO_GrantPayment::REPRINT) {
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/grant/payment/reprint', 'reset=1&prid=' . $params['id']));
}
}
}
......@@ -57,7 +57,7 @@ class CRM_Grant_BAO_PaymentSearch {
$displayRelationshipType = NULL,
$operator = 'AND'
) {
$this->_params =& $params;
$this->_params = $params;
if ($this->_params == NULL) {
$this->_params = array();
......@@ -185,11 +185,15 @@ class CRM_Grant_BAO_PaymentSearch {
function whereClauseSingle(&$values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
$this->_tables['civicrm_payment'] = $this->_whereTables['civicrm_payment'] = 1;
switch ($values[0]) {
case 'id':
$this->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("p.$name", $op, $value, 'Int');
return;
case 'payment_status_id':
$this->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("p.$name", $op, $value, 'Int');
$this->_qill[$grouping][] = ts('Payment Status is ') . CRM_Core_PseudoConstant::getLabel('CRM_Grant_DAO_GrantPayment', 'payment_status_id', $value);
$this->_tables['civicrm_payment'] = $this->_whereTables['civicrm_payment'] = 1;
return;
case 'payable_to_name':
......@@ -270,13 +274,26 @@ class CRM_Grant_BAO_PaymentSearch {
* @access public
*/
function select() {
$this->_select['id'] = 'p.id as id';
$this->_select['payable_to_name'] = 'cc.display_name as payable_to_name';
$this->_select['payment_batch_number'] = 'b.id as payment_batch_number';
$this->_select['payment_status_id'] = 'p.payment_status_id';
$this->_select['payment_created_date'] = 'p.payment_created_date';
$this->_select['amount'] = 'ft.total_amount as amount';
$this->_select['payment_number'] = 'ft.check_number as payment_number';
$clauses = [
'id' => 'p.id as id',
'contact_id' => 'fi.contact_id',
'payable_to_name' => 'cc.display_name as payable_to_name',
'payment_batch_number' => 'b.id as payment_batch_number',
'payment_status_id' => 'p.payment_status_id',
'payment_created_date' => 'p.payment_created_date',
'amount' => 'ft.total_amount as amount',
'payment_number' => 'CASE WHEN p.replaces_check_number <> \'\' THEN p.replaces_check_number ELSE ft.check_number END AS payment_number',
'payment_created_date' => 'p.payment_created_date',
'payment_date' => 'ft.trxn_date as payment_date',
'currency' => 'fi.currency',
'payment_reason' => 'p.payment_reason',
'replaces_payment_id' => 'p.replaces_payment_id',
];
foreach ($clauses as $property => $clause) {
if (!empty($this->_returnProperties[$property])) {
$this->_select[$property] = $clause;
}
}
return $this->_select;
}
......@@ -288,7 +305,6 @@ class CRM_Grant_BAO_PaymentSearch {
$this->_element['payment_status_id'] = 1;
$this->_element['payment_created_date'] = 1;
$this->_element['amount'] = 1;
return $this->_select;
return $this->_element;
}
......@@ -301,9 +317,7 @@ class CRM_Grant_BAO_PaymentSearch {
*/
static function where(&$query) {
foreach (array_keys($query->_params) as $id) {
if (substr($query->_params[$id][0], 0, 6) == 'grant_') {
self::whereClauseSingle($query->_params[$id], $query);
}
self::whereClauseSingle($query->_params[$id], $query);
}
}
......@@ -317,9 +331,7 @@ class CRM_Grant_BAO_PaymentSearch {
return (isset($this->_qill)) ? $this->_qill : "";
}
static function defaultReturnProperties($mode,
$includeCustomFields = TRUE
) {
static function defaultReturnProperties($mode = CRM_Grant_BAO_PaymentSearch::MODE_GRANT_PAYMENT, $includeCustomFields = TRUE) {
$properties = NULL;
if ($mode & CRM_Grant_BAO_PaymentSearch::MODE_GRANT_PAYMENT) {
$properties = array(
......@@ -410,6 +422,7 @@ class CRM_Grant_BAO_PaymentSearch {
) {
list($select, $from, $where, $having) = $this->query($count, $sortByChar, $groupContacts);
$groupBy = '';
$order = $orderBy = $limit = '';
if (!$count) {
......@@ -451,18 +464,13 @@ class CRM_Grant_BAO_PaymentSearch {
'SELECT p.id as id';
}
}
$groupBy = 'GROUP BY p.id';
$query = "$select $from $where $having $groupBy $order $limit";
$groupBy = $this->_groupByComponentClause;
}
$query = "$select $from $where $having $groupBy $order $limit";
if ($count) {
$query = "$select $from $where";
return CRM_Core_DAO::singleValueQuery($query);
}
elseif (empty($query)) {
$query = "$select $from $where $having $groupBy $order $limit";
}
//CRM_Core_Error::debug_var('q', $query);
$dao = CRM_Core_DAO::executeQuery($query);
if ($groupContacts) {
......
......@@ -196,6 +196,17 @@ class CRM_Grant_DAO_GrantPayment extends CRM_Core_DAO
'dataPattern' => '',
'export' => true,
) ,
'replaces_check_number' => array(
'name' => 'replaces_check_number',
'type' => CRM_Utils_Type::T_STRING,
'maxlength' => 20,
'size' => CRM_Utils_Type::EIGHT,
'import' => true,
'where' => 'civicrm_payment.replaces_check_number',
'headerPattern' => '',
'dataPattern' => '',
'export' => true,
) ,
);
}
return self::$_fields;
......
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.4 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2011 |
+--------------------------------------------------------------------+
| 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-2011
* $Id$
*
*/
/**
* This class generates form components for processing a Grant
*
*
*/
class CRM_Grant_Form_Payment_View extends CRM_Core_Form {
/**
* Function to set variables up before form is built
*
* @return void
* @access public
/**
* Function to set variables up before form is built
*
* @return void
* @access public
*/
public function preProcess() {
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
$context = CRM_Utils_Request::retrieve('context', 'String', $this);
$this->assign('context', $context);
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/grant/payment/search', '_qf_PaymentSearch_display=true&force=1&reset=1'));
$values = array();
$params['id'] = $this->_id;
CRM_Grant_BAO_GrantPayment::retrieve( $params, $values);
$paymentStatus = CRM_Core_OptionGroup::values( 'grant_payment_status' );
$contributionTypes = CRM_Grant_BAO_GrantProgram::contributionTypes();
$this->assign('payment_status_id', $paymentStatus[$values['payment_status_id']]);
$this->assign('financial_type_id', $contributionTypes[$values['financial_type_id']]);
$grantTokens = array(
'payment_batch_number',
'payment_number',
'payment_created_date',
'payment_date',
'payable_to_name',
'payable_to_address',
'amount',
'currency',
'payment_reason',
'replaces_payment_id'
);
foreach ($grantTokens as $token) {
$this->assign($token, CRM_Utils_Array::value($token, $values));
$context = CRM_Utils_Request::retrieve('context', 'String', $this);
if (!$this->_action) {
$this->_action = $_REQUEST['action'];
}
$this->assign('id', $this->_id);
$this->assign('context', $context);
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/grant/payment/search', '_qf_PaymentSearch_display=true&force=1&reset=1'));
}
/**
* Function to build the form
*
......@@ -87,30 +30,63 @@ class CRM_Grant_Form_Payment_View extends CRM_Core_Form {
* @access public
*/
public function buildQuickForm() {
if ($this->_action & CRM_Core_Action::VIEW) {
$this->addButtons(array(
array (
'type' => 'cancel',
'name' => ts('Cancel'),
'isDefault' => TRUE)
)
);
}
elseif (($this->_action & CRM_Core_Action::STOP) || ($this->_action & CRM_Core_Action::REPRINT) || ($this->_action & CRM_Core_Action::WITHDRAW)) {
$this->addButtons(array(
array (
'type' => 'submit',
'name' => ts('OK'),
'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
'isDefault' => TRUE),
array (
'type' => 'cancel',
'name' => ts('Cancel'),
'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
if ($this->_action == CRM_Core_Action::VIEW) {
$returnProperties = array_merge(
CRM_Grant_BAO_PaymentSearch::defaultReturnProperties(),
[
'id' => 1,
'contact_id' => 1,
'payment_created_date' => 1,
'payment_date' => 1,
'currency' => 1,
'payment_reason' => 1,
'replaces_payment_id' => 1,
]
);
$params = ['id' => $this->_id];
$p = new CRM_Grant_BAO_PaymentSearch(
CRM_Grant_BAO_PaymentSearch::convertFormValues($params),
$returnProperties,
NULL,
FALSE,
FALSE,
CRM_Grant_BAO_PaymentSearch::MODE_GRANT_PAYMENT
);
$values = $p->searchQuery()->fetchAll()[0];
$values['payment_status_id'] = CRM_Core_PseudoConstant::getLabel('CRM_Grant_DAO_GrantPayment', 'payment_status_id', $values['payment_status_id']);
$values['payable_to_address'] = CRM_Grant_BAO_GrantProgram::getAddress($values['contact_id'], NULL, TRUE);
foreach (array_keys($returnProperties) as $token) {
$this->assign($token, CRM_Utils_Array::value($token, $values));
}
$this->addButtons(array(
array (
'type' => 'cancel',
'name' => ts('Cancel'),
'isDefault' => TRUE)
)
);
}
else {
$this->assign('action1', $this->_action);
if ($this->_action == CRM_Grant_BAO_GrantPayment::STOP) {
CRM_Utils_System::setTitle(ts('Stop Grants Payment'));
CRM_Core_Session::setStatus(ts('Selected Grant Payment has been stopped successfully.'), '', 'no-popup');
}
$this->addButtons(array(
array (
'type' => 'submit',
'name' => ts('OK'),
'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
'isDefault' => TRUE),
array (
'type' => 'cancel',
'name' => ts('Cancel'),
'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
),
));
}
}
public function postProcess() {
......@@ -124,10 +100,10 @@ class CRM_Grant_Form_Payment_View extends CRM_Core_Form {
$dao->save();
CRM_Core_Session::setStatus(ts('Selected Grant Payment has been stopped successfully.'));
CRM_Utils_System::redirect( CRM_Utils_System::url('civicrm/grant/payment/search', 'reset=1&force=1'));
}
}
elseif ($this->_action & CRM_Core_Action::REPRINT) {
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/grant/payment/reprint', 'reset=1&prid=' . $this->_id));
}
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/grant/payment/reprint', 'reset=1&prid=' . $this->_id));
}
elseif ($this->_action & CRM_Core_Action::WITHDRAW) {
$query = "SELECT cp.id as pid, cg.amount_granted as total_amount, cp.currency, cp.payment_reason, cp.contact_id as id, cep.entity_id as grant_id, cg.grant_program_id, cg.grant_type_id FROM civicrm_payment as cp LEFT JOIN civicrm_entity_payment as cep ON cep.payment_id = cp.id LEFT JOIN civicrm_grant as cg ON cg.id = cep.entity_id WHERE cp.id IN (".$this->_id.")";
$grantDao = CRM_Grant_DAO_Grant::executeQuery($query);
......@@ -150,5 +126,5 @@ class CRM_Grant_Form_Payment_View extends CRM_Core_Form {
CRM_Core_Session::setStatus(ts('Selected Grant Payment has been withdraw successfully.'));
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/grant/payment/search', 'reset=1&force=1'));
}
}
}
\ No newline at end of file
}
}
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.4 |
| CiviCRM version 5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2011 |
| Copyright CiviCRM LLC (c) 2004-2018 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
......@@ -24,12 +23,12 @@
| 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-2011
* @copyright CiviCRM LLC (c) 2004-2018
* $Id$
*
*/
......@@ -37,112 +36,50 @@
/**
* Files required
*/
/**
* This file is for civigrant search
*/
class CRM_Grant_Form_PaymentSearch extends CRM_Core_Form {
/**
* Are we forced to run a search
*
* @var int
* @access protected
*/
protected $_force;
class CRM_Grant_Form_PaymentSearch extends CRM_Core_Form_Search {
/**
* name of search button
*
* @var string
* @access protected
*/
protected $_searchButtonName;
/**
* name of print button
*
* @var string
* @access protected
*/
protected $_printButtonName;
/**
* name of action button
*
* @var string
* @access protected
*/
protected $_actionButtonName;
/**
* form values that we will be using
* The params that are sent to the query.
*
* @var array
* @access protected
*/
protected $_formValues;
/**
* the params that are sent to the query
*
* @var array
* @access protected
*/
protected $_queryParams;
/**
* have we already done this search
*
* @access protected
* @var boolean
*/
protected $_done;
/**
* are we restricting ourselves to a single contact
* Are we restricting ourselves to a single contact.
*
* @access protected
* @var boolean
*/
protected $_single = FALSE;
/**
* are we restricting ourselves to a single contact
* Are we restricting ourselves to a single contact.
*
* @access protected
* @var boolean
*/
protected $_limit = NULL;
/**
* what context are we being invoked from
*
* @access protected
* @var string
*/
protected $_context = NULL;
/**
* prefix for the controller
*
* Prefix for the controller.
*/
protected $_prefix = "grant_";
public $_defaults;
/**
* processing needed for buildForm and later
* Processing needed for buildForm and later.
*
* @return void
* @access public
*/
function preProcess() {
public function preProcess() {
/**
* set the button names
*/
$this->_searchButtonName = $this->getButtonName('refresh');
$this->_printButtonName = $this->getButtonName('next', 'print');
$this->_actionButtonName = $this->getButtonName('next', 'action');
$this->_done = FALSE;
$this->defaults = array();
......@@ -150,12 +87,11 @@ class CRM_Grant_Form_PaymentSearch extends CRM_Core_Form {
* we allow the controller to set force/reset externally, useful when we are being
* driven by the wizard framework
*/
$this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean', CRM_Core_DAO::$_nullObject);
$this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE);
$this->_download = CRM_Utils_Request::retrieve('download', 'String', $this, FALSE);
$this->_batchId = CRM_Utils_Request::retrieve('bid', 'Positive', $this, FALSE);
$this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean');
$this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE);
$this->_limit = CRM_Utils_Request::retrieve('limit', 'Positive', $this);
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'search');
$this->_context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this, FALSE, 'search');
$this->assign("context", $this->_context);
......@@ -168,15 +104,20 @@ class CRM_Grant_Form_PaymentSearch extends CRM_Core_Form {
$this->_formValues = $this->get('formValues');
}
if (empty($this->_formValues)) {
if (isset($this->_ssID)) {
$this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
}
}
if ($this->_force) {
$this->postProcess();
$this->set('force', 0);
}
$sortID = NULL;
if ($this->get( CRM_Utils_Sort::SORT_ID)) {
$sortID = CRM_Utils_Sort::sortIDValue(
$this->get(CRM_Utils_Sort::SORT_ID ),
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
);
}
......@@ -195,114 +136,44 @@ class CRM_Grant_Form_PaymentSearch extends CRM_Core_Form {
if ($this->_context == 'user') {
$prefix = $this->_prefix;
}
$this->assign("{$prefix}limit", $this->_limit);
$this->assign("{$prefix}single", $this->_single);
$controller = new CRM_Core_Selector_Controller(
$selector ,
$this->get( CRM_Utils_Pager::PAGE_ID ),
$controller = new CRM_Core_Selector_Controller($selector,
$this->get(CRM_Utils_Pager::PAGE_ID),
$sortID,
CRM_Core_Action::VIEW,
$this,
CRM_Core_Selector_Controller::TRANSFER,
$prefix
);
$controller->setEmbedded(TRUE);
$controller->moveFromSessionToTemplate();
$this->assign('summary', $this->get('summary'));
$download = FALSE;
if (CRM_Utils_Array::value('bid', $_GET)) {
$download = TRUE;
}
if ($this->_download && $download) {
//FIXME : incase of wp and joomla
global $base_url;
$config = CRM_Core_Config::singleton();
$directory = strstr($config->customFileUploadDir, 'sites');
$config = CRM_Core_Config::singleton();
$file_name = $base_url . '/' . $directory . $this->_download;
$this->assign('download', $file_name);
}
}
/**
* Build the form
* Build the form object.
*
*
* @access public
* @return void
*/
function buildQuickForm() {
$paymentStatus = CRM_Core_OptionGroup::values('grant_payment_status');
$this->add('select', 'payment_status_id', ts('Status'),
array('' => ts('- select -')) + $paymentStatus);
$this->add('select', 'payment_batch_number',
ts('Batch'),
// CRM-19325
['' => ts('None')] + CRM_Contribute_PseudoConstant::batch(),
FALSE, array('class' => 'crm-select2')
);
$this->addElement('text', 'payment_number', ts('Payment Number'), array('size' => 10, 'maxlength' => 10));