Evra70

BF GetInvoiceArListForHandoverInvoiceAr

May 5th, 2021
1,191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.14 KB | None | 0 0
  1. package org.jleaf.erp.fin.bo.handoverinvoicear;
  2.  
  3. import java.util.List;
  4.  
  5. import javax.persistence.Query;
  6.  
  7. import org.jleaf.core.AbstractBusinessFunction;
  8. import org.jleaf.core.BusinessFunction;
  9. import org.jleaf.core.Dto;
  10. import org.jleaf.core.GeneralConstants;
  11. import org.jleaf.core.annotation.ErrorList;
  12. import org.jleaf.core.annotation.Info;
  13. import org.jleaf.core.annotation.InfoIn;
  14. import org.jleaf.core.annotation.InfoOut;
  15. import org.jleaf.core.dao.CriteriaHelper;
  16. import org.jleaf.core.dao.QueryBuilder;
  17. import org.jleaf.erp.fin.dao.HandoverInvoiceArDao;
  18. import org.jleaf.erp.fin.entity.InvoiceArBalanceHandover;
  19. import org.jleaf.erp.master.MasterConstants;
  20. import org.jleaf.util.DateUtil;
  21. import org.jleaf.util.DtoUtil;
  22. import org.jleaf.util.ValidationUtil;
  23. import org.slf4j.Logger;
  24. import org.slf4j.LoggerFactory;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.stereotype.Service;
  27.  
  28. /**
  29.  * Get List InvoiceAr For Handover Invoice Ar
  30.  * @author H.Kevin, Tue Jan 21 13:28:54 WIB 2020
  31.  */
  32.  
  33. @Service
  34. @InfoIn(value = {
  35.     @Info(name = "tenantId", description = "Tenant Id", type = Long.class, required = true),
  36.     @Info(name = "ouId", description = "Ou Id", type = Long.class, required = true),
  37.     @Info(name = "customerCodeName", description = "customer Code Name", type = String.class, required = true),
  38.     @Info(name = "dueDateTypeCode", description = "Code of Due Date Type", type = String.class, required = true),
  39.     @Info(name = "limit", description = "limit", type = Long.class, required = false),
  40.     @Info(name = "offset", description = "offset", type = Long.class, required = false)
  41. })
  42. @InfoOut(value = {
  43.     @Info(name = "invoiceArList", description = "List invoiceAr(id, tenantId, ouId, invoiceId, docTypeId, docTypeDesc, docNo, docDate, partnerId,partnerCode, partnerName, dueDate, currCode, invoiceAmount, paymentAmount, osAmount, version)",
  44.             type = List.class, required = true)
  45. })
  46. @ErrorList(errorKeys = { })
  47. public class GetInvoiceArListForHandoverInvoiceAr extends AbstractBusinessFunction implements BusinessFunction {
  48.    
  49.     private static final Logger log = LoggerFactory.getLogger(GetInvoiceArListForHandoverInvoiceAr.class);
  50.    
  51.     @Autowired
  52.     HandoverInvoiceArDao handoverInvoiceArDao;
  53.    
  54.     //LIMIT OFFSET BELUMM
  55.    
  56.     @Override
  57.     public String getDescription () {
  58.         return "Get Invoice Ar List for handover invoice";
  59.     }
  60.    
  61.     @SuppressWarnings("unchecked")
  62.     @Override
  63.     public Dto execute(Dto inputDto) throws Exception {
  64.         ValidationUtil.valDtoContainsKey(inputDto, "tenantId");
  65.         ValidationUtil.valDtoContainsKey(inputDto, "ouId");
  66.         ValidationUtil.valDtoContainsKey(inputDto, "customerCodeName");
  67.         ValidationUtil.valDtoContainsKey(inputDto, "dueDateTypeCode");
  68.        
  69.         List<Object[]> result = null;
  70.         Long tenantId = inputDto.getLong("tenantId");
  71.         Long ouId = inputDto.getLong("ouId");
  72.         String customerCodeName = ((inputDto.get("customerCodeName")) == null ? GeneralConstants.EMPTY_VALUE : inputDto.get("customerCodeName").toString());
  73.         String dueDateTypeCode = inputDto.getString("dueDateTypeCode");
  74.         Long limit = inputDto.getLong("limit");
  75.         Long offset = inputDto.getLong("offset");
  76.        
  77.         QueryBuilder builder = new QueryBuilder();
  78.        
  79.         builder.add(" SELECT A.invoice_ar_balance_handover_id AS id, A.tenant_id, B.ou_id, A.invoice_id, ");
  80.         builder.add("       A.doc_type_id, f_get_doc_desc(A.doc_type_id) AS doc_type_desc, B.doc_no, B.doc_date, B.partner_id, ");
  81.         builder.add("       f_get_partner_code(B.partner_id) AS partner_code, f_get_partner_name(B.partner_id) AS partner_name, ");
  82.         builder.add("       B.due_date, B.curr_code, B.amount AS invoice_amount, B.payment_amount, ");
  83.         builder.add("       (B.amount - B.payment_amount) AS outstanding_amount, A.version, A.flg_handover, A.flg_handover_back ");
  84.        
  85.         builder.add(" FROM ").add(InvoiceArBalanceHandover.TABLE_NAME).add(" A ");
  86.         builder.add("       INNER JOIN vw_fi_os_debt_invoice_ar B ON A.invoice_id = B.id AND A.doc_type_id = B.doc_type_id ");
  87.        
  88.         // update 20210105, sasa-230 dokumen dgn status handover back y juga bisa muncul
  89.         builder.add(" WHERE (A.flg_handover =:NO OR (A.flg_handover = :YES AND A.flg_handover_back = :YES ))");
  90.         builder.add("       AND A.tenant_id = :tenantId ");
  91.         builder.add("       AND B.ou_id = :ouId ");
  92.        
  93.         builder.addIfNotEmpty(customerCodeName, new StringBuilder()
  94.                 .append(" AND ( " )
  95.                 .append(CriteriaHelper.likeExpressionIgnoreCase(customerCodeName, " f_get_partner_code(B.partner_id) "))
  96.                 .append(" OR ")
  97.                 .append(CriteriaHelper.likeExpressionIgnoreCase(customerCodeName, " f_get_partner_name(B.partner_id) "))
  98.                 .append(" ) ").toString() );
  99.        
  100.         builder.addIfElseEquals(dueDateTypeCode, MasterConstants.DUE_DATE_TYPE_NOT_YET_DUE,
  101.                 " AND B.due_date > :dueDateNow ", "");
  102.         builder.addIfElseEquals(dueDateTypeCode, MasterConstants.DUE_DATE_TYPE_CURRENT,
  103.                 " AND B.due_date = :dueDateNow ", "");
  104.         builder.addIfElseEquals(dueDateTypeCode, MasterConstants.DUE_DATE_TYPE_OVERDUE,
  105.                 " AND B.due_date < :dueDateNow ", "");
  106.            
  107.         builder.add(" ORDER BY B.doc_date ASC, B.doc_no ASC ");
  108.         builder.addIfNotNull(limit, " LIMIT :limit ");
  109.         builder.addIfNotNull(offset, " OFFSET :offset ");
  110.        
  111.         Query query = handoverInvoiceArDao.createNativeQuery(builder.toString());
  112.         query.setParameter("tenantId", tenantId);
  113.         query.setParameter("ouId", ouId);
  114.         query.setParameter("NO", GeneralConstants.NO);
  115.         query.setParameter("YES", GeneralConstants.YES);
  116.         if (!GeneralConstants.EMPTY_VALUE.equals(dueDateTypeCode)) {
  117.             query.setParameter("dueDateNow", DateUtil.dateNow());
  118.         }
  119.         if (limit!=null && offset!=null) {
  120.             query.setParameter("limit", limit.intValue());
  121.             query.setParameter("offset", offset.intValue());
  122.         }
  123.        
  124.         //log.debug("builder nyahhh  >>" +builder+"\n\n");
  125.         //log.debug("query nyahhh  >>" +query+"\n\n");
  126.        
  127.         result = query.getResultList();
  128.        
  129.         return new Dto().put("invoiceArList", DtoUtil.createDtoListFromArray(result,
  130.                 "id", "tenantId", "ouId", "invoiceId", "docTypeId", "docTypeDesc", "docNo", "docDate",
  131.                 "partnerId","partnerCode", "partnerName", "dueDate", "currCode",
  132.                 "invoiceAmount", "paymentAmount", "osAmount", "version","flgHandover", "flgHandoverBack"));
  133.        
  134.     }  
  135. }
Advertisement
Add Comment
Please, Sign In to add comment