Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.erp.sls.bo.inquiry;
- import java.util.List;
- import javax.persistence.Query;
- import org.jleaf.core.AbstractBusinessFunction;
- import org.jleaf.core.BusinessFunction;
- import org.jleaf.core.CoreException;
- import org.jleaf.core.CoreExceptionConstants;
- import org.jleaf.core.Dto;
- import org.jleaf.core.GeneralConstants;
- import org.jleaf.core.annotation.ErrorList;
- import org.jleaf.core.annotation.Info;
- import org.jleaf.core.annotation.InfoIn;
- import org.jleaf.core.annotation.InfoOut;
- import org.jleaf.core.dao.CriteriaHelper;
- import org.jleaf.core.dao.QueryBuilder;
- import org.jleaf.erp.inv.entity.DeliveryOrderReceipt;
- import org.jleaf.erp.inv.entity.LogBook;
- import org.jleaf.erp.master.entity.BrandExt;
- import org.jleaf.erp.sls.SalesConstantsForKtmt;
- import org.jleaf.erp.sls.dao.SoStatusDao;
- import org.jleaf.erp.sls.entity.DeliveryOrder;
- import org.jleaf.erp.sls.entity.SalesOrder;
- import org.jleaf.erp.sls.entity.SoBrandItem;
- import org.jleaf.erp.sls.entity.SoInfo;
- import org.jleaf.erp.sls.entity.SoStatus;
- import org.jleaf.util.DtoUtil;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- /**
- *
- * @author Agik, May 31, 2016
- *
- * Get SO list for Inquiry SO
- *
- * @modify Adrian
- * Dec 29, 2016
- *
- * Menampilkan total qty do dan flag do receipt
- * Menambahkan infoIn flgDoReceipt
- */
- //@formatter:off
- @Service
- @InfoIn(value = {
- @Info(name = "tenantId", description = "tenant id", type = Long.class),
- @Info(name = "ouId", description = "ou id", type = Long.class),
- @Info(name = "periodStart", description = "period start", type = String.class),
- @Info(name = "periodEnd", description = "period end", type = String.class),
- @Info(name = "customer", description = "customer", type = String.class),
- @Info(name = "soNo", description = "SO No", type = String.class),
- @Info(name = "flgTypeSo", description = "Flg Type So", type = String.class),
- @Info(name = "statusSo", description = "status SO", type = String.class),
- @Info(name = "statusSettlement", description = "status Settlement", type = String.class),
- @Info(name = "statusPrint", description = "status Print", type = String.class),
- @Info(name = "statusScan", description = "status Scan", type = String.class),
- @Info(name = "statusExpedition", description = "status Expedition", type = String.class),
- @Info(name = "statusInvoice", description = "status Invoice", type = String.class),
- @Info(name = "flgAutoSettle", description = "flg auto settlement", type = String.class),
- @Info(name = "ctgrProductId", description = "ctgr Product Id", type = Long.class),
- @Info(name = "groupBrand", description = "group Brand", type = String.class),
- @Info(name = "brandId", description = "brandId", type = Long.class),
- @Info(name = "salesman", description = "salesman", type = String.class),
- @Info(name = "custDocNo", description = "cust Doc No", type = String.class),
- @Info(name = "offset", description = "offset", type=Long.class),
- @Info(name = "limit", description = "limit", type=Long.class),
- @Info(name = "doDocNo", description = "DO Doc No", type = String.class),
- @Info(name = "flgDoReceipt", description = "Flag DO Receipt", type = String.class)
- })
- @InfoOut(value = {
- @Info(name = "soList", description = "list of SO", type = List.class)
- })
- @ErrorList(errorKeys = {
- })
- //@formatter:on
- public class GetSalesOrderListforInquirySo extends AbstractBusinessFunction implements BusinessFunction {
- @Autowired
- private SoStatusDao soStatusDao;
- @Override
- public String getDescription() {
- return "Get SO list for Inquiry SO";
- }
- @SuppressWarnings("unchecked")
- @Override
- public Dto execute(Dto inputDto) throws Exception {
- if (inputDto == null) {
- throw new CoreException(CoreExceptionConstants.DTO_CANNOT_NULL);
- }
- Long brandId = inputDto.getLong("brandId");
- List<Object[]> result = null;
- //@formatter:off
- StringBuilder filterCustomer = new StringBuilder();
- filterCustomer.append(" AND ( ")
- .append(CriteriaHelper.likeExpressionIgnoreCase(inputDto.getString("customer"), "f_get_partner_code(A.partner_id)"))
- .append(" OR ")
- .append(CriteriaHelper.likeExpressionIgnoreCase(inputDto.getString("customer"), "f_get_partner_name(A.partner_id)"))
- .append(" ) ");
- StringBuilder filterSoNo = new StringBuilder();
- filterSoNo.append(" AND ")
- .append(CriteriaHelper.likeExpressionIgnoreCase(inputDto.getString("soNo"), "A.doc_no"));
- StringBuilder filterSalesman = new StringBuilder();
- filterSalesman.append(" AND ( ")
- .append(CriteriaHelper.likeExpressionIgnoreCase(inputDto.getString("salesman"), "f_get_partner_code(B.salesman_id)"))
- .append(" OR ")
- .append(CriteriaHelper.likeExpressionIgnoreCase(inputDto.getString("salesman"), "f_get_partner_name(B.salesman_id)"))
- .append(" ) ");
- StringBuilder filterExtDocNo = new StringBuilder();
- filterExtDocNo.append(" AND ")
- .append(CriteriaHelper.likeExpressionIgnoreCase(inputDto.getString("custDocNo"), "B.ext_doc_no"));
- /*
- StringBuilder filterBrand = new StringBuilder();
- filterBrand.append(" AND ")
- .append(CriteriaHelper.likeExpressionIgnoreCase(inputDto.getString("brand"), "G.brand"));
- */
- StringBuilder filterDoDocNo = new StringBuilder();
- filterDoDocNo.append(" AND ")
- .append(CriteriaHelper.likeExpressionIgnoreCase(inputDto.getString("doDocNo"), "I.doc_no"));
- QueryBuilder builder = new QueryBuilder();
- builder.add(" WITH so_brand AS ( ")
- .add(" SELECT A.so_id, B.group_brand, string_agg(f_get_brand_code(A.brand_id), ', ') AS brand ")
- .add(" FROM ").add(SoBrandItem.TABLE_NAME).add(" A ")
- .add(" INNER JOIN ").add(BrandExt.TABLE_NAME).add(" B ON A.brand_id = B.brand_id ")
- .addIfNotEquals(brandId, GeneralConstants.NULL_REF_VALUE_LONG, " WHERE A.brand_id = :brandId ")
- .addIfNotEmpty(inputDto.getString("groupBrand"), " AND B.group_brand = :groupBrand ")
- .add(" GROUP BY A.so_id, B.group_brand ")
- .add(" ) ")
- .add("SELECT A.so_id, A.tenant_id, A.ou_id, B.doc_no, B.doc_date, B.partner_id, f_get_partner_code(B.partner_id) AS partner_code, ")
- .add(" f_get_partner_name(B.partner_id) AS partner_name, B.remark, f_get_total_brand_amount_include_tax_sob_by_so_id(A.so_id) AS so_amount, ")
- .add(" f_get_role_name(D.current_role_id) AS current_role, B.status_doc, A.status_settlement, A.so_settlement_id, A.status_picking, ")
- .add(" A.status_do, A.do_id, A.status_log_book, A.log_book_id, A.status_invoice, A.invoice_id, E.flg_auto_settle, ")
- .add(" G.brand AS brand_code, G.group_brand, B.ext_doc_no, ")
- .add(" f_get_partner_code(B.salesman_id) AS salesman_code, f_get_partner_name(B.salesman_id) AS salesman_name, A.version AS version_so_status, ")
- .add(" f_get_status_cetak_report(A.so_id, B.doc_type_id, '").add(SalesConstantsForKtmt.GROUP_PRINT_FORM_DO).add("' ) AS status_print_do, ")
- .add(" COALESCE(H.doc_no, '-') AS log_book_no, COALESCE(H.doc_date, '-') AS log_book_date, ")
- .add(" CASE WHEN (E.flg_type_so = 'REG') ")
- .add(" THEN 'REGULAR' ")
- .add(" WHEN (E.flg_type_so = 'TRL') ")
- .add(" THEN 'TRIAL' ")
- .add(" WHEN (E.flg_type_so = 'FOC') ")
- .add(" THEN 'FOC' ")
- .add(" WHEN (E.flg_type_so = 'SMP') ")
- .add(" THEN 'SAMPEL' ")
- .add(" WHEN (E.flg_type_so = 'RVS') ")
- .add(" THEN 'REVISI' ")
- .add(" WHEN (E.flg_type_so = 'CON') ")
- .add(" THEN 'KONSINYASI' ")
- .add(" END AS type_so, f_get_username(B.create_user_id) AS create_username, COALESCE(I.doc_no, '-') AS delivery_order_no, ")
- .add(" f_get_total_jenis_sku_of_so(B.tenant_id, A.so_id) AS total_jenis_sku_so, E.remark_internal, E.remark_settlement, ")
- .add(" CASE WHEN EXISTS ( SELECT TRUE FROM ")
- .add(DeliveryOrderReceipt.TABLE_NAME)
- .add(" WHERE ref_id = A.do_id ) ")
- .add(" THEN 'Y' ")
- .add(" ELSE 'N' ")
- .add(" END AS flg_do_receipt, ")
- .add(" f_get_total_qty_do_sob_by_so_id(A.so_id) ")
- .add(" FROM ").add(SoStatus.TABLE_NAME).add(" A ")
- .add(" INNER JOIN ").add(SalesOrder.TABLE_NAME).add(" B ON A.so_id = B.so_id ")
- .add(" INNER JOIN awe_currdoc_status D ON B.tenant_id = D.tenant_id AND D.scheme = :scheme AND B.so_id = D.doc_id ")
- .add(" INNER JOIN ").add(SoInfo.TABLE_NAME).add(" E ON A.so_id = E.so_id ")
- .add(" INNER JOIN so_brand G ON B.so_id = G.so_id ")
- .add(" LEFT JOIN ").add(LogBook.TABLE_NAME).add(" H ON A.log_book_id = H.log_book_id ")
- .add(" LEFT JOIN ").add(DeliveryOrder.TABLE_NAME).add(" I ON B.so_id = I.ref_id AND B.doc_type_id = I.ref_doc_type_id ")
- .add(" WHERE A.tenant_id = :tenantId ")
- .add(" AND A.ou_id = :ouId ")
- .add(" AND A.doc_date BETWEEN :periodStart AND :periodEnd ")
- .addIfNotEmpty(inputDto.getString("customer"), filterCustomer.toString())
- .addIfNotEmpty(inputDto.getString("soNo"), filterSoNo.toString())
- .addIfNotEmpty(inputDto.getString("flgTypeSo"), " AND E.flg_type_so = :flgTypeSo ")
- .addIfNotEmpty(inputDto.getString("statusSo"), " AND B.status_doc = :statusSo ")
- .addIfNotEmpty(inputDto.getString("statusSettlement"), " AND A.status_settlement = :statusSettlement ")
- .addIfNotEmpty(inputDto.getString("statusPrint"), " AND A.status_picking = :statusPrint ")
- .addIfNotEmpty(inputDto.getString("statusScan"), " AND A.status_do = :statusScan ")
- .addIfNotEmpty(inputDto.getString("statusExpedition"), " AND A.status_log_book = :statusExpedition ")
- .addIfNotEmpty(inputDto.getString("statusInvoice"), " AND A.status_invoice = :statusInvoice ")
- .addIfNotEmpty(inputDto.getString("flgAutoSettle"), " AND E.flg_auto_settle = :flgAutoSettle ")
- /*.addIfElseEquals(inputDto.getString("flgDoReceipt"), GeneralConstants.YES,
- " AND EXISTS ( SELECT TRUE FROM "+ DeliveryOrderReceipt.TABLE_NAME+" WHERE ref_id = A.do_id ) ", " AND NOT EXISTS ( SELECT TRUE FROM "+ DeliveryOrderReceipt.TABLE_NAME+" WHERE ref_id = A.do_id ) ")*/
- .addIfNotEmpty(inputDto.getString("flgDoReceipt"), " AND ")
- .addIfElseEquals(inputDto.getString("flgDoReceipt"), GeneralConstants.NO, " NOT ", " ")
- .addIfNotEmpty(inputDto.getString("flgDoReceipt"), " EXISTS ( SELECT TRUE FROM "+ DeliveryOrderReceipt.TABLE_NAME+" WHERE ref_id = A.do_id ) ")
- .addIfNotEmpty(inputDto.getString("salesman"), filterSalesman.toString())
- .addIfNotEmpty(inputDto.getString("custDocNo"), filterExtDocNo.toString())
- //.addIfNotEmpty(inputDto.getString("brand"), filterBrand.toString())
- .addIfNotEmpty(inputDto.getString("doDocNo"), filterDoDocNo.toString())
- .add(" ORDER BY B.doc_date, B.doc_no ")
- .addIfNotNull(inputDto.get("limit"), " LIMIT :limit ")
- .addIfNotNull(inputDto.get("offset"), " OFFSET :offset ");
- //@formatter:on
- Query query = soStatusDao.createNativeQuery(builder.toString());
- query.setParameter("scheme", SalesConstantsForKtmt.SHEME_DOCUMENT_SALES_ORDER_BY_BRAND);
- query.setParameter("tenantId", inputDto.getLong("tenantId"));
- query.setParameter("ouId", inputDto.getLong("ouId"));
- query.setParameter("periodStart", inputDto.getString("periodStart"));
- query.setParameter("periodEnd", inputDto.getString("periodEnd"));
- if (!inputDto.getString("statusSo").isEmpty())
- query.setParameter("statusSo", inputDto.getString("statusSo"));
- if (!inputDto.getString("statusSettlement").isEmpty())
- query.setParameter("statusSettlement", inputDto.getString("statusSettlement"));
- if (!inputDto.getString("statusPrint").isEmpty())
- query.setParameter("statusPrint", inputDto.getString("statusPrint"));
- if (!inputDto.getString("statusScan").isEmpty())
- query.setParameter("statusScan", inputDto.getString("statusScan"));
- if (!inputDto.getString("statusExpedition").isEmpty())
- query.setParameter("statusExpedition", inputDto.getString("statusExpedition"));
- if (!inputDto.getString("statusInvoice").isEmpty())
- query.setParameter("statusInvoice", inputDto.getString("statusInvoice"));
- if (!inputDto.getString("flgAutoSettle").isEmpty())
- query.setParameter("flgAutoSettle", inputDto.getString("flgAutoSettle"));
- if (!inputDto.getString("groupBrand").isEmpty())
- query.setParameter("groupBrand", inputDto.getString("groupBrand"));
- if (!inputDto.getString("flgTypeSo").isEmpty())
- query.setParameter("flgTypeSo", inputDto.getString("flgTypeSo"));
- if (inputDto.get("limit") != null)
- query.setParameter("limit", inputDto.getLong("limit"));
- if (inputDto.get("offset") != null)
- query.setParameter("offset", inputDto.getLong("offset"));
- if (!GeneralConstants.NULL_REF_VALUE_LONG.equals(brandId))
- query.setParameter("brandId", brandId);
- result = query.getResultList();
- return new Dto().putList("soList", DtoUtil.createDtoListFromArray(result, "soId", "tenantId", "ouId", "docNo", "docDate",
- "partnerId", "partnerCode", "partnerName", "remark", "soAmount", "currentRole", "statusSo", "statusSoSettlement",
- "soSettlementId", "statusPicking", "statusScan", "scanId", "statusExpedition", "expeditionId", "statusInvoice",
- "invoiceId", "flgAutoSettle", "brandCode", "groupBrand", "extDocNo",
- "salesmanCode", "salesmanName", "versionSoStatus", "statusPrintDo", "logBookNo", "logBookDate", "typeSo", "createUserName",
- "deliveryOrderNo", "totalJenisSkuSo", "remarkInternal", "remarkSettlement", "flgDoReceipt", "totalQtyDo"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement