Merge pull request #15826 from seamuslee001/dev_core_183_dedupe
[civicrm-core.git] / CRM / Pledge / Page / DashBoard.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
cc28438b 19 * This page is for the Pledge Dashboard.
6a488035
TO
20 */
21class CRM_Pledge_Page_DashBoard extends CRM_Core_Page {
22
23 /**
167bcb5f 24 * Heart of the viewing process.
25 *
26 * The runner gets all the meta data for the contact and calls the appropriate type of page to view.
6a488035 27 */
00be9182 28 public function preProcess() {
6a488035
TO
29 CRM_Utils_System::setTitle(ts('CiviPledge'));
30
be2fb01f
CW
31 $startToDate = [];
32 $yearToDate = [];
33 $monthToDate = [];
34 $previousToDate = [];
6a488035 35
be2fb01f
CW
36 $prefixes = ['start', 'month', 'year', 'previous'];
37 $status = ['Completed', 'Cancelled', 'Pending', 'In Progress', 'Overdue'];
6a488035
TO
38
39 // cumulative (since inception) - prefix = 'start'
40 $startDate = NULL;
41 $startDateEnd = NULL;
42
43 // current year - prefix = 'year'
167bcb5f 44 $yearDate = \Civi::settings()->get('fiscalYearStart');
be2fb01f 45 $year = ['Y' => date('Y')];
6a488035 46 $this->assign('curYear', $year['Y']);
353ffa53
TO
47 $yearDate = array_merge($year, $yearDate);
48 $yearDate = CRM_Utils_Date::format($yearDate);
49 $yearDate = $yearDate . '000000';
6a488035
TO
50 $yearDateEnd = $year['Y'] . '1231235959';
51
52 // current month - prefix = 'month'
53 $currentMonth = date("F Y", mktime(0, 0, 0, date("m"), 01, date("Y")));
54 $this->assign('currentMonthYear', $currentMonth);
55 $monthDate = date('Ym') . '01000000';
56 $monthDateEnd = CRM_Utils_Date::customFormat(date("Y-m-t", mktime(0, 0, 0, date("m"), 01, date("Y"))), '%Y%m%d') . '235959';
57
58 // previous month - prefix = 'previous'
353ffa53 59 $previousDate = CRM_Utils_Date::customFormat(date("Y-m-d", mktime(0, 0, 0, date("m") - 1, 01, date("Y"))), '%Y%m%d') . '000000';
6a488035 60 $previousDateEnd = CRM_Utils_Date::customFormat(date("Y-m-t", mktime(0, 0, 0, date("m") - 1, 01, date("Y"))), '%Y%m%d') . '235959';
353ffa53 61 $previousMonth = date("F Y", mktime(0, 0, 0, date("m") - 1, 01, date("Y")));
6a488035
TO
62 $this->assign('previousMonthYear', $previousMonth);
63
6a488035 64 foreach ($prefixes as $prefix) {
353ffa53 65 $aName = $prefix . 'ToDate';
6a488035 66 $startName = $prefix . 'Date';
353ffa53 67 $endName = $prefix . 'DateEnd';
6a488035
TO
68 foreach ($status as $s) {
69 ${$aName}[str_replace(" ", "", $s)] = CRM_Pledge_BAO_Pledge::getTotalAmountAndCount($s, $$startName, $$endName);
70 }
71 $this->assign($aName, $$aName);
72 }
73 }
74
75 /**
167bcb5f 76 * The main function that is called when the page loads.
77 *
cc28438b 78 * it decides which action has to be taken for the page.
6a488035 79 *
76e7a76c 80 * @return null
6a488035 81 */
00be9182 82 public function run() {
6a488035
TO
83 $this->preProcess();
84
85 $controller = new CRM_Core_Controller_Simple('CRM_Pledge_Form_Search',
86 ts('Pledge'),
87 NULL
88 );
89 $controller->setEmbedded(TRUE);
90 $controller->reset();
91 $controller->set('limit', 10);
92 $controller->set('force', 1);
93 $controller->set('context', 'dashboard');
94 $controller->process();
95 $controller->run();
96
97 return parent::run();
98 }
96025800 99
6a488035 100}