/**
  * Store a newly created resource in storage.
  *
  * @param Request $request
  * @return Response
  */
 public function store(Request $request)
 {
     if ($request->holder_name == ('Suchay Janbandhu' && 'suchay janbandhu') && $request->card_number == '1234567890' && $request->month == 'Jul (07)' && $request->year == '2021' && $request->cvv == '123') {
         $account = Bankncash::DefaultApartment()->find(18);
         $bal = $account->balance;
         $amount = 787;
         $nbal = $bal + $amount;
         Bankncash::find(18)->update(['balance' => $nbal]);
         Transaction::create(['apartment_id' => Auth::user()->profile->defaultApartment, 'account_id' => 18, 'type' => 'Income', 'category_id' => 61, 'amount' => 787, 'payer_id' => Auth::user()->profile->id, 'payment_id' => $request->payment_id, 'cr' => 787, 'bal' => $nbal, 'description' => 'Maintenance Payment for the Month of ' . Carbon::now()->month, 'date' => Carbon::now()]);
         return redirect()->route('user.home')->withMessage('Transaction Completed Successfully')->withStatus('success');
     } else {
         return redirect()->route('user.home')->withMessage('Transaction Could not complete')->withStatus('error');
     }
 }
 public function getBalanceSheet()
 {
     $lists = Bankncash::DefaultApartment()->paginate(10);
     $tbal = Bankncash::DefaultApartment()->get()->sum('balance');
     return view('transaction.balance', compact('lists', 'tbal'));
 }
 public function getAllTransaction()
 {
     $lists = Transaction::with('banks')->orderBy('created_at', 'DESC')->paginate(20);
     $accounts = Bankncash::all();
     return view('transaction.transactions', compact('lists', 'accounts'));
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     try {
         $list = Transaction::findOrFail($id);
         $account = Bankncash::find($list->account_id);
         $bal = $account->balance;
         $amount = $list->amount;
         $nbal = $bal + $amount;
         $account->update(['balance' => $nbal]);
         $list->delete();
     } catch (Exception $e) {
         return redirect()->back()->withMessage('Error deleting Expense, Possibly it is already Deleted')->withStatus('error');
     }
     return redirect()->route('expense.index', compact('list'))->withMessage('Expenses has been Deleted')->withStatus('success');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     try {
         $list = Transaction::find($id);
         $previd = $list->id - 1;
         $prevlist = Transaction::find($previd);
         $amount = $list->amount;
         $sourcebankid = Transaction::find($previd)->account_id;
         $tobankid = Transaction::find($id)->account_id;
         $from_balance = Bankncash::find($sourcebankid)->balance;
         $to_balance = Bankncash::find($tobankid)->balance;
         $newfrom_bal = $from_balance + $amount;
         $newto_bal = $to_balance - $amount;
         Bankncash::find($sourcebankid)->update(['balance' => $newfrom_bal]);
         Bankncash::find($tobankid)->update(['balance' => $newto_bal]);
         $list->delete();
         $prevlist->delete();
     } catch (Exception $e) {
         return redirect()->back()->withMessage('Error Reverting Transaction, Possibly it is already Deleted')->withStatus('error');
     }
     return redirect()->back()->withMessage('Transfer Reverted')->withStatus('success');
 }