widana

EditQtyItemTransaction

Oct 26th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.39 KB | None | 0 0
  1. package org.jleaf.pos2.bo.postransaction;
  2.  
  3. import javax.persistence.Query;
  4.  
  5. import org.jleaf.core.BusinessFunction;
  6. import org.jleaf.core.BusinessTransaction;
  7. import org.jleaf.core.DefaultBusinessTransaction;
  8. import org.jleaf.core.Dto;
  9. import org.jleaf.core.GeneralConstants;
  10. import org.jleaf.core.annotation.ErrorList;
  11. import org.jleaf.core.annotation.Info;
  12. import org.jleaf.core.annotation.InfoIn;
  13. import org.jleaf.core.annotation.InfoOut;
  14. import org.jleaf.core.dao.QueryBuilder;
  15. import org.jleaf.pos2.PosConstants;
  16. import org.jleaf.pos2.entity.Pos;
  17. import org.jleaf.pos2.entity.PosItem;
  18. import org.jleaf.pos2.dao.PosItemDao;
  19. import org.jleaf.pos2.util.PosUtil;
  20. import org.jleaf.util.Calc;
  21. import org.jleaf.util.GsonUtil;
  22. import org.jleaf.util.ValidationUtil;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.beans.factory.annotation.Qualifier;
  25. import org.springframework.stereotype.Service;
  26.  
  27. /**
  28.  * Business Transactions: EditQtyItemTransaction
  29.  *
  30.  * @author Widana Nur Azis , 25 Oct 2016
  31.  */
  32.  
  33. // @formatter:off
  34. @Service
  35. @InfoIn(value = {
  36.         @Info(name = "userLoginId", description = "user login id", type = Long.class),
  37.         @Info(name = "userLoginName", description = "user login name", type = String.class),
  38.         @Info(name = "roleLoginId", description = "role login id", type = Long.class),
  39.         @Info(name = "roleLoginName", description = "role login name", type = String.class),
  40.         @Info(name = "tenantLoginId", description = "tenantLoginId", type = Long.class),
  41.         @Info(name = "datetime", description = "date time", type = String.class),
  42.  
  43.         @Info(name = "posItemId", description = "posItemId", type = Long.class),
  44.         @Info(name = "posCashierId", description = "posCashierId", type = Long.class),
  45.         @Info(name = "posId", description = "posId", type = Long.class),
  46.         @Info(name = "qty", description = "qty", type = Long.class)
  47. })
  48.  
  49. @InfoOut(value = {
  50.         @Info(name = "posId", description = "posId", type = Long.class),
  51.         @Info(name = "posCashierId", description = "posCashierId", type = Long.class),
  52.         @Info(name = "docTypeId", description = "docTypeId", type = Long.class),
  53.         @Info(name = "docNo", description = "docNo", type = String.class),
  54.         @Info(name = "docDate", description = "docDate", type = String.class),
  55.         @Info(name = "extDocNo", description = "extDocNo", type = String.class),
  56.         @Info(name = "extDocDate", description = "extDocDate", type = String.class),
  57.         @Info(name = "refDocTypeId", description = "refDocTypeId", type = String.class),
  58.         @Info(name = "refId", description = "refId", type = Long.class),
  59.         @Info(name = "remark", description = "remark", type = String.class),
  60.         @Info(name = "customerCode", description = "customerCode", type = String.class),
  61.         @Info(name = "customerName", description = "customerName", type = String.class),
  62.         @Info(name = "customerPhone", description = "customerPhone", type = String.class),
  63.         @Info(name = "salesmanCode", description = "salesmanCode", type = String.class),
  64.         @Info(name = "currCode", description = "currCode", type = String.class),
  65.         @Info(name = "grossAmount", description = "grossAmount", type = String.class),
  66.         @Info(name = "totalDiscountItem", description = "totalDiscountItem", type = Double.class),
  67.         @Info(name = "addDiscountPercentage", description = "addDiscountPercentage", type = Double.class),
  68.         @Info(name = "addDiscountAmount", description = "addDiscountAmount", type = Double.class),
  69.         @Info(name = "nettAmount", description = "nettAmount", type = Double.class),
  70.         @Info(name = "taxAmount", description = "taxAmount", type = Double.class),
  71.         @Info(name = "addAmount", description = "addAmount", type = Double.class),
  72.         @Info(name = "totalAmount", description = "totalAmount", type = Double.class),
  73.         @Info(name = "roundingAmount", description = "roundingAmount", type = Double.class),
  74.         @Info(name = "totalPayment", description = "totalPayment", type = Double.class),
  75.         @Info(name = "totalRefund", description = "totalRefund", type = Double.class),
  76.         @Info(name = "status", description = "status", type = String.class),
  77.  
  78.         @Info(name = "createUsername", description = "create username", type = String.class),
  79.         @Info(name = "updateUsername", description = "update username", type = String.class),
  80.         @Info(name = "active", description = "active", type = String.class, required = true),
  81.         @Info(name = "activeDateTime", description = "active date time", type = String.class),
  82.         @Info(name = "nonActiveDateTime", description = "non active date time", type = String.class),
  83.         @Info(name = "createDateTime", description = "create date time", type = String.class),
  84.         @Info(name = "updateDateTime", description = "update date time", type = String.class),
  85.         @Info(name = "version", description = "version", type = Long.class) })
  86.  
  87. // @formatter:on
  88. @ErrorList(errorKeys = {})
  89.  
  90. public class EditQtyItemTransaction extends DefaultBusinessTransaction implements BusinessTransaction {
  91.  
  92.     @Autowired
  93.     PosItemDao posItemDao;
  94.  
  95.     @Autowired
  96.     @Qualifier("findPosCashierById")
  97.     BusinessFunction findPosCashierById;
  98.  
  99.     @Autowired
  100.     @Qualifier("findPosById")
  101.     BusinessFunction findPosById;
  102.  
  103.     @Autowired
  104.     @Qualifier("findPosTransactionItemById")
  105.     BusinessFunction findPosTransactionItemById;
  106.    
  107.     @Override
  108.     public String getDescription() {
  109.         // TODO Auto-generated method stub
  110.         return "EditQtyItemTransaction using for edit qty pos transaction item";
  111.     }
  112.  
  113.     @Override
  114.     public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
  115.         // TODO Auto-generated method stub
  116.  
  117.         ValidationUtil.valBlankOrNull(inputDto, "posItemId");
  118.         ValidationUtil.valBlankOrNull(inputDto, "posCashierId");
  119.         ValidationUtil.valBlankOrNull(inputDto, "posId");
  120.         ValidationUtil.valBlankOrNull(inputDto, "qty");
  121.  
  122.         ValidationUtil.valDtoContainsKey(inputDto, "posItemId");
  123.         ValidationUtil.valDtoContainsKey(inputDto, "posCashierId");
  124.         ValidationUtil.valDtoContainsKey(inputDto, "posId");
  125.         ValidationUtil.valDtoContainsKey(inputDto, "qty");
  126.        
  127.         findPosCashierById.execute(new Dto().put("id", inputDto.getLong("posCashierId")));
  128.  
  129.         Dto findPosByIdDto =  findPosById.execute(new Dto().put("id", inputDto.getLong("posId")));
  130.        
  131.         Dto findPosTransactionItemByIdDto = findPosTransactionItemById.execute(new Dto().put("id", inputDto.getLong("posItemId")));
  132.        
  133.         Double taxAmount = new Calc(findPosTransactionItemByIdDto.getDouble("taxPrice")).multiply(inputDto.getLong("qty")).doubleValue();
  134.         Double nettAmountItem = new Calc(findPosTransactionItemByIdDto.getDouble("nettSellPrice")).multiply(inputDto.getLong("qty")).doubleValue();
  135.  
  136.         Dto editQtyItemTransactionDto = new Dto();
  137.         editQtyItemTransactionDto.put("posItemId", findPosTransactionItemByIdDto.getLong("id"));
  138.         editQtyItemTransactionDto.put("posId", findPosByIdDto.getLong("id"));
  139.         editQtyItemTransactionDto.put("taxAmount", taxAmount);
  140.         editQtyItemTransactionDto.put("nettAmountItem", nettAmountItem);
  141.         editQtyItemTransactionDto.put("qty", inputDto.getLong("qty"));
  142.         editQtyItemTransactionDto.put("version", findPosTransactionItemByIdDto.getLong("version")+1);
  143.        
  144.         inputDto.put("editQtyItemTransactionDto", editQtyItemTransactionDto);
  145.        
  146.         return null;
  147.     }
  148.  
  149.     @Override
  150.     public Dto process(Dto inputDto, Dto originalDto) throws Exception {
  151.         // TODO Auto-generated method stub
  152.  
  153.         Dto getEditQtyItemTransactionDto = inputDto.getDto("editQtyItemTransactionDto");
  154.  
  155.         QueryBuilder builder = new QueryBuilder();
  156.         builder.add(" UPDATE ")
  157.         .add(PosItem.TABLE_NAME)
  158.         .add(" SET tax_amount = :taxAmount , nett_amount_item = :nettAmountItem , qty = :qty , version = :version ")
  159.         .add(" WHERE pos_item_id = :posItemId AND pos_id = :posId ");
  160.        
  161.         Query queryUpdatePosTransactionItemQty = posItemDao.createNativeQuery(builder.toString());
  162.         queryUpdatePosTransactionItemQty.setParameter("taxAmount", getEditQtyItemTransactionDto.getDouble("taxAmount"));
  163.         queryUpdatePosTransactionItemQty.setParameter("nettAmountItem", getEditQtyItemTransactionDto.getDouble("nettAmountItem"));
  164.         queryUpdatePosTransactionItemQty.setParameter("qty", getEditQtyItemTransactionDto.getLong("qty"));
  165.         queryUpdatePosTransactionItemQty.setParameter("version", getEditQtyItemTransactionDto.getLong("version"));
  166.         queryUpdatePosTransactionItemQty.setParameter("posItemId", getEditQtyItemTransactionDto.getLong("posItemId"));
  167.         queryUpdatePosTransactionItemQty.setParameter("posId", getEditQtyItemTransactionDto.getLong("posId"));
  168.  
  169.         queryUpdatePosTransactionItemQty.executeUpdate();
  170.        
  171.         return new Dto();
  172.     }
  173.  
  174. }
Add Comment
Please, Sign In to add comment