/** * ApproveRestrictedPayeeCTR.js */ import React, { Component } from "react"; import Helmet from "react-helmet"; import { BaseContainers, BaseComponents } from "frontend-react-f4-base-ui"; import { BaseContext } from "frontend-react-f4-base-commons"; import { observer } from "mobx-react"; import TextArea from "../../components/TextArea/TextArea"; import moment from "moment"; import { Modal } from "antd"; import MaintenanceApprovalConfirmPanel from "../../components/MaintenanceApprovalConfirmPanel/MaintenanceApprovalConfirmPanel"; import MaintenanceApprovalPanel from "../../components/MaintenanceApprovalPanel/MaintenanceApprovalPanel"; import CitrineFunctionCodes from "../../enums/CitrineFunctionCodes"; import MaintenanceApprovalAckPanel from "../../components/MaintenanceApprovalAckPanel/MaintenanceApprovalAckPanel"; import ViewPage from "../../components/ViewPage/ViewPage"; import AckMessage from "../../components/AckMessage/AckMessage"; import _ from "underscore"; import ApproveRejectViewPageActionPanel from "../../components/ApproveRejectViewPageActionPanel/ApproveRejectViewPageActionPanel"; import BoNewViewPage from "../../components/BoNewViewPage/BoNewViewPage"; import NewViewRestrictedPayeePanel from "../../components/NewViewRestrictedPayeePanel/NewViewRestrictedPayeePanel"; const { connect } = BaseContext; const { F4ContentContainer } = BaseContainers; const { strings, F4Stepper, Feedback } = BaseComponents; import ClientConfig from "../../config/ClientConfig"; @observer @connect class ApproveRestrictedPayeeCTR extends Component { constructor(props) { super(props); this.state = { pages: { initial: 0, confirm: 1, ack: 2, view: 3, viewForConfirmAck: 4, ackForSingle: 5 }, showErrorModal: false, errorModalMsg: "", readOnly: false, prevPage: 0, isForView: false, clickedApprove: false, clickedReject: false }; } componentDidMount() { const { RestrictedPayeeStore } = this.context.store; const { onLoadResults } = this.props; RestrictedPayeeStore.resetApprovalFields(); if (onLoadResults && onLoadResults === true) { this.onSearch(); } } redirectTo = pageNo => { const { RestrictedPayeeStore } = this.context.store; RestrictedPayeeStore.selectedMenuOnApprove = pageNo; }; confirmOnClickBack = () => { const { MaintenanceStore, RestrictedPayeeStore } = this.context.store; MaintenanceStore.approveList = null; RestrictedPayeeStore.resetApprovalFields(); this.redirectTo( this.state.isForView ? this.state.pages.view : this.state.pages.initial ); this.setState({ isForView: false }); }; confirmOnClickSubmit = (isApprove, succCB) => { const { auth, RestrictedPayeeStore, SettingsStore } = this.context.store; SettingsStore.isScreenLoading = true; this.setState({ prevPage: this.state.pages.confirm }); RestrictedPayeeStore.approveListReqModel.localUserCd = auth.sessionUser.user.cd; RestrictedPayeeStore.approveListReqModel.isApprove = isApprove; RestrictedPayeeStore.approveListReqModel.remarks = RestrictedPayeeStore.approvalConfirmProps.remarks; RestrictedPayeeStore.approveListReqModel.maintenanceList = RestrictedPayeeStore.approvalConfirmProps.dataList; if (isApprove) { RestrictedPayeeStore.validateApproval( RestrictedPayeeStore.approveListReqModel.maintenanceList, res => { console.log("Res on validate Approval", res); if (res.body && res.body.error) { if (res.body.error.errors) { _.each(res.body.error.errors, errStr => { RestrictedPayeeStore.errors.push(errStr.message); }); } else if (res.body.error.message) { RestrictedPayeeStore.errors.push(res.body.error.message); } SettingsStore.isScreenLoading = false; this.setState({ clickedApprove: false }); succCB && succCB(); } else { this.approveList(isApprove, succCB); // SettingsStore.isScreenLoading = false; } } ); } else { this.approveList(isApprove, succCB); // SettingsStore.isScreenLoading = false; } }; approveList = (isApprove, succCB) => { const { RestrictedPayeeStore, SettingsStore } = this.context.store; let message = isApprove ? strings.formatString( strings.feedback_success_approval, strings.global_restrictedpayeenm, "approved" ) : strings.formatString( strings.feedback_success_approval, strings.global_restrictedpayeenm, "rejected" ); let messageSingle = isApprove ? "Restricted Payee Name was approved." : "Restricted Payee Name was rejected."; RestrictedPayeeStore.approveList( RestrictedPayeeStore.approveListReqModel, res => { console.log("Approve List: ", res); if (!res.body && res.text) { RestrictedPayeeStore.approvalAckProps = { dataList: RestrictedPayeeStore.approvalConfirmProps.dataList, action: isApprove ? strings.global_approve.toLowerCase() : strings.global_reject.toLowerCase(), remarks: RestrictedPayeeStore.approvalConfirmProps.remarks, refNo: res.text, message: this.state.isForView ? messageSingle : message }; if (this.state.isForView) { let maintenanceList = RestrictedPayeeStore.approvalAckProps.dataList; RestrictedPayeeStore.restrictedPayeeDtlString = maintenanceList && maintenanceList.length > 0 && JSON.parse(maintenanceList[0].dtlString); this.redirectTo(this.state.pages.ackForSingle); this.setState({ prevPage: this.state.pages.ackForSingle }); } else { this.redirectTo(this.state.pages.ack); this.setState({ prevPage: this.state.pages.ack }); } SettingsStore.isScreenLoading = false; succCB && succCB(); } else { if (res.body.error.errors) { _.each(res.body.error.errors, errStr => { RestrictedPayeeStore.errors.push(errStr.message); }); } else if (res.body.error.message) { RestrictedPayeeStore.errors.push(res.body.error.message); } SettingsStore.isScreenLoading = false; succCB && succCB(); } } ); }; onClickRefNo = data => { const { RestrictedPayeeStore, MaintenanceStore } = this.context.store; RestrictedPayeeStore.resetErrorList(); RestrictedPayeeStore.viewPageMaintenanceData = data; MaintenanceStore.remarks = null; RestrictedPayeeStore.resetApprovalFields(); this.redirectTo(this.state.pages.view); this.setState({ readOnly: false, prevPage: this.state.pages.confirm, isForView: true }); }; onClickRefNoForConfirmAck = data => { const { RestrictedPayeeStore, MaintenanceStore } = this.context.store; RestrictedPayeeStore.viewPageMaintenanceData = data; this.redirectTo(this.state.pages.viewForConfirmAck); this.setState({ readOnly: true }); }; onClickApprove = (maintenanceList, remarks, succCB) => { const { RestrictedPayeeStore, MaintenanceStore, auth, SettingsStore } = this.context.store; MaintenanceStore.errors = []; SettingsStore.isScreenLoading = true; this.setState({ clickedApprove: true }); RestrictedPayeeStore.validateApproval(maintenanceList, res => { console.log("Res on Validate Payee Approval: ", res); if (res.body && res.body.error) { if (res.body.error.errors) { _.each(res.body.error.errors, errStr => { MaintenanceStore.errors.push(errStr.message); RestrictedPayeeStore.errors.push(errStr.message); }); } else if (res.body.error.message) { MaintenanceStore.errors.push(res.body.error.message); RestrictedPayeeStore.errors.push(res.body.error.message); } MaintenanceStore.remarks = null; SettingsStore.isScreenLoading = false; this.setState({ clickedApprove: false }); succCB && succCB(); } else { console.log("No Errors."); MaintenanceStore.validateApprovalReqModel.isApprove = true; MaintenanceStore.validateApprovalReqModel.maintenanceList = maintenanceList; MaintenanceStore.validateApprovalReqModel.modelNm = strings.global_payee; MaintenanceStore.validateApprovalReqModel.remarks = remarks; MaintenanceStore.validateApprovalReqModel.requiresApprovalFuncCd = CitrineFunctionCodes.RESTRICTED_PAYEE_NM_REQUIRES_APPROVAL; //CitrineFunctionCodes.COURIER_MAINTENANCE_REQUIRES_APPROVAL; MaintenanceStore.validateApprovalReqModel.userCd = auth.sessionUser.user.cd; MaintenanceStore.validateApproval( MaintenanceStore.validateApprovalReqModel, res => { if (res.body && res.body.error) { _.each(res.body.error.errors, errStr => { MaintenanceStore.errors.push(errStr.message); }); this.setState({ clickedApprove: false }); SettingsStore.isScreenLoading = false; succCB && succCB(); } else { console.log("No Errors."); RestrictedPayeeStore.approvalConfirmProps = { action: strings.global_approve.toLowerCase(), remarks: remarks, dataList: maintenanceList }; RestrictedPayeeStore.resetErrorList(); if (this.state.isForView) { this.confirmOnClickSubmit(true, null); } else { this.redirectTo(this.state.pages.confirm); this.setState({ prevPage: this.state.pages.confirm }); SettingsStore.isScreenLoading = false; } MaintenanceStore.remarks = null; this.setState({ clickedApprove: false }); succCB && succCB(); } } ); } }); }; onClickReject = (maintenanceList, remarks, succCB) => { const { RestrictedPayeeStore, MaintenanceStore, auth, SettingsStore } = this.context.store; SettingsStore.isScreenLoading = true; MaintenanceStore.errors = []; this.setState({ clickedReject: true }); MaintenanceStore.validateApprovalReqModel.isApprove = false; MaintenanceStore.validateApprovalReqModel.maintenanceList = maintenanceList; MaintenanceStore.validateApprovalReqModel.modelNm = strings.global_payee; MaintenanceStore.validateApprovalReqModel.remarks = remarks; MaintenanceStore.validateApprovalReqModel.requiresApprovalFuncCd = CitrineFunctionCodes.RESTRICTED_PAYEE_NM_REQUIRES_APPROVAL; // CitrineFunctionCodes.COURIER_MAINTENANCE_REQUIRES_APPROVAL; MaintenanceStore.validateApprovalReqModel.userCd = auth.sessionUser.user.cd; MaintenanceStore.validateApproval( MaintenanceStore.validateApprovalReqModel, res => { if (res.body && res.body.error) { _.each(res.body.error.errors, errStr => { MaintenanceStore.errors.push(errStr.message); }); this.setState({ showErrorModal: true, errorModalMsg: MaintenanceStore.errors[0], clickedReject: false }); SettingsStore.isScreenLoading = false; succCB && succCB(); } else { console.log("No Errors."); RestrictedPayeeStore.approvalConfirmProps = { action: strings.global_reject.toLowerCase(), remarks: remarks, dataList: maintenanceList }; RestrictedPayeeStore.resetErrorList(); if (this.state.isForView) { this.confirmOnClickSubmit(false, () => { this.setState({ clickedReject: false }); }); } else { this.redirectTo(this.state.pages.confirm); this.setState({ prevPage: this.state.pages.confirm, clickedReject: false }); } SettingsStore.isScreenLoading = false; succCB && succCB(); } MaintenanceStore.remarks = null; } ); }; onSearch = multiSort => { const { RestrictedPayeeStore, MaintenanceStore, auth } = this.context.store; if (!multiSort) { multiSort = { page: 0, count: 10, sortList: [ { direction: "desc", sort: "updatedDt" } ] }; } let fields = RestrictedPayeeStore.approvalFields; { fields != undefined && fields.map( field => (MaintenanceStore.searchRequestModel[field.index] = field.value) ); } MaintenanceStore.errors = []; MaintenanceStore.searchRequestModel.notCreatedBy = auth.sessionUser.user.cd; MaintenanceStore.searchRequestModel.filterTypeOne = { isCaseSensitive: false, isEq: true }; MaintenanceStore.searchRequestModel.filterTypeTwo = { isCaseSensitive: false, isEq: false }; MaintenanceStore.searchRequestModel.funcCd = CitrineFunctionCodes.RESTRICTED_PAYEE_NM_REQUIRES_APPROVAL; //CitrineFunctionCodes.COURIER_MAINTENANCE_REQUIRES_APPROVAL; MaintenanceStore.findBySearchModel( MaintenanceStore.searchRequestModel, multiSort, res => { if (res.body && !res.body.error) { console.log("app res: ", res); MaintenanceStore.responseBody = res.body; MaintenanceStore.approveList = res.body.content; let data = MaintenanceStore.approveList; MaintenanceStore.dataTableRef.setState({ data: data, copyOfData: data, totalItemsCount: res.body.totalElements }); MaintenanceStore.dataTableRef && MaintenanceStore.dataTableRef.forceUpdate(); } else { console.log("Error", res.body.error); } // this.setState({ hasClickedSearch: true }); } ); }; _createData = () => { return [ { headerTitle: strings.global_refno, name: "refNo", type: "link", width: 100, cell: props => ( this.onClickRefNo(props.data)} > {" "} {props.data.refNo}{" "} ) }, { headerTitle: strings.global_restrictedpayeenm, name: "filterOne", type: "text", width: 100 }, { headerTitle: strings.global_amount, name: "filterTwo", type: "text", width: 100 }, { headerTitle: strings.global_func, // name: "actnFuncCd", name: "actnFunc.description", type: "text", width: 150, sortBy: "actnFunc.description", cell: props => ( {props.data.actnFunc.description} ) }, { headerTitle: strings.global_creatdby, name: "createdBy", type: "text", width: 150 }, { headerTitle: strings.global_createdt, name: "createdDt", type: "text", width: 150, formatter: "date" } ]; }; _createDataForConfirmAck = () => { return [ { headerTitle: strings.global_refno, name: "refNo", type: "link", width: 100, cell: props => ( this.onClickRefNoForConfirmAck(props.data)} > {" "} {props.data.refNo}{" "} ) }, { headerTitle: strings.global_restrictedpayeenm, name: "filterOne", type: "text", width: 100 }, { headerTitle: strings.global_amount, name: "filterTwo", type: "text", width: 100 }, { headerTitle: strings.global_func, // name: "actnFuncCd", name: "actnFunc.description", type: "text", width: 150, sortBy: "actnFunc.description", cell: props => ( {props.data.actnFunc.description} ) }, { headerTitle: strings.global_creatdby, name: "createdBy", type: "text", width: 150 }, { headerTitle: strings.global_createdt, name: "createdDt", type: "text", width: 120, formatter: "date" } ]; }; onClickDownload = multiSort => { const { MaintenanceStore, auth } = this.context.store; return new Promise(resolve => { MaintenanceStore.findBySearchModel( MaintenanceStore.searchRequestModel, multiSort, res => { if (res.body && !res.body.error) { resolve(res.body.content); } } ); }); }; _showMaintenanceApprovalPanel() { const { RestrictedPayeeStore } = this.context.store; return ( ); } _showMaintenanceApprovalConfirmPanel() { const { MaintenanceStore, RestrictedPayeeStore } = this.context.store; let isApprove = RestrictedPayeeStore.approvalConfirmProps.action === "approve"; return ( { MaintenanceStore.remarks = null; RestrictedPayeeStore.resetErrorList(); this.confirmOnClickBack(); }} onClickSubmit={() => this.confirmOnClickSubmit(isApprove, null)} errorFeedback={RestrictedPayeeStore.errors} stepWizardHeader={"Confirm Details"} modelName={strings.global_payee} /> ); } _showMaintenanceApprovalAckPanel() { const { MaintenanceStore, RestrictedPayeeStore } = this.context.store; return ( { MaintenanceStore.remarks = null; RestrictedPayeeStore.resetApprovalFields(); MaintenanceStore.approveList = null; this.redirectTo(this.state.pages.initial); }} stepWizardHeader={strings.global_acknowledgement} /> ); } _showViewPage(actionButtons) { const { RestrictedPayeeStore, MaintenanceStore } = this.context.store; let dtlStringData = RestrictedPayeeStore.viewPageMaintenanceData ? JSON.parse(RestrictedPayeeStore.viewPageMaintenanceData.dtlString) : null; let funcDscp = RestrictedPayeeStore.viewPageMaintenanceData && RestrictedPayeeStore.viewPageMaintenanceData.actnFunc.description; return ( } onClickBack={() => { MaintenanceStore.resetRemarks(); MaintenanceStore.errors = []; RestrictedPayeeStore.resetErrorList(); MaintenanceStore.approveList = null; this.setState({ isForView: false }); this.redirectTo(this.state.pages.initial); }} onClickApprove={() => { this.setState({ isForView: true }); let data = []; data.push(RestrictedPayeeStore.viewPageMaintenanceData); this.onClickApprove(data, MaintenanceStore.remarks); MaintenanceStore.errors = []; }} onClickReject={() => { this.setState({ isForView: true }); let data = []; data.push(RestrictedPayeeStore.viewPageMaintenanceData); this.checkIfHasRemarks(data); MaintenanceStore.errors = []; }} /> ); } _showViewPageForConfirmAck() { const { RestrictedPayeeStore, MaintenanceStore } = this.context.store; let dtlStringData = this.showViewPageConfirmAckData(); return ( } onClickBack={() => { this.state.prevPage == this.state.pages.ack ? this.redirectTo(this.state.pages.ack) : this.redirectTo(this.state.pages.confirm); }} /> ); } _showAckForSingle() { const { MaintenanceStore, RestrictedPayeeStore } = this.context.store; let data = RestrictedPayeeStore.restrictedPayeeDtlString; let funcDscp = RestrictedPayeeStore.viewPageMaintenanceData && RestrictedPayeeStore.viewPageMaintenanceData.actnFunc.description; return ( { MaintenanceStore.remarks = null; MaintenanceStore.approveList = null; RestrictedPayeeStore.resetApprovalFields(); this.redirectTo(this.state.pages.initial); this.setState({ isForView: false }); }} viewPanel={ } /> ); } showViewPageConfirmAckData() { const { RestrictedPayeeStore } = this.context.store; return RestrictedPayeeStore.viewPageMaintenanceData ? JSON.parse(RestrictedPayeeStore.viewPageMaintenanceData.dtlString) : null; } handleCancel = () => { this.setState({ showErrorModal: false, errorModalMsg: "" }); }; handleKeyDown = e => { const { MaintenanceStore } = this.context.store; MaintenanceStore.remarks = e.target.value; }; checkIfHasRemarks = data => { const { MaintenanceStore, SettingsStore } = this.context.store; if (!MaintenanceStore.remarks) { let errorList = [ strings.formatString( strings.feedback_bad_isrequired, strings.global_remarks ) ]; RestrictedPayeeStore.errors = errorList; this.setState({ showErrorModal: true, errorModalMsg: errorList[0] }); SettingsStore.isScreenLoading = false; } else { this.onClickReject(data, MaintenanceStore.remarks); } }; render() { const { RestrictedPayeeStore, MaintenanceStore } = this.context.store; const actionButtons = (