Esempio n. 1
0
 public function loadTargetData(\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 dealer contains collated ids 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->salesTargets();
     }
     // Add where clauses for date range and product ids
     $query = $query->whereBetween('date', array($startDate, $endDate))->whereIn('product_id', $productIds);
     // If the excludedSegment is not set, then need to exclude it
     if (!in_array($excludedSegment, $segments)) {
         // $GLOBALS['logger']->info("Has prof");
         $excludedSegmentID = $this->getIDBySegment($excludedSegment);
         $query = $query->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'));
 }