Evra70

controller nya

May 5th, 2021
541
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.jleaf.erp.fin.web.controller.handoverinvoicear;
  2.  
  3. import org.jleaf.core.GeneralConstants;
  4. import org.jleaf.erp.fin.api.FinanceApi;
  5. import org.jleaf.erp.fin.web.PageInputConstants;
  6. import org.jleaf.erp.fin.web.model.handoverinvoicear.HandoverInvoiceArLazyModel;
  7. import org.jleaf.util.Calc;
  8. import org.jleaf.web.helper.MessageHelper;
  9. import org.jleaf.web.jsf.FacesUtils;
  10. import org.jleaf.web.jsf.template.AbstractBrowseWithBasketController;
  11. import org.jleaf.web.model.ComboItem;
  12. import org.json.simple.JSONObject;
  13. import org.primefaces.context.RequestContext;
  14. import org.slf4j.Logger;
  15. import org.slf4j.LoggerFactory;
  16. import org.springframework.context.annotation.Scope;
  17. import org.springframework.stereotype.Controller;
  18.  
  19. import javax.annotation.PostConstruct;
  20. import java.io.Serializable;
  21. import java.util.*;
  22.  
  23. /**
  24.  * @author H.Kevin, January 6, 2020
  25.  *
  26.  */
  27.  
  28. @SuppressWarnings("serial")
  29. @Controller
  30. @Scope("view")
  31. public class CreateHandoverInvoiceArController extends AbstractBrowseWithBasketController implements FinanceApi, Serializable {
  32.  
  33.     private static final Logger log = LoggerFactory.getLogger(CreateHandoverInvoiceArController.class);
  34.     //private List<JSONObject> selectedInvoiceArBalanceList;
  35.    
  36.     private Double totalAmount = 0d;
  37.     private HandoverInvoiceArLazyModel model;
  38.    
  39.    
  40.     @SuppressWarnings("unchecked")
  41.     @PostConstruct
  42.     private void init() {
  43.         log.debug("run init()");
  44.         filterBean.getData().put("ou", new ComboItem("id", 10));
  45.         filterBean.getData().put("dueDate", new ComboItem("code", GeneralConstants.EMPTY_VALUE));
  46.         log.debug("filterBean.getData(): "+filterBean.getData());
  47.     }
  48.  
  49.    
  50.  
  51.     @SuppressWarnings({ "unchecked" })
  52.     @Override
  53.     public JSONObject getJsonForSearch() {
  54.         log.debug("filterBean: " + filterBean.getData());
  55.         String dueDateTypeCode = GeneralConstants.EMPTY_VALUE;
  56.        
  57.         JSONObject ou = (JSONObject) filterBean.getData().get("ou");
  58.         String customerCodeName = filterBean.getData().get("customerCodeName").toString().trim();
  59.         JSONObject dueDateType = (JSONObject) filterBean.getData().get("dueDate");
  60.        
  61.         if(dueDateType != null) {
  62.             dueDateTypeCode = dueDateType.get("code").toString();
  63.         }
  64.        
  65.         JSONObject jsonInput = new JSONObject();
  66.         jsonInput.put("ouId", ou.get("id") == null ? GeneralConstants.EMPTY_VALUE : ou.get("id"));
  67.         jsonInput.put("customerCodeName", customerCodeName == null ? GeneralConstants.EMPTY_VALUE : customerCodeName);
  68.         jsonInput.put("dueDateTypeCode", dueDateTypeCode);
  69.  
  70.         log.debug("jsonInput: " + jsonInput);
  71.  
  72.         return jsonInput;
  73.     }
  74.  
  75.     @Override
  76.     public void afterSearch(JSONObject result, boolean isOk) {
  77.         log.debug("result after search: "+result);
  78.         if (isOk) {
  79.            
  80.             Long rowCount = Long.valueOf(result.get("count").toString());
  81.             model = new HandoverInvoiceArLazyModel(serviceContext, getJsonForSearch());
  82.             model.setRowCount(rowCount.intValue());
  83.             model.setPageSize(25);
  84.            
  85.             setSelectedList(null);
  86.         }else {
  87.             MessageHelper.displayError(result);
  88.         }
  89.     }
  90.  
  91.     @Override
  92.     public String searchTaskName() {
  93.         return COUNT_GET_INVOICE_AR_LIST_FOR_HANDOVER_INVOICE_AR;
  94.     }
  95.        
  96.     @Override
  97.     public void afterBasketAdd(JSONObject arg0) {
  98.         // Nothing TO DO
  99.  
  100.     }
  101.  
  102.     @SuppressWarnings("unchecked")
  103.     @Override
  104.     public String next() {
  105.         if (getChosenList().isEmpty()) {
  106.             MessageHelper.displayError("org.jleaf.erp.fin.web.pleaseChooseInvoiceFirst");
  107.             return PageInputConstants.CREATE_HANDOVER_INVOICE_AR + "?faces-redirect=false";
  108.         }
  109.        
  110.         //String dueDateTypeCode = GeneralConstants.EMPTY_VALUE;
  111.         List<JSONObject> invoiceArList = new ArrayList<JSONObject>(getChosenList().size());
  112.        
  113.         for (JSONObject balance : getChosenList()) {
  114.             JSONObject json = new JSONObject();
  115.             json.put("id", balance.get("invoiceId"));
  116.             json.put("tenantId", balance.get("tenantId"));
  117.             json.put("ouId", balance.get("ouId"));
  118.             json.put("docTypeId", balance.get("docTypeId"));
  119.             json.put("docDesc", balance.get("docTypeDesc"));
  120.             json.put("docNo", balance.get("docNo"));
  121.             json.put("docDate", balance.get("docDate"));
  122.             json.put("partnerId", balance.get("partnerId"));
  123.             json.put("partnerCode", balance.get("partnerCode"));
  124.             json.put("partnerName", balance.get("partnerName"));
  125.             json.put("dueDate", balance.get("dueDate"));
  126.             json.put("currCode", balance.get("currCode"));
  127.             json.put("invoiceAmount", balance.get("invoiceAmount"));
  128.             json.put("paymentAmount", balance.get("paymentAmount"));
  129.             json.put("osAmount", balance.get("osAmount"));
  130.             json.put("version", balance.get("version"));
  131.            
  132.             invoiceArList.add(json);
  133.            
  134.         }
  135.        
  136.         JSONObject ou = (JSONObject) filterBean.getData().get("ou");
  137. //      String customerCodeName = filterBean.getData().get("customerCodeName").toString().trim();
  138. //      JSONObject dueDateType = (JSONObject) filterBean.getData().get("dueDate");
  139. //     
  140. //      if(dueDateType != null) {
  141. //          dueDateTypeCode = dueDateType.get("code").toString();
  142. //      }
  143.        
  144.         Map<String, Object> params = new HashMap<String, Object>();
  145.         params.put("ouId", ou.get("id"));
  146.         params.put("ouCode", ou.get("code"));
  147.         params.put("ouName", ou.get("name"));
  148.         params.put("invoiceArList", invoiceArList);
  149.    
  150.         log.debug("PARAMS FOR CREATE: " + params);
  151.         FacesUtils.storeForCreate(PageInputConstants.INPUT_HANDOVER_INVOICE_AR, params);
  152.        
  153.         RequestContext.getCurrentInstance().execute("document.location='inputHandoverInvoiceAr.jsf'");
  154.        
  155.         return PageInputConstants.INPUT_HANDOVER_INVOICE_AR;
  156.     }
  157.  
  158.     public void onOuChanged() {
  159.         log.debug("ou: "+filterBean.getData().get("ou"));
  160.         model = null;
  161.         if (getChosenList() != null) {
  162.             getChosenList().clear();
  163.         }
  164.         checkOnChange();
  165.     }
  166.    
  167.     public void onDueDateChanged() {
  168.         log.debug("dueDate: "+filterBean.getData().get("dueDate"));
  169.         //model = null;
  170.         //getChosenList().clear();
  171.         checkOnChange();
  172.     }
  173.  
  174.     private void checkOnChange() {
  175.         RequestContext context = RequestContext.getCurrentInstance();
  176.         if (!getChosenList().isEmpty()) {
  177.             context.addCallbackParam("show", true);
  178.         } else {
  179.             context.addCallbackParam("show", false);
  180.             resetGrids();
  181.         }
  182.     }
  183.  
  184.     public void resetGrids() {
  185.         gridItemList = null;
  186.         setSelectedList(null);
  187.         clearBasket();
  188.     }
  189.    
  190.     @SuppressWarnings("unchecked")
  191.     @Override
  192.     public void addToBasket() {
  193.         log.debug(">> addToBasket()");
  194.         log.debug("selectedList >>: " + Arrays.toString(getSelectedList()));
  195.        
  196.         RequestContext context = RequestContext.getCurrentInstance();
  197.        
  198.         //check Empty List
  199.         if ((getSelectedList() == null) || (getSelectedList().length == 0)) {
  200.             MessageHelper.displayError("org.jleaf.erp.fin.web.noDataSelected");
  201.             context.addCallbackParam("show", false);
  202.             return;
  203.         }
  204.        
  205.         //Check duplicate invoice
  206.         if(getChosenList() != null) {
  207.             for(JSONObject newList : getSelectedList()) {
  208.                 log.debug("newList: "+newList);
  209.                 for (JSONObject addedInvoice : getChosenList()) {
  210.                     log.debug("addedInvoice: "+addedInvoice);
  211.                     if(addedInvoice.containsValue(newList.get("id"))){
  212.                         MessageHelper.displayError("invoice.already.added.to.basket");
  213.                         return;
  214.                     }
  215.                 }
  216.             }
  217.         }
  218.        
  219.         super.addToBasket();
  220.    
  221.         log.debug("getChosenList >> : " +getChosenList());
  222.        
  223.         calculateTotalAmount();
  224.     }
  225.    
  226.     public void calculateTotalAmount(){
  227.         Calc calc = new Calc(0);
  228.         if(getChosenList()!=null && !getChosenList().isEmpty()) {
  229.             for(JSONObject data : getChosenList()){
  230.                 calc = calc.add(Double.valueOf(data.get("osAmount").toString()));
  231.             }
  232.         }
  233.         totalAmount = calc.doubleValue();
  234.         log.debug("totalAmount : >>"+totalAmount);
  235.     }
  236.    
  237.     @Override
  238.     public boolean isMultiple() {
  239.         return true;
  240.     }
  241.     @Override
  242.     public void removeFromBasket(){
  243.         super.removeFromBasket();
  244.         calculateTotalAmount();
  245.     }
  246.     @Override
  247.     public void clearBasket(){
  248.         super.clearBasket();
  249.         calculateTotalAmount();
  250.     }
  251.    
  252.    
  253.     public Double getTotalAmount() {
  254.         return totalAmount;
  255.     }
  256.  
  257.     public void setTotalAmount(Double totalAmount) {
  258.         this.totalAmount = totalAmount;
  259.     }
  260.    
  261.     public HandoverInvoiceArLazyModel getModel() {
  262.         return model;
  263.     }
  264. }
  265.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×