Skip to content

Commit

Permalink
Merged in PG-352-update_giftaid_report (pull request civicrm#17)
Browse files Browse the repository at this point in the history
reorder report columns
  • Loading branch information
guanhuan committed Nov 15, 2016
2 parents 8b940af + e4580d0 commit 3baab74
Showing 1 changed file with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function __construct() {
'receive_date' => array(
'name' => 'receive_date',
'title' => ts('Donation Date'),
'type' => CRM_Utils_Type::T_STRING,
'no_display' => FALSE,
'required' => TRUE,
),
Expand All @@ -123,7 +124,7 @@ public function __construct() {
'name' => 'id',
'title' => ts('Financial Type No'),
'no_display' => TRUE,
'required' => FALSE,
'required' => TRUE,
),
),
),
Expand Down Expand Up @@ -172,7 +173,8 @@ public function __construct() {
'title' => ts('Amount'),
'no_display' => FALSE,
'required' => TRUE,
'type' => CRM_Utils_Type::T_MONEY
// HMRC requires only number
//'type' => CRM_Utils_Type::T_MONEY
),
'quantity' => array(
'name' => 'qty',
Expand Down Expand Up @@ -279,7 +281,7 @@ public function select() {

$this->_columnHeaders['civicrm_line_item_gift_aid_amount'] = array(
'title' => 'Gift Aid Amount',
'type' => CRM_Utils_Type::T_MONEY
//'type' => CRM_Utils_Type::T_MONEY
);

$this->reorderColumns();
Expand Down Expand Up @@ -327,6 +329,9 @@ public function statistics(&$rows) {
$totalGiftAidAmount += $row['civicrm_line_item_gift_aid_amount'];
}

$totalAmount = round($totalAmount, 2);
$totalGiftAidAmount = round($totalGiftAidAmount, 2);

$statistics['counts']['amount'] = array(
'value' => $totalAmount,
'title' => 'Total Amount',
Expand Down Expand Up @@ -377,11 +382,11 @@ public function alterDisplay(&$rows) {
}
if (isset($row['civicrm_line_item_amount'])) {
$batch = $this->getBatchById($row['civicrm_entity_batch_batch_id']);
$rows[$rowNum]['civicrm_line_item_gift_aid_amount'] =
CRM_Civigiftaid_Utils_Contribution::calculateGiftAidAmt(
$giftaidAmount = CRM_Civigiftaid_Utils_Contribution::calculateGiftAidAmt(
$row['civicrm_line_item_amount'],
$batch['basic_rate_tax']
);
);
$rows[$rowNum]['civicrm_line_item_gift_aid_amount'] = number_format((float)$giftaidAmount, 2, '.', '');
}
if (!empty($row['civicrm_line_item_entity_table'])) {
$rows[$rowNum]['civicrm_line_item_entity_table'] =
Expand Down Expand Up @@ -420,6 +425,14 @@ public function alterDisplay(&$rows) {
$entryFound = TRUE;
}

// handle donation date
if (array_key_exists('civicrm_contribution_receive_date', $row)) {
if ($value = $row['civicrm_contribution_receive_date']) {
$rows[$rowNum]['civicrm_contribution_receive_date'] = date("d/m/y", strtotime($value));
}
$entryFound = TRUE;
}

// skip looking further in rows, if first row itself doesn't
// have the column we need
if (!$entryFound) {
Expand Down Expand Up @@ -472,25 +485,25 @@ private function getBatchById($id) {

private function reorderColumns() {
$columnTitleOrder = array(
'payment no',
'line item no',
'title',
'first name',
'last name',
'donor name',
'item',
'description',
'donation date',
'street address',
'city',
'county',
'country',
'postcode',
'eligible for gift aid?',
'quantity',
'country',
'donation date',
'amount',
'gift aid amount',
'batch name'
'donor name',
'item',
'description',
'quantity',
'eligible for gift aid?',
'batch name',
'payment no',
'line item no',
'gift aid amount'
);

$compare = function ($a, $b) use (&$columnTitleOrder) {
Expand Down

0 comments on commit 3baab74

Please sign in to comment.