Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 /**
  * Save a new expense.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $receipt = $request->file('receipt_url');
     if ($receipt) {
         $filename = time() . '.' . $receipt->getClientOriginalExtension();
         $filepath = '/receipts/' . $filename;
         if (!Storage::disk('s3')->put($filepath, file_get_contents($receipt), 'public')) {
             $filename = '';
         }
     }
     $this->validate($request, ['amount' => 'required']);
     if ($request->purchase_date) {
         $request->purchase_date = date('Y-m-d', strtotime($request->purchase_date));
     }
     if (!$request->id) {
         Expense::create(['store_id' => $request->store_id, 'amount' => $request->amount, 'purchase_date' => $request->purchase_date, 'notes' => $request->notes, 'receipt_url' => isset($filepath) ? $filepath : '']);
     } else {
         $purchase = Expense::find($request->id);
         $purchase->notes = $request->notes;
         $purchase->store_id = $request->store_id;
         $purchase->amount = $request->amount;
         $purchase->purchase_date = $request->purchase_date;
         if ($receipt) {
             $purchase->receipt_url = $filepath;
         }
         $purchase->save();
     }
     return redirect('/expense');
 }
 /**
  * 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;
 }
Ejemplo n.º 4
0
 private function setPurchasePayment()
 {
     $accountPayment = NameOfAccount::find(Input::get('account_name_id'));
     if ($accountPayment->opening_balance >= Input::get('amount')) {
         $expense[0] = Expense::where('invoice_id', '=', Input::get('invoice_id'))->get();
         $expenseTransaction = new Transaction();
         $expenseTransaction->branch_id = Input::get('branch_id');
         $expenseTransaction->account_category_id = Input::get('account_category_id');
         $expenseTransaction->account_name_id = Input::get('account_name_id');
         $expenseTransaction->amount = Input::get('amount');
         $expenseTransaction->remarks = Input::get('remarks');
         $expenseTransaction->type = "Expense";
         $expenseTransaction->user_id = Session::get('user_id');
         $expenseTransaction->payment_method = Input::get('payment_method');
         $expenseTransaction->invoice_id = Input::get('invoice_id');
         $expenseTransaction->cheque_no = Input::get('cheque_no');
         $expenseTransaction->save();
         $totalAmount = 0;
         $transactions = Transaction::where('invoice_id', '=', $expenseTransaction->invoice_id)->get();
         foreach ($transactions as $transaction) {
             $totalAmount = $totalAmount + $transaction->amount;
         }
         $expense = Expense::find($expense[0][0]['id']);
         if ($totalAmount == $expense->amount) {
             $expense->status = "Completed";
         } else {
             $expense->status = "Partial";
         }
         $expense->save();
         $accountPayment->opening_balance = $accountPayment->opening_balance - Input::get('amount');
         $accountPayment->save();
         Session::flash('message', 'Expense has been Successfully Cleared.');
     } else {
         Session::flash('message', 'You dont have Enough Balance');
     }
 }
Ejemplo n.º 5
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($project_id, $id)
 {
     $expense = Expense::find($id);
     $expense->delete();
     flash()->success('Expense has been successfully deleted!');
     return redirect()->action('ProjectsController@show', $project_id);
 }
Ejemplo n.º 6
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $expense = Expense::find($id);
     $supplements = array_column($expense->supplements()->get()->toArray(), 'id');
     ExpenseSupplement::destroy($supplements);
     Expense::destroy($expense->id);
 }