Merge pull request #7032 from mlutfy/4.7-crm17432
[civicrm-core.git] / CRM / Contribute / Page / DashBoard.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
6a488035
TO
32 */
33
34/**
347e061b 35 * Page for displaying list of Payment-Instrument.
6a488035
TO
36 */
37class CRM_Contribute_Page_DashBoard extends CRM_Core_Page {
38
39 /**
347e061b 40 * Heart of the viewing process.
6a488035 41 *
347e061b 42 * The runner gets all the meta data for the contact and calls the appropriate type of page to view.
6a488035 43 */
00be9182 44 public function preProcess() {
6a488035
TO
45 CRM_Utils_System::setTitle(ts('CiviContribute'));
46
353ffa53
TO
47 $status = array('Valid', 'Cancelled');
48 $prefixes = array('start', 'month', 'year');
49 $startDate = NULL;
6a488035
TO
50 $startToDate = $monthToDate = $yearToDate = array();
51
52 //get contribution dates.
53 $dates = CRM_Contribute_BAO_Contribution::getContributionDates();
54 foreach (array(
353ffa53
TO
55 'now',
56 'yearDate',
28a04ea9 57 'monthDate',
353ffa53 58 ) as $date) {
6a488035
TO
59 $$date = $dates[$date];
60 }
acff69f0
PJ
61 // fiscal years end date
62 $yearNow = date('Ymd', strtotime('+1 year -1 day', strtotime($yearDate)));
63
6a488035
TO
64 foreach ($prefixes as $prefix) {
65 $aName = $prefix . 'ToDate';
66 $dName = $prefix . 'Date';
67
68 if ($prefix == 'year') {
69 $now = $yearNow;
70 }
71
106f4f2d
PJ
72 // appending end date i.e $now with time
73 // to also calculate records of end date till mid-night
74 $nowWithTime = $now . '235959';
75
6a488035 76 foreach ($status as $s) {
106f4f2d 77 ${$aName}[$s] = CRM_Contribute_BAO_Contribution::getTotalAmountAndCount($s, $$dName, $nowWithTime);
6a488035
TO
78 ${$aName}[$s]['url'] = CRM_Utils_System::url('civicrm/contribute/search',
79 "reset=1&force=1&status=1&start={$$dName}&end=$now&test=0"
80 );
81 }
82
83 $this->assign($aName, $$aName);
84 }
85
86 //for contribution tabular View
87 $buildTabularView = CRM_Utils_Array::value('showtable', $_GET, FALSE);
88 $this->assign('buildTabularView', $buildTabularView);
89 if ($buildTabularView) {
90 return;
91 }
92
93 // Check for admin permission to see if we should include the Manage Contribution Pages action link
94 $isAdmin = 0;
95 if (CRM_Core_Permission::check('administer CiviCRM')) {
96 $isAdmin = 1;
97 }
98 $this->assign('isAdmin', $isAdmin);
99 }
100
101 /**
dc195289 102 * the main function that is called when the page loads,
6a488035
TO
103 * it decides the which action has to be taken for the page.
104 *
76e7a76c 105 * @return null
6a488035 106 */
00be9182 107 public function run() {
6a488035
TO
108 $this->preProcess();
109
110 $controller = new CRM_Core_Controller_Simple('CRM_Contribute_Form_Search',
111 ts('Contributions'), NULL
112 );
113 $controller->setEmbedded(TRUE);
114
115 $controller->set('limit', 10);
116 $controller->set('force', 1);
117 $controller->set('context', 'dashboard');
118 $controller->process();
119 $controller->run();
120 $chartForm = new CRM_Core_Controller_Simple('CRM_Contribute_Form_ContributionCharts',
121 ts('Contributions Charts'), NULL
122 );
123
124 $chartForm->setEmbedded(TRUE);
125 $chartForm->process();
126 $chartForm->run();
353ffa53
TO
127 CRM_Core_Resources::singleton()
128 ->addScriptFile('civicrm', 'templates/CRM/Contribute/Page/DashBoard.js', 1, 'html-header');
6a488035
TO
129
130 return parent::run();
131 }
96025800 132
6a488035 133}