Merge pull request #4818 from pratikshad/CRM-15770
[civicrm-core.git] / CRM / Contribute / Page / DashBoard.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
06b69b18 31 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
32 * $Id$
33 *
34 */
35
36/**
37 * Page for displaying list of Payment-Instrument
38 */
39class CRM_Contribute_Page_DashBoard extends CRM_Core_Page {
40
41 /**
42 * Heart of the viewing process. The runner gets all the meta data for
43 * the contact and calls the appropriate type of page to view.
44 *
45 * @return void
6a488035
TO
46 *
47 */
00be9182 48 public function preProcess() {
6a488035
TO
49 CRM_Utils_System::setTitle(ts('CiviContribute'));
50
51 $status = array('Valid', 'Cancelled');
52 $prefixes = array('start', 'month', 'year');
53 $startDate = NULL;
54 $startToDate = $monthToDate = $yearToDate = array();
55
56 //get contribution dates.
57 $dates = CRM_Contribute_BAO_Contribution::getContributionDates();
58 foreach (array(
59 'now', 'yearDate', 'monthDate') as $date) {
60 $$date = $dates[$date];
61 }
acff69f0
PJ
62 // fiscal years end date
63 $yearNow = date('Ymd', strtotime('+1 year -1 day', strtotime($yearDate)));
64
6a488035
TO
65 foreach ($prefixes as $prefix) {
66 $aName = $prefix . 'ToDate';
67 $dName = $prefix . 'Date';
68
69 if ($prefix == 'year') {
70 $now = $yearNow;
71 }
72
106f4f2d
PJ
73 // appending end date i.e $now with time
74 // to also calculate records of end date till mid-night
75 $nowWithTime = $now . '235959';
76
6a488035 77 foreach ($status as $s) {
106f4f2d 78 ${$aName}[$s] = CRM_Contribute_BAO_Contribution::getTotalAmountAndCount($s, $$dName, $nowWithTime);
6a488035
TO
79 ${$aName}[$s]['url'] = CRM_Utils_System::url('civicrm/contribute/search',
80 "reset=1&force=1&status=1&start={$$dName}&end=$now&test=0"
81 );
82 }
83
84 $this->assign($aName, $$aName);
85 }
86
87 //for contribution tabular View
88 $buildTabularView = CRM_Utils_Array::value('showtable', $_GET, FALSE);
89 $this->assign('buildTabularView', $buildTabularView);
90 if ($buildTabularView) {
91 return;
92 }
93
94 // Check for admin permission to see if we should include the Manage Contribution Pages action link
95 $isAdmin = 0;
96 if (CRM_Core_Permission::check('administer CiviCRM')) {
97 $isAdmin = 1;
98 }
99 $this->assign('isAdmin', $isAdmin);
100 }
101
102 /**
103 * This function is the main function that is called when the page loads,
104 * it decides the which action has to be taken for the page.
105 *
106 * return null
6a488035 107 */
00be9182 108 public function run() {
6a488035
TO
109 $this->preProcess();
110
111 $controller = new CRM_Core_Controller_Simple('CRM_Contribute_Form_Search',
112 ts('Contributions'), NULL
113 );
114 $controller->setEmbedded(TRUE);
115
116 $controller->set('limit', 10);
117 $controller->set('force', 1);
118 $controller->set('context', 'dashboard');
119 $controller->process();
120 $controller->run();
121 $chartForm = new CRM_Core_Controller_Simple('CRM_Contribute_Form_ContributionCharts',
122 ts('Contributions Charts'), NULL
123 );
124
125 $chartForm->setEmbedded(TRUE);
126 $chartForm->process();
127 $chartForm->run();
96ed17aa 128 CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'templates/CRM/Contribute/Page/DashBoard.js', 1, 'html-header');
6a488035
TO
129
130 return parent::run();
131 }
132}