/** * Display aggregated results of sales. Per product to value that has been sold in the specified period. * * @param Request $request * @param $id */ public function showAggregation(Request $request, $account) { $account = Account::findOrFail($account); $orderlines = OrderLine::where('created_at', '>=', Carbon::parse($request->start)->format('Y-m-d H:i:s'))->where('created_at', '<', Carbon::parse($request->end)->format('Y-m-d H:i:s'))->get(); $products = []; $totals = []; foreach ($orderlines as $orderline) { if ($orderline->product->account->account_number == $account->account_number) { $p = $orderline->product; if (!array_key_exists($p->id, $products)) { $products[$p->id] = $p; $totals[$p->id] = 0; } $totals[$p->id] += $orderline->total_price; } } return view('omnomcom.accounts.aggregation', ['account' => $account, 'products' => $products, 'totals' => $totals, 'start' => $request->start, 'end' => $request->end]); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function adminindex(Request $request) { $date = $request->has('date') ? $request->input('date') : null; $orderlines = OrderLine::where('created_at', '>=', $date ? Carbon::parse($date)->format('Y-m-d H:i:s') : Carbon::today()->format('Y-m-d H:i:s')); if ($date != null) { $orderlines = $orderlines->where('created_at', '<=', Carbon::parse($date . ' 23:59:59')->format('Y-m-d H:i:s')); } $orderlines = $orderlines->orderBy('created_at', 'desc')->get(); if (Auth::user()->can('alfred')) { $neworderlines = []; foreach ($orderlines as $orderline) { if ($orderline->product->account->id == config('omnomcom.alfred-account')) { $neworderlines[] = $orderline; } } $orderlines = collect($neworderlines); } return view('omnomcom.orders.adminhistory', ['date' => $date, 'orderlines' => $orderlines ? $orderlines : []]); }
public function total() { return OrderLine::where('payed_with_withdrawal', $this->id)->sum('total_price'); }