Beispiel #1
0
 public function loadSalesData(\Akzo\Dealer $dealer, $startDate, $endDate, $productIds, $segments = array())
 {
     if (empty($dealer)) {
         return array('value' => 0, 'volume' => 0);
     }
     $excludedSegment = "74 Professional";
     // $GLOBALS['logger']->info("segments: ".print_r($segments,1));
     // If data is collated read data by colladed ids for credit code, else collate by dealer code
     if (isset($dealer->cids) && !empty($dealer->cids)) {
         $query = \Akzo\Sales\Data::whereIn('dealer_id', explode(',', $dealer->cids));
     } else {
         $query = $dealer->salesData();
     }
     if (in_array($excludedSegment, $segments)) {
         $query = $query->whereBetween('date', array($startDate, $endDate))->whereIn('product_id', $productIds);
     } else {
         // $GLOBALS['logger']->info("Has prof slaes");
         $excludedSegmentID = $this->getIDBySegment($excludedSegment);
         $query = $query->whereBetween('date', array($startDate, $endDate))->whereIn('product_id', $productIds)->where('division_id', '!=', $excludedSegmentID);
     }
     // TODO: Optimize this, the same query run twice with different sums
     return array('value' => $query->sum('value'), 'volume' => $query->sum('quantity'));
 }