widana

GetPosTransactionItemListById

Oct 26th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.80 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.core.dao.CriteriaHelper;
  15. import org.jleaf.core.dao.QueryBuilder;
  16. import org.jleaf.pos2.entity.PosItem;
  17. import org.jleaf.pos2.dao.PosItemDao;
  18. import org.jleaf.pos2.entity.Pos;
  19. import org.jleaf.pos2.entity.PosCashier;
  20. import org.jleaf.util.DtoUtil;
  21. import org.jleaf.util.ValidationUtil;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.stereotype.Service;
  24.  
  25. /**
  26.  * Business Function: GetPosTransactionItemByPosId
  27.  *
  28.  * @author Widana Nur Azis 24 Oct 2016
  29.  */
  30.  
  31. @Service
  32. @InfoIn(value = {
  33.         @Info(name = "userLoginId", description = "user login id", type = Long.class, required = true),
  34.         @Info(name = "userLoginName", description = "user login name", type = String.class, required = true),
  35.         @Info(name = "roleLoginId", description = "role login id", type = Long.class, required = true),
  36.         @Info(name = "roleLoginName", description = "role login name", type = String.class, required = true),
  37.         @Info(name = "tenantLoginId", description = "tenant login id", type = Long.class, required = true),
  38.         @Info(name = "datetime", description = "datetime", type = String.class, required = true),
  39.  
  40.         @Info(name = "posId", description = "posId", type = Long.class, required = true),
  41.         @Info(name = "posCashierId", description = "posCashierId", type = Long.class, required = true)
  42.  
  43. })
  44.  
  45. @InfoOut(value = {})
  46.  
  47. @ErrorList(errorKeys = {})
  48.  
  49. public class GetPosTransactionItemListById extends AbstractBusinessFunction
  50.         implements BusinessFunction {
  51.  
  52.     @Autowired
  53.     PosItemDao posItemDao;
  54.  
  55.     @Override
  56.     public String getDescription() {
  57.  
  58.         return "GetPosTransactionItemByPosId item for buy to customer";
  59.     }
  60.  
  61.     @SuppressWarnings("unchecked")
  62.     @Override
  63.     public Dto execute(Dto inputDto) throws Exception {
  64.  
  65.         ValidationUtil.valBlankOrNull(inputDto, "posId");
  66.         ValidationUtil.valBlankOrNull(inputDto, "posCashierId");
  67.  
  68.         ValidationUtil.valDtoContainsKey(inputDto, "posId");
  69.         ValidationUtil.valDtoContainsKey(inputDto, "posCashierId");
  70.  
  71.         List<Object[]> result = null;
  72.  
  73.         QueryBuilder builder = new QueryBuilder();
  74.  
  75.         builder.add(" SELECT ")
  76.                 .add(" A.pos_item_id, A.pos_id, A.line_no, A.product_code, A.product_serial_number,  ")
  77.                 .add(" A.uom_code, A.qty, A.curr_code, A.gross_sell_price, A.tax_id, A.tax_percentage,  ")
  78.                 .add(" A.tax_price, A.promo_code, A.discount_percentage, A.discount_amount,  ")
  79.                 .add(" A.nett_sell_price, A.tax_amount, A.nett_amount_item, A.remark, A.active,  ")
  80.                 .add(" A.active_datetime, A.non_active_datetime, A.version, A.create_datetime,  ")
  81.                 .add(" A.create_username, A.update_datetime, A.update_username, A.flg_tax_amount, ")
  82.                 .add(" COALESCE(SUM(A.gross_sell_price * A.qty),0) total_amount ")
  83.                 .add(" FROM ")
  84.                 .add(PosItem.TABLE_NAME)
  85.                 .add(" A ")
  86.                 .add(" INNER JOIN ")
  87.                 .add(Pos.TABLE_NAME)
  88.                 .add(" B ")
  89.                 .add(" ON B.pos_id = A.pos_id ")
  90.                 .add(" INNER JOIN ")
  91.                 .add(PosCashier.TABLE_NAME)
  92.                 .add(" C ")
  93.                 .add(" ON C.pos_cashier_id = B.pos_cashier_id ")
  94.                 .add(" WHERE A.pos_id = :posId AND B.pos_cashier_id = :posCashierId ")
  95.                 .add(" GROUP BY ")
  96.                 .add(" A.pos_item_id, A.pos_id, A.line_no, A.product_code, A.product_serial_number,  ")
  97.                 .add(" A.uom_code, A.qty, A.curr_code, A.gross_sell_price, A.tax_id, A.tax_percentage,  ")
  98.                 .add(" A.tax_price, A.promo_code, A.discount_percentage, A.discount_amount,  ")
  99.                 .add(" A.nett_sell_price, A.tax_amount, A.nett_amount_item, A.remark, A.active,  ")
  100.                 .add(" A.active_datetime, A.non_active_datetime, A.version, A.create_datetime,  ")
  101.                 .add(" A.create_username, A.update_datetime, A.update_username, A.flg_tax_amount");
  102.  
  103.         Query query = posItemDao.createNativeQuery(builder.toString());
  104.         query.setParameter("posId", inputDto.getLong("posId"));
  105.         query.setParameter("posCashierId", inputDto.getLong("posCashierId"));
  106.  
  107.         result = query.getResultList();
  108.  
  109.         return new Dto().putList("posItemTransaction", DtoUtil
  110.                 .createDtoListFromArray(result, "posItemId", "posId", "lineNo",
  111.                         "productCode", "productSerialNumber", "uomCode", "qty",
  112.                         "currCode", "grossSellPrice", "taxId", "taxPercentage",
  113.                         "taxPrice", "promoCode", "discountPercentage",
  114.                         "discountAmount", "nettSellPrice", "taxAmount",
  115.                         "nettAmountItem", "remark", "active", "activeDatetime",
  116.                         "nonActiveDatetime", "version", "createDatetime",
  117.                         "createUsername", "updateDatetime", "updateUsername",
  118.                         "flgTaxAmount", "totalAmount"));
  119.     }
  120.  
  121. }
Advertisement
Add Comment
Please, Sign In to add comment