Merge pull request #19701 from civicrm/5.35
[civicrm-core.git] / CRM / Contribute / Page / DashBoard.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * Page for displaying list of Payment-Instrument.
20 */
21 class CRM_Contribute_Page_DashBoard extends CRM_Core_Page {
22
23 /**
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.
27 */
28 public function preProcess() {
29 CRM_Utils_System::setTitle(ts('CiviContribute'));
30
31 $status = ['Valid', 'Cancelled'];
32 $prefixes = ['start', 'month', 'year'];
33 $startDate = NULL;
34 $startToDate = $monthToDate = $yearToDate = [];
35
36 //get contribution dates.
37 $dates = CRM_Contribute_BAO_Contribution::getContributionDates();
38 foreach ([
39 'now',
40 'yearDate',
41 'monthDate',
42 ] as $date) {
43 $$date = $dates[$date];
44 }
45 // fiscal years end date
46 $yearNow = date('Ymd', strtotime('+1 year -1 day', strtotime($yearDate)));
47
48 foreach ($prefixes as $prefix) {
49 $aName = $prefix . 'ToDate';
50 $dName = $prefix . 'Date';
51
52 if ($prefix == 'year') {
53 $now = $yearNow;
54 }
55
56 // appending end date i.e $now with time
57 // to also calculate records of end date till mid-night
58 $nowWithTime = $now . '235959';
59
60 foreach ($status as $s) {
61 ${$aName}[$s] = CRM_Contribute_BAO_Contribution::getTotalAmountAndCount($s, $$dName, $nowWithTime);
62 ${$aName}[$s]['url'] = CRM_Utils_System::url('civicrm/contribute/search',
63 "reset=1&force=1&status=1&receive_date_low={$$dName}&receive_date_high=$now&test=0"
64 );
65 }
66
67 $this->assign($aName, $$aName);
68 }
69
70 //for contribution tabular View
71 $buildTabularView = CRM_Utils_Array::value('showtable', $_GET, FALSE);
72 $this->assign('buildTabularView', $buildTabularView);
73 if ($buildTabularView) {
74 return;
75 }
76
77 // Check for admin permission to see if we should include the Manage Contribution Pages action link
78 $isAdmin = 0;
79 if (CRM_Core_Permission::check('administer CiviCRM')) {
80 $isAdmin = 1;
81 }
82 $this->assign('isAdmin', $isAdmin);
83 }
84
85 /**
86 * the main function that is called when the page loads,
87 * it decides the which action has to be taken for the page.
88 *
89 * @return null
90 */
91 public function run() {
92 $this->preProcess();
93
94 $controller = new CRM_Core_Controller_Simple('CRM_Contribute_Form_Search',
95 ts('Contributions'), NULL
96 );
97 $controller->setEmbedded(TRUE);
98
99 $controller->set('limit', 10);
100 $controller->set('force', 1);
101 $controller->set('context', 'dashboard');
102 $controller->process();
103 $controller->run();
104 $chartForm = new CRM_Core_Controller_Simple('CRM_Contribute_Form_ContributionCharts',
105 ts('Contributions Charts'), NULL
106 );
107
108 $chartForm->setEmbedded(TRUE);
109 $chartForm->process();
110 $chartForm->run();
111 CRM_Core_Resources::singleton()
112 ->addScriptFile('civicrm', 'templates/CRM/Contribute/Page/DashBoard.js', 1, 'html-header');
113
114 return parent::run();
115 }
116
117 }