Unverified Commit d96f1357 authored by Monish Deb's avatar Monish Deb Committed by GitHub

Merge pull request #264 from JMAConsulting/4.7-dev

Merge 4.7 to master
parents f9791ee8 d4ca1665
......@@ -328,10 +328,20 @@ WHERE civicrm_contact.id = $id ";
),
'PDFFilename' => '',
);
$defaultAddress = CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL, ' AND is_default = 1');
foreach ($defaultAddress as $id => $value) {
$sendTemplateParams['from'] = $value;
$emailQuery = "SELECT from_email_address FROM civicrm_grant_program WHERE id = %1";
$defaultAddress = CRM_Core_DAO::singleValueQuery($emailQuery, array(
1 => array($values['grant_program_id'], 'Integer')
));
if (!isset($defaultAddress) || $defaultAddress == '') {
$defaultAddress = CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL, ' AND is_default = 1');
foreach ($defaultAddress as $id => $value) {
$sendTemplateParams['from'] = $value;
}
} else {
$sendTemplateParams['from'] = $defaultAddress;
}
$sendTemplateParams['toName'] = $displayName;
......
......@@ -110,6 +110,7 @@ class CRM_Grant_BAO_Query {
$query->_element['grant_type_id'] = 1;
$query->_element['grant_status_id'] = 1;
$query->_tables['civicrm_grant'] = 1;
$query->_tables['civicrm_payment'] = 1;
$query->_whereTables['civicrm_grant'] = 1;
}
}
......@@ -297,7 +298,7 @@ class CRM_Grant_BAO_Query {
}
$from .= "$side JOIN civicrm_entity_payment AS temp1 ON (civicrm_grant.id = temp1.entity_id AND temp1.entity_table = 'civicrm_grant')
$side JOIN (SELECT payment_id AS payment_id, entity_id AS entity_id FROM civicrm_entity_payment ORDER BY payment_id DESC) AS temp2 ON temp1.entity_id = temp2.entity_id
$side JOIN civicrm_payment ON (temp2.payment_id = civicrm_payment.id)";
$side JOIN civicrm_payment civicrm_payment2 ON (temp2.payment_id = civicrm_payment2.id)";
break;
......@@ -312,6 +313,11 @@ $side JOIN civicrm_payment ON (temp2.payment_id = civicrm_payment.id)";
case 'grant_program':
$from .= " $side JOIN civicrm_grant_program gp ON (civicrm_grant.grant_program_id = gp.id)";
break;
case 'civicrm_payment':
$from .= " $side JOIN civicrm_entity_payment ep ON (civicrm_grant.id = ep.entity_id AND ep.entity_table = 'civicrm_grant')" .
" $side JOIN civicrm_payment civicrm_payment ON (ep.payment_id = civicrm_payment.id)";
break;
}
return $from;
}
......
......@@ -116,6 +116,12 @@ class CRM_Grant_DAO_GrantProgram extends CRM_Core_DAO
* @var float
*/
public $remainder_amount;
/**
* FROM identity default for grant program;
*
* @var string
*/
public $from_email_address;
/**
* Financial Type ID
*
......@@ -272,6 +278,13 @@ class CRM_Grant_DAO_GrantProgram extends CRM_Core_DAO
'dataPattern' => '/^\d+(\.\d{2})?$/',
'export' => true,
) ,
'from_email_address' => array(
'name' => 'from_email_address',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('FROM Email Address') ,
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
) ,
'financial_type_id' => array(
'name' => 'financial_type_id',
'type' => CRM_Utils_Type::T_INT,
......
......@@ -85,6 +85,14 @@ class CRM_Grant_Form_GrantProgram extends CRM_Core_Form {
$defaults['is_auto_email'] = 1;
return $defaults;
}
if (!isset($defaults['from_email_address']) || $defaults['from_email_address'] == '') {
// Set to default identity
$defaultEmails =
CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL, ' AND is_default = 1');
$defaults['from_email_address'] = array_pop($defaultEmails);
}
return $defaults;
}
......@@ -128,7 +136,12 @@ class CRM_Grant_Form_GrantProgram extends CRM_Core_Form {
$this->add('text', 'remainder_amount', ts('Remainder Amount'),
$attributes['remainder_amount'], FALSE);
$this->addRule('remainder_amount', ts('Please enter a valid amount.'), 'money');
$this->addRule('remainder_amount', ts('Please enter a valid amount.'), 'money');
$this->registerRule('from_identity', 'callback', '_validateIdentity', 'CRM_Grant_Form_GrantProgram');
$this->add('text', 'from_email_address', ts('FROM Email Address'),
$attributes['from_email_address'], FALSE);
$this->addRule('from_email_address', ts('Please follow the proper format for From Email Address'), 'from_identity');
$contributionTypes = CRM_Grant_BAO_GrantProgram::contributionTypes();
$this->add('select', 'financial_type_id', ts('Financial Types'),
......@@ -179,6 +192,7 @@ class CRM_Grant_Form_GrantProgram extends CRM_Core_Form {
}
$values = $this->controller->exportValues($this->_name);
$values['from_email_address'] = htmlspecialchars_decode($values['from_email_address']); // avoid QuickForm's safe value for this field
$domainID = CRM_Core_Config::domainID();
$result = $this->updateGrantProgram($values, $domainID);
......@@ -203,6 +217,7 @@ class CRM_Grant_Form_GrantProgram extends CRM_Core_Form {
$dao->grant_type_id = $values['grant_type_id'];
$dao->total_amount = $values['total_amount'];
$dao->remainder_amount = $values['remainder_amount'];
$dao->from_email_address = str_replace('"<', '" <', $values['from_email_address']); // apparently we need a space
$dao->financial_type_id = $values['financial_type_id'];
$dao->status_id = CRM_Grant_BAO_GrantProgram::getOptionValueID(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup','grant_program_status','id','name'), $values['status_id']);
$dao->allocation_date = CRM_Utils_Date::processDate($values['allocation_date']);
......@@ -212,6 +227,26 @@ class CRM_Grant_Form_GrantProgram extends CRM_Core_Form {
$dao->grant_program_id = $values['grant_program_id'];
return $dao->save();
}
/**
* Validate FROM identity.
*
* @param $data
* @return bool
*/
static function _validateIdentity($data) {
$formEmail = CRM_Utils_Mail::pluckEmailFromHeader($data);
if (!CRM_Utils_Rule::email($formEmail)) {
return false;
}
$formName = explode('"', $data);
if (empty($formName[1]) || count($formName) != 3) {
return false;
}
return true;
}
}
......@@ -58,11 +58,11 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
$this->assign('contributionType', $contributionTypes[$values['financial_type_id']] );
$this->assign('grantProgramAlgorithm', CRM_Grant_BAO_GrantProgram::getOptionName( $values['allocation_algorithm']));
$this->assign('grant_program_id', empty($grantPrograms[$values['grant_program_id']]) ? NULL : $grantPrograms[$values['grant_program_id']]);
$grantTokens = array('label','name','total_amount',
$grantTokens = array('label','name','total_amount','from_email_address',
'remainder_amount', 'allocation_date', 'is_active', 'is_auto_email');
foreach ($grantTokens as $token) {
$this->assign($token, CRM_Utils_Array::value($token, $values));
$this->assign($token, htmlspecialchars(CRM_Utils_Array::value($token, $values)));
}
$this->assign('id', $this->_id);
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -41,7 +41,7 @@ require_once 'CRM/Grant/Form/Task.php';
* participations. This class provides functionality for the actual
* deletion.
*/
class CRM_Grant_Form_Task_Pay extends CRM_Grant_Form_Task
class CRM_Grant_Form_Task_Pay extends CRM_Grant_Form_Task
{
/**
* Are we operating in "single mode", i.e. deleting one
......@@ -57,19 +57,20 @@ class CRM_Grant_Form_Task_Pay extends CRM_Grant_Form_Task
* @return void
* @access public
*/
function preProcess( )
function preProcess( )
{
parent::preProcess( );
//check permission for delete.
if ( !CRM_Core_Permission::checkActionPermission( 'CiviGrant', CRM_Core_Action::PAY ) ) {
CRM_Core_Error::fatal( ts( 'You do not have permission to access this page' ) );
CRM_Core_Error::fatal( ts( 'You do not have permission to access this page' ) );
}
$grantStatus = CRM_Core_OptionGroup::values('grant_status', TRUE, FALSE, FALSE, NULL, 'name');
$paidGrants = $approvedGrants = array();
CRM_Core_PseudoConstant::populate($paidGrants, 'CRM_Grant_DAO_Grant', true, 'status_id', false, " id in (".implode ( ', ' , $this->_grantIds ).") AND status_id = {$grantStatus['Paid']}" );
CRM_Core_PseudoConstant::populate($approvedGrants, 'CRM_Grant_DAO_Grant', true, 'status_id', false, " id in (".implode ( ', ' , $this->_grantIds ).") AND status_id = {$grantStatus['Approved for Payment']}" );
CRM_Core_PseudoConstant::populate($paidGrants, 'CRM_Grant_DAO_Grant', true, 'status_id', false, " id in (".implode ( ', ' , $this->_grantIds ).") AND status_id = {$grantStatus['Paid']}");
CRM_Core_PseudoConstant::populate($approvedGrants, 'CRM_Grant_DAO_Grant', true, 'status_id', false, " id in (".implode ( ', ' , $this->_grantIds ).") AND status_id = {$grantStatus['Approved for Payment']}");
$this->_paidGrants = $paidGrants;
$this->_notApproved = count($this->_grantIds) - count( $this->_paidGrants ) - count( $approvedGrants );
......@@ -103,7 +104,7 @@ class CRM_Grant_Form_Task_Pay extends CRM_Grant_Form_Task
* @access public
* @return void
*/
function buildQuickForm( )
function buildQuickForm( )
{
$message = "";
if (count($this->_approvedGrants)) {
......@@ -120,28 +121,28 @@ class CRM_Grant_Form_Task_Pay extends CRM_Grant_Form_Task
$message .= 'Would you like to proceed to paying the '.count( $this->_approvedGrants ).' eligible or approved for payment but unpaid grants?';
CRM_Core_Session::setStatus(ts($message), NULL, 'no-popup');
}
$this->addButtons( array(
array (
array (
'type' => 'next',
'name' => ts('Continue >>'),
'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
'isDefault' => true,
'isDefault' => true,
),
array (
array (
'type' => 'cancel',
'name' => ts('Cancel'),
'name' => ts('Cancel'),
),
)
);
}
}
else {
CRM_Core_Session::setStatus(ts('Please select at least one grant that has been approved for payment or eligible and not been paid.'), NULL, 'no-popup');
$this->addButtons(array(
$this->addButtons(array(
array (
'type' => 'cancel',
'name' => ts('Cancel') ),
)
'type' => 'cancel',
'name' => ts('Cancel') ),
)
);
}
}
......@@ -152,11 +153,9 @@ class CRM_Grant_Form_Task_Pay extends CRM_Grant_Form_Task
* @access public
* @return None
*/
public function postProcess( )
public function postProcess( )
{
$this->set( 'approvedGrants', $this->_approvedGrants );
$this->controller->resetPage( 'GrantPayment' );
}
}
......@@ -179,7 +179,7 @@ class CRM_Grant_Form_Task_Reprint extends CRM_Grant_Form_PaymentTask
$payment['payment_status_id'] = CRM_Core_OptionGroup::getValue( 'grant_payment_status', 'Reprinted', 'name' );
$payment['replaces_payment_id'] = $paymentId;
$result = CRM_Grant_BAO_GrantPayment::add( &$payment, $ids = array() );
$result = CRM_Grant_BAO_GrantPayment::add( $payment, $ids = array() );
$newPaymentId = $result->id;
......
This diff is collapsed.
......@@ -44,6 +44,6 @@ abstract class CRM_Grantprograms_Hook extends CRM_Utils_Hook {
*/
static function grantAssessment(&$params) {
return self::singleton( )->invoke(1, $params, self::$_nullObject,
self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_grantAssessment');
self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_grantAssessment');
}
}
......@@ -8,6 +8,17 @@ class CRM_Grantprograms_Upgrader extends CRM_Grantprograms_Upgrader_Base {
// By convention, functions that look like "function upgrade_NNNN()" are
// upgrade tasks. They are executed in order (like Drupal's hook_update_N).
/**
* Add from_email column to grant program table to allow
*
* @return bool
*/
public function upgrade_4601() {
$this->ctx->log->info('Applying update 4601');
CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_grant_program ADD COLUMN from_email_address VARCHAR(255)');
return TRUE;
}
/**
* Example: Run an external SQL script when the module is installed
*
......
This diff is collapsed.
......@@ -82,6 +82,7 @@ CREATE TABLE IF NOT EXISTS `civicrm_grant_program` (
`is_auto_email` tinyint(4) DEFAULT '1' COMMENT 'Is auto email active?',
`allocation_algorithm` int(10) unsigned DEFAULT NULL COMMENT 'Allocation Algorithm.',
`grant_program_id` int(11) DEFAULT NULL COMMENT 'FK reference to this civicrm_grant_program table, used to determine grants given to contact in previous year during assessment.',
`from_email_address` varchar(255) DEFAULT NULL COMMENT 'FROM Email Identity',
PRIMARY KEY (`id`),
KEY `FK_civicrm_grant_program_grant_type_id` (`grant_type_id`),
KEY `FK_civicrm_grant_program_status_id` (`status_id`),
......@@ -283,9 +284,9 @@ SELECT @parentId1 := id FROM civicrm_navigation WHERE name = 'CiviGrant';
SELECT @parentId2 := id FROM civicrm_navigation WHERE name = 'Grants';
SELECT @weight := MAX(weight) FROM civicrm_navigation WHERE parent_id = @parentId2;
INSERT INTO `civicrm_navigation` (`domain_id`, `label`, `name`, `url`, `permission`, `permission_operator`, `parent_id`, `is_active`, `has_separator`, `weight`) VALUES
(1, 'Find Grant Payments', 'Find Grant Payments', 'civicrm/grant/payment/search&reset=1', 'access CiviGrant', 'AND', @parentId2, 1, 1, @weight = @weight + 1),
(1, 'Find Grant Payments', 'Find Grant Payments', 'civicrm/grant/payment/search?reset=1', 'access CiviGrant', 'AND', @parentId2, 1, 1, @weight = @weight + 1),
(1, 'New Grant Program', 'New Grant Program', 'civicrm/grant_program?action=add&reset=1', 'access CiviCRM,access CiviGrant,edit grants', 'AND', @parentId2, 1, 0, @weight = @weight + 1),
(1, 'Grant Programs', 'Grant Programs', 'civicrm/grant_program&reset=1', 'access CiviGrant,administer CiviCRM', 'AND', @parentId1, 1, NULL, 2);
(1, 'Grant Programs', 'Grant Programs', 'civicrm/grant_program?reset=1', 'access CiviGrant,administer CiviCRM', 'AND', @parentId1, 1, NULL, 2);
-- Accounting integration RG-125
......
......@@ -47,6 +47,12 @@
<td class="label">{$form.remainder_amount.label}</td>
<td class="html-adjust">{$form.remainder_amount.html}</td>
</tr>
<tr class="crm-grant_program-form-block-from_email_address">
<td class="label">{$form.from_email_address.label}</td>
<td class="html-adjust">{$form.from_email_address.html}<br />
<span class="description">{ts}Include double-quotes (&quot;) around the name and angle-brackets (&lt; &gt;) around the email address.<br />EXAMPLE: <em>&quot;Client Services&quot; &lt;clientservices@example.org&gt;</em>{/ts}<span>
</td>
</tr>
<tr class="crm-grant_program-form-block-contribution_type_id">
<td class="label">{$form.financial_type_id.label}</td>
<td class="html-adjust">{$form.financial_type_id.html}</td>
......
......@@ -54,6 +54,8 @@
<tr class="crm-grant-program-view-form-block-grant_type_id"><td class="label">{ts}Grant Type{/ts}</td> <td>{$grantType}</td></tr>
<tr class="crm-grant-program-view-form-block-total_amount"><td class="label">{ts}Total Amount{/ts}</td> <td>{$total_amount|crmMoney}</td></tr>
<tr class="crm-grant-program-view-form-block-remainder_amount"><td class="label">{ts}Remainder Amount{/ts}</td> <td>{$remainder_amount|crmMoney}</td></tr>
<tr class="crm-grant-program-view-form-block-from_email_address"><td class="label">{ts}FROM Email Address{/ts}</td>
<td>{$from_email_address}</td></tr>
<tr class="crm-grant-program-view-form-block-contribution_type_id"><td class="label">{ts}Contribution Type{/ts}</td> <td>{$contributionType}</td></tr>
<tr class="crm-grant-program-view-form-block-status_id"><td class="label">{ts}Grant Status{/ts}</td> <td>{$grantProgramStatus}</td></tr>
<tr class="crm-grant-program-view-form-block-allocation_algorithm"><td class="label">{ts}Allocation Algorithm{/ts}</td> <td>{$grantProgramAlgorithm}</td></tr>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment