Merge pull request #16899 from mlutfy/mailingReportView
[civicrm-core.git] / CRM / Contribute / 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/**
347e061b 19 * Page for displaying list of Payment-Instrument.
6a488035
TO
20 */
21class CRM_Contribute_Page_DashBoard extends CRM_Core_Page {
22
23 /**
347e061b 24 * Heart of the viewing process.
6a488035 25 *
347e061b 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('CiviContribute'));
30
be2fb01f
CW
31 $status = ['Valid', 'Cancelled'];
32 $prefixes = ['start', 'month', 'year'];
353ffa53 33 $startDate = NULL;
be2fb01f 34 $startToDate = $monthToDate = $yearToDate = [];
6a488035
TO
35
36 //get contribution dates.
37 $dates = CRM_Contribute_BAO_Contribution::getContributionDates();
be2fb01f 38 foreach ([
1330f57a
SL
39 'now',
40 'yearDate',
41 'monthDate',
42 ] as $date) {
6a488035
TO
43 $$date = $dates[$date];
44 }
acff69f0
PJ
45 // fiscal years end date
46 $yearNow = date('Ymd', strtotime('+1 year -1 day', strtotime($yearDate)));
47
6a488035
TO
48 foreach ($prefixes as $prefix) {
49 $aName = $prefix . 'ToDate';
50 $dName = $prefix . 'Date';
51
52 if ($prefix == 'year') {
53 $now = $yearNow;
54 }
55
106f4f2d
PJ
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
6a488035 60 foreach ($status as $s) {
106f4f2d 61 ${$aName}[$s] = CRM_Contribute_BAO_Contribution::getTotalAmountAndCount($s, $$dName, $nowWithTime);
6a488035
TO
62 ${$aName}[$s]['url'] = CRM_Utils_System::url('civicrm/contribute/search',
63 "reset=1&force=1&status=1&start={$$dName}&end=$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 /**
dc195289 86 * the main function that is called when the page loads,
6a488035
TO
87 * it decides the which action has to be taken for the page.
88 *
76e7a76c 89 * @return null
6a488035 90 */
00be9182 91 public function run() {
6a488035
TO
92 $this->preProcess();
93
94 $controller = new CRM_Core_Controller_Simple('CRM_Contribute_Form_Search',
eb0010b8 95 ts('Contributions'), NULL
6a488035
TO
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();
353ffa53
TO
111 CRM_Core_Resources::singleton()
112 ->addScriptFile('civicrm', 'templates/CRM/Contribute/Page/DashBoard.js', 1, 'html-header');
6a488035
TO
113
114 return parent::run();
115 }
96025800 116
6a488035 117}