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