private static function monthlySales() { $thisMonth = date("Y-m"); $lastMonth = date("Y-m", strtotime($thisMonth . ' -1 day')); $thisMonthSales = 0; $lastMonthSales = 0; //Orders from today $thisMonthOrders = DB::table('orders')->where('created_at', 'like', "{$thisMonth}%")->get(); foreach ($thisMonthOrders as $month) { $thisMonthSales += Order::find($month->id)->orderCost(); } //Orders from yesterday $lastMonthOrders = DB::table('orders')->where('created_at', 'like', "{$lastMonth}%")->get(); foreach ($lastMonthOrders as $lastMonth) { $lastMonthSales += Order::find($lastMonth->id)->orderCost(); } $percentage = @round(($lastMonthSales - $thisMonthSales) / $lastMonthSales * 100, 2); //determine if percentage is up or down. //This passes a value which determines which sign is displayed. $diff = 'none'; if ($percentage > 0) { $diff = 'down'; $percentage = abs($percentage); } else { if ($percentage < 0) { $diff = 'up'; $percentage = abs($percentage); } else { $diff = 'none'; $percentage = abs($percentage); } } $stats = array('sales' => number_format($thisMonthSales, 2), 'percentage' => $percentage, 'diff' => $diff); return $stats; }
/** * Display a listing of the resource. * * @return Response */ public function index() { return view('admin', ['customers' => Customer::select('id', 'name', 'phoneMob', 'address')->orderBy('name')->get(), 'items' => MenuItem::all(), 'stats' => Order::adminStats(), 'customerCount' => Customer::all()->count()]); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $order = Order::find($id); $order->delete(); Session::flash('message', 'Order Deleted!'); return Redirect::to(URL::previous()); }