abirama62

backup_VoidPosShopForSasaObsolete

Apr 24th, 2020
754
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.jleaf.erp.pos_intgr.bo.pos;
  2.  
  3. import org.jleaf.common.CommonConstants;
  4. import org.jleaf.common.CommonExceptionConstants;
  5. import org.jleaf.core.*;
  6. import org.jleaf.core.annotation.ErrorList;
  7. import org.jleaf.core.annotation.Info;
  8. import org.jleaf.core.annotation.InfoIn;
  9. import org.jleaf.core.annotation.InfoOut;
  10. import org.jleaf.core.dao.QueryBuilder;
  11. import org.jleaf.erp.cb.dao.BalanceSettlementDao;
  12. import org.jleaf.erp.cb.dao.CashBankBalanceDao;
  13. import org.jleaf.erp.cb.entity.BalanceSettlement;
  14. import org.jleaf.erp.cb.entity.CashBankBalance;
  15. import org.jleaf.erp.inv.dao.LogProductBalanceStockDao;
  16. import org.jleaf.erp.inv.dao.ProductBalanceStockDao;
  17. import org.jleaf.erp.inv.entity.LogProductBalanceStock;
  18. import org.jleaf.erp.inv.entity.ProductBalanceStock;
  19. import org.jleaf.erp.master.MasterConstants;
  20. import org.jleaf.erp.pos_intgr.PosIntegrationConstants;
  21. import org.jleaf.erp.pos_intgr.PosIntegrationExceptionConstants;
  22. import org.jleaf.erp.pos_intgr.PosIntegrationExceptionConstantsForSasa;
  23. import org.jleaf.erp.pos_intgr.dao.*;
  24. import org.jleaf.erp.pos_intgr.entity.*;
  25. import org.jleaf.util.Calc;
  26. import org.jleaf.util.GsonUtil;
  27. import org.jleaf.util.ValidationUtil;
  28. import org.slf4j.Logger;
  29. import org.slf4j.LoggerFactory;
  30. import org.springframework.beans.factory.annotation.Autowired;
  31. import org.springframework.beans.factory.annotation.Qualifier;
  32. import org.springframework.stereotype.Service;
  33.  
  34. import javax.persistence.Query;
  35. import java.util.*;
  36.  
  37. /**
  38.  * Void POS Shop
  39.  *
  40.  * @author WTC, May 10, 2013
  41.  * @version 1.0.0
  42.  */
  43.  
  44. /**
  45.  * Menambahkan insert ke in_log_nempil_barang_balance_stock
  46.  * modified by Adrian
  47.  * Jul 7, 2017
  48.  */
  49. //@Service("voidPosShop")
  50. @Service
  51. //@formatter:off
  52. @InfoIn(value = {
  53.         @Info(name = "id", description = "Point of Sales Id", type = Long.class),
  54.         @Info(name = "refProcessNo", description = "POS process no", type = String.class),
  55.         @Info(name = "version", description = "version", type = Long.class),
  56.         @Info(name = "voidDate", description = "void Date", type = String.class),
  57.         @Info(name = "reason", description = "void reason", type = String.class),
  58.         @Info(name = "remark", description = "void remark", type = String.class),
  59.         @Info(name = "securityCode", description = "security code for voiding POS transaction", type = String.class),
  60.         @Info(name = "userLoginId", description = "user login id", type = Long.class),
  61.         @Info(name = "roleLoginId", description = "role login id", type = Long.class),
  62.         @Info(name = "tenantLoginId", description = "tenant login id", type = Long.class),
  63.         @Info(name = "datetime", description = "datetime", type = String.class)
  64. })
  65. @InfoOut(value = {
  66.         @Info(name = "id", description = "Point of Sales Id", type = Long.class),
  67.         @Info(name = "processNo", description = "process no", type = String.class),
  68.         @Info(name = "tenantId", description = "PT", type = Long.class),
  69.         @Info(name = "docTypeId", description = "Document Type id", type = Long.class),
  70.         @Info(name = "docNo", description = "Document Number (Autogenerate)", type = String.class),
  71.         @Info(name = "docDate", description = "Document Date", type = String.class),
  72.         @Info(name = "ouId", description = "Organization unit Id", type = Long.class),
  73.         @Info(name = "extDocNo", description = "External Document Number", type = String.class),
  74.         @Info(name = "extDocDate", description = "External Document Date", type = String.class),
  75.         @Info(name = "refDocTypeId", description = "Reference document type Id", type = Long.class),
  76.         @Info(name = "refId", description = "Reference Id", type = Long.class),
  77.         @Info(name = "remark", description = "Remark", type = String.class),
  78.         @Info(name = "partnerId", description = "Partner id", type = Long.class),
  79.         @Info(name = "partnerBillToId", description = "Partner bill to Id", type = Long.class),
  80.         @Info(name = "partnerShipToId", description = "Partner ship to Id", type = Long.class),
  81.         @Info(name = "salesmanId", description = "Salesman Id", type = Long.class),
  82.         @Info(name = "currCode", description = "Currency code", type = String.class),
  83.         @Info(name = "addDiscountPercentage", description = "additional Discount percentage", type = Double.class),
  84.         @Info(name = "addDiscountAmount", description = "Additional Discount Amount", type = Double.class),
  85.         @Info(name = "grossAmount", description = "Gross Amount, total nilai netto item (sudah dipotong dengan disc per item belum dipotong pajak)", type = Double.class),
  86.         @Info(name = "nettAmount", description = "Net Amount, Nilai Item - additional discount", type = Double.class),
  87.         @Info(name = "taxAmount", description = "Tax Amount, Nilai Pajak berdasarkan detail tax document", type = Double.class),
  88.         @Info(name = "addAmount", description = "Additional Amount, nilai tambahan biaya yang dibebankan ke customer", type = Double.class),
  89.         @Info(name = "totalAmount", description = "TotalAmount, Net Amount + Nilai Pajak + add amount", type = Double.class),
  90.         @Info(name = "roundingAmount", description = "Rounding Amount, pembulatan nilai netto", type = Double.class),
  91.         @Info(name = "totalPayment", description = "Total Payment, Total Amount_conversion dari table cash dan non_cash", type = Double.class),
  92.         @Info(name = "totalRefund", description = "Total Refund", type = Double.class),
  93.         @Info(name = "status", description = "Status Transaction", type = String.class),
  94.         @Info(name = "version", description = "version", type = Long.class),
  95.         @Info(name = "createDateTime", description = "create date time", type = String.class),
  96.         @Info(name = "createUserId", description = "create user id", type = Long.class),
  97.         @Info(name = "updateDateTime", description = "update date time", type = String.class),
  98.         @Info(name = "updateUserId", description = "update user id", type = Long.class)
  99. })
  100. @ErrorList(errorKeys = {
  101.         CommonExceptionConstants.TENANT_LOGIN_CANT_USED,
  102.         CommonExceptionConstants.OU_ID_NOT_FOUND,
  103.         CommonExceptionConstants.USER_ID_NOT_FOUND,
  104.         PosIntegrationExceptionConstants.POS_ID_NOT_FOUND,
  105.         PosIntegrationExceptionConstants.POS_ALREADY_VOIDED,
  106.         PosIntegrationExceptionConstants.POS_NOT_SUBMITTED,
  107.         PosIntegrationExceptionConstants.POS_TRANSFERRED_TO_SERVER,
  108.         PosIntegrationExceptionConstants.PRODUCT_BALANCE_STOCK_NOT_FOUND,
  109.         PosIntegrationExceptionConstants.OUTLET_SECURITY_CODE_NOT_FOUND,
  110.         PosIntegrationExceptionConstants.INVALID_SECURITY_CODE,
  111.         PosIntegrationExceptionConstants.OUTLET_NOT_FOUND,
  112.         PosIntegrationExceptionConstants.OUTLET_NOT_ACTIVATED
  113. })
  114. //@formatter:on
  115. public class VoidPosShopForSasaObsolete extends DefaultBusinessTransaction implements BusinessTransaction {
  116.     private static final Logger log = LoggerFactory.getLogger(VoidPosShopForSasaObsolete.class);
  117.     @Autowired
  118.     private PointOfSalesDao posDao;
  119.  
  120.     @Autowired
  121.     private PointOfSalesItemDao posItemDao;
  122.  
  123.     @Autowired
  124.     private PointOfSalesExtSasaDao pointOfSalesExtSasaDao;
  125.  
  126.     @Autowired
  127.     private ProductBalanceStockDao productBalanceStockDao;
  128.    
  129.     @Autowired
  130.     private NempilBarangBalanceStockDao nempilBarangBalanceStockDao;
  131.  
  132.     @Autowired
  133.     private LogProductBalanceStockDao logProductBalanceStockDao;
  134.    
  135.     @Autowired
  136.     private LogNempilBarangBalanceStockDao logNempilBarangBalanceStockDao;
  137.  
  138.     @Autowired
  139.     private CashBankBalanceDao cashBankBalanceDao;
  140.  
  141.     @Autowired
  142.     private BalanceSettlementDao balanceSettlementDao;
  143.  
  144.     @Autowired
  145.     private TrxLogVoidedPosCustomDao trxLogVoidedPosCustomDao;
  146.  
  147.     @Autowired
  148.     @Qualifier("valTenantLoginCanUse")
  149.     private BusinessFunction valTenantLoginCanUse;
  150.  
  151.     @Autowired
  152.     @Qualifier("valDocCanInputByDate")
  153.     private BusinessFunction valDocCanInputByDate;
  154.  
  155.     @Autowired
  156.     @Qualifier("findPosById")
  157.     private BusinessFunction findPosById;
  158.  
  159.     @Autowired
  160.     @Qualifier("findUserById")
  161.     private BusinessFunction findUserById;
  162.  
  163.     @Autowired
  164.     @Qualifier("getPosItemListByPosId")
  165.     private BusinessFunction getPosItemListByPosId;
  166.    
  167.     @Autowired
  168.     @Qualifier("getPosItemNempilListByPosId")
  169.     private BusinessFunction getPosItemNempilListByPosId;
  170.  
  171.     @Autowired
  172.     @Qualifier("getPosAssemblyProductListByPosItemId")
  173.     private BusinessFunction getPosAssemblyProductListByPosItemId;
  174.  
  175.     @Autowired
  176.     @Qualifier("getPosCashPaymentListByPosId")
  177.     private BusinessFunction getPosCashPaymentListByPosId;
  178.  
  179.     @Autowired
  180.     @Qualifier("getPosNonCashPaymentListByPosId")
  181.     private BusinessFunction getPosNonCashPaymentListByPosId;
  182.  
  183.     @Autowired
  184.     @Qualifier("findProductBalanceStockByIndex")
  185.     private BusinessFunction findProductBalanceStockByIndex;
  186.    
  187.     @Autowired
  188.     @Qualifier("findProductNempilByIndex")
  189.     private BusinessFunction findProductNempilByIndex;
  190.  
  191.     @Autowired
  192.     @Qualifier("isCashBankBalanceExistsByIndex")
  193.     private BusinessFunction isCashBankBalanceExistsByIndex;
  194.  
  195.     @Autowired
  196.     @Qualifier("getCashBankDataOutletList")
  197.     private BusinessFunction getCashBankDataOutletList;
  198.  
  199.     @Autowired
  200.     @Qualifier("findCashBankBalanceByIndex")
  201.     private BusinessFunction findCashBankBalanceByIndex;
  202.  
  203.     @Autowired
  204.     @Qualifier("findBalanceSettlementByIndex")
  205.     private BusinessFunction findBalanceSettlementByIndex;
  206.  
  207.     @Autowired
  208.     @Qualifier("findPosItemById")
  209.     private BusinessFunction findPosItemById;
  210.  
  211.     @Autowired
  212.     @Qualifier("findPointOfSalesExtByIndex")
  213.     private BusinessFunction findPointOfSalesExtByIndex;
  214.  
  215.     @Autowired
  216.     @Qualifier("valOutletActivatedByIndex")
  217.     private BusinessFunction valOutletActivatedByIndex;
  218.  
  219.     @Autowired
  220.     @Qualifier("valVoidPos")
  221.     private BusinessFunction valVoidPos;
  222.  
  223.     @Autowired
  224.     @Qualifier("findSystemConfigByParamCode")
  225.     private BusinessFunction findSystemConfigByParamCode;
  226.  
  227.     @Autowired
  228.     @Qualifier("findCashBankOuById")
  229.     private BusinessFunction findCashBankOuById;
  230.    
  231.     @Override
  232.     public String getDescription() {
  233.         return "Void POS Shop";
  234.     }
  235.  
  236.     @SuppressWarnings("unchecked")
  237.     @Override
  238.     public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
  239.         // Standard Validation
  240.         ValidationUtil.valDtoContainsKey(inputDto, "id");
  241.         ValidationUtil.valBlankOrNull(inputDto, "refProcessNo");
  242.         ValidationUtil.valBlankOrNull(inputDto, "reason");
  243.         ValidationUtil.valBlankOrNull(inputDto, "securityCode");
  244.         ValidationUtil.valLong(inputDto, "version");
  245.         ValidationUtil.valDtoContainsKey(inputDto, "userLoginId");
  246.         ValidationUtil.valDtoContainsKey(inputDto, "roleLoginId");
  247.         ValidationUtil.valDtoContainsKey(inputDto, "tenantLoginId");
  248.         ValidationUtil.valBlankOrNull(inputDto, "datetime");
  249.  
  250.         // Preparing input parameters
  251.         Long id = inputDto.getLong("id");
  252.         Long userLoginId = inputDto.getLong("userLoginId");
  253.         Long roleLoginId = inputDto.getLong("roleLoginId");
  254.         Long tenantLoginId = inputDto.getLong("tenantLoginId");
  255.         String datetime = inputDto.getString("datetime");
  256.         String voidDate = inputDto.getString("voidDate");
  257.         String refProcessNo = inputDto.getString("refProcessNo");
  258.  
  259.         // Validation tenant login id can be use
  260.         Dto loginDto = new Dto();
  261.         loginDto.put("tenantLoginId", tenantLoginId);
  262.         loginDto.put("userLoginId", userLoginId);
  263.         loginDto.put("roleLoginId", roleLoginId);
  264.         valTenantLoginCanUse.execute(loginDto);
  265.  
  266.         // Find POS by id
  267.         Dto posDto = new Dto();
  268.         posDto.put("id", id);
  269.         posDto.put("processNo", refProcessNo);
  270.         posDto.put("tenantId", tenantLoginId);
  271.         posDto = findPosById.execute(posDto);
  272.  
  273.         Dto posForVoidDto = new Dto();
  274.         posForVoidDto.put("id", id);
  275.         posForVoidDto.put("processNo", refProcessNo);
  276.         posForVoidDto.put("tenantId", tenantLoginId);
  277.         posForVoidDto = findPosById.execute(posForVoidDto);
  278.  
  279.         Long docTypeId = posDto.getLong("docTypeId");
  280.         String docNo = posDto.getString("docNo");
  281.         String docDate = posDto.getString("docDate");
  282.         Long ouId = posDto.getLong("ouId");
  283.         String currCode = posDto.getString("currCode");
  284.         Double totalRefund = posDto.getDouble("totalRefund");
  285.         String status = posDto.getString("status");
  286.         String processNo = docNo; // TODO: harusnya autonum
  287.  
  288.         log.info("Value of void Date: "+voidDate);
  289.         log.info("Value of doc Date: "+docDate);
  290.        
  291.         // validasi pos bisa divoid atau tidak
  292.         valVoid(docNo, docDate, ouId, tenantLoginId, posDto.getDouble("totalPayment"));
  293.        
  294.         // Validate the pos status must be S (submitted)
  295.         if (!PosIntegrationConstants.SUBMITTED_TRANSACTION.equals(status)) {
  296.             if (PosIntegrationConstants.VOIDED_TRANSACTION.equals(status))
  297.                 throw new CoreException(PosIntegrationExceptionConstants.POS_ALREADY_VOIDED);
  298.             else
  299.                 throw new CoreException(PosIntegrationExceptionConstants.POS_NOT_SUBMITTED);
  300.         }
  301.        
  302.         // Validate the outlet has been activated, by index.
  303.         Dto outletDto = valOutletActivatedByIndex.execute(new Dto().put("tenantId", tenantLoginId).put("ouId", ouId));
  304.         Long outletId = outletDto.getLong("id");
  305.         Long warehouseId = outletDto.getLong("warehouseId");
  306.        
  307.         Dto valDocDateDto = new Dto();
  308.         valDocDateDto.put("tenantId", tenantLoginId);
  309.         valDocDateDto.put("docDate", voidDate);
  310.         valDocDateDto.put("ouId", ouId);
  311.         valDocCanInputByDate.execute(valDocDateDto);
  312.        
  313.         // Validate the security code is valid
  314.         Dto valVoidPosDto = new Dto();
  315.         valVoidPosDto.put("tenantId", tenantLoginId);
  316.         valVoidPosDto.put("securityCode", inputDto.getString("securityCode"));
  317.         valVoidPosDto.put("ouId", ouId);
  318.         valVoidPos.execute(valVoidPosDto);
  319.  
  320.         // Get Username
  321.         Dto userDto = new Dto();
  322.         userDto.put("id", userLoginId);
  323.         userDto = findUserById.execute(userDto);
  324.         String username = userDto.getString("name");
  325.  
  326.         // Preparing Input Header
  327.         Dto mergePosDto = (Dto) posDto.clone();
  328.         mergePosDto.put("status", PosIntegrationConstants.VOIDED_TRANSACTION);
  329.         mergePosDto.put("version", inputDto.getLong("version"));
  330.         mergePosDto.put("updateUsername", username);
  331.         prepareUpdateAudit(mergePosDto, userLoginId, datetime);
  332.  
  333.         // Preparing log voided POS dto
  334.         Dto persistLogVoidedPosDto = new Dto();
  335.         persistLogVoidedPosDto.putLong("trxLogVoidedPosCustomPk.id", GeneralConstants.NULL_REF_VALUE_LONG);
  336.         persistLogVoidedPosDto.putString("trxLogVoidedPosCustomPk.processNo", processNo);
  337.         persistLogVoidedPosDto.putLong("trxLogVoidedPosCustomPk.tenantId", tenantLoginId);
  338.         persistLogVoidedPosDto.putLong("docTypeId", PosIntegrationConstants.DOCUMENT_VOID_SALES_RETAIL_SHOP);
  339.         persistLogVoidedPosDto.putString("docNo", docNo);
  340.         persistLogVoidedPosDto.putString("docDate", voidDate);
  341.         persistLogVoidedPosDto.putLong("ouId", ouId);
  342.         persistLogVoidedPosDto.putLong("refDocTypeId", docTypeId);
  343.         persistLogVoidedPosDto.putLong("refId", id);
  344.         persistLogVoidedPosDto.putString("reason", inputDto.getString("reason"));
  345.         persistLogVoidedPosDto.putString("remark", inputDto.getString("remark"));
  346.         persistLogVoidedPosDto.putString("securityCode", inputDto.getString("securityCode"));
  347.         prepareInsertAudit(persistLogVoidedPosDto, userLoginId, datetime);
  348.         prepareUpdateAudit(persistLogVoidedPosDto, userLoginId, datetime);
  349.  
  350.         // Looping detail item
  351.         // Update product balance stock
  352.         Dto paramPosItemListDto = new Dto();
  353.         paramPosItemListDto.putLong("posId", id);
  354.         paramPosItemListDto.putString("processNo", refProcessNo);
  355.         paramPosItemListDto.putLong("tenantId", tenantLoginId);
  356.         List<Dto> posItemList = getPosItemListByPosId.execute(paramPosItemListDto).getList("posItemList");
  357.         Map<Long, Dto> mergeProductBalanceStockList = new HashMap<Long, Dto>();
  358.         if (posItemList != null) {
  359.             for (Dto posItemDto : posItemList) {
  360.  
  361.                 // Preparing Variable
  362.                 Long productId = posItemDto.getLong("productId");
  363.                 Long productBalanceId = posItemDto.getLong("productBalanceId");
  364.                 String productStatus = PosIntegrationConstants.DEFAULT_PRODUCT_STATUS;
  365.                 Double qty = posItemDto.getDouble("qty");
  366.  
  367.                 Dto mergeProductBalanceStockDto = null;
  368.                 if (GeneralConstants.NULL_REF_VALUE_LONG.equals(productBalanceId)) {
  369.                     List<Dto> posAssemblyProductList = getPosAssemblyProductListByPosItemId.execute(
  370.                             new Dto().putLong("posItemId", posItemDto.getLong("id"))).getList("posAssemblyProductList");
  371.                     for (Dto posAssemblyProductDto : posAssemblyProductList) {
  372.                         productId = posAssemblyProductDto.getLong("productId");
  373.                         productBalanceId = posAssemblyProductDto.getLong("productBalanceId");
  374.                         productStatus = posAssemblyProductDto.getString("productStatus");
  375.                         qty = posAssemblyProductDto.getDouble("qty");
  376.                        
  377.                         mergeProductBalanceStockDto = getMergeProductBalanceStock(tenantLoginId, warehouseId, productId, productBalanceId,
  378.                                                         productStatus, mergeProductBalanceStockList, userLoginId, datetime);
  379.                        
  380.                         updateProductBalanceStock(docNo, voidDate, ouId, userLoginId,
  381.                                 tenantLoginId, datetime, qty, mergeProductBalanceStockDto);
  382.                     }
  383.                 } else {
  384.                     mergeProductBalanceStockDto = getMergeProductBalanceStock(tenantLoginId, warehouseId, productId, productBalanceId,
  385.                                                     productStatus, mergeProductBalanceStockList, userLoginId, datetime);
  386.                    
  387.                     updateProductBalanceStock(docNo, voidDate, ouId, userLoginId,
  388.                             tenantLoginId, datetime, qty, mergeProductBalanceStockDto);
  389.                 }
  390.             }
  391.         }
  392.  
  393.         // TODO: 27/02/20 Prepare input POS for Refund
  394.         Dto persistPosDto = (Dto) posForVoidDto.clone();
  395.         persistPosDto.put("docNo", persistPosDto.getString("docNo").concat("_").concat(CommonConstants.STATE_VOID));
  396.         persistPosDto.put("pointOfSalesPk.id", GeneralConstants.NULL_REF_VALUE_LONG);
  397.         persistPosDto.put("pointOfSalesPk.processNo", persistPosDto.getString("docNo"));
  398.         persistPosDto.put("pointOfSalesPk.tenantId", tenantLoginId);
  399.         persistPosDto.put("status", PosIntegrationConstants.SUBMITTED_TRANSACTION);
  400.         persistPosDto.put("createUsername", username);
  401.         persistPosDto.put("updateUsername", username);
  402.         persistPosDto.put("docDate", voidDate);
  403.         persistPosDto.put("remark", inputDto.getString("remark"));
  404.         persistPosDto.put("grossAmount", persistPosDto.getDouble("grossAmount")*(-1));
  405.         persistPosDto.put("nettAmount", persistPosDto.getDouble("nettAmount")*(-1));
  406.         persistPosDto.put("addAmount", persistPosDto.getDouble("addAmount")*(-1));
  407.         persistPosDto.put("totalAmount", persistPosDto.getDouble("totalAmount")*(-1));
  408.         persistPosDto.put("roundingAmount", persistPosDto.getDouble("roundingAmount")*(-1));
  409.         persistPosDto.put("totalPayment", persistPosDto.getDouble("totalPayment")*(-1));
  410.         persistPosDto.put("totalRefund", persistPosDto.getDouble("totalRefund")*(-1));
  411.         prepareInsertAudit(persistPosDto, userLoginId, datetime);
  412.         prepareUpdateAudit(persistPosDto, userLoginId, datetime);
  413.  
  414.         String processNoForVoid = persistPosDto.getString("pointOfSalesPk.processNo");
  415.  
  416.         log.info("Value of Void POS Persist: "+persistPosDto);
  417.  
  418.         // TODO: 27/02/20 Prepare input POS item for refund
  419.         Map<Long, Dto> persistPosItemList = new HashMap<Long, Dto>();
  420.         if (posItemList != null) {
  421.             for (Dto posItemDto : posItemList) {
  422.  
  423.                 Dto findPosItem = new Dto();
  424.                 findPosItem.put("id", posItemDto.getLong("id"));
  425.                 findPosItem = findPosItemById.execute(findPosItem);
  426.  
  427.                 Double qty = findPosItem.getDouble("qty");
  428.                 Double nettAmountItem = findPosItem.getDouble("nettAmountItem");
  429.  
  430.                 findPosItem.put("processNo", processNoForVoid);
  431.                 findPosItem.put("qty", qty*(-1));
  432.                 findPosItem.put("nettAmountItem", nettAmountItem*(-1));
  433.                 prepareInsertAudit(findPosItem, userLoginId, datetime);
  434.                 prepareUpdateAudit(findPosItem, userLoginId, datetime);
  435.  
  436.                 persistPosItemList.put(findPosItem.getLong("id"), new Dto().put("posItemDto", findPosItem));
  437.             }
  438.         }
  439.         log.info("Value of Void POS Item Persist: "+persistPosItemList);
  440.  
  441.         // Looping detail item nempil
  442.         // Update product nempil balance stock
  443.         Dto paramPosItemNempilListDto = new Dto();
  444.         paramPosItemNempilListDto.putLong("posId", id);
  445.         paramPosItemNempilListDto.putString("processNo", refProcessNo);
  446.         paramPosItemNempilListDto.putLong("tenantId", tenantLoginId);
  447.         List<Dto> posItemNempilList = getPosItemNempilListByPosId.execute(paramPosItemNempilListDto).getList("posItemNempilList");
  448.         Map<Long, Dto> mergeProductNempilBalanceStockList = new HashMap<Long, Dto>();
  449.         if (posItemNempilList != null) {
  450.             for (Dto posItemNempilDto : posItemNempilList) {
  451.  
  452.                 // Preparing Variable
  453.                 Long productId = posItemNempilDto.getLong("id");
  454.                 String productCode = posItemNempilDto.getString("productCode");
  455.                 Double qty = posItemNempilDto.getDouble("qty");
  456.                 Double sellPrice = posItemNempilDto.getDouble("sellPrice");
  457.                 Double grossSellPrice = posItemNempilDto.getDouble("grossSellPrice");
  458.  
  459.                 Dto mergeNempilBarangBalanceStockDto = null;
  460.                 mergeNempilBarangBalanceStockDto = getMergeNempilBarangBalanceStock(tenantLoginId, ouId, productCode, productId,
  461.                         mergeProductNempilBalanceStockList);
  462.  
  463.                 updateNempilBarangBalanceStock(docNo, voidDate, ouId, userLoginId, tenantLoginId, datetime, qty, mergeNempilBarangBalanceStockDto);
  464.             }
  465.         }
  466.  
  467.         // Looping Cash
  468.         // Update cash balance
  469.         Dto paramPosCashPaymentListDto = new Dto();
  470.         paramPosCashPaymentListDto.putLong("posId", id);
  471.         paramPosCashPaymentListDto.putString("processNo", refProcessNo);
  472.         paramPosCashPaymentListDto.putLong("tenantId", tenantLoginId);
  473.         List<Dto> cashList = getPosCashPaymentListByPosId.execute(paramPosCashPaymentListDto).getList("posCashPaymentList");
  474.         List<Dto> persistCashBalanceList = new ArrayList<Dto>();
  475.         List<Dto> mergeCashBalanceList = new ArrayList<Dto>();
  476.         if (cashList != null) {
  477.             for (Dto cashDto : cashList) {
  478.  
  479.                 // Preparing Variable
  480.                 String currPaymentCode = cashDto.getString("currPaymentCode");
  481.                 Double paymentAmount = cashDto.getDouble("paymentAmount");
  482.  
  483.                 Dto findCashBankOuByIdDto = findCashBankOuById.execute(new Dto().put("cashBankId", getCashBankDataOutletList(outletId, currPaymentCode).getLong("id")));
  484.                
  485.                 // Check is Cash Balance exists
  486.                 Dto cashBalanceDto = new Dto();
  487.                 cashBalanceDto.put("tenantId", tenantLoginId);
  488.                 cashBalanceDto.put("ouId", findCashBankOuByIdDto.getLong("ouId"));
  489.                 cashBalanceDto.put("cashBankId", getCashBankDataOutletList(outletId, currPaymentCode).getLong("id"));
  490.                 cashBalanceDto.put("cashBankDate", voidDate);
  491.                 cashBalanceDto.put("recType", PosIntegrationConstants.RECORD_TYPE_CASH_BALANCE_CREDIT);
  492.                 cashBalanceDto = isCashBankBalanceExistsByIndex.execute(cashBalanceDto);
  493.  
  494.                 // Preparing for Cash Balance
  495.                 if (cashBalanceDto.getBoolean("exists")) {
  496.                     // merge cash balance
  497.                     Dto mergeCashBalanceDto = cashBalanceDto.getDto("cashBankBalanceDto");
  498.                     mergeCashBalanceDto.put("amount", new Calc(mergeCashBalanceDto.getDouble("amount")).add(paymentAmount)
  499.                             .doubleValue());
  500.                     prepareUpdateAudit(mergeCashBalanceDto, userLoginId, datetime);
  501.  
  502.                     mergeCashBalanceList.add(mergeCashBalanceDto);
  503.                 } else {
  504.                     // persist cash balance
  505.                     Dto persistCashBalanceDto = new Dto();
  506.                     persistCashBalanceDto.put("tenantId", tenantLoginId);
  507.                     persistCashBalanceDto.put("ouId", findCashBankOuByIdDto.getLong("ouId"));
  508.                     persistCashBalanceDto.put("cashBankId", getCashBankDataOutletList(outletId, currPaymentCode).getLong("id"));
  509.                     persistCashBalanceDto.put("cashBankDate", voidDate);
  510.                     persistCashBalanceDto.put("recType", PosIntegrationConstants.RECORD_TYPE_CASH_BALANCE_CREDIT);
  511.                     persistCashBalanceDto.put("currCode", currPaymentCode);
  512.                     persistCashBalanceDto.put("amount", paymentAmount);
  513.                     prepareInsertAudit(persistCashBalanceDto, userLoginId, datetime);
  514.  
  515.                     persistCashBalanceList.add(persistCashBalanceDto);
  516.                 }
  517.             }
  518.         }
  519.  
  520.         // Looping Non Cash
  521.         // Update Non Cash Balance
  522.         Dto paramPosNonCashPaymentListDto = new Dto();
  523.         paramPosNonCashPaymentListDto.putLong("posId", id);
  524.         paramPosNonCashPaymentListDto.putString("processNo", refProcessNo);
  525.         paramPosNonCashPaymentListDto.putLong("tenantId", tenantLoginId);
  526.         List<Dto> nonCashList = getPosNonCashPaymentListByPosId.execute(paramPosNonCashPaymentListDto).getList("posNonCashPaymentList");
  527.         List<Dto> mergeNonCashBalanceList = new ArrayList<Dto>();
  528.         if (nonCashList != null) {
  529.             for (Dto nonCashDto : nonCashList) {
  530.                 Long deviceMerchantId = nonCashDto.getLong("deviceMerchantId");
  531.                 String cardType = nonCashDto.getString("cardType");
  532.                 String bankCardCode = nonCashDto.getString("bankCardCode");
  533.                 String cardNo = nonCashDto.getString("cardNo");
  534.                
  535.                 // The non cash balance could be already merged. Try to look it in the list first.
  536.                 boolean merged = false;
  537.                 for (Dto tempDto : mergeNonCashBalanceList) {
  538.                     if (deviceMerchantId.equals(tempDto.getLong("deviceMerchantId")) &&
  539.                             cardType.equals(tempDto.getString("cardType")) &&
  540.                             bankCardCode.equals(tempDto.getString("bankCardCode")) &&
  541.                             cardNo.equals(tempDto.getString("cardNo"))) {
  542.                         merged = true;
  543.                         tempDto.put("amountPayment",
  544.                                 new Calc(tempDto.getDouble("amountPayment")).subtract(nonCashDto.getDouble("paymentAmount")).doubleValue());
  545.                         break;
  546.                     }
  547.                 }
  548.                
  549.                 // The non cash balance hasn't been merged yet. Find and merge it
  550.                 if (!merged) {
  551.                     Dto nonCashBalanceDto = new Dto();
  552.                     nonCashBalanceDto.put("tenantId", tenantLoginId);
  553.                     nonCashBalanceDto.put("ouId", ouId);
  554.                     nonCashBalanceDto.put("docTypeId", docTypeId);
  555.                     nonCashBalanceDto.put("docNo", docNo);
  556.                     nonCashBalanceDto.put("docDate", voidDate);
  557.                     nonCashBalanceDto.put("deviceMerchantId", deviceMerchantId);
  558.                     nonCashBalanceDto.put("cardType", cardType);
  559.                     nonCashBalanceDto.put("bankCardCode", bankCardCode);
  560.                     nonCashBalanceDto.put("cardNo", cardNo);
  561.                     nonCashBalanceDto = findBalanceSettlementByIndex.execute(nonCashBalanceDto);
  562.  
  563.                     // merge non cash balance
  564.                     nonCashBalanceDto.put("amountPayment",
  565.                             new Calc(nonCashBalanceDto.getDouble("amountPayment")).subtract(nonCashDto.getDouble("paymentAmount")).doubleValue());
  566.                     prepareUpdateAudit(nonCashBalanceDto, userLoginId, datetime);
  567.  
  568.                     mergeNonCashBalanceList.add(nonCashBalanceDto);
  569.                 }
  570.             }
  571.         }
  572.  
  573.         // Update Cash Balance for Refund
  574.         if(totalRefund.doubleValue() > 0D){
  575.             // Check is Cash Balance exists
  576.             Dto cashBalanceDto = new Dto();
  577.             cashBalanceDto.put("tenantId", tenantLoginId);
  578.             cashBalanceDto.put("ouId", ouId);
  579.             cashBalanceDto.put("cashBankId", getCashBankDataOutletList(outletId, currCode).getLong("id"));
  580.             cashBalanceDto.put("cashBankDate", voidDate);
  581.             cashBalanceDto.put("recType", PosIntegrationConstants.RECORD_TYPE_CASH_BALANCE_DEBT);
  582.             cashBalanceDto = isCashBankBalanceExistsByIndex.execute(cashBalanceDto);
  583.    
  584.             // Preparing for Cash Balance
  585.        
  586.             if (cashBalanceDto.getBoolean("exists")) {
  587.                 // merge cash balance
  588.                 Dto mergeCashBalanceDto = cashBalanceDto.getDto("cashBankBalanceDto");
  589.                 mergeCashBalanceDto.put("amount", new Calc(mergeCashBalanceDto.getDouble("amount")).add(totalRefund).doubleValue());
  590.                 prepareUpdateAudit(mergeCashBalanceDto, userLoginId, datetime);
  591.    
  592.                 mergeCashBalanceList.add(mergeCashBalanceDto);
  593.             } else {
  594.                 // persist cash balance
  595.                 Dto persistCashBalanceDto = new Dto();
  596.                 persistCashBalanceDto.put("tenantId", tenantLoginId);
  597.                 persistCashBalanceDto.put("ouId", ouId);
  598.                 persistCashBalanceDto.put("cashBankId", getCashBankDataOutletList(outletId, currCode).getLong("id"));
  599.                 persistCashBalanceDto.put("cashBankDate", voidDate);
  600.                 persistCashBalanceDto.put("recType", PosIntegrationConstants.RECORD_TYPE_CASH_BALANCE_DEBT);
  601.                 persistCashBalanceDto.put("currCode", currCode);
  602.                 persistCashBalanceDto.put("amount", totalRefund);
  603.                 prepareInsertAudit(persistCashBalanceDto, userLoginId, datetime);
  604.    
  605.                 persistCashBalanceList.add(persistCashBalanceDto);
  606.             }
  607.         }
  608.        
  609.         // Get DB Version in Parameter
  610.         Dto dbVersionDto = new Dto();
  611.         dbVersionDto.put("tenantId", tenantLoginId);
  612.         dbVersionDto.put("parameterCode", MasterConstants.PARAMETER_CODE_DB_VERSION);
  613.         dbVersionDto = findSystemConfigByParamCode.execute(dbVersionDto);
  614.         String dbVersionString = dbVersionDto.getString("value");
  615.  
  616.         // Set persist Dto to inputDto
  617.         inputDto.putDto("mergePosDto", mergePosDto);
  618.         inputDto.putDto("persistPosDto", persistPosDto);
  619.         inputDto.putList("mergeProductBalanceStockList", new ArrayList<Dto>(mergeProductBalanceStockList.values()));
  620.         inputDto.putList("mergeProductNempilBalanceStockList", new ArrayList<Dto>(mergeProductNempilBalanceStockList.values()));
  621.         inputDto.putList("persistPosItemList", new ArrayList<Dto>(persistPosItemList.values()));
  622.         inputDto.putList("persistCashBalanceList", persistCashBalanceList);
  623.         inputDto.putList("mergeCashBalanceList", mergeCashBalanceList);
  624.         inputDto.putList("mergeNonCashBalanceList", mergeNonCashBalanceList);
  625.         inputDto.putDto("persistLogVoidedPosDto", persistLogVoidedPosDto);
  626.         inputDto.putString("dbVersion", dbVersionString);
  627.  
  628.         return null;
  629.     }
  630.    
  631.     private void valVoid(String docNo, String docDate, Long ouId, Long tenantId, Double totalPayment) {
  632.         QueryBuilder builderValVoid = new QueryBuilder();
  633.         builderValVoid.add(" SELECT COUNT(1) ")
  634.                      .add(" FROM fi_invoice_ar_balance A ")
  635.                      .add(" INNER JOIN fi_invoice_ar B ON A.invoice_ar_id = B.invoice_ar_id ")
  636.                      .add(" INNER JOIN m_ou_structure C ON B.ou_id = C.ou_bu_id AND C.ou_id = :ouId ")
  637.                      .add(" WHERE B.tenant_id = :tenantId ")
  638.                      .add(" AND B.doc_type_id = :docTypeIdDebtNoteAr ")
  639.                      .add(" AND B.doc_no = :docNo ")
  640.                      .add(" AND B.doc_date = :docDate ")
  641.                      .add(" AND A.doc_type_id = :docTypeIdDebtNoteAr ")
  642.                      .add(" AND ((A.flg_payment = :NO AND A.payment_amount <> :totalPayment) OR (A.flg_payment = :inProgress AND A.payment_amount <> 0) OR (A.flg_payment = :YES AND A.payment_amount <> 0)) ");
  643.  
  644.         Query queryValVoid = posDao.createNativeQuery(builderValVoid.toString());
  645.         queryValVoid.setParameter("ouId", ouId);
  646.         queryValVoid.setParameter("tenantId", tenantId);
  647.         queryValVoid.setParameter("docTypeIdDebtNoteAr", 241);
  648.         queryValVoid.setParameter("docNo", docNo);
  649.         queryValVoid.setParameter("docDate", docDate);
  650.         queryValVoid.setParameter("inProgress", PosIntegrationConstants.IN_PROGRESS_TRANSACTION);
  651.         queryValVoid.setParameter("YES", GeneralConstants.YES);
  652.         queryValVoid.setParameter("NO", GeneralConstants.NO);
  653.         queryValVoid.setParameter("totalPayment", totalPayment);
  654.        
  655.         Double countValVoid = Double.valueOf(queryValVoid.getSingleResult().toString());
  656.        
  657.         /*
  658.          * mod by Didit, 5 Des 2016
  659.          * tidak perlu cek lagi saldo tax, karena dpp dan ppn digabung dalam satu saldo
  660.          *
  661.         builderValVoid = new QueryBuilder();
  662.         builderValVoid.add(" SELECT COUNT(1) ")
  663.                      .add(" FROM fi_invoice_tax_ar_balance A ")
  664.                      .add(" INNER JOIN fi_invoice_ar_balance D ON A.invoice_ar_balance_id = D.invoice_ar_balance_id ")
  665.                      .add(" INNER JOIN fi_invoice_ar B ON D.invoice_ar_id = B.invoice_ar_id ")
  666.                      .add(" INNER JOIN m_ou_structure C ON B.ou_id = C.ou_bu_id AND C.ou_id = :ouId ")
  667.                      .add(" WHERE B.tenant_id = :tenantId ")
  668.                      .add(" AND B.doc_type_id = :docTypeIdDebtNoteAr ")
  669.                      .add(" AND B.doc_no = :docNo ")
  670.                      .add(" AND B.doc_date = :docDate ")
  671.                      .add(" AND A.doc_type_id = :docTypeIdFakturPajakKeluaran ")
  672.                      .add(" AND A.payment_amount <> 0 ")
  673.                      .add(" OR (A.flg_payment = :inProgress AND A.payment_amount = 0) ");
  674.  
  675.         queryValVoid = posDao.createNativeQuery(builderValVoid.toString());
  676.         queryValVoid.setParameter("ouId", ouId);
  677.         queryValVoid.setParameter("tenantId", tenantId);
  678.         queryValVoid.setParameter("docTypeIdDebtNoteAr", 241);
  679.         queryValVoid.setParameter("docNo", docNo);
  680.         queryValVoid.setParameter("docDate", docDate);
  681.         queryValVoid.setParameter("docTypeIdFakturPajakKeluaran", 281);
  682.         queryValVoid.setParameter("inProgress", PosIntegrationConstants.IN_PROGRESS_TRANSACTION);
  683.        
  684.         Calc countValVoidCalc = new Calc(countValVoid).add(Double.valueOf(queryValVoid.getSingleResult().toString()));
  685.         */
  686.         if (countValVoid.doubleValue() != 0) {
  687.             throw new CoreException(PosIntegrationExceptionConstantsForSasa.POS_CAN_NOT_VOID);
  688.         }
  689.     }
  690.  
  691.     private void updateProductBalanceStock(String docNo, String docDate,
  692.                                            Long ouId, Long userLoginId, Long tenantLoginId, String datetime,
  693.                                            Double qty,
  694.                                            Dto mergeProductBalanceStockDto) {
  695.        
  696.         Dto productBalanceStockDto = mergeProductBalanceStockDto.getDto("productBalanceStock");
  697.         // Product Balance
  698.         // Count qty opname = qty Opname + qty Item
  699.         Double qtyOpname = new Calc(productBalanceStockDto.getDouble("qty")).add(qty).doubleValue();
  700.        
  701.         // Update qty at product balance stock
  702.         productBalanceStockDto.put("qty", qtyOpname);
  703.  
  704.         Dto logProductBalanceStockDto;
  705.         if ((logProductBalanceStockDto = mergeProductBalanceStockDto.getDto("logProductBalanceStock")) == null) {
  706.             // Create Log for product balance stock
  707.             LogProductBalanceStock logProductBalanceStock = new LogProductBalanceStock();
  708.             logProductBalanceStock.setTenantId(tenantLoginId);
  709.             logProductBalanceStock.setOuId(ouId);
  710.             // logProductBalanceStock.setRefId(posItemId);
  711.             logProductBalanceStock.setPartnerId(PosIntegrationConstants.PARTNER_RETAIL);
  712.             logProductBalanceStock.setDocTypeId(PosIntegrationConstants.DOCUMENT_VOID_SALES_RETAIL_SHOP);
  713.             logProductBalanceStock.setDocNo(docNo);
  714.             logProductBalanceStock.setDocDate(docDate);
  715.             logProductBalanceStock.setProductId(productBalanceStockDto.getLong("productId"));
  716.             logProductBalanceStock.setWarehouseId(productBalanceStockDto.getLong("warehouseId"));
  717.             logProductBalanceStock.setProductBalanceId(productBalanceStockDto.getLong("productBalanceId"));
  718.             logProductBalanceStock.setProductStatus(productBalanceStockDto.getString("productStatus"));
  719.             logProductBalanceStock.setBaseUomId(productBalanceStockDto.getLong("baseUomId"));
  720.             logProductBalanceStock.setQty(qty);
  721.  
  722.             logProductBalanceStockDto = new Dto(logProductBalanceStock);
  723.             prepareInsertAudit(logProductBalanceStockDto, userLoginId, datetime);
  724.             prepareUpdateAudit(logProductBalanceStockDto, userLoginId, datetime);
  725.            
  726.             mergeProductBalanceStockDto.putDto("logProductBalanceStock", logProductBalanceStockDto);
  727.         } else {
  728.             // Update the qty of log for product balance stock
  729.             logProductBalanceStockDto.put("qty", new Calc(logProductBalanceStockDto.getDouble("qty")).add(qty).doubleValue());
  730.         }
  731.     }
  732.  
  733.     private Dto getMergeProductBalanceStock(Long tenantLoginId, Long warehouseId, Long productId,
  734.                                             Long productBalanceId, String productStatus,
  735.                                             Map<Long, Dto> mergeProductBalanceStockList, Long userLoginId, String datetime) throws Exception {
  736.  
  737.         // Validation product balance stock must exists
  738.         Dto productBalanceStockDto = new Dto();
  739.         productBalanceStockDto.put("tenantId", tenantLoginId);
  740.         productBalanceStockDto.put("warehouseId", warehouseId);
  741.         productBalanceStockDto.put("productId", productId);
  742.         productBalanceStockDto.put("productBalanceId", productBalanceId);
  743.         productBalanceStockDto.put("productStatus", productStatus);
  744.         productBalanceStockDto = findProductBalanceStockByIndex.execute(productBalanceStockDto);
  745.        
  746.         Dto mergeProductBalanceStockDto = mergeProductBalanceStockList.get(productBalanceStockDto.getLong("id"));
  747.         if (mergeProductBalanceStockDto == null) {
  748.             mergeProductBalanceStockDto = new Dto().put("productBalanceStock", productBalanceStockDto);
  749.             mergeProductBalanceStockList.put(productBalanceStockDto.getLong("id"), mergeProductBalanceStockDto);
  750.             prepareUpdateAudit(productBalanceStockDto, userLoginId, datetime);
  751.         }
  752.        
  753.         return mergeProductBalanceStockDto;
  754.     }
  755.    
  756.     private void updateNempilBarangBalanceStock(String docNo, String docDate,
  757.                                                 Long ouId, Long userLoginId, Long tenantLoginId, String datetime,
  758.                                                 Double qty,
  759.                                                 Dto mergeNempilBarangBalanceStockDto) {
  760.        
  761.         Dto nempilBarangBalanceStockDto = mergeNempilBarangBalanceStockDto.getDto("nempilBarangBalanceStock");
  762.         // Nempil Barang Balance
  763.         // Count qty opname = qty Opname + qty Item
  764.         Double qtyOpname = new Calc(nempilBarangBalanceStockDto.getDouble("qty")).add(qty).doubleValue();
  765.        
  766.         // Update qty at nempil barang balance stock
  767.         nempilBarangBalanceStockDto.put("qty", qtyOpname);
  768.         prepareUpdateAudit(nempilBarangBalanceStockDto, userLoginId, datetime);
  769.  
  770.         Dto logNempilBarangBalanceStockDto;
  771.         if ((logNempilBarangBalanceStockDto = mergeNempilBarangBalanceStockDto.getDto("logNempilBarangBalanceStock")) == null) {
  772.             // Create Log for nempil barang balance stock
  773.             LogNempilBarangBalanceStock logNempilBarangBalanceStock = new LogNempilBarangBalanceStock();
  774.             logNempilBarangBalanceStock.setTenantId(tenantLoginId);
  775.             logNempilBarangBalanceStock.setOuId(ouId);
  776.             logNempilBarangBalanceStock.setDocTypeId(PosIntegrationConstants.DOCUMENT_VOID_SALES_RETAIL_SHOP);
  777.             logNempilBarangBalanceStock.setDocNo(docNo);
  778.             logNempilBarangBalanceStock.setDocDate(docDate);
  779.             logNempilBarangBalanceStock.setProductCode(nempilBarangBalanceStockDto.getString("productCode"));
  780.             logNempilBarangBalanceStock.setQty(qty);
  781.  
  782.             logNempilBarangBalanceStockDto = new Dto(logNempilBarangBalanceStock);
  783.             prepareInsertAudit(logNempilBarangBalanceStockDto, userLoginId, datetime);
  784.  
  785.             prepareUpdateAudit(logNempilBarangBalanceStockDto, userLoginId, datetime);
  786.             mergeNempilBarangBalanceStockDto.putDto("logNempilBarangBalanceStock", logNempilBarangBalanceStockDto);
  787.         } else {
  788.             // Update the qty of log for product balance stock
  789.             logNempilBarangBalanceStockDto.put("qty", new Calc(logNempilBarangBalanceStockDto.getDouble("qty")).add(qty).doubleValue());
  790.         }
  791.     }
  792.    
  793.     private Dto getMergeNempilBarangBalanceStock(Long tenantLoginId, Long ouId, String productCode, Long productId,
  794.                                                  Map<Long, Dto> mergeNempilBarangBalanceStockList) throws Exception {
  795.  
  796.         // Validation product balance stock must exists
  797.         Dto nempilBarangBalanceStockDto = new Dto();
  798.         nempilBarangBalanceStockDto.put("tenantId", tenantLoginId);
  799.         nempilBarangBalanceStockDto.put("ouId", ouId);
  800.         nempilBarangBalanceStockDto.put("productCode", productCode);
  801.         nempilBarangBalanceStockDto = findProductNempilByIndex.execute(nempilBarangBalanceStockDto);
  802.        
  803.         Dto mergeNempilBarangBalanceStockDto = mergeNempilBarangBalanceStockList.get(nempilBarangBalanceStockDto.getLong("id"));
  804.         if (mergeNempilBarangBalanceStockDto == null) {
  805.             mergeNempilBarangBalanceStockDto = new Dto().put("nempilBarangBalanceStock", nempilBarangBalanceStockDto);
  806.             mergeNempilBarangBalanceStockList.put(nempilBarangBalanceStockDto.getLong("id"), mergeNempilBarangBalanceStockDto);
  807.         }
  808.  
  809.         return mergeNempilBarangBalanceStockDto;
  810.     }
  811.  
  812.     @SuppressWarnings("unchecked")
  813.     @Override
  814.     public Dto process(Dto inputDto, Dto originalDto) throws Exception {
  815.         Dto mergePosDto = inputDto.getDto("mergePosDto");
  816.         Dto persistPosDto = inputDto.getDto("persistPosDto");
  817.         List<Dto> mergeProductBalanceStockList = inputDto.getList("mergeProductBalanceStockList");
  818.         List<Dto> mergeProductNempilBalanceStockList = inputDto.getList("mergeProductNempilBalanceStockList");
  819.         List<Dto> persistPosItemList = inputDto.getList("persistPosItemList");
  820.         List<Dto> persistCashBalanceList = inputDto.getList("persistCashBalanceList");
  821.         List<Dto> mergeCashBalanceList = inputDto.getList("mergeCashBalanceList");
  822.         List<Dto> mergeNonCashBalanceList = inputDto.getList("mergeNonCashBalanceList");
  823.         Dto persistLogVoidedPosDto = inputDto.getDto("persistLogVoidedPosDto");
  824.         Long tenantLoginId = inputDto.getLong("tenantLoginId");
  825.         Long userLoginId = inputDto.getLong("userLoginId");
  826.         String datetime = inputDto.getString("datetime");
  827.         String dbVersion = inputDto.getString("dbVersion");
  828.  
  829.         // Insert header data
  830.         PointOfSales pos = GsonUtil.fromDto(mergePosDto, PointOfSales.class);
  831.         PointOfSalesPk posPk = pos.getPointOfSalesPk();
  832.         posDao.merge(posPk, pos);
  833.  
  834.         PointOfSales posVoid = GsonUtil.fromDto(persistPosDto, PointOfSales.class);
  835.         posDao.persist(posVoid);
  836.  
  837.         Long posId = posPk.getId();
  838.         String sessionId = UUID.randomUUID().toString();
  839.         Long tenantId = posPk.getTenantId();
  840.         String processNo = posPk.getProcessNo();
  841.         Long ouId = pos.getOuId();
  842.         String docDate = pos.getDocDate();
  843.        
  844.         // Merge Product Balance Stock
  845.         for (Dto productBalanceStockDto : mergeProductBalanceStockList) {
  846.             ProductBalanceStock productBalanceStock = GsonUtil.fromDto(productBalanceStockDto.getDto("productBalanceStock"), ProductBalanceStock.class);
  847.             productBalanceStock = productBalanceStockDao.merge(productBalanceStock.getId(), productBalanceStock);
  848.            
  849.             Dto logProductBalanceStockDto = productBalanceStockDto.getDto("logProductBalanceStock");
  850.             logProductBalanceStockDto.put("refId", posId);
  851.            
  852.             // Persist Log Product Balance Stock
  853.             LogProductBalanceStock logProductBalanceStock = GsonUtil.fromDto(logProductBalanceStockDto, LogProductBalanceStock.class);
  854.             logProductBalanceStockDao.persist(logProductBalanceStock);
  855.         }
  856.        
  857.         // Merge Nempil Barang Balance Stock
  858.         for (Dto nempilBarangBalanceStockDto : mergeProductNempilBalanceStockList) {
  859.             NempilBarangBalanceStock nempilBarangBalanceStock = GsonUtil.fromDto(nempilBarangBalanceStockDto.getDto("nempilBarangBalanceStock"), NempilBarangBalanceStock.class);
  860.             nempilBarangBalanceStock = nempilBarangBalanceStockDao.merge(nempilBarangBalanceStock.getId(), nempilBarangBalanceStock);
  861.            
  862.             // Persist Log Nempil Barang Balance Stock
  863.             LogNempilBarangBalanceStock logNempilBarangBalanceStock = GsonUtil.fromDto(nempilBarangBalanceStockDto.getDto("logNempilBarangBalanceStock"),
  864.                     LogNempilBarangBalanceStock.class);
  865.             logNempilBarangBalanceStockDao.persist(logNempilBarangBalanceStock);
  866.         }
  867.  
  868.         // Persist new pos item void
  869.         for (Dto posItemDto : persistPosItemList) {
  870.             Dto preparePosItemDto = posItemDto.getDto("posItemDto");
  871.             preparePosItemDto.remove("id");
  872.  
  873.             PointOfSalesItem pointOfSalesItem = GsonUtil.fromDto(preparePosItemDto, PointOfSalesItem.class);
  874.             posItemDao.persist(pointOfSalesItem);
  875.         }
  876.  
  877.         // Merge Cash Balance
  878.         for (Dto cashBalanceDto : mergeCashBalanceList) {
  879.             CashBankBalance cashBalance = GsonUtil.fromDto(cashBalanceDto, CashBankBalance.class);
  880.             cashBalance = cashBankBalanceDao.merge(cashBalance.getId(), cashBalance);
  881.         }
  882.  
  883.         // Persist Cash Balance
  884.         for (Dto cashBalanceDto : persistCashBalanceList) {
  885.             CashBankBalance cashBalance = GsonUtil.fromDto(cashBalanceDto, CashBankBalance.class);
  886.             cashBankBalanceDao.persist(cashBalance);
  887.         }
  888.  
  889.         // Merge Non Cash Balance
  890.         for (Dto nonCashBalanceDto : mergeNonCashBalanceList) {
  891.             BalanceSettlement nonCashBalance = GsonUtil.fromDto(nonCashBalanceDto, BalanceSettlement.class);
  892.             nonCashBalance = balanceSettlementDao.merge(nonCashBalance.getId(), nonCashBalance);
  893.         }
  894.  
  895.  
  896.         TrxLogVoidedPosCustom logVoidedPos = GsonUtil.fromDto(persistLogVoidedPosDto, TrxLogVoidedPosCustom.class);
  897.         trxLogVoidedPosCustomDao.persist(logVoidedPos);
  898.  
  899.         // panggil proses void pos untuk cabut data jurnal
  900.         QueryBuilder builder = new QueryBuilder();
  901.         builder.add("SELECT COUNT( i_process_void_pos_delete_journal( :sessionId, :tenantId, :trxPosId, :processNo, :userId, :datetime ) )");
  902.  
  903.         Query query = posDao.createNativeQuery(builder.toString());
  904.         query.setParameter("tenantId", tenantId);
  905.         query.setParameter("sessionId", sessionId);
  906.         query.setParameter("trxPosId", posId);
  907.         query.setParameter("processNo", processNo);
  908.         query.setParameter("userId", userLoginId);
  909.         query.setParameter("datetime", datetime);
  910.  
  911.         query.getSingleResult();
  912.        
  913.         return new Dto(pos);
  914.     }
  915.  
  916.     @SuppressWarnings("unchecked")
  917.     private Dto getCashBankDataOutletList(Long outletId, String currencyCode) throws Exception {
  918.         Dto inputDtoForGetCashAccountList = new Dto();
  919.         inputDtoForGetCashAccountList.put("outletId", outletId);
  920.         inputDtoForGetCashAccountList.put("flagCashBank", MasterConstants.FLAG_CASH);
  921.  
  922.         // Processing
  923.         Dto outputDtoForGetCashAccountList = getCashBankDataOutletList.execute(inputDtoForGetCashAccountList);
  924.        
  925.         List<Dto> cashBankList = outputDtoForGetCashAccountList.getList("cashBankDataOutletList");
  926.        
  927.         if (cashBankList != null) {
  928.             for (Dto cashBankOutlet : cashBankList) {
  929.                 if (currencyCode.equals(cashBankOutlet.getString("currencyCode"))) {
  930.                     return new Dto().put("id", Long.valueOf(cashBankOutlet.get("cashBankId").toString())).put("code", cashBankOutlet.getString("cashBankCode"));
  931.                 }
  932.             }
  933.         } else {
  934.             throw new CoreException(PosIntegrationExceptionConstants.POS_CASH_NOT_FOUND);
  935.         }
  936.        
  937.         return new Dto();
  938.     }
  939.  
  940. }
RAW Paste Data