Merge pull request #23741 from ufundo/entitybatchcurrency
[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 $this->assign('isAdmin', CRM_Core_Permission::check('administer CiviCRM'));
79 }
80
81 /**
82 * the main function that is called when the page loads,
83 * it decides the which action has to be taken for the page.
84 *
85 * @return null
86 */
87 public function run() {
88 $this->preProcess();
89
90 $controller = new CRM_Core_Controller_Simple('CRM_Contribute_Form_Search',
91 ts('Contributions'), NULL
92 );
93 $controller->setEmbedded(TRUE);
94
95 $controller->set('limit', 10);
96 $controller->set('force', 1);
97 $controller->set('context', 'dashboard');
98 $controller->process();
99 $controller->run();
100 $chartForm = new CRM_Core_Controller_Simple('CRM_Contribute_Form_ContributionCharts',
101 ts('Contributions Charts'), NULL
102 );
103
104 $chartForm->setEmbedded(TRUE);
105 $chartForm->process();
106 $chartForm->run();
107 CRM_Core_Resources::singleton()
108 ->addScriptFile('civicrm', 'templates/CRM/Contribute/Page/DashBoard.js', 1, 'html-header');
109
110 return parent::run();
111 }
112
113 }