Merge pull request #22487 from mattwire/repeattransactiontemplatecontribution
[civicrm-core.git] / CRM / Contribute / Page / DashBoard.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
347e061b 19 * Page for displaying list of Payment-Instrument.
6a488035
TO
20 */
21class CRM_Contribute_Page_DashBoard extends CRM_Core_Page {
22
23 /**
347e061b 24 * Heart of the viewing process.
6a488035 25 *
347e061b 26 * The runner gets all the meta data for the contact and calls the appropriate type of page to view.
6a488035 27 */
00be9182 28 public function preProcess() {
6a488035
TO
29 CRM_Utils_System::setTitle(ts('CiviContribute'));
30
be2fb01f
CW
31 $status = ['Valid', 'Cancelled'];
32 $prefixes = ['start', 'month', 'year'];
353ffa53 33 $startDate = NULL;
be2fb01f 34 $startToDate = $monthToDate = $yearToDate = [];
6a488035
TO
35
36 //get contribution dates.
37 $dates = CRM_Contribute_BAO_Contribution::getContributionDates();
be2fb01f 38 foreach ([
1330f57a
SL
39 'now',
40 'yearDate',
41 'monthDate',
42 ] as $date) {
6a488035
TO
43 $$date = $dates[$date];
44 }
acff69f0
PJ
45 // fiscal years end date
46 $yearNow = date('Ymd', strtotime('+1 year -1 day', strtotime($yearDate)));
47
6a488035
TO
48 foreach ($prefixes as $prefix) {
49 $aName = $prefix . 'ToDate';
50 $dName = $prefix . 'Date';
51
52 if ($prefix == 'year') {
53 $now = $yearNow;
54 }
55
106f4f2d
PJ
56 // appending end date i.e $now with time
57 // to also calculate records of end date till mid-night
58 $nowWithTime = $now . '235959';
59
6a488035 60 foreach ($status as $s) {
106f4f2d 61 ${$aName}[$s] = CRM_Contribute_BAO_Contribution::getTotalAmountAndCount($s, $$dName, $nowWithTime);
6a488035 62 ${$aName}[$s]['url'] = CRM_Utils_System::url('civicrm/contribute/search',
0d7f0b19 63 "reset=1&force=1&status=1&receive_date_low={$$dName}&receive_date_high=$now&test=0"
6a488035
TO
64 );
65 }
66
67 $this->assign($aName, $$aName);
68 }
69
70 //for contribution tabular View
71 $buildTabularView = CRM_Utils_Array::value('showtable', $_GET, FALSE);
72 $this->assign('buildTabularView', $buildTabularView);
73 if ($buildTabularView) {
74 return;
75 }
76
77 // Check for admin permission to see if we should include the Manage Contribution Pages action link
fed95fdf 78 $this->assign('isAdmin', CRM_Core_Permission::check('administer CiviCRM'));
6a488035
TO
79 }
80
81 /**
dc195289 82 * the main function that is called when the page loads,
6a488035
TO
83 * it decides the which action has to be taken for the page.
84 *
76e7a76c 85 * @return null
6a488035 86 */
00be9182 87 public function run() {
6a488035
TO
88 $this->preProcess();
89
90 $controller = new CRM_Core_Controller_Simple('CRM_Contribute_Form_Search',
eb0010b8 91 ts('Contributions'), NULL
6a488035
TO
92 );
93 $controller->setEmbedded(TRUE);
94
95 $controller->set('limit', 10);
96 $controller->set('force', 1);
97 $controller->set('context', 'dashboard');
98 $controller->process();
99 $controller->run();
100 $chartForm = new CRM_Core_Controller_Simple('CRM_Contribute_Form_ContributionCharts',
101 ts('Contributions Charts'), NULL
102 );
103
104 $chartForm->setEmbedded(TRUE);
105 $chartForm->process();
106 $chartForm->run();
353ffa53
TO
107 CRM_Core_Resources::singleton()
108 ->addScriptFile('civicrm', 'templates/CRM/Contribute/Page/DashBoard.js', 1, 'html-header');
6a488035
TO
109
110 return parent::run();
111 }
96025800 112
6a488035 113}