Example #1
0
 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);
 }
Example #2
0
 public function singleAM($id)
 {
     $singleReport = AMReport::findOrFail($id);
     $singleReport['promotedProducts'] = AMReportPromotedProduct::select('product_id')->where('report_id', $singleReport->id)->get();
     $singleReport['sampleProducts'] = AMReportSampleProduct::select('product_id')->where('report_id', $singleReport->id)->get();
     $singleReport['gifts'] = AMReportGift::select('gift_id')->where('report_id', $singleReport->id)->get();
     $singleReport['soldProducts'] = AMReportSoldProduct::select('product_id', 'quantity')->where('report_id', $singleReport->id)->get();
     $dataView = ['singleReport' => $singleReport];
     return view('sm.report.single', $dataView);
 }