Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.erp.inv.bo.inquiryexchange;
- import java.util.List;
- import javax.persistence.Query;
- import org.jleaf.core.AbstractBusinessFunction;
- import org.jleaf.core.BusinessFunction;
- import org.jleaf.core.Dto;
- import org.jleaf.core.GeneralConstants;
- 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.InventoryConstantsForKtmt;
- import org.jleaf.erp.inv.dao.InOutExchangeDao;
- import org.jleaf.erp.inv.entity.InOutExchange;
- import org.jleaf.util.DtoUtil;
- import org.jleaf.util.ValidationUtil;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- /**
- *
- * @author Sarah, Jun 14, 2016
- *
- * @modified by Henik, 21 Des 2017
- * - Merapikan querynya, terutam bagian filter beberapa saya ubah pakai StringBuilder
- *
- **/
- @Service
- @InfoIn(value = {
- @Info(name = "tenantId", description = "tenant Id", type = Long.class),
- @Info(name = "ouId", description = "ou Id", type = Long.class),
- @Info(name = "dateFrom", description = "date from", type = String.class),
- @Info(name = "dateTo", description = "date to", type = String.class),
- @Info(name = "customer", description = "partner / customer", type = Long.class),
- @Info(name = "docNo", description = "doc no", type = String.class),
- @Info(name = "statusDocReq", description = "status Doc request exchange", type = String.class),
- @Info(name = "statusDocExchangeOut", description = "status Doc exchange out", type = String.class),
- @Info(name = "statusDocExchangeIn", description = "status Doc exchange in", type = String.class),
- @Info(name = "brandId", description = "brand Id", type = Long.class),
- @Info(name = "limit", description = "limit", type = Long.class, required = false),
- @Info(name = "offset", description = "offset", type = Long.class, required = false)
- })
- @InfoOut(value = {
- @Info(name = "inquiryExchangeList", description = "inquiryExchangeList")
- })
- public class GetInquiryExchangeList extends AbstractBusinessFunction implements BusinessFunction {
- private static final Logger log = LoggerFactory.getLogger(GetInquiryExchangeList.class);
- @Autowired
- private InOutExchangeDao inOutExchangeDao;
- private String statusDocExchangeIn;
- private String statusDocExchangeOut;
- private String kondisiWhere;
- @Override
- public String getDescription() {
- return "Get Inquiry Exchange List";
- }
- @SuppressWarnings({ "unchecked" })
- @Override
- public Dto execute(Dto inputDto) throws Exception {
- log.info("paramInput GET =:"+inputDto);
- ValidationUtil.valDtoContainsKey(inputDto, "tenantId");
- ValidationUtil.valDtoContainsKey(inputDto, "ouId");
- ValidationUtil.valDtoContainsKey(inputDto, "dateFrom");
- ValidationUtil.valDtoContainsKey(inputDto, "dateTo");
- ValidationUtil.valDtoContainsKey(inputDto, "customer");
- ValidationUtil.valDtoContainsKey(inputDto, "docNo");
- ValidationUtil.valDtoContainsKey(inputDto, "statusDocReq");
- ValidationUtil.valDtoContainsKey(inputDto, "statusDocExchangeOut");
- ValidationUtil.valDtoContainsKey(inputDto, "statusDocExchangeIn");
- ValidationUtil.valDtoContainsKey(inputDto, "brandId");
- Long tenantId = inputDto.getLong("tenantId");
- Long ouId = inputDto.getLong("ouId");
- String dateFrom = inputDto.getString("dateFrom");
- String dateTo = inputDto.getString("dateTo");
- String customer = inputDto.getString("customer");
- String docNo = inputDto.getString("docNo");
- String statusDocReq = inputDto.getString("statusDocReq");
- Long brandId = inputDto.getLong("brandId");
- if(inputDto.getString("statusDocExchangeOut").equals(GeneralConstants.YES)) {
- statusDocExchangeOut = " AND D.status_doc IN('R', 'F') ";
- } else if(inputDto.getString("statusDocExchangeOut").equals(InventoryConstantsForKtmt.IN_PROGRESS_TRANSACTION)) {
- statusDocExchangeOut = " AND D.status_doc IN('D', 'I') ";
- } else if(inputDto.getString("statusDocExchangeOut").equals(GeneralConstants.NO)) {
- statusDocExchangeOut = " AND D.status_doc IS NULL ";
- }
- if(inputDto.getString("statusDocExchangeIn").equals(GeneralConstants.YES)) {
- statusDocExchangeIn = " AND E.status_doc IN('R', 'F') ";
- } else if(inputDto.getString("statusDocExchangeIn").equals(InventoryConstantsForKtmt.IN_PROGRESS_TRANSACTION)) {
- statusDocExchangeIn = " AND E.status_doc IN('D', 'I') ";
- } if(inputDto.getString("statusDocExchangeIn").equals(GeneralConstants.NO)) {
- statusDocExchangeIn = " AND E.status_doc IS NULL ";
- }
- kondisiWhere = GeneralConstants.EMPTY_VALUE;
- if(!GeneralConstants.EMPTY_VALUE.equals(inputDto.getString("statusDocExchangeOut")) ||
- !GeneralConstants.EMPTY_VALUE.equals(inputDto.getString("statusDocExchangeIn"))){
- kondisiWhere = " WHERE ";
- }
- List<Object[]> result = null;
- // D untuk exchange out, E untuk exchange In
- //@formatter:off
- StringBuilder filterDocNo = new StringBuilder();
- filterDocNo.append(" AND ")
- .append(CriteriaHelper.likeExpressionIgnoreCase(docNo, " A.doc_no "));
- StringBuilder filterCustomer = new StringBuilder();
- filterCustomer.append(" AND ( ")
- .append(CriteriaHelper.likeExpressionIgnoreCase(customer, " B.partner_code "))
- .append(" OR ")
- .append(CriteriaHelper.likeExpressionIgnoreCase(customer, " B.partner_name "))
- .append(" ) ");
- QueryBuilder builder = new QueryBuilder();
- builder.add(" WITH data_req_exchange AS( ")
- .add(" SELECT A.in_out_exchange_id, A.tenant_id, A.ou_id, A.doc_type_id, ")
- .add(" A.doc_no AS doc_no_req, A.doc_date AS doc_date_req, A.partner_id, ")
- .add(" f_get_partner_code(A.partner_id) AS partner_code, ")
- .add(" f_get_partner_name(A.partner_id) AS partner_name, ")
- .add(" A.brand_id, f_get_brand_code(A.brand_id) AS brand_code, ")
- .add(" f_get_brand_name(A.brand_id) AS brand_name, ")
- .add(" CASE WHEN A.status_doc = 'D' THEN 'Draft' ")
- .add(" WHEN A.status_doc = 'I' THEN 'In progress' ")
- .add(" WHEN A.status_doc = 'R' THEN 'Approved' ")
- .add(" END AS status_req, ")
- .add(" A.remark, A.version, ")
- .add(" f_get_status_cetak_report(A.in_out_exchange_id, A.doc_type_id, '").add(InventoryConstantsForKtmt.FORM_REQUEST_EXCHANGE_OUT).add("' ) AS status_print_req_exchange_out ")
- .add(" FROM ").add(InOutExchange.TABLE_NAME).add(" A ")
- .add(" WHERE A.tenant_id = :tenantId ")
- .add(" AND A.doc_type_id = :docTypeIdReqExchange ")
- .add(" AND A.ou_id = :ouId ")
- .add(" AND A.doc_date BETWEEN :dateFrom AND :dateTo ")
- .addIfNotEquals(brandId, GeneralConstants.NULL_REF_VALUE_LONG, " AND A.brand_id = :brandId ")
- .addIfNotEmpty(docNo, filterDocNo.toString())
- .addIfNotEmpty(customer, filterCustomer.toString() )
- .addIfNotEmpty(statusDocReq, " AND A.status_doc = :statusDocReq ")
- .add(" ) ")
- .add(" SELECT A.in_out_exchange_id, COALESCE(D.in_out_exchange_id, -99) AS exchange_out_id, ")
- .add(" COALESCE(E.in_out_exchange_id, -99) AS exchange_in_id, A.tenant_id, A.ou_id, A.doc_type_id, ")
- .add(" doc_no_req, doc_date_req, A.partner_id, A.partner_code, ")
- .add(" A.partner_name, A.brand_id, A.brand_code, A.brand_name, ")
- .add(" COALESCE(D.doc_no, :emptyString) AS doc_no_out, COALESCE(D.doc_date, :emptyString) AS doc_date_out, ")
- .add(" COALESCE(E.doc_no, :emptyString) AS doc_no_in, COALESCE(E.doc_date, :emptyString) AS doc_date_in, ")
- .add(" A.status_req, ")
- .add(" CASE WHEN D.status_doc = 'D' OR D.status_doc = 'I' THEN 'In progress' ")
- .add(" WHEN D.status_doc = 'R' OR D.status_doc = 'F' THEN 'Yes' ELSE 'No' ")
- .add(" END AS status_out, ")
- .add(" CASE WHEN E.status_doc = 'D' OR E.status_doc = 'I' THEN 'In progress' ")
- .add(" WHEN E.status_doc = 'R' OR E.status_doc = 'F' THEN 'Yes' ELSE 'No' ")
- .add(" END AS status_in, ")
- .add(" A.remark, A.version, ")
- .add(" A.status_print_req_exchange_out, ")
- .add(" f_get_status_cetak_report(COALESCE(D.in_out_exchange_id, -99), COALESCE(D.doc_type_id, -99), '").add(InventoryConstantsForKtmt.FORM_EXCHANGE_OUT).add("' ) AS status_print_exchange_out, ")
- .add(" f_get_status_cetak_report(COALESCE(E.in_out_exchange_id, -99), COALESCE(E.doc_type_id, -99), '").add(InventoryConstantsForKtmt.FORM_EXCHANGE_IN).add("' ) AS status_print_exchange_in ")
- .add(" FROM data_req_exchange A ")
- .add(" LEFT JOIN ").add(InOutExchange.TABLE_NAME).add(" D ON A.in_out_exchange_id = D.req_id AND A.doc_type_id = D.req_doc_type_id")
- .add(" LEFT JOIN ").add(InOutExchange.TABLE_NAME).add(" E ON D.in_out_exchange_id = E.ref_id AND D.doc_type_id = E.ref_doc_type_id")
- .add( kondisiWhere )
- .addIfNotEmpty(inputDto.getString("statusDocExchangeOut"), statusDocExchangeOut )
- .addIfNotEmpty(inputDto.getString("statusDocExchangeIn"), statusDocExchangeIn )
- .add(" ORDER BY A.doc_date_req, A.doc_no_req ");
- //@formatter:on
- if(inputDto.get("limit")!=null) builder.add(" LIMIT " + inputDto.getLong("limit"));
- if(inputDto.get("offset")!=null) builder.add(" OFFSET " + inputDto.getLong("offset"));
- log.info("builder GET -->:"+builder.toString());
- Query q = inOutExchangeDao.createNativeQuery(builder.toString());
- q.setParameter("tenantId", tenantId);
- q.setParameter("docTypeIdReqExchange", InventoryConstantsForKtmt.DOCUMENT_REQ_EXCHANGE_OUT);
- q.setParameter("dateFrom", dateFrom);
- q.setParameter("dateTo", dateTo);
- q.setParameter("ouId", ouId);
- q.setParameter("emptyString", GeneralConstants.EMPTY_VALUE);
- if(!GeneralConstants.NULL_REF_VALUE_LONG.equals(brandId)){
- q.setParameter("brandId", brandId);
- }
- if(!GeneralConstants.EMPTY_VALUE.equals(statusDocReq)){
- q.setParameter("statusDocReq", statusDocReq);
- }
- result = q.getResultList();
- return new Dto().putList("inquiryExchangeList", DtoUtil.createDtoListFromArray(result, "reqExchangeId", "exchangeOutId",
- "exchangeInId", "tenantId", "ouId", "docTypeId", "docNoReq", "docDateReq", "partnerId", "partnerCode", "partnerName",
- "brandId", "brandCode", "brandName", "docNoOut", "docDateOut", "docNoIn", "docDateIn", "statusReq", "statusOut",
- "statusIn", "remark", "version", "statusPrintRexo", "statusPrintExo", "statusPrintExi"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement