Example #1
0
 /**
  * Auto create a report for a given month
  * 
  */
 public function monthreportAction()
 {
     $user = $this->userService->getUserByField('username', $this->_getParam('username'));
     $client = $this->clientService->getClient($this->_getParam('clientid'));
     if ($user == null && $client == null) {
         throw new Exception("User or client not found");
     }
     $startDate = date('Y-m-01', strtotime($this->_getParam('month')));
     $endDate = date('Y-m-d', strtotime('-1 second', strtotime('+1 month', strtotime(date('Y-m-01 00:00:00', strtotime($this->_getParam('month')))))));
     $report = new ExpenseReport();
     $titleName = $user != null ? $user->username : $client->title;
     $report->title = "Expenses for {$titleName} for " . date('F Y', strtotime($startDate));
     $report->from = $startDate;
     $report->to = $endDate;
     if ($user) {
         $report->username = $user->username;
     }
     if ($client) {
         $report->clientid = $client->id;
     }
     $report = $this->expenseService->saveReport($report);
     //         $this->expenseService->lockExpenseReport($report);
     if ($user) {
         $this->redirect('expense', 'listforuser', array('username' => $user->username));
     } else {
         $this->redirect('client', 'view', array('id' => $client->id, '#expenses'));
     }
 }