Commit c4825c57 authored by Monish Deb's avatar Monish Deb

Refactored 'Reprint grant payment' task form

parent 8ce39eb9
......@@ -37,8 +37,9 @@
class CRM_Grant_BAO_GrantPayment extends CRM_Grant_DAO_GrantPayment {
const
STOP = 1,
REPRINT = 2;
STOP = 100,
REPRINT = 200,
WITHDRAW = 300;
/**
* static field for all the grant information that we can potentially export
* @var array
......
This diff is collapsed.
......@@ -236,20 +236,24 @@ class CRM_Grant_Form_PaymentSearch extends CRM_Core_Form {
$this->add('select', 'payment_status_id', ts('Status'),
array('' => ts('- select -')) + $paymentStatus);
$this->addElement('text', 'payment_batch_number', ts('Batch Number'), array('size' => 8, 'maxlength' => 8));
$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));
$this->addDate('payment_created_date_low', ts('From'), FALSE, array('formatType' => 'searchDate'));
$this->addDate('payment_created_date_high', ts('To'), FALSE, array('formatType' => 'searchDate'));
CRM_Core_Form_Date::buildDateRange($this, 'payment_created_date', 1, '_low', '_high', ts('From:'), FALSE);
$this->addElement('text', 'payable_to_name', ts('Payee name'), CRM_Core_DAO::getAttribute('CRM_Grant_DAO_GrantPayment', 'payable_to_name'));
$this->add('text', 'amount', ts('Amount'), array('size' => 8, 'maxlength' => 8));
/*
* add form checkboxes for each row. This is needed out here to conform to QF protocol
* of all elements being declared in builQuickForm
*/
$this->add('text', 'amount_low', ts('From'), array('size' => 8, 'maxlength' => 8));
$this->addRule('amount_low', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('9.99', ' '))), 'money');
$this->add('text', 'amount_high', ts('To'), array('size' => 8, 'maxlength' => 8));
$this->addRule('amount_high', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
$rows = $this->get('rows');
......@@ -339,7 +343,7 @@ class CRM_Grant_Form_PaymentSearch extends CRM_Core_Form {
if ($buttonName == $this->_actionButtonName || $buttonName == $this->_printButtonName) {
// check actionName and if next, then do not repeat a search, since we are going to the next page
// hack, make sure we reset the task values
$stateMachine =& $this->controller->getStateMachine();
$stateMachine = $this->controller->getStateMachine();
$formName = $stateMachine->getTaskFormName();
$this->controller->resetPage($formName);
return;
......
......@@ -36,7 +36,7 @@
/**
* This class generates task actions for CiviEvent
*
*
*/
class CRM_Grant_Form_PaymentTask extends CRM_Core_Form {
/**
......@@ -80,7 +80,7 @@ class CRM_Grant_Form_PaymentTask extends CRM_Core_Form {
static function preProcessCommon(&$form, $useTable = FALSE) {
$form->_grantIds = array();
if (!CRM_Utils_Array::value('prid', $_GET )) {
$values = $form->controller->exportValues('PaymentSearch');
}
......@@ -97,18 +97,18 @@ class CRM_Grant_Form_PaymentTask extends CRM_Core_Form {
$ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN);
}
}
}
}
else {
$queryParams = $form->get('queryParams');
$query = new CRM_Grant_BAO_PaymentSearch(
$queryParams,
NULL,
NULL,
FALSE,
FALSE,
$query = new CRM_Grant_BAO_PaymentSearch(
$queryParams,
NULL,
NULL,
FALSE,
FALSE,
CRM_Grant_BAO_PaymentSearch::MODE_GRANT_PAYMENT
);
$query->_distinctComponentClause = " civicrm_payment.id";
$query->_groupByComponentClause = " GROUP BY civicrm_payment.id ";
$result = $query->searchQuery(0, 0, NULL);
......@@ -123,7 +123,7 @@ class CRM_Grant_Form_PaymentTask extends CRM_Core_Form {
implode(',', $ids) . ' ) ';
$form->assign('totalSelectedGrants', count($ids));
}
$form->_grantPaymentIds = $form->_componentIds = $ids;
//set the context for redirection for any task actions
......@@ -142,30 +142,8 @@ class CRM_Grant_Form_PaymentTask extends CRM_Core_Form {
*/
public function setContactIDs() {
$this->_contactIds =& CRM_Core_DAO::getContactIDsFromComponent($this->_grantIds,
'civicrm_grant'
'civicrm_grant'
);
}
/**
* simple shell that derived classes can call to add buttons to
* the form with a customized title for the main Submit
*
* @param string $title title of the main button
* @param string $type button type for the form after processing
* @return void
* @access public
*/
function addDefaultButtons($title, $nextType = 'next', $backType = 'back') {
$this->addButtons(array(
array (
'type' => $nextType,
'name' => $title,
'isDefault' => TRUE),
array (
'type' => $backType,
'name' => ts('Back')),
)
);
}
}
......@@ -55,10 +55,10 @@ class CRM_Grant_Form_Task_GrantPayment extends CRM_Core_Form {
/**
* Get payment fields
*/
public function getPaymentFields() {
public static function getPaymentFields($print) {
return array(
'check_number' => array(
'is_required' => TRUE,
'is_required' => $print,
'add_field' => TRUE,
),
'trxn_id' => array(
......@@ -76,7 +76,7 @@ class CRM_Grant_Form_Task_GrantPayment extends CRM_Core_Form {
'htmlType' => 'datepicker',
'name' => 'trxn_date',
'title' => ts('Payment date to appear on cheques'),
'is_required' => TRUE,
'is_required' => $print,
'attributes' => array(
'date' => 'yyyy-mm-dd',
'time' => 24,
......@@ -89,7 +89,7 @@ class CRM_Grant_Form_Task_GrantPayment extends CRM_Core_Form {
'name' => 'contribution_batch_id',
'title' => ts('Assign to Batch'),
'attributes' => ['' => ts('None')] + CRM_Contribute_PseudoConstant::batch(),
'is_required' => TRUE,
'is_required' => $print,
],
);
}
......@@ -100,7 +100,8 @@ class CRM_Grant_Form_Task_GrantPayment extends CRM_Core_Form {
* @return None
* @access public
*/
public function buildQuickForm(){
public function buildQuickForm() {
CRM_Utils_System::setTitle(ts('Print Grants'));
if ($this->_action & CRM_Core_Action::DELETE) {
$this->addButtons([
[
......@@ -115,9 +116,25 @@ class CRM_Grant_Form_Task_GrantPayment extends CRM_Core_Form {
]);
return;
}
self::buildPaymentBlock($this);
$paymentFields = $this->getPaymentFields();
$this->assign('paymentFields', $paymentFields);
$buttonName = $this->_prid ? 'Reprint Checks and CSV Export' : 'Create Checks and CSV Export';
$this->addButtons([
[
'type' => 'upload',
'name' => ts($buttonName),
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
],
]);
}
public static function buildPaymentBlock($form, $print = TRUE) {
$paymentFields = self::getPaymentFields($print);
$form->assign('paymentFields', $paymentFields);
foreach ($paymentFields as $name => $paymentField) {
if (!empty($paymentField['add_field'])) {
$attributes = array(
......@@ -126,10 +143,10 @@ class CRM_Grant_Form_Task_GrantPayment extends CRM_Core_Form {
'context' => 'create',
'action' => 'create',
);
$this->addField($name, $attributes, $paymentField['is_required']);
$form->addField($name, $attributes, $paymentField['is_required']);
}
else {
$this->add($paymentField['htmlType'],
$form->add($paymentField['htmlType'],
$name,
$paymentField['title'],
$paymentField['attributes'],
......@@ -137,19 +154,6 @@ class CRM_Grant_Form_Task_GrantPayment extends CRM_Core_Form {
);
}
}
$buttonName = $this->_prid ? 'Reprint Checks and CSV Export' : 'Create Checks and CSV Export';
$this->addButtons([
[
'type' => 'upload',
'name' => ts($buttonName),
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
],
]);
}
public function postProcess() {
......@@ -160,11 +164,8 @@ class CRM_Grant_Form_Task_GrantPayment extends CRM_Core_Form {
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
$financialItemStatus = CRM_Core_PseudoConstant::accountOptionValues('financial_item_status');
$checkID = CRM_Core_PseudoConstant::getKey('CRM_Contribute_DAO_Contribution', 'payment_instrument_id', 'Check');
$mailParams = $printedRows = $files = [];
$mailParams = $printedRows = $files = $trxnIDs = [];
$totalAmount = $counter = 0;
$maxLimit = CRM_Utils_Array::value('Maximum number of checks per pdf file', CRM_Core_OptionGroup::values('grant_thresholds', TRUE));
$config = CRM_Core_Config::singleton();
$entityFileDAO = new CRM_Core_DAO_EntityFile();
$dao = CRM_Core_DAO::executeQuery(sprintf("
SELECT ft.id as ft_id, g.id as grant_id, fi.id as fi_id, g.financial_type_id, ft.to_financial_account_id, fi.currency, gp.is_auto_email, ft.total_amount, fi.contact_id, g.grant_program_id
......@@ -192,12 +193,13 @@ class CRM_Grant_Form_Task_GrantPayment extends CRM_Core_Form {
'entity_id' => $grantID,
];
$trxnID = civicrm_api3('FinancialTrxn', 'create', $financialTrxnParams)['id'];
$trxnIDs[] = $trxnID;
$description = CRM_Utils_Array::value('description', $values, $grantPrograms[$dao->grant_program_id]);
$financialParams = ['description' => $description, 'status_id' => CRM_Core_PseudoConstant::getKey('CRM_Financial_BAO_FinancialItem', 'status_id', 'Paid'), 'amount' => $dao->total_amount];
$ids = ['id' => $dao->fi_id];
$trxnIDs = ['id' => $trxnID];
CRM_Financial_BAO_FinancialItem::create($financialParams, $ids, $trxnIDs);
$trxnids = ['id' => $trxnID];
CRM_Financial_BAO_FinancialItem::create($financialParams, $ids, $trxnids);
civicrm_api3('EntityBatch', 'create', [
'entity_table' => 'civicrm_financial_trxn',
......@@ -225,6 +227,7 @@ class CRM_Grant_Form_Task_GrantPayment extends CRM_Core_Form {
];
CRM_Grant_BAO_GrantPayment::add($grantPaymentRecord);
$printedRows[$grantID] = [
'contact_id' => $dao->contact_id,
'financial_type_id' => $dao->financial_type_id,
......@@ -238,7 +241,7 @@ class CRM_Grant_Form_Task_GrantPayment extends CRM_Core_Form {
'amount' => $dao->total_amount,
'curreny' => $dao->currency,
'payment_reason' => CRM_Utils_Array::value('description', $values, $grantPrograms[$dao->grant_program_id]),
'payment_status_id' => array_search('Completed', $contributionStatuses),
'payment_status_id' => $grantPaymentRecord['payment_status_id'],
'replaces_payment_id' => NULL,
'payment_details' => sprintf(
'%s </td><td>%s</td><td>%s</td><td>%s',
......@@ -256,23 +259,69 @@ class CRM_Grant_Form_Task_GrantPayment extends CRM_Core_Form {
));
}
if (empty($printedRows)) {
return;
self::printPayments($this, $trxnIDs, CRM_Core_PseudoConstant::getKey('CRM_Grant_DAO_GrantPayment', 'payment_status_id', 'Printed'));
}
public static function printPayments($form, $trxnIDs, $statusID, $printPDF = TRUE) {
$totalAmount = 0;
$batchID = NULL;
$dao = CRM_Core_DAO::executeQuery(sprintf("
SELECT ft.id as ft_id, g.id as grant_id, fi.id as fi_id, g.financial_type_id, ft.to_financial_account_id, fi.currency, gp.is_auto_email, ft.total_amount, fi.contact_id, g.grant_program_id, fi.description, ft.trxn_date, ft.check_number, eb.batch_id
FROM civicrm_entity_financial_trxn eft
INNER JOIN civicrm_financial_trxn ft ON ft.id = eft.financial_trxn_id AND eft.entity_table = 'civicrm_grant'
INNER JOIN civicrm_grant g ON g.id = eft.entity_id
INNER JOIN civicrm_entity_financial_trxn eft1 ON eft1.financial_trxn_id = ft.id AND eft1.entity_table = 'civicrm_financial_item'
INNER JOIN civicrm_financial_item fi ON fi.id = eft1.entity_id
INNER JOIN civicrm_grant_program gp ON gp.id = g.grant_program_id
INNER JOIN civicrm_entity_batch eb ON eb.entity_id = ft.id AND eb.entity_table = 'civicrm_financial_trxn'
WHERE ft.id IN (%s) GROUP BY ft.id ", implode(', ', $trxnIDs)));
while($dao->fetch()) {
$batchID = $dao->batch_id;
$printedRows[$dao->ft_id] = [
'contact_id' => $dao->contact_id,
'financial_type_id' => $dao->financial_type_id,
'payment_batch_number' => $dao->batch_id,
'payment_number' => $dao->check_number,
'payment_date' => date("Y-m-d", strtotime($dao->trxn_date)),
'payment_created_date' => date('Y-m-d'),
// TODO remove CRM_Grant_BAO_GrantProgram::getDisplayName
'payable_to_name' => CRM_Contact_BAO_Contact::displayName($dao->contact_id),
'payable_to_address' => CRM_Utils_Array::value('address', CRM_Grant_BAO_GrantProgram::getAddress($dao->contact_id, NULL, TRUE)),
'amount' => $dao->total_amount,
'curreny' => $dao->currency,
'payment_reason' => $dao->description,
'payment_status_id' => $statusID,
'replaces_payment_id' => NULL,
'payment_details' => sprintf(
'%s </td><td>%s</td><td>%s</td><td>%s',
date("Y-m-d", strtotime($dao->trxn_date)),
$dao->grant_id,
CRM_Contact_BAO_Contact::displayName($dao->contact_id),
CRM_Utils_Money::format($dao->total_amount, NULL, NULL, FALSE)
),
'total_in_words' => CRM_Grant_BAO_GrantProgram::convertNumberToWords($dao->total_amount),
];
$totalAmount += $dao->total_amount;
}
$form->assign('grantPayment', $printedRows);
foreach (array_chunk($printedRows, $maxLimit, TRUE) as $payments) {
$this->assign('grantPayment', $payments);
$downloadNamePDF = implode('_', [
check_plain('grantPayment'),
date('Ymdhis'),
$counter
]) . '.pdf';
$fileName = CRM_Utils_File::makeFileName($downloadNamePDF);
$files[] = $fileName = $config->customFileUploadDir . CRM_Grant_BAO_GrantPayment::makePDF($fileName, $payments);
$counter++;
$maxLimit = CRM_Utils_Array::value('Maximum number of checks per pdf file', CRM_Core_OptionGroup::values('grant_thresholds', TRUE));
$config = CRM_Core_Config::singleton();
$entityFileDAO = new CRM_Core_DAO_EntityFile();
if ($printPDF) {
$counter = 0;
foreach (array_chunk($printedRows, $maxLimit, TRUE) as $payments) {
$downloadNamePDF = implode('_', [
check_plain('grantPayment'),
date('Ymdhis'),
$counter
]) . '.pdf';
$fileName = CRM_Utils_File::makeFileName($downloadNamePDF);
$files[] = $fileName = $config->customFileUploadDir . CRM_Grant_BAO_GrantPayment::makePDF($fileName, $payments);
$counter++;
}
}
$this->assign('grantPayment', $printedRows);
$downloadNameCSV = implode('_', [
check_plain('grantPayment'),
date('Ymdhis')
......@@ -290,13 +339,13 @@ class CRM_Grant_Form_Task_GrantPayment extends CRM_Core_Form {
$entityFileDAO->file_id = $fileID;
$entityFileDAO->save();
$this->assign('date', date('Y-m-d'));
$this->assign('time', date('H:i:s'));
$this->assign('batch_number', $values['contribution_batch_id']);
$this->assign('contact', CRM_Contact_BAO_Contact::displayName(CRM_Core_Session::getLoggedInContactID()));
$this->assign('total_payments', count($approvedGrantIDs));
$this->assign('total_amount' , CRM_Utils_Money::format($totalAmount, NULL, NULL,FALSE));
$this->assign('domain_name', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Domain', CRM_Core_Config::domainID(), 'name'));
$form->assign('date', date('Y-m-d'));
$form->assign('time', date('H:i:s'));
$form->assign('batch_number', $batchID);
$form->assign('contact', CRM_Contact_BAO_Contact::displayName(CRM_Core_Session::getLoggedInContactID()));
$form->assign('total_payments', count($printedRows));
$form->assign('total_amount' , CRM_Utils_Money::format($totalAmount, NULL, NULL,FALSE));
$form->assign('domain_name', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Domain', CRM_Core_Config::domainID(), 'name'));
$checkFile = CRM_Utils_File::makeFileName(check_plain('CheckRegister') . '.pdf');
$checkRegister = CRM_Grant_BAO_GrantPayment::makeReport($checkFile, $printedRows);
$files[] = $config->customFileUploadDir . $checkRegister;
......
<?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 provides the functionality to delete a group of
* participations. This class provides functionality for the actual
* deletion.
* This class provides the functionality to reprint payments.
*/
class CRM_Grant_Form_Task_Reprint extends CRM_Grant_Form_PaymentTask
{
class CRM_Grant_Form_Task_Reprint extends CRM_Grant_Form_PaymentTask {
/**
* Are we operating in "single mode", i.e. deleting one
* specific participation?
......@@ -55,255 +18,125 @@ class CRM_Grant_Form_Task_Reprint extends CRM_Grant_Form_PaymentTask
* @return void
* @access public
*/
function preProcess( )
{
parent::preProcess( );
if ( !CRM_Core_Permission::checkActionPermission( 'CiviGrant', CRM_Core_Action::PAY ) ) {
function preProcess() {
parent::preProcess();
if (!CRM_Core_Permission::check('create payments in CiviGrant')) {
CRM_Core_Error::fatal( ts( 'You do not have permission to access this page' ) );
}
}
/**
* Build the form
*
* @access public
* @return void
*/
function buildQuickForm( )
{
require_once 'CRM/Core/OptionGroup.php';
$validStatus = array( 'Printed', 'Reprinted');
$paymentStatus = CRM_Core_OptionGroup::values( 'grant_payment_status' );
foreach( $paymentStatus as $statusKey => $status ) {
if(in_array( $status , $validStatus) ) {
unset( $paymentStatus[$statusKey] );
}
}
$selectedPayments = count($this->_grantPaymentIds);
foreach ( $this->_grantPaymentIds as $key => $paymentId ) {
$paymentDAO = new CRM_Grant_DAO_GrantPayment();
$paymentDAO->id = $paymentId;
$paymentDAO->find(true);
if( array_key_exists( $paymentDAO->payment_status_id, $paymentStatus ) ) {
$validIDs = CRM_Utils_Array::collect('id', CRM_Core_DAO::executeQuery(
sprintf(
"SELECT DISTINCT id FROM civicrm_payment WHERE id IN (%s) AND payment_status_id IN (%s) ",
implode(',', $this->_grantPaymentIds),
implode(',', [
CRM_Core_PseudoConstant::getKey('CRM_Grant_BAO_GrantPayment', 'payment_status_id', 'Printed'),
CRM_Core_PseudoConstant::getKey('CRM_Grant_BAO_GrantPayment', 'payment_status_id', 'Reprinted'),
])
)
)->fetchAll());
$invalidCounts = count($this->_grantPaymentIds) - count($validIDs);
foreach ($this->_grantPaymentIds as $key => $id) {
if (!in_array($id, $validIDs)) {
unset($this->_grantPaymentIds[$key]);
}
}
$reprinted = count($this->_grantPaymentIds);
$stopped = $selectedPayments - $reprinted;
if ( count($this->_grantPaymentIds ) ) {
$this->assign( 'payments', 1 );
CRM_Core_Session::setStatus(ts( $stopped.' of the '.$selectedPayments.' selected grant payments have already been stopped. '.count($this->_grantPaymentIds).' of the '.count($this->_grantPaymentIds).' selected grant payments are printed or reprinted.'), NULL, 'no-popup');
$this->applyFilter('__ALL__','trim');
$attributes = CRM_Core_DAO::getAttribute( 'CRM_Grant_DAO_GrantProgram' );
$this->_contributionTypes = CRM_Grant_BAO_GrantProgram::contributionTypes();
$this->add('select', 'financial_type_id', ts( 'From account' ),
array( '' => ts( '- select -' ) ) + $this->_contributionTypes , true);
$this->add( 'text', 'payment_batch_number', ts( 'Payment Batch number' ),
$attributes['label'], true );
$this->add( 'text', 'payment_number', ts( 'Starting cheque number' ),
$attributes['label'], true );
$this->addDate( 'payment_date', ts('Payment date to appear on cheques'), false, array( 'formatType' => 'custom') );
$this->addButtons(array(
array ( 'type' => 'upload',
'name' => ts('Reprint Checks'),
'isDefault' => true ),
array ( 'type' => 'next',
'name' => ts('Export to CSV'),),
array ( 'type' => 'cancel',
'name' => ts('Cancel') ),
)
);
} else {
CRM_Core_Session::setStatus(ts('Please select at least one grant payment that has been printed.'), NULL, 'no-popup');
$this->addButtons(array(
array ( 'type' => 'cancel',
'name' => ts('Cancel') ),
)
);
$message = '';
if ($invalidCounts) {
$message .= $invalidCounts . ' of the selected grant payments have already been stopped or cancelled.';
}
CRM_Core_Session::setStatus(ts($message . count($this->_grantPaymentIds) . ' of the selected grant payments found eligible to be reprinted.'));
}
/**
* process the form after the input has been submitted and validated
*
* @access public
* @return None
*/
public function postProcess( )
{
$values = $this->controller->exportValues( $this->_name );
$makePdf = true;
foreach ( $_POST as $buttonKey => $buttonValue ) {
if ( $buttonKey == '_qf_Reprint_next' ) {
$makePdf = false;
}
function buildQuickForm() {
CRM_Utils_System::setTitle(ts('Reprint Grants'));
$validCount = (count($this->_grantPaymentIds) > 0);
$this->assign('recordFound', $validCount);
if ($validCount) {
$this->addButtons([
[
'type' => 'upload',
'name' => ts('Reprint Checks'),
'isDefault' => TRUE,
],
[
'type' => 'next',
'name' => ts('Export to CSV'),
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
],
]);
CRM_Grant_Form_Task_GrantPayment::buildPaymentBlock($this, FALSE);
}
$totalAmount = 0;
foreach ( $this->_grantPaymentIds as $paymentId ) {
else {
CRM_Core_Session::setStatus(ts('Please select at least one grant payment that has been printed.'));
$this->addButtons([
[
'type' => 'cancel',
'name' => ts('Back'),
],
]);
}
}
public function postProcess() {
$values = $this->controller->exportValues($this->_name);
$makePdf = empty($_POST['_qf_Reprint_next']);
$totalAmount = 0;
$stoppedStatusID = CRM_Core_PseudoConstant::getKey('CRM_Grant_BAO_GrantPayment', 'payment_status_id', 'Stopped');
$reprintedStatusID = CRM_Core_PseudoConstant::getKey('CRM_Grant_BAO_GrantPayment', 'payment_status_id', 'Reprinted');
$trxnIDs = $printedRows = [];
foreach ($this->_grantPaymentIds as $paymentId ) {
$paymentDAO = new CRM_Grant_DAO_GrantPayment();
$paymentDAO->id = $paymentId;
$paymentDAO->payment_status_id = CRM_Core_OptionGroup::getValue( 'grant_payment_status', 'Stopped', 'name' );
$paymentDAO->payment_status_id = $stoppedStatusID;
$paymentDAO->save();
$paymentDAO = new CRM_Grant_DAO_GrantPayment();
$paymentDAO->id = $paymentId;
$paymentDAO->find(true);
$payment['payment_batch_number'] = $values['payment_batch_number'];