public function convertGems(convertFormRequest $request) { // Get user id from form $id = $request->id; $user = User::find($id); // Get amount of gems to convert $gemsAmount = $request->gemsAmount; if ($user->gems >= $gemsAmount) { // Convert gems to money $converted = $gemsAmount / 100; // Saves new values in database $user->gems = $user->gems - $gemsAmount; $user->money = $user->money + $converted; $user->save(); // Create transaction record $transaction = new Transactions(); $transaction->user_id = $id; $transaction->username = $user->username; $transaction->status = 'CONVERT'; $transaction->amount = $gemsAmount; $transaction->value = 'GEMS'; $transaction->result = $converted; $transaction->result_value = 'POUNDS'; $transaction->save(); return Redirect::back()->with('convertSuccessMessage', 'You successfully converted ' . $gemsAmount . ' Gems to £' . number_format($converted, 2) . '!'); } else { return Redirect::back()->with('convertErrorMessage', 'You do not have the required funds to make that conversion.'); } }
public function index() { if (Auth::check()) { $children = Child::where('user_group', '=', Auth::user()->user_group)->get(); } $users = User::all(); $transactions = Transactions::all()->sortByDesc('created_at')->take(20); return view('home', compact('users', 'transactions', 'children')); }
private function getSalesInfo($month) { $result = array(); $buyers = array(); $buyers_total = array(); $data = Transactions::where(DB::raw('MONTH(created_at)'), '=', $month)->get(); foreach ($data as $t) { $buyers = array_add($buyers, $t->buyer->name, Transactions::where(DB::raw('MONTH(created_at)'), '=', $month)->where('buyer_id', $t->buyer->id)->count()); $buyers_total = array_add($buyers_total, $t->buyer->name, Transactions::where(DB::raw('MONTH(created_at)'), '=', $month)->where('buyer_id', $t->buyer->id)->sum('sub_total')); } $result = array_add($result, 'buyers', $buyers); $result = array_add($result, 'buyers_total', $buyers_total); return $result; }
public function printTransaction(Request $request) { $transaction = Transactions::find($request->q); $pdf = App::make('dompdf.wrapper'); $pdf->loadHtml(view('dompdf.wrapper', compact('transaction'))->render()); return $pdf->stream(); //return view('dompdf.wrapper', compact('transaction')); }