public function single($mr, $currentMonth) { $actualVisits = []; $MonthlyCustomerProducts = []; $MRLine = []; $doctors = Customer::where('mr_id', $mr)->get(); foreach ($doctors as $singleDoctor) { $actualVisits[$singleDoctor->id] = Report::where('mr_id', $mr)->where('month', $currentMonth)->where('doctor_id', $singleDoctor->id)->count(); $MonthlyCustomerProducts[$singleDoctor->id] = Customer::monthlyProductsBought([$singleDoctor->id])->toArray(); } $products = Product::where('line_id', Employee::findOrFail($mr)->line_id)->get(); $coverageStats = Employee::coverageStats($mr, $currentMonth); $allManagers = Employee::yourManagers($mr); $totalProducts = Employee::monthlyDirectSales($mr, $currentMonth); $totalSoldProductsSales = $totalProducts['totalSoldProductsSales']; $totalSoldProductsSalesPrice = $totalProducts['totalSoldProductsSalesPrice']; $currentMonth = \Carbon\Carbon::parse($currentMonth); $lines = MrLines::select('line_id', 'from', 'to')->where('mr_id', $mr)->get(); foreach ($lines as $line) { $lineFrom = \Carbon\Carbon::parse($line->from); $lineTo = \Carbon\Carbon::parse($line->to); if (!$currentMonth->lte($lineTo) && $currentMonth->gte($lineFrom)) { $MRLine = MrLines::where('mr_id', $mr)->where('line_id', $line->line_id)->get(); } } $dataView = ['doctors' => $doctors, 'MonthlyCustomerProducts' => $MonthlyCustomerProducts, 'actualVisits' => $actualVisits, 'products' => $products, 'totalVisitsCount' => $coverageStats['totalVisitsCount'], 'actualVisitsCount' => $coverageStats['actualVisitsCount'], 'totalMonthlyCoverage' => $coverageStats['totalMonthlyCoverage'], 'allManagers' => $allManagers, 'totalSoldProductsSales' => $totalSoldProductsSales, 'totalSoldProductsSalesPrice' => $totalSoldProductsSalesPrice, 'MRLines' => $MRLine]; return view('am.line.single', $dataView); }
public function doHistory(LineHistoryRequest $request) { $year = $request->year; $month = $request->month; $line = isset($request->line) ? $request->line : NULL; $month = \Carbon\Carbon::parse($month . '-' . $year); $line = MrLines::select('id', 'from', 'to')->where('mr_id', \Auth::user()->id)->where('line_id', $line)->first(); $lineFrom = \Carbon\Carbon::parse($line->from); $lineTo = \Carbon\Carbon::parse($line->to); if (is_null($line->to) && !$month->gte($lineFrom)) { return Redirect::back()->with('message', 'You don\'t have access to this line now'); } if (!$month->lte($lineTo) && $month->gte($lineFrom)) { return Redirect::back()->with('message', 'You don\'t have access to this line now'); } return Redirect::route('singleLine', \Carbon\Carbon::parse($month)->format('M-Y')); }