Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 4.82 KB | None | 0 0
  1. package org.jleaf.erp.fin.web.controller;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5.  
  6. import javax.annotation.PostConstruct;
  7.  
  8. import org.jleaf.core.GeneralConstants;
  9. import org.jleaf.erp.fin.api.FinanceApiForKtmt;
  10. import org.jleaf.erp.fin.web.FinanceWebConstantsForKtmt;
  11. import org.jleaf.erp.fin.web.PageInputConstantsForKtmt;
  12. import org.jleaf.uploadui.controller.UploadCsvResultController;
  13. import org.jleaf.util.DateUtil;
  14. import org.jleaf.util.JSONObjectUtil;
  15. import org.jleaf.web.helper.MessageHelper;
  16. import org.jleaf.web.helper.ServiceResult;
  17. import org.jleaf.web.jsf.FacesUtils;
  18. import org.jleaf.web.jsf.template.BasicController;
  19. import org.json.simple.JSONObject;
  20. import org.slf4j.Logger;
  21. import org.slf4j.LoggerFactory;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.context.annotation.Scope;
  24. import org.springframework.stereotype.Controller;
  25.  
  26. @Controller
  27. @Scope("view")
  28. public class ViewResultUploadSettlementUnprocessedInvoiceController extends BasicController implements FinanceApiForKtmt {
  29.  
  30.     @Autowired
  31.     UploadCsvResultController uploadCsvResultController;
  32.  
  33.     private static final Logger log = LoggerFactory.getLogger(ViewResultUploadSettlementUnprocessedInvoiceController.class);
  34.  
  35.     private JSONObject input = new JSONObject();
  36.    
  37.     @SuppressWarnings("unchecked")
  38.     @PostConstruct
  39.     public void init() {
  40.        
  41.         Map<String, Object> data = (Map<String, Object>) FacesUtils.retrieveForView(PageInputConstantsForKtmt.VIEW_RESULT_UPLOAD_SETTLEMENT_UNPROCESSED_INVOICE);
  42.  
  43.         log.debug("init() : "+data);
  44.        
  45.         JSONObject type = new JSONObject();
  46.         type.put("typeName", FinanceWebConstantsForKtmt.UPLOAD_SETTLEMENT_UNPROCESSED_INVOICE);
  47.         filterBean.getData().put("type", type);
  48.        
  49.         if(data!=null) {
  50.  
  51.             JSONObject status = new JSONObject();
  52.             status.put("value", GeneralConstants.EMPTY_VALUE);
  53.             status.put("label", FinanceWebConstantsForKtmt.ALL);
  54.             filterBean.getData().put("status", status);
  55.            
  56.             filterBean.getData().put("dateFrom", data.get("dateFrom"));
  57.             filterBean.getData().put("dateTo", data.get("dateTo"));
  58.             input.put("markedId", data.get("markedId")==null?GeneralConstants.NULL_REF_VALUE_LONG:data.get("markedId"));
  59.            
  60.             doSearch();
  61.             FacesUtils.removeForView(PageInputConstantsForKtmt.VIEW_RESULT_UPLOAD_SETTLEMENT_UNPROCESSED_INVOICE);
  62.         } else {
  63.             input.remove("markedId");
  64.         }
  65.        
  66.         log.debug("filterBean.getData() : " + filterBean.getData());
  67.     }
  68.    
  69.     public void doSearch() {
  70.         uploadCsvResultController.doSearch();
  71.     }
  72.    
  73.     @SuppressWarnings("unchecked")
  74.     public String goToView(JSONObject item) {
  75.         log.debug("gotoView() : " + item);
  76.        
  77.         try {
  78.             JSONObject jsonInput = new JSONObject();
  79.             jsonInput.put("ulHeaderId", item.get("id"));
  80.             jsonInput.put("key", FinanceWebConstantsForKtmt.DOC_ID);
  81.            
  82.             JSONObject output = serviceContext.executeService(FIND_UPLOAD_PARAMETER_BY_INDEX, jsonInput);
  83.             JSONObject result = JSONObjectUtil.getResult(output);
  84.             if (ServiceResult.isOk(output)) {
  85.                 Long id = Long.valueOf(result.get("value").toString());
  86.                
  87.                 boolean exists = isExistsDocument(id);
  88.                
  89.                 if(exists) {
  90.                    
  91.                     Map<String, Object> parameter = new HashMap<String, Object>();
  92.                     parameter.put("id",id );
  93.                     log.debug("GO TO VIEW: " + parameter);
  94.    
  95.                     FacesUtils.storeForView(PageInputConstantsForKtmt.INPUT_SETTLEMENT_UNPROCESSED_INVOICE, parameter);
  96.                     return PageInputConstantsForKtmt.INPUT_SETTLEMENT_UNPROCESSED_INVOICE;
  97.                    
  98.                 } else {
  99.                     MessageHelper.displayError("This document has been deleted");
  100.                     return "";
  101.                 }
  102.                
  103.             } else if (ServiceResult.isFail(output)) {
  104.  
  105.                 MessageHelper.displayError(result);
  106.                
  107.                 return "";
  108.             }
  109.         } catch (Exception e) {
  110.             log.error("Error on add adj stock qty along with its items", e);
  111.             FacesUtils.addErrorMessage(e.getMessage());
  112.         }
  113.        
  114.         return "";
  115.     }
  116.    
  117.     @SuppressWarnings("unchecked")
  118.     public boolean isExistsDocument(Long id) {
  119.        
  120.         boolean resultBoolean = false;
  121.        
  122.         log.debug("isExistsDocument() : " + id);
  123.        
  124.         try {
  125.             JSONObject jsonInput = new JSONObject();
  126.             jsonInput.put("id", id);
  127.            
  128.             JSONObject output = serviceContext.executeService(IS_SETTLEMENT_UNPROCESSED_INVOICE_EXISTS_BY_ID, jsonInput);
  129.             JSONObject result = JSONObjectUtil.getResult(output);
  130.             if (ServiceResult.isOk(output)) {
  131.                 if(Boolean.valueOf(result.get("exists").toString())){
  132.                     resultBoolean = true;
  133.                 }
  134.             } else if (ServiceResult.isFail(output)) {
  135.                 MessageHelper.displayError(result);
  136.             }
  137.         } catch (Exception e) {
  138.             log.error("Error on check document unprocessed settlement invoice", e);
  139.             FacesUtils.addErrorMessage(e.getMessage());
  140.         }
  141.        
  142.         return resultBoolean;
  143.     }
  144.    
  145.  
  146.     // Getter & Setter
  147.     public JSONObject getInput() {
  148.         return input;
  149.     }
  150.  
  151.     public void setInput(JSONObject input) {
  152.         this.input = input;
  153.     }
  154.    
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement