Merge pull request #4818 from pratikshad/CRM-15770
[civicrm-core.git] / CRM / Pledge / Page / DashBoard.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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
31 * @copyright CiviCRM LLC (c) 2004-2014
32 * $Id$
33 *
34 */
35
36 /**
37 * This is page is for Pledge Dashboard
38 */
39 class CRM_Pledge_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
46 *
47 */
48 public function preProcess() {
49 CRM_Utils_System::setTitle(ts('CiviPledge'));
50
51 $startToDate = array();
52 $yearToDate = array();
53 $monthToDate = array();
54 $previousToDate = array();
55
56 $prefixes = array('start', 'month', 'year', 'previous');
57 $status = array('Completed', 'Cancelled', 'Pending', 'In Progress', 'Overdue');
58
59 // cumulative (since inception) - prefix = 'start'
60 $startDate = NULL;
61 $startDateEnd = NULL;
62
63 // current year - prefix = 'year'
64 $config = CRM_Core_Config::singleton();
65 $yearDate = $config->fiscalYearStart;
66 $year = array('Y' => date('Y'));
67 $this->assign('curYear', $year['Y']);
68 $yearDate = array_merge($year, $yearDate);
69 $yearDate = CRM_Utils_Date::format($yearDate);
70 $yearDate = $yearDate . '000000';
71 $yearDateEnd = $year['Y'] . '1231235959';
72
73 // current month - prefix = 'month'
74 $currentMonth = date("F Y", mktime(0, 0, 0, date("m"), 01, date("Y")));
75 $this->assign('currentMonthYear', $currentMonth);
76 $monthDate = date('Ym') . '01000000';
77 $monthDateEnd = CRM_Utils_Date::customFormat(date("Y-m-t", mktime(0, 0, 0, date("m"), 01, date("Y"))), '%Y%m%d') . '235959';
78
79 // previous month - prefix = 'previous'
80 $previousDate = CRM_Utils_Date::customFormat(date("Y-m-d", mktime(0, 0, 0, date("m") - 1, 01, date("Y"))), '%Y%m%d') . '000000';
81 $previousDateEnd = CRM_Utils_Date::customFormat(date("Y-m-t", mktime(0, 0, 0, date("m") - 1, 01, date("Y"))), '%Y%m%d') . '235959';
82 $previousMonth = date("F Y", mktime(0, 0, 0, date("m") - 1, 01, date("Y")));
83 $this->assign('previousMonthYear', $previousMonth);
84
85
86 foreach ($prefixes as $prefix) {
87 $aName = $prefix . 'ToDate';
88 $startName = $prefix . 'Date';
89 $endName = $prefix . 'DateEnd';
90 foreach ($status as $s) {
91 ${$aName}[str_replace(" ", "", $s)] = CRM_Pledge_BAO_Pledge::getTotalAmountAndCount($s, $$startName, $$endName);
92 }
93 $this->assign($aName, $$aName);
94 }
95 }
96
97 /**
98 * This function is the main function that is called when the page loads,
99 * it decides the which action has to be taken for the page.
100 *
101 * return null
102 */
103 public function run() {
104 $this->preProcess();
105
106 $controller = new CRM_Core_Controller_Simple('CRM_Pledge_Form_Search',
107 ts('Pledge'),
108 NULL
109 );
110 $controller->setEmbedded(TRUE);
111 $controller->reset();
112 $controller->set('limit', 10);
113 $controller->set('force', 1);
114 $controller->set('context', 'dashboard');
115 $controller->process();
116 $controller->run();
117
118 return parent::run();
119 }
120 }