public function doAMSearch(AMSalesSearchRequest $request) { $productSales = []; $from = $request->date_from; $to = $request->date_to; $product = $request->product; $doctor = $request->doctor; $AM = $request->am; $allSearchedReport = AMReport::select('id')->where('date', '>=', $from)->where('date', '<=', $to); if (!empty($AM)) { $allSearchedReport = $allSearchedReport->where('am_id', $AM); } if (!empty($doctor)) { $allSearchedReport = $allSearchedReport->where('doctor_id', $doctor); } $searchResult = AMReportSoldProduct::whereIn('report_id', $allSearchedReport->get()); if (!empty($product)) { $searchResult->where('product_id', $product); } foreach ($searchResult->get() as $singleResult) { if (isset($productSales[$singleResult->product->name])) { $productSales[$singleResult->product->name] += $singleResult->quantity; } else { $productSales[$singleResult->product->name] = $singleResult->quantity; } } $dataView = ['productSales' => $productSales]; \Session::flash('date_from', $from); \Session::flash('date_to', $to); \Session::flash('productSales', $productSales); return view('admin.search.sales.result', $dataView); }
public function doSearch(ReportSearchRequest $request) { $searchResult = null; $from = $request->date_from; $to = $request->date_to; $doctor = $request->doctor; $promoted_product = $request->promoted_product; $sample_product = $request->sample_product; $sold_product = $request->sold_product; $gift = $request->gift; $follow_up = $request->follow_up; $feedback = $request->feedback; $allReportsInRange = AMReport::select('am_report.id', 'month', 'date', 'doctor_id', 'am_id', 'total_sold_products_price')->where('date', '>=', $from)->where('date', '<=', $to)->where('am_id', 4); if (!empty($doctor)) { $allReportsInRange->where('doctor_id', $doctor); } if (!empty($promoted_product)) { $allReportsInRange->join('report_promoted_product', 'report_promoted_product.report_id', '=', 'am_report.id')->where('report_promoted_product.product_id', $promoted_product); } if (!empty($sample_product)) { $allReportsInRange->join('report_sample_product', 'report_sample_product.report_id', '=', 'report.id')->where('report_sample_product.product_id', $sample_product); } if (!empty($sold_product)) { $allReportsInRange->join('report_sold_product', 'report_sold_product.report_id', '=', 'am_report.id')->where('report_sold_product.product_id', $sold_product); } if (!empty($gift)) { $allReportsInRange->join('report_gift', 'report_gift.report_id', '=', 'am_report.id')->where('report_gift.gift_id', $gift); } if ($follow_up == 1) { $allReportsInRange->where('am_report.follow_up', '<>', ''); } if ($feedback == 1) { $allReportsInRange->where('am_report.feedback', '<>', ''); } $searchResult = $allReportsInRange->get(); $dataView = ['searchResult' => $searchResult]; return view('am.search.reports.result', $dataView); }