Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.erp.sls.bo.salesquotation;
- import java.util.ArrayList;
- import java.util.List;
- 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.Info;
- import org.jleaf.core.annotation.InfoIn;
- import org.jleaf.core.annotation.InfoOut;
- import org.jleaf.erp.sls.SalesConstants;
- import org.jleaf.erp.sls.SalesExceptionConstants;
- import org.jleaf.erp.sls.dao.SalesQuotationDao;
- import org.jleaf.erp.sls.dao.SalesQuotationItemDao;
- import org.jleaf.erp.sls.dao.SalesQuotationTcDao;
- import org.jleaf.erp.sls.entity.SalesQuotation;
- import org.jleaf.erp.sls.entity.SalesQuotationItem;
- import org.jleaf.erp.sls.entity.SalesQuotationTc;
- import org.jleaf.erp.sls.entity.BalanceQuotation;
- import org.jleaf.erp.sls.dao.BalanceQuotationDao;
- import org.jleaf.util.DtoUtil;
- 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;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- /**
- *
- * @author Widana, Sep 15, 2017
- *
- **/
- @Service
- @InfoIn(value = {
- @Info(name = "tenantLoginId", description = "tenant login id", type = Long.class),
- @Info(name = "userLoginId", description = "User Login Id", type = Long.class),
- @Info(name = "roleLoginId", description = "roleLoginId", type = Long.class),
- @Info(name = "datetime", description = "datetime", type = String.class),
- @Info(name = "docNo", description = "doc No", type = String.class),
- @Info(name = "docDate", description = "doc Date", type = String.class),
- @Info(name = "ouId", description = "ou Id", type = Long.class),
- @Info(name = "quotationId", description = "ou Id", type = Long.class),
- @Info(name = "remark", description = "remark", type = String.class)
- })
- @InfoOut(value = {
- @Info(name = "id", description = "quotation Id", type = Long.class)
- })
- public class AddSalesQuotationFromRevision extends DefaultBusinessTransaction implements BusinessTransaction {
- private static final Logger log = LoggerFactory.getLogger(AddSalesQuotationFromRevision.class);
- @Autowired
- SalesQuotationDao salesQuotationDao;
- @Autowired
- SalesQuotationItemDao salesQuotationItemDao;
- @Autowired
- SalesQuotationTcDao salesQuotationTcDao;
- @Autowired
- BalanceQuotationDao balanceQuotationDao;
- @Autowired
- @Qualifier("findSalesQuotationById")
- BusinessFunction findSalesQuotationById;
- @Autowired
- @Qualifier("findSalesQuotationItemById")
- BusinessFunction findSalesQuotationItemById;
- @Autowired
- @Qualifier("findSalesQuotationTcById")
- BusinessFunction findSalesQuotationTcById;
- @Autowired
- @Qualifier("valTenantLoginCanUse")
- BusinessFunction valTenantLoginCanUse;
- @Autowired
- @Qualifier("findOUById")
- BusinessFunction findOUById;
- @Autowired
- @Qualifier("valOUAsMainBusinessUnitOrBranch")
- BusinessFunction valOUAsMainBusinessUnitOrBranch;
- @Autowired
- @Qualifier("findPartnerById")
- BusinessFunction findPartnerById;
- @Autowired
- @Qualifier("findPartnerCpById")
- BusinessFunction findPartnerCpById;
- @Autowired
- @Qualifier("findPartnerAddressById")
- BusinessFunction findPartnerAddressById;
- @Autowired
- @Qualifier("getSalesQuotationItemListBySalesQuotation")
- BusinessFunction getSalesQuotationItemListBySalesQuotation;
- @Autowired
- @Qualifier("getTermsAndConditionSalesQuotation")
- BusinessFunction getTermsAndConditionSalesQuotation;
- @Autowired
- @Qualifier("findBalanceQuotationById")
- BusinessFunction findBalanceQuotationById;
- @Override
- public String getDescription() {
- return "Add Sales Quotation From Revision";
- }
- @SuppressWarnings("unchecked")
- @Override
- public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
- log.info("prepare inputDto addSalesQuotationFromRevision " + inputDto.toString());
- this.validationUtil(inputDto);
- Long tenantId = inputDto.getLong("tenantLoginId");
- Long userId = inputDto.getLong("userLoginId");
- Long roleId = inputDto.getLong("roleLoginId");
- Long quotationId = inputDto.getLong("quotationId");
- Long ouId = inputDto.getLong("ouId");
- String datetime = inputDto.getString("datetime");
- String docNo = inputDto.getString("docNo");
- String docDate = inputDto.getString("docDate");
- String remark = inputDto.getString("remark");
- Dto loginDto = new Dto();
- loginDto.put("tenantLoginId", tenantId);
- loginDto.put("userLoginId", userId);
- loginDto.put("roleLoginId", roleId);
- valTenantLoginCanUse.execute(loginDto);
- Dto ouAsMainBusinessOrBranchDto = new Dto();
- ouAsMainBusinessOrBranchDto.put("id", ouId);
- valOUAsMainBusinessUnitOrBranch.execute(ouAsMainBusinessOrBranchDto);
- Dto ouDto = new Dto();
- ouDto.put("id", ouId);
- findOUById.execute(ouDto);
- Dto salesQuotationDto = new Dto();
- salesQuotationDto.put("id", quotationId);
- Dto resultSalesQuotation = findSalesQuotationById.execute(salesQuotationDto);
- if(!resultSalesQuotation.getLong("partnerId").equals(GeneralConstants.NULL_REF_VALUE_LONG)){
- Dto partnerDto = new Dto();
- partnerDto.put("id", resultSalesQuotation.getLong("partnerId"));
- findPartnerById.execute(partnerDto);
- }
- if(!resultSalesQuotation.getLong("partnerCpId").equals(GeneralConstants.NULL_REF_VALUE_LONG)){
- Dto partnerCpDto = new Dto();
- partnerCpDto.put("id", resultSalesQuotation.getLong("partnerCpId"));
- findPartnerCpById.execute(partnerCpDto);
- }
- if(!resultSalesQuotation.getLong("partnerAddressId").equals(GeneralConstants.NULL_REF_VALUE_LONG)){
- Dto partnerAddressDto = new Dto();
- partnerAddressDto.put("id", resultSalesQuotation.getLong("partnerAddressId"));
- findPartnerAddressById.execute(partnerAddressDto);
- }
- Dto balanceQuotationDto = new Dto();
- balanceQuotationDto.put("id", quotationId);
- Dto resultBalanceQuotation = findBalanceQuotationById.execute(balanceQuotationDto);
- if(resultBalanceQuotation.getString("statusDoc").equals(SalesConstants.IN_PROGRESS_TRANSACTION)) {
- throw new CoreException(SalesExceptionConstants.SALES_QUOTATION_ALREADY_IN_USE_OTHER_TRANSACTION);
- }
- if(resultBalanceQuotation.getString("flgRevision").equals(GeneralConstants.YES)) {
- throw new CoreException(SalesExceptionConstants.SALES_QUOTATION_ALREADY_REVISION_WITH_DOCUMENT_NO, resultSalesQuotation.getString("docNo"));
- }
- resultBalanceQuotation.put("statusDoc", SalesConstants.IN_PROGRESS_TRANSACTION);
- this.prepareUpdateAudit(resultBalanceQuotation, userId, datetime);
- Dto salesQuotationItemDto = new Dto();
- salesQuotationItemDto.put("tenantId", tenantId);
- salesQuotationItemDto.put("quotationId", quotationId);
- Dto salesQuotationItemListDto = getSalesQuotationItemListBySalesQuotation.execute(salesQuotationItemDto);
- List<Dto> itemSalesQuotationList = salesQuotationItemListDto.getList("salesQuotationItemList");
- List<Dto> inputSalesQuotationItemDto = new ArrayList<Dto>();
- List<Dto> failList = new ArrayList<Dto>();
- if(itemSalesQuotationList.size() == 0 || itemSalesQuotationList == null) {
- throw new CoreException(SalesExceptionConstants.SALES_ORDER_MUST_HAVE_AT_LEAST_ONE_DETAIL_ITEM);
- }
- Long lineNo = 0L;
- for(Dto itemDto : itemSalesQuotationList) {
- lineNo++;
- try {
- Dto quotationItemDto = new Dto();
- quotationItemDto.put("id", Long.valueOf(itemDto.get("quotationItemId").toString()));
- Dto resultSalesQuotationItem = findSalesQuotationItemById.execute(quotationItemDto);
- log.debug("isiitemSQRev : "+resultSalesQuotationItem);
- if(resultSalesQuotationItem.get("flgStock").equals(GeneralConstants.NO)) {
- if(resultSalesQuotationItem.get("indentDays").equals("0")){
- throw new CoreException(SalesExceptionConstants.INDENT_DAYS_MUST_BE_GREATER_THAN_ZERRO);
- }
- }
- Dto inputItemDto = new Dto();
- inputItemDto.put("tenantId", tenantId);
- inputItemDto.put("lineNo", lineNo);
- inputItemDto.put("refId", resultSalesQuotationItem.getLong("id"));
- inputItemDto.put("refDocTypeId", SalesConstants.DOCUMENT_SALES_QUOTATION);
- inputItemDto.put("productId", resultSalesQuotationItem.getLong("productId"));
- inputItemDto.put("productCode", resultSalesQuotationItem.getString("productCode"));
- inputItemDto.put("productDesc", resultSalesQuotationItem.getString("productDesc"));
- inputItemDto.put("qty", resultSalesQuotationItem.getDouble("qty"));
- inputItemDto.put("uomId", resultSalesQuotationItem.getLong("uomId"));
- inputItemDto.put("sellPrice", resultSalesQuotationItem.getDouble("sellPrice"));
- inputItemDto.put("amount", resultSalesQuotationItem.getDouble("amount"));
- inputItemDto.put("brandCode", resultSalesQuotationItem.getString("brandCode"));
- inputItemDto.put("brandName", resultSalesQuotationItem.getString("brandName"));
- inputItemDto.put("remark", resultSalesQuotationItem.getString("remark"));
- inputItemDto.put("flgStock", resultSalesQuotationItem.getString("flgStock"));
- this.prepareInsertAudit(inputItemDto, userId, datetime);
- this.prepareUpdateAudit(inputItemDto, userId, datetime);
- log.debug("resultSalesQuotationItemIsi >>> : "+resultSalesQuotationItem);
- inputSalesQuotationItemDto.add(inputItemDto);
- } catch(CoreException e) {
- Dto errorDto = new Dto();
- errorDto.put("productCode", itemDto.getString("productCode"));
- errorDto.put("productName", itemDto.getString("productDesc"));
- errorDto.put("flgStock", itemDto.getString("flgStock"));
- errorDto.put("indentDays", itemDto.getString("indentDays"));
- errorDto.put("qty", Double.valueOf(itemDto.getString("qty").toString()));
- errorDto.put("sellPrice", Double.valueOf(itemDto.getString("sellPrice").toString()));
- errorDto.put("amount", Double.valueOf(itemDto.getString("amount").toString()));
- errorDto.put("errorKey", e.getErrorKey());
- List<Object> argsList = new ArrayList<Object>();
- if (e.getParamValues() != null && e.getParamValues().length > 0)
- for (Object paramValue : e.getParamValues()) {
- argsList.add(paramValue);
- }
- errorDto.put("args", argsList);
- failList.add(errorDto);
- }
- }
- Dto salesQuotationTcDto = new Dto();
- salesQuotationTcDto.put("tenantId", tenantId);
- salesQuotationTcDto.put("quotationId", quotationId);
- Dto salesQuotationTcItemListDto = getTermsAndConditionSalesQuotation.execute(salesQuotationTcDto);
- List<Dto> itemSalesQuotationDto = salesQuotationTcItemListDto.getList("termsAndConditionList");
- List<Dto> inputSalesQuotationTcDto = new ArrayList<Dto>();
- if(itemSalesQuotationDto.size() > 0) {
- Long lineNoTc = 0L;
- for(Dto itemDto : itemSalesQuotationDto) {
- lineNoTc++;
- Dto inputItemDto = new Dto();
- inputItemDto.put("tenantId", tenantId);
- inputItemDto.put("lineNo", lineNoTc);
- inputItemDto.put("termCondition", itemDto.getString("termCondition"));
- this.prepareInsertAudit(inputItemDto, userId, datetime);
- this.prepareUpdateAudit(inputItemDto, userId, datetime);
- inputSalesQuotationTcDto.add(inputItemDto);
- }
- }
- if (!failList.isEmpty()) {
- Dto errorParamDto = new Dto();
- DtoUtil.putInErrorParamDto(errorParamDto, "failList",
- new String[] { "productCode", "productName", "flgStock", "indentDays", "qty", "sellPrice", "amount", "errorKey", "args" }, failList);
- throw new CoreException(SalesExceptionConstants.SALES_QUOTATION_ITEMS_ERROR, errorParamDto);
- }
- Dto inputSalesQuotationDto = new Dto();
- inputSalesQuotationDto.put("tenantId", tenantId);
- inputSalesQuotationDto.put("ouId", ouId);
- inputSalesQuotationDto.put("docTypeId", SalesConstants.DOCUMENT_SALES_QUOTATION);
- inputSalesQuotationDto.put("docNo", docNo);
- inputSalesQuotationDto.put("docDate", docDate);
- inputSalesQuotationDto.put("extDocNo", resultSalesQuotation.getString("extDocNo"));
- inputSalesQuotationDto.put("extDocDate", resultSalesQuotation.getString("extDocDate"));
- inputSalesQuotationDto.put("refDocTypeId", SalesConstants.DOCUMENT_SALES_QUOTATION);
- inputSalesQuotationDto.put("refId", quotationId);
- inputSalesQuotationDto.put("partnerId", resultSalesQuotation.getLong("partnerId"));
- inputSalesQuotationDto.put("partnerAddressId", resultSalesQuotation.getLong("partnerAddressId"));
- inputSalesQuotationDto.put("partnerName", resultSalesQuotation.getString("partnerName"));
- inputSalesQuotationDto.put("partnerAddress1", resultSalesQuotation.getString("partnerAddress1"));
- inputSalesQuotationDto.put("partnerAddress2", resultSalesQuotation.getString("partnerAddress2"));
- inputSalesQuotationDto.put("partnerAddress3", resultSalesQuotation.getString("partnerAddress3"));
- inputSalesQuotationDto.put("partnerCpId", resultSalesQuotation.getLong("partnerCpId"));
- inputSalesQuotationDto.put("partnerCpName", resultSalesQuotation.getString("partnerCpName"));
- inputSalesQuotationDto.put("partnerCpPhone1", resultSalesQuotation.getString("partnerCpPhone1"));
- inputSalesQuotationDto.put("partnerCpPhone2", resultSalesQuotation.getString("partnerCpPhone2"));
- inputSalesQuotationDto.put("partnerCpFax1", resultSalesQuotation.getString("partnerCpFax1"));
- inputSalesQuotationDto.put("partnerCpFax2", resultSalesQuotation.getString("partnerCpFax2"));
- inputSalesQuotationDto.put("partnerCpEmail", resultSalesQuotation.getString("partnerCpEmail"));
- inputSalesQuotationDto.put("partnerCpMobilePhone1", resultSalesQuotation.getString("partnerCpMobilePhone1"));
- inputSalesQuotationDto.put("partnerCpMobilePhone2", resultSalesQuotation.getString("partnerCpMobilePhone2"));
- inputSalesQuotationDto.put("salesmanId", resultSalesQuotation.getLong("salesmanId"));
- inputSalesQuotationDto.put("currCode", resultSalesQuotation.getString("currCode"));
- inputSalesQuotationDto.put("flgTaxAmount", resultSalesQuotation.getString("flgTaxAmount"));
- inputSalesQuotationDto.put("taxId", resultSalesQuotation.getString("taxId"));
- inputSalesQuotationDto.put("remark", remark);
- inputSalesQuotationDto.put("statusDoc", SalesConstants.DRAFT_TRANSACTION);
- inputSalesQuotationDto.put("workflowStatus", SalesConstants.WORKFLOW_STATUS_DRAFT);
- this.prepareInsertAudit(inputSalesQuotationDto, userId, datetime);
- this.prepareUpdateAudit(inputSalesQuotationDto, userId, datetime);
- inputDto.put("inputSalesQuotationDto", inputSalesQuotationDto);
- inputDto.put("inputSalesQuotationItemDto", inputSalesQuotationItemDto);
- inputDto.put("inputSalesQuotationTcDto", inputSalesQuotationTcDto);
- inputDto.put("balanceQuotationDto", resultBalanceQuotation);
- return null;
- }
- @SuppressWarnings("unchecked")
- @Override
- public Dto process(Dto inputDto, Dto originalDto) throws Exception {
- Dto inputSalesQuotationDto = inputDto.getDto("inputSalesQuotationDto");
- SalesQuotation salesQuotation = GsonUtil.fromDto(inputSalesQuotationDto, SalesQuotation.class);
- salesQuotationDao.persist(salesQuotation);
- List<Dto> inputSalesQuotationItemDto = inputDto.getList("inputSalesQuotationItemDto");
- for (Dto salesQuotationItemDto : inputSalesQuotationItemDto) {
- salesQuotationItemDto.put("quotationId", salesQuotation.getId());
- SalesQuotationItem salesQuotationItem = GsonUtil.fromDto(salesQuotationItemDto, SalesQuotationItem.class);
- salesQuotationItemDao.persist(salesQuotationItem);
- }
- List<Dto> inputSalesQuotationTcDto = inputDto.getList("inputSalesQuotationTcDto");
- if(inputSalesQuotationTcDto.size() != 0) {
- for(Dto salesQuotationTcDto : inputSalesQuotationTcDto) {
- salesQuotationTcDto.put("quotationId", salesQuotation.getId());
- SalesQuotationTc salesQuotationTc = GsonUtil.fromDto(salesQuotationTcDto, SalesQuotationTc.class);
- salesQuotationTcDao.persist(salesQuotationTc);
- }
- }
- Dto balanceQuotationDto = inputDto.getDto("balanceQuotationDto");
- BalanceQuotation balanceQuotation = GsonUtil.fromDto(balanceQuotationDto, BalanceQuotation.class);
- balanceQuotationDao.merge(balanceQuotation.getId(), balanceQuotation);
- return new Dto().put("id", salesQuotation.getId());
- }
- public void validationUtil(Dto inputDto) {
- ValidationUtil.valDtoContainsKey(inputDto, "tenantLoginId");
- ValidationUtil.valDtoContainsKey(inputDto, "roleLoginId");
- ValidationUtil.valDtoContainsKey(inputDto, "userLoginId");
- ValidationUtil.valDtoContainsKey(inputDto, "datetime");
- ValidationUtil.valDtoContainsKey(inputDto, "docNo");
- ValidationUtil.valDtoContainsKey(inputDto, "docDate");
- ValidationUtil.valDtoContainsKey(inputDto, "ouId");
- ValidationUtil.valDtoContainsKey(inputDto, "quotationId");
- ValidationUtil.valDtoContainsKey(inputDto, "remark");
- ValidationUtil.valBlankOrNull(inputDto, "tenantLoginId");
- ValidationUtil.valBlankOrNull(inputDto, "roleLoginId");
- ValidationUtil.valBlankOrNull(inputDto, "userLoginId");
- ValidationUtil.valBlankOrNull(inputDto, "ouId");
- ValidationUtil.valBlankOrNull(inputDto, "quotationId");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement