- /**
- * RestrictedPayeeStore.js
- */
- import {
- observable,
- extendObservable,
- action,
- asMap,
- reaction,
- autorunm,
- toJS
- } from "mobx";
- import _ from "underscore";
- import ClientConfig from "../config/ClientConfig";
- import { BaseMiddlewares } from "frontend-react-f4-base-commons";
- const { ClientMiddleware } = BaseMiddlewares;
- import { BaseComponents } from "frontend-react-f4-base-ui";
- import CitrineFunctionCodes from "../enums/CitrineFunctionCodes";
- import moment from "moment";
- const { strings } = BaseComponents;
- import YesOrNoEnum from "../enums/YesOrNoEnum";
- export default class RestrictedPayeeStore {
- constructor(RestrictedPayeeStore) {
- if (RestrictedPayeeStore) {
- Object.assign(this, RestrictedPayeeStore);
- }
- this.reset();
- this.resetInputs();
- this.resetErrorList();
- this.resetSearchFields();
- this.resetApprovalFields();
- }
- @action
- reset() {
- extendObservable(this, {
- copyFromStore: null,
- hasManualAuth: false,
- hasUploadAuth: false,
- isManual: true,
- clickedNext: false,
- clickedBack: false,
- previousData: null,
- dataTableRef: null,
- isforView: false,
- dataTableStore: {
- getTotal: null
- },
- selectedMenuOnAdd: 0,
- selectedMenuOnEdit: 0,
- selectedMenuOnApprove: 0,
- selectedMenuOnSearch: 0,
- fields: {
- payeeName: strings.global_restrictedpayeenm,
- amount: strings.global_amount,
- isAllowed: strings.global_isallowed,
- charToIgnore: strings.global_character_ignore
- },
- copyFromFields: [
- {
- key: "amount"
- }
- ],
- payeeFields: [
- {
- key: "payeeName",
- label: strings.global_restrictedpayeenm
- },
- {
- key: "amount",
- label: strings.global_amount
- },
- {
- key: "isAllowed",
- label: strings.global_isallowed
- },
- {
- key: "charToIgnore",
- label: strings.global_character_ignore
- }
- ],
- payeeSaved: null,
- refNoDeleteMultiple: null,
- isForApproval: false,
- ackMessage: {
- header: null,
- refNo: null
- },
- approveListReqModel: {
- localUserCd: null,
- maintenanceList: null,
- isApprove: false
- },
- approvalConfirmProps: {
- action: null,
- remarks: "",
- dataList: null
- },
- approvalAckProps: {
- dataList: null,
- action: null,
- remarks: null,
- refNo: null,
- message: null
- },
- viewPageMaintenanceData: null,
- uploadFields: {
- payeeName: null,
- amount: 0,
- isAllowed: false,
- charToIgnore: null
- },
- searchFilter: {
- payeeName: null,
- amount: 0,
- isAllowed: false,
- charToIgnore: null,
- restrictedPayeeDate: null,
- filterList: [],
- isInquiry: true,
- maker: null,
- requiresApprovalFuncCd:
- CitrineFunctionCodes.RESTRICTED_PAYEE_NM_REQUIRES_APPROVAL
- },
- // transactionOptionsRadioButton: [
- // {
- // value: 0,
- // label: "Disallow Payee"
- // },
- // {
- // value: 1,
- // label: "Allow Payee but with Override"
- // }
- // ],
- isAllowed: [
- {
- value: 0,
- label: "Disallow Payee"
- },
- {
- value: 1,
- label: "Allow Payee but with Override"
- }
- ]
- });
- }
- @observable responseBody = null;
- @observable restrictedPayeeList = null;
- @observable restrictedPayeeDtlString = null;
- @action getFieldLabel(key) {
- let field = _.findWhere(this.payeeFields, {
- key: key
- });
- return field ? field.label : "";
- }
- @action resetErrorList() {
- extendObservable(this, {
- errors: []
- });
- }
- @action initializeMaintenanceModel(data, actnFuncCd, userCd, grpId) {
- let isAdd = actnFuncCd === CitrineFunctionCodes.RESTRICTED_PAYEE_NM_ADD;
- let editFuncCd =
- actnFuncCd === isAdd
- ? null
- : CitrineFunctionCodes.RESTRICTED_PAYEE_NM_EDIT;
- let deleteFuncCd = isAdd
- ? null
- : CitrineFunctionCodes.RESTRICTED_PAYEE_NM_DEL;
- return {
- localUserCd: userCd,
- requiresApprovalFuncCd:
- CitrineFunctionCodes.RESTRICTED_PAYEE_NM_REQUIRES_APPROVAL,
- actnFuncCd: actnFuncCd,
- approveRejectFuncCd:
- CitrineFunctionCodes.RESTRICTED_PAYEE_NM_APPROVE_REJECT,
- addFuncCd: isAdd ? CitrineFunctionCodes.RESTRICTED_PAYEE_NM_ADD : null,
- editFuncCd: editFuncCd,
- deleteFuncCd: deleteFuncCd,
- modelNm: strings.global_payee,
- grpId: grpId,
- isAdd: isAdd,
- dtlString: JSON.stringify({
- id: isAdd ? null : data.id,
- cd: isAdd ? null : data.cd,
- funcCd: data.funcCd,
- payeeName: data.payeeName,
- amount: data.amount,
- charToIgnore: data.charToIgnore,
- isAllowed: data.isAllowed,
- version: isAdd ? null : data.version
- }),
- filterValues: [
- data.payeeName,
- data.amount,
- data.isAllowed,
- data.charToIgnore
- ],
- uniqueCds: [data.payeeName]
- };
- }
- @action resetInputs() {
- extendObservable(this, {
- restrictedPayeeInputs: {
- localUserCd: null,
- id: null,
- payeeName: "",
- amount: 0,
- isAllowed: true,
- isAllowedStr: "",
- transactionOptionRadioButton: 0,
- charToIgnore: null,
- showEdit: false
- }
- });
- }
- @action resetSearchFields() {
- extendObservable(this, {
- searchRestrictedPayeeFields: [
- {
- index: "payeeName",
- label: strings.global_restrictedpayeenm,
- type: "text",
- content: null,
- value: null
- },
- {
- index: "amount",
- label: strings.global_amount,
- type: "text",
- content: null,
- value: null
- },
- {
- index: "isAllowed",
- label: strings.global_action,
- type: "radio",
- content: [
- {
- value: 1,
- // label: YesOrNoEnum.getDescriptionFromKey(1)
- label: "Allow Payee but with Override"
- },
- {
- value: 0,
- // label: YesOrNoEnum.getDescriptionFromKey(0)
- label: "Disallow Payee"
- },
- {
- value: 2,
- label: strings.global_all
- }
- ],
- value: 2,
- defaultValue: 2
- }
- ]
- });
- }
- @action
- resetSearchFilters() {
- extendObservable(this, {});
- }
- @action
- resetApprovalFields() {
- extendObservable(this, {
- approvalFields: [
- {
- index: "refNo",
- label: strings.global_refno,
- type: "text",
- content: null,
- value: null
- },
- {
- index: "filterOne",
- label: strings.global_restrictedpayeenm,
- type: "text",
- content: null,
- value: null,
- filterType: {
- isEq: true,
- isCaseSensitive: true
- }
- },
- {
- index: "filterTwo",
- label: strings.global_amount,
- type: "text",
- content: null,
- value: null,
- filterType: {
- isEq: true,
- isCaseSensitive: true
- }
- },
- // {
- // index: "filterThree",
- // label: strings.global_isallowed,
- // type: "text",
- // content: null,
- // value: null,
- // filterType: {
- // isEq: true,
- // isCaseSensitive: true
- // }
- // },
- // {
- // index: "filterFour",
- // label: "Characters To Ignore",
- // type: "text",
- // content: null,
- // value: null,
- // filterType: {
- // isEq: true,
- // isCaseSensitive: true
- // }
- // },
- {
- index: "fromDate",
- label: strings.global_creatddt,
- type: "dateBetween",
- content: null,
- value: moment()
- .subtract(2, "months")
- .add(1, "days"),
- children: null
- },
- {
- index: "toDate",
- label: strings.global_creatddt,
- type: "dateBetween",
- content: null,
- value: moment(),
- children: null
- }
- ]
- });
- }
- @action
- hasErrors(responseBody) {
- if (responseBody && !responseBody.error) {
- return false;
- } else {
- let errorMessage = null;
- if (
- responseBody &&
- responseBody.error &&
- responseBody.statusCode != 500
- ) {
- if (responseBody.error.errors) {
- errorMessage = responseBody.error.errors;
- } else if (responseBody.error.message) {
- errorMessage = responseBody.error.message;
- } else {
- errorMessage = responseBody.message;
- }
- } else {
- errorMessage = this.feedbackBadErrloginMessage;
- }
- this.setErrors(errorMessage);
- return true;
- }
- }
- @action
- setErrors = error => {
- if (this.isString(error)) {
- this.errors = [error];
- } else if (this.isArray(error)) {
- this.errors = _.map(error, e => e.message);
- }
- };
- @action
- isString(value) {
- return typeof value === "string" || value instanceof String;
- }
- @action
- isArray(value) {
- return value && typeof value === "object" && value.constructor === Array;
- }
- @action
- validateRestrictedPayee(restrictedPayeeReqModel, succCB, errCB) {
- console.log("Endpoint on RestrictedPayeeStore.validateRestrictedPayee");
- this.errors = [];
- ClientMiddleware.post(
- ClientConfig.apiEndpoints.restrictedPayeeValidate,
- restrictedPayeeReqModel,
- succCB,
- err => {
- this.hasErrors(err);
- errCB && errCB(err);
- }
- );
- }
- @action
- addRestrictedPayee(restrictedPayeeReqModel, succCB, errCB) {
- console.log("Endpoint on restrictedPayeeStore.addrestrictedPayee");
- ClientMiddleware.post(
- ClientConfig.apiEndpoints.restrictedPayeeAdd,
- restrictedPayeeReqModel,
- succCB,
- err => {
- this.hasErrors(err);
- errCB && errCB(err);
- }
- );
- }
- @action
- editrestrictedPayee(restrictedPayeeReqModel, succCB, errCB) {
- console.log("Endpoint on restrictedPayeeStore.editrestrictedPayee");
- ClientMiddleware.put(
- ClientConfig.apiEndpoints.restrictedPayeeEdit,
- restrictedPayeeReqModel,
- succCB,
- err => {
- this.hasErrors(err);
- errCB && errCB(err);
- }
- );
- }
- @action
- deleteRestrictedPayee(restrictedPayee, succCB, errCB) {
- console.log("Endpoint on restrictedPayee.deleterestrictedPayee");
- ClientMiddleware.post(
- ClientConfig.apiEndpoints.restrictedPayeeDelete,
- restrictedPayee,
- succCB,
- err => {
- this.hasErrors(err);
- errCB && errCB(err);
- }
- );
- }
- @action
- deleteMultiplerestrictedPayee(
- localUserCd,
- restrictedPayeeList,
- succCB,
- errCB
- ) {
- console.log(
- "Endpoint on restrictedPayeeStore.deleteMultiplerestrictedPayee"
- );
- ClientMiddleware.post(
- ClientConfig.apiEndpoints.restrictedPayeeDeleteMultiple,
- { restrictedPayeeList, localUserCd },
- succCB,
- err => {
- this.hasErrors(err);
- errCB && errCB(err);
- }
- );
- }
- @action
- findBySearchModel(search, multiSort, succCB, errCB) {
- console.log(
- "Endpoint on restrictedPayeeStore.restrictedPayeeFindBySearchModel"
- );
- ClientMiddleware.post(
- ClientConfig.apiEndpoints.restrictedPayeeFindBySearchModel,
- { search, multiSort },
- succCB,
- err => {
- this.hasErrors(err);
- errCB && errCB(err);
- }
- );
- }
- @action
- findBySearchModelForMaintenance(search, multiSort, succCB, errCB) {
- console.log(
- "Endpoint on restrictedPayeeStore.findBySearchModelForMaintenance"
- );
- ClientMiddleware.post(
- ClientConfig.apiEndpoints.restrictedPayeeFindBySearchModelForMaintenance,
- { search, multiSort },
- succCB,
- err => {
- this.hasErrors(err);
- errCB && errCB(err);
- }
- );
- }
- @action
- validateApproval(validateApprovalReqModel, succCB, errCB) {
- console.log("Endpoint on restrictedPayeeStore.validateApproval");
- this.errors = [];
- ClientMiddleware.post(
- ClientConfig.apiEndpoints.validateRestrictedPayeeApproval,
- validateApprovalReqModel,
- succCB,
- errCB
- );
- }
- @action
- approveList(reqModel, succCB, errCB) {
- console.log("Endpoint on restrictedPayeeStore.approveList");
- ClientMiddleware.post(
- ClientConfig.apiEndpoints.restrictedPayeeApproveList,
- reqModel,
- succCB,
- err => {
- this.hasErrors(err);
- errCB && errCB(err);
- }
- );
- }
- }