Beispiel #1
0
 public function getDealersByGid($gid, $attributes = array(), $segments = array(), $groupDealersByCreditCode = false, $offset = 0, $count = null)
 {
     // The first character of the gid is type
     $gidType = substr($gid, 0, 1);
     // The rest is the id
     $id = substr($gid, 1);
     // Sort the attributes
     if (!empty($attributes)) {
         $attributes = $this->_sortAttributes($attributes);
     }
     if (strcmp($gidType, 'C') === 0) {
         // Dealer (Customer)
         return array(\Akzo\Dealer::find($id));
         //$query = \Akzo\Dealer::where("id", "=",(int) $id);
     } else {
         if (strcmp($gidType, 'D') === 0) {
             // Depot
             $query = \Akzo\Geography\Depot::find($id)->dealers();
         } else {
             if (strcmp($gidType, 'Z') === 0) {
                 // Zones
                 $query = \Akzo\Geography\Zone::find($id)->dealers();
                 //->all();
             }
         }
     }
     // Add the attributes to the query
     if (!empty($attributes)) {
         foreach ($attributes as $attrKey => $attr) {
             if (isset($attr['included']) && !empty($attr['included'])) {
                 $query = $query->whereIn($attrKey, $attr['included']);
             }
             if (isset($attr['excluded']) && !empty($attr['excluded'])) {
                 $query = $query->whereNotIn($attrKey, $attr['excluded']);
             }
         }
     }
     if (!empty($segments)) {
         // $this->logger->info("Has segments");
         $query = $query->whereIn('segment', $segments);
     }
     if (!empty($count)) {
         $query = $query->take($count)->skip($offset);
     }
     if ($groupDealersByCreditCode) {
         // Group concat ids and code
         $query = $query->selectRaw("GROUP_CONCAT(`ak_sales_dealers`.`id`) `cids`, GROUP_CONCAT(`ak_sales_dealers`.`code`) `ccodes`")->groupBy('credit_code');
     }
     return $query->orderBy('id')->get()->all();
 }
Beispiel #2
0
 public function getDepotByCode($code)
 {
     $this->_validate($code, "code");
     try {
         return \Akzo\Geography\Depot::where('code', 'like', $code)->first();
     } catch (\PDOException $e) {
         $GLOBALS['logger']->info("Error: " . $e->getMessage());
         throw new \InvalidArgumentException(\Akzo\Product\ErrorMessages::PROCESS_ERROR, \Native5\Core\Http\StatusCodes::BAD_REQUEST);
     }
 }