Advertisement
IdlaNier97

Untitled

Jun 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.29 KB | None | 0 0
  1. public function process ($dto) {
  2.  
  3.         // Validasi limit harus angka
  4.         $this->validateLimit($dto);
  5.  
  6.         // Validasi offset harus angka
  7.         $this->validateOffset($dto);
  8.  
  9.         // Validasi record_owner_id harus terdaftar di m_record_owner dan angka
  10.         $this->validateRecordOwnerId($dto);
  11.  
  12.         // Validasi minimum_stock_level harus Y sama N
  13.         $this->validateMinimumStockLevel($dto);
  14.  
  15.         // Validasi status bisa '', Y, N
  16.         $this->validateStatus($dto);
  17.  
  18.          \Log::debug(json_encode($dto));
  19.  
  20.         $keyword = trim(strtoupper($dto["keyword"]));
  21.         $limit = $dto["limit"];
  22.         $offset = $dto["offset"];
  23.         $recordOwnerId = $dto["record_owner_id"];
  24.         $minimum_stock_level = $dto["minimum_stock_level"];
  25.         $status = $dto["status"];
  26.  
  27.         $queryBuilder = new QueryBuilder();
  28.         $queryBuilder
  29.             ->add(" SELECT ")
  30.             ->add(" A.product_code, A.product_name, ")
  31.             ->add(" SUM(B.qty) as stock, A.minimum_stock_level, A.active ")
  32.             ->add(" FROM ")->add(Product::getTableName())->add(" A ")
  33.             ->add(" JOIN ")->add(InProductBalanceStock::getTableName())->add(" B ")
  34.             ->add(" ON A.product_id = B.product_id AND A.record_owner_id = B.record_owner_id")
  35.             ->add(" WHERE (A.record_owner_id = :record_owner_id OR A.record_owner_id = -99)")
  36.             ->addIfNotEmpty($keyword, " AND ".ConditionExpression::likeCaseInsensitive(" A.product_code ", $keyword." OR ".ConditionExpression::likeCaseInsensitive(" A.product_name", $keyword)))
  37.             ->addIfNotEmpty($status, " AND ".ConditionExpression::equalCaseSensitive(" A.active ", $status))
  38.             ->add(" GROUP BY A.product_code, A.product_name, A.minimum_stock_level, A.active ")
  39.             ->addIfEquals($minimum_stock_level, _YES, " HAVING A.minimum_stock_level <= SUM(B.qty)")
  40.             ->add(" LIMIT :limit OFFSET :offset ");
  41.  
  42.         $query = new CreateNativeQuery($queryBuilder->toString());
  43.         $query->setParameter("record_owner_id", $recordOwnerId);
  44.         $query->setParameter("limit", $limit);
  45.         $query->setParameter("offset", $offset);
  46.  
  47.         $result = $query->getResultList();
  48.         return [
  49.             "product_stock_list" => $result
  50.         ];
  51.            
  52.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement