Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by gporosnicu on 17.10.2022.
- */
- import { LightningElement, api, track, wire } from 'lwc';
- import { ShowToastEvent } from 'lightning/platformShowToastEvent';
- import { updateRecord } from 'lightning/uiRecordApi';
- import userId from '@salesforce/schema/User.Id';
- //Import Custom Labels
- import EL_Account_Balance_Information from '@salesforce/label/c.EL_Account_Balance_Information';
- import EL_Account_Balance from '@salesforce/label/c.EL_Account_balance';
- import EL_Account_Balance_More_Than_9_Contract_Accounts_Message from '@salesforce/label/c.EL_Account_Balance_More_Than_9_Contract_Accounts_Message';
- import EL_Account_Balance_Open_Invoices_Timeout_Message from '@salesforce/label/c.EL_Account_Balance_Open_Invoices_Timeout_Message';
- import EL_Contract_Account from '@salesforce/label/c.EL_Contract_Account';
- import EL_Contract_Account_with_Highest_Dunning_Level from '@salesforce/label/c.EL_Contract_Account_with_Highest_Dunning_Level';
- import EL_Document_Date from '@salesforce/label/c.EL_Document_Date';
- import EL_Due_Date from '@salesforce/label/c.EL_Due_Date';
- import EL_Reported_Due_Date from '@salesforce/label/c.EL_Reported_Due_Date';
- import EL_Dunning_Level from '@salesforce/label/c.EL_Dunning_Level';
- import EL_Dunning_Level_Icon from '@salesforce/label/c.EL_Dunning_Level_Icon';
- import EL_Invoice_Dunning_Level from '@salesforce/label/c.EL_Invoice_Dunning_Level';
- import EL_Invoice_Dunning_Level_Icon from '@salesforce/label/c.EL_Invoice_Dunning_Level_Icon';
- import EL_Invoice_Number from '@salesforce/label/c.EL_Invoice_Number';
- import EL_Open_Amount from '@salesforce/label/c.EL_Open_Amount';
- import EL_Open_Invoices from '@salesforce/label/c.EL_Open_Invoices';
- import EL_Open_Invoices_for_Contract_Account from '@salesforce/label/c.EL_Open_Invoices_for_Contract_Account';
- import EL_Site_Address from '@salesforce/label/c.EL_Site_Address';
- import EL_Total_Open_Amount from '@salesforce/label/c.EL_Total_Open_Amount';
- import EL_Total_Open_Amount_Information from '@salesforce/label/c.EL_Total_Open_Amount_Information';
- //Dunning Level Labels
- import BAILIFF from '@salesforce/label/c.EL_Dunning_Level_Bailiff';
- import BANKRUPTCY from '@salesforce/label/c.EL_Dunning_Level_Bankruptcy';
- import CUTOFF from '@salesforce/label/c.EL_Dunning_Level_Cutoff';
- import EXTERNAL_OFFICES from '@salesforce/label/c.EL_Dunning_Level_External_Offices';
- import INSOLVENT from '@salesforce/label/c.EL_Dunning_Level_Insolvent';
- import LAST_REMINDER from '@salesforce/label/c.EL_Dunning_Level_Last_Reminder';
- import OVERDEBTNESS from '@salesforce/label/c.EL_Dunning_Level_Overdebtness';
- import PAYMENT_ORDER from '@salesforce/label/c.EL_Dunning_Level_Payment_Order';
- import REMINDER_LEVEL_1 from '@salesforce/label/c.EL_Dunning_Level_Reminder_level_01';
- import REMINDER_LEVEL_2 from '@salesforce/label/c.EL_Dunning_Level_Reminder_level_02';
- import REMINDER_LEVEL_3 from '@salesforce/label/c.EL_Dunning_Level_Reminder_level_03';
- import WAGE_GARNISHMENT from '@salesforce/label/c.EL_Dunning_Level_Wage_Garnishment';
- //Import Apex
- import getAccountBalance from '@salesforce/apex/EL_AccountBalance_Controller.getAccountBalance';
- import getAccount from '@salesforce/apex/EL_AccountBalance_Controller.getAccount';
- import getSubscription from '@salesforce/apex/EL_AccountBalance_Controller.getSubscription';
- import getSubscriptionsBySAPContractAccount from '@salesforce/apex/EL_AccountBalance_Controller.getSubscriptionsBySAPContractAccount';
- import saveAccountBalanceReportedDate from '@salesforce/apex/EL_AccountBalance_Controller.saveAccountBalanceReportedDate';
- import getUserRole from '@salesforce/apex/EL_AccountBalance_Controller.getUserRole';
- //Import Custom Colors from static resource
- import {loadStyle} from 'lightning/platformResourceLoader'
- import COLORS from '@salesforce/resourceUrl/EL_Custom_Colors'
- //Table 1 columns
- const columnsTable1 = [
- { label: EL_Contract_Account, fieldName: 'contractAccount', type: 'text', sortable: true, wrapText: true, cellAttributes: { alignment: 'center' } },
- { label: EL_Site_Address, fieldName: 'siteAddress', type: 'text', sortable: true, wrapText: true, cellAttributes: { alignment: 'center' } },
- { label: EL_Total_Open_Amount, fieldName: 'totalOpenAmount', type: 'number', sortable: true, wrapText: true, cellAttributes: { alignment: 'center' } },
- { label: EL_Dunning_Level, fieldName: 'dunningLevel', type: 'text', sortable: true, wrapText: true, cellAttributes: { alignment: 'center' } },
- { label: 'Indicator', fieldName: '', type: 'text', wrapText: true , initialWidth: 100, cellAttributes: { alignment: 'center', class: {fieldName: 'dunningLevelIcon'}}},
- { label: "", fieldName: 'openInvoices', type: 'button', cellAttributes: { alignment: 'center' }, typeAttributes: { label: EL_Open_Invoices, name: 'openInvoices', variant: 'outline-brand'} },
- { label: EL_Reported_Due_Date, fieldName: 'reportedDueDate', type: 'date-local',editable: true, sortable: true, wrapText: true , cellAttributes: { alignment: 'center' }}
- ];
- //Table 2 columns
- const columnsTable2 = [
- { label: EL_Invoice_Number, fieldName: 'invoiceNumber', type: 'text', sortable: true, wrapText: true, initialWidth: 220, cellAttributes: { alignment: 'center' } },
- { label: EL_Open_Amount, fieldName: 'amount', type: 'number', editable:true, sortable: true, wrapText: true, cellAttributes: { alignment: 'center' } },
- { label: EL_Invoice_Dunning_Level, fieldName: 'invoiceDunningLevel', type: 'text', sortable: true, wrapText: true, cellAttributes: { alignment: 'center' } },
- { label: 'Indicator', fieldName: '', type: 'text', sortable: true, wrapText: true, initialWidth: 100, cellAttributes: { alignment: 'center', class: {fieldName: 'invoiceDunningLevelIcon'} } },
- { label: EL_Document_Date, fieldName: 'documentDate', type: 'date-local', sortable: true, wrapText: true , cellAttributes: { alignment: 'center' }},
- { label: EL_Due_Date, fieldName: 'dueDate', type: 'date-local', sortable: true, wrapText: true , cellAttributes: { alignment: 'center' }},
- { label: 'Reported Due Date 2', fieldName: 'invoiceReportedDueDate', type: 'date-local', editable: true, sortable: true, wrapText: true , cellAttributes: { alignment: 'center' }}
- ];
- export default class elAccountBalance extends LightningElement {
- //Custom Labels
- labels = {
- EL_Account_Balance,
- EL_Account_Balance_Information,
- EL_Account_Balance_More_Than_9_Contract_Accounts_Message,
- EL_Account_Balance_Open_Invoices_Timeout_Message,
- EL_Contract_Account,
- EL_Contract_Account_with_Highest_Dunning_Level,
- EL_Document_Date,
- EL_Due_Date,
- EL_Reported_Due_Date,
- EL_Dunning_Level,
- EL_Dunning_Level_Icon,
- EL_Invoice_Dunning_Level,
- EL_Invoice_Dunning_Level_Icon,
- EL_Invoice_Number,
- EL_Open_Amount,
- EL_Open_Invoices,
- EL_Open_Invoices_for_Contract_Account,
- EL_Site_Address,
- EL_Total_Open_Amount,
- EL_Total_Open_Amount_Information
- }
- //Dunning Level Labels
- dunningLevelLabels = {
- BAILIFF,
- BANKRUPTCY,
- CUTOFF,
- EXTERNAL_OFFICES,
- INSOLVENT,
- LAST_REMINDER ,
- OVERDEBTNESS,
- PAYMENT_ORDER,
- REMINDER_LEVEL_1,
- REMINDER_LEVEL_2,
- REMINDER_LEVEL_3,
- WAGE_GARNISHMENT
- }
- //Track Variables
- @track data1 = [];
- @track data2 = [];
- @track columnsTable1 = columnsTable1;
- @track columnsTable2 = columnsTable2;
- @track defaultSortDirection1 = "desc";
- @track defaultSortDirection2 = "asc";
- @track sortDirection1;
- @track sortDirection2;
- @track sortedBy1 = "totalOpenAmount";
- @track sortedBy2 = "documentDate";
- @track showAccountBalanceInformationSection = false;
- @track showTotalOpenAmountInformationSection = false;
- @track showOpenInvoicesForContractAccountSection = false;
- @track totalOpenAmountOpenInvoice;
- @track reportedDueDate;
- @track invoiceReportedDueDate;
- @track contractAccount;
- @track subscriptionSAPContractAccount;
- @track listDataInput = [];
- @track inputElement;
- @track errors = {};
- @track wiredInvoicesResult;
- @track userRole;
- @track hasErrors;
- //Track Variables - Booleans
- @track showSpinner = false;
- @track showLWC = false;
- @track showMoreThan9ContractAccountsWarning = false;
- @track showTimeoutWarning = false;
- @track isRecordAccount = false;
- @track isRecordSubscription = false;
- //API variables
- @api recordId;
- @api bpNumber;
- //Constant Variables
- INTEGRATION_MESSAGE_STATUS_IN_ERROR = 'Read timed out';
- //User Role Variables
- USER_ROLE_SLPRO_SUPERVISOR = 'SLPro Supervisor';
- USER_ROLE_SLPRO_AGENT = 'SLPro Agent';
- USER_ROLE_CSC_SUPERVISOR = 'CSC Supervisor';
- USER_ROLE_CSC_AGENT = 'CSC Agent';
- //Other Variables
- responseFromSAP = [];
- responseSAPContractAccounts = new Map();
- isCssLoaded = false;
- dunningLevelColor = '';
- updatedDueDates = new WeakMap();
- draftValues = [];
- /********************************************************************************************************
- *
- * @description This is the start method of the LWC when the page loads.
- * @date 2022-10-19
- * US MP2-1023
- *********************************************************************************************************/
- connectedCallback(){
- //Spinner On
- this.showSpinner = true;
- //Get user Role
- getUserRole()//added via MP2-4111
- .then(result => {
- this.userRole = result;
- }).catch(error => {
- console.log('Error while getting the user role ' + JSON.stringify(error));
- })
- //Check if the record is an Account or Subscription
- this.checkRecordObjectType();
- }
- /********************************************************************************************************
- *
- * @description This is the rendering method of the LWC after everything on the page finish loading.
- * @date 2022-11-22
- * US MP2-1024
- *********************************************************************************************************/
- renderedCallback(){
- //If the page already rendered
- if(this.isCssLoaded) {
- return;
- } else {
- //If it's the first time the page finish loading
- this.isCssLoaded = true;
- //Load the COLORS css file
- loadStyle(this, COLORS).then(()=>{}).catch(error=>{
- //Error handling
- this.handleErrorDisplay(error);
- });
- }
- }
- /********************************************************************************************************
- *
- * @description This method will check whether the record is an Account or a Subscription
- * @date 2022-10-20
- * US MP2-1023
- *********************************************************************************************************/
- checkRecordObjectType() {
- if (String(this.recordId).startsWith('001')) {
- //Call this method from the controller to get the account record
- getAccount({
- accountId: this.recordId
- }).then(result => {
- //Populate fields from accounts to js variables
- this.bpNumber = result.EL_BP_Number__c;
- //Get the Account Balance from SAP
- this.getAccountBalanceFromSAP(1); // 1-Account ; 2-Subscription
- }).catch(error => {
- //Error handling
- this.handleErrorDisplay(error);
- });
- //Display components for account
- this.isRecordAccount = true;
- this.isRecordSubscription = false;
- } else if (String(this.recordId).startsWith('02i')){
- //Call this method from the controller to get the subscription record
- getSubscription({
- subscriptionId: this.recordId
- }).then(result => {
- //Populate fields from accounts to js variables
- this.bpNumber = result.Account.EL_BP_Number__c;
- this.subscriptionSAPContractAccount = result.EL_SAP_Contract_Account__c;
- //Get the Account Balance from SAP
- this.getAccountBalanceFromSAP(2); // 1-Account ; 2-Subscription
- }).catch(error => {
- //Error handling
- this.handleErrorDisplay(error);
- });
- //Display components for subscription
- this.isRecordAccount = false;
- this.isRecordSubscription = true;
- this.showOpenInvoicesForContractAccountSection = true;
- }
- }
- /********************************************************************************************************
- *
- * @description This method will GET the account balance from SAP and populate the front-end tables.
- * @date 2022-11-15
- * @param recordType: This variable will decide if the record is an Account or Subscription
- * @US MP2-1024
- *********************************************************************************************************/
- getAccountBalanceFromSAP(recordType){
- //Call this method from the controller to do the callout and retrieve the account balance
- getAccountBalance({
- recordId: this.recordId,
- bpNumber: this.bpNumber
- }).then(result => {
- //Move the response in a variable
- this.responseFromSAP = result;
- //Prepare local variables to prepare the table data
- let dataTable1 = [];
- let dataTable2 = [];
- //Prepare collection for the SAP Contract accounts
- let sapContractAccounts = [];
- //Check if there are more than 9 contract accounts, if yes - display a warning message
- if(this.responseFromSAP.length >= 10){
- this.showLWC = false;
- this.showMoreThan9ContractAccountsWarning = true;
- } else {
- //Get the list of contract accounts to query the subscriptions and get the sites
- for(let i=0; i < this.responseFromSAP.length; i++){
- sapContractAccounts.push(this.responseFromSAP[i].contractAccount);
- }
- getSubscriptionsBySAPContractAccount({
- sapContractAccounts: sapContractAccounts
- }).then(result => {
- //Map the response to a local variable
- this.responseSAPContractAccounts = result;
- //Prepare the SAPContractAccount - Site map local variable
- let responseSAPContractAccountsMap = new Map();
- //Iterate and create the SAPContractNumber - Site map
- for (const sapContractNumber in this.responseSAPContractAccounts) {
- responseSAPContractAccountsMap.set(sapContractNumber, this.responseSAPContractAccounts[sapContractNumber]);
- }
- //Iterate through the SAP response
- for(let i=0; i < this.responseFromSAP.length; i++){
- //Handle the dunning level colouring
- this.handleDunningLevelColor(this.responseFromSAP[i].dunningLevel);
- //Populate data table 1
- dataTable1.push({
- id : i,
- contractAccount : this.responseFromSAP[i].contractAccount,
- siteAddress : responseSAPContractAccountsMap.get(this.responseFromSAP[i].contractAccount),
- totalOpenAmount : this.responseFromSAP[i].openAmount,
- dunningLevelIcon : this.dunningLevelColor,
- dunningLevel : this.responseFromSAP[i].dunningLevel
- //reportedDueDate : this.responseFromSAP[i].invoices[j].reportedDueDate
- });
- //Populate the Open Invoices table for the Subscription record
- if(this.subscriptionSAPContractAccount != null && this.subscriptionSAPContractAccount == this.responseFromSAP[i].contractAccount){
- //Iterate through each invoice and populate the table
- for(let j=0; j<this.responseFromSAP[i].invoices.length; j++){
- //Handle the dunning level colouring
- this.handleDunningLevelColor(this.responseFromSAP[i].invoices[j].dunningLevel);
- //Populate data table 2
- dataTable2.push({
- id : j,
- invoiceNumber : this.responseFromSAP[i].invoices[j].invoiceNumber,
- amount : this.responseFromSAP[i].invoices[j].amount,
- invoiceDunningLevelIcon : this.dunningLevelColor,
- invoiceDunningLevel : this.responseFromSAP[i].invoices[j].dunningLevel,
- documentDate : this.responseFromSAP[i].invoices[j].documentDate,
- dueDate : this.responseFromSAP[i].invoices[j].dueDate,
- invoiceReportedDueDate : this.responseFromSAP[i].invoices[j].duedate
- });
- }
- }
- }
- //Load the data to the front-end tables
- this.data1 = dataTable1;
- this.data2 = dataTable2;
- //Default Table Sorting
- this.defaultSortingTable();
- //Spinner Off
- this.showSpinner = false;
- //Show the LWC
- this.showLWC = true;
- }).catch(error => {
- //Error handling
- this.handleErrorDisplay(error);
- });
- }
- }).catch(error => {
- //Display timeout warning message
- if(error.body.message == this.INTEGRATION_MESSAGE_STATUS_IN_ERROR){
- this.showTimeoutWarning = true;
- }
- //Error handling
- this.handleErrorDisplay(error);
- });
- }
- /********************************************************************************************************
- *
- * @description This method will check the row action (button/drop-down) and call the desired action.
- * @date 2022-10-20
- * US MP2-1023
- *********************************************************************************************************/
- callRowAction( event ) {
- //Data from the event
- const i = event.detail.row.id;
- const contractAccountFromRow = event.detail.row.contractAccount;
- const totalOpenAmountFromRow = event.detail.row.totalOpenAmount;
- const actionName = event.detail.action.name;
- //Check what's the desired action
- if ( actionName === 'openInvoices' ) {
- //Prepare local variables to prepare the table data
- let dataTable2 = [];
- //Display the table 2
- this.showOpenInvoicesForContractAccountSection = true;
- //Variables data to display above the table
- this.contractAccount = contractAccountFromRow;
- this.totalOpenAmountOpenInvoice = totalOpenAmountFromRow;
- //Populate through each invoice
- for(let j=0; j<this.responseFromSAP[i].invoices.length; j++){
- //Handle the dunning level colouring
- this.handleDunningLevelColor(this.responseFromSAP[i].invoices[j].dunningLevel);
- //Populate data table 2
- dataTable2.push({
- id : j,
- invoiceNumber : this.responseFromSAP[i].invoices[j].invoiceNumber,
- amount : this.responseFromSAP[i].invoices[j].amount,
- invoiceDunningLevelIcon : this.dunningLevelColor,
- invoiceDunningLevel : this.responseFromSAP[i].invoices[j].dunningLevel,
- documentDate : this.responseFromSAP[i].invoices[j].documentDate,
- dueDate : this.responseFromSAP[i].invoices[j].dueDate,
- invoiceReportedDueDate : this.responseFromSAP[i].invoices[j].dueDate
- });
- }
- //Load the data to the front-end tables
- this.data2 = dataTable2;
- // Log the entire row object
- console.log('Row object:', event.detail.row);
- // Log the contract account and total open amount from the row
- console.log('Contract account:', contractAccountFromRow);
- console.log('Total open amount:', totalOpenAmountFromRow);
- }
- }
- /********************************************************************************************************
- *
- * @description This method will handle the dunning level cell coloring
- * @date 2022-11-22
- * US MP2-1024
- *********************************************************************************************************/
- handleDunningLevelColor(dunningLevelSAP) {
- //Prepare a map of Dunning Level Text - Color Code
- let dunningLevelTextWithColorMap = new Map([
- [this.dunningLevelLabels.REMINDER_LEVEL_1, 1],
- [this.dunningLevelLabels.REMINDER_LEVEL_2, 2],
- [this.dunningLevelLabels.REMINDER_LEVEL_3, 3],
- [this.dunningLevelLabels.LAST_REMINDER, 5],
- [this.dunningLevelLabels.PAYMENT_ORDER, 6],
- [this.dunningLevelLabels.WAGE_GARNISHMENT, 7],
- [this.dunningLevelLabels.BAILIFF, 8],
- [this.dunningLevelLabels.CUTOFF, 9],
- [this.dunningLevelLabels.OVERDEBTNESS, 10],
- [this.dunningLevelLabels.EXTERNAL_OFFICES, 11],
- [this.dunningLevelLabels.BANKRUPTCY, 12],
- [this.dunningLevelLabels.INSOLVENT, 13]
- ]);
- //Find the right color based on the dunning level
- switch(dunningLevelTextWithColorMap.get(dunningLevelSAP)) {
- case 1: case 2: case 3:
- this.dunningLevelColor = "dunning-level-blue dunning-level-blue:hover";
- break;
- case 5:
- this.dunningLevelColor = "dunning-level-orange dunning-level-orange:hover";
- break;
- case 6:
- this.dunningLevelColor = "dunning-level-yellow dunning-level-yellow:hover";
- break;
- case 7: case 8:
- this.dunningLevelColor = "dunning-level-brown dunning-level-brown:hover";
- break;
- case 9:
- this.dunningLevelColor = "dunning-level-red dunning-level-red:hover";
- break;
- case 10: case 11:
- this.dunningLevelColor = "dunning-level-purple dunning-level-purple:hover";
- break;
- case 12: case 13:
- this.dunningLevelColor = "dunning-level-black dunning-level-black:hover";
- break;
- default:
- this.dunningLevelColor = "dunning-level-green dunning-level-green:hover";
- }
- }
- /********************************************************************************************************
- *
- * @description This method will handle the default sorting of the tables.
- * @date 2022-11-20
- * US MP2-1024
- *********************************************************************************************************/
- defaultSortingTable() {
- //Clone the tables data
- const cloneData1 = [...this.data1];
- const cloneData2 = [...this.data2];
- //Sort the cloned data
- cloneData1.sort(this.sortBy(this.sortedBy1, this.defaultSortDirection1 === 'asc' ? 1 : -1));
- cloneData2.sort(this.sortBy(this.sortedBy2, this.defaultSortDirection2 === 'asc' ? 1 : -1));
- //Overwrite the tables data with the new sorted one
- this.data1 = cloneData1;
- this.data2 = cloneData2;
- }
- /********************************************************************************************************
- *
- * @description This method will handle the sort of the table Total Open Amount Information
- * @date 2022-11-20
- * US MP2-1024
- *********************************************************************************************************/
- onHandleSortTotalOpenAmountInformation(event) {
- const { fieldName: sortedBy, sortDirection } = event.detail;
- //Clone the table data
- const cloneData = [...this.data1];
- //Sort the cloned data
- cloneData.sort(this.sortBy(sortedBy, sortDirection === 'desc' ? 1 : -1));
- //Overwrite the table data with the new sorted one
- this.data1 = cloneData;
- this.sortDirection1 = sortDirection;
- this.sortedBy1 = sortedBy;
- }
- /********************************************************************************************************
- *
- * @description This method will handle the sort of the table Open Invoices for Contract Account
- * @date 2022-11-20
- * US MP2-1024
- *********************************************************************************************************/
- onHandleSortOpenInvoicesForContractAccount(event) {
- const { fieldName: sortedBy, sortDirection } = event.detail;
- //Clone the table data
- const cloneData = [...this.data2];
- //Sort the cloned data
- cloneData.sort(this.sortBy(sortedBy, sortDirection === 'asc' ? 1 : -1));
- //Overwrite the table data with the new sorted one
- this.data2 = cloneData;
- this.sortDirection2 = sortDirection;
- this.sortedBy2 = sortedBy;
- }
- /********************************************************************************************************
- *
- * @description This method is used to sort tables based on a field and a direction
- * @date 2022-11-20
- * US MP2-1024
- *********************************************************************************************************/
- sortBy(field, reverse, primer) {
- const key = primer
- ? function (x) {
- return primer(x[field]);
- }
- : function (x) {
- return x[field];
- };
- return function (a, b) {
- a = key(a);
- b = key(b);
- return reverse * ((a > b) - (b > a));
- };
- }
- /********************************************************************************************************
- *
- * @description This method will handle the error display
- * @date 2022-11-20
- * US MP2-1024
- *********************************************************************************************************/
- handleErrorDisplay(error) {
- //Hide the Tables
- this.showLWC = false;
- //Hide the spinner
- this.showSpinner = false;
- //Show the error message
- this.dispatchEvent( new ShowToastEvent({
- title: 'Error',
- message: error.body.message,
- variant: 'error'
- })
- );
- }
- validationRule(event){
- let hasErrors = false;
- let selectedRow = event.detail.selectedRows;
- console.log('tabledata2: ', JSON.stringify(this.data2));
- if (this.data2.length > 0) {
- const firstRow = this.data2[0];
- firstRow.invoiceReportedDueDate = '2023-06-01';
- console.log('First selected row:', JSON.stringify(firstRow));
- // Convert date strings to Date objects
- var invoiceReportedDueDate = new Date(firstRow.invoiceReportedDueDate);
- var dueDate = new Date(firstRow.dueDate);
- // Calculate the difference in milliseconds
- var dif = Math.abs(invoiceReportedDueDate - dueDate);
- // Calculate the difference in days
- var d = dif / (1000 * 3600 * 24);
- // Log specific properties from the first selected row
- console.log('Color :', JSON.stringify(firstRow.invoiceDunningLevelIcon));
- console.log('DueDate:', JSON.stringify(firstRow.dueDate));
- console.log('ReportedDueDate:', JSON.stringify(firstRow.invoiceReportedDueDate));
- console.log('dif', dif);
- console.log('days', d);
- }
- console.log('draft Value: ', event.detail.draftValues);
- const editedRow = [];
- for(let i = 0; i < selectedRow.length; i++){
- console.log('Reported Due Date', selectedRow[i].invoiceReportedDueDate );
- console.log('Due Date', selectedRow[i].dueDate);
- console.log('Color1 : ', selectedRow[i].invoiceDunningLevelIcon);
- console.log('reportedDueDate : ', selectedRow[i].invoiceReportedDueDate);
- if((selectedRows[0].JSON.stringify(invoiceDunningLevelIcon).includes("dunning-level-green") || selectedRows[0].JSON.stringify(invoiceDunningLevelIcon).includes("dunning-level-blue")) && d > 30 ){
- this.dispatchEvent(
- new ShowToastEvent({
- title: 'Error',
- message: 'Nu ai voie',
- variant: 'error'
- })
- );
- }
- hasErrors = true;
- }
- return hasErrors;
- }
- saveHandleAction(event) {
- // Validation
- let selectedRow = event.detail.selectedRows;
- // Validate the data
- this.validationRule(event);
- // Save the data if there are no validation errors
- try {
- this.inputElement = event.detail.draftValues;
- console.log('Input Event.DraftValues', event.detail.draftValues);
- console.log('Input element', this.inputElement.length);
- this.draftValues = [];
- console.log('This draftValue: ', this.draftValues);
- this.dispatchEvent(
- new ShowToastEvent({
- title: 'Success',
- message: 'Records Updated Successfully!!',
- variant: 'success'
- })
- );
- } catch (error) {
- console.error('Update error:', error);
- this.dispatchEvent(
- new ShowToastEvent({
- title: 'Error',
- message: 'An Error Occured!!',
- variant: 'error'
- })
- );
- }
- }
- saveHandleActionAccount(event) {
- // Validation
- let selectedRow = event.detail.draftValues;
- // Save the data if there are no validation errors
- this.draftValues = [];
- try {
- this.inputElement = event.detail.draftValues;
- console.log('Input Event.DraftValues', event.detail.draftValues);
- console.log('Input element', this.inputElement.length);
- console.log('This draftValue: ', this.draftValues);
- this.dispatchEvent(
- new ShowToastEvent({
- title: 'Success',
- message: 'Records Updated Successfully!!',
- variant: 'success'
- })
- );
- } catch (error) {
- console.error('Update error:', error);
- this.dispatchEvent(
- new ShowToastEvent({
- title: 'Error',
- message: 'An Error Occured!!',
- variant: 'error'
- })
- );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement