public function complete(Request $request, $id) { $userid = Auth::id(); $transaction_id = Transaction::where('user_id', $userid)->where('status', 'open')->first()->transaction_id; $totalValue = Transaction::where('user_id', $userid)->where('status', 'open')->sum('price'); $tax = 0.08; $total = $totalValue * $tax + $totalValue; $change = $id; $notes = $request->input('notes'); $cash_received = $change + $total; //store receipt Receipt::create(array('transaction_id' => $transaction_id, 'user_id' => $userid, 'total' => $total, 'cash_received' => $cash_received, 'change' => $change, 'notes' => $notes)); //close transaction $transactionItems = Transaction::where('user_id', $userid)->where('status', 'open')->get(); foreach ($transactionItems as $item) { $item->update(array('status' => 'closed')); } return redirect('home'); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $new_receipt = $this->prepareInputReceipt(); $receipt = Receipt::create($new_receipt); return $receipt; }