Facebook
From akoto, 4 Years ago, written in Plain Text.
This paste is a reply to ApproveRestrictedPayeeCTR from akoto - view diff
Embed
Download Paste or View Raw
Hits: 239
  1. /**
  2.  * RestrictedPayeeStore.js
  3.  */
  4.  
  5. import {
  6.   observable,
  7.   extendObservable,
  8.   action,
  9.   asMap,
  10.   reaction,
  11.   autorunm,
  12.   toJS
  13. } from "mobx";
  14. import _ from "underscore";
  15. import ClientConfig from "../config/ClientConfig";
  16. import { BaseMiddlewares } from "frontend-react-f4-base-commons";
  17. const { ClientMiddleware } = BaseMiddlewares;
  18. import { BaseComponents } from "frontend-react-f4-base-ui";
  19. import CitrineFunctionCodes from "../enums/CitrineFunctionCodes";
  20. import moment from "moment";
  21. const { strings } = BaseComponents;
  22. import YesOrNoEnum from "../enums/YesOrNoEnum";
  23.  
  24. export default class RestrictedPayeeStore {
  25.   constructor(RestrictedPayeeStore) {
  26.     if (RestrictedPayeeStore) {
  27.       Object.assign(this, RestrictedPayeeStore);
  28.     }
  29.  
  30.     this.reset();
  31.     this.resetInputs();
  32.     this.resetErrorList();
  33.     this.resetSearchFields();
  34.     this.resetApprovalFields();
  35.   }
  36.  
  37.   @action
  38.   reset() {
  39.     extendObservable(this, {
  40.       copyFromStore: null,
  41.       hasManualAuth: false,
  42.       hasUploadAuth: false,
  43.       isManual: true,
  44.  
  45.       clickedNext: false,
  46.       clickedBack: false,
  47.       previousData: null,
  48.       dataTableRef: null,
  49.       isforView: false,
  50.       dataTableStore: {
  51.         getTotal: null
  52.       },
  53.       selectedMenuOnAdd: 0,
  54.       selectedMenuOnEdit: 0,
  55.       selectedMenuOnApprove: 0,
  56.       selectedMenuOnSearch: 0,
  57.       fields: {
  58.         payeeName: strings.global_restrictedpayeenm,
  59.         amount: strings.global_amount,
  60.         isAllowed: strings.global_isallowed,
  61.         charToIgnore: strings.global_character_ignore
  62.       },
  63.       copyFromFields: [
  64.         {
  65.           key: "amount"
  66.         }
  67.       ],
  68.       payeeFields: [
  69.         {
  70.           key: "payeeName",
  71.           label: strings.global_restrictedpayeenm
  72.         },
  73.         {
  74.           key: "amount",
  75.           label: strings.global_amount
  76.         },
  77.         {
  78.           key: "isAllowed",
  79.           label: strings.global_isallowed
  80.         },
  81.         {
  82.           key: "charToIgnore",
  83.           label: strings.global_character_ignore
  84.         }
  85.       ],
  86.       payeeSaved: null,
  87.       refNoDeleteMultiple: null,
  88.  
  89.       isForApproval: false,
  90.       ackMessage: {
  91.         header: null,
  92.         refNo: null
  93.       },
  94.       approveListReqModel: {
  95.         localUserCd: null,
  96.         maintenanceList: null,
  97.         isApprove: false
  98.       },
  99.       approvalConfirmProps: {
  100.         action: null,
  101.         remarks: "",
  102.         dataList: null
  103.       },
  104.       approvalAckProps: {
  105.         dataList: null,
  106.         action: null,
  107.         remarks: null,
  108.         refNo: null,
  109.         message: null
  110.       },
  111.       viewPageMaintenanceData: null,
  112.       uploadFields: {
  113.         payeeName: null,
  114.         amount: 0,
  115.         isAllowed: false,
  116.         charToIgnore: null
  117.       },
  118.       searchFilter: {
  119.         payeeName: null,
  120.         amount: 0,
  121.         isAllowed: false,
  122.         charToIgnore: null,
  123.         restrictedPayeeDate: null,
  124.         filterList: [],
  125.         isInquiry: true,
  126.         maker: null,
  127.         requiresApprovalFuncCd:
  128.           CitrineFunctionCodes.RESTRICTED_PAYEE_NM_REQUIRES_APPROVAL
  129.       },
  130.       // transactionOptionsRadioButton: [
  131.       //   {
  132.       //     value: 0,
  133.       //     label: "Disallow Payee"
  134.       //   },
  135.       //   {
  136.       //     value: 1,
  137.       //     label: "Allow Payee but with Override"
  138.       //   }
  139.       // ],
  140.       isAllowed: [
  141.         {
  142.           value: 0,
  143.           label: "Disallow Payee"
  144.         },
  145.         {
  146.           value: 1,
  147.           label: "Allow Payee but with Override"
  148.         }
  149.       ]
  150.     });
  151.   }
  152.  
  153.   @observable responseBody = null;
  154.   @observable restrictedPayeeList = null;
  155.   @observable restrictedPayeeDtlString = null;
  156.  
  157.   @action getFieldLabel(key) {
  158.     let field = _.findWhere(this.payeeFields, {
  159.       key: key
  160.     });
  161.     return field ? field.label : "";
  162.   }
  163.  
  164.   @action resetErrorList() {
  165.     extendObservable(this, {
  166.       errors: []
  167.     });
  168.   }
  169.  
  170.   @action initializeMaintenanceModel(data, actnFuncCd, userCd, grpId) {
  171.     let isAdd = actnFuncCd === CitrineFunctionCodes.RESTRICTED_PAYEE_NM_ADD;
  172.     let editFuncCd =
  173.       actnFuncCd === isAdd
  174.         ? null
  175.         : CitrineFunctionCodes.RESTRICTED_PAYEE_NM_EDIT;
  176.     let deleteFuncCd = isAdd
  177.       ? null
  178.       : CitrineFunctionCodes.RESTRICTED_PAYEE_NM_DEL;
  179.  
  180.     return {
  181.       localUserCd: userCd,
  182.       requiresApprovalFuncCd:
  183.         CitrineFunctionCodes.RESTRICTED_PAYEE_NM_REQUIRES_APPROVAL,
  184.       actnFuncCd: actnFuncCd,
  185.       approveRejectFuncCd:
  186.         CitrineFunctionCodes.RESTRICTED_PAYEE_NM_APPROVE_REJECT,
  187.       addFuncCd: isAdd ? CitrineFunctionCodes.RESTRICTED_PAYEE_NM_ADD : null,
  188.       editFuncCd: editFuncCd,
  189.       deleteFuncCd: deleteFuncCd,
  190.       modelNm: strings.global_payee,
  191.       grpId: grpId,
  192.       isAdd: isAdd,
  193.       dtlString: JSON.stringify({
  194.         id: isAdd ? null : data.id,
  195.         cd: isAdd ? null : data.cd,
  196.         funcCd: data.funcCd,
  197.         payeeName: data.payeeName,
  198.         amount: data.amount,
  199.         charToIgnore: data.charToIgnore,
  200.         isAllowed: data.isAllowed,
  201.         version: isAdd ? null : data.version
  202.       }),
  203.       filterValues: [
  204.         data.payeeName,
  205.         data.amount,
  206.         data.isAllowed,
  207.         data.charToIgnore
  208.       ],
  209.       uniqueCds: [data.payeeName]
  210.     };
  211.   }
  212.  
  213.   @action resetInputs() {
  214.     extendObservable(this, {
  215.       restrictedPayeeInputs: {
  216.         localUserCd: null,
  217.         id: null,
  218.         payeeName: "",
  219.         amount: 0,
  220.         isAllowed: true,
  221.         isAllowedStr: "",
  222.         transactionOptionRadioButton: 0,
  223.         charToIgnore: null,
  224.         showEdit: false
  225.       }
  226.     });
  227.   }
  228.  
  229.   @action resetSearchFields() {
  230.     extendObservable(this, {
  231.       searchRestrictedPayeeFields: [
  232.         {
  233.           index: "payeeName",
  234.           label: strings.global_restrictedpayeenm,
  235.           type: "text",
  236.           content: null,
  237.           value: null
  238.         },
  239.         {
  240.           index: "amount",
  241.           label: strings.global_amount,
  242.           type: "text",
  243.           content: null,
  244.           value: null
  245.         },
  246.         {
  247.           index: "isAllowed",
  248.           label: strings.global_action,
  249.           type: "radio",
  250.           content: [
  251.             {
  252.               value: 1,
  253.               // label: YesOrNoEnum.getDescriptionFromKey(1)
  254.               label: "Allow Payee but with Override"
  255.             },
  256.             {
  257.               value: 0,
  258.               // label: YesOrNoEnum.getDescriptionFromKey(0)
  259.               label: "Disallow Payee"
  260.             },
  261.             {
  262.               value: 2,
  263.               label: strings.global_all
  264.             }
  265.           ],
  266.           value: 2,
  267.           defaultValue: 2
  268.         }
  269.       ]
  270.     });
  271.   }
  272.  
  273.   @action
  274.   resetSearchFilters() {
  275.     extendObservable(this, {});
  276.   }
  277.  
  278.   @action
  279.   resetApprovalFields() {
  280.     extendObservable(this, {
  281.       approvalFields: [
  282.         {
  283.           index: "refNo",
  284.           label: strings.global_refno,
  285.           type: "text",
  286.           content: null,
  287.           value: null
  288.         },
  289.         {
  290.           index: "filterOne",
  291.           label: strings.global_restrictedpayeenm,
  292.           type: "text",
  293.           content: null,
  294.           value: null,
  295.           filterType: {
  296.             isEq: true,
  297.             isCaseSensitive: true
  298.           }
  299.         },
  300.         {
  301.           index: "filterTwo",
  302.           label: strings.global_amount,
  303.           type: "text",
  304.           content: null,
  305.           value: null,
  306.           filterType: {
  307.             isEq: true,
  308.             isCaseSensitive: true
  309.           }
  310.         },
  311.         // {
  312.         //   index: "filterThree",
  313.         //   label: strings.global_isallowed,
  314.         //   type: "text",
  315.         //   content: null,
  316.         //   value: null,
  317.         //   filterType: {
  318.         //     isEq: true,
  319.         //     isCaseSensitive: true
  320.         //   }
  321.         // },
  322.         // {
  323.         //   index: "filterFour",
  324.         //   label: "Characters To Ignore",
  325.         //   type: "text",
  326.         //   content: null,
  327.         //   value: null,
  328.         //   filterType: {
  329.         //     isEq: true,
  330.         //     isCaseSensitive: true
  331.         //   }
  332.         // },
  333.         {
  334.           index: "fromDate",
  335.           label: strings.global_creatddt,
  336.           type: "dateBetween",
  337.           content: null,
  338.           value: moment()
  339.             .subtract(2, "months")
  340.             .add(1, "days"),
  341.           children: null
  342.         },
  343.         {
  344.           index: "toDate",
  345.           label: strings.global_creatddt,
  346.           type: "dateBetween",
  347.           content: null,
  348.           value: moment(),
  349.           children: null
  350.         }
  351.       ]
  352.     });
  353.   }
  354.  
  355.   @action
  356.   hasErrors(responseBody) {
  357.     if (responseBody && !responseBody.error) {
  358.       return false;
  359.     } else {
  360.       let errorMessage = null;
  361.       if (
  362.         responseBody &&
  363.         responseBody.error &&
  364.         responseBody.statusCode != 500
  365.       ) {
  366.         if (responseBody.error.errors) {
  367.           errorMessage = responseBody.error.errors;
  368.         } else if (responseBody.error.message) {
  369.           errorMessage = responseBody.error.message;
  370.         } else {
  371.           errorMessage = responseBody.message;
  372.         }
  373.       } else {
  374.         errorMessage = this.feedbackBadErrloginMessage;
  375.       }
  376.       this.setErrors(errorMessage);
  377.       return true;
  378.     }
  379.   }
  380.  
  381.   @action
  382.   setErrors = error => {
  383.     if (this.isString(error)) {
  384.       this.errors = [error];
  385.     } else if (this.isArray(error)) {
  386.       this.errors = _.map(error, e => e.message);
  387.     }
  388.   };
  389.  
  390.   @action
  391.   isString(value) {
  392.     return typeof value === "string" || value instanceof String;
  393.   }
  394.  
  395.   @action
  396.   isArray(value) {
  397.     return value && typeof value === "object" && value.constructor === Array;
  398.   }
  399.  
  400.   @action
  401.   validateRestrictedPayee(restrictedPayeeReqModel, succCB, errCB) {
  402.     console.log("Endpoint on RestrictedPayeeStore.validateRestrictedPayee");
  403.     this.errors = [];
  404.  
  405.     ClientMiddleware.post(
  406.       ClientConfig.apiEndpoints.restrictedPayeeValidate,
  407.       restrictedPayeeReqModel,
  408.       succCB,
  409.       err => {
  410.         this.hasErrors(err);
  411.         errCB && errCB(err);
  412.       }
  413.     );
  414.   }
  415.  
  416.   @action
  417.   addRestrictedPayee(restrictedPayeeReqModel, succCB, errCB) {
  418.     console.log("Endpoint on restrictedPayeeStore.addrestrictedPayee");
  419.     ClientMiddleware.post(
  420.       ClientConfig.apiEndpoints.restrictedPayeeAdd,
  421.       restrictedPayeeReqModel,
  422.       succCB,
  423.       err => {
  424.         this.hasErrors(err);
  425.         errCB && errCB(err);
  426.       }
  427.     );
  428.   }
  429.  
  430.   @action
  431.   editrestrictedPayee(restrictedPayeeReqModel, succCB, errCB) {
  432.     console.log("Endpoint on restrictedPayeeStore.editrestrictedPayee");
  433.     ClientMiddleware.put(
  434.       ClientConfig.apiEndpoints.restrictedPayeeEdit,
  435.       restrictedPayeeReqModel,
  436.       succCB,
  437.       err => {
  438.         this.hasErrors(err);
  439.         errCB && errCB(err);
  440.       }
  441.     );
  442.   }
  443.  
  444.   @action
  445.   deleteRestrictedPayee(restrictedPayee, succCB, errCB) {
  446.     console.log("Endpoint on restrictedPayee.deleterestrictedPayee");
  447.     ClientMiddleware.post(
  448.       ClientConfig.apiEndpoints.restrictedPayeeDelete,
  449.       restrictedPayee,
  450.       succCB,
  451.       err => {
  452.         this.hasErrors(err);
  453.         errCB && errCB(err);
  454.       }
  455.     );
  456.   }
  457.  
  458.   @action
  459.   deleteMultiplerestrictedPayee(
  460.     localUserCd,
  461.     restrictedPayeeList,
  462.     succCB,
  463.     errCB
  464.   ) {
  465.     console.log(
  466.       "Endpoint on restrictedPayeeStore.deleteMultiplerestrictedPayee"
  467.     );
  468.     ClientMiddleware.post(
  469.       ClientConfig.apiEndpoints.restrictedPayeeDeleteMultiple,
  470.       { restrictedPayeeList, localUserCd },
  471.       succCB,
  472.       err => {
  473.         this.hasErrors(err);
  474.         errCB && errCB(err);
  475.       }
  476.     );
  477.   }
  478.  
  479.   @action
  480.   findBySearchModel(search, multiSort, succCB, errCB) {
  481.     console.log(
  482.       "Endpoint on restrictedPayeeStore.restrictedPayeeFindBySearchModel"
  483.     );
  484.     ClientMiddleware.post(
  485.       ClientConfig.apiEndpoints.restrictedPayeeFindBySearchModel,
  486.       { search, multiSort },
  487.       succCB,
  488.       err => {
  489.         this.hasErrors(err);
  490.         errCB && errCB(err);
  491.       }
  492.     );
  493.   }
  494.  
  495.   @action
  496.   findBySearchModelForMaintenance(search, multiSort, succCB, errCB) {
  497.     console.log(
  498.       "Endpoint on restrictedPayeeStore.findBySearchModelForMaintenance"
  499.     );
  500.     ClientMiddleware.post(
  501.       ClientConfig.apiEndpoints.restrictedPayeeFindBySearchModelForMaintenance,
  502.       { search, multiSort },
  503.       succCB,
  504.       err => {
  505.         this.hasErrors(err);
  506.         errCB && errCB(err);
  507.       }
  508.     );
  509.   }
  510.  
  511.   @action
  512.   validateApproval(validateApprovalReqModel, succCB, errCB) {
  513.     console.log("Endpoint on restrictedPayeeStore.validateApproval");
  514.     this.errors = [];
  515.  
  516.     ClientMiddleware.post(
  517.       ClientConfig.apiEndpoints.validateRestrictedPayeeApproval,
  518.       validateApprovalReqModel,
  519.       succCB,
  520.       errCB
  521.     );
  522.   }
  523.  
  524.   @action
  525.   approveList(reqModel, succCB, errCB) {
  526.     console.log("Endpoint on restrictedPayeeStore.approveList");
  527.  
  528.     ClientMiddleware.post(
  529.       ClientConfig.apiEndpoints.restrictedPayeeApproveList,
  530.       reqModel,
  531.       succCB,
  532.       err => {
  533.         this.hasErrors(err);
  534.         errCB && errCB(err);
  535.       }
  536.     );
  537.   }
  538. }
  539.