reportsController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. $report = new reportModel($year, $month);
  26. $this->view->report = $report->getTimesheets();
  27. $timesheet = new timesheetModel($year, $month);
  28. $this->view->nextMonth = $timesheet->getNextMonth();
  29. $this->view->previousMonth = $timesheet->getPreviousMonth();
  30. $this->view->year = $timesheet->getCurrentYear();
  31. $yearForm = new changeYearForm();
  32. $yearForm->setAction($this->_link(array('reports','changeyear')));
  33. $this->view->yearForm = $yearForm;
  34. $this->view->accountLevel = $this->authLevel;
  35. $date = new DateTime();
  36. $date->setDate($year, $month, 1);
  37. $this->view->month = $date->format('F');
  38. $printTimeSheetForm = new printTimeSheetForm();
  39. if($printTimeSheetForm->wasSubmitted())
  40. {
  41. $printTimeSheetForm->addData($_POST);
  42. if($printTimeSheetForm->validate())
  43. {
  44. $data = $printTimeSheetForm->exportFormData();
  45. $this->layout->addScriptBlock("
  46. window.open('".$this->_link(array("reports","printpreview",$year,$month,$data['account']))."');
  47. ");
  48. $this->view->printTimeSheetForm = $printTimeSheetForm;
  49. }
  50. else
  51. {
  52. $this->view->printTimeSheetForm = $printTimeSheetForm;
  53. }
  54. }
  55. else
  56. {
  57. $this->view->printTimeSheetForm = $printTimeSheetForm;
  58. }
  59. }
  60. public function changeyear()
  61. {
  62. $form = new changeYearForm();
  63. if($form->wasSubmitted())
  64. {
  65. $form->addData($_POST);
  66. if($form->validate())
  67. {
  68. $data = $form->exportFormData();
  69. header("location: ".$this->_link(array('reports',$data['year']))."");
  70. }
  71. else
  72. {
  73. header("location: ".$this->_link(array('reports'))."");
  74. }
  75. }
  76. else
  77. {
  78. header("location: ".$this->_link(array('reports'))."");
  79. }
  80. }
  81. public function weekly()
  82. {
  83. //Weekly report form
  84. $form = new weeklyReportForm();
  85. if ($form->wasSubmitted()) {
  86. $form->addData($_POST);
  87. if ($form->validate()) {
  88. $data = $form->exportFormData();
  89. $report = new weeklyReportModel();
  90. $this->view->report = $report->timeWorked($data['account'], $data['year']);
  91. $account = new userModel();
  92. $this->view->account = $account->userInfo($data['account']);
  93. $this->view->year = $data['year'];
  94. } else {
  95. $this->view->form = $form;
  96. }
  97. } else {
  98. $this->view->form = $form;
  99. }
  100. }
  101. public function unlock()
  102. {
  103. $auth = Staple_Auth::get();
  104. $this->authLevel = $auth->getAuthLevel();
  105. if ($this->authLevel < 900)
  106. {
  107. header("location:" . $this->_link(array('index', 'index')) . "");
  108. }
  109. else
  110. {
  111. $year = date('Y');
  112. $month = date('m');
  113. $timesheets = new reportModel($year, $month);
  114. $this->view->accounts = $timesheets;
  115. }
  116. }
  117. public function unlockid($id)
  118. {
  119. $auth = Staple_Auth::get();
  120. $this->authLevel = $auth->getAuthLevel();
  121. if ($this->authLevel < 900)
  122. {
  123. header("location:" . $this->_link(array('index', 'index')) . "");
  124. }
  125. else
  126. {
  127. $unlock = new unlockModel();
  128. if ($unlock->unlock($id))
  129. {
  130. $this->view->message = "<i class='fa fa-check'></i> Time entry unlocked.";
  131. }
  132. else
  133. {
  134. $this->view->message = "<i class='fa fa-close'></i> ERROR: Unable to unlock your own time entries.";
  135. }
  136. }
  137. }
  138. public function printpreview($year,$month,$uid)
  139. {
  140. $this->_setLayout('print');
  141. $user = new userModel();
  142. $account = $user->userInfo($uid);
  143. $this->view->firstName = $account['firstName'];
  144. $this->view->lastName = $account['lastName'];
  145. $this->view->batchId = $account['batchId'];
  146. $this->view->year = $year;
  147. $this->view->month = date('F',$month);
  148. $timesheet = new timesheetModel($year, $month,$uid);
  149. $this->view->timesheet = $timesheet;
  150. }
  151. public function payperiod($year = null, $month = null)
  152. {
  153. if ($year == null) {
  154. $year = date('Y');
  155. }
  156. if ($month == null) {
  157. $month = date('m');
  158. }
  159. $this->view->year = $year;
  160. $date = new DateTime();
  161. $date->setDate($year,$month,26);
  162. $date->setTime(0,0,0);
  163. $this->view->date = $date->format("F Y");
  164. $date->modify('+1 year');
  165. $this->view->nextYear = $date->format('Y');
  166. $date->modify('-2 year');
  167. $this->view->previousYear = $date->format('Y');
  168. $this->view->month = $date->format('m');
  169. $date->modify('-1 month');
  170. $this->view->previousMonth = $date->format('m');
  171. $date->modify('+2 month');
  172. $this->view->nextMonth = $date->format('m');
  173. $date2 = new DateTime();
  174. $date2->setDate($year,$month,25);
  175. $date2->setTime(24,0,0);
  176. $interval = date_diff($date,$date2);
  177. $this->view->span = $interval->days;
  178. $reports = new reportModel($year, $month);
  179. $this->view->report = $reports->payPeriodTotals($year, $month);
  180. }
  181. public function payperiodprint($year, $month)
  182. {
  183. if($year != null || $month != null)
  184. {
  185. $this->_setLayout('print');
  186. $this->view->year = $year;
  187. $date = new DateTime();
  188. $date->setDate($year,$month,26);
  189. $date->setTime(0,0,0);
  190. $this->view->month = $date->format('m');
  191. $date->modify('-1 month');
  192. $this->view->previousMonth = $date->format('m');
  193. $date2 = new DateTime();
  194. $date2->setDate($year,$month,25);
  195. $date2->setTime(24,0,0);
  196. $interval = date_diff($date,$date2);
  197. $this->view->span = $interval->days;
  198. $reports = new reportModel($year, $month);
  199. $this->view->report = $reports->payPeriodTotals($year, $month);
  200. $this->view->startDate = $date->format("F jS Y");
  201. $days = $interval->days - 1;
  202. $date->modify("+$days days");
  203. $this->view->endDate = $date->format("F jS Y");
  204. }
  205. else
  206. {
  207. header("location:".$this->_link(array('reports','payperiod'))."");
  208. }
  209. }
  210. public function payroll($year = null, $month = null)
  211. {
  212. if($year == null)
  213. {
  214. $year = date('Y');
  215. }
  216. if($month == null)
  217. {
  218. $month = date('m');
  219. }
  220. $this->view->year = $year;
  221. $date = new DateTime();
  222. $date->setDate($year,$month,26);
  223. $date->setTime(0,0,0);
  224. $this->view->date = $date->format("F Y");
  225. $date->modify('+1 year');
  226. $this->view->nextYear = $date->format('Y');
  227. $date->modify('-2 year');
  228. $this->view->previousYear = $date->format('Y');
  229. $this->view->month = $date->format('m');
  230. $date->modify('-1 month');
  231. $this->view->previousMonth = $date->format('m');
  232. $date->modify('+2 month');
  233. $this->view->nextMonth = $date->format('m');
  234. $date2 = new DateTime();
  235. $date2->setDate($year,$month,25);
  236. $date2->setTime(24,0,0);
  237. $interval = date_diff($date,$date2);
  238. $this->view->span = $interval->days;
  239. $reports = new reportModel($year, $month);
  240. $this->view->report = $reports->payroll($year, $month);
  241. $this->view->startDate = $date->format("F jS Y");
  242. $days = $interval->days - 1;
  243. $date->modify("+$days days");
  244. $this->view->endDate = $date->format("F jS Y");
  245. $codes = new codeModel();
  246. $this->view->codes = $codes->allCodes();
  247. }
  248. public function payrollprint($year = null, $month = null)
  249. {
  250. if($year != null || $month != null) {
  251. $this->_setLayout('print');
  252. if ($year == null) {
  253. $year = date('Y');
  254. }
  255. if ($month == null) {
  256. $month = date('m');
  257. }
  258. $this->view->year = $year;
  259. $date = new DateTime();
  260. $date->setDate($year, $month, 26);
  261. $date->setTime(0, 0, 0);
  262. $this->view->month = $date->format('m');
  263. $date->modify('-1 month');
  264. $this->view->previousMonth = $date->format('m');
  265. $date2 = new DateTime();
  266. $date2->setDate($year, $month, 25);
  267. $date2->setTime(24, 0, 0);
  268. $interval = date_diff($date, $date2);
  269. $this->view->span = $interval->days;
  270. $reports = new reportModel($year, $month);
  271. $this->view->report = $reports->payroll($year, $month);
  272. $this->view->startDate = $date->format("F jS Y");
  273. $days = $interval->days - 1;
  274. $date->modify("+$days days");
  275. $this->view->endDate = $date->format("F jS Y");
  276. $codes = new codeModel();
  277. $this->view->codes = $codes->allCodes();
  278. }
  279. else
  280. {
  281. header("location:".$this->_link(array('reports','payroll'))."");
  282. }
  283. }
  284. }