Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.erp.sls.web.controller.salesquotation;
- import java.io.Serializable;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import javax.faces.event.AjaxBehaviorEvent;
- import org.jleaf.core.GeneralConstants;
- import org.jleaf.erp.sls.api.SalesApi;
- import org.jleaf.erp.sls.api.SalesHumanTask;
- import org.jleaf.erp.master.api.MasterApi;
- import org.jleaf.erp.sls.web.PageInputConstants;
- import org.jleaf.erp.sls.web.SalesWebConstants;
- import org.jleaf.erp.sls.web.controller.GlobalSalesCombo;
- import org.jleaf.erp.sls.web.model.ProductLazyModel;
- import org.jleaf.util.DateUtil;
- import org.jleaf.util.JSONObjectUtil;
- import org.jleaf.web.helper.MessageHelper;
- import org.jleaf.web.helper.ServiceResult;
- import org.jleaf.web.jsf.FacesUtils;
- import org.jleaf.web.jsf.WebJsfConstants;
- import org.jleaf.web.jsf.controller.Combo;
- import org.jleaf.web.jsf.template.AbstractInputWithApprovalController;
- import org.jleaf.web.jsf.util.MessageUtil;
- import org.jleaf.web.model.ComboItem;
- import org.jleaf.web.report.server.ReportServerProvider;
- import org.json.simple.JSONObject;
- import org.primefaces.context.RequestContext;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.annotation.Scope;
- import org.springframework.stereotype.Controller;
- import javax.faces.context.FacesContext;
- /**
- *
- * @author Sarah, May 6, 2016
- *
- **/
- @SuppressWarnings("serial")
- @Controller
- @Scope("view")
- public class inputSalesQuotationController extends AbstractInputWithApprovalController implements SalesApi, Serializable {
- private static final Logger log = LoggerFactory.getLogger(inputSalesQuotationController.class);
- private List<JSONObject> partnerAddressList = new ArrayList<JSONObject>();
- private List<JSONObject> partnerList = new ArrayList<JSONObject>();
- private List<JSONObject> cpList = new ArrayList<JSONObject>();
- private List<JSONObject> tcList = new ArrayList<JSONObject>();
- private List<JSONObject> subCategoryProductList;
- private JSONObject filterAddMoreItems = new JSONObject();
- private JSONObject dataProduct = new JSONObject();
- private JSONObject itemToBeDeleted;
- private Long lastLineNo = Long.valueOf(0L);
- private List<JSONObject> taxList = new ArrayList<JSONObject>();
- private String dataPartner;
- private ProductLazyModel model;
- @Autowired
- private GlobalSalesCombo combo;
- @Autowired
- private ReportServerProvider reportServerProvider;
- @SuppressWarnings("unchecked")
- @Override
- protected void init() {
- super.init();
- JSONObject signatureSalesQuotation = new JSONObject();
- signatureSalesQuotation.put("salesQuotationSignature", GeneralConstants.EMPTY_VALUE);
- }
- @SuppressWarnings("unchecked")
- @Override
- protected void addDocument() {
- log.debug("------------------------HEADER---------------------------" + header);
- Object tempValue;
- JSONObject salesman = (JSONObject) header.get("salesman");
- JSONObject tax = (JSONObject) header.get("tax");
- JSONObject currency = (JSONObject) header.get("currency");
- JSONObject input = new JSONObject();
- input.put("ouId", header.get("ouId"));
- input.put("docNo", header.get("docNo"));
- input.put("docDate", header.get("docDate"));
- input.put("extDocNo", header.get("extDocNo"));
- input.put("extDocDate", header.get("extDocDate"));
- input.put("flgFromWebpos", header.get("flgFromWebpos") != null ? header.get("flgFromWebpos") : GeneralConstants.NO);
- if(header.get("salesman") == null || header.get("salesman").equals(GeneralConstants.EMPTY_VALUE)){
- MessageHelper.displayError("salesman must be filled");
- } else {
- input.put("currCode", currency.get("code"));
- input.put("flgTaxAmount", (tempValue = header.get("flgTax")) == null ? GeneralConstants.NO : tempValue);
- input.put("taxId", (tax == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(tax.get("id").toString())));
- input.put("remark", (tempValue = header.get("remark")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("partnerId", (tempValue = Long.valueOf(header.get("partnerId").toString())) == null ? GeneralConstants.NULL_REF_VALUE_LONG : tempValue);
- input.put("partnerName", (tempValue = header.get("partnerName")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("partnerAddressId", (tempValue = (header.get("partnerAddressId")) == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(header.get("partnerAddressId").toString())));
- input.put("partnerAddress1", (tempValue = header.get("partnerAddress1")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("partnerAddress2", (tempValue = header.get("partnerAddress2")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("partnerAddress3", (tempValue = header.get("partnerAddress3")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("partnerCpId", (tempValue = (header.get("partnerCpId")) == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(header.get("partnerCpId").toString())));
- input.put("partnerCpName", (tempValue = header.get("partnerCpName")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("partnerCpPhone1", (tempValue = header.get("partnerCpPhone1")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("partnerCpPhone2", (tempValue = header.get("partnerCpPhone2")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("partnerCpFax1", (tempValue = header.get("partnerCpFax1")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("partnerCpFax2", (tempValue = header.get("partnerCpFax2")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("partnerCpEmail", (tempValue = header.get("partnerCpEmail")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("partnerCpMobilePhone1", (tempValue = header.get("partnerCpMobilePhone1")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("partnerCpMobilePhone2", (tempValue = header.get("partnerCpMobilePhone2")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("salesmanId", (salesman == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(salesman.get("id").toString())));
- List<JSONObject> itemList = new ArrayList<JSONObject>();
- if (details != null && !details.isEmpty()) {
- for (JSONObject item : details) {
- JSONObject inputItem = new JSONObject();
- if(header.get("flgFromWebpos").equals(GeneralConstants.YES)) {
- inputItem.put("refDocTypeId", item.get("docTypeId"));
- inputItem.put("refId", item.get("refId"));
- } else {
- inputItem.put("refDocTypeId", GeneralConstants.NULL_REF_VALUE_LONG);
- inputItem.put("refId", GeneralConstants.NULL_REF_VALUE_LONG);
- }
- inputItem.put("lineNo", item.get("lineNo"));
- inputItem.put("productId", item.get("productId"));
- inputItem.put("productCode", item.get("productCode"));
- inputItem.put("productDesc", item.get("productDesc"));
- inputItem.put("uomId", item.get("uomId"));
- inputItem.put("qty", (tempValue = item.get("qty")) == null ? 0d : tempValue);
- inputItem.put("amount", (Double.valueOf(item.get("qty").toString())*Double.valueOf(item.get("sellPrice").toString())));
- inputItem.put("sellPrice", (tempValue = item.get("sellPrice")) == null ? 0d : tempValue);
- inputItem.put("brandCode", item.get("brandCode"));
- inputItem.put("brandName", item.get("brandName"));
- inputItem.put("remark", item.get("remark"));
- inputItem.put("flgStock", item.get("flgStock"));
- inputItem.put("indentDays", item.get("indentDays"));
- itemList.add(inputItem);
- }
- }
- input.put("salesQuotationProductList", itemList);
- log.debug("add document " + input.toString());
- try {
- JSONObject output = serviceContext.executeService(ADD_SALES_QUOTATION, input);
- JSONObject result = JSONObjectUtil.getResult(output);
- if (ServiceResult.isOk(output)) {
- MessageHelper.displayInfo("org.jleaf.erp.sls.web.dataSuccessSave");
- editMode = true;
- header.put("id", result.get("id"));
- loadSalesQuotation();
- loadSalesQuotationTC();
- loadSalesQuotationItem();
- loadDocumentStatus();
- } else if (ServiceResult.isFail(output)) {
- MessageHelper.displayError(result);
- errorHolder.putError("org.jleaf.erp.sls.web", result);
- }
- } catch (Exception e) {
- log.error("Error on add sales order along with its items", e);
- MessageHelper.displayError(e.getMessage());
- }
- }
- }
- @Override
- public String approveTaskName() {
- return APPROVED_SALES_QUOTATION;
- }
- @Override
- public String cancelTaskName() {
- return CANCEL_SALES_QUOTATION;
- }
- @Override
- public String deleteTaskName() {
- return REMOVE_SALES_QUOTATION;
- }
- @SuppressWarnings("unchecked")
- @Override
- protected void editDocument() {
- log.debug("------------------------HEADER---------------------------" + header);
- Object tempValue;
- JSONObject salesman = (JSONObject) header.get("salesman");
- JSONObject tax = (JSONObject) header.get("tax");
- JSONObject currency = (JSONObject) header.get("currency");
- if(header.get("salesman") == null || header.get("salesman").equals(GeneralConstants.EMPTY_VALUE)){
- MessageHelper.displayError("salesman must be filled");
- } else {
- JSONObject input = new JSONObject();
- input.put("quotationId", header.get("id"));
- input.put("version", header.get("version"));
- input.put("extDocNo", header.get("extDocNo"));
- input.put("extDocDate", header.get("extDocDate"));
- input.put("docNo", header.get("docNo"));
- input.put("ouId", header.get("ouId"));
- input.put("docDate", header.get("docDate"));
- input.put("currCode", currency.get("code"));
- input.put("flgTaxAmount", (tempValue = header.get("flgTax")) == null ? GeneralConstants.NO : tempValue);
- input.put("taxId", (Long.valueOf(tax == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(tax.get("id").toString()))));
- input.put("remark", (tempValue = header.get("remark")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("partnerId", (tempValue = header.get("partnerId")) == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(header.get("partnerId").toString()));
- input.put("partnerName", (tempValue = header.get("partnerName")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("partnerAddressId", (tempValue = (header.get("partnerAddressId")) == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(header.get("partnerAddressId").toString())));
- input.put("partnerAddress1", (tempValue = header.get("partnerAddress1")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("partnerAddress2", (tempValue = header.get("partnerAddress2")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("partnerAddress3", (tempValue = header.get("partnerAddress3")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("partnerCpId", (tempValue = (header.get("partnerCpId")) == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(header.get("partnerCpId").toString())));
- input.put("partnerCpName", (tempValue = header.get("partnerCpName")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("partnerCpPhone1", (tempValue = header.get("partnerCpPhone1")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("partnerCpPhone2", (tempValue = header.get("partnerCpPhone2")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("partnerCpFax1", (tempValue = header.get("partnerCpFax1")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("partnerCpFax2", (tempValue = header.get("partnerCpFax2")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("partnerCpEmail", (tempValue = header.get("partnerCpEmail")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("partnerCpMobilePhone1", (tempValue = header.get("partnerCpMobilePhone1")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("partnerCpMobilePhone2", (tempValue = header.get("partnerCpMobilePhone2")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
- input.put("salesmanId", (salesman == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(salesman.get("id").toString())));
- log.debug("--------=========== ++++ isi input " + input);
- try {
- JSONObject output = serviceContext.executeService(EDIT_SALES_QUOTATION, input);
- JSONObject result = JSONObjectUtil.getResult(output);
- if (ServiceResult.isOk(output)) {
- MessageHelper.displayInfo("org.jleaf.erp.sls.web.dataSuccessSave");
- header.put("id", result.get("id"));
- loadSalesQuotation();
- loadSalesQuotationTC();
- loadSalesQuotationItem();
- loadDocumentStatus();
- editMode = true;
- } else if (ServiceResult.isFail(output)) {
- MessageHelper.displayError(result);
- errorHolder.putError("org.jleaf.erp.sls.web", result);
- }
- } catch (Exception e) {
- log.error("Error on add sales order along with its items", e);
- MessageHelper.displayError(e.getMessage());
- }
- }
- }
- @SuppressWarnings("unchecked")
- @Override
- public void doDownload() {
- log.debug("call doDownload()");
- try {
- JSONObject jsonInput = new JSONObject();
- jsonInput.put("sessionId", FacesUtils.getSessionId());
- jsonInput.put("tenantId", Long.valueOf(FacesUtils.getSessionMap().get(WebJsfConstants.SESS_LOGGED_TENANT_ID).toString()));
- jsonInput.put("quotationId", Long.valueOf(header.get("id").toString()));
- jsonInput.put("ouId", Long.valueOf(header.get("ouId").toString()));
- jsonInput.put("userId", Long.valueOf(FacesUtils.getSessionMap().get(WebJsfConstants.SESS_LOGGED_USER_ID).toString()));
- log.debug("getReportUserParameters Data" + getReportUserParameters());
- String paramsValue = GeneralConstants.EMPTY_VALUE;
- if (getReportUserParameters().size() > 0) {
- for (JSONObject item : getReportUserParameters()) {
- paramsValue = item.get("value").toString();
- }
- }
- jsonInput.put("salesQuotationSignature", paramsValue);
- log.debug(">> input download " + jsonInput);
- String reportName = getCurrentReportName();
- String fileName = GeneralConstants.SPACE_VALUE;
- if (reportName.equals(SalesWebConstants.FORM_SALES_QUOTATION)) {
- reportName = SalesWebConstants.FORM_SALES_QUOTATION;
- fileName = SalesWebConstants.FORM_SALES_QUOTATION + "_" + header.get("docNo").toString() + "_" + DateUtil.dateTimeNow();
- }
- // FacesContext.getCurrentInstance().getExternalContext().redirect(export(reportName, fileName, jsonInput));
- boolean isQueue = false;
- if (isQueue) {
- JSONObject output = reportServerProvider
- .requestDownloadAsync(
- SalesHumanTask.DOWNLOAD_PDF_SALES_QUOTATION,
- reportName, fileName,
- "Form Sales Quotation", jsonInput);
- JSONObject result = JSONObjectUtil.getResult(output);
- if (ServiceResult.isOk(output)) {
- reportServerProvider.goToResultPage(result,
- FacesContext.getCurrentInstance());
- } else {
- MessageHelper.displayError(result);
- }
- } else {
- reportServerProvider
- .requestDownloadSync(
- SalesHumanTask.DOWNLOAD_PDF_SALES_QUOTATION,
- reportName, fileName,
- "Form Sales Quotation", jsonInput,
- FacesContext.getCurrentInstance());
- }
- } catch(Exception e) {
- log.error(e.getMessage(), e);
- MessageHelper.displayError(e.getMessage());
- }
- }
- @Override
- public String getDocStatusTaskName() {
- return GET_SALES_QUOTATION_STATUS_BY_USER_ROLE_AND_DOC_ID;
- }
- @Override
- public String getViewName() {
- return PageInputConstants.INPUT_SALES_QUOTATION;
- }
- @Override
- public void onActionFail(String action, JSONObject result) {
- MessageHelper.displayError(result);
- }
- @Override
- public void onActionSuccess(String action, JSONObject result) {
- if (action.equals(WebJsfConstants.ACTION_DELETE)) {
- RequestContext context = RequestContext.getCurrentInstance();
- context.execute("document.location='createSalesQuotation.jsf'");
- } else {
- loadDocumentStatus();
- }
- if (action.equals(WebJsfConstants.ACTION_SUBMIT)){
- loadDocumentStatus();
- loadSalesQuotation();
- loadSalesQuotationItem();
- loadSalesQuotationTC();
- editMode = true;
- } else {
- loadDocumentStatus();
- }
- if (action.equals(WebJsfConstants.ACTION_CANCEL) || action.equals(WebJsfConstants.ACTION_REQUEST_CHANGES) || action.equals(WebJsfConstants.ACTION_REJECT)){
- loadDocumentStatus();
- loadSalesQuotation();
- loadSalesQuotationItem();
- loadSalesQuotationTC();
- } else {
- loadDocumentStatus();
- }
- }
- @SuppressWarnings("unchecked")
- @Override
- public void prepareAdd(Map<String, Object> parameter) {
- log.debug("\n\n Prepare Add Sales Quotation \n\n");
- log.debug("parameter >>>>>>>>>>>>>>>> " + parameter);
- JSONObject ou = (JSONObject) parameter.get("ou");
- log.debug("\n\n Prepare Add Ou : "+ou+" \n\n");
- getHeader().put("docNo", GeneralConstants.EMPTY_VALUE);
- log.debug("\n\n Prepare Add Get Header Doc No : "+getHeader().get("docNo")+" \n\n");
- getHeader().put("docDate", DateUtil.dateNow());
- log.debug("\n\n Prepare Add Get Header Doc Date : "+getHeader().get("docDate")+" \n\n");
- getHeader().put("ouId", Long.valueOf(ou.get("id").toString()));
- log.debug("\n\n Prepare Add Get Header Ou Id : "+getHeader().get("ouId")+" \n\n");
- getHeader().put("ouName", ou.get("name"));
- log.debug("\n\n Prepare Add Get Header Ou Name : "+getHeader().get("ouName")+" \n\n");
- getHeader().put("currency", new ComboItem("code", SalesWebConstants.DEFAULT_CURRENCY_CODE));
- log.debug("\n\n Prepare Add Get Header Currency : "+getHeader().get("currency")+" \n\n");
- getHeader().put("flgTax", GeneralConstants.NO);
- log.debug("\n\n Prepare Add Get Header Flag Tax : "+getHeader().get("flgTax")+" \n\n");
- getHeader().put("remark", GeneralConstants.EMPTY_VALUE);
- log.debug("\n\n Prepare Add Get Header Remark : "+getHeader().get("remark")+" \n\n");
- getHeader().put("partnerCpId", GeneralConstants.NULL_REF_VALUE_LONG);
- log.debug("\n\n Prepare Add Get Header Partner CP Id : "+getHeader().get("partnerCpId")+" \n\n");
- getHeader().put("partnerAddressId", GeneralConstants.NULL_REF_VALUE_LONG);
- log.debug("\n\n Prepare Add Get Header Partner Address Id : "+getHeader().get("partnerAddressId")+" \n\n");
- getHeader().put("flgFromWebpos", parameter.get("flgFromWebpos") != null ? parameter.get("flgFromWebpos") : GeneralConstants.NO);
- log.debug("\n\n Prepare Add Get Header Flag From Web Pos : "+getHeader().get("flgFromWebpos")+" \n\n");
- log.debug("\n\n Prepare Add Get Header Before Load Ou : "+getHeader()+" \n\n");
- loadOu();
- log.debug("\n\n Prepare Add Get Header After Load Ou : "+getHeader()+" \n\n");
- if(getHeader().get("flgFromWebpos").equals(GeneralConstants.YES)) {
- log.debug("\n\n Prepare Add If Flag From Web Pos Equals Yes \n\n");
- JSONObject partner = (JSONObject) parameter.get("partner");
- log.debug("\n\n Prepare Add Partner : "+partner+" \n\n");
- getHeader().put("extDocNo", parameter.get("extDocNo"));
- log.debug("\n\n Prepare Add Get Header Ext Doc No : "+getHeader().get("extDocNo")+" \n\n");
- getHeader().put("extDocDate", parameter.get("extDocDate"));
- log.debug("\n\n Prepare Add Get Header Ext Doc Date : "+getHeader().get("extDocDate")+" \n\n");
- getHeader().put("partnerId", partner.get("partnerId"));
- log.debug("\n\n Prepare Add Get Header Partner Id : "+getHeader().get("partnerId")+" \n\n");
- log.debug("\n\n Prepare Add Get Header Before Load Customer : "+getHeader()+" \n\n");
- loadCustomer(Long.valueOf(partner.get("partnerId").toString()));
- log.debug("\n\n Prepare Add Get Header After Load Customer : "+getHeader()+" \n\n");
- this.details = (List<JSONObject>) parameter.get("salesQuotationItem");
- log.debug("\n\n Prepare Add Details (Sales Quotation Item) : "+details+" \n\n");
- } else {
- log.debug("\n\n Prepare Add Else Flag From Web Pos \n\n");
- getHeader().put("extDocNo", GeneralConstants.EMPTY_VALUE);
- log.debug("\n\n Prepare Add Get Header Ext Doc No : "+getHeader().get("extDocNo")+" \n\n");
- getHeader().put("extDocDate", DateUtil.dateNow());
- log.debug("\n\n Prepare Add Get Header Ext Doc Date : "+getHeader().get("extDocDate")+" \n\n");
- getHeader().put("partnerId", GeneralConstants.NULL_REF_VALUE_LONG);
- log.debug("\n\n Prepare Add Get Header Partner Id : "+getHeader().get("partnerId")+" \n\n");
- this.details = (List<JSONObject>) parameter.get("salesQuotationItem");
- log.debug("\n\n Prepare Add Details (Sales Quotation Item) Before Config: "+details+" \n\n");
- if ((this.details == null) || (this.details.isEmpty())) {
- MessageHelper.displayError("so.item.at.least.one");
- return;
- }
- log.debug(">>>>>>>>>>>>>>>>>>>>>>>>>> " + details);
- this.lastLineNo = Long.valueOf(0L);
- for (JSONObject item : this.details) {
- item.put("lineNo", this.lastLineNo = Long.valueOf(this.lastLineNo.longValue() + 1L));
- item.put("currCode", SalesWebConstants.DEFAULT_CURRENCY_CODE);
- item.put("sellPrice", Double.valueOf(0.0D));
- item.put("amount", Double.valueOf(0.0D));
- }
- log.debug("\n\n Prepare Add Details (Sales Quotation Item) After Config: "+details+" \n\n");
- }
- log.debug("\n\n Prepare Add Get Header : "+getHeader()+"\n\n");
- log.debug("\n\n Prepare Add Header : "+header+"\n\n");
- }
- @SuppressWarnings("unchecked")
- @Override
- public void prepareEdit(Map<String, Object> parameter) {
- log.debug("prepareEdit(Map<String, Object> parameter)");
- Object id = parameter.get("id"); // From draft page
- Object docId = parameter.get("docId"); // From approval page
- log.debug("PARAMETER EDIT >>>>>>>>>>>>>>> " + parameter);
- if (id != null || docId != null) {
- editMode = true;
- header.put("id", id == null ? docId.toString() : id.toString());
- loadSalesQuotation();
- loadOu();
- loadSalesQuotationItem();
- loadSalesQuotationTC();
- }
- log.debug("prepare edit header >>>>>>>>>>>>>>> " + header);
- }
- @Override
- public String rejectTaskName() {
- return REJECT_SALES_QUOTATION;
- }
- @Override
- public String requestChangesTaskName() {
- return REQUEST_CHANGES_SALES_QUOTATION;
- }
- @Override
- public String submitTaskName() {
- return SUBMIT_SALES_QUOTATION;
- }
- @Override
- public String updateTaskName() {
- return UPDATE_SALES_QUOTATION;
- }
- @SuppressWarnings("unchecked")
- public void prepareAddMoreItems() {
- log.debug("masuk ke prepare add more items");
- filterAddMoreItems.put("productDesc", GeneralConstants.EMPTY_VALUE);
- filterAddMoreItems.put("productCode", GeneralConstants.EMPTY_VALUE);
- filterAddMoreItems.put("currCode", SalesWebConstants.DEFAULT_CURRENCY_CODE);
- filterAddMoreItems.put("nettSellPrice", 0D);
- filterAddMoreItems.put("nettAmount", 0D);
- filterAddMoreItems.put("qty", 1D);
- filterAddMoreItems.put("flgStock", GeneralConstants.YES);
- filterAddMoreItems.put("indentDays", "0");
- }
- @SuppressWarnings("unchecked")
- public void doAddMoreItems() {
- log.debug("============filterAddMoreItems=============== " + filterAddMoreItems);
- log.debug("============lastLineNo=============== " + lastLineNo);
- String indentDays = filterAddMoreItems.get("indentDays").toString();
- if(filterAddMoreItems.get("flgStock").equals(GeneralConstants.NO)) {
- if(filterAddMoreItems.get("indentDays").equals("0")){
- RequestContext.getCurrentInstance().addCallbackParam("success", false);
- MessageHelper.displayError("erp.jleaf.erp.sls.web.indentMustBeGreaterThenZerro");
- return;
- }
- } else {
- indentDays = "0";
- }
- if(filterAddMoreItems.get("qty") == null || filterAddMoreItems.get("qty").equals(GeneralConstants.EMPTY_VALUE)){
- RequestContext.getCurrentInstance().addCallbackParam("success", false);
- MessageHelper.displayError("qty can not null");
- return;
- } else {
- RequestContext.getCurrentInstance().addCallbackParam("success", true);
- filterAddMoreItems.put("lineNo", ++lastLineNo);
- filterAddMoreItems.put("productId", GeneralConstants.NULL_REF_VALUE_LONG);
- filterAddMoreItems.put("productCode", filterAddMoreItems.get("productCode"));
- filterAddMoreItems.put("productDesc", filterAddMoreItems.get("productDesc"));
- filterAddMoreItems.put("qty", Double.valueOf(filterAddMoreItems.get("qty").toString()));
- filterAddMoreItems.put("uomId", GeneralConstants.NULL_REF_VALUE_LONG);
- filterAddMoreItems.put("sellPrice", Double.valueOf(filterAddMoreItems.get("nettSellPrice").toString()));
- filterAddMoreItems.put("amount", (Double.valueOf(filterAddMoreItems.get("qty").toString())*Double.valueOf(filterAddMoreItems.get("nettSellPrice").toString())));
- filterAddMoreItems.put("amount", (Double.valueOf(filterAddMoreItems.get("qty").toString())*Double.valueOf(filterAddMoreItems.get("nettSellPrice").toString())));
- filterAddMoreItems.put("brandCode", GeneralConstants.EMPTY_VALUE);
- filterAddMoreItems.put("brandName", filterAddMoreItems.get("brandName"));
- filterAddMoreItems.put("remark", filterAddMoreItems.get("remark"));
- filterAddMoreItems.put("flgStock", filterAddMoreItems.get("flgStock"));
- filterAddMoreItems.put("indentDays", indentDays);
- log.debug("after filterAddMoreItems " + filterAddMoreItems.toString());
- if(editMode){
- log.debug("masuk ke ADD NEW Product ----------- ");
- try {
- filterAddMoreItems.put("quotationId", Long.valueOf(header.get("id").toString()));
- filterAddMoreItems.put("quotationVersion", header.get("version"));
- JSONObject output = serviceContext.executeService(ADD_PRODUCT_SALES_QUOTATION, filterAddMoreItems);
- JSONObject result = JSONObjectUtil.getResult(output);
- if (ServiceResult.isOk(output)) {
- MessageHelper.displayInfo("org.jleaf.erp.sls.web.dataSuccessSave");
- header.put("id", result.get("id"));
- loadSalesQuotation();
- loadSalesQuotationTC();
- loadSalesQuotationItem();
- loadDocumentStatus();
- } else if (ServiceResult.isFail(output)) {
- MessageHelper.displayError(result);
- errorHolder.putError("org.jleaf.erp.sls.web", result);
- }
- } catch (Exception e) {
- log.error("Error on add sales order along with its items", e);
- MessageHelper.displayError(e.getMessage());
- }
- } else {
- log.debug("============MASUK KE DETAIL=============== " + filterAddMoreItems);
- JSONObject itemToAdd = new JSONObject();
- itemToAdd.put("lineNo", lastLineNo);
- JSONObject currency = (JSONObject) header.get("currency");
- itemToAdd.put("currCode", currency.get("code"));
- itemToAdd.put("currPropKey", currency.get("propKey"));
- itemToAdd.put("currency", currency);
- itemToAdd.put("productCode", filterAddMoreItems.get("productCode"));
- itemToAdd.put("productDesc", filterAddMoreItems.get("productDesc"));
- itemToAdd.put("qty", filterAddMoreItems.get("qty"));
- itemToAdd.put("productId", filterAddMoreItems.get("productId") == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(filterAddMoreItems.get("productId").toString()));
- itemToAdd.put("uomId", filterAddMoreItems.get("baseUomId") == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(filterAddMoreItems.get("baseUomId").toString()));
- itemToAdd.put("uomCode", filterAddMoreItems.get("baseUomCode") == null ? GeneralConstants.EMPTY_VALUE : filterAddMoreItems.get("baseUomCode"));
- itemToAdd.put("uomName", filterAddMoreItems.get("baseUomName") == null ? GeneralConstants.EMPTY_VALUE : filterAddMoreItems.get("baseUomName"));
- itemToAdd.put("baseUomId", filterAddMoreItems.get("baseUomId") == null ? GeneralConstants.EMPTY_VALUE : filterAddMoreItems.get("baseUomId"));
- itemToAdd.put("baseUomCode", filterAddMoreItems.get("baseUomCode") == null ? GeneralConstants.EMPTY_VALUE : filterAddMoreItems.get("baseUomCode"));
- itemToAdd.put("baseUomName", filterAddMoreItems.get("baseUomName") == null ? GeneralConstants.EMPTY_VALUE : filterAddMoreItems.get("baseUomName"));
- itemToAdd.put("amount", (Double.valueOf(filterAddMoreItems.get("qty").toString())*Double.valueOf(filterAddMoreItems.get("nettSellPrice").toString())));
- itemToAdd.put("sellPrice", filterAddMoreItems.get("nettSellPrice"));
- itemToAdd.put("brandCode", filterAddMoreItems.get("brandCode"));
- itemToAdd.put("brandName", filterAddMoreItems.get("brandName"));
- itemToAdd.put("remark", filterAddMoreItems.get("remark"));
- itemToAdd.put("sellPrice", filterAddMoreItems.get("nettSellPrice"));
- itemToAdd.put("flgStock", filterAddMoreItems.get("flgStock"));
- itemToAdd.put("indentDays", indentDays);
- details.add(itemToAdd);
- filterAddMoreItems = new JSONObject();
- log.debug("=============details============== " + details);
- }
- }
- }
- @SuppressWarnings("unchecked")
- public void doEditItem() {
- log.debug("============filterAddMoreItems=============== " + filterAddMoreItems);
- String indentDays = filterAddMoreItems.get("indentDays").toString();
- if(filterAddMoreItems.get("flgStock").equals(GeneralConstants.NO)) {
- if(filterAddMoreItems.get("indentDays").equals("0")){
- RequestContext.getCurrentInstance().addCallbackParam("success", false);
- MessageHelper.displayError("erp.jleaf.erp.sls.web.indentMustBeGreaterThenZerro");
- return;
- }
- } else {
- indentDays = "0";
- }
- if(filterAddMoreItems.get("qty") == null || filterAddMoreItems.get("qty").equals(GeneralConstants.EMPTY_VALUE)){
- RequestContext.getCurrentInstance().addCallbackParam("success", false);
- MessageHelper.displayError("qty can not null");
- return;
- } else {
- if(filterAddMoreItems.get("productId").equals(GeneralConstants.NULL_REF_VALUE_LONG.toString())) {
- filterAddMoreItems.put("brandCode", GeneralConstants.EMPTY_VALUE);
- filterAddMoreItems.put("brandName", filterAddMoreItems.get("brandName"));
- filterAddMoreItems.put("productId", GeneralConstants.NULL_REF_VALUE_LONG);
- } else {
- filterAddMoreItems.put("productId", Long.valueOf(filterAddMoreItems.get("productId").toString()));
- }
- filterAddMoreItems.put("lineNo", ++lastLineNo);
- filterAddMoreItems.put("productCode", filterAddMoreItems.get("productCode"));
- filterAddMoreItems.put("productDesc", filterAddMoreItems.get("productDesc"));
- filterAddMoreItems.put("qty", Double.valueOf(filterAddMoreItems.get("qty").toString()));
- filterAddMoreItems.put("uomId", GeneralConstants.NULL_REF_VALUE_LONG);
- filterAddMoreItems.put("sellPrice", Double.valueOf(filterAddMoreItems.get("nettSellPrice").toString()));
- filterAddMoreItems.put("amount", (Double.valueOf(filterAddMoreItems.get("qty").toString())*Double.valueOf(filterAddMoreItems.get("nettSellPrice").toString())));
- filterAddMoreItems.put("quotationId", Long.valueOf(header.get("id").toString()));
- filterAddMoreItems.put("quotationItemId", Long.valueOf(filterAddMoreItems.get("quotationItemId").toString()));
- filterAddMoreItems.put("version", filterAddMoreItems.get("version"));
- filterAddMoreItems.put("quotationVersion", header.get("version"));
- filterAddMoreItems.put("remark", filterAddMoreItems.get("remark"));
- filterAddMoreItems.put("flgStock", filterAddMoreItems.get("flgStock"));
- filterAddMoreItems.put("indentDays", indentDays);
- RequestContext.getCurrentInstance().addCallbackParam("success", true);
- log.debug("============SERVICE EDIT_PRODUCT_SALES_QUOTATION=============== " + filterAddMoreItems);
- try {
- JSONObject output = serviceContext.executeService(EDIT_PRODUCT_SALES_QUOTATION, filterAddMoreItems);
- JSONObject result = JSONObjectUtil.getResult(output);
- if (ServiceResult.isOk(output)) {
- MessageHelper.displayInfo("org.jleaf.erp.sls.web.dataSuccessSave");
- loadSalesQuotation();
- loadSalesQuotationTC();
- loadSalesQuotationItem();
- filterAddMoreItems = new JSONObject();
- } else if (ServiceResult.isFail(output)) {
- MessageHelper.displayError(result);
- errorHolder.putError("org.jleaf.erp.sls.web", result);
- }
- } catch (Exception e) {
- log.error("Error on add sales order along with its items", e);
- MessageHelper.displayError(e.getMessage());
- }
- }
- }
- @SuppressWarnings("unchecked")
- public void addProductExisting(JSONObject addItem) {
- JSONObject item = new JSONObject();
- item = (JSONObject) addItem.clone();
- log.debug("============item=============== " + item);
- String indentDays = "0";
- String flgStock = GeneralConstants.YES;
- if(item.get("qty").toString().equals("0")) {
- flgStock = GeneralConstants.NO;
- }
- if(editMode){
- item.put("quotationId", Long.valueOf(header.get("id").toString()));
- item.put("lineNo", ++lastLineNo);
- item.put("productId", item.get("productId"));
- item.put("productDesc", item.get("productName"));
- item.put("productCode", item.get("productCode"));
- item.put("qty", 1D);
- item.put("amount", 0D);
- item.put("uomId", item.get("baseUomId"));
- item.put("sellPrice", 0D);
- item.put("quotationVersion", Long.valueOf(header.get("version").toString()));
- item.put("brandCode", GeneralConstants.EMPTY_VALUE);
- item.put("brandName", GeneralConstants.EMPTY_VALUE);
- item.put("remark", GeneralConstants.EMPTY_VALUE);
- item.put("indentDays", indentDays);
- item.put("flgStock", flgStock);
- try {
- JSONObject output = this.serviceContext.executeService(ADD_PRODUCT_SALES_QUOTATION, item);
- JSONObject result = JSONObjectUtil.getResult(output);
- if (ServiceResult.isOk(output)) {
- MessageHelper.displayInfo("org.jleaf.erp.sls.web.dataSuccessSave");
- header.put("id", result.get("id"));
- filterAddMoreItems = new JSONObject();
- loadSalesQuotation();
- loadSalesQuotationTC();
- loadSalesQuotationItem();
- loadDocumentStatus();
- } else if (ServiceResult.isFail(output)) {
- MessageHelper.displayError(result);
- }
- } catch (Exception e) {
- e.printStackTrace();
- MessageHelper.displayError(e.getMessage());
- }
- } else {
- JSONObject itemToAdd = new JSONObject();
- itemToAdd.put("lineNo", ++lastLineNo);
- itemToAdd.put("currCode", SalesWebConstants.DEFAULT_CURRENCY_CODE);
- itemToAdd.put("sellPrice", 0D);
- itemToAdd.put("amount", 0D);
- itemToAdd.put("productCode", item.get("productCode"));
- itemToAdd.put("productDesc", item.get("productName"));
- itemToAdd.put("qty", 1D);
- itemToAdd.put("productId", item.get("productId") == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(item.get("productId").toString()));
- itemToAdd.put("uomId", item.get("baseUomId") == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(item.get("baseUomId").toString()));
- itemToAdd.put("uomCode", item.get("baseUomCode") == null ? GeneralConstants.EMPTY_VALUE : item.get("baseUomCode"));
- itemToAdd.put("uomName", item.get("baseUomName") == null ? GeneralConstants.EMPTY_VALUE : item.get("baseUomName"));
- itemToAdd.put("baseUomId", item.get("baseUomId") == null ? GeneralConstants.EMPTY_VALUE : item.get("baseUomId"));
- itemToAdd.put("baseUomCode", item.get("baseUomCode") == null ? GeneralConstants.EMPTY_VALUE : item.get("baseUomCode"));
- itemToAdd.put("baseUomName", item.get("baseUomName") == null ? GeneralConstants.EMPTY_VALUE : item.get("baseUomName"));
- itemToAdd.put("brandCode", GeneralConstants.EMPTY_VALUE);
- itemToAdd.put("brandName", GeneralConstants.EMPTY_VALUE);
- itemToAdd.put("remark", GeneralConstants.EMPTY_VALUE);
- itemToAdd.put("indentDays", indentDays);
- itemToAdd.put("flgStock", flgStock);
- details.add(itemToAdd);
- filterAddMoreItems = new JSONObject();
- log.debug("=============details============== " + details);
- }
- }
- @SuppressWarnings("unchecked")
- public void doAddTCItems() {
- log.debug("============filterAddMoreItems=============== " + filterAddMoreItems);
- log.debug("============lastLineNo=============== " + lastLineNo);
- JSONObject newTC = new JSONObject();
- newTC.put("lineNo", ++lastLineNo);
- newTC.put("termCondition", filterAddMoreItems.get("termCondition"));
- newTC.put("quotationId", Long.valueOf(header.get("id").toString()));
- newTC.put("quotationVersion", Long.valueOf(header.get("version").toString()));
- log.debug("============SERVICE ADD_TERMS_AND_CONDITION_SALES_QUOTATION=============== " + newTC);
- try {
- JSONObject output = serviceContext.executeService(ADD_TERMS_AND_CONDITION_SALES_QUOTATION, newTC);
- JSONObject result = JSONObjectUtil.getResult(output);
- if (ServiceResult.isOk(output)) {
- MessageHelper.displayInfo("org.jleaf.erp.sls.web.dataSuccessSave");
- header.put("id", result.get("id"));
- loadSalesQuotation();
- loadSalesQuotationTC();
- loadSalesQuotationItem();
- loadDocumentStatus();
- filterAddMoreItems = new JSONObject();
- } else if (ServiceResult.isFail(output)) {
- MessageHelper.displayError(result);
- errorHolder.putError("org.jleaf.erp.sls.web", result);
- }
- } catch (Exception e) {
- log.error("Error on add sales order along with its items", e);
- MessageHelper.displayError(e.getMessage());
- }
- }
- @SuppressWarnings("unchecked")
- public void prepareEditItem(JSONObject editedItem) {
- log.debug("Prepare edit item : " + editedItem);
- filterAddMoreItems.clear();
- log.debug("resultProduct " + editedItem.get("productId"));
- if(!editedItem.get("productId").equals(GeneralConstants.NULL_REF_VALUE_LONG.toString())) {
- filterAddMoreItems.put("brandCode", editedItem.get("code"));
- filterAddMoreItems.put("brandName", editedItem.get("name"));
- } else {
- filterAddMoreItems.put("brandCode", editedItem.get("brandCode"));
- filterAddMoreItems.put("brandName", editedItem.get("brandName"));
- }
- filterAddMoreItems.put("quotationItemId", editedItem.get("quotationItemId"));
- filterAddMoreItems.put("quotationId", editedItem.get("quotationId"));
- filterAddMoreItems.put("lineNo", editedItem.get("lineNo"));
- filterAddMoreItems.put("productId", editedItem.get("productId"));
- filterAddMoreItems.put("productDesc", editedItem.get("productDesc"));
- filterAddMoreItems.put("productCode", editedItem.get("productCode"));
- filterAddMoreItems.put("qty", editedItem.get("qty"));
- filterAddMoreItems.put("nettSellPrice", editedItem.get("sellPrice"));
- filterAddMoreItems.put("currCode", header.get("currCode"));
- filterAddMoreItems.put("nettAmount", editedItem.get("amount"));
- filterAddMoreItems.put("remark", editedItem.get("remark"));
- filterAddMoreItems.put("version", editedItem.get("version"));
- filterAddMoreItems.put("flgStock", editedItem.get("flgStock"));
- filterAddMoreItems.put("indentDays", editedItem.get("indentDays"));
- }
- public void prepareRemoveItem(JSONObject removedItem) {
- this.setItemToBeDeleted(((JSONObject) removedItem.clone()));
- }
- @SuppressWarnings("unchecked")
- public void doRemoveItem() {
- log.debug("================ " + this.itemToBeDeleted);
- log.debug("================ " + this.details);
- if ((this.itemToBeDeleted.get("quotationItemId") == null) || (this.itemToBeDeleted.get("quotationItemId").toString().equals(GeneralConstants.NULL_REF_VALUE_LONG.toString()))) {
- log.debug("=======MASUK KE REMOVE DETAIL TANPA SERVICE========= " + this.details);
- this.details.remove(this.itemToBeDeleted);
- this.itemToBeDeleted = new JSONObject();
- } else {
- log.debug("=======MASUK KE REMOVE DETAIL PAKAI SERVICE========= ");
- JSONObject input = new JSONObject();
- input.put("quotationItemId", Long.valueOf(this.itemToBeDeleted.get("quotationItemId").toString()));
- input.put("quotationId", Long.valueOf(this.header.get("id").toString()));
- input.put("quotationVersion", Long.valueOf(this.header.get("version").toString()));
- try {
- JSONObject output = this.serviceContext.executeService(REMOVE_PRODUCT_SALES_QUOTATION, input);
- JSONObject result = JSONObjectUtil.getResult(output);
- if (ServiceResult.isOk(output)) {
- MessageHelper.displayInfo("org.jleaf.erp.sls.web.dataHasBeenRemoved");
- loadSalesQuotation();
- loadSalesQuotationItem();
- loadSalesQuotationTC();
- } else if (ServiceResult.isFail(output)) {
- MessageHelper.displayError(result);
- }
- } catch (Exception e) {
- log.error("Error on remove sales order item", e);
- MessageHelper.displayError(e.getMessage());
- }
- }
- }
- @SuppressWarnings("unchecked")
- public void doRemoveTc() {
- log.debug("================ " + this.itemToBeDeleted);
- JSONObject input = new JSONObject();
- input.put("quotationTcId", Long.valueOf(this.itemToBeDeleted.get("quotationTcId").toString()));
- input.put("quotationId", Long.valueOf(this.header.get("id").toString()));
- input.put("quotationVersion", Long.valueOf(this.header.get("version").toString()));
- try {
- JSONObject output = this.serviceContext.executeService(REMOVE_TERMS_AND_CONDITION_SALES_QUOTATION, input);
- JSONObject result = JSONObjectUtil.getResult(output);
- if (ServiceResult.isOk(output)) {
- MessageHelper.displayInfo("org.jleaf.erp.sls.web.dataHasBeenRemoved");
- loadSalesQuotation();
- loadOu();
- loadSalesQuotationItem();
- loadSalesQuotationTC();
- } else if (ServiceResult.isFail(output)) {
- MessageHelper.displayError(result);
- }
- } catch (Exception e) {
- log.error("Error on remove sales order item", e);
- MessageHelper.displayError(e.getMessage());
- }
- }
- @SuppressWarnings("unchecked")
- public void onCurrencyChanged(AjaxBehaviorEvent e) {
- if (details != null && details.size() > 0) {
- for (JSONObject item : details) {
- item.put("currCode", ((JSONObject) header.get("currency")).get("code"));
- log.info("jalan for nya currency code nih . . . . . . . . . . . . . . . " + item.toString());
- }
- }
- header.put("currCode", ((JSONObject) header.get("currency")).get("code"));
- }
- @SuppressWarnings("unchecked")
- public void doSearchProduct(){
- JSONObject jsonInput = new JSONObject();
- JSONObject subCtgrProduct = (JSONObject) dataProduct.get("subCtgrProduct");
- jsonInput.put("ouId", header.get("ouId"));
- jsonInput.put("subCtgrProductId", subCtgrProduct == null ? GeneralConstants.NULL_REF_VALUE_LONG : subCtgrProduct.get("id"));
- jsonInput.put("productCodeName", dataProduct.get("productCodeName"));
- jsonInput.put("brandCodeName", dataProduct.get("brandCodeName"));
- jsonInput.put("active", GeneralConstants.YES);
- try {
- JSONObject output = serviceContext.executeService(COUNT_GET_AUTHORIZED_PRODUCT_BALANCE_STOCK_LIST_FOR_SALES_ORDER, jsonInput);
- JSONObject result = JSONObjectUtil.getResult(output);
- if (ServiceResult.isOk(output)) {
- Long rowCount = Long.valueOf(result.get("count").toString());
- model = new ProductLazyModel(serviceContext, jsonInput);
- model.setRowCount(rowCount.intValue());
- model.setPageSize(25);
- MessageHelper.displayLoadSuccess();
- } else if (ServiceResult.isFail(output)) {
- MessageHelper.displayError(result);
- }
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- MessageHelper.displayError(ex.getMessage());
- }
- }
- @SuppressWarnings("unchecked")
- public void doSearchPartner(){
- JSONObject jsonInput = new JSONObject();
- log.debug("=============dataPartner==================== " + dataPartner);
- jsonInput.put("keyword", (dataPartner == null ? GeneralConstants.EMPTY_VALUE : dataPartner));
- jsonInput.put("ctgrPartnerId", GeneralConstants.NULL_REF_VALUE_LONG);
- try {
- JSONObject output = serviceContext.executeService(GET_AUTHORIZED_CUSTOMER_LIST_ADVANCE, jsonInput);
- JSONObject result = JSONObjectUtil.getResult(output);
- if (ServiceResult.isOk(output)) {
- log.debug("----------------------- " + result);
- this.setPartnerList(ServiceResult.toArray(result.get("customerList")));
- } else if (ServiceResult.isFail(output)) {
- MessageHelper.displayError(result);
- }
- } catch (Exception e) {
- log.error("Error on load term condition sales quotation", e);
- MessageHelper.displayError(e.getMessage());
- }
- }
- @SuppressWarnings("unchecked")
- public void doSearchPartnerCP(){
- JSONObject jsonInput = new JSONObject();
- jsonInput.put("partnerId", (header.get("partnerId") == null ? GeneralConstants.NULL_REF_VALUE_LONG : header.get("partnerId")));
- jsonInput.put("active", (header.get("activePartner") == null ? GeneralConstants.YES : header.get("activePartner")));
- try {
- JSONObject output = serviceContext.executeService(GET_PARTNER_CP_LIST_BY_PARTNER, jsonInput);
- JSONObject result = JSONObjectUtil.getResult(output);
- if (ServiceResult.isOk(output)) {
- log.debug("----------------------- " + result);
- this.setCpList(ServiceResult.toArray(result.get("contactPersonList")));
- } else if (ServiceResult.isFail(output)) {
- MessageHelper.displayError(result);
- }
- } catch (Exception e) {
- log.error("Error on load term condition sales quotation", e);
- MessageHelper.displayError(e.getMessage());
- }
- }
- @SuppressWarnings("unchecked")
- public void loadPartnerAddress(){
- JSONObject jsonInput = new JSONObject();
- jsonInput.put("partnerId", (header.get("partnerId") == null ? GeneralConstants.NULL_REF_VALUE_LONG : header.get("partnerId")));
- jsonInput.put("active", (header.get("activePartner") == null ? GeneralConstants.YES : header.get("activePartner")));
- try {
- JSONObject output = serviceContext.executeService(GET_PARTNER_ADDRESS_LIST, jsonInput);
- JSONObject result = JSONObjectUtil.getResult(output);
- if (ServiceResult.isOk(output)) {
- this.setPartnerAddressList(ServiceResult.toArray(result.get("addressList")));
- log.debug("-----------loadPartnerAddress------------ " + partnerAddressList);
- } else if (ServiceResult.isFail(output)) {
- MessageHelper.displayError(result);
- }
- } catch (Exception e) {
- log.error("Error on load partner address sales quotation", e);
- MessageHelper.displayError(e.getMessage());
- }
- }
- @SuppressWarnings("unchecked")
- public void clearPartner(){
- header.put("partnerId", GeneralConstants.NULL_REF_VALUE_LONG);
- header.remove("activePartner");
- header.remove("partnerCode");
- header.remove("partnerName");
- clearPartnerCp();
- clearPartnerAddress();
- }
- @SuppressWarnings("unchecked")
- public void clearPartnerCp(){
- header.put("partnerCpId", GeneralConstants.NULL_REF_VALUE_LONG);
- header.remove("partnerCpName");
- header.remove("partnerCpPhone1");
- header.remove("partnerCpPhone2");
- header.remove("partnerCpFax1");
- header.remove("partnerCpFax2");
- header.remove("partnerCpEmail");
- header.remove("partnerCpMobilePhone1");
- header.remove("partnerCpMobilePhone2");
- }
- @SuppressWarnings("unchecked")
- public void clearPartnerAddress(){
- header.put("partnerAddressId", GeneralConstants.NULL_REF_VALUE_LONG);
- header.remove("partnerAddress1");
- header.remove("partnerAddress2");
- header.remove("partnerAddress3");
- }
- @SuppressWarnings("unchecked")
- public void chooseCustomer(JSONObject addItem) {
- JSONObject item = new JSONObject();
- item = (JSONObject) addItem.clone();
- log.debug("============item=============== " + item);
- header.put("partnerId", item.get("id"));
- header.put("activePartner", item.get("active"));
- header.put("partnerId", item.get("id"));
- header.put("partnerName", item.get("name"));
- header.put("partnerCode", item.get("code"));
- clearPartnerCp();
- clearPartnerAddress();
- log.debug("=============header partner============== " + header);
- }
- @SuppressWarnings("unchecked")
- public void chooseCustomerCP(JSONObject addItem) {
- JSONObject item = new JSONObject();
- item = (JSONObject) addItem.clone();
- log.debug("============ITEM=============== " + item);
- header.put("partnerCpId", item.get("id"));
- header.put("partnerCpName", item.get("cpName") == null ? GeneralConstants.EMPTY_VALUE : item.get("cpName"));
- header.put("partnerCpPhone1", item.get("phone1") == null ? GeneralConstants.EMPTY_VALUE : item.get("phone1"));
- header.put("partnerCpPhone2", item.get("phone2") == null ? GeneralConstants.EMPTY_VALUE : item.get("phone2"));
- header.put("partnerCpFax1", item.get("fax1") == null ? GeneralConstants.EMPTY_VALUE : item.get("fax1"));
- header.put("partnerCpFax2", item.get("fax2") == null ? GeneralConstants.EMPTY_VALUE : item.get("fax2"));
- header.put("partnerCpEmail", item.get("email") == null ? GeneralConstants.EMPTY_VALUE : item.get("email"));
- header.put("partnerCpMobilePhone1", item.get("mobilePhone1") == null ? GeneralConstants.EMPTY_VALUE : item.get("mobilePhone1"));
- header.put("partnerCpMobilePhone2", item.get("mobilePhone2") == null ? GeneralConstants.EMPTY_VALUE : item.get("mobilePhone2"));
- log.debug("=============header inputPartnerCp============== " + header);
- }
- @SuppressWarnings("unchecked")
- public void chooseCustomerAddress(JSONObject addItem) {
- JSONObject item = new JSONObject();
- item = (JSONObject) addItem.clone();
- log.debug("============item=============== " + item);
- header.put("partnerAddressId", item.get("partnerAddressId") == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(item.get("partnerAddressId").toString()));
- header.put("partnerAddress1", item.get("address1") == null ? GeneralConstants.EMPTY_VALUE : item.get("address1"));
- header.put("partnerAddress2", item.get("address2") == null ? GeneralConstants.EMPTY_VALUE : item.get("address2"));
- header.put("partnerAddress3", item.get("address3") == null ? GeneralConstants.EMPTY_VALUE : item.get("address3"));
- log.debug("=============header partner============== " + header);
- }
- ///////////////////////////////////////////////////////////////// LOAD //////////////////////////////////////////////////////////
- @SuppressWarnings("unchecked")
- private void loadOu() {
- log.debug("\n\n LOAD OU \n\n");
- JSONObject input = new JSONObject();
- input.put("id", header.get("ouId"));
- log.debug("\n\n Load Ou Input : "+input+" \n\n");
- try {
- JSONObject output = serviceContext.executeService(FIND_OU_BY_ID, input);
- log.debug("\n\n Load Ou Output Find Ou By Id : "+output+" \n\n");
- JSONObject result = JSONObjectUtil.getResult(output);
- log.debug("\n\n Load Ou Result Find Ou By Id : "+result+" \n\n");
- String status = JSONObjectUtil.getResultStatus(output);
- log.debug("\n\n Load Ou Result Status : "+status+" \n\n");
- log.debug("result load OU : " + output);
- if (status != null && status.equals(GeneralConstants.OK)) {
- log.debug("\n\n Load Ou If Status Is OK or Not Equals Null \n\n");
- header.put("ouCode", result.get("code"));
- log.debug("\n\n Load Ou Header Ou Code : "+header.get("ouCode")+" \n\n");
- header.put("ouName", result.get("name"));
- log.debug("\n\n Load Ou Header Ou Name : "+header.get("ouName")+" \n\n");
- if(result.get("flgPkp").equals(GeneralConstants.YES)){
- log.debug("\n\n Load Ou If Flag Pkp Equals Yes \n\n");
- header.put("flgPkp", result.get("flgPkp"));
- log.debug("\n\n Load Ou Header Flag Pkp : "+header.get("flgPkp")+" \n\n");
- this.taxList = this.combo.getTaxListAdvance();
- log.debug("\n\n Load Ou Tax List : "+this.taxList+" \n\n");
- String taxId = GeneralConstants.NULL_REF_VALUE_LONG.toString();
- log.debug("\n\n Load Ou Tax Id Before Set: "+taxId+" \n\n");
- if(taxList != null || !taxList.isEmpty()){
- log.debug("\n\n Load Ou If Tax List Not Null Or Not Empty \n\n");
- taxId = taxList.get(0).get("id").toString();
- log.debug("\n\n Load Ou Tax Id : "+taxId+" \n\n");
- }
- log.debug("\n\n Load Ou Tax Id After Set: "+taxId+" \n\n");
- header.put("tax", new ComboItem("id", taxId));
- log.debug("\n\n Load Ou Header Tax : "+header.get("tax")+" \n\n");
- header.put("flgTax", GeneralConstants.YES);
- log.debug("\n\n Load Ou Header Flag Tax : "+header.get("flgTax")+" \n\n");
- } else {
- log.debug("\n\n Load Ou Else Flag Pkp \n\n");
- header.put("flgPkp", GeneralConstants.NO);
- log.debug("\n\n Load Ou Header Flag Pkp : "+header.get("flgPkp")+" \n\n");
- header.put("tax", new ComboItem("id", GeneralConstants.NULL_REF_VALUE_LONG));
- log.debug("\n\n Load Ou Header Tax : "+header.get("tax")+" \n\n");
- header.put("flgTax", GeneralConstants.NO);
- log.debug("\n\n Load Ou Header Flag Tax : "+header.get("flgTax")+" \n\n");
- }
- } else if (status != null && status.equals(GeneralConstants.FAIL)) {
- FacesUtils.addErrorMessage(MessageUtil.getInstance().getLabel((String) result.get("errorKey"), result.get("args")));
- }
- } catch (Exception e) {
- log.error("Error on load OU", e);
- FacesUtils.addErrorMessage(e.getMessage());
- }
- log.debug("\n\n END LOAD OU :" + header + "\n\n");
- }
- @SuppressWarnings("unchecked")
- private void loadSalesQuotationTC() {
- if (this.header.get("id") == null) {
- } else {
- JSONObject input = new JSONObject();
- input.put("quotationId", this.header.get("id"));
- try {
- JSONObject output = this.serviceContext.executeService(GET_TERMS_AND_CONDITION_SALES_QUOTATION_ITEM_LIST_BY_SALES_QUOTATION, input);
- JSONObject result = JSONObjectUtil.getResult(output);
- if (ServiceResult.isOk(output)) {
- this.setTcList(ServiceResult.toArray(result.get("termsAndConditionList")));
- } else if (ServiceResult.isFail(output)) {
- MessageHelper.displayError(result);
- }
- } catch (Exception e) {
- log.error("Error on load term condition sales quotation", e);
- MessageHelper.displayError(e.getMessage());
- }
- }
- }
- @SuppressWarnings("unchecked")
- private void loadSalesQuotationItem() {
- if (this.header.get("id") == null) {
- } else {
- JSONObject input = new JSONObject();
- input.put("quotationId", this.header.get("id"));
- try {
- JSONObject output = this.serviceContext.executeService(GET_SALES_QUOTATION_ITEM_LIST_BY_SALES_QUOTATION, input);
- JSONObject result = JSONObjectUtil.getResult(output);
- if (ServiceResult.isOk(output)) {
- log.debug("loadSalesQuotationItem() result : " + result);
- details = ServiceResult.toArray(result.get("salesQuotationItemList"));
- for (JSONObject item : this.details) {
- item.put("currCode", header.get("currCode"));
- }
- log.debug("isi details " + details);
- } else if (ServiceResult.isFail(output)) {
- MessageHelper.displayError(result);
- }
- } catch (Exception e) {
- log.error("Error on load term condition sales quotation", e);
- MessageHelper.displayError(e.getMessage());
- }
- }
- }
- @SuppressWarnings("unchecked")
- private void loadSalesQuotation() {
- if (this.header.get("id") == null) {
- this.header.put("docNo", "");
- this.header.put("docDate", DateUtil.dateNow());
- this.header.put("extDocNo", "");
- this.header.put("extDocDate", DateUtil.dateNow());
- this.header.put("remark", "");
- this.header.put("flgTax", "N");
- this.header.put("currCode", "");
- } else {
- JSONObject input = new JSONObject();
- input.put("id", this.header.get("id"));
- List<JSONObject> taxList = this.combo.getTaxListAdvance();
- try {
- JSONObject output = this.serviceContext.executeService(FIND_SALES_QUOTATION_BY_ID, input);
- JSONObject result = JSONObjectUtil.getResult(output);
- if (ServiceResult.isOk(output)) {
- log.debug("isi outputtt ==========>>>>>>>>>> " + output);
- header = result;
- header.put("id", Long.valueOf(header.get("id").toString()));
- header.put("version", Long.valueOf(header.get("version").toString()));
- header.put("ouId", Long.valueOf(header.get("ouId").toString()));
- header.put("currency", new ComboItem("code", header.get("currCode")));
- header.put("flgTax", header.get("flgTaxAmount"));
- header.put("refId", Long.valueOf(result.get("refId").toString()));
- header.put("flgFromWebpos",result.get("flgFromWebpos") != null ? result.get("flgFromWebpos").toString() : GeneralConstants.NO);
- if(taxList != null && !taxList.isEmpty()){
- for(JSONObject tax : taxList){
- if(tax.get("id").equals(header.get("taxId"))){
- header.put("tax", tax);
- break;
- }
- }
- }
- loadSalesman(Long.valueOf(header.get("salesmanId").toString()));
- loadCustomer(Long.valueOf(header.get("partnerId").toString()));
- loadOu();
- loadSalesQuotationFromRevision(Long.valueOf(result.get("refId").toString()));
- editMode = true;
- super.loadDocumentStatus();
- } else if (ServiceResult.isFail(output)) {
- MessageHelper.displayError(result);
- }
- } catch (Exception e) {
- log.error("Error on load sales order", e);
- MessageHelper.displayError(e.getMessage());
- }
- }
- }
- @SuppressWarnings("unchecked")
- private void loadSalesQuotationFromRevision(Long refIdQuotation) {
- header.put("refDocNo", GeneralConstants.EMPTY_VALUE);
- header.put("refDocDate", GeneralConstants.EMPTY_VALUE);
- if(!GeneralConstants.NULL_REF_VALUE_LONG.equals(refIdQuotation)) {
- try {
- JSONObject jsonInput = new JSONObject();
- jsonInput.put("id", refIdQuotation);
- JSONObject output = serviceContext.executeService(FIND_SALES_QUOTATION_BY_ID, jsonInput);
- JSONObject result = JSONObjectUtil.getResult(output);
- if(ServiceResult.isOk(output)) {
- header.put("refDocNo", result.get("docNo"));
- header.put("refDocDate", result.get("docDate"));
- } else if(ServiceResult.isFail(output)) {
- MessageHelper.displayError(result);
- }
- } catch(Exception e) {
- MessageHelper.displayError(e.getMessage());
- }
- }
- }
- @SuppressWarnings("unchecked")
- private void loadSalesman(Long salesmanId) {
- log.debug("load salesman. Salesman ID: " + salesmanId);
- log.debug("Current header: " + header);
- if (header.get("salesman") == null && header.get("salesmanId") != null
- && !GeneralConstants.NULL_REF_VALUE_LONG.equals(Long.valueOf(header.get("salesmanId").toString()))) {
- JSONObject input = new JSONObject();
- input.put("id", header.get("salesmanId"));
- try {
- JSONObject output = serviceContext.executeService(FIND_PARTNER_BY_ID, input);
- JSONObject result = JSONObjectUtil.getResult(output);
- String status = JSONObjectUtil.getResultStatus(output);
- if (status != null && status.equals(GeneralConstants.OK)) {
- ComboItem temp = new ComboItem("id");
- temp.put("id", result.get("id"));
- temp.put("code", result.get("code"));
- temp.put("name", result.get("name"));
- header.put("salesman", temp);
- } else if (status != null && status.equals(GeneralConstants.FAIL)) {
- FacesUtils.addErrorMessage(MessageUtil.getInstance().getLabel((String) result.get("errorKey"), result.get("args")));
- }
- } catch (Exception e) {
- log.error("Error on load salesman", e);
- FacesUtils.addErrorMessage(e.getMessage());
- }
- }
- }
- @SuppressWarnings("unchecked")
- private void loadCustomer(Long partnerId) {
- log.debug("\n\n Load Customer \n\n");
- if (header.get("partnerId") != null && !GeneralConstants.NULL_REF_VALUE_LONG.equals(Long.valueOf(header.get("partnerId").toString()))) {
- log.debug("\n\n Load Customer If Header Partner Not Null Or Empty Id \n\n");
- JSONObject input = new JSONObject();
- input.put("id", header.get("partnerId"));
- log.debug("\n\n Load Customer Input "+input+" \n\n");
- try {
- JSONObject output = serviceContext.executeService(FIND_PARTNER_BY_ID, input);
- log.debug("\n\n Load Customer Output Service Find Partner By Id : "+output+" \n\n");
- JSONObject result = JSONObjectUtil.getResult(output);
- log.debug("\n\n Load Customer Result Service Find Partner By Id : "+result+" \n\n");
- String status = JSONObjectUtil.getResultStatus(output);
- log.debug("\n\n Load Customer Result Status : "+status+" \n\n");
- if (status != null && status.equals(GeneralConstants.OK)) {
- log.debug("\n\n Load Customer If Result Status Not Null And Equals OK \n\n");
- header.put("partnerCode", result.get("code"));
- log.debug("\n\n Load Customer Header Partner Code : "+header.get("partnerCode")+" \n\n");
- header.put("partnerName", result.get("name"));
- log.debug("\n\n Load Customer Header Partner Name : "+header.get("partnerName")+" \n\n");
- log.debug("ini isi dari code customer === " + header.get("partnerCode"));
- } else if (status != null && status.equals(GeneralConstants.FAIL)) {
- log.debug("ini isi dari ERROR NYA code customer === ");
- FacesUtils.addErrorMessage(MessageUtil.getInstance().getLabel((String) result.get("errorKey"), result.get("args")));
- }
- } catch (Exception e) {
- log.error("Error on load customer", e);
- FacesUtils.addErrorMessage(e.getMessage());
- }
- }
- }
- @Override
- public String getScheme() {
- return SalesWebConstants.SCHEME_SALES_QUOTATION;
- }
- @Override
- public boolean isCanCancelApprove() {
- return true;
- }
- @Override
- public String cancelApproveTaskName() {
- return CANCEL_APPROVE_SALES_QUOTATION;
- }
- /////////////////////////////////////////////////////// SETTER & GETTER //////////////////////////////////////////////////////////
- public Long getLastLineNo() {
- return lastLineNo;
- }
- public void setLastLineNo(Long lastLineNo) {
- this.lastLineNo = lastLineNo;
- }
- public List<JSONObject> getTcList() {
- return tcList;
- }
- public void setTcList(List<JSONObject> tcList) {
- this.tcList = tcList;
- }
- public JSONObject getFilterAddMoreItems() {
- return filterAddMoreItems;
- }
- public void setFilterAddMoreItems(JSONObject filterAddMoreItems) {
- this.filterAddMoreItems = filterAddMoreItems;
- }
- public List<JSONObject> getSubCategoryProductList() {
- return subCategoryProductList;
- }
- public void setSubCategoryProductList(List<JSONObject> subCategoryProductList) {
- this.subCategoryProductList = subCategoryProductList;
- }
- public JSONObject getItemToBeDeleted() {
- return itemToBeDeleted;
- }
- public void setItemToBeDeleted(JSONObject itemToBeDeleted) {
- this.itemToBeDeleted = itemToBeDeleted;
- }
- public ProductLazyModel getModel() {
- return model;
- }
- public JSONObject getDataProduct() {
- return dataProduct;
- }
- public void setDataProduct(JSONObject dataProduct) {
- this.dataProduct = dataProduct;
- }
- public String getDataPartner() {
- return dataPartner;
- }
- public void setDataPartner(String dataPartner) {
- this.dataPartner = dataPartner;
- }
- public List<JSONObject> getPartnerList() {
- return partnerList;
- }
- public void setPartnerList(List<JSONObject> partnerList) {
- this.partnerList = partnerList;
- }
- public List<JSONObject> getCpList() {
- return cpList;
- }
- public void setCpList(List<JSONObject> cpList) {
- this.cpList = cpList;
- }
- public List<JSONObject> getPartnerAddressList() {
- return partnerAddressList;
- }
- public void setPartnerAddressList(List<JSONObject> partnerAddressList) {
- this.partnerAddressList = partnerAddressList;
- }
- public List<JSONObject> getTaxList() {
- return taxList;
- }
- public void setTaxList(List<JSONObject> taxList) {
- this.taxList = taxList;
- }
- }
Add Comment
Please, Sign In to add comment