Commit b2735de1 authored by KarinG's avatar KarinG
Browse files

Merge branch 'location-issued2' into 'master'

#46 - Add Location Issued field

See merge request !170
parents 405c373f 6d2de1a3
......@@ -43,6 +43,7 @@ class CRM_Cdntaxreceipts_Form_Report_ReceiptsIssued extends CRM_Report_Form {
'fields' =>
array(
'issued_on' => array('title' => 'Issued On', 'default' => TRUE,'type' => CRM_Utils_Type::T_TIMESTAMP,),
'location_issued' => array('title' => 'Location Issued', 'default' => FALSE,),
'receipt_amount' => array('title' => 'Receipt Amount', 'default' => TRUE, 'type' => CRM_Utils_Type::T_MONEY,),
'receipt_no' => array('title' => 'Receipt No.', 'default' => TRUE),
'issue_type' => array('title' => 'Issue Type', 'default' => TRUE),
......@@ -59,6 +60,11 @@ class CRM_Cdntaxreceipts_Form_Report_ReceiptsIssued extends CRM_Report_Form {
'title' => 'Issued On',
'type' => CRM_Utils_Type::T_TIMESTAMP,
'operatorType' => CRM_Report_Form::OP_DATE),
'location_issued' =>
array(
'title' => 'Location Issued',
'type' => CRM_Utils_Type::T_STRING,
),
'issue_type' =>
array(
'title' => ts('Issue Type'),
......
......@@ -62,7 +62,10 @@ class CRM_Cdntaxreceipts_Form_Settings extends CRM_Core_Form {
$this->add('text', 'org_email', ts('Email', array('domain' => 'org.civicrm.cdntaxreceipts')));
$this->add('text', 'org_web', ts('Website', array('domain' => 'org.civicrm.cdntaxreceipts')));
$this->add('text', 'org_charitable_no', ts('Charitable Registration Number', array('domain' => 'org.civicrm.cdntaxreceipts')));
$this->add('text', 'receipt_location_issued', ts('Location Issued', array('domain' => 'org.civicrm.cdntaxreceipts')));
// @todo: Do we need to do this - can't we just use the `required` param in add() above?
// If we do need to do this, shouldn't the labels be ts'd?
$this->addRule('org_name', 'Enter Organization Name', 'required');
$this->addRule('org_address_line1', 'Enter Address Line 1', 'required');
$this->addRule('org_address_line2', 'Enter Address Line 2', 'required');
......@@ -70,6 +73,7 @@ class CRM_Cdntaxreceipts_Form_Settings extends CRM_Core_Form {
$this->addRule('org_email', 'Enter Email', 'required');
$this->addRule('org_web', 'Enter Website', 'required');
$this->addRule('org_charitable_no', 'Enter Charitable Number', 'required');
$this->addRule('receipt_location_issued', 'Location Issued', 'required');
}
else if ( $mode == 'defaults' ) {
$defaults = array(
......@@ -85,6 +89,7 @@ class CRM_Cdntaxreceipts_Form_Settings extends CRM_Core_Form {
'receipt_watermark' => Civi::settings()->get('receipt_watermark'),
'receipt_pdftemplate' => Civi::settings()->get('receipt_pdftemplate'),
'org_charitable_no' => Civi::settings()->get('org_charitable_no'),
'receipt_location_issued' => Civi::settings()->get('receipt_location_issued'),
);
return $defaults;
}
......@@ -98,6 +103,7 @@ class CRM_Cdntaxreceipts_Form_Settings extends CRM_Core_Form {
Civi::settings()->set('org_email', $values['org_email']);
Civi::settings()->set('org_web', $values['org_web']);
Civi::settings()->set('org_charitable_no', $values['org_charitable_no']);
Civi::settings()->set('receipt_location_issued', $values['receipt_location_issued']);
}
}
......
......@@ -23,6 +23,9 @@ class CRM_Cdntaxreceipts_Form_ViewTaxReceipt extends CRM_Core_Form {
if (!CRM_Core_Permission::check('access CiviContribute')) {
CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
}
_cdntaxreceipts_check_requirements();
parent::preProcess();
$contributionId = CRM_Utils_Array::value('id', $_GET);
......
......@@ -26,6 +26,8 @@ class CRM_Cdntaxreceipts_Task_IssueAggregateTaxReceipts extends CRM_Contribute_F
CRM_Core_Error::fatal(ts('You do not have permission to access this page', array('domain' => 'org.civicrm.cdntaxreceipts')));
}
_cdntaxreceipts_check_requirements();
parent::preProcess();
$this->_contributions_status = array();
......
......@@ -24,6 +24,8 @@ class CRM_Cdntaxreceipts_Task_IssueAnnualTaxReceipts extends CRM_Contact_Form_Ta
CRM_Core_Error::fatal(ts('You do not have permission to access this page', array('domain' => 'org.civicrm.cdntaxreceipts')));
}
_cdntaxreceipts_check_requirements();
parent::preProcess();
$thisYear = date("Y");
......
......@@ -25,6 +25,8 @@ class CRM_Cdntaxreceipts_Task_IssueSingleTaxReceipts extends CRM_Contribute_Form
CRM_Core_Error::fatal(ts('You do not have permission to access this page', array('domain' => 'org.civicrm.cdntaxreceipts')));
}
_cdntaxreceipts_check_requirements();
parent::preProcess();
$receipts = array( 'original' => array('email' => 0, 'print' => 0, 'data' => 0),
......
......@@ -83,6 +83,7 @@ issue_method varchar(16) NULL COMMENT 'The send method (email or print).',
receipt_status varchar(10) DEFAULT 'issued' COMMENT 'The status of the receipt (issued or cancelled)',
email_tracking_id varchar(64) NULL COMMENT 'A unique id to track email opens.',
email_opened datetime NULL COMMENT 'Timestamp an email open event was detected.',
location_issued varchar(32) NOT NULL DEFAULT '' COMMENT 'City where receipt was issued.',
PRIMARY KEY (id),
INDEX contact_id (contact_id),
INDEX receipt_no (receipt_no)
......@@ -183,6 +184,16 @@ AND COLUMN_NAME = 'receipt_status'");
return TRUE;
}
/**
* Add location issued column
*/
public function upgrade_1412() {
$this->ctx->log->info('Applying update 1412: add location issued column');
// We don't extend the incremental base class, so we can't add a task and need to call directly.
CRM_Upgrade_Incremental_Base::addColumn($this->ctx, 'cdntaxreceipts_log', 'location_issued', "varchar(32) NOT NULL DEFAULT '' COMMENT 'City where receipt was issued.'");
return TRUE;
}
public function _create_message_template($email_message, $email_subject) {
$html_message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
......
......@@ -132,7 +132,7 @@ function cdntaxreceipts_load_receipt($receipt_id) {
return $receipt;
}
$sql = "SELECT l.id, l.receipt_no, l.issued_on, l.contact_id, l.receipt_amount as total_receipt,
$sql = "SELECT l.id, l.receipt_no, l.issued_on, l.location_issued, l.contact_id, l.receipt_amount as total_receipt,
l.is_duplicate, l.uid, l.ip, l.issue_type, l.issue_method, l.receipt_status,
l.email_tracking_id, l.email_opened,
c.contribution_id, c.contribution_amount, c.receipt_amount, c.receive_date
......@@ -148,6 +148,7 @@ function cdntaxreceipts_load_receipt($receipt_id) {
'id' => $dao->id,
'receipt_no' => $dao->receipt_no,
'issued_on' => date('Y-m-d H:i:s', $dao->issued_on),
'location_issued' => $dao->location_issued,
'contact_id' => $dao->contact_id,
'receipt_amount' => $dao->total_receipt,
'is_duplicate' => $dao->is_duplicate,
......@@ -206,10 +207,11 @@ function cdntaxreceipts_log($receipt) {
9 => array( $receipt['issue_method'], 'String' ),
10 => array( $receipt['receipt_status'], 'String' ),
11 => array( $receipt['email_tracking_id'], 'String' ),
12 => array( $receipt['location_issued'], 'String' ),
);
$sql = "INSERT INTO cdntaxreceipts_log (receipt_no, issued_on, contact_id, receipt_amount,
is_duplicate, uid, ip, issue_type, issue_method, receipt_status, email_tracking_id)
VALUES (%1, %2, %3, %4, %5, %6, %7, %8, %9, %10, %11)";
is_duplicate, uid, ip, issue_type, issue_method, receipt_status, email_tracking_id, location_issued)
VALUES (%1, %2, %3, %4, %5, %6, %7, %8, %9, %10, %11, %12)";
$result = CRM_Core_DAO::executeQuery($sql, $params);
if (is_a($result, 'DB_Error')) {
return FALSE;
......
......@@ -263,6 +263,7 @@ function cdntaxreceipts_generateFormattedReceipt($receipt, &$collectedPdf = NULL
"display_date" => $display_date,
"display_year" => $display_year,
"issued_on" => date('Y-m-d', $receipt['issued_on']),
"location_issued" => _cdntaxreceipts_get_location(),
"issue_type" => $receipt['issue_type'],
"receipt_number" => $receipt['receipt_no'],
"displayname" => $displayname,
......@@ -341,6 +342,7 @@ function _cdntaxreceipts_writePage(&$f, $pdf_variables, $receipt) {
function _cdntaxreceipts_writeReceipt(&$pdf, $pdf_variables) {
// Extract variables
// @todo Why do we do this?
$mode = $pdf_variables["mode"];
$mymargin_left = $pdf_variables["mymargin_left"];
$mymargin_top = $pdf_variables["mymargin_top"];
......@@ -351,6 +353,7 @@ function _cdntaxreceipts_writeReceipt(&$pdf, $pdf_variables) {
$amount = $pdf_variables["amount"];
$display_date = $pdf_variables["display_date"];
$issued_on = $pdf_variables["issued_on"];
$location_issued = $pdf_variables["location_issued"];
$receipt_number = $pdf_variables["receipt_number"];
$displayname = $pdf_variables["displayname"];
$address_line_1 = $pdf_variables["address_line_1"];
......@@ -429,6 +432,8 @@ function _cdntaxreceipts_writeReceipt(&$pdf, $pdf_variables) {
$pdf->Write(10, ts("Received on: %1", array(1 => $display_date, 'domain' => 'org.civicrm.cdntaxreceipts')));
$pdf->SetXY($mymargin_left + $x_detailscolumn, $mymargin_top + $y_detailscolumnstart + 18);
$pdf->Write(10, ts("Eligible Amount: $%1", array(1 => number_format($amount, 2), 'domain' => 'org.civicrm.cdntaxreceipts')));
$pdf->SetXY($mymargin_left + $x_detailscolumn, $mymargin_top + $y_detailscolumnstart + 24);
$pdf->Write(10, ts("Location Issued: %1", array(1 => $location_issued, 'domain' => 'org.civicrm.cdntaxreceipts')));
$pdf->SetXY($mymargin_left + $x_detailscolumn, $mymargin_top + $y_detailscolumnstart + 34);
if ($issue_type == 'annual') {
......@@ -740,6 +745,7 @@ function cdntaxreceipts_issueTaxReceipt($contribution, &$collectedPdf = NULL, $m
$receipt = array(
'receipt_no' => $receipt_no,
'issued_on' => CRM_Cdntaxreceipts_Utils_Time::time(),
'location_issued' => _cdntaxreceipts_get_location(),
'contact_id' => $contribution->contact_id,
'receipt_amount' => cdntaxreceipts_eligibleAmount($contribution->id),
'is_duplicate' => $is_duplicate,
......@@ -924,6 +930,7 @@ function cdntaxreceipts_issueAnnualTaxReceipt( $contactId, $year, &$collectedPdf
$method = 'print';
}
$receipt['issued_on'] = CRM_Cdntaxreceipts_Utils_Time::time();
$receipt['location_issued'] = _cdntaxreceipts_get_location();
$receipt['is_duplicate'] = 1;
$receipt['receive_date'] = $year;
$receipt['issue_method'] = $method;
......@@ -956,6 +963,7 @@ function cdntaxreceipts_issueAnnualTaxReceipt( $contactId, $year, &$collectedPdf
$receipt = array(
'receipt_no' => $receiptNo,
'issued_on' => CRM_Cdntaxreceipts_Utils_Time::time(),
'location_issued' => _cdntaxreceipts_get_location(),
'contact_id' => $contactId,
'receipt_amount' => $totalReceipt,
'is_duplicate' => 0,
......@@ -1031,6 +1039,7 @@ function cdntaxreceipts_issueAggregateTaxReceipt($contactId, $year, $contributio
$method = 'print';
}
$receipt['issued_on'] = CRM_Cdntaxreceipts_Utils_Time::time();
$receipt['location_issued'] = _cdntaxreceipts_get_location();
$receipt['is_duplicate'] = 1;
$receipt['issue_method'] = $method;
$receipt['receive_date'] = $year;
......@@ -1056,6 +1065,7 @@ function cdntaxreceipts_issueAggregateTaxReceipt($contactId, $year, $contributio
$receipt = array(
'receipt_no' => $receiptNo,
'issued_on' => CRM_Cdntaxreceipts_Utils_Time::time(),
'location_issued' => _cdntaxreceipts_get_location(),
'contact_id' => $contactId,
'receipt_amount' => $totalReceipt,
'is_duplicate' => 0,
......@@ -1375,3 +1385,28 @@ function _cdntaxreceipts_custom_field_exists($custom_group_id, $field_label) {
$result = civicrm_api('custom_field', 'get', $params);
return ($result['count'] != 0);
}
/**
* Get the issuing city, but bounce if not set.
* @return string
*/
function _cdntaxreceipts_get_location(): string {
$city = \Civi::settings()->get('receipt_location_issued');
if (empty($city)) {
CRM_Core_Error::statusBounce(
ts('Location Issued is not set. Please set it under Administer - CiviContribute - CDN Tax Receipts.', array('domain' => 'org.civicrm.cdntaxreceipts')),
CRM_Utils_System::url('civicrm/cdntaxreceipts/settings', 'reset=1')
);
}
return $city;
}
/**
* On upgrade, it may not always be possible to set a new setting to a sane
* value, or some similar issue. So on relevant pages we should call this to
* run some checks and statusBounce if not good to go.
*/
function _cdntaxreceipts_check_requirements(): void {
// At the moment this is all we do...
_cdntaxreceipts_get_location();
}
......@@ -44,6 +44,11 @@
<td class="content">{$form.org_charitable_no.html}
<p class="description">10000-000-RR0000</p></td>
</tr>
<tr>
<td class="label">{$form.receipt_location_issued.label}</td>
<td class="content">{$form.receipt_location_issued.html}
<p class="description">Toronto</p></td>
</tr>
</tbody>
</table>
......
......@@ -47,6 +47,12 @@ cj(document).ready(
<td class="label">Email Opened</td>
<td>{$receipt.email_opened|crmDate}</td>
</tr>
<tr>
<td class="label">{ts domain='org.civicrm.cdntaxreceipts'}Location Issued{/ts}</td>
<td>{$receipt.location_issued|escape}</td>
<td class="label"></td>
<td></td>
</tr>
</table>
{/if}
......
......@@ -24,6 +24,7 @@ class CRM_Cdntaxreceipts_Base extends \CiviUnitTestCase {
'receipt_prefix' => 'C-',
'receipt_serial' => 0,
'receipt_authorized_signature_text' => 'Receet Sighnor',
'receipt_location_issued' => 'Toronto',
'issue_inkind' => 0,
'delivery_method' => CDNTAX_DELIVERY_DATA_ONLY,
'attach_to_workflows' => 0,
......
<?php
/**
* @group headless
*/
class CRM_Cdntaxreceipts_LocationIssuedTest extends CRM_Cdntaxreceipts_Base {
/**
* Test the location issued is recorded for the receipt.
*/
public function testLocationIssued() {
\Civi::settings()->set('receipt_location_issued', 'Vancouver');
// create contribution
$contact_id = $this->individualCreate([], 1);
$datestr = date('Y-m-d');
$contribution_id = civicrm_api3('Contribution', 'create', [
'contact_id' => $contact_id,
'financial_type_id' => 'Donation',
'total_amount' => '10',
'receive_date' => $datestr,
])['id'];
// Need it in DAO format
$contribution = new CRM_Contribute_DAO_Contribution();
$contribution->id = $contribution_id;
$contribution->find(TRUE);
// issue receipt
list($result, $method) = cdntaxreceipts_issueTaxReceipt($contribution);
$this->assertTrue($result);
$this->assertEquals('data', $method);
$records = \CRM_Core_DAO::executeQuery("SELECT * FROM cdntaxreceipts_log")->fetchAll();
$this->assertCount(1, $records);
$this->assertEquals('Vancouver', $records[0]['location_issued']);
}
}
......@@ -70,7 +70,7 @@ class CRM_Cdntaxreceipts_ReceiptsIssuedReportTest extends CRM_Cdntaxreceipts_Bas
'civicrm_cdntaxreceipts_log_contributions_contribution_id' => 1,
'civicrm_contact_sort_name_link' => '/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=' . $contact_id,
'civicrm_contact_sort_name_hover' => 'View Contact Summary for this Contact',
]
],
], $data);
}
......@@ -135,7 +135,7 @@ class CRM_Cdntaxreceipts_ReceiptsIssuedReportTest extends CRM_Cdntaxreceipts_Bas
'civicrm_contribution_payment_instrument_id' => 'Check',
'civicrm_contact_sort_name_link' => '/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=' . $contact_id,
'civicrm_contact_sort_name_hover' => 'View Contact Summary for this Contact',
]
],
], $data);
}
......
......@@ -16,6 +16,7 @@ class AggregateTest extends CdntaxreceiptsBase {
parent::setUp();
$this->createUserAndLogIn();
$this->contact = $this->createContact();
\Civi::settings()->set('receipt_location_issued', 'Toronto');
}
public function testAggregateTaxReceipt() {
......@@ -68,6 +69,7 @@ class AggregateTest extends CdntaxreceiptsBase {
0 => array(
'id' => '1',
'issued_on' => (string) strtotime($mock_time),
'location_issued' => 'Toronto',
'receipt_no' => 'C-00000003',
'contact_id' => (string) $contact2['id'],
'receipt_amount' => '40.00',
......@@ -79,6 +81,7 @@ class AggregateTest extends CdntaxreceiptsBase {
1 => array(
'id' => '2',
'issued_on' => (string) strtotime($mock_time),
'location_issued' => 'Toronto',
'receipt_no' => 'C-00000002',
'contact_id' => (string) $this->contact['id'],
'receipt_amount' => '30.00',
......
......@@ -52,7 +52,7 @@ class CdntaxreceiptsBase extends CiviCrmTestBase {
'issue cdn tax receipts',
]);
$this->drupalLogin($account);
$this->_loggedInUser = $account->uid;
$this->_loggedInUser = (int) $account->id();
}
/**
......@@ -71,6 +71,7 @@ class CdntaxreceiptsBase extends CiviCrmTestBase {
'receipt_prefix' => 'C-',
'receipt_serial' => 0,
'receipt_authorized_signature_text' => 'Receet Sighnor',
'receipt_location_issued' => 'Toronto',
'issue_inkind' => 0,
'delivery_method' => CDNTAX_DELIVERY_DATA_ONLY,
'attach_to_workflows' => 0,
......
......@@ -16,6 +16,7 @@ class CustomTemplateTest extends CdntaxreceiptsBase {
parent::setUp();
$this->createUserAndLogIn();
$this->contact = $this->createContact();
\Civi::settings()->set('receipt_location_issued', 'Calgary');
}
public function testCustomTemplate() {
......
Supports Markdown
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