public function messages() { $reportId = $this->route('reportId'); if ($reportId == null) { $expenseId = $this->route('expenseId'); $reportId = Expense::find($expenseId)->report_id; } $report = ExpenseReport::find($reportId); $messages = ['title.required' => "Title is required", 'date.after' => "Expense date should be on or after report start date (" . date('d M Y', strtotime($report->startDate)) . ")", $report->owner_id . '.numeric' => 'Contributions should be numeric', $report->owner_id . '.min' => 'Contributions cannot be negative', $report->owner_id . 'p.numeric' => 'Participation Ratios should be numeric', $report->owner_id . 'p.min' => 'Participation Ratios cannot be negative']; $amount = 0; $participationRatios = 0; $input = $this->all(); foreach ($report->users as $user) { $amount += $input[$user->id]; $participationRatios += $input[$user->id . 'p']; $messages[$user->id . '.numeric'] = 'Contributions should be numeric'; $messages[$user->id . '.min'] = 'Contributions cannot be negative'; $messages[$user->id . 'p.numeric'] = 'Participation Ratios should be numeric'; $messages[$user->id . 'p.min'] = 'Participation Ratios cannot be negative'; } if ($amount == 0) { $messages[$report->owner_id . '.min'] = 'Sum of Contributions cannot be 0'; $messages[$report->owner_id . '.required'] = 'Sum of Contributions cannot be 0'; } if ($participationRatios == 0) { $messages[$report->owner_id . 'p.min'] = 'Sum of Participation Ratios cannot be 0'; $messages[$report->owner_id . 'p.required'] = 'Sum of Participation Ratios cannot be 0'; } return $messages; }
/** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { $reportId = $this->route('id'); $report = ExpenseReport::find($reportId); if ($report->owner_id == \Auth::user()->id) { return true; } return false; }
/** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { $expenses = $this->input('expense_ids'); if ($expenses != null && count($expenses) > 0) { $reportId = Expense::find($expenses[0])->report_id; $report = ExpenseReport::find($reportId); if ($report->status) { return false; } } return true; }
public function storeExpense($reportId, AddExpenseRequest $request) { $report = ExpenseReport::find($reportId); $input = $request->all(); $input['report_id'] = $reportId; $input['owner_id'] = \Auth::user()->id; $input['amount'] = 0; $input['usage_total'] = 0; $expense = Expense::create($input); $this->modifyAndSaveExpense($expense, $report, $input); session()->flash('message', 'Expense (' . $expense->title . ') added!'); return redirect('expenseReports/' . $reportId); }
public function show($reportId) { $authenticatedUser = \Auth::user(); $selectStmtAuthUser = "******"; $selectStmtOtherUsers = "select s.amount, s.owee_id, s.owed_id, owee.name as oweeName, owed.name as owedName from settlements s, users owee, users owed where s.owee_id=owee.id and s.owed_id=owed.id and s.report_id = ? and (s.owee_id != ? and s.owed_id != ?) order by owee.name, owed.name"; $authUserSettlements = DB::select($selectStmtAuthUser, [$reportId, $authenticatedUser->id, $authenticatedUser->id]); $otherUserSettlements = DB::select($selectStmtOtherUsers, [$reportId, $authenticatedUser->id, $authenticatedUser->id]); //If report has only been closed and the settlements have not been determined $report = ExpenseReport::find($reportId); if ($report->status == 1) { if (\Auth::user()->id != $report->owner_id) { $messageHeader = 'Settlements for: ' . $report->title; $messageBody = 'Settlements for this report have not been determined yet.'; return view('utilities.displayMessage', compact(['messageHeader', 'messageBody', 'report'])); } return redirect('expenseReports/' . $reportId . '/close'); } $report = ExpenseReport::find($reportId); $isArchived = $report->isArchivedForUser(\Auth::user()->id); return view('settlements.reportSettlements', compact('authUserSettlements', 'otherUserSettlements', 'report', 'authenticatedUser', 'isArchived')); }
public function deleteReports(DeleteReportRequest $request, AppMailer $mailer) { $input = $request->all(); $reports = ExpenseReport::find($input['report_ids']); $reports->load('users', 'owner'); foreach ($reports as $report) { $report->delete(); $mailer->sendReportDeletedNotification($report); } session()->flash('message', count($input['report_ids']) . " Report(s) deleted"); return redirect('/expenseReports?sortBy=' . $input['sortBy'] . '&sortOrder=' . $input['sortOrder']); }