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