reportsController.php 14 KB

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