Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.pos2.bo.postransaction;
- import java.util.List;
- import javax.persistence.Query;
- import org.jleaf.core.AbstractBusinessFunction;
- import org.jleaf.core.BusinessFunction;
- import org.jleaf.core.Dto;
- import org.jleaf.core.annotation.ErrorList;
- import org.jleaf.core.annotation.Info;
- import org.jleaf.core.annotation.InfoIn;
- import org.jleaf.core.annotation.InfoOut;
- import org.jleaf.pos2.entity.Pos;
- import org.jleaf.pos2.dao.PosDao;
- import org.jleaf.pos2.entity.PosCashier;
- import org.jleaf.pos2.dao.PosCashierDao;
- import org.jleaf.pos2.entity.PosItem;
- import org.jleaf.pos2.dao.PosItemDao;
- import org.jleaf.core.dao.CriteriaHelper;
- import org.jleaf.core.dao.QueryBuilder;
- import org.jleaf.util.DtoUtil;
- import org.jleaf.util.ValidationUtil;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- /**
- * Business Function: GetSummaryPosTransactionItemByPosId
- *
- * @author Widana Nur Azis 26 Oct 2016
- */
- @Service
- @InfoIn(value = {
- @Info(name = "userLoginId", description = "user login id", type = Long.class, required = true),
- @Info(name = "userLoginName", description = "user login name", type = String.class, required = true),
- @Info(name = "roleLoginId", description = "role login id", type = Long.class, required = true),
- @Info(name = "roleLoginName", description = "role login name", type = String.class, required = true),
- @Info(name = "tenantLoginId", description = "tenant login id", type = Long.class, required = true),
- @Info(name = "datetime", description = "datetime", type = String.class, required = true),
- @Info(name = "posId", description = "posId", type = Long.class, required = true),
- @Info(name = "posCashierId", description = "posCashierId", type = Long.class, required = true)
- })
- @InfoOut(value = {
- @Info(name = "posId", description = "posId", type = Long.class),
- @Info(name = "currCode", description = "currCode", type = String.class),
- @Info(name = "totalItem,", description = "totalItem", type = Long.class),
- @Info(name = "totalDiscount", description = "totalDiscount", type = Long.class),
- @Info(name = "subTotal", description = "subTotal", type = Long.class),
- @Info(name = "total", description = "total", type = Long.class)
- })
- @ErrorList(errorKeys = {})
- public class GetSummaryPosTransactionItemByPosId extends AbstractBusinessFunction implements BusinessFunction {
- @Autowired
- PosItemDao posItemDao;
- @Override
- public String getDescription() {
- // TODO Auto-generated method stub
- return "GetSummaryPosTransactionItemByPosId";
- }
- @SuppressWarnings("unchecked")
- @Override
- public Dto execute(Dto inputDto) throws Exception {
- // TODO Auto-generated method stub
- ValidationUtil.valBlankOrNull(inputDto, "posId");
- ValidationUtil.valBlankOrNull(inputDto, "posCashierId");
- ValidationUtil.valDtoContainsKey(inputDto, "posId");
- ValidationUtil.valDtoContainsKey(inputDto, "posCashierId");
- List<Object[]> result = null;
- QueryBuilder builder = new QueryBuilder();
- builder.add(" SELECT ")
- .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, ")
- .add(" COALESCE(SUM(B.qty),0) AS total_qty, COALESCE(SUM(B.discount_amount),0) AS total_discount ,")
- .add(" (COALESCE(SUM(B.qty * B.gross_sell_price),0) - COALESCE(SUM(B.discount_amount),0)) AS total ")
- .add(" FROM ")
- .add(Pos.TABLE_NAME).add(" A ")
- .add(" LEFT JOIN ").add(PosItem.TABLE_NAME).add(" B ").add(" ON A.pos_id = B.pos_id ")
- .add(" RIGHT JOIN ").add(PosCashier.TABLE_NAME).add(" C ").add(" ON ").add(" A.pos_cashier_id = C.pos_cashier_id ")
- .add(" WHERE A.pos_id = :posId AND C.pos_cashier_id = :posCashierId")
- .add(" GROUP BY A.pos_id, A.curr_code , C.pos_cashier_id");
- Query query = posItemDao.createNativeQuery(builder.toString());
- query.setParameter("posId", inputDto.getLong("posId"));
- query.setParameter("posCashierId", inputDto.getLong("posCashierId"));
- result = query.getResultList();
- return new Dto().putList("summaryTransactionItem", DtoUtil.createDtoListFromArray(result,
- "posId","currCode","posCashierId","totalItem","subTotal","totalQty","totalDiscount","total"
- ));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment