UNPKG

viam-projectv-scan

Version:

ViaCheck deposit application

211 lines (195 loc) 7.39 kB
const CheckCommonRules = require('./checkCommonRules'); const CHECK_LIMIT_DEPOSIT = 21; export const markChecksDeposited = ( checksArray, checksSentDeposit, isDeposited, isSentDeposit ) => { const newChecksArray = checksArray; checksSentDeposit.forEach(check => { const index = CheckCommonRules.getCheckArrayIndex(newChecksArray, check); newChecksArray[index].isDeposited = isDeposited; newChecksArray[index].isSentDeposit = isSentDeposit; }); return checksArray; }; export const getChecksForReceipt = (checkReceipt, checkInformationList) => { const newCheckRecepit = checkReceipt; checkInformationList.forEach(check => { newCheckRecepit.push(check); }); return newCheckRecepit; }; const getCheckHoldRestriction = onHoldResults => { let onHoldInformation = null; if (onHoldResults !== null && onHoldResults !== undefined) { if ( onHoldResults.restrictionInformation !== null && onHoldResults.restrictionInformation !== undefined ) { onHoldInformation = onHoldResults.restrictionInformation.onHoldReasonList; } } return onHoldInformation; }; const getCheckHoldStatus = (checksOnHoldArray, check) => { let onHoldResults = null; const onHoldResultsList = checksOnHoldArray.filter(function getCheckWithHold( onHoldElement ) { return onHoldElement.id === check.scanOrder; }); if (onHoldResultsList !== null && onHoldResultsList !== undefined) { if (onHoldResultsList.length > 0) { [onHoldResults] = onHoldResultsList; } } return onHoldResults; }; const getFronImage = (imagesArray, scanOrder) => { const images = imagesArray.filter(function getElement(check) { return check.scanOrder === scanOrder; }); return images[0]; }; // Check deposit export const createNewChecksArray = ( batch, depositArray, imagesArray, checksOnHoldArray ) => { const newChecksArray = []; let limit = 0; depositArray.forEach(check => { const newCheck = check; const onHoldResults = getCheckHoldStatus(checksOnHoldArray, newCheck); const onHoldInformation = getCheckHoldRestriction(onHoldResults); if (limit < CHECK_LIMIT_DEPOSIT && !newCheck.isDeposit) { limit += 1; newCheck.isDeposited = false; newCheck.isSentDeposit = true; newChecksArray.push({ id: newCheck.scanOrder, userName: newCheck.userName, agencyName: newCheck.agencyName, batchId: batch, mircLine: newCheck.mircLine === null || newCheck.mircLine === '' ? 'NA' : newCheck.mircLine, bank: newCheck.bank === null || newCheck.bank === '' ? 'NA' : newCheck.bank, limitRoutingScore: newCheck.limitRoutingScore, limitCheckNumberScore: newCheck.limitCheckNumberScore, limitAmountScore: newCheck.limitAmountScore, limitDateScore: newCheck.limitDateScore, limitAccountScore: newCheck.limitAccountScore, returnedChecksMaker: newCheck.returnedChecksMaker, issuedChecksMaker: newCheck.issuedChecksMaker, updateMakerCorrected : (newCheck.isMakerCorrected && newCheck.isModifiedFields.maker) , account: newCheck.account, checkNumber: newCheck.checkNumber, amount: newCheck.amount.toString(), routing: newCheck.routing, checkStatus: onHoldResults !== null && onHoldResults !== undefined ? onHoldResults.status.code : '0', checkDate: newCheck.checkDate === '' || newCheck.checkDate === null ? 'NA' : newCheck.checkDate.replace('0/0/0', 'NA'), payee: newCheck.payee === null || newCheck.payee === '' ? 'NA' : newCheck.payee, payerAddressName: newCheck.payerAddressName === '' || newCheck.payerAddressName === null ? 'NA' : newCheck.payerAddressName, payerAddressDestination: newCheck.payerAddressDestination === '' || newCheck.payerAddressDestination === null ? 'NA' : newCheck.payerAddressDestination, payerAddressZipCode: newCheck.payerAddressZipCode === '' || newCheck.payerAddressZipCode === null ? 'NA' : newCheck.payerAddressZipCode, lar: newCheck.lar === null || newCheck.lar === '' ? 'NA' : newCheck.lar, signature: newCheck.signature === null || newCheck.signature === '' ? 'NA' : newCheck.signature, checkType: newCheck.checkType === null || newCheck.checkType === '' ? 'NA' : newCheck.checkType, originalAmount: newCheck.originalAmount === 'NA' || newCheck.originalAmount === '' || newCheck.originalAmount === null ? '0' : newCheck.originalAmount, originalRouting: newCheck.originalRouting === '' || newCheck.originalRouting === null ? 'NA' : newCheck.originalRouting, originalAccount: newCheck.originalAccount === '' || newCheck.originalAccount === null ? 'NA' : newCheck.originalAccount, originalCheckNumber: newCheck.originalCheckNumber === '' || newCheck.originalCheckNumber === null ? 'NA' : newCheck.originalCheckNumber, modified: newCheck.modified, reprocess: newCheck.reprocess, checkFrontObjectBase64: getFronImage(imagesArray, newCheck.scanOrder) .frontImage, checkBackObjectBase64: getFronImage(imagesArray, newCheck.scanOrder) .backImage, scoreFields: { amount: newCheck.scoreFields.amount, checkNumber: newCheck.scoreFields.checkNumber, checkType: newCheck.scoreFields.checkType, checkDate: newCheck.scoreFields.checkDate, mircLine: newCheck.scoreFields.mircLine, payee: newCheck.scoreFields.payee, lar: newCheck.scoreFields.lar, signature: newCheck.scoreFields.signature, payerFullName: newCheck.scoreFields.payerFullName, payerAddressName: newCheck.scoreFields.payerAddressName, payerAddressDestination: newCheck.scoreFields.payerAddressDestination, payerAddressZipCode: newCheck.scoreFields.payerAddressZipCode }, onHoldRestrictions: { id: onHoldResults !== null && onHoldResults !== undefined ? onHoldResults.id : 0, status: onHoldResults !== null && onHoldResults !== undefined ? onHoldResults.status : 'NA', restrictionInformation: onHoldInformation !== null && onHoldInformation !== undefined ? onHoldInformation : 'NA' } }); } }); // console.log(newChecksArray); return newChecksArray; }; export const getChecksForDeposit = checksArray => { const newcheckarray = checksArray.filter(function getElement(check) { return check.isDeposited === false && check.isSentDeposit === false; }); return newcheckarray; };