Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.pos2.bo.postransaction;
- import javax.persistence.Query;
- import org.jleaf.core.BusinessFunction;
- import org.jleaf.core.BusinessTransaction;
- import org.jleaf.core.DefaultBusinessTransaction;
- import org.jleaf.core.Dto;
- import org.jleaf.core.GeneralConstants;
- 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.core.dao.QueryBuilder;
- import org.jleaf.pos2.PosConstants;
- import org.jleaf.pos2.entity.Pos;
- import org.jleaf.pos2.entity.PosItem;
- import org.jleaf.pos2.dao.PosItemDao;
- import org.jleaf.pos2.util.PosUtil;
- import org.jleaf.util.Calc;
- import org.jleaf.util.GsonUtil;
- import org.jleaf.util.ValidationUtil;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Qualifier;
- import org.springframework.stereotype.Service;
- /**
- * Business Transactions: EditQtyItemTransaction
- *
- * @author Widana Nur Azis , 25 Oct 2016
- */
- // @formatter:off
- @Service
- @InfoIn(value = {
- @Info(name = "userLoginId", description = "user login id", type = Long.class),
- @Info(name = "userLoginName", description = "user login name", type = String.class),
- @Info(name = "roleLoginId", description = "role login id", type = Long.class),
- @Info(name = "roleLoginName", description = "role login name", type = String.class),
- @Info(name = "tenantLoginId", description = "tenantLoginId", type = Long.class),
- @Info(name = "datetime", description = "date time", type = String.class),
- @Info(name = "posItemId", description = "posItemId", type = Long.class),
- @Info(name = "posCashierId", description = "posCashierId", type = Long.class),
- @Info(name = "posId", description = "posId", type = Long.class),
- @Info(name = "qty", description = "qty", type = Long.class)
- })
- @InfoOut(value = {
- @Info(name = "posId", description = "posId", type = Long.class),
- @Info(name = "posCashierId", description = "posCashierId", type = Long.class),
- @Info(name = "docTypeId", description = "docTypeId", type = Long.class),
- @Info(name = "docNo", description = "docNo", type = String.class),
- @Info(name = "docDate", description = "docDate", type = String.class),
- @Info(name = "extDocNo", description = "extDocNo", type = String.class),
- @Info(name = "extDocDate", description = "extDocDate", type = String.class),
- @Info(name = "refDocTypeId", description = "refDocTypeId", type = String.class),
- @Info(name = "refId", description = "refId", type = Long.class),
- @Info(name = "remark", description = "remark", type = String.class),
- @Info(name = "customerCode", description = "customerCode", type = String.class),
- @Info(name = "customerName", description = "customerName", type = String.class),
- @Info(name = "customerPhone", description = "customerPhone", type = String.class),
- @Info(name = "salesmanCode", description = "salesmanCode", type = String.class),
- @Info(name = "currCode", description = "currCode", type = String.class),
- @Info(name = "grossAmount", description = "grossAmount", type = String.class),
- @Info(name = "totalDiscountItem", description = "totalDiscountItem", type = Double.class),
- @Info(name = "addDiscountPercentage", description = "addDiscountPercentage", type = Double.class),
- @Info(name = "addDiscountAmount", description = "addDiscountAmount", type = Double.class),
- @Info(name = "nettAmount", description = "nettAmount", type = Double.class),
- @Info(name = "taxAmount", description = "taxAmount", type = Double.class),
- @Info(name = "addAmount", description = "addAmount", type = Double.class),
- @Info(name = "totalAmount", description = "totalAmount", type = Double.class),
- @Info(name = "roundingAmount", description = "roundingAmount", type = Double.class),
- @Info(name = "totalPayment", description = "totalPayment", type = Double.class),
- @Info(name = "totalRefund", description = "totalRefund", type = Double.class),
- @Info(name = "status", description = "status", type = String.class),
- @Info(name = "createUsername", description = "create username", type = String.class),
- @Info(name = "updateUsername", description = "update username", type = String.class),
- @Info(name = "active", description = "active", type = String.class, required = true),
- @Info(name = "activeDateTime", description = "active date time", type = String.class),
- @Info(name = "nonActiveDateTime", description = "non active date time", type = String.class),
- @Info(name = "createDateTime", description = "create date time", type = String.class),
- @Info(name = "updateDateTime", description = "update date time", type = String.class),
- @Info(name = "version", description = "version", type = Long.class) })
- // @formatter:on
- @ErrorList(errorKeys = {})
- public class EditQtyItemTransaction extends DefaultBusinessTransaction implements BusinessTransaction {
- @Autowired
- PosItemDao posItemDao;
- @Autowired
- @Qualifier("findPosCashierById")
- BusinessFunction findPosCashierById;
- @Autowired
- @Qualifier("findPosById")
- BusinessFunction findPosById;
- @Autowired
- @Qualifier("findPosTransactionItemById")
- BusinessFunction findPosTransactionItemById;
- @Override
- public String getDescription() {
- // TODO Auto-generated method stub
- return "EditQtyItemTransaction using for edit qty pos transaction item";
- }
- @Override
- public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
- // TODO Auto-generated method stub
- ValidationUtil.valBlankOrNull(inputDto, "posItemId");
- ValidationUtil.valBlankOrNull(inputDto, "posCashierId");
- ValidationUtil.valBlankOrNull(inputDto, "posId");
- ValidationUtil.valBlankOrNull(inputDto, "qty");
- ValidationUtil.valDtoContainsKey(inputDto, "posItemId");
- ValidationUtil.valDtoContainsKey(inputDto, "posCashierId");
- ValidationUtil.valDtoContainsKey(inputDto, "posId");
- ValidationUtil.valDtoContainsKey(inputDto, "qty");
- findPosCashierById.execute(new Dto().put("id", inputDto.getLong("posCashierId")));
- Dto findPosByIdDto = findPosById.execute(new Dto().put("id", inputDto.getLong("posId")));
- Dto findPosTransactionItemByIdDto = findPosTransactionItemById.execute(new Dto().put("id", inputDto.getLong("posItemId")));
- Double taxAmount = new Calc(findPosTransactionItemByIdDto.getDouble("taxPrice")).multiply(inputDto.getLong("qty")).doubleValue();
- Double nettAmountItem = new Calc(findPosTransactionItemByIdDto.getDouble("nettSellPrice")).multiply(inputDto.getLong("qty")).doubleValue();
- Dto editQtyItemTransactionDto = new Dto();
- editQtyItemTransactionDto.put("posItemId", findPosTransactionItemByIdDto.getLong("id"));
- editQtyItemTransactionDto.put("posId", findPosByIdDto.getLong("id"));
- editQtyItemTransactionDto.put("taxAmount", taxAmount);
- editQtyItemTransactionDto.put("nettAmountItem", nettAmountItem);
- editQtyItemTransactionDto.put("qty", inputDto.getLong("qty"));
- editQtyItemTransactionDto.put("version", findPosTransactionItemByIdDto.getLong("version")+1);
- inputDto.put("editQtyItemTransactionDto", editQtyItemTransactionDto);
- return null;
- }
- @Override
- public Dto process(Dto inputDto, Dto originalDto) throws Exception {
- // TODO Auto-generated method stub
- Dto getEditQtyItemTransactionDto = inputDto.getDto("editQtyItemTransactionDto");
- QueryBuilder builder = new QueryBuilder();
- builder.add(" UPDATE ")
- .add(PosItem.TABLE_NAME)
- .add(" SET tax_amount = :taxAmount , nett_amount_item = :nettAmountItem , qty = :qty , version = :version ")
- .add(" WHERE pos_item_id = :posItemId AND pos_id = :posId ");
- Query queryUpdatePosTransactionItemQty = posItemDao.createNativeQuery(builder.toString());
- queryUpdatePosTransactionItemQty.setParameter("taxAmount", getEditQtyItemTransactionDto.getDouble("taxAmount"));
- queryUpdatePosTransactionItemQty.setParameter("nettAmountItem", getEditQtyItemTransactionDto.getDouble("nettAmountItem"));
- queryUpdatePosTransactionItemQty.setParameter("qty", getEditQtyItemTransactionDto.getLong("qty"));
- queryUpdatePosTransactionItemQty.setParameter("version", getEditQtyItemTransactionDto.getLong("version"));
- queryUpdatePosTransactionItemQty.setParameter("posItemId", getEditQtyItemTransactionDto.getLong("posItemId"));
- queryUpdatePosTransactionItemQty.setParameter("posId", getEditQtyItemTransactionDto.getLong("posId"));
- queryUpdatePosTransactionItemQty.executeUpdate();
- return new Dto();
- }
- }
Add Comment
Please, Sign In to add comment