Esempio n. 1
0
 public function doSearch(SalesSearchRequest $request)
 {
     $productSales = [];
     $from = date('Y-m-d', strtotime($request->date_from));
     $to = date('Y-m-d', strtotime($request->date_to));
     $product = $request->product;
     $doctor = $request->doctor;
     $allSearchedReport = Report::select('id')->where('date', '>=', $from)->where('date', '<=', $to);
     if (!empty($MR)) {
         $allSearchedReport = $allSearchedReport->where('mr_id', \Auth::user()->id);
     }
     if (!empty($doctor)) {
         $allSearchedReport = $allSearchedReport->where('doctor_id', $doctor);
     }
     $searchResult = ReportSoldProduct::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 = ['searchResult' => $productSales];
     \Session::flash('date_from', $from);
     \Session::flash('date_to', $to);
     \Session::flash('productSales', $productSales);
     return view('mr.search.sales.result', $dataView);
 }
Esempio n. 2
0
 public static function test()
 {
     $mrId = '3';
     $currentMonth = 'Dec-2015';
     $totalSoldProductsSales = [];
     $totalSoldProductsSalesPrice = 0;
     $reportsId = Report::select('id')->where('month', $currentMonth)->where('mr_id', $mrId)->get()->toArray();
     $allSoldProducts = ReportSoldProduct::whereIn('report_id', $reportsId)->get();
     foreach ($allSoldProducts as $singleReportProducts) {
         $productName = $singleReportProducts->product->name;
         $productPrice = $singleReportProducts->product->unit_price;
         $quantity = $singleReportProducts->quantity;
         $totalSoldProductsSalesPrice += $quantity * $productPrice;
         if (isset($totalSoldProductsSales[$productName])) {
             $totalSoldProductsSales[$productName] += $quantity;
         } else {
             $totalSoldProductsSales[$productName] = $quantity;
         }
     }
     return ['totalSoldProductsSales' => $totalSoldProductsSales, 'totalSoldProductsSalesPrice' => $totalSoldProductsSalesPrice];
     print_r($totalSoldProductsSales);
     print_r($totalSoldProductsSalesPrice);
 }
Esempio n. 3
0
 public function singleMR($id)
 {
     $singleReport = Report::findOrFail($id);
     $singleReport['promotedProducts'] = ReportPromotedProduct::select('product_id')->where('report_id', $singleReport->id)->get();
     $singleReport['sampleProducts'] = ReportSampleProduct::select('product_id')->where('report_id', $singleReport->id)->get();
     $singleReport['gifts'] = ReportGift::select('gift_id')->where('report_id', $singleReport->id)->get();
     $singleReport['soldProducts'] = ReportSoldProduct::select('product_id', 'quantity')->where('report_id', $singleReport->id)->get();
     $dataView = ['singleReport' => $singleReport];
     return view('sm.report.single', $dataView);
 }