widana

GetSummaryPosTransactionItemByPosId

Oct 26th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.30 KB | None | 0 0
  1. package org.jleaf.pos2.bo.postransaction;
  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.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.pos2.entity.Pos;
  15. import org.jleaf.pos2.dao.PosDao;
  16. import org.jleaf.pos2.entity.PosCashier;
  17. import org.jleaf.pos2.dao.PosCashierDao;
  18. import org.jleaf.pos2.entity.PosItem;
  19. import org.jleaf.pos2.dao.PosItemDao;
  20. import org.jleaf.core.dao.CriteriaHelper;
  21. import org.jleaf.core.dao.QueryBuilder;
  22. import org.jleaf.util.DtoUtil;
  23. import org.jleaf.util.ValidationUtil;
  24. import org.slf4j.Logger;
  25. import org.slf4j.LoggerFactory;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.stereotype.Service;
  28.  
  29. /**
  30.  * Business Function: GetSummaryPosTransactionItemByPosId
  31.  *
  32.  * @author Widana Nur Azis 26 Oct 2016
  33.  */
  34.  
  35. @Service
  36. @InfoIn(value = {
  37.         @Info(name = "userLoginId", description = "user login id", type = Long.class, required = true),
  38.         @Info(name = "userLoginName", description = "user login name", type = String.class, required = true),
  39.         @Info(name = "roleLoginId", description = "role login id", type = Long.class, required = true),
  40.         @Info(name = "roleLoginName", description = "role login name", type = String.class, required = true),
  41.         @Info(name = "tenantLoginId", description = "tenant login id", type = Long.class, required = true),
  42.         @Info(name = "datetime", description = "datetime", type = String.class, required = true),
  43.  
  44.         @Info(name = "posId", description = "posId", type = Long.class, required = true),
  45.         @Info(name = "posCashierId", description = "posCashierId", type = Long.class, required = true)
  46. })
  47.  
  48. @InfoOut(value = {
  49.         @Info(name = "posId", description = "posId", type = Long.class),
  50.         @Info(name = "currCode", description = "currCode", type = String.class),
  51.         @Info(name = "totalItem,", description = "totalItem", type = Long.class),
  52.         @Info(name = "totalDiscount", description = "totalDiscount", type = Long.class),
  53.         @Info(name = "subTotal", description = "subTotal", type = Long.class),
  54.         @Info(name = "total", description = "total", type = Long.class)
  55. })
  56. @ErrorList(errorKeys = {})
  57.  
  58. public class GetSummaryPosTransactionItemByPosId extends AbstractBusinessFunction implements BusinessFunction {
  59.  
  60.     @Autowired
  61.     PosItemDao posItemDao;
  62.    
  63.     @Override
  64.     public String getDescription() {
  65.         // TODO Auto-generated method stub
  66.         return "GetSummaryPosTransactionItemByPosId";
  67.     }
  68.    
  69.     @SuppressWarnings("unchecked")
  70.     @Override
  71.     public Dto execute(Dto inputDto) throws Exception {
  72.         // TODO Auto-generated method stub
  73.        
  74.         ValidationUtil.valBlankOrNull(inputDto, "posId");
  75.         ValidationUtil.valBlankOrNull(inputDto, "posCashierId");
  76.  
  77.         ValidationUtil.valDtoContainsKey(inputDto, "posId");
  78.         ValidationUtil.valDtoContainsKey(inputDto, "posCashierId");
  79.        
  80.         List<Object[]> result = null;
  81.        
  82.         QueryBuilder builder = new QueryBuilder();
  83.        
  84.         builder.add(" SELECT ")
  85.         .add(" A.pos_id , A.curr_code , C.pos_cashier_id , COALESCE(COUNT(B.pos_id),0) AS total_item , COALESCE(SUM(B.qty * B.gross_sell_price),0) AS sub_total, ")
  86.         .add(" COALESCE(SUM(B.qty),0) AS total_qty, COALESCE(SUM(B.discount_amount),0) AS total_discount ,")
  87.         .add(" (COALESCE(SUM(B.qty * B.gross_sell_price),0) - COALESCE(SUM(B.discount_amount),0)) AS total ")
  88.         .add(" FROM ")
  89.         .add(Pos.TABLE_NAME).add(" A ")
  90.         .add(" LEFT JOIN ").add(PosItem.TABLE_NAME).add(" B ").add(" ON A.pos_id = B.pos_id ")
  91.         .add(" RIGHT JOIN ").add(PosCashier.TABLE_NAME).add(" C ").add(" ON ").add(" A.pos_cashier_id = C.pos_cashier_id ")
  92.         .add(" WHERE A.pos_id = :posId AND C.pos_cashier_id = :posCashierId")
  93.         .add(" GROUP BY A.pos_id, A.curr_code , C.pos_cashier_id");
  94.  
  95.         Query query = posItemDao.createNativeQuery(builder.toString());
  96.         query.setParameter("posId", inputDto.getLong("posId"));
  97.         query.setParameter("posCashierId", inputDto.getLong("posCashierId"));
  98.        
  99.         result = query.getResultList();
  100.        
  101.         return new Dto().putList("summaryTransactionItem", DtoUtil.createDtoListFromArray(result,
  102.                 "posId","currCode","posCashierId","totalItem","subTotal","totalQty","totalDiscount","total"
  103.                 ));
  104.        
  105.     }
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment