123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- <?php
- class reportsController extends Staple_Controller
- {
- private $authLevel;
- private $uid;
- public function _start()
- {
- $this->_setLayout('main');
- $auth = Staple_Auth::get();
- $this->authLevel = $auth->getAuthLevel();
- $user = new userModel();
- $this->uid = $user->getId();
- if ($this->authLevel < 500) {
- header("location:" . $this->_link(array('index', 'index')) . "");
- }
- }
- public function index($year = null, $month = null)
- {
- if ($year == null) {
- $year = date('Y');
- }
- if ($month == null) {
- $month = date('m');
- }
- $report = new reportModel($year, $month);
- $this->view->report = $report->getTimesheets();
- $timesheet = new timesheetModel($year, $month);
- $this->view->nextMonth = $timesheet->getNextMonth();
- $this->view->previousMonth = $timesheet->getPreviousMonth();
- $this->view->year = $timesheet->getCurrentYear();
- $yearForm = new changeYearForm();
- $yearForm->setAction($this->_link(array('reports','changeyear')));
- $this->view->yearForm = $yearForm;
- $this->view->accountLevel = $this->authLevel;
- $date = new DateTime();
- $date->setDate($year, $month, 1);
- $this->view->month = $date->format('F');
- $printTimeSheetForm = new printTimeSheetForm();
- if($printTimeSheetForm->wasSubmitted())
- {
- $printTimeSheetForm->addData($_POST);
- if($printTimeSheetForm->validate())
- {
- $data = $printTimeSheetForm->exportFormData();
- $this->layout->addScriptBlock("
- window.open('".$this->_link(array("reports","printpreview",$year,$month,$data['account']))."');
- ");
- $this->view->printTimeSheetForm = $printTimeSheetForm;
- }
- else
- {
- $this->view->printTimeSheetForm = $printTimeSheetForm;
- }
- }
- else
- {
- $this->view->printTimeSheetForm = $printTimeSheetForm;
- }
- }
- public function changeyear()
- {
- $form = new changeYearForm();
- if($form->wasSubmitted())
- {
- $form->addData($_POST);
- if($form->validate())
- {
- $data = $form->exportFormData();
- header("location: ".$this->_link(array('reports',$data['year']))."");
- }
- else
- {
- header("location: ".$this->_link(array('reports'))."");
- }
- }
- else
- {
- header("location: ".$this->_link(array('reports'))."");
- }
- }
- public function weekly()
- {
- //Weekly report form
- $form = new weeklyReportForm();
- if ($form->wasSubmitted()) {
- $form->addData($_POST);
- if ($form->validate()) {
- $data = $form->exportFormData();
- $report = new weeklyReportModel();
- $this->view->report = $report->timeWorked($data['account'], $data['year']);
- $account = new userModel();
- $this->view->account = $account->userInfo($data['account']);
- $this->view->year = $data['year'];
- } else {
- $this->view->form = $form;
- }
- } else {
- $this->view->form = $form;
- }
- }
- public function unlock()
- {
- $auth = Staple_Auth::get();
- $this->authLevel = $auth->getAuthLevel();
- if ($this->authLevel < 900)
- {
- header("location:" . $this->_link(array('index', 'index')) . "");
- }
- else
- {
- $year = date('Y');
- $month = date('m');
- $timesheets = new reportModel($year, $month);
- $this->view->accounts = $timesheets;
- }
- }
- public function unlockid($id)
- {
- $auth = Staple_Auth::get();
- $this->authLevel = $auth->getAuthLevel();
- if ($this->authLevel < 900)
- {
- header("location:" . $this->_link(array('index', 'index')) . "");
- }
- else
- {
- $unlock = new unlockModel();
- if ($unlock->unlock($id))
- {
- $this->view->message = "<i class='fa fa-check'></i> Time entry unlocked.";
- }
- else
- {
- $this->view->message = "<i class='fa fa-close'></i> ERROR: Unable to unlock your own time entries.";
- }
- }
- }
- public function printpreview($year,$month,$uid)
- {
- $this->_setLayout('print');
- $user = new userModel();
- $account = $user->userInfo($uid);
- $this->view->firstName = $account['firstName'];
- $this->view->lastName = $account['lastName'];
- $this->view->batchId = $account['batchId'];
- $this->view->year = $year;
- $this->view->month = date('F',$month);
- $timesheet = new timesheetModel($year, $month,$uid);
- $this->view->timesheet = $timesheet;
- }
- public function payperiod($year = null, $month = null)
- {
- if ($year == null) {
- $year = date('Y');
- }
- if ($month == null) {
- $month = date('m');
- }
- $this->view->year = $year;
- $date = new DateTime();
- $date->setDate($year,$month,26);
- $date->setTime(0,0,0);
- $this->view->month = $date->format('m');
- $date->modify('-1 month');
- $this->view->previousMonth = $date->format('m');
- $date2 = new DateTime();
- $date2->setDate($year,$month,25);
- $date2->setTime(24,0,0);
- $interval = date_diff($date,$date2);
- $this->view->span = $interval->days;
- $reports = new reportModel($year, $month);
- $this->view->report = $reports->payPeriodTotals($year, $month);
- }
- public function payperiodprint($year, $month)
- {
- if($year != null || $month != null)
- {
- $this->_setLayout('print');
- $this->view->year = $year;
- $date = new DateTime();
- $date->setDate($year,$month,26);
- $date->setTime(0,0,0);
- $this->view->month = $date->format('m');
- $date->modify('-1 month');
- $this->view->previousMonth = $date->format('m');
- $date2 = new DateTime();
- $date2->setDate($year,$month,25);
- $date2->setTime(24,0,0);
- $interval = date_diff($date,$date2);
- $this->view->span = $interval->days;
- $reports = new reportModel($year, $month);
- $this->view->report = $reports->payPeriodTotals($year, $month);
- $this->view->startDate = $date->format("F jS Y");
- $days = $interval->days - 1;
- $date->modify("+$days days");
- $this->view->endDate = $date->format("F jS Y");
- }
- else
- {
- header("location:".$this->_link(array('reports','payperiod'))."");
- }
- }
- public function payroll($year = null, $month = null)
- {
- if($year == null)
- {
- $year = date('Y');
- }
- if($month == null)
- {
- $month = date('m');
- }
- $this->view->year = $year;
- $date = new DateTime();
- $date->setDate($year,$month,26);
- $date->setTime(0,0,0);
- $this->view->month = $date->format('m');
- $date->modify('-1 month');
- $this->view->previousMonth = $date->format('m');
- $date2 = new DateTime();
- $date2->setDate($year,$month,25);
- $date2->setTime(24,0,0);
- $interval = date_diff($date,$date2);
- $this->view->span = $interval->days;
- $reports = new reportModel($year, $month);
- $this->view->report = $reports->payroll($year, $month);
- $this->view->startDate = $date->format("F jS Y");
- $days = $interval->days - 1;
- $date->modify("+$days days");
- $this->view->endDate = $date->format("F jS Y");
- $codes = new codeModel();
- $this->view->codes = $codes->allCodes();
- }
- public function payrollprint($year = null, $month = null)
- {
- if($year != null || $month != null) {
- $this->_setLayout('print');
- if ($year == null) {
- $year = date('Y');
- }
- if ($month == null) {
- $month = date('m');
- }
- $this->view->year = $year;
- $date = new DateTime();
- $date->setDate($year, $month, 26);
- $date->setTime(0, 0, 0);
- $this->view->month = $date->format('m');
- $date->modify('-1 month');
- $this->view->previousMonth = $date->format('m');
- $date2 = new DateTime();
- $date2->setDate($year, $month, 25);
- $date2->setTime(24, 0, 0);
- $interval = date_diff($date, $date2);
- $this->view->span = $interval->days;
- $reports = new reportModel($year, $month);
- $this->view->report = $reports->payroll($year, $month);
- $this->view->startDate = $date->format("F jS Y");
- $days = $interval->days - 1;
- $date->modify("+$days days");
- $this->view->endDate = $date->format("F jS Y");
- $codes = new codeModel();
- $this->view->codes = $codes->allCodes();
- }
- else
- {
- header("location:".$this->_link(array('reports','payroll'))."");
- }
- }
- }
|