1DanielLee9

InputSalesQuotationController

Apr 14th, 2021 (edited)
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 62.87 KB | None | 0 0
  1. package org.jleaf.erp.sls.web.controller.salesquotation;
  2.  
  3. import java.io.Serializable;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import java.util.Map;
  7.  
  8. import javax.faces.event.AjaxBehaviorEvent;
  9.  
  10. import org.jleaf.core.GeneralConstants;
  11. import org.jleaf.erp.sls.api.SalesApi;
  12. import org.jleaf.erp.sls.api.SalesHumanTask;
  13. import org.jleaf.erp.master.api.MasterApi;
  14. import org.jleaf.erp.sls.web.PageInputConstants;
  15. import org.jleaf.erp.sls.web.SalesWebConstants;
  16. import org.jleaf.erp.sls.web.controller.GlobalSalesCombo;
  17. import org.jleaf.erp.sls.web.model.ProductLazyModel;
  18. import org.jleaf.util.DateUtil;
  19. import org.jleaf.util.JSONObjectUtil;
  20. import org.jleaf.web.helper.MessageHelper;
  21. import org.jleaf.web.helper.ServiceResult;
  22. import org.jleaf.web.jsf.FacesUtils;
  23. import org.jleaf.web.jsf.WebJsfConstants;
  24. import org.jleaf.web.jsf.controller.Combo;
  25. import org.jleaf.web.jsf.template.AbstractInputWithApprovalController;
  26. import org.jleaf.web.jsf.util.MessageUtil;
  27. import org.jleaf.web.model.ComboItem;
  28. import org.jleaf.web.report.server.ReportServerProvider;
  29. import org.json.simple.JSONObject;
  30. import org.primefaces.context.RequestContext;
  31. import org.slf4j.Logger;
  32. import org.slf4j.LoggerFactory;
  33. import org.springframework.beans.factory.annotation.Autowired;
  34. import org.springframework.context.annotation.Scope;
  35. import org.springframework.stereotype.Controller;
  36.  
  37. import javax.faces.context.FacesContext;
  38.  
  39. /**
  40.  *
  41.  * @author Sarah, May 6, 2016
  42.  *
  43.  **/
  44. @SuppressWarnings("serial")
  45. @Controller
  46. @Scope("view")
  47. public class inputSalesQuotationController extends AbstractInputWithApprovalController implements SalesApi, Serializable {
  48.     private static final Logger log = LoggerFactory.getLogger(inputSalesQuotationController.class);
  49.  
  50.     private List<JSONObject> partnerAddressList = new ArrayList<JSONObject>();
  51.     private List<JSONObject> partnerList = new ArrayList<JSONObject>();
  52.     private List<JSONObject> cpList = new ArrayList<JSONObject>();
  53.     private List<JSONObject> tcList = new ArrayList<JSONObject>();
  54.     private List<JSONObject> subCategoryProductList;
  55.     private JSONObject filterAddMoreItems = new JSONObject();
  56.     private JSONObject dataProduct = new JSONObject();
  57.     private JSONObject itemToBeDeleted;
  58.     private Long lastLineNo = Long.valueOf(0L);
  59.     private List<JSONObject> taxList = new ArrayList<JSONObject>();
  60.     private String dataPartner;
  61.     private ProductLazyModel model;
  62.    
  63.     @Autowired
  64.     private GlobalSalesCombo combo;
  65.    
  66.     @Autowired
  67.     private ReportServerProvider reportServerProvider;
  68.    
  69.     @SuppressWarnings("unchecked")
  70.     @Override
  71.     protected void init() {
  72.         super.init();
  73.         JSONObject signatureSalesQuotation = new JSONObject();
  74.         signatureSalesQuotation.put("salesQuotationSignature", GeneralConstants.EMPTY_VALUE);
  75.     }
  76.    
  77.     @SuppressWarnings("unchecked")
  78.     @Override
  79.     protected void addDocument() {
  80.         log.debug("------------------------HEADER---------------------------" + header);
  81.         Object tempValue;
  82.  
  83.         JSONObject salesman = (JSONObject) header.get("salesman");
  84.         JSONObject tax = (JSONObject) header.get("tax");
  85.         JSONObject currency = (JSONObject) header.get("currency");
  86.  
  87.         JSONObject input = new JSONObject();
  88.         input.put("ouId", header.get("ouId"));
  89.         input.put("docNo", header.get("docNo"));
  90.         input.put("docDate", header.get("docDate"));
  91.         input.put("extDocNo", header.get("extDocNo"));
  92.         input.put("extDocDate", header.get("extDocDate"));
  93.         input.put("flgFromWebpos", header.get("flgFromWebpos") != null ? header.get("flgFromWebpos") : GeneralConstants.NO);
  94.        
  95.         if(header.get("salesman") == null || header.get("salesman").equals(GeneralConstants.EMPTY_VALUE)){
  96.             MessageHelper.displayError("salesman must be filled");
  97.         } else {   
  98.             input.put("currCode", currency.get("code"));
  99.             input.put("flgTaxAmount", (tempValue = header.get("flgTax")) == null ? GeneralConstants.NO : tempValue);
  100.             input.put("taxId", (tax == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(tax.get("id").toString())));
  101.             input.put("remark", (tempValue = header.get("remark")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  102.             input.put("partnerId", (tempValue = Long.valueOf(header.get("partnerId").toString())) == null ? GeneralConstants.NULL_REF_VALUE_LONG : tempValue);
  103.             input.put("partnerName", (tempValue = header.get("partnerName")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  104.             input.put("partnerAddressId", (tempValue = (header.get("partnerAddressId")) == null ? GeneralConstants.NULL_REF_VALUE_LONG :  Long.valueOf(header.get("partnerAddressId").toString())));
  105.             input.put("partnerAddress1", (tempValue = header.get("partnerAddress1")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  106.             input.put("partnerAddress2", (tempValue = header.get("partnerAddress2")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  107.             input.put("partnerAddress3", (tempValue = header.get("partnerAddress3")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  108.             input.put("partnerCpId", (tempValue = (header.get("partnerCpId")) == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(header.get("partnerCpId").toString())));
  109.             input.put("partnerCpName", (tempValue = header.get("partnerCpName")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  110.             input.put("partnerCpPhone1", (tempValue = header.get("partnerCpPhone1")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  111.             input.put("partnerCpPhone2", (tempValue = header.get("partnerCpPhone2")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  112.             input.put("partnerCpFax1", (tempValue = header.get("partnerCpFax1")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  113.             input.put("partnerCpFax2", (tempValue = header.get("partnerCpFax2")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  114.             input.put("partnerCpEmail", (tempValue = header.get("partnerCpEmail")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  115.             input.put("partnerCpMobilePhone1", (tempValue = header.get("partnerCpMobilePhone1")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  116.             input.put("partnerCpMobilePhone2", (tempValue = header.get("partnerCpMobilePhone2")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  117.             input.put("salesmanId", (salesman == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(salesman.get("id").toString())));
  118.             List<JSONObject> itemList = new ArrayList<JSONObject>();
  119.    
  120.             if (details != null && !details.isEmpty()) {
  121.                 for (JSONObject item : details) {
  122.  
  123.                     JSONObject inputItem = new JSONObject();
  124.                        
  125.                     if(header.get("flgFromWebpos").equals(GeneralConstants.YES)) {
  126.                         inputItem.put("refDocTypeId", item.get("docTypeId"));
  127.                         inputItem.put("refId", item.get("refId"));
  128.                     } else {
  129.                         inputItem.put("refDocTypeId", GeneralConstants.NULL_REF_VALUE_LONG);
  130.                         inputItem.put("refId", GeneralConstants.NULL_REF_VALUE_LONG);
  131.                     }
  132.                    
  133.                     inputItem.put("lineNo", item.get("lineNo"));
  134.                     inputItem.put("productId", item.get("productId"));
  135.                     inputItem.put("productCode", item.get("productCode"));
  136.                     inputItem.put("productDesc", item.get("productDesc"));
  137.                     inputItem.put("uomId", item.get("uomId"));
  138.                     inputItem.put("qty", (tempValue = item.get("qty")) == null ? 0d : tempValue);
  139.                     inputItem.put("amount", (Double.valueOf(item.get("qty").toString())*Double.valueOf(item.get("sellPrice").toString())));
  140.                     inputItem.put("sellPrice", (tempValue = item.get("sellPrice")) == null ? 0d : tempValue);
  141.                     inputItem.put("brandCode", item.get("brandCode"));
  142.                     inputItem.put("brandName", item.get("brandName"));
  143.                     inputItem.put("remark", item.get("remark"));
  144.                     inputItem.put("flgStock", item.get("flgStock"));
  145.                     inputItem.put("indentDays", item.get("indentDays"));
  146.                     itemList.add(inputItem);
  147.                 }
  148.             }
  149.    
  150.             input.put("salesQuotationProductList", itemList);
  151.            
  152.             log.debug("add document " + input.toString());
  153.            
  154.             try {
  155.                 JSONObject output = serviceContext.executeService(ADD_SALES_QUOTATION, input);
  156.                 JSONObject result = JSONObjectUtil.getResult(output);
  157.                 if (ServiceResult.isOk(output)) {
  158.                     MessageHelper.displayInfo("org.jleaf.erp.sls.web.dataSuccessSave");
  159.                     editMode = true;
  160.                    
  161.                     header.put("id", result.get("id"));
  162.                     loadSalesQuotation();
  163.                     loadSalesQuotationTC();
  164.                     loadSalesQuotationItem();
  165.                     loadDocumentStatus();
  166.                    
  167.                 } else if (ServiceResult.isFail(output)) {
  168.                     MessageHelper.displayError(result);
  169.                     errorHolder.putError("org.jleaf.erp.sls.web", result);
  170.                 }
  171.             } catch (Exception e) {
  172.                 log.error("Error on add sales order along with its items", e);
  173.                 MessageHelper.displayError(e.getMessage());
  174.             }
  175.         }
  176.        
  177.     }
  178.    
  179.     @Override
  180.     public String approveTaskName() {
  181.         return APPROVED_SALES_QUOTATION;
  182.     }
  183.    
  184.     @Override
  185.     public String cancelTaskName() {
  186.         return CANCEL_SALES_QUOTATION;
  187.     }
  188.     @Override
  189.     public String deleteTaskName() {
  190.         return REMOVE_SALES_QUOTATION;
  191.     }
  192.    
  193.     @SuppressWarnings("unchecked")
  194.     @Override
  195.     protected void editDocument() {
  196.         log.debug("------------------------HEADER---------------------------" + header);
  197.         Object tempValue;
  198.        
  199.         JSONObject salesman = (JSONObject) header.get("salesman");
  200.         JSONObject tax = (JSONObject) header.get("tax");
  201.         JSONObject currency = (JSONObject) header.get("currency");
  202.  
  203.         if(header.get("salesman") == null || header.get("salesman").equals(GeneralConstants.EMPTY_VALUE)){
  204.             MessageHelper.displayError("salesman must be filled");
  205.         } else {
  206.             JSONObject input = new JSONObject();
  207.             input.put("quotationId", header.get("id"));
  208.             input.put("version", header.get("version"));
  209.             input.put("extDocNo", header.get("extDocNo"));
  210.             input.put("extDocDate", header.get("extDocDate"));
  211.             input.put("docNo", header.get("docNo"));
  212.             input.put("ouId", header.get("ouId"));
  213.             input.put("docDate", header.get("docDate"));
  214.             input.put("currCode", currency.get("code"));
  215.             input.put("flgTaxAmount", (tempValue = header.get("flgTax")) == null ? GeneralConstants.NO : tempValue);
  216.             input.put("taxId", (Long.valueOf(tax == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(tax.get("id").toString()))));
  217.             input.put("remark", (tempValue = header.get("remark")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  218.             input.put("partnerId", (tempValue = header.get("partnerId")) == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(header.get("partnerId").toString()));
  219.             input.put("partnerName", (tempValue = header.get("partnerName")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  220.             input.put("partnerAddressId", (tempValue = (header.get("partnerAddressId")) == null ? GeneralConstants.NULL_REF_VALUE_LONG :  Long.valueOf(header.get("partnerAddressId").toString())));
  221.             input.put("partnerAddress1", (tempValue = header.get("partnerAddress1")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  222.             input.put("partnerAddress2", (tempValue = header.get("partnerAddress2")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  223.             input.put("partnerAddress3", (tempValue = header.get("partnerAddress3")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  224.             input.put("partnerCpId", (tempValue = (header.get("partnerCpId")) == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(header.get("partnerCpId").toString())));
  225.             input.put("partnerCpName", (tempValue = header.get("partnerCpName")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  226.             input.put("partnerCpPhone1", (tempValue = header.get("partnerCpPhone1")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  227.             input.put("partnerCpPhone2", (tempValue = header.get("partnerCpPhone2")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  228.             input.put("partnerCpFax1", (tempValue = header.get("partnerCpFax1")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  229.             input.put("partnerCpFax2", (tempValue = header.get("partnerCpFax2")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  230.             input.put("partnerCpEmail", (tempValue = header.get("partnerCpEmail")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  231.             input.put("partnerCpMobilePhone1", (tempValue = header.get("partnerCpMobilePhone1")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  232.             input.put("partnerCpMobilePhone2", (tempValue = header.get("partnerCpMobilePhone2")) == null ? GeneralConstants.EMPTY_VALUE : tempValue);
  233.             input.put("salesmanId", (salesman == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(salesman.get("id").toString())));
  234.        
  235.             log.debug("--------=========== ++++ isi input " + input);
  236.    
  237.             try {
  238.                 JSONObject output = serviceContext.executeService(EDIT_SALES_QUOTATION, input);
  239.                 JSONObject result = JSONObjectUtil.getResult(output);
  240.                 if (ServiceResult.isOk(output)) {
  241.                     MessageHelper.displayInfo("org.jleaf.erp.sls.web.dataSuccessSave");
  242.                     header.put("id", result.get("id"));
  243.                     loadSalesQuotation();
  244.                     loadSalesQuotationTC();
  245.                     loadSalesQuotationItem();
  246.                     loadDocumentStatus();
  247.                    
  248.                     editMode = true;
  249.    
  250.                 } else if (ServiceResult.isFail(output)) {
  251.                     MessageHelper.displayError(result);
  252.                     errorHolder.putError("org.jleaf.erp.sls.web", result);
  253.                 }
  254.             } catch (Exception e) {
  255.                 log.error("Error on add sales order along with its items", e);
  256.                 MessageHelper.displayError(e.getMessage());
  257.             }
  258.         }
  259.     }
  260.    
  261.     @SuppressWarnings("unchecked")
  262.     @Override
  263.     public void doDownload() {
  264.         log.debug("call doDownload()");
  265.        
  266.         try {
  267.            
  268.             JSONObject jsonInput = new JSONObject();
  269.             jsonInput.put("sessionId", FacesUtils.getSessionId());
  270.             jsonInput.put("tenantId", Long.valueOf(FacesUtils.getSessionMap().get(WebJsfConstants.SESS_LOGGED_TENANT_ID).toString()));
  271.             jsonInput.put("quotationId", Long.valueOf(header.get("id").toString()));
  272.             jsonInput.put("ouId", Long.valueOf(header.get("ouId").toString()));
  273.             jsonInput.put("userId", Long.valueOf(FacesUtils.getSessionMap().get(WebJsfConstants.SESS_LOGGED_USER_ID).toString()));
  274.  
  275.             log.debug("getReportUserParameters Data" + getReportUserParameters());
  276.            
  277.             String paramsValue = GeneralConstants.EMPTY_VALUE;
  278.             if (getReportUserParameters().size() > 0) {
  279.                 for (JSONObject item : getReportUserParameters()) {
  280.                     paramsValue = item.get("value").toString();
  281.                 }
  282.             }
  283.             jsonInput.put("salesQuotationSignature", paramsValue);
  284.            
  285.             log.debug(">> input download " + jsonInput);
  286.             String reportName = getCurrentReportName();
  287.             String fileName = GeneralConstants.SPACE_VALUE;
  288.  
  289.             if (reportName.equals(SalesWebConstants.FORM_SALES_QUOTATION)) {
  290.                 reportName = SalesWebConstants.FORM_SALES_QUOTATION;
  291.                 fileName = SalesWebConstants.FORM_SALES_QUOTATION + "_" + header.get("docNo").toString() + "_" + DateUtil.dateTimeNow();
  292.             }
  293.            
  294. //          FacesContext.getCurrentInstance().getExternalContext().redirect(export(reportName, fileName, jsonInput));
  295.            
  296.             boolean isQueue = false;
  297.             if (isQueue) {
  298.                 JSONObject output = reportServerProvider
  299.                         .requestDownloadAsync(
  300.                                 SalesHumanTask.DOWNLOAD_PDF_SALES_QUOTATION,
  301.                                 reportName, fileName,
  302.                                 "Form Sales Quotation", jsonInput);
  303.                 JSONObject result = JSONObjectUtil.getResult(output);
  304.  
  305.                 if (ServiceResult.isOk(output)) {
  306.                     reportServerProvider.goToResultPage(result,
  307.                             FacesContext.getCurrentInstance());
  308.  
  309.                 } else {
  310.                     MessageHelper.displayError(result);
  311.                 }
  312.             } else {
  313.                 reportServerProvider
  314.                         .requestDownloadSync(
  315.                                 SalesHumanTask.DOWNLOAD_PDF_SALES_QUOTATION,
  316.                                 reportName, fileName,
  317.                                 "Form Sales Quotation", jsonInput,
  318.                                 FacesContext.getCurrentInstance());
  319.             }
  320.            
  321.         } catch(Exception e) {
  322.             log.error(e.getMessage(), e);
  323.             MessageHelper.displayError(e.getMessage());
  324.            
  325.         }
  326.        
  327.     }
  328.    
  329.     @Override
  330.     public String getDocStatusTaskName() {
  331.         return GET_SALES_QUOTATION_STATUS_BY_USER_ROLE_AND_DOC_ID;
  332.     }
  333.     @Override
  334.     public String getViewName() {
  335.         return PageInputConstants.INPUT_SALES_QUOTATION;
  336.     }
  337.  
  338.     @Override
  339.     public void onActionFail(String action, JSONObject result) {
  340.         MessageHelper.displayError(result);    
  341.     }
  342.  
  343.     @Override
  344.     public void onActionSuccess(String action, JSONObject result) {
  345.         if (action.equals(WebJsfConstants.ACTION_DELETE)) {
  346.             RequestContext context = RequestContext.getCurrentInstance();
  347.             context.execute("document.location='createSalesQuotation.jsf'");
  348.         } else {
  349.             loadDocumentStatus();
  350.         }
  351.        
  352.         if (action.equals(WebJsfConstants.ACTION_SUBMIT)){
  353.             loadDocumentStatus();
  354.             loadSalesQuotation();
  355.             loadSalesQuotationItem();
  356.             loadSalesQuotationTC();
  357.             editMode = true;
  358.         } else {
  359.             loadDocumentStatus();
  360.         }
  361.        
  362.         if (action.equals(WebJsfConstants.ACTION_CANCEL) || action.equals(WebJsfConstants.ACTION_REQUEST_CHANGES) || action.equals(WebJsfConstants.ACTION_REJECT)){
  363.             loadDocumentStatus();
  364.             loadSalesQuotation();
  365.             loadSalesQuotationItem();
  366.             loadSalesQuotationTC();
  367.         } else {
  368.             loadDocumentStatus();
  369.         }
  370.     }
  371.    
  372.     @SuppressWarnings("unchecked")
  373.     @Override
  374.     public void prepareAdd(Map<String, Object> parameter) {
  375.         log.debug("\n\n Prepare Add Sales Quotation \n\n");
  376.         log.debug("parameter >>>>>>>>>>>>>>>> " + parameter);
  377.        
  378.         JSONObject ou = (JSONObject) parameter.get("ou");
  379.         log.debug("\n\n Prepare Add Ou : "+ou+" \n\n");
  380.        
  381.         getHeader().put("docNo", GeneralConstants.EMPTY_VALUE);
  382.         log.debug("\n\n Prepare Add Get Header Doc No : "+getHeader().get("docNo")+" \n\n");
  383.        
  384.         getHeader().put("docDate", DateUtil.dateNow());
  385.         log.debug("\n\n Prepare Add Get Header Doc Date : "+getHeader().get("docDate")+" \n\n");
  386.        
  387.         getHeader().put("ouId", Long.valueOf(ou.get("id").toString()));
  388.         log.debug("\n\n Prepare Add Get Header Ou Id : "+getHeader().get("ouId")+" \n\n");
  389.        
  390.         getHeader().put("ouName", ou.get("name"));
  391.         log.debug("\n\n Prepare Add Get Header Ou Name : "+getHeader().get("ouName")+" \n\n");
  392.        
  393.         getHeader().put("currency", new ComboItem("code", SalesWebConstants.DEFAULT_CURRENCY_CODE));
  394.         log.debug("\n\n Prepare Add Get Header Currency : "+getHeader().get("currency")+" \n\n");
  395.        
  396.         getHeader().put("flgTax", GeneralConstants.NO);
  397.         log.debug("\n\n Prepare Add Get Header Flag Tax : "+getHeader().get("flgTax")+" \n\n");
  398.        
  399.         getHeader().put("remark", GeneralConstants.EMPTY_VALUE);
  400.         log.debug("\n\n Prepare Add Get Header Remark : "+getHeader().get("remark")+" \n\n");
  401.        
  402.         getHeader().put("partnerCpId", GeneralConstants.NULL_REF_VALUE_LONG);
  403.         log.debug("\n\n Prepare Add Get Header Partner CP Id : "+getHeader().get("partnerCpId")+" \n\n");
  404.        
  405.         getHeader().put("partnerAddressId", GeneralConstants.NULL_REF_VALUE_LONG);
  406.         log.debug("\n\n Prepare Add Get Header Partner Address Id : "+getHeader().get("partnerAddressId")+" \n\n");
  407.        
  408.         getHeader().put("flgFromWebpos", parameter.get("flgFromWebpos") != null ? parameter.get("flgFromWebpos") : GeneralConstants.NO);
  409.         log.debug("\n\n Prepare Add Get Header Flag From Web Pos : "+getHeader().get("flgFromWebpos")+" \n\n");
  410.        
  411.  
  412.         log.debug("\n\n Prepare Add Get Header Before Load Ou : "+getHeader()+" \n\n");
  413.         loadOu();
  414.         log.debug("\n\n Prepare Add Get Header After Load Ou : "+getHeader()+" \n\n");
  415.        
  416.         if(getHeader().get("flgFromWebpos").equals(GeneralConstants.YES)) {
  417.             log.debug("\n\n Prepare Add If Flag From Web Pos Equals Yes \n\n");
  418.            
  419.             JSONObject partner = (JSONObject) parameter.get("partner");
  420.             log.debug("\n\n Prepare Add Partner : "+partner+" \n\n");
  421.            
  422.             getHeader().put("extDocNo", parameter.get("extDocNo"));
  423.             log.debug("\n\n Prepare Add Get Header Ext Doc No : "+getHeader().get("extDocNo")+" \n\n");
  424.            
  425.             getHeader().put("extDocDate", parameter.get("extDocDate"));
  426.             log.debug("\n\n Prepare Add Get Header Ext Doc Date : "+getHeader().get("extDocDate")+" \n\n");
  427.            
  428.             getHeader().put("partnerId", partner.get("partnerId"));
  429.             log.debug("\n\n Prepare Add Get Header Partner Id : "+getHeader().get("partnerId")+" \n\n");
  430.            
  431.             log.debug("\n\n Prepare Add Get Header Before Load Customer : "+getHeader()+" \n\n");
  432.             loadCustomer(Long.valueOf(partner.get("partnerId").toString()));           
  433.             log.debug("\n\n Prepare Add Get Header After Load Customer : "+getHeader()+" \n\n");
  434.  
  435.             this.details = (List<JSONObject>) parameter.get("salesQuotationItem");
  436.             log.debug("\n\n Prepare Add Details (Sales Quotation Item) : "+details+" \n\n");
  437.            
  438.         } else {
  439.             log.debug("\n\n Prepare Add Else Flag From Web Pos \n\n");
  440.            
  441.             getHeader().put("extDocNo", GeneralConstants.EMPTY_VALUE);
  442.             log.debug("\n\n Prepare Add Get Header Ext Doc No : "+getHeader().get("extDocNo")+" \n\n");
  443.            
  444.             getHeader().put("extDocDate", DateUtil.dateNow());
  445.             log.debug("\n\n Prepare Add Get Header Ext Doc Date : "+getHeader().get("extDocDate")+" \n\n");
  446.            
  447.             getHeader().put("partnerId", GeneralConstants.NULL_REF_VALUE_LONG);
  448.             log.debug("\n\n Prepare Add Get Header Partner Id : "+getHeader().get("partnerId")+" \n\n");
  449.            
  450.             this.details = (List<JSONObject>) parameter.get("salesQuotationItem");
  451.             log.debug("\n\n Prepare Add Details (Sales Quotation Item) Before Config: "+details+" \n\n");
  452.             if ((this.details == null) || (this.details.isEmpty())) {
  453.                 MessageHelper.displayError("so.item.at.least.one");
  454.                 return;
  455.             }
  456.             log.debug(">>>>>>>>>>>>>>>>>>>>>>>>>>  " + details);
  457.            
  458.             this.lastLineNo = Long.valueOf(0L);
  459.             for (JSONObject item : this.details) {
  460.                 item.put("lineNo", this.lastLineNo = Long.valueOf(this.lastLineNo.longValue() + 1L));
  461.                 item.put("currCode", SalesWebConstants.DEFAULT_CURRENCY_CODE);
  462.                 item.put("sellPrice", Double.valueOf(0.0D));
  463.                 item.put("amount", Double.valueOf(0.0D));
  464.             }
  465.             log.debug("\n\n Prepare Add Details (Sales Quotation Item) After Config: "+details+" \n\n");
  466.         }
  467.            
  468.         log.debug("\n\n Prepare Add Get Header : "+getHeader()+"\n\n");
  469.         log.debug("\n\n Prepare Add Header : "+header+"\n\n");
  470.     }
  471.    
  472.     @SuppressWarnings("unchecked")
  473.     @Override
  474.     public void prepareEdit(Map<String, Object> parameter) {
  475.         log.debug("prepareEdit(Map<String, Object> parameter)");
  476.         Object id = parameter.get("id"); // From draft page
  477.         Object docId = parameter.get("docId"); // From approval page
  478.         log.debug("PARAMETER EDIT >>>>>>>>>>>>>>> " + parameter);
  479.  
  480.         if (id != null || docId != null) {
  481.             editMode = true;
  482.             header.put("id", id == null ? docId.toString() : id.toString());
  483.             loadSalesQuotation();
  484.             loadOu();
  485.             loadSalesQuotationItem();
  486.             loadSalesQuotationTC();
  487.         }
  488.         log.debug("prepare edit header >>>>>>>>>>>>>>> " + header);
  489.     }
  490.    
  491.    
  492.     @Override
  493.     public String rejectTaskName() {
  494.         return REJECT_SALES_QUOTATION;
  495.     }
  496.     @Override
  497.     public String requestChangesTaskName() {
  498.         return REQUEST_CHANGES_SALES_QUOTATION;
  499.     }
  500.     @Override
  501.     public String submitTaskName() {
  502.         return SUBMIT_SALES_QUOTATION;
  503.     }
  504.     @Override
  505.     public String updateTaskName() {
  506.         return UPDATE_SALES_QUOTATION;
  507.     }
  508.    
  509.     @SuppressWarnings("unchecked")
  510.     public void prepareAddMoreItems() {
  511.         log.debug("masuk ke prepare add more items");
  512.         filterAddMoreItems.put("productDesc", GeneralConstants.EMPTY_VALUE);
  513.         filterAddMoreItems.put("productCode", GeneralConstants.EMPTY_VALUE);
  514.         filterAddMoreItems.put("currCode", SalesWebConstants.DEFAULT_CURRENCY_CODE);
  515.         filterAddMoreItems.put("nettSellPrice", 0D);
  516.         filterAddMoreItems.put("nettAmount", 0D);
  517.         filterAddMoreItems.put("qty", 1D);
  518.         filterAddMoreItems.put("flgStock", GeneralConstants.YES);
  519.         filterAddMoreItems.put("indentDays", "0");
  520.        
  521.     }
  522.    
  523.     @SuppressWarnings("unchecked")
  524.     public void doAddMoreItems() {
  525.         log.debug("============filterAddMoreItems=============== " + filterAddMoreItems);  
  526.         log.debug("============lastLineNo=============== " + lastLineNo);
  527.  
  528.         String indentDays = filterAddMoreItems.get("indentDays").toString();
  529.         if(filterAddMoreItems.get("flgStock").equals(GeneralConstants.NO)) {
  530.             if(filterAddMoreItems.get("indentDays").equals("0")){
  531.                 RequestContext.getCurrentInstance().addCallbackParam("success", false);
  532.                 MessageHelper.displayError("erp.jleaf.erp.sls.web.indentMustBeGreaterThenZerro");
  533.                 return;
  534.             }
  535.         } else {
  536.             indentDays = "0";
  537.         }
  538.        
  539.         if(filterAddMoreItems.get("qty") == null || filterAddMoreItems.get("qty").equals(GeneralConstants.EMPTY_VALUE)){
  540.             RequestContext.getCurrentInstance().addCallbackParam("success", false);
  541.             MessageHelper.displayError("qty can not null");
  542.             return;
  543.         } else {   
  544.             RequestContext.getCurrentInstance().addCallbackParam("success", true);
  545.            
  546.             filterAddMoreItems.put("lineNo", ++lastLineNo);
  547.             filterAddMoreItems.put("productId", GeneralConstants.NULL_REF_VALUE_LONG);
  548.             filterAddMoreItems.put("productCode", filterAddMoreItems.get("productCode"));
  549.             filterAddMoreItems.put("productDesc", filterAddMoreItems.get("productDesc"));
  550.             filterAddMoreItems.put("qty", Double.valueOf(filterAddMoreItems.get("qty").toString()));
  551.             filterAddMoreItems.put("uomId", GeneralConstants.NULL_REF_VALUE_LONG);
  552.             filterAddMoreItems.put("sellPrice", Double.valueOf(filterAddMoreItems.get("nettSellPrice").toString()));
  553.             filterAddMoreItems.put("amount", (Double.valueOf(filterAddMoreItems.get("qty").toString())*Double.valueOf(filterAddMoreItems.get("nettSellPrice").toString())));
  554.             filterAddMoreItems.put("amount", (Double.valueOf(filterAddMoreItems.get("qty").toString())*Double.valueOf(filterAddMoreItems.get("nettSellPrice").toString())));
  555.             filterAddMoreItems.put("brandCode", GeneralConstants.EMPTY_VALUE);
  556.             filterAddMoreItems.put("brandName", filterAddMoreItems.get("brandName"));
  557.             filterAddMoreItems.put("remark", filterAddMoreItems.get("remark"));
  558.             filterAddMoreItems.put("flgStock", filterAddMoreItems.get("flgStock"));
  559.             filterAddMoreItems.put("indentDays", indentDays);
  560.            
  561.             log.debug("after filterAddMoreItems " + filterAddMoreItems.toString());
  562.            
  563.             if(editMode){
  564.                 log.debug("masuk ke ADD NEW Product ----------- ");
  565.                 try {
  566.                     filterAddMoreItems.put("quotationId", Long.valueOf(header.get("id").toString()));
  567.                     filterAddMoreItems.put("quotationVersion", header.get("version"));
  568.                     JSONObject output = serviceContext.executeService(ADD_PRODUCT_SALES_QUOTATION, filterAddMoreItems);
  569.                     JSONObject result = JSONObjectUtil.getResult(output);
  570.                     if (ServiceResult.isOk(output)) {
  571.                         MessageHelper.displayInfo("org.jleaf.erp.sls.web.dataSuccessSave");
  572.                         header.put("id", result.get("id"));
  573.                         loadSalesQuotation();
  574.                         loadSalesQuotationTC();
  575.                         loadSalesQuotationItem();
  576.                         loadDocumentStatus();
  577.        
  578.                     } else if (ServiceResult.isFail(output)) {
  579.                         MessageHelper.displayError(result);
  580.                         errorHolder.putError("org.jleaf.erp.sls.web", result);
  581.                     }
  582.                 } catch (Exception e) {
  583.                     log.error("Error on add sales order along with its items", e);
  584.                     MessageHelper.displayError(e.getMessage());
  585.                 }          
  586.             } else {
  587.                 log.debug("============MASUK KE DETAIL=============== " + filterAddMoreItems);
  588.                 JSONObject itemToAdd = new JSONObject();
  589.                 itemToAdd.put("lineNo", lastLineNo);
  590.                 JSONObject currency = (JSONObject) header.get("currency");
  591.                 itemToAdd.put("currCode", currency.get("code"));
  592.                 itemToAdd.put("currPropKey", currency.get("propKey"));
  593.                 itemToAdd.put("currency", currency);
  594.            
  595.                 itemToAdd.put("productCode", filterAddMoreItems.get("productCode"));
  596.                 itemToAdd.put("productDesc", filterAddMoreItems.get("productDesc"));
  597.                 itemToAdd.put("qty", filterAddMoreItems.get("qty"));
  598.                 itemToAdd.put("productId", filterAddMoreItems.get("productId") == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(filterAddMoreItems.get("productId").toString()));
  599.                 itemToAdd.put("uomId", filterAddMoreItems.get("baseUomId") == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(filterAddMoreItems.get("baseUomId").toString()));
  600.                 itemToAdd.put("uomCode", filterAddMoreItems.get("baseUomCode") == null ? GeneralConstants.EMPTY_VALUE : filterAddMoreItems.get("baseUomCode"));
  601.                 itemToAdd.put("uomName", filterAddMoreItems.get("baseUomName") == null ? GeneralConstants.EMPTY_VALUE : filterAddMoreItems.get("baseUomName"));
  602.                 itemToAdd.put("baseUomId", filterAddMoreItems.get("baseUomId") == null ? GeneralConstants.EMPTY_VALUE : filterAddMoreItems.get("baseUomId"));
  603.                 itemToAdd.put("baseUomCode", filterAddMoreItems.get("baseUomCode") == null ? GeneralConstants.EMPTY_VALUE : filterAddMoreItems.get("baseUomCode"));
  604.                 itemToAdd.put("baseUomName", filterAddMoreItems.get("baseUomName") == null ? GeneralConstants.EMPTY_VALUE : filterAddMoreItems.get("baseUomName"));
  605.                 itemToAdd.put("amount", (Double.valueOf(filterAddMoreItems.get("qty").toString())*Double.valueOf(filterAddMoreItems.get("nettSellPrice").toString())));
  606.                 itemToAdd.put("sellPrice", filterAddMoreItems.get("nettSellPrice"));
  607.                 itemToAdd.put("brandCode", filterAddMoreItems.get("brandCode"));
  608.                 itemToAdd.put("brandName", filterAddMoreItems.get("brandName"));
  609.                 itemToAdd.put("remark", filterAddMoreItems.get("remark"));
  610.                 itemToAdd.put("sellPrice", filterAddMoreItems.get("nettSellPrice"));
  611.                 itemToAdd.put("flgStock", filterAddMoreItems.get("flgStock"));
  612.                 itemToAdd.put("indentDays", indentDays);
  613.  
  614.                 details.add(itemToAdd);
  615.                 filterAddMoreItems = new JSONObject();
  616.                 log.debug("=============details============== " + details);
  617.             }
  618.         }
  619.     }
  620.    
  621.    
  622.     @SuppressWarnings("unchecked")
  623.     public void doEditItem() {
  624.         log.debug("============filterAddMoreItems=============== " + filterAddMoreItems);
  625.        
  626.         String indentDays = filterAddMoreItems.get("indentDays").toString();
  627.         if(filterAddMoreItems.get("flgStock").equals(GeneralConstants.NO)) {
  628.             if(filterAddMoreItems.get("indentDays").equals("0")){
  629.                 RequestContext.getCurrentInstance().addCallbackParam("success", false);
  630.                 MessageHelper.displayError("erp.jleaf.erp.sls.web.indentMustBeGreaterThenZerro");
  631.                 return;
  632.             }
  633.         } else {
  634.             indentDays = "0";
  635.         }
  636.        
  637.         if(filterAddMoreItems.get("qty") == null || filterAddMoreItems.get("qty").equals(GeneralConstants.EMPTY_VALUE)){
  638.             RequestContext.getCurrentInstance().addCallbackParam("success", false);
  639.             MessageHelper.displayError("qty can not null");
  640.             return;
  641.         } else {   
  642.            
  643.             if(filterAddMoreItems.get("productId").equals(GeneralConstants.NULL_REF_VALUE_LONG.toString())) {
  644.                 filterAddMoreItems.put("brandCode", GeneralConstants.EMPTY_VALUE);
  645.                 filterAddMoreItems.put("brandName", filterAddMoreItems.get("brandName"));
  646.                 filterAddMoreItems.put("productId", GeneralConstants.NULL_REF_VALUE_LONG);
  647.             } else {
  648.                 filterAddMoreItems.put("productId", Long.valueOf(filterAddMoreItems.get("productId").toString()));
  649.             }
  650.            
  651.             filterAddMoreItems.put("lineNo", ++lastLineNo);
  652.             filterAddMoreItems.put("productCode", filterAddMoreItems.get("productCode"));
  653.             filterAddMoreItems.put("productDesc", filterAddMoreItems.get("productDesc"));
  654.             filterAddMoreItems.put("qty", Double.valueOf(filterAddMoreItems.get("qty").toString()));
  655.             filterAddMoreItems.put("uomId", GeneralConstants.NULL_REF_VALUE_LONG);
  656.             filterAddMoreItems.put("sellPrice", Double.valueOf(filterAddMoreItems.get("nettSellPrice").toString()));
  657.             filterAddMoreItems.put("amount", (Double.valueOf(filterAddMoreItems.get("qty").toString())*Double.valueOf(filterAddMoreItems.get("nettSellPrice").toString())));
  658.             filterAddMoreItems.put("quotationId", Long.valueOf(header.get("id").toString()));
  659.             filterAddMoreItems.put("quotationItemId", Long.valueOf(filterAddMoreItems.get("quotationItemId").toString()));
  660.             filterAddMoreItems.put("version", filterAddMoreItems.get("version"));
  661.             filterAddMoreItems.put("quotationVersion", header.get("version"));
  662.             filterAddMoreItems.put("remark", filterAddMoreItems.get("remark"));
  663.             filterAddMoreItems.put("flgStock", filterAddMoreItems.get("flgStock"));
  664.             filterAddMoreItems.put("indentDays", indentDays);
  665.  
  666.             RequestContext.getCurrentInstance().addCallbackParam("success", true);
  667.            
  668.             log.debug("============SERVICE EDIT_PRODUCT_SALES_QUOTATION=============== " + filterAddMoreItems);
  669.             try {
  670.                 JSONObject output = serviceContext.executeService(EDIT_PRODUCT_SALES_QUOTATION, filterAddMoreItems);
  671.                 JSONObject result = JSONObjectUtil.getResult(output);
  672.                 if (ServiceResult.isOk(output)) {
  673.                     MessageHelper.displayInfo("org.jleaf.erp.sls.web.dataSuccessSave");
  674.                     loadSalesQuotation();
  675.                     loadSalesQuotationTC();
  676.                     loadSalesQuotationItem();
  677.    
  678.                     filterAddMoreItems = new JSONObject();
  679.                 } else if (ServiceResult.isFail(output)) {
  680.                     MessageHelper.displayError(result);
  681.                     errorHolder.putError("org.jleaf.erp.sls.web", result);
  682.                 }
  683.             } catch (Exception e) {
  684.                 log.error("Error on add sales order along with its items", e);
  685.                 MessageHelper.displayError(e.getMessage());
  686.             }
  687.         }
  688.     }
  689.  
  690.    
  691.    
  692.     @SuppressWarnings("unchecked")
  693.     public void addProductExisting(JSONObject addItem) {
  694.         JSONObject item = new JSONObject();
  695.         item = (JSONObject) addItem.clone();
  696.         log.debug("============item=============== " + item);
  697.  
  698.         String indentDays = "0";
  699.         String flgStock = GeneralConstants.YES;
  700.         if(item.get("qty").toString().equals("0")) {
  701.             flgStock = GeneralConstants.NO;
  702.         }
  703.        
  704.         if(editMode){
  705.            
  706.             item.put("quotationId", Long.valueOf(header.get("id").toString()));
  707.             item.put("lineNo", ++lastLineNo);
  708.             item.put("productId", item.get("productId"));
  709.             item.put("productDesc", item.get("productName"));
  710.             item.put("productCode", item.get("productCode"));
  711.             item.put("qty", 1D);
  712.             item.put("amount", 0D);
  713.             item.put("uomId", item.get("baseUomId"));
  714.             item.put("sellPrice", 0D);
  715.             item.put("quotationVersion", Long.valueOf(header.get("version").toString()));
  716.             item.put("brandCode", GeneralConstants.EMPTY_VALUE);
  717.             item.put("brandName", GeneralConstants.EMPTY_VALUE);
  718.             item.put("remark", GeneralConstants.EMPTY_VALUE);
  719.             item.put("indentDays", indentDays);
  720.             item.put("flgStock", flgStock);
  721.            
  722.             try {
  723.                 JSONObject output = this.serviceContext.executeService(ADD_PRODUCT_SALES_QUOTATION, item);
  724.                 JSONObject result = JSONObjectUtil.getResult(output);
  725.                 if (ServiceResult.isOk(output)) {
  726.                     MessageHelper.displayInfo("org.jleaf.erp.sls.web.dataSuccessSave");
  727.                     header.put("id", result.get("id"));
  728.                     filterAddMoreItems = new JSONObject();
  729.                    
  730.                     loadSalesQuotation();
  731.                     loadSalesQuotationTC();
  732.                     loadSalesQuotationItem();
  733.                     loadDocumentStatus();
  734.                 } else if (ServiceResult.isFail(output)) {
  735.                     MessageHelper.displayError(result);
  736.                 }
  737.             } catch (Exception e) {
  738.                 e.printStackTrace();
  739.                 MessageHelper.displayError(e.getMessage());
  740.             }
  741.         } else {
  742.             JSONObject itemToAdd = new JSONObject();
  743.             itemToAdd.put("lineNo", ++lastLineNo);
  744.            
  745.             itemToAdd.put("currCode", SalesWebConstants.DEFAULT_CURRENCY_CODE);
  746.             itemToAdd.put("sellPrice", 0D);
  747.             itemToAdd.put("amount", 0D);
  748.    
  749.             itemToAdd.put("productCode", item.get("productCode"));
  750.             itemToAdd.put("productDesc", item.get("productName"));
  751.             itemToAdd.put("qty", 1D);
  752.             itemToAdd.put("productId", item.get("productId") == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(item.get("productId").toString()));
  753.             itemToAdd.put("uomId", item.get("baseUomId") == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(item.get("baseUomId").toString()));
  754.        
  755.             itemToAdd.put("uomCode", item.get("baseUomCode") == null ? GeneralConstants.EMPTY_VALUE : item.get("baseUomCode"));
  756.             itemToAdd.put("uomName", item.get("baseUomName") == null ? GeneralConstants.EMPTY_VALUE : item.get("baseUomName"));
  757.             itemToAdd.put("baseUomId", item.get("baseUomId") == null ? GeneralConstants.EMPTY_VALUE : item.get("baseUomId"));
  758.             itemToAdd.put("baseUomCode", item.get("baseUomCode") == null ? GeneralConstants.EMPTY_VALUE : item.get("baseUomCode"));
  759.             itemToAdd.put("baseUomName", item.get("baseUomName") == null ? GeneralConstants.EMPTY_VALUE : item.get("baseUomName"));
  760.             itemToAdd.put("brandCode", GeneralConstants.EMPTY_VALUE);
  761.             itemToAdd.put("brandName", GeneralConstants.EMPTY_VALUE);
  762.             itemToAdd.put("remark", GeneralConstants.EMPTY_VALUE);
  763.             itemToAdd.put("indentDays", indentDays);
  764.             itemToAdd.put("flgStock", flgStock);
  765.            
  766.             details.add(itemToAdd);
  767.             filterAddMoreItems = new JSONObject();
  768.             log.debug("=============details============== " + details);
  769.         }
  770.     }
  771.    
  772.    
  773.     @SuppressWarnings("unchecked")
  774.     public void doAddTCItems() {
  775.         log.debug("============filterAddMoreItems=============== " + filterAddMoreItems);  
  776.         log.debug("============lastLineNo=============== " + lastLineNo);
  777.         JSONObject newTC = new JSONObject();
  778.         newTC.put("lineNo", ++lastLineNo);
  779.         newTC.put("termCondition", filterAddMoreItems.get("termCondition"));
  780.         newTC.put("quotationId", Long.valueOf(header.get("id").toString()));
  781.         newTC.put("quotationVersion", Long.valueOf(header.get("version").toString()));
  782.         log.debug("============SERVICE ADD_TERMS_AND_CONDITION_SALES_QUOTATION=============== " + newTC);
  783.         try {
  784.             JSONObject output = serviceContext.executeService(ADD_TERMS_AND_CONDITION_SALES_QUOTATION, newTC);
  785.             JSONObject result = JSONObjectUtil.getResult(output);
  786.             if (ServiceResult.isOk(output)) {
  787.                 MessageHelper.displayInfo("org.jleaf.erp.sls.web.dataSuccessSave");
  788.                 header.put("id", result.get("id"));
  789.                
  790.                 loadSalesQuotation();
  791.                 loadSalesQuotationTC();
  792.                 loadSalesQuotationItem();
  793.                 loadDocumentStatus();
  794.  
  795.                 filterAddMoreItems = new JSONObject();
  796.                
  797.             } else if (ServiceResult.isFail(output)) {
  798.                 MessageHelper.displayError(result);
  799.                 errorHolder.putError("org.jleaf.erp.sls.web", result);
  800.             }
  801.         } catch (Exception e) {
  802.             log.error("Error on add sales order along with its items", e);
  803.             MessageHelper.displayError(e.getMessage());
  804.         }
  805.     }
  806.    
  807.  
  808.     @SuppressWarnings("unchecked")
  809.     public void prepareEditItem(JSONObject editedItem) {
  810.         log.debug("Prepare edit item : " + editedItem);
  811.         filterAddMoreItems.clear();
  812.  
  813.         log.debug("resultProduct " + editedItem.get("productId"));
  814.        
  815.         if(!editedItem.get("productId").equals(GeneralConstants.NULL_REF_VALUE_LONG.toString())) {
  816.             filterAddMoreItems.put("brandCode", editedItem.get("code"));
  817.             filterAddMoreItems.put("brandName", editedItem.get("name"));
  818.         } else {
  819.             filterAddMoreItems.put("brandCode", editedItem.get("brandCode"));
  820.             filterAddMoreItems.put("brandName", editedItem.get("brandName"));
  821.         }
  822.  
  823.         filterAddMoreItems.put("quotationItemId", editedItem.get("quotationItemId"));
  824.         filterAddMoreItems.put("quotationId", editedItem.get("quotationId"));
  825.         filterAddMoreItems.put("lineNo", editedItem.get("lineNo"));
  826.         filterAddMoreItems.put("productId", editedItem.get("productId"));
  827.         filterAddMoreItems.put("productDesc", editedItem.get("productDesc"));
  828.         filterAddMoreItems.put("productCode", editedItem.get("productCode"));
  829.         filterAddMoreItems.put("qty", editedItem.get("qty"));
  830.         filterAddMoreItems.put("nettSellPrice", editedItem.get("sellPrice"));
  831.         filterAddMoreItems.put("currCode", header.get("currCode"));
  832.         filterAddMoreItems.put("nettAmount", editedItem.get("amount"));
  833.         filterAddMoreItems.put("remark", editedItem.get("remark"));
  834.         filterAddMoreItems.put("version", editedItem.get("version"));
  835.         filterAddMoreItems.put("flgStock", editedItem.get("flgStock"));
  836.         filterAddMoreItems.put("indentDays", editedItem.get("indentDays"));
  837.        
  838.     }
  839.    
  840.     public void prepareRemoveItem(JSONObject removedItem) {
  841.         this.setItemToBeDeleted(((JSONObject) removedItem.clone()));
  842.     }
  843.    
  844.     @SuppressWarnings("unchecked")
  845.     public void doRemoveItem() {
  846.         log.debug("================ " + this.itemToBeDeleted);
  847.         log.debug("================ " + this.details);
  848.         if ((this.itemToBeDeleted.get("quotationItemId") == null) || (this.itemToBeDeleted.get("quotationItemId").toString().equals(GeneralConstants.NULL_REF_VALUE_LONG.toString()))) {
  849.             log.debug("=======MASUK KE REMOVE  DETAIL TANPA SERVICE========= " + this.details);
  850.             this.details.remove(this.itemToBeDeleted);
  851.             this.itemToBeDeleted = new JSONObject();
  852.         } else {
  853.             log.debug("=======MASUK KE REMOVE  DETAIL PAKAI SERVICE========= ");
  854.             JSONObject input = new JSONObject();
  855.             input.put("quotationItemId", Long.valueOf(this.itemToBeDeleted.get("quotationItemId").toString()));
  856.             input.put("quotationId", Long.valueOf(this.header.get("id").toString()));
  857.             input.put("quotationVersion", Long.valueOf(this.header.get("version").toString()));
  858.             try {
  859.                 JSONObject output = this.serviceContext.executeService(REMOVE_PRODUCT_SALES_QUOTATION, input);
  860.                 JSONObject result = JSONObjectUtil.getResult(output);
  861.                 if (ServiceResult.isOk(output)) {
  862.                     MessageHelper.displayInfo("org.jleaf.erp.sls.web.dataHasBeenRemoved");
  863.                     loadSalesQuotation();
  864.                     loadSalesQuotationItem();
  865.                     loadSalesQuotationTC();
  866.                 } else if (ServiceResult.isFail(output)) {
  867.                     MessageHelper.displayError(result);
  868.                 }
  869.             } catch (Exception e) {
  870.                 log.error("Error on remove sales order item", e);
  871.                 MessageHelper.displayError(e.getMessage());
  872.             }
  873.         }
  874.     }
  875.    
  876.    
  877.     @SuppressWarnings("unchecked")
  878.     public void doRemoveTc() {
  879.         log.debug("================ " + this.itemToBeDeleted);
  880.         JSONObject input = new JSONObject();
  881.         input.put("quotationTcId", Long.valueOf(this.itemToBeDeleted.get("quotationTcId").toString()));
  882.         input.put("quotationId", Long.valueOf(this.header.get("id").toString()));
  883.         input.put("quotationVersion", Long.valueOf(this.header.get("version").toString()));
  884.         try {
  885.             JSONObject output = this.serviceContext.executeService(REMOVE_TERMS_AND_CONDITION_SALES_QUOTATION, input);
  886.             JSONObject result = JSONObjectUtil.getResult(output);
  887.             if (ServiceResult.isOk(output)) {
  888.                 MessageHelper.displayInfo("org.jleaf.erp.sls.web.dataHasBeenRemoved");
  889.                 loadSalesQuotation();
  890.                 loadOu();
  891.                 loadSalesQuotationItem();
  892.                 loadSalesQuotationTC();
  893.             } else if (ServiceResult.isFail(output)) {
  894.                 MessageHelper.displayError(result);
  895.             }
  896.         } catch (Exception e) {
  897.             log.error("Error on remove sales order item", e);
  898.             MessageHelper.displayError(e.getMessage());
  899.         }  
  900.     }
  901.    
  902.    
  903.     @SuppressWarnings("unchecked")
  904.     public void onCurrencyChanged(AjaxBehaviorEvent e) {
  905.         if (details != null && details.size() > 0) {
  906.             for (JSONObject item : details) {
  907.                 item.put("currCode", ((JSONObject) header.get("currency")).get("code"));
  908.                 log.info("jalan for nya currency code nih . . . . . . . . . . . . . . . " + item.toString());
  909.             }
  910.         }
  911.         header.put("currCode", ((JSONObject) header.get("currency")).get("code"));
  912.     }
  913.  
  914.    
  915.     @SuppressWarnings("unchecked")
  916.     public void doSearchProduct(){     
  917.         JSONObject jsonInput = new JSONObject();
  918.  
  919.         JSONObject subCtgrProduct = (JSONObject) dataProduct.get("subCtgrProduct");
  920.  
  921.         jsonInput.put("ouId", header.get("ouId"));
  922.         jsonInput.put("subCtgrProductId", subCtgrProduct == null ? GeneralConstants.NULL_REF_VALUE_LONG : subCtgrProduct.get("id"));
  923.         jsonInput.put("productCodeName", dataProduct.get("productCodeName"));
  924.         jsonInput.put("brandCodeName", dataProduct.get("brandCodeName"));
  925.         jsonInput.put("active", GeneralConstants.YES);
  926.  
  927.         try {
  928.             JSONObject output = serviceContext.executeService(COUNT_GET_AUTHORIZED_PRODUCT_BALANCE_STOCK_LIST_FOR_SALES_ORDER, jsonInput);
  929.             JSONObject result = JSONObjectUtil.getResult(output);
  930.             if (ServiceResult.isOk(output)) {
  931.                 Long rowCount = Long.valueOf(result.get("count").toString());
  932.                 model = new ProductLazyModel(serviceContext, jsonInput);
  933.                 model.setRowCount(rowCount.intValue());
  934.                 model.setPageSize(25);         
  935.                
  936.                 MessageHelper.displayLoadSuccess();
  937.             } else if (ServiceResult.isFail(output)) {
  938.                 MessageHelper.displayError(result);
  939.             }
  940.         } catch (Exception ex) {
  941.             log.error(ex.getMessage(), ex);
  942.             MessageHelper.displayError(ex.getMessage());
  943.         }
  944.     }
  945.    
  946.    
  947.     @SuppressWarnings("unchecked")
  948.     public void doSearchPartner(){     
  949.         JSONObject jsonInput = new JSONObject();
  950.         log.debug("=============dataPartner==================== " + dataPartner);
  951.         jsonInput.put("keyword", (dataPartner == null ? GeneralConstants.EMPTY_VALUE : dataPartner));
  952.         jsonInput.put("ctgrPartnerId", GeneralConstants.NULL_REF_VALUE_LONG);
  953.  
  954.         try {
  955.             JSONObject output = serviceContext.executeService(GET_AUTHORIZED_CUSTOMER_LIST_ADVANCE, jsonInput);
  956.             JSONObject result = JSONObjectUtil.getResult(output);
  957.             if (ServiceResult.isOk(output)) {
  958.                 log.debug("----------------------- " + result);
  959.                 this.setPartnerList(ServiceResult.toArray(result.get("customerList")));
  960.  
  961.             } else if (ServiceResult.isFail(output)) {
  962.                 MessageHelper.displayError(result);
  963.             }
  964.         } catch (Exception e) {
  965.             log.error("Error on load term condition sales quotation", e);
  966.             MessageHelper.displayError(e.getMessage());
  967.         }
  968.     }
  969.    
  970.    
  971.     @SuppressWarnings("unchecked")
  972.     public void doSearchPartnerCP(){       
  973.         JSONObject jsonInput = new JSONObject();
  974.         jsonInput.put("partnerId", (header.get("partnerId") == null ? GeneralConstants.NULL_REF_VALUE_LONG : header.get("partnerId")));
  975.         jsonInput.put("active", (header.get("activePartner") == null ? GeneralConstants.YES : header.get("activePartner")));
  976.  
  977.         try {
  978.             JSONObject output = serviceContext.executeService(GET_PARTNER_CP_LIST_BY_PARTNER, jsonInput);
  979.             JSONObject result = JSONObjectUtil.getResult(output);
  980.             if (ServiceResult.isOk(output)) {
  981.                 log.debug("----------------------- " + result);
  982.                 this.setCpList(ServiceResult.toArray(result.get("contactPersonList")));
  983.  
  984.             } else if (ServiceResult.isFail(output)) {
  985.                 MessageHelper.displayError(result);
  986.             }
  987.         } catch (Exception e) {
  988.             log.error("Error on load term condition sales quotation", e);
  989.             MessageHelper.displayError(e.getMessage());
  990.         }
  991.     }
  992.    
  993.    
  994.     @SuppressWarnings("unchecked")
  995.     public void loadPartnerAddress(){      
  996.         JSONObject jsonInput = new JSONObject();
  997.         jsonInput.put("partnerId", (header.get("partnerId") == null ? GeneralConstants.NULL_REF_VALUE_LONG : header.get("partnerId")));
  998.         jsonInput.put("active", (header.get("activePartner") == null ? GeneralConstants.YES : header.get("activePartner")));
  999.  
  1000.         try {
  1001.             JSONObject output = serviceContext.executeService(GET_PARTNER_ADDRESS_LIST, jsonInput);
  1002.             JSONObject result = JSONObjectUtil.getResult(output);
  1003.             if (ServiceResult.isOk(output)) {
  1004.                 this.setPartnerAddressList(ServiceResult.toArray(result.get("addressList")));
  1005.                 log.debug("-----------loadPartnerAddress------------ " + partnerAddressList);
  1006.  
  1007.             } else if (ServiceResult.isFail(output)) {
  1008.                 MessageHelper.displayError(result);
  1009.             }
  1010.         } catch (Exception e) {
  1011.             log.error("Error on load partner address sales quotation", e);
  1012.             MessageHelper.displayError(e.getMessage());
  1013.         }
  1014.     }
  1015.    
  1016.     @SuppressWarnings("unchecked")
  1017.     public void clearPartner(){
  1018.         header.put("partnerId", GeneralConstants.NULL_REF_VALUE_LONG);
  1019.         header.remove("activePartner");
  1020.         header.remove("partnerCode");
  1021.         header.remove("partnerName");
  1022.         clearPartnerCp();
  1023.         clearPartnerAddress();
  1024.     }
  1025.    
  1026.     @SuppressWarnings("unchecked")
  1027.     public void clearPartnerCp(){
  1028.         header.put("partnerCpId", GeneralConstants.NULL_REF_VALUE_LONG);
  1029.         header.remove("partnerCpName");
  1030.         header.remove("partnerCpPhone1");
  1031.         header.remove("partnerCpPhone2");
  1032.         header.remove("partnerCpFax1");
  1033.         header.remove("partnerCpFax2");
  1034.         header.remove("partnerCpEmail");
  1035.         header.remove("partnerCpMobilePhone1");
  1036.         header.remove("partnerCpMobilePhone2");
  1037.     }  
  1038.    
  1039.     @SuppressWarnings("unchecked")
  1040.     public void clearPartnerAddress(){
  1041.         header.put("partnerAddressId", GeneralConstants.NULL_REF_VALUE_LONG);
  1042.         header.remove("partnerAddress1");
  1043.         header.remove("partnerAddress2");
  1044.         header.remove("partnerAddress3");
  1045.     }  
  1046.    
  1047.     @SuppressWarnings("unchecked")
  1048.     public void chooseCustomer(JSONObject addItem) {
  1049.         JSONObject item = new JSONObject();
  1050.         item = (JSONObject) addItem.clone();
  1051.         log.debug("============item=============== " + item);
  1052.             header.put("partnerId", item.get("id"));
  1053.             header.put("activePartner", item.get("active"));
  1054.             header.put("partnerId", item.get("id"));
  1055.             header.put("partnerName", item.get("name"));
  1056.             header.put("partnerCode", item.get("code"));       
  1057.  
  1058.             clearPartnerCp();
  1059.             clearPartnerAddress();
  1060.            
  1061.             log.debug("=============header partner============== " + header);
  1062.     }
  1063.    
  1064.    
  1065.     @SuppressWarnings("unchecked")
  1066.     public void chooseCustomerCP(JSONObject addItem) {
  1067.         JSONObject item = new JSONObject();
  1068.         item = (JSONObject) addItem.clone();
  1069.        
  1070.         log.debug("============ITEM=============== " + item);
  1071.         header.put("partnerCpId", item.get("id"));
  1072.         header.put("partnerCpName", item.get("cpName") == null ? GeneralConstants.EMPTY_VALUE : item.get("cpName"));
  1073.         header.put("partnerCpPhone1", item.get("phone1") == null ? GeneralConstants.EMPTY_VALUE : item.get("phone1"));
  1074.         header.put("partnerCpPhone2", item.get("phone2") == null ? GeneralConstants.EMPTY_VALUE : item.get("phone2"));
  1075.         header.put("partnerCpFax1", item.get("fax1") == null ? GeneralConstants.EMPTY_VALUE : item.get("fax1"));
  1076.         header.put("partnerCpFax2", item.get("fax2") == null ? GeneralConstants.EMPTY_VALUE : item.get("fax2"));
  1077.         header.put("partnerCpEmail", item.get("email") == null ? GeneralConstants.EMPTY_VALUE : item.get("email"));
  1078.         header.put("partnerCpMobilePhone1", item.get("mobilePhone1") == null ? GeneralConstants.EMPTY_VALUE : item.get("mobilePhone1"));
  1079.         header.put("partnerCpMobilePhone2", item.get("mobilePhone2") == null ? GeneralConstants.EMPTY_VALUE : item.get("mobilePhone2"));
  1080.         log.debug("=============header inputPartnerCp============== " + header);
  1081.     }  
  1082.    
  1083.    
  1084.     @SuppressWarnings("unchecked")
  1085.     public void chooseCustomerAddress(JSONObject addItem) {
  1086.         JSONObject item = new JSONObject();
  1087.         item = (JSONObject) addItem.clone();
  1088.         log.debug("============item=============== " + item);
  1089.        
  1090.         header.put("partnerAddressId", item.get("partnerAddressId") == null ? GeneralConstants.NULL_REF_VALUE_LONG : Long.valueOf(item.get("partnerAddressId").toString()));
  1091.         header.put("partnerAddress1", item.get("address1") == null ? GeneralConstants.EMPTY_VALUE : item.get("address1"));
  1092.         header.put("partnerAddress2", item.get("address2") == null ? GeneralConstants.EMPTY_VALUE : item.get("address2"));
  1093.         header.put("partnerAddress3", item.get("address3") == null ? GeneralConstants.EMPTY_VALUE : item.get("address3"));
  1094.             log.debug("=============header partner============== " + header);
  1095.     }
  1096.  
  1097.     ///////////////////////////////////////////////////////////////// LOAD //////////////////////////////////////////////////////////
  1098.    
  1099.     @SuppressWarnings("unchecked")
  1100.     private void loadOu() {
  1101.         log.debug("\n\n LOAD OU \n\n");
  1102.         JSONObject input = new JSONObject();
  1103.         input.put("id", header.get("ouId"));
  1104.         log.debug("\n\n Load Ou Input : "+input+" \n\n");
  1105.         try {
  1106.             JSONObject output = serviceContext.executeService(FIND_OU_BY_ID, input);
  1107.             log.debug("\n\n Load Ou Output Find Ou By Id : "+output+" \n\n");
  1108.            
  1109.             JSONObject result = JSONObjectUtil.getResult(output);
  1110.             log.debug("\n\n Load Ou Result Find Ou By Id : "+result+" \n\n");
  1111.            
  1112.             String status = JSONObjectUtil.getResultStatus(output);
  1113.             log.debug("\n\n Load Ou Result Status : "+status+" \n\n");
  1114.            
  1115.             log.debug("result load OU : " + output);
  1116.             if (status != null && status.equals(GeneralConstants.OK)) {
  1117.                 log.debug("\n\n Load Ou If Status Is OK or Not Equals Null \n\n");
  1118.                                
  1119.                
  1120.                
  1121.                 header.put("ouCode", result.get("code"));
  1122.                 log.debug("\n\n Load Ou Header Ou Code : "+header.get("ouCode")+" \n\n");
  1123.                
  1124.                 header.put("ouName", result.get("name"));
  1125.                 log.debug("\n\n Load Ou Header Ou Name : "+header.get("ouName")+" \n\n");
  1126.                
  1127.                 if(result.get("flgPkp").equals(GeneralConstants.YES)){
  1128.                     log.debug("\n\n Load Ou If Flag Pkp Equals Yes \n\n");
  1129.                    
  1130.                     header.put("flgPkp", result.get("flgPkp"));
  1131.                     log.debug("\n\n Load Ou Header Flag Pkp : "+header.get("flgPkp")+" \n\n");
  1132.                    
  1133.                     this.taxList = this.combo.getTaxListAdvance();
  1134.                     log.debug("\n\n Load Ou Tax List : "+this.taxList+" \n\n");
  1135.  
  1136.                     String taxId = GeneralConstants.NULL_REF_VALUE_LONG.toString();                
  1137.                     log.debug("\n\n Load Ou Tax Id Before Set: "+taxId+" \n\n");
  1138.                    
  1139.                     if(taxList != null || !taxList.isEmpty()){
  1140.                         log.debug("\n\n Load Ou If Tax List Not Null Or Not Empty \n\n");
  1141.                        
  1142.                         taxId = taxList.get(0).get("id").toString();
  1143.                         log.debug("\n\n Load Ou Tax Id : "+taxId+" \n\n");
  1144.                     }
  1145.                    
  1146.                     log.debug("\n\n Load Ou Tax Id After Set: "+taxId+" \n\n");
  1147.                    
  1148.                     header.put("tax", new ComboItem("id", taxId));
  1149.                     log.debug("\n\n Load Ou Header Tax : "+header.get("tax")+" \n\n");
  1150.                    
  1151.                     header.put("flgTax", GeneralConstants.YES);
  1152.                     log.debug("\n\n Load Ou Header Flag Tax : "+header.get("flgTax")+" \n\n");
  1153.                 } else {
  1154.                     log.debug("\n\n Load Ou Else Flag Pkp \n\n");
  1155.                    
  1156.                     header.put("flgPkp", GeneralConstants.NO);
  1157.                     log.debug("\n\n Load Ou Header Flag Pkp : "+header.get("flgPkp")+" \n\n");
  1158.                    
  1159.                     header.put("tax", new ComboItem("id", GeneralConstants.NULL_REF_VALUE_LONG));
  1160.                     log.debug("\n\n Load Ou Header Tax : "+header.get("tax")+" \n\n");
  1161.                    
  1162.                     header.put("flgTax", GeneralConstants.NO);
  1163.                     log.debug("\n\n Load Ou Header Flag Tax : "+header.get("flgTax")+" \n\n");
  1164.                 }
  1165.                
  1166.             } else if (status != null && status.equals(GeneralConstants.FAIL)) {
  1167.                 FacesUtils.addErrorMessage(MessageUtil.getInstance().getLabel((String) result.get("errorKey"), result.get("args")));
  1168.             }
  1169.         } catch (Exception e) {
  1170.             log.error("Error on load OU", e);
  1171.             FacesUtils.addErrorMessage(e.getMessage());
  1172.         }
  1173.         log.debug("\n\n END LOAD OU :" + header + "\n\n");
  1174.     }
  1175.    
  1176.    
  1177.     @SuppressWarnings("unchecked")
  1178.     private void loadSalesQuotationTC() {
  1179.         if (this.header.get("id") == null) {
  1180.  
  1181.         } else {
  1182.             JSONObject input = new JSONObject();
  1183.             input.put("quotationId", this.header.get("id"));
  1184.             try {
  1185.                 JSONObject output = this.serviceContext.executeService(GET_TERMS_AND_CONDITION_SALES_QUOTATION_ITEM_LIST_BY_SALES_QUOTATION, input);
  1186.                 JSONObject result = JSONObjectUtil.getResult(output);
  1187.                 if (ServiceResult.isOk(output)) {
  1188.                     this.setTcList(ServiceResult.toArray(result.get("termsAndConditionList")));
  1189.  
  1190.                 } else if (ServiceResult.isFail(output)) {
  1191.                     MessageHelper.displayError(result);
  1192.                 }
  1193.             } catch (Exception e) {
  1194.                 log.error("Error on load term condition sales quotation", e);
  1195.                 MessageHelper.displayError(e.getMessage());
  1196.             }
  1197.         }
  1198.     }
  1199.    
  1200.     @SuppressWarnings("unchecked")
  1201.     private void loadSalesQuotationItem() {
  1202.         if (this.header.get("id") == null) {
  1203.  
  1204.         } else {
  1205.             JSONObject input = new JSONObject();
  1206.             input.put("quotationId", this.header.get("id"));
  1207.             try {
  1208.                 JSONObject output = this.serviceContext.executeService(GET_SALES_QUOTATION_ITEM_LIST_BY_SALES_QUOTATION, input);
  1209.                 JSONObject result = JSONObjectUtil.getResult(output);
  1210.                 if (ServiceResult.isOk(output)) {
  1211.                     log.debug("loadSalesQuotationItem() result : " + result);
  1212.                    
  1213.                     details = ServiceResult.toArray(result.get("salesQuotationItemList"));
  1214.                     for (JSONObject item : this.details) {
  1215.                         item.put("currCode", header.get("currCode"));
  1216.                     }
  1217.                     log.debug("isi details " + details);
  1218.                 } else if (ServiceResult.isFail(output)) {
  1219.                     MessageHelper.displayError(result);
  1220.                 }
  1221.             } catch (Exception e) {
  1222.                 log.error("Error on load term condition sales quotation", e);
  1223.                 MessageHelper.displayError(e.getMessage());
  1224.             }
  1225.         }
  1226.     }
  1227.    
  1228.    
  1229.     @SuppressWarnings("unchecked")
  1230.     private void loadSalesQuotation() {
  1231.         if (this.header.get("id") == null) {
  1232.             this.header.put("docNo", "");
  1233.             this.header.put("docDate", DateUtil.dateNow());
  1234.             this.header.put("extDocNo", "");
  1235.             this.header.put("extDocDate", DateUtil.dateNow());
  1236.             this.header.put("remark", "");
  1237.             this.header.put("flgTax", "N");
  1238.             this.header.put("currCode", "");
  1239.  
  1240.         } else {
  1241.             JSONObject input = new JSONObject();
  1242.             input.put("id", this.header.get("id"));
  1243.  
  1244.             List<JSONObject> taxList = this.combo.getTaxListAdvance();
  1245.            
  1246.             try {
  1247.                 JSONObject output = this.serviceContext.executeService(FIND_SALES_QUOTATION_BY_ID, input);
  1248.                 JSONObject result = JSONObjectUtil.getResult(output);
  1249.                 if (ServiceResult.isOk(output)) {
  1250.                     log.debug("isi outputtt ==========>>>>>>>>>>  " + output);
  1251.                     header = result;
  1252.                    
  1253.                     header.put("id", Long.valueOf(header.get("id").toString()));
  1254.                     header.put("version", Long.valueOf(header.get("version").toString()));
  1255.                     header.put("ouId", Long.valueOf(header.get("ouId").toString()));
  1256.                     header.put("currency", new ComboItem("code", header.get("currCode")));
  1257.                     header.put("flgTax", header.get("flgTaxAmount"));  
  1258.                     header.put("refId", Long.valueOf(result.get("refId").toString()));
  1259.                     header.put("flgFromWebpos",result.get("flgFromWebpos") != null ? result.get("flgFromWebpos").toString() : GeneralConstants.NO);
  1260.                    
  1261.                     if(taxList != null && !taxList.isEmpty()){
  1262.                         for(JSONObject tax : taxList){
  1263.                             if(tax.get("id").equals(header.get("taxId"))){
  1264.                                 header.put("tax", tax);
  1265.                                 break;
  1266.                             }
  1267.                         }
  1268.                     }
  1269.                    
  1270.                     loadSalesman(Long.valueOf(header.get("salesmanId").toString()));
  1271.                     loadCustomer(Long.valueOf(header.get("partnerId").toString()));
  1272.                     loadOu();
  1273.                     loadSalesQuotationFromRevision(Long.valueOf(result.get("refId").toString()));
  1274.                    
  1275.                     editMode = true;
  1276.                     super.loadDocumentStatus();
  1277.                 } else if (ServiceResult.isFail(output)) {
  1278.                     MessageHelper.displayError(result);
  1279.                 }
  1280.             } catch (Exception e) {
  1281.                 log.error("Error on load sales order", e);
  1282.                 MessageHelper.displayError(e.getMessage());
  1283.             }
  1284.         }
  1285.     }
  1286.  
  1287.     @SuppressWarnings("unchecked")
  1288.     private void loadSalesQuotationFromRevision(Long refIdQuotation) {
  1289.  
  1290.         header.put("refDocNo", GeneralConstants.EMPTY_VALUE);
  1291.         header.put("refDocDate", GeneralConstants.EMPTY_VALUE);
  1292.         if(!GeneralConstants.NULL_REF_VALUE_LONG.equals(refIdQuotation)) {
  1293.            
  1294.             try {
  1295.                
  1296.                 JSONObject jsonInput = new JSONObject();
  1297.                 jsonInput.put("id", refIdQuotation);
  1298.                
  1299.                 JSONObject output = serviceContext.executeService(FIND_SALES_QUOTATION_BY_ID, jsonInput);
  1300.                 JSONObject result = JSONObjectUtil.getResult(output);
  1301.                
  1302.                 if(ServiceResult.isOk(output)) {
  1303.                     header.put("refDocNo", result.get("docNo"));
  1304.                     header.put("refDocDate", result.get("docDate"));
  1305.                    
  1306.                 } else if(ServiceResult.isFail(output)) {
  1307.                     MessageHelper.displayError(result);
  1308.                 }
  1309.                
  1310.                
  1311.             } catch(Exception e) {
  1312.                 MessageHelper.displayError(e.getMessage());
  1313.             }
  1314.            
  1315.         }
  1316.        
  1317.     }
  1318.    
  1319.     @SuppressWarnings("unchecked")
  1320.     private void loadSalesman(Long salesmanId) {
  1321.         log.debug("load salesman. Salesman ID: " + salesmanId);
  1322.         log.debug("Current header: " + header);
  1323.  
  1324.         if (header.get("salesman") == null && header.get("salesmanId") != null
  1325.                 && !GeneralConstants.NULL_REF_VALUE_LONG.equals(Long.valueOf(header.get("salesmanId").toString()))) {
  1326.  
  1327.             JSONObject input = new JSONObject();
  1328.             input.put("id", header.get("salesmanId"));
  1329.             try {
  1330.                 JSONObject output = serviceContext.executeService(FIND_PARTNER_BY_ID, input);
  1331.                 JSONObject result = JSONObjectUtil.getResult(output);
  1332.                 String status = JSONObjectUtil.getResultStatus(output);
  1333.                 if (status != null && status.equals(GeneralConstants.OK)) {
  1334.                     ComboItem temp = new ComboItem("id");
  1335.                     temp.put("id", result.get("id"));
  1336.                     temp.put("code", result.get("code"));
  1337.                     temp.put("name", result.get("name"));
  1338.                     header.put("salesman", temp);
  1339.  
  1340.                 } else if (status != null && status.equals(GeneralConstants.FAIL)) {
  1341.                     FacesUtils.addErrorMessage(MessageUtil.getInstance().getLabel((String) result.get("errorKey"), result.get("args")));
  1342.                 }
  1343.             } catch (Exception e) {
  1344.                 log.error("Error on load salesman", e);
  1345.                 FacesUtils.addErrorMessage(e.getMessage());
  1346.             }
  1347.         }
  1348.     }
  1349.    
  1350.     @SuppressWarnings("unchecked")
  1351.     private void loadCustomer(Long partnerId) {
  1352.         log.debug("\n\n Load Customer \n\n");
  1353.        
  1354.         if (header.get("partnerId") != null && !GeneralConstants.NULL_REF_VALUE_LONG.equals(Long.valueOf(header.get("partnerId").toString()))) {
  1355.             log.debug("\n\n Load Customer If Header Partner Not Null Or Empty Id \n\n");
  1356.  
  1357.             JSONObject input = new JSONObject();
  1358.             input.put("id", header.get("partnerId"));
  1359.             log.debug("\n\n Load Customer Input "+input+" \n\n");
  1360.             try {
  1361.                 JSONObject output = serviceContext.executeService(FIND_PARTNER_BY_ID, input);
  1362.                 log.debug("\n\n Load Customer Output Service Find Partner By Id : "+output+" \n\n");
  1363.                
  1364.                 JSONObject result = JSONObjectUtil.getResult(output);
  1365.                 log.debug("\n\n Load Customer Result Service Find Partner By Id : "+result+" \n\n");
  1366.                
  1367.                 String status = JSONObjectUtil.getResultStatus(output);
  1368.                 log.debug("\n\n Load Customer Result Status : "+status+" \n\n");
  1369.                
  1370.                 if (status != null && status.equals(GeneralConstants.OK)) {
  1371.                     log.debug("\n\n Load Customer If Result Status Not Null And Equals OK  \n\n");
  1372.                    
  1373.                     header.put("partnerCode", result.get("code"));
  1374.                     log.debug("\n\n Load Customer Header Partner Code : "+header.get("partnerCode")+" \n\n");
  1375.                    
  1376.                     header.put("partnerName", result.get("name"));
  1377.                     log.debug("\n\n Load Customer Header Partner Name : "+header.get("partnerName")+" \n\n");
  1378.                    
  1379.                     log.debug("ini isi dari code customer === " + header.get("partnerCode"));
  1380.                 } else if (status != null && status.equals(GeneralConstants.FAIL)) {
  1381.                     log.debug("ini isi dari ERROR NYA code customer === ");
  1382.                     FacesUtils.addErrorMessage(MessageUtil.getInstance().getLabel((String) result.get("errorKey"), result.get("args")));
  1383.                 }
  1384.             } catch (Exception e) {
  1385.                 log.error("Error on load customer", e);
  1386.                 FacesUtils.addErrorMessage(e.getMessage());
  1387.             }
  1388.         }
  1389.     }
  1390.    
  1391.     @Override
  1392.     public String getScheme() {
  1393.         return SalesWebConstants.SCHEME_SALES_QUOTATION;
  1394.     }
  1395.    
  1396.  
  1397.     @Override
  1398.     public boolean isCanCancelApprove() {
  1399.         return true;
  1400.     }
  1401.    
  1402.     @Override
  1403.     public String cancelApproveTaskName() {
  1404.         return CANCEL_APPROVE_SALES_QUOTATION;
  1405.     }
  1406.    
  1407.    
  1408.     /////////////////////////////////////////////////////// SETTER & GETTER //////////////////////////////////////////////////////////
  1409.    
  1410.  
  1411.     public Long getLastLineNo() {
  1412.         return lastLineNo;
  1413.     }
  1414.     public void setLastLineNo(Long lastLineNo) {
  1415.         this.lastLineNo = lastLineNo;
  1416.     }
  1417.     public List<JSONObject> getTcList() {
  1418.         return tcList;
  1419.     }
  1420.     public void setTcList(List<JSONObject> tcList) {
  1421.         this.tcList = tcList;
  1422.     }
  1423.     public JSONObject getFilterAddMoreItems() {
  1424.         return filterAddMoreItems;
  1425.     }
  1426.     public void setFilterAddMoreItems(JSONObject filterAddMoreItems) {
  1427.         this.filterAddMoreItems = filterAddMoreItems;
  1428.     }
  1429.     public List<JSONObject> getSubCategoryProductList() {
  1430.         return subCategoryProductList;
  1431.     }
  1432.     public void setSubCategoryProductList(List<JSONObject> subCategoryProductList) {
  1433.         this.subCategoryProductList = subCategoryProductList;
  1434.     }
  1435.     public JSONObject getItemToBeDeleted() {
  1436.         return itemToBeDeleted;
  1437.     }
  1438.     public void setItemToBeDeleted(JSONObject itemToBeDeleted) {
  1439.         this.itemToBeDeleted = itemToBeDeleted;
  1440.     }
  1441.     public ProductLazyModel getModel() {
  1442.         return model;
  1443.     }
  1444.     public JSONObject getDataProduct() {
  1445.         return dataProduct;
  1446.     }
  1447.     public void setDataProduct(JSONObject dataProduct) {
  1448.         this.dataProduct = dataProduct;
  1449.     }
  1450.     public String getDataPartner() {
  1451.         return dataPartner;
  1452.     }
  1453.     public void setDataPartner(String dataPartner) {
  1454.         this.dataPartner = dataPartner;
  1455.     }
  1456.     public List<JSONObject> getPartnerList() {
  1457.         return partnerList;
  1458.     }
  1459.     public void setPartnerList(List<JSONObject> partnerList) {
  1460.         this.partnerList = partnerList;
  1461.     }
  1462.     public List<JSONObject> getCpList() {
  1463.         return cpList;
  1464.     }
  1465.     public void setCpList(List<JSONObject> cpList) {
  1466.         this.cpList = cpList;
  1467.     }
  1468.     public List<JSONObject> getPartnerAddressList() {
  1469.         return partnerAddressList;
  1470.     }
  1471.     public void setPartnerAddressList(List<JSONObject> partnerAddressList) {
  1472.         this.partnerAddressList = partnerAddressList;
  1473.     }
  1474.  
  1475.     public List<JSONObject> getTaxList() {
  1476.         return taxList;
  1477.     }
  1478.  
  1479.     public void setTaxList(List<JSONObject> taxList) {
  1480.         this.taxList = taxList;
  1481.     }
  1482.    
  1483. }
Add Comment
Please, Sign In to add comment