reportsController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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. $printTimeSheetForm = new printTimeSheetForm();
  48. $printTimeSheetForm->setAction($this->_link(array("reports",$year,$month)));
  49. if($printTimeSheetForm->wasSubmitted())
  50. {
  51. $printTimeSheetForm->addData($_POST);
  52. if($printTimeSheetForm->validate())
  53. {
  54. $data = $printTimeSheetForm->exportFormData();
  55. $this->layout->addScriptBlock("
  56. window.open('".$this->_link(array("reports","printpreview",$year,$month,$data['account']))."');
  57. ");
  58. $this->view->printTimeSheetForm = $printTimeSheetForm;
  59. }
  60. else
  61. {
  62. $this->view->printTimeSheetForm = $printTimeSheetForm;
  63. }
  64. }
  65. else
  66. {
  67. $this->view->printTimeSheetForm = $printTimeSheetForm;
  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. $year = date('Y');
  122. $month = date('m');
  123. $timesheets = new reportModel($year, $month);
  124. $this->view->accounts = $timesheets;
  125. }
  126. }
  127. public function unlockid($id)
  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. $unlock = new unlockModel();
  138. if ($unlock->unlock($id))
  139. {
  140. $this->view->message = "<i class='fa fa-check'></i> Time entry unlocked.";
  141. }
  142. else
  143. {
  144. $this->view->message = "<i class='fa fa-close'></i> ERROR: Unable to unlock your own time entries.";
  145. }
  146. }
  147. }
  148. public function printpreview($year,$month,$uid)
  149. {
  150. $this->_setLayout('print');
  151. $user = new userModel();
  152. $account = $user->userInfo($uid);
  153. $this->view->firstName = $account['firstName'];
  154. $this->view->lastName = $account['lastName'];
  155. $this->view->batchId = $account['batchId'];
  156. $this->view->year = $year;
  157. $this->view->month = date('F',$month);
  158. $timesheet = new timesheetModel($year, $month,$uid);
  159. $this->view->timesheet = $timesheet;
  160. }
  161. public function payperiod($year = null, $month = null)
  162. {
  163. if ($year == null) {
  164. $year = date('Y');
  165. }
  166. if ($month == null) {
  167. $month = date('m');
  168. }
  169. $date = new DateTime();
  170. $date->setDate($year,$month,26);
  171. $date->setTime(0,0,0);
  172. $year = $date->format('Y');
  173. $this->view->year = $year;
  174. $nextYear = $date->modify('+1 year')->format('Y');
  175. $this->view->nextYear = $nextYear;
  176. $previousYear = $date->modify('-2 year')->format('Y');
  177. $this->view->previousYear = $previousYear;
  178. $month = $date->format('m');
  179. $this->view->month = $month;
  180. $nextMonth = $date->modify('+1 month')->format('m');
  181. $this->view->nextMonth = $nextMonth;
  182. $previousMonth = $date->modify('-2 month')->format('m');
  183. $this->view->previousMonth = $previousMonth;
  184. $date->setDate($year,$month,26);
  185. $date->setTime(0,0,0);
  186. $newDate = new DateTime();
  187. switch($month)
  188. {
  189. case 1:
  190. $newDate->setDate($previousYear,$previousMonth,26);
  191. break;
  192. default:
  193. $newDate->setDate($year,$previousMonth,26);
  194. }
  195. $newDate->setTime(0,0,0);
  196. $date2 = new DateTime();
  197. $date2->setDate($year,$month,25);
  198. $date2->setTime(24,00,00);
  199. $interval = date_diff($newDate,$date2);
  200. $span = $interval->days;
  201. $this->view->span = $span;
  202. $this->view->date = $date->format("F Y");
  203. $reports = new reportModel($year, $month);
  204. $this->view->report = $reports->payPeriodTotals($year, $month);
  205. }
  206. public function payperiodprint($year, $month)
  207. {
  208. if($year != null || $month != null)
  209. {
  210. $this->_setLayout('print');
  211. $this->view->year = $year;
  212. $date = new DateTime();
  213. $date->setDate($year,$month,26);
  214. $date->setTime(0,0,0);
  215. $this->view->month = $date->format('m');
  216. $date->modify('-1 month');
  217. $this->view->previousMonth = $date->format('m');
  218. $date2 = new DateTime();
  219. $date2->setDate($year,$month,25);
  220. $date2->setTime(24,0,0);
  221. $interval = date_diff($date,$date2);
  222. $this->view->span = $interval->days;
  223. $reports = new reportModel($year, $month);
  224. $this->view->report = $reports->payPeriodTotals($year, $month);
  225. $this->view->startDate = $date->format("F jS Y");
  226. $days = $interval->days - 1;
  227. $date->modify("+$days days");
  228. $this->view->endDate = $date->format("F jS Y");
  229. }
  230. else
  231. {
  232. header("location:".$this->_link(array('reports','payperiod'))."");
  233. }
  234. }
  235. public function payroll($year = null, $month = null)
  236. {
  237. if($year == null)
  238. {
  239. $year = date('Y');
  240. }
  241. if($month == null)
  242. {
  243. $month = date('m');
  244. }
  245. $this->view->year = $year;
  246. $date = new DateTime();
  247. $date->setDate($year,$month,26);
  248. $date->setTime(0,0,0);
  249. $this->view->date = $date->format("F Y");
  250. $date->modify('+1 year');
  251. $this->view->nextYear = $date->format('Y');
  252. $date->modify('-2 year');
  253. $this->view->previousYear = $date->format('Y');
  254. $this->view->month = $date->format('m');
  255. $date->modify('-1 month');
  256. $this->view->previousMonth = $date->format('m');
  257. $date->modify('+2 month');
  258. $this->view->nextMonth = $date->format('m');
  259. $date2 = new DateTime();
  260. $date2->setDate($year,$month,25);
  261. $date2->setTime(24,0,0);
  262. $interval = date_diff($date,$date2);
  263. $this->view->span = $interval->days;
  264. $reports = new reportModel($year, $month);
  265. $this->view->report = $reports->payroll($year, $month);
  266. $this->view->startDate = $date->format("F jS Y");
  267. $days = $interval->days - 1;
  268. $date->modify("+$days days");
  269. $this->view->endDate = $date->format("F jS Y");
  270. $codes = new codeModel();
  271. $this->view->codes = $codes->allCodes();
  272. }
  273. public function payrollprint($year = null, $month = null)
  274. {
  275. if($year != null || $month != null) {
  276. $this->_setLayout('print');
  277. if ($year == null) {
  278. $year = date('Y');
  279. }
  280. if ($month == null) {
  281. $month = date('m');
  282. }
  283. $this->view->year = $year;
  284. $date = new DateTime();
  285. $date->setDate($year, $month, 26);
  286. $date->setTime(0, 0, 0);
  287. $this->view->month = $date->format('m');
  288. $date->modify('-1 month');
  289. $this->view->previousMonth = $date->format('m');
  290. $date2 = new DateTime();
  291. $date2->setDate($year, $month, 25);
  292. $date2->setTime(24, 0, 0);
  293. $interval = date_diff($date, $date2);
  294. $this->view->span = $interval->days;
  295. $reports = new reportModel($year, $month);
  296. $this->view->report = $reports->payroll($year, $month);
  297. $this->view->startDate = $date->format("F jS Y");
  298. $days = $interval->days - 1;
  299. $date->modify("+$days days");
  300. $this->view->endDate = $date->format("F jS Y");
  301. $codes = new codeModel();
  302. $this->view->codes = $codes->allCodes();
  303. }
  304. else
  305. {
  306. header("location:".$this->_link(array('reports','payroll'))."");
  307. }
  308. }
  309. }