Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.erp.fin.web.controller;
- import java.util.HashMap;
- import java.util.Map;
- import javax.annotation.PostConstruct;
- import org.jleaf.core.GeneralConstants;
- import org.jleaf.erp.fin.api.FinanceApiForKtmt;
- import org.jleaf.erp.fin.web.FinanceWebConstantsForKtmt;
- import org.jleaf.erp.fin.web.PageInputConstantsForKtmt;
- import org.jleaf.uploadui.controller.UploadCsvResultController;
- import org.jleaf.util.DateUtil;
- import org.jleaf.util.JSONObjectUtil;
- import org.jleaf.web.helper.MessageHelper;
- import org.jleaf.web.helper.ServiceResult;
- import org.jleaf.web.jsf.FacesUtils;
- import org.jleaf.web.jsf.template.BasicController;
- import org.json.simple.JSONObject;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.annotation.Scope;
- import org.springframework.stereotype.Controller;
- @Controller
- @Scope("view")
- public class ViewResultUploadSettlementUnprocessedInvoiceController extends BasicController implements FinanceApiForKtmt {
- @Autowired
- UploadCsvResultController uploadCsvResultController;
- private static final Logger log = LoggerFactory.getLogger(ViewResultUploadSettlementUnprocessedInvoiceController.class);
- private JSONObject input = new JSONObject();
- @SuppressWarnings("unchecked")
- @PostConstruct
- public void init() {
- Map<String, Object> data = (Map<String, Object>) FacesUtils.retrieveForView(PageInputConstantsForKtmt.VIEW_RESULT_UPLOAD_SETTLEMENT_UNPROCESSED_INVOICE);
- log.debug("init() : "+data);
- JSONObject type = new JSONObject();
- type.put("typeName", FinanceWebConstantsForKtmt.UPLOAD_SETTLEMENT_UNPROCESSED_INVOICE);
- filterBean.getData().put("type", type);
- if(data!=null) {
- JSONObject status = new JSONObject();
- status.put("value", GeneralConstants.EMPTY_VALUE);
- status.put("label", FinanceWebConstantsForKtmt.ALL);
- filterBean.getData().put("status", status);
- filterBean.getData().put("dateFrom", data.get("dateFrom"));
- filterBean.getData().put("dateTo", data.get("dateTo"));
- input.put("markedId", data.get("markedId")==null?GeneralConstants.NULL_REF_VALUE_LONG:data.get("markedId"));
- doSearch();
- FacesUtils.removeForView(PageInputConstantsForKtmt.VIEW_RESULT_UPLOAD_SETTLEMENT_UNPROCESSED_INVOICE);
- } else {
- input.remove("markedId");
- }
- log.debug("filterBean.getData() : " + filterBean.getData());
- }
- public void doSearch() {
- uploadCsvResultController.doSearch();
- }
- @SuppressWarnings("unchecked")
- public String goToView(JSONObject item) {
- log.debug("gotoView() : " + item);
- try {
- JSONObject jsonInput = new JSONObject();
- jsonInput.put("ulHeaderId", item.get("id"));
- jsonInput.put("key", FinanceWebConstantsForKtmt.DOC_ID);
- JSONObject output = serviceContext.executeService(FIND_UPLOAD_PARAMETER_BY_INDEX, jsonInput);
- JSONObject result = JSONObjectUtil.getResult(output);
- if (ServiceResult.isOk(output)) {
- Long id = Long.valueOf(result.get("value").toString());
- boolean exists = isExistsDocument(id);
- if(exists) {
- Map<String, Object> parameter = new HashMap<String, Object>();
- parameter.put("id",id );
- log.debug("GO TO VIEW: " + parameter);
- FacesUtils.storeForView(PageInputConstantsForKtmt.INPUT_SETTLEMENT_UNPROCESSED_INVOICE, parameter);
- return PageInputConstantsForKtmt.INPUT_SETTLEMENT_UNPROCESSED_INVOICE;
- } else {
- MessageHelper.displayError("This document has been deleted");
- return "";
- }
- } else if (ServiceResult.isFail(output)) {
- MessageHelper.displayError(result);
- return "";
- }
- } catch (Exception e) {
- log.error("Error on add adj stock qty along with its items", e);
- FacesUtils.addErrorMessage(e.getMessage());
- }
- return "";
- }
- @SuppressWarnings("unchecked")
- public boolean isExistsDocument(Long id) {
- boolean resultBoolean = false;
- log.debug("isExistsDocument() : " + id);
- try {
- JSONObject jsonInput = new JSONObject();
- jsonInput.put("id", id);
- JSONObject output = serviceContext.executeService(IS_SETTLEMENT_UNPROCESSED_INVOICE_EXISTS_BY_ID, jsonInput);
- JSONObject result = JSONObjectUtil.getResult(output);
- if (ServiceResult.isOk(output)) {
- if(Boolean.valueOf(result.get("exists").toString())){
- resultBoolean = true;
- }
- } else if (ServiceResult.isFail(output)) {
- MessageHelper.displayError(result);
- }
- } catch (Exception e) {
- log.error("Error on check document unprocessed settlement invoice", e);
- FacesUtils.addErrorMessage(e.getMessage());
- }
- return resultBoolean;
- }
- // Getter & Setter
- public JSONObject getInput() {
- return input;
- }
- public void setInput(JSONObject input) {
- this.input = input;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement