abirama62

BT addCombineTax

Jul 16th, 2021
1,471
83 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.jleaf.erp.fin.bo.combinetaxinvoice;
  2.  
  3. import org.jleaf.core.BusinessFunction;
  4. import org.jleaf.core.BusinessTransaction;
  5. import org.jleaf.core.CoreException;
  6. import org.jleaf.core.DefaultBusinessTransaction;
  7. import org.jleaf.core.Dto;
  8. import org.jleaf.core.GeneralConstants;
  9. import org.jleaf.core.annotation.Info;
  10. import org.jleaf.core.annotation.InfoIn;
  11. import org.jleaf.core.annotation.InfoOut;
  12. import org.jleaf.erp.fin.FinanceConstants;
  13. import org.jleaf.erp.fin.FinanceExceptionConstants;
  14. import org.jleaf.erp.fin.dao.AdminCombineTaxDao;
  15. import org.jleaf.erp.fin.dao.InvoiceArDao;
  16. import org.jleaf.erp.fin.dao.InvoiceArItemDao;
  17. import org.jleaf.erp.fin.dao.InvoiceArTaxDao;
  18. import org.jleaf.erp.fin.entity.AdminCombineTax;
  19. import org.jleaf.erp.fin.entity.InvoiceAr;
  20. import org.jleaf.erp.fin.entity.InvoiceArItem;
  21. import org.jleaf.erp.fin.entity.InvoiceArTax;
  22. import org.jleaf.erp.master.MasterConstants;
  23. import org.jleaf.util.GsonUtil;
  24. import org.jleaf.util.ValidationUtil;
  25. import org.jleaf.validator.CommonBusinessValidator;
  26. import org.slf4j.Logger;
  27. import org.slf4j.LoggerFactory;
  28. import org.springframework.beans.factory.annotation.Autowired;
  29. import org.springframework.beans.factory.annotation.Qualifier;
  30. import org.springframework.stereotype.Service;
  31.  
  32. import java.util.ArrayList;
  33. import java.util.List;
  34. import java.util.concurrent.TimeUnit;
  35.  
  36. @Service
  37. @InfoIn(value={
  38.     @Info(name="tenantLoginId", description="tenant Login Id", type=Long.class),
  39.     @Info(name="datetime", description="doc date", type=String.class),
  40.     @Info(name="userId", description="ou Id", type=Long.class),
  41.     @Info(name="ouId", description="ou Id", type=Long.class),
  42.     @Info(name="dateYearMonth", description="date year month", type=String.class),
  43.     @Info(name="sessionId", description="date year month", type=String.class),
  44.     @Info(name="taxNo", description="tax no", type=String.class),
  45.     @Info(name="taxDate", description="tax date", type=String.class),
  46.     @Info(name="docNo", description="doc no", type=String.class),
  47.     @Info(name="docDate", description="doc date", type=String.class)
  48. })
  49. @InfoOut(value={
  50.        
  51. })
  52.  
  53. public class AddCombineTaxInvoice extends DefaultBusinessTransaction implements BusinessTransaction{
  54.     Logger log = LoggerFactory.getLogger(AddCombineTaxInvoice.class);
  55.    
  56.     @Autowired
  57.     private InvoiceArDao invoiceArDao;
  58.  
  59.     @Autowired
  60.     private InvoiceArItemDao invoiceArItemDao;
  61.  
  62.     @Autowired
  63.     private InvoiceArTaxDao invoiceArTaxDao;
  64.    
  65.     @Autowired
  66.     private AdminCombineTaxDao adminCombineTaxDao;
  67.    
  68.     @Autowired
  69.     @Qualifier("findAdminCombineTaxById")
  70.     private BusinessFunction findAdminCombineTaxById;
  71.    
  72.     /*@Autowired
  73.     private JdbcTemplate jdbcTemplate;*/
  74.  
  75.     @Autowired
  76.     @Qualifier("findSystemConfigByParamCode")
  77.     private BusinessFunction findSystemConfigByParamCode;
  78.  
  79.     @Autowired
  80.     @Qualifier("findTaxByIndex")
  81.     private BusinessFunction findTaxByIndex;
  82.    
  83.     @Autowired
  84.     @Qualifier("findCombineTaxStatusByDateYearMonth")
  85.     private BusinessFunction findCombineTaxStatusByDateYearMonth;
  86.  
  87.     @Autowired
  88.     @Qualifier("getInvoiceListForCombineTax")
  89.     private BusinessFunction getInvoiceListForCombineTax;
  90.  
  91.     @Autowired
  92.     @Qualifier("getSummaryAmountInvoiceSystemForCombineTax")
  93.     private BusinessFunction getSummaryAmountInvoiceSystemForCombineTax;
  94.    
  95.     @Autowired
  96.     @Qualifier("valCombineTaxInvoiceHasDataToProcess")
  97.     private BusinessFunction valCombineTaxInvoiceHasDataToProcess;
  98.    
  99.     @Override
  100.     public String getDescription() {
  101.         return "Add Combine Tax Invoice";
  102.     }
  103.  
  104.     @Override
  105.     public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
  106.         ValidationUtil.valBlankOrNull(inputDto, "tenantLoginId");
  107.         ValidationUtil.valBlankOrNull(inputDto, "datetime");
  108.         ValidationUtil.valBlankOrNull(inputDto, "userId");
  109.         ValidationUtil.valBlankOrNull(inputDto, "ouId");
  110.         ValidationUtil.valBlankOrNull(inputDto, "dateYearMonth");
  111.         ValidationUtil.valBlankOrNull(inputDto, "sessionId");
  112.         ValidationUtil.valBlankOrNull(inputDto, "taxNo");
  113.         ValidationUtil.valBlankOrNull(inputDto, "taxDate");
  114.         ValidationUtil.valBlankOrNull(inputDto, "docNo");
  115.         ValidationUtil.valBlankOrNull(inputDto, "docDate");
  116.  
  117.         Long userLoginId = inputDto.getLong("userLoginId");
  118.         Long tenantLoginId = inputDto.getLong("tenantLoginId");
  119.         Long roleLoginId = inputDto.getLong("roleLoginId");
  120.         String datetime = inputDto.getString("datetime");
  121.  
  122.         Long ouId = inputDto.getLong("ouId");
  123.         String docNo = inputDto.getString("docNo");
  124.         String docDate = inputDto.getString("docDate");
  125.         String taxNo = inputDto.getString("taxNo");
  126.         String taxDate = inputDto.getString("taxDate");
  127.         String periode = inputDto.getString("dateYearMonth");
  128.  
  129.         log.debug("Hasil Periode : "+periode+", Tax Date : "+taxDate);
  130.         CommonBusinessValidator.valCompareDate(periode.concat("01"), FinanceConstants.PERIOD_MINIMAL,
  131.                 CommonBusinessValidator.COMPARE_GREATER_EQUAL, "Periode",
  132.                 "Period Minimal");
  133.  
  134.         //16 Juli 2021, Periode dan taxDate boleh beda
  135.         /*
  136.         if (!CommonBusinessValidator.compareDate(periode.concat("01").toString(),
  137.                 taxDate.substring(0, 6).concat("01").toString(), CommonBusinessValidator.COMPARE_EQUAL, "Periode", "Tax Date")) {
  138.             throw new CoreException(FinanceExceptionConstants.PERIOD_NOT_EQUALS_TAX_DATE, periode.concat("01").toString(),
  139.                     taxDate.substring(0, 6).concat("01").toString());
  140.         }
  141.         */
  142.  
  143.         Dto taxDto = new Dto();
  144.         taxDto.put("tenantId", tenantLoginId);
  145.         taxDto.put("code", FinanceConstants.TAX_CODE_PPN);
  146.  
  147.         taxDto = findTaxByIndex.execute(taxDto);
  148.        
  149.         Dto inputForFindCombineTaxStatusDto = new Dto();
  150.         inputForFindCombineTaxStatusDto.put("tenantLoginId", inputDto.get("tenantLoginId"));
  151.         inputForFindCombineTaxStatusDto.put("ouId", inputDto.get("ouId"));
  152.         inputForFindCombineTaxStatusDto.put("dateYearMonth", inputDto.get("dateYearMonth"));
  153.        
  154.         Dto outputForFindCombineTaxStatusDto = findCombineTaxStatusByDateYearMonth.execute(inputForFindCombineTaxStatusDto);
  155.         if(outputForFindCombineTaxStatusDto.get("flgStatus").equals(GeneralConstants.YES)){
  156.             throw new CoreException(FinanceExceptionConstants.ADMIN_COMBINE_TAX_ALREADY_PROCESSED, inputDto.get("dateYearMonth"));
  157.         } else if(outputForFindCombineTaxStatusDto.get("flgStatus").equals(FinanceConstants.IN_PROGRESS)){
  158.             throw new CoreException(FinanceExceptionConstants.ADMIN_COMBINE_TAX_IN_PROGRESS, inputDto.get("dateYearMonth"));
  159.         }
  160.  
  161.         // Get valuta gov
  162.         Dto inputCurrCodeGovDto = new Dto();
  163.         inputCurrCodeGovDto.put("tenantId", inputDto.getLong("tenantLoginId"));
  164.         inputCurrCodeGovDto.put("parameterCode", MasterConstants.PARAMETER_CODE_VALUTA_RESMI);
  165.  
  166.         Dto outputCurrCodeGovDto = findSystemConfigByParamCode.execute(inputCurrCodeGovDto);
  167.         String currCodeGov = outputCurrCodeGovDto.getString("value");
  168.        
  169.         //validasi harus ada data yg di process
  170.         Dto inputForVallCombineTaxInvoiceDto = new Dto();
  171.         inputForVallCombineTaxInvoiceDto.put("tenantId", inputDto.get("tenantLoginId"));
  172.         inputForVallCombineTaxInvoiceDto.put("ouId", inputDto.get("ouId"));
  173.         inputForVallCombineTaxInvoiceDto.put("dateYearMonth", inputDto.get("dateYearMonth"));
  174.         valCombineTaxInvoiceHasDataToProcess.execute(inputForVallCombineTaxInvoiceDto);
  175.  
  176.         Dto outputGetInvoiceArTaxListByInvoiceAr = getInvoiceListForCombineTax.execute(new Dto()
  177.                 .put("tenantLoginId", tenantLoginId)
  178.                 .put("ouId", ouId)
  179.                 .put("dateYearMonth", periode));
  180.         List<Dto> invoiceList = outputGetInvoiceArTaxListByInvoiceAr.getList("invoiceList");
  181.  
  182.         Dto summaryInvoiceSystemDto = getSummaryAmountInvoiceSystemForCombineTax.execute(new Dto()
  183.                 .put("tenantLoginId", tenantLoginId)
  184.                 .put("ouId", ouId)
  185.                 .put("dateYearMonth", periode));
  186.         Double totalBaseAmountSystem = summaryInvoiceSystemDto.getDouble("totalBaseAmountSystem");
  187.         Double totalTaxAmountSystem = summaryInvoiceSystemDto.getDouble("totalTaxAmountSystem");
  188.         Double totalAmountSystem = summaryInvoiceSystemDto.getDouble("totalAmountSystem");
  189.  
  190.         // prepare param for combine tax invoice
  191.         Dto addAdminCombineTaxDto = new Dto();
  192.         addAdminCombineTaxDto.put("tenantId", tenantLoginId);
  193.         addAdminCombineTaxDto.put("ouId", ouId);
  194.         addAdminCombineTaxDto.put("dateYearMonth", periode);
  195.         addAdminCombineTaxDto.put("flgStatus", FinanceConstants.IN_PROGRESS);
  196.         addAdminCombineTaxDto.put("refDocTypeId", GeneralConstants.NULL_REF_VALUE_LONG);
  197.         addAdminCombineTaxDto.put("refId", GeneralConstants.NULL_REF_VALUE_LONG);
  198.         prepareInsertAudit(addAdminCombineTaxDto, userLoginId, datetime);
  199.         prepareUpdateAudit(addAdminCombineTaxDto, userLoginId, datetime);
  200.  
  201.         // prepare param for invoice AR
  202.         Dto invoiceArDto = new Dto();
  203.         invoiceArDto.put("tenantId", tenantLoginId);
  204.         invoiceArDto.put("docTypeId", FinanceConstants.DOC_TYPE_COMBINE_TAX);
  205.         invoiceArDto.put("docNo", docNo);
  206.         invoiceArDto.put("docDate", docDate);
  207.         invoiceArDto.put("ouId", ouId);
  208.         invoiceArDto.put("partnerId", GeneralConstants.NULL_REF_VALUE_LONG);
  209.         invoiceArDto.put("extDocNo", GeneralConstants.EMPTY_VALUE);
  210.         invoiceArDto.put("extDocDate", GeneralConstants.EMPTY_VALUE);
  211.         invoiceArDto.put("refDocTypeId", GeneralConstants.NULL_REF_VALUE_LONG);
  212.         invoiceArDto.put("refId", GeneralConstants.NULL_REF_VALUE_LONG);
  213.         invoiceArDto.put("dueDate", GeneralConstants.EMPTY_VALUE);
  214.         invoiceArDto.put("currCode", currCodeGov);
  215.         invoiceArDto.put("totalTaxBaseAmount", totalBaseAmountSystem);
  216.         invoiceArDto.put("totalAmount", totalAmountSystem);
  217.         invoiceArDto.put("taxAmount", totalTaxAmountSystem);
  218.         invoiceArDto.put("remark", GeneralConstants.EMPTY_VALUE);
  219.         invoiceArDto.put("statusDoc", FinanceConstants.DRAFT_TRANSACTION);
  220.         invoiceArDto.put("workflowStatus", FinanceConstants.WORKFLOW_STATUS_DRAFT);
  221.         prepareInsertAudit(invoiceArDto, userLoginId, datetime);
  222.         prepareUpdateAudit(invoiceArDto, userLoginId, datetime);
  223.  
  224.         List<Dto> invoiceItemList = new ArrayList<Dto>();
  225.         if(invoiceList!=null && invoiceList.size()>0){
  226.             for (Dto invoiceListTemp : invoiceList) {
  227.                 Dto invoiceItemDto = new Dto();
  228.                 invoiceItemDto.put("invoiceArId", GeneralConstants.NULL_REF_VALUE_LONG);
  229.                 invoiceItemDto.put("tenantId", tenantLoginId);
  230.                 invoiceItemDto.put("ouId", ouId);
  231.                 invoiceItemDto.put("refDocTypeId", invoiceListTemp.get("docTypeId"));
  232.                 invoiceItemDto.put("refArBalanceId", invoiceListTemp.get("invoiceArBalanceId"));
  233.                 invoiceItemDto.put("amount", invoiceListTemp.get("amount"));
  234.                 invoiceItemDto.put("baseAmount", invoiceListTemp.get("baseAmount"));
  235.                 invoiceItemDto.put("taxAmount", invoiceListTemp.get("taxAmount"));
  236.                 this.prepareInsertAudit(invoiceItemDto, userLoginId, datetime);
  237.                 this.prepareUpdateAudit(invoiceItemDto, userLoginId, datetime);
  238.  
  239.                 invoiceItemList.add(invoiceItemDto);
  240.             }
  241.         }
  242.  
  243.         // prepare param for invoice AR Tax
  244.         Dto invoiceArTaxDto = new Dto();
  245.         invoiceArTaxDto.put("tenantId", tenantLoginId);
  246.         invoiceArTaxDto.put("invoiceArId", GeneralConstants.NULL_REF_VALUE_LONG);
  247.         invoiceArTaxDto.put("taxId", taxDto.get("id"));
  248.         invoiceArTaxDto.put("flagAmount", taxDto.get("flagAmount"));
  249.         invoiceArTaxDto.put("taxPercentage", taxDto.get("percentage"));
  250.         invoiceArTaxDto.put("baseAmount", 0D);
  251.         invoiceArTaxDto.put("taxAmount", 0D);
  252.         invoiceArTaxDto.put("taxNo", taxNo);
  253.         invoiceArTaxDto.put("taxDate", taxDate);
  254.         invoiceArTaxDto.put("taxCurrCode", currCodeGov);
  255.         invoiceArTaxDto.put("govTaxAmount", 0D);
  256.         invoiceArTaxDto.put("remark", GeneralConstants.EMPTY_VALUE);
  257.         prepareInsertAudit(invoiceArTaxDto, userLoginId, datetime);
  258.         prepareUpdateAudit(invoiceArTaxDto, userLoginId, datetime);
  259.  
  260.         inputDto.putDto("adminCombineTaxDto", addAdminCombineTaxDto);
  261.         inputDto.putDto("invoiceArDto", invoiceArDto);
  262.         inputDto.putDto("invoiceArTaxDto", invoiceArTaxDto);
  263.         inputDto.put("invoiceItemList", invoiceItemList);
  264.         return null;
  265.     }
  266.  
  267.     @Override
  268.     public Dto process(Dto inputDto, Dto originalDto) throws Exception {
  269.        
  270.         Dto adminCombineTaxDto = inputDto.getDto("adminCombineTaxDto");
  271.         Dto invoiceArDto = inputDto.getDto("invoiceArDto");
  272.         Dto invoiceArTaxDto = inputDto.getDto("invoiceArTaxDto");
  273.         Dto invoiceItemList = inputDto.getDto("invoiceItemList");
  274.  
  275.         InvoiceAr invoiceAr = GsonUtil.fromDto(invoiceArDto, InvoiceAr.class);
  276.         invoiceArDao.persist(invoiceAr);
  277.  
  278.         invoiceArTaxDto.put("invoiceArId", invoiceAr.getId());
  279.         InvoiceArTax invoiceArTax = GsonUtil.fromDto(invoiceArTaxDto, InvoiceArTax.class);
  280.         invoiceArTaxDao.persist(invoiceArTax);
  281.  
  282.         List<Dto> invoiceArItemList = inputDto.getList("invoiceItemList");
  283.         for (Dto invoiceArItemDto : invoiceArItemList) {
  284.             invoiceArItemDto.put("invoiceArId", invoiceAr.getId());
  285.  
  286.             InvoiceArItem invoiceArItem = GsonUtil.fromDto(invoiceArItemDto, InvoiceArItem.class);
  287.             invoiceArItemDao.persist(invoiceArItem);
  288.         }
  289.  
  290.         adminCombineTaxDto.put("refId", invoiceAr.getId());
  291.         adminCombineTaxDto.put("refDocTypeId", invoiceAr.getDocTypeId());
  292.         log.info("FI ADMIN COMBINE TAX INVOICE DTO : " +adminCombineTaxDto.toString());
  293.  
  294.         AdminCombineTax adminCombineTax = GsonUtil.fromDto(adminCombineTaxDto, AdminCombineTax.class);
  295.         adminCombineTaxDao.persist(adminCombineTax);
  296.        
  297.         return new Dto(adminCombineTax).put("docNo",adminCombineTaxDto.getString("docNo"));
  298.     }
  299.    
  300. }
  301.  
RAW Paste Data