Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function process ($dto) {
- // Validasi limit harus angka
- $this->validateLimit($dto);
- // Validasi offset harus angka
- $this->validateOffset($dto);
- // Validasi record_owner_id harus terdaftar di m_record_owner dan angka
- $this->validateRecordOwnerId($dto);
- // Validasi minimum_stock_level harus Y sama N
- $this->validateMinimumStockLevel($dto);
- // Validasi status bisa '', Y, N
- $this->validateStatus($dto);
- \Log::debug(json_encode($dto));
- $keyword = trim(strtoupper($dto["keyword"]));
- $limit = $dto["limit"];
- $offset = $dto["offset"];
- $recordOwnerId = $dto["record_owner_id"];
- $minimum_stock_level = $dto["minimum_stock_level"];
- $status = $dto["status"];
- $queryBuilder = new QueryBuilder();
- $queryBuilder
- ->add(" SELECT ")
- ->add(" A.product_code, A.product_name, ")
- ->add(" SUM(B.qty) as stock, A.minimum_stock_level, A.active ")
- ->add(" FROM ")->add(Product::getTableName())->add(" A ")
- ->add(" JOIN ")->add(InProductBalanceStock::getTableName())->add(" B ")
- ->add(" ON A.product_id = B.product_id AND A.record_owner_id = B.record_owner_id")
- ->add(" WHERE (A.record_owner_id = :record_owner_id OR A.record_owner_id = -99)")
- ->addIfNotEmpty($keyword, " AND ".ConditionExpression::likeCaseInsensitive(" A.product_code ", $keyword." OR ".ConditionExpression::likeCaseInsensitive(" A.product_name", $keyword)))
- ->addIfNotEmpty($status, " AND ".ConditionExpression::equalCaseSensitive(" A.active ", $status))
- ->add(" GROUP BY A.product_code, A.product_name, A.minimum_stock_level, A.active ")
- ->addIfEquals($minimum_stock_level, _YES, " HAVING A.minimum_stock_level <= SUM(B.qty)")
- ->add(" LIMIT :limit OFFSET :offset ");
- $query = new CreateNativeQuery($queryBuilder->toString());
- $query->setParameter("record_owner_id", $recordOwnerId);
- $query->setParameter("limit", $limit);
- $query->setParameter("offset", $offset);
- $result = $query->getResultList();
- return [
- "product_stock_list" => $result
- ];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement