Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.pos2.bo.postransaction;
- import java.math.BigDecimal;
- import org.jleaf.core.BusinessFunction;
- import org.jleaf.core.BusinessTransaction;
- import org.jleaf.core.CoreException;
- 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.pos2.PosConstants;
- import org.jleaf.pos2.PosExceptionConstants;
- import org.jleaf.pos2.entity.ProductSellPrice;
- import org.jleaf.pos2.dao.SellPriceProductDao;
- import org.jleaf.pos2.entity.Product;
- import org.jleaf.pos2.dao.ProductDao;
- import org.jleaf.pos2.entity.Pos;
- import org.jleaf.pos2.dao.PosDao;
- import org.jleaf.pos2.entity.PosCashier;
- import org.jleaf.pos2.entity.PosCashier;
- import org.jleaf.pos2.entity.PosItem;
- import org.jleaf.pos2.dao.PosItemDao;
- 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: AddPosTransaction
- *
- * @author Widana Nur Azis , 26 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 = "posId", description = "docNo", type = String.class),
- @Info(name = "posCashierId", description = "posCashierId", type = Long.class),
- @Info(name = "productCode", description = "productCode", type = String.class),
- @Info(name = "qty", description = "qty", type = Long.class),
- @Info(name = "flgDiscount", description = "flgDiscount", type = String.class),
- @Info(name = "discount", description = "discount", type = Double.class),
- @Info(name = "active", description = "active", type = String.class)
- })
- @InfoOut(value = {
- @Info(name = "posItemId", description = "posItemId", type = Long.class),
- @Info(name = "posId", description = "posId", type = Long.class),
- @Info(name = "lineNo,", description = "lineNo", type = Long.class),
- @Info(name = "productCode", description = "productCode", type = String.class),
- @Info(name = "productSerialNumber", description = "productSerialNumber", type = String.class),
- @Info(name = "uomCode", description = "uomCode", type = String.class),
- @Info(name = "qty", description = "qty", type = Long.class),
- @Info(name = "currCode", description = "currCode", type = String.class),
- @Info(name = "grossSellPrice", description = "grossSellPrice", type = Double.class),
- @Info(name = "taxId", description = "taxId", type = Long.class),
- @Info(name = "taxPercentage", description = "taxPercentage", type = Long.class),
- @Info(name = "taxPrice", description = "taxPrice", type = Double.class),
- @Info(name = "promoCode", description = "promoCode", type = String.class),
- @Info(name = "discountPercentage", description = "discountPercentage", type = Long.class),
- @Info(name = "discountAmount", description = "discountAmount", type = Double.class),
- @Info(name = "nettSellPrice", description = "nettSellPrice", type = Double.class),
- @Info(name = "taxAmount", description = "taxAmount", type = Double.class),
- @Info(name = "nettAmountItem", description = "nettAmountItem", type = Double.class),
- @Info(name = "remark", description = "remark", type = String.class),
- @Info(name = "flgDiscount", description = "flgDiscount", type = String.class),
- @Info(name = "flgTaxAmount", description = "flgTaxAmount", 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 = {
- PosExceptionConstants.DISCOUNT_MUST_BE_GREATER_THAN_ZERO
- })
- public class AddPosTransactionItem extends DefaultBusinessTransaction implements BusinessTransaction {
- @Autowired
- PosItemDao posItemDao;
- @Autowired
- @Qualifier("findPosById")
- BusinessFunction findPosById;
- @Autowired
- @Qualifier("findPosCashierById")
- BusinessFunction findPosCashierById;
- @Autowired
- @Qualifier("findProductById")
- BusinessFunction findProductById;
- @Autowired
- @Qualifier("findProductSellPriceById")
- BusinessFunction findProductSellPriceById;
- @Override
- public String getDescription() {
- // TODO Auto-generated method stub
- return "AddPosTransactionItem";
- }
- @SuppressWarnings("unchecked")
- @Override
- public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
- // TODO Auto-generated method stub
- ValidationUtil.valBlankOrNull(inputDto, "posId");
- ValidationUtil.valBlankOrNull(inputDto, "posCashierId");
- ValidationUtil.valBlankOrNull(inputDto, "productCode");
- ValidationUtil.valBlankOrNull(inputDto, "qty");
- ValidationUtil.valDtoContainsKey(inputDto, "posId");
- ValidationUtil.valDtoContainsKey(inputDto, "posCashierId");
- ValidationUtil.valDtoContainsKey(inputDto, "flgDiscount");
- ValidationUtil.valDtoContainsKey(inputDto, "qty");
- ValidationUtil.valDtoContainsKey(inputDto, "qty");
- Long posId = inputDto.getLong("posId");
- Long posCashierId = inputDto.getLong("posCashierId");
- String productCode = inputDto.getString("productCode");
- Long qty = inputDto.getLong("qty");
- String flgDiscount = inputDto.getString("flgDiscount");
- Double discountAmoutOrPercentage = inputDto.getDouble("discount");
- String flgTaxAmount = PosConstants.YES; // ambil dari system config
- Long taxPercentage = 10L; // ambil dari system config
- Double nettSellPrice = 0D;
- findPosById.execute(new Dto().put("id", posId));
- findPosCashierById.execute(new Dto().put("id", posCashierId));
- Dto findProductByIdDto = findProductById.execute(new Dto().put("productCode", productCode));
- Dto findProductSellPriceByIdDto = findProductSellPriceById.execute(new Dto().put("productCode", productCode));
- Double grossSellPrice = findProductSellPriceByIdDto.getDouble("grossSellPrice");
- Dto addPosTransactionItemDto = new Dto();
- BigDecimal sellPriceIncludeTaxBigDecimal = new BigDecimal((100 / (100 + taxPercentage) * grossSellPrice));
- BigDecimal sellPriceIncludeTaxBigDecimalAfterScale = sellPriceIncludeTaxBigDecimal.setScale(0, BigDecimal.ROUND_UP);
- Double sellPriceIncludeTax = sellPriceIncludeTaxBigDecimalAfterScale.doubleValue();
- Double taxPrice = grossSellPrice - sellPriceIncludeTax;
- if(flgDiscount.equals("PCT")){
- // nett sell price if flg discount PCT (grossSellPrice * ((100 - discountPercentage) / 100))
- ValidationUtil.valBlankOrNull(inputDto, "discount");
- ValidationUtil.valDtoContainsKey(inputDto, "discount");
- if(inputDto.getDouble("discount") <= PosConstants.ZERO_VALUE_DOUBEL){
- throw new CoreException(PosExceptionConstants.DISCOUNT_MUST_BE_GREATER_THAN_ZERO , PosConstants.ZERO_VALUE_DOUBEL);
- }
- nettSellPrice = new Calc(grossSellPrice)
- .multiply(new Calc(100).subtract(discountAmoutOrPercentage))
- .divide(100, 0, BigDecimal.ROUND_DOWN).doubleValue();
- addPosTransactionItemDto.put("discountPercentage", discountAmoutOrPercentage);
- addPosTransactionItemDto.put("discountAmount", nettSellPrice);
- } else if(flgDiscount.equals("AMT")) {
- // nett sell price if flg discount AMT (grossSellPrice - discountAmoutOrPercentage)
- ValidationUtil.valBlankOrNull(inputDto, "discount");
- ValidationUtil.valDtoContainsKey(inputDto, "discount");
- if(inputDto.getDouble("discount") <= PosConstants.ZERO_VALUE_DOUBEL){
- throw new CoreException(PosExceptionConstants.DISCOUNT_MUST_BE_GREATER_THAN_ZERO , PosConstants.ZERO_VALUE_DOUBEL);
- }
- nettSellPrice = new Calc(grossSellPrice).subtract(discountAmoutOrPercentage).doubleValue();
- addPosTransactionItemDto.put("discountPercentage", PosConstants.ZERO_VALUE_DOUBEL);
- addPosTransactionItemDto.put("discountAmount", discountAmoutOrPercentage);
- } else {
- // nett sell price if there no discount amount or percentage else nettSellPrice = taxPrice
- nettSellPrice = taxPrice;
- addPosTransactionItemDto.put("discountPercentage", PosConstants.ZERO_VALUE_DOUBEL);
- addPosTransactionItemDto.put("discountAmount", PosConstants.ZERO_VALUE_DOUBEL);
- }
- Double taxAmount = new Calc(qty).multiply(taxPrice).doubleValue();
- Double nettAmountItem = new Calc(qty).multiply(nettSellPrice).doubleValue();
- addPosTransactionItemDto.put("posId", posId);
- addPosTransactionItemDto.put("lineNo", 1);
- addPosTransactionItemDto.put("productCode", productCode);
- addPosTransactionItemDto.put("productSerailNumber", PosConstants.EMPTY_STRING);
- addPosTransactionItemDto.put("uomCode", findProductByIdDto.getString("baseUomCode"));
- addPosTransactionItemDto.put("qty", qty);
- addPosTransactionItemDto.put("currCode", "IDR");
- addPosTransactionItemDto.put("grossSellPrice", grossSellPrice);
- addPosTransactionItemDto.put("flgTaxAmount", flgTaxAmount);
- addPosTransactionItemDto.put("taxId", PosConstants.VALUE_DEFAULT);
- addPosTransactionItemDto.put("taxPercentage", taxPercentage);
- addPosTransactionItemDto.put("taxPrice", taxPrice);
- addPosTransactionItemDto.put("flgDiscount", flgDiscount);
- addPosTransactionItemDto.put("promoCode", "");
- addPosTransactionItemDto.put("nettSellPrice", nettSellPrice);
- addPosTransactionItemDto.put("taxAmount", taxAmount);
- addPosTransactionItemDto.put("nettAmountItem", nettAmountItem);
- addPosTransactionItemDto.put("remark", "");
- inputDto.put("addPosTransactionItemDto", addPosTransactionItemDto);
- return null;
- }
- @Override
- public Dto process(Dto inputDto, Dto originalDto) throws Exception {
- // TODO Auto-generated method stub
- Dto getAddPosTransactionItemDto = inputDto.getDto("addPosTransactionItemDto");
- PosItem entityPosItem = GsonUtil.fromDto(getAddPosTransactionItemDto, PosItem.class);
- posItemDao.persist(entityPosItem);
- return new Dto(entityPosItem);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement