reportsController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <?php
  2. class reportsController extends Staple_Controller
  3. {
  4. private $authLevel;
  5. private $uid;
  6. public function _start()
  7. {
  8. $this->_setLayout('main');
  9. $auth = Staple_Auth::get();
  10. $this->authLevel = $auth->getAuthLevel();
  11. $user = new userModel();
  12. $this->uid = $user->getId();
  13. if ($this->authLevel < 500) {
  14. header("location:" . $this->_link(array('index', 'index')) . "");
  15. }
  16. }
  17. public function index($year = null, $month = null)
  18. {
  19. if ($year == null) {
  20. $year = date('Y');
  21. }
  22. if ($month == null) {
  23. $month = date('m');
  24. }
  25. $date = new DateTime();
  26. $date->setDate($year,$month,26);
  27. $date->setTime(0,0,0);
  28. $this->view->year = $date->format('Y');
  29. $this->view->date = $date->format("F Y");
  30. $date->modify('+1 year');
  31. $this->view->nextYear = $date->format('Y');
  32. $date->modify('-2 year');
  33. $this->view->previousYear = $date->format('Y');
  34. $date->modify('+1 year');
  35. $month = $date->format('m');
  36. $this->view->month = $month;
  37. $date->modify('-1 month');
  38. $this->view->previousMonth = $date->format('m');
  39. $date->modify('+2 month');
  40. $this->view->nextMonth = $date->format('m');
  41. $report = new reportModel($year, $month);
  42. $this->view->report = $report->getTimesheets();
  43. $this->view->accountLevel = $this->authLevel;
  44. $date = new DateTime();
  45. $date->setDate($year, $month, 1);
  46. $this->view->monthName = $date->format('F');
  47. $printActiveTimeSheetForm = new printActiveTimeSheetForm();
  48. $printActiveTimeSheetForm->setAction($this->_link(array("reports",$year,$month)));
  49. if($printActiveTimeSheetForm->wasSubmitted())
  50. {
  51. $printActiveTimeSheetForm->addData($_POST);
  52. if($printActiveTimeSheetForm->validate())
  53. {
  54. $data = $printActiveTimeSheetForm->exportFormData();
  55. $this->layout->addScriptBlock("
  56. window.open('".$this->_link(array("reports","printpreview",$year,$month,$data['account']))."');
  57. ");
  58. $this->view->printTimeSheetForm = $printActiveTimeSheetForm;
  59. }
  60. else
  61. {
  62. $this->view->printTimeSheetForm = $printActiveTimeSheetForm;
  63. }
  64. }
  65. else
  66. {
  67. $this->view->printTimeSheetForm = $printActiveTimeSheetForm;
  68. }
  69. }
  70. public function changeyear()
  71. {
  72. $form = new changeYearForm();
  73. if($form->wasSubmitted())
  74. {
  75. $form->addData($_POST);
  76. if($form->validate())
  77. {
  78. $data = $form->exportFormData();
  79. header("location: ".$this->_link(array('reports',$data['year']))."");
  80. }
  81. else
  82. {
  83. header("location: ".$this->_link(array('reports'))."");
  84. }
  85. }
  86. else
  87. {
  88. header("location: ".$this->_link(array('reports'))."");
  89. }
  90. }
  91. public function weekly()
  92. {
  93. //Weekly report form
  94. $form = new weeklyReportForm();
  95. if ($form->wasSubmitted()) {
  96. $form->addData($_POST);
  97. if ($form->validate()) {
  98. $data = $form->exportFormData();
  99. $report = new weeklyReportModel();
  100. $this->view->report = $report->timeWorked($data['account'], $data['year']);
  101. $account = new userModel();
  102. $this->view->account = $account->userInfo($data['account']);
  103. $this->view->year = $data['year'];
  104. } else {
  105. $this->view->form = $form;
  106. }
  107. } else {
  108. $this->view->form = $form;
  109. }
  110. }
  111. public function unlock()
  112. {
  113. $auth = Staple_Auth::get();
  114. $this->authLevel = $auth->getAuthLevel();
  115. if ($this->authLevel < 900)
  116. {
  117. header("location:" . $this->_link(array('index', 'index')) . "");
  118. }
  119. else
  120. {
  121. $date = new DateTime();
  122. if($date->format('d') >= 26)
  123. {
  124. $date->modify('+1 month');
  125. }
  126. $timesheets = new reportModel($date->format('Y'), $date->format('m'));
  127. $this->view->accounts = $timesheets;
  128. $this->view->dateTitle = $date->format('F')." ".$date->format('Y');
  129. }
  130. }
  131. public function unlockid($id)
  132. {
  133. $auth = Staple_Auth::get();
  134. $this->authLevel = $auth->getAuthLevel();
  135. if ($this->authLevel < 900)
  136. {
  137. header("location:" . $this->_link(array('index', 'index')) . "");
  138. }
  139. else
  140. {
  141. $unlock = new unlockModel();
  142. if ($unlock->unlock($id))
  143. {
  144. $this->view->message = "<i class='fa fa-check'></i> Time entry unlocked.";
  145. }
  146. else
  147. {
  148. $this->view->message = "<i class='fa fa-close'></i> ERROR: Unable to unlock your own time entries.";
  149. }
  150. }
  151. }
  152. public function printpreview($year,$month,$uid)
  153. {
  154. $this->_setLayout('print');
  155. $user = new userModel();
  156. $account = $user->userInfo($uid);
  157. $this->view->firstName = $account['firstName'];
  158. $this->view->lastName = $account['lastName'];
  159. $this->view->batchId = $account['batchId'];
  160. $this->view->year = $year;
  161. $this->view->month = date('F',$month);
  162. $timesheet = new timesheetModel($year, $month,$uid);
  163. $this->view->timesheet = $timesheet;
  164. }
  165. public function payperiod($year = null, $month = null)
  166. {
  167. if ($year == null) {
  168. $year = date('Y');
  169. }
  170. if ($month == null) {
  171. $month = date('m');
  172. }
  173. $date = new DateTime();
  174. $date->setDate($year,$month,26);
  175. $date->setTime(0,0,0);
  176. $year = $date->format('Y');
  177. $this->view->year = $year;
  178. $nextYear = $date->modify('+1 year')->format('Y');
  179. $this->view->nextYear = $nextYear;
  180. $previousYear = $date->modify('-2 year')->format('Y');
  181. $this->view->previousYear = $previousYear;
  182. $month = $date->format('m');
  183. $this->view->month = $month;
  184. $nextMonth = $date->modify('+1 month')->format('m');
  185. $this->view->nextMonth = $nextMonth;
  186. $previousMonth = $date->modify('-2 month')->format('m');
  187. $this->view->previousMonth = $previousMonth;
  188. $date->setDate($year,$month,26);
  189. $date->setTime(0,0,0);
  190. $newDate = new DateTime();
  191. switch($month)
  192. {
  193. case 1:
  194. $newDate->setDate($previousYear,$previousMonth,26);
  195. break;
  196. default:
  197. $newDate->setDate($year,$previousMonth,26);
  198. }
  199. $newDate->setTime(0,0,0);
  200. $date2 = new DateTime();
  201. $date2->setDate($year,$month,25);
  202. $date2->setTime(24,00,00);
  203. $interval = date_diff($newDate,$date2);
  204. $span = $interval->days;
  205. $this->view->span = $span;
  206. $this->view->date = $date->format("F Y");
  207. $reports = new reportModel($year, $month);
  208. $this->view->report = $reports->payPeriodTotals($year, $month);
  209. }
  210. public function payperiodprint($year, $month)
  211. {
  212. if($year != null || $month != null)
  213. {
  214. $this->_setLayout('print');
  215. $this->view->year = $year;
  216. $date = new DateTime();
  217. $date->setDate($year,$month,26);
  218. $date->setTime(0,0,0);
  219. $this->view->month = $date->format('m');
  220. $date->modify('-1 month');
  221. $this->view->previousMonth = $date->format('m');
  222. $date2 = new DateTime();
  223. $date2->setDate($year,$month,25);
  224. $date2->setTime(24,0,0);
  225. $interval = date_diff($date,$date2);
  226. $this->view->span = $interval->days;
  227. $reports = new reportModel($year, $month);
  228. $this->view->report = $reports->payPeriodTotals($year, $month);
  229. $this->view->startDate = $date->format("F jS Y");
  230. $days = $interval->days - 1;
  231. $date->modify("+$days days");
  232. $this->view->endDate = $date->format("F jS Y");
  233. }
  234. else
  235. {
  236. header("location:".$this->_link(array('reports','payperiod'))."");
  237. }
  238. }
  239. public function payroll($year = null, $month = null)
  240. {
  241. if($year == null)
  242. {
  243. $year = date('Y');
  244. }
  245. if($month == null)
  246. {
  247. $month = date('m');
  248. }
  249. $this->view->year = $year;
  250. $date = new DateTime();
  251. $date->setDate($year,$month,26);
  252. $date->setTime(0,0,0);
  253. $this->view->date = $date->format("F Y");
  254. $date->modify('+1 year');
  255. $this->view->nextYear = $date->format('Y');
  256. $date->modify('-2 year');
  257. $this->view->previousYear = $date->format('Y');
  258. $this->view->month = $date->format('m');
  259. $date->modify('-1 month');
  260. $this->view->previousMonth = $date->format('m');
  261. $date->modify('+2 month');
  262. $this->view->nextMonth = $date->format('m');
  263. $date2 = new DateTime();
  264. $date2->setDate($year,$month,25);
  265. $date2->setTime(24,0,0);
  266. $interval = date_diff($date,$date2);
  267. $this->view->span = $interval->days;
  268. $reports = new reportModel($year, $month);
  269. $this->view->report = $reports->payroll($year, $month);
  270. $this->view->startDate = $date->format("F jS Y");
  271. $days = $interval->days - 1;
  272. $date->modify("+$days days");
  273. $this->view->endDate = $date->format("F jS Y");
  274. $codes = new codeModel();
  275. $this->view->codes = $codes->allCodes();
  276. }
  277. public function payrollprint($year = null, $month = null)
  278. {
  279. if($year != null || $month != null) {
  280. $this->_setLayout('print');
  281. if ($year == null) {
  282. $year = date('Y');
  283. }
  284. if ($month == null) {
  285. $month = date('m');
  286. }
  287. $this->view->year = $year;
  288. $date = new DateTime();
  289. $date->setDate($year, $month, 26);
  290. $date->setTime(0, 0, 0);
  291. $this->view->month = $date->format('m');
  292. $date->modify('-1 month');
  293. $this->view->previousMonth = $date->format('m');
  294. $date2 = new DateTime();
  295. $date2->setDate($year, $month, 25);
  296. $date2->setTime(24, 0, 0);
  297. $interval = date_diff($date, $date2);
  298. $this->view->span = $interval->days;
  299. $reports = new reportModel($year, $month);
  300. $this->view->report = $reports->payroll($year, $month);
  301. $this->view->startDate = $date->format("F jS Y");
  302. $days = $interval->days - 1;
  303. $date->modify("+$days days");
  304. $this->view->endDate = $date->format("F jS Y");
  305. $codes = new codeModel();
  306. $this->view->codes = $codes->allCodes();
  307. }
  308. else
  309. {
  310. header("location:".$this->_link(array('reports','payroll'))."");
  311. }
  312. }
  313. public function inactive($year = null, $month = null)
  314. {
  315. if ($year == null) {
  316. $year = date('Y');
  317. }
  318. if ($month == null) {
  319. $month = date('m');
  320. }
  321. $date = new DateTime();
  322. $date->setDate($year,$month,26);
  323. $date->setTime(0,0,0);
  324. $this->view->year = $date->format('Y');
  325. $this->view->date = $date->format("F Y");
  326. $date->modify('+1 year');
  327. $this->view->nextYear = $date->format('Y');
  328. $date->modify('-2 year');
  329. $this->view->previousYear = $date->format('Y');
  330. $date->modify('+1 year');
  331. $month = $date->format('m');
  332. $this->view->month = $month;
  333. $date->modify('-1 month');
  334. $this->view->previousMonth = $date->format('m');
  335. $date->modify('+2 month');
  336. $this->view->nextMonth = $date->format('m');
  337. $report = new reportModel($year, $month,1);
  338. $this->view->report = $report->getTimesheets();
  339. $this->view->accountLevel = $this->authLevel;
  340. $date = new DateTime();
  341. $date->setDate($year, $month, 1);
  342. $this->view->monthName = $date->format('F');
  343. $printInactiveTimeSheetForm = new printInactiveTimeSheetForm();
  344. $printInactiveTimeSheetForm->setAction($this->_link(array("reports","inactive",$year,$month)));
  345. if($printInactiveTimeSheetForm->wasSubmitted())
  346. {
  347. $printInactiveTimeSheetForm->addData($_POST);
  348. if($printInactiveTimeSheetForm->validate())
  349. {
  350. $data = $printInactiveTimeSheetForm->exportFormData();
  351. $this->layout->addScriptBlock("
  352. window.open('".$this->_link(array("reports","printpreview",$year,$month,$data['account']))."');
  353. ");
  354. $this->view->printTimeSheetForm = $printInactiveTimeSheetForm;
  355. }
  356. else
  357. {
  358. $this->view->printTimeSheetForm = $printInactiveTimeSheetForm;
  359. }
  360. }
  361. else
  362. {
  363. $this->view->printTimeSheetForm = $printInactiveTimeSheetForm;
  364. }
  365. }
  366. }