Advertisement
aadddrr

GetInvoiceArBalanceListAdvance

Oct 18th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.32 KB | None | 0 0
  1. package org.jleaf.erp.fin.bo.paymentorderar;
  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.FinanceConstants;
  18. import org.jleaf.erp.fin.dao.InvoiceArBalanceDao;
  19. import org.jleaf.erp.master.MasterConstants;
  20. import org.jleaf.erp.master.entity.Partner;
  21. import org.jleaf.util.DtoUtil;
  22. import org.jleaf.util.ValidationUtil;
  23. import org.jleaf.workflow.core.jpa.entity.MasterDocument;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.stereotype.Service;
  26.  
  27. /**
  28.  * JLEAFFIN-107
  29.  * Get invoice ar balance by advance parameter
  30.  *
  31.  * @author ivan, Sep 14, 2018
  32.  * @since 1.0.0
  33.  * @version 1.0.0
  34.  */
  35. //@formatter:off
  36. @Service
  37. @InfoIn(value = {
  38.     @Info(name = "tenantId", description = "Tenant id", type = Long.class),
  39.     @Info(name = "datetime", description = "Datetime", type = String.class),
  40.     @Info(name = "ouId", description = "OU id", type = Long.class),
  41.     @Info(name = "docTypeId", description = "Doc type id", type = Long.class),
  42.     @Info(name = "customerId", description = "Cutomer id", type = String.class),
  43.     @Info(name = "customerCodeName", description = "Customer code or name", type = String.class),
  44.     @Info(name = "currCode", description = "Currency code", type = String.class),
  45.     @Info(name = "dueDate", description = "Due date", type = String.class),
  46.     @Info(name = "docDateFrom", description = "Doc date from", type = String.class),
  47.     @Info(name = "docDateTo", description = "Doc date to", type = String.class),
  48.     @Info(name = "docNo", description = "Doc No", type = String.class),
  49.     @Info(name = "remark", description = "Remark", type = String.class)
  50. })
  51. @InfoOut(value = {
  52.     @Info(name = "invoiceArBalanceList", description = "list of invoice ar balance(uniqueKey, invoiceArBalanceId, ouId, docTypeId, docDesc, invoiceArId, docNo, docDate, partnerId, parnerCode, partnerName, dueDate, invoiceNo, invoiceDate, curCode, amount, remark, paymentAmount, flagPayment, remainingAmount, version)", type = List.class)
  53. })
  54. @ErrorList(errorKeys ={
  55.        
  56. })
  57. //@formatter:off
  58. public class GetInvoiceArBalanceListAdvance extends AbstractBusinessFunction implements BusinessFunction {
  59.     @Autowired
  60.     private InvoiceArBalanceDao invoiceArBalanceDao;
  61.    
  62.     @Override
  63.     public String getDescription() {
  64.         return "Get Invoice AR balance List by advance parameter";
  65.     }
  66.    
  67.     @SuppressWarnings("unchecked")
  68.     @Override
  69.     public Dto execute(Dto inputDto) throws Exception {
  70. //      @Info(name = "tenantId", description = "Tenant id", type = Long.class),
  71. //      @Info(name = "ouId", description = "OU id", type = Long.class),
  72. //      @Info(name = "customerId", description = "Customer id", type = String.class),
  73. //      @Info(name = "currCode", description = "Currency code", type = String.class),
  74. //      @Info(name = "dueDate", description = "Due date", type = String.class),
  75. //      @Info(name = "remark", description = "Remark", type = String.class)
  76.        
  77.         ValidationUtil.valDtoContainsKey(inputDto, "tenantId");
  78.         ValidationUtil.valDtoContainsKey(inputDto, "ouId");
  79.         ValidationUtil.valDtoContainsKey(inputDto, "customerId");
  80.         ValidationUtil.valBlankOrNull(inputDto, "currCode");
  81.         ValidationUtil.valDtoContainsKey(inputDto, "dueDate");
  82.         ValidationUtil.valDtoContainsKey(inputDto, "remark");
  83.        
  84.         Long tenantId = inputDto.getLong("tenantId");
  85.         String datetime = inputDto.getString("datetime");
  86.        
  87.         Long ouId = inputDto.getLong("ouId");
  88.         Long customerId = inputDto.getLong("customerId");
  89.         String currCode = inputDto.getString("currCode");
  90.         String dueDate = inputDto.getString("dueDate");
  91.         String remark = inputDto.getString("remark");
  92.         String customerCodeName = inputDto.getString("customerCodeName");
  93.         String docDateFrom = inputDto.getString("docDateFrom");
  94.         String docDateTo = inputDto.getString("docDateTo");
  95.         //String flgPayment = inputDto.getString("flgPayment");
  96.         String dueDateFrom = GeneralConstants.START_DATE;
  97.         String dueDateTo = GeneralConstants.END_DATE;
  98.        
  99.         if(docDateFrom.isEmpty()){
  100.             docDateFrom = GeneralConstants.START_DATE;
  101.         }
  102.        
  103.         if(docDateTo.isEmpty()){
  104.             docDateTo = GeneralConstants.END_DATE;
  105.         }
  106.        
  107.         if(MasterConstants.DUE_DATE_TYPE_OVERDUE.equals(dueDate)){
  108.             dueDateTo = datetime.substring(0,8);
  109.         } else if(MasterConstants.DUE_DATE_TYPE_CURRENT.equals(dueDate)){
  110.             dueDateFrom = datetime.substring(0,8);
  111.             dueDateTo = dueDateFrom;
  112.         } else if(MasterConstants.DUE_DATE_TYPE_NOT_YET_DUE.equals(dueDate)){
  113.             dueDateFrom = datetime.substring(0,8);
  114.         }
  115.        
  116.         List<Object[]> result = null;
  117.         /**
  118.          * invoiceArBalanceId, ouId, docTypeId,
  119.          * invoiceArId, docNo, docDate, extDocNo,
  120.          * extDocDate, refDocTypeId, refId,
  121.          * partnerId, parnerCode, partnerName, dueDate,
  122.          * curCode, amount, remark, paymentAmount,
  123.          * flagPayment, version
  124.          */
  125.        
  126.         StringBuilder filterCustomerCodeName = new StringBuilder();
  127.         filterCustomerCodeName.append(" AND ( ")
  128.         .append(CriteriaHelper.likeExpressionIgnoreCase(customerCodeName, "B.partner_code"))
  129.         .append(" OR ")
  130.         .append(CriteriaHelper.likeExpressionIgnoreCase(customerCodeName, "B.partner_name"))
  131.         .append(" ) ");
  132.        
  133.         StringBuilder filterRemark = new StringBuilder();
  134.         filterRemark.append(" AND ").append(CriteriaHelper.likeExpressionIgnoreCase(remark, "A.remark"));
  135.        
  136.         QueryBuilder builder = new QueryBuilder();
  137.         builder.add(" SELECT '' || A.id || A.doc_type_id AS unique_key, A.id, A.ou_id, A.doc_type_id, C.doc_desc ")
  138.                 .add(" , A.invoice_ar_id, A.doc_no, A.doc_date ")
  139.                 .add(" , A.partner_id,  B.partner_code, B.partner_name, A.due_date ")
  140.                 .add(" , A.invoice_no, A.invoice_date ")
  141.                 .add(" , A.curr_code, A.amount, A.remark, A.payment_amount ")
  142.                 .add(" , A.flg_payment, (A.amount-A.payment_amount) AS remaining_amount, A.version ")
  143.             .add(" FROM vw_fi_os_all_invoice_ar A ")
  144.             .add(" INNER JOIN ").add(Partner.TABLE_NAME).add(" B ON A.partner_id = B.partner_id ")
  145.                 .add(" AND A.tenant_id = B.tenant_id ")
  146.             .add(" INNER JOIN ").add(MasterDocument.TABLE_NAME).add(" C ON A.doc_type_id = C.doc_type_id ")
  147.             .add(" WHERE A.tenant_id = :tenantId ")
  148.                 .add(" AND A.doc_type_id IN (") .add(FinanceConstants.DOCUMENT_RETURN_PURCH_INVOICE)
  149.                 .add(", ") .add(FinanceConstants.DOCUMENT_RETURN_VAT_IN) .add(")")
  150.                 .add(" AND A.doc_date BETWEEN :docDateFrom AND :docDateTo ")
  151.                 .add(" AND A.due_date BETWEEN :dueDateFrom AND :dueDateTo ")
  152.                 .addIfNotEmpty(currCode, " AND A.curr_code = :currCode ")
  153.                 .addIfNotEquals(ouId, GeneralConstants.NULL_REF_VALUE_LONG, " AND A.ou_id = :ouId ")
  154.                 .addIfNotEquals(customerId, GeneralConstants.NULL_REF_VALUE_LONG, " AND A.partner_id = :customerId ")
  155.                 //View yg digunakan sudah filter yg outstanding, jadi tidak perlu filter flag payment lagi
  156.                 //.addIfNotEmpty(flgPayment, " AND A.flg_payment = '"+flgPayment+"' ")
  157.                 .addIfNotEmpty(customerCodeName, filterCustomerCodeName.toString())
  158.                 .addIfNotEmpty(remark, filterRemark.toString())
  159.             .add(" ORDER BY invoice_no, invoice_date, C.doc_desc, A.doc_no, A.doc_date ");
  160.        
  161.         Query q = invoiceArBalanceDao.createNativeQuery(builder.toString());
  162.         q.setParameter("tenantId", tenantId);
  163.         q.setParameter("docDateFrom", docDateFrom);
  164.         q.setParameter("docDateTo", docDateTo);
  165.         q.setParameter("dueDateTo", dueDateTo);
  166.         q.setParameter("dueDateFrom", dueDateFrom);
  167.         if (!GeneralConstants.EMPTY_VALUE.equals(currCode)) {
  168.             q.setParameter("currCode", currCode);
  169.         }
  170.         if (!GeneralConstants.NULL_REF_VALUE_LONG.equals(ouId)) {
  171.             q.setParameter("ouId", ouId);
  172.         }
  173.         if (!GeneralConstants.NULL_REF_VALUE_LONG.equals(customerId)) {
  174.             q.setParameter("customerId", customerId);
  175.         }
  176.        
  177.         result = q.getResultList();
  178.        
  179.         return new Dto().put("invoiceArBalanceList", DtoUtil.createDtoListFromArray(result,
  180.                 "uniqueKey", "invoiceArBalanceId", "ouId", "docTypeId", "docDesc", "invoiceArId", "docNo", "docDate",
  181.                 "partnerId", "partnerCode", "partnerName", "dueDate", "invoiceNo", "invoiceDate", "currCode", "amount", "remark",
  182.                 "paymentAmount", "flagPayment", "remainingAmount", "version"));
  183.     }
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement