import { P2P_MESSAGE_TYPE, P2P_NOD_SPECIAL_VALUE } from '../../../enum/p2p'; import NoticeOfDiscrepancy from '../../../pages/p2p/noticeOfDiscrepancy.page'; import P2PMessage from '../../../pages/p2p/p2pMessage.page'; import { getP2PShortTodayStr, getTimestampStr } from '../../../util/dateUtil'; import { recordLatestGeneraP2PThread } from '../../../util/p2pContextUtil'; import scenarioContext from '../../../util/scenarioContext'; import { getNoticeOfDiscrepancyFromRowsHash } from '../nod/glue/getNoticeOfDiscrepancyFromRowsHash'; import { getGeneralMessageFromRowsHash } from './p2pGlueUtil'; const p2pMessagePage = new P2PMessage(); export async function fillInCreateP2PMessage(messageType: string, dataTable: { rowsHash: () => any }) { const rowsHash = dataTable.rowsHash(); const senderCompany = scenarioContext().currentLoggedInCompany; if (messageType === P2P_MESSAGE_TYPE.GENERAL) { await fillInGeneralMessage(senderCompany, rowsHash); } else if (messageType === P2P_MESSAGE_TYPE.NOTICE_OF_DISCREPANCY) { await fillInNoticeOfDiscrepancy(senderCompany, rowsHash); } } async function fillInGeneralMessage(senderCompany: string, rowsHash: any) { const message = getGeneralMessageFromRowsHash(senderCompany, rowsHash); await p2pMessagePage.getSubjectTextArea().setInputField(message.subject); message.recipients.displayNames.forEach(async (displayName) => { if (displayName !== message.sender.displayName) { await p2pMessagePage.getRecipientsDropdown().clickElement(); await p2pMessagePage.getRecipientsOption(displayName).clickElement(); } }); await p2pMessagePage.getFormMessageTextArea().setInputField(message.message); message.fullPathAttachments.forEach(async (fullFiePath) => { await p2pMessagePage.getAttachFileUpload().uploadFile(fullFiePath); }); recordLatestGeneraP2PThread( message.subject, message.message, message.sender.displayName, message.recipients.displayNames, getP2PShortTodayStr(), getTimestampStr(), message.fullPathAttachments ); } async function fillInNoticeOfDiscrepancy(senderCompany: string, rowsHash: any) { const nodPage = new NoticeOfDiscrepancy(); const message = getNoticeOfDiscrepancyFromRowsHash(senderCompany, rowsHash); if (message.recipients) { message.recipients.displayNames.forEach(async (displayName) => { if (displayName !== message.sender.displayName) { await p2pMessagePage.getRecipientsDropdown().clickElement(); await p2pMessagePage.getRecipientsOption(displayName).clickElement(); } }); } //TODO: figure out why principalAmount cannot be set amount if (message.principalAmount) { await nodPage.getPrincipalAmount().setInputField(message.principalAmount); } if (message.additionalAmount) { await nodPage.getAdditionalAmount().setInputField(message.additionalAmount); } if (message.chargesToBeAddedChecked === true) { await nodPage.getChargesToBeDeductedCheckbox().clickElement(); } if (message.chargesToBeDeductedAmount) { await await nodPage.getChargesToBeDeductedAmount().setInputField(message.chargesToBeDeductedAmount); } if (message.deductedChargeCodes) { message.deductedChargeCodes.forEach(async (code) => { switch (code.trim()) { case P2P_NOD_SPECIAL_VALUE.AGENT: await nodPage.getAgentChargeCodesToBeDeducted().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.COMM: await nodPage.getCommChargeCodesToBeDeducted().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.CORCOM: await nodPage.getCorcomChargeCodesToBeDeducted().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.DISC: await nodPage.getDiscChargeCodesToBeDeducted().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.INSUR: await nodPage.getInsurChargeCodesToBeDeducted().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.POST: await nodPage.getPostChargeCodesToBeDeducted().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.STAMP: await nodPage.getStampChargeCodesToBeDeducted().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.TELECHAR: await nodPage.getTelecharChargeCodesToBeDeducted().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.WAREHOUS: await nodPage.getWarehousChargeCodesToBeDeducted().clickElement(); break; } }); } if (message.chargesToBeDeductedDetails) { await nodPage.getChargesToBeDeductedDetails().setInputField(message.chargesToBeDeductedDetails); } if (message.chargesToBeAddedChecked === true) { await nodPage.getChargesToBeAddedCheckbox().clickElement(); } if (message.chargesToBeDeductedAmount) { await nodPage.getChargesToBeAddedAmount().setInputField(message.chargesToBeAddedAmount); } if (message.addedChargeCodes) { message.addedChargeCodes.forEach(async (code) => { switch (code.trim()) { case P2P_NOD_SPECIAL_VALUE.ACCPTCOM: await nodPage.getAccptcomChargeCodesToBeAdded().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.ADVCOM: await nodPage.getAdvcomChargeCodesToBeAdded().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.AMNDCOM: await nodPage.getAmndcomChargeCodesToBeAdded().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.CONFCOM: await nodPage.getConfcomChargeCodesToBeAdded().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.CORCOM: await nodPage.getCorcomChargeCodesToBeAdded().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.DEFCOM: await nodPage.getDefcomChargeCodesToBeAdded().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.DSCRPCOM: await nodPage.getDscrpcomChargeCodesToBeAdded().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.HANDLCOM: await nodPage.getHandlcomChargeCodesToBeAdded().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.INTEREST: await nodPage.getInterestChargeCodesToBeAdded().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.MISC: await nodPage.getMiscChargeCodesToBeAdded().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.NEGCOM: await nodPage.getNegcomChargeCodesToBeAdded().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.NOTFCOM: await nodPage.getNotfcomChargeCodesToBeAdded().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.PAYCOM: await nodPage.getPaycomChargeCodesToBeAdded().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.POST: await nodPage.getPostChargeCodesToBeAdded().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.PREADCOM: await nodPage.getPreadcomChargeCodesToBeAdded().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.SEE72Z: await nodPage.getSee72ZChargeCodesToBeAdded().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.SEE77: await nodPage.getSee77ChargeCodesToBeAdded().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.STAMP: await nodPage.getStampChargeCodesToBeAdded().clickElement(); break; case P2P_NOD_SPECIAL_VALUE.TELECHAR: await nodPage.getTelecharChargeCodesToBeAdded().clickElement(); break; } }); } if (message.chargesToBeAddedDetails) { await nodPage.getChargesToBeAddedDetails().setInputField(message.chargesToBeAddedDetails); } if (message.totalAmountToBePaid) { await nodPage.getTotalAmount().setInputField(message.totalAmountToBePaid); } if (message.accountWithBank) { await nodPage.getAccountWithBank().setInputField(message.accountWithBank); } if (message.senderToReceiverInformation) { await nodPage.getSenderToReceiver().setInputField(message.senderToReceiverInformation); } if (message.noticeOfDiscrepancies) { await nodPage.getNoticeOfDiscrepancies().setInputField(message.noticeOfDiscrepancies); } }