-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a429e66
commit 8db3e5c
Showing
5 changed files
with
271 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
renderer/validation-new/modules/DOLPHIN_MOTOR_AGENCY.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
export const MAIN = (excelData: any) => { | ||
console.log("DOLPHIN MOTOR AGENCY", (excelData)); | ||
const OB = getOpeningBalance(excelData); | ||
const CB = getClosingBalance(excelData); | ||
// // // const LD = getLedgerDuration(excelData); | ||
const LT = getTransactionDetails(excelData); | ||
const TCD = getTotalCreditAndDebit(LT); | ||
return { | ||
account: { | ||
accountName: "DOLPHIN MOTOR AGENCY", | ||
duration: `${LT[0].date.toDateString()} - ${LT[LT.length - 1].date.toDateString()}`, | ||
startDate: LT[0].date, | ||
endDate: LT[LT.length - 1].date, | ||
}, | ||
openingBalance: OB, | ||
closingBalance: CB, | ||
transactions: LT, | ||
totalCredit: TCD.totalCredit, | ||
totalDebit: TCD.totalDebit, | ||
}; | ||
}; | ||
|
||
function getOpeningBalance(excelData: any): number { | ||
const openingBalanceRow = 10; | ||
const fieldName = "__EMPTY_4"; | ||
const openingBalance = Number(excelData[openingBalanceRow][fieldName]); | ||
console.log("Opening Balance", openingBalance); | ||
return openingBalance; | ||
} | ||
|
||
function getClosingBalance(excelData: any): number { | ||
const closingBalanceRow = excelData.length - 2; | ||
const fieldName = "__EMPTY_5"; | ||
const closingBalance = Number(excelData[closingBalanceRow][fieldName]); | ||
console.log("Closing Balance", closingBalance); | ||
return closingBalance; | ||
} | ||
|
||
function getLedgerDuration(excelData: any): { startDate: Date, endDate: Date } { | ||
|
||
function convertDate(dateString: string): { startDate: Date, endDate: Date } { | ||
// Split the input string into start and end date strings | ||
const [startDateStr, endDateStr] = dateString.split(' - '); | ||
|
||
// Convert date strings to JavaScript Date objects | ||
const startDate = new Date(startDateStr); | ||
const endDate = new Date(endDateStr); | ||
|
||
// Return an object containing start and end dates | ||
return { startDate, endDate }; | ||
} | ||
|
||
const durationRow = 3; | ||
const fieldName = "RAHUL AUTO AGENCY PVT. LTD." | ||
const durationUnFiltered = excelData[durationRow][fieldName]; | ||
const duration = convertDate(durationUnFiltered); | ||
console.log("Duration", duration); | ||
return duration; | ||
|
||
|
||
// console.log("Duration", startDate, endDate); | ||
return convertDate("01-04-2021 - 31-03-2022"); | ||
|
||
} | ||
|
||
function getTransactionDetails(excelData: any): any[] { | ||
const transactionDetails = []; | ||
const transactionStartRow = 11; | ||
const transactionEndRow = excelData.length - 4; | ||
const creditFieldName = "__EMPTY_5"; | ||
const debitFieldName = "__EMPTY_4"; | ||
const dateFieldName = "DOLPHIN MOTOR AGENCY"; | ||
for (let i = transactionStartRow; i <= transactionEndRow; i++) { | ||
let tempTransaction = { | ||
date: excelSerialToJSDate(excelData[i][dateFieldName]), | ||
type: excelData[i][creditFieldName] ? "PURCHASE" : "PAYMENT", | ||
credit: excelData[i][creditFieldName] ? Number(excelData[i][creditFieldName]) : 0, | ||
debit: excelData[i][debitFieldName] ? Number(excelData[i][debitFieldName]) : 0, | ||
} | ||
transactionDetails.push(tempTransaction); | ||
} | ||
console.log("Transaction Details", transactionDetails); | ||
return transactionDetails; | ||
} | ||
|
||
function getTotalCreditAndDebit(transactions: any[]): { totalCredit: number, totalDebit: number } { | ||
let totalCredit = 0; | ||
let totalDebit = 0; | ||
transactions.forEach(transaction => { | ||
totalCredit += transaction?.credit || 0; | ||
totalDebit += transaction?.debit || 0; | ||
}); | ||
|
||
console.log("Total Credit and Debit", totalCredit, totalDebit); | ||
|
||
return { | ||
totalCredit, | ||
totalDebit | ||
}; | ||
|
||
} | ||
|
||
function excelSerialToJSDate(serial: number): Date { | ||
const millisecondsPerDay = 24 * 60 * 60 * 1000; | ||
const excelStartDate = new Date('1900-01-01T00:00:00Z'); | ||
|
||
// Calculate the number of days from the Excel start date , Adjust for the Julian date bug | ||
const days = serial - 2; | ||
|
||
// Calculate the total milliseconds | ||
const totalMilliseconds = days * millisecondsPerDay; | ||
|
||
// Convert to JavaScript Date object | ||
const resultDate = new Date(excelStartDate.getTime() + totalMilliseconds); | ||
|
||
return resultDate; | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
export const MAIN = (excelData: any) => { | ||
console.log("PN Distributors", (excelData)); | ||
alert("❌ This ledger account not yet supported.") | ||
// const OB = getOpeningBalance(excelData); | ||
// const CB = getClosingBalance(excelData); | ||
// // // // const LD = getLedgerDuration(excelData); | ||
// const LT = getTransactionDetails(excelData); | ||
// const TCD = getTotalCreditAndDebit(LT); | ||
// return { | ||
// account: { | ||
// accountName: "PN Distributors", | ||
// duration: `${LT[0].date.toDateString()} - ${LT[LT.length - 1].date.toDateString()}`, | ||
// startDate: LT[0].date, | ||
// endDate: LT[LT.length - 1].date, | ||
// }, | ||
// openingBalance: OB, | ||
// closingBalance: CB, | ||
// transactions: LT, | ||
// totalCredit: TCD.totalCredit, | ||
// totalDebit: TCD.totalDebit, | ||
// }; | ||
}; | ||
|
||
function getOpeningBalance(excelData: any): number { | ||
const openingBalanceRow = 10; | ||
const fieldName = "__EMPTY_4"; | ||
const openingBalance = Number(excelData[openingBalanceRow][fieldName]); | ||
console.log("Opening Balance", openingBalance); | ||
return openingBalance; | ||
} | ||
|
||
function getClosingBalance(excelData: any): number { | ||
const closingBalanceRow = excelData.length - 2; | ||
const fieldName = "__EMPTY_5"; | ||
const closingBalance = Number(excelData[closingBalanceRow][fieldName]); | ||
console.log("Closing Balance", closingBalance); | ||
return closingBalance; | ||
} | ||
|
||
function getLedgerDuration(excelData: any): { startDate: Date, endDate: Date } { | ||
|
||
function convertDate(dateString: string): { startDate: Date, endDate: Date } { | ||
// Split the input string into start and end date strings | ||
const [startDateStr, endDateStr] = dateString.split(' - '); | ||
|
||
// Convert date strings to JavaScript Date objects | ||
const startDate = new Date(startDateStr); | ||
const endDate = new Date(endDateStr); | ||
|
||
// Return an object containing start and end dates | ||
return { startDate, endDate }; | ||
} | ||
|
||
const durationRow = 3; | ||
const fieldName = "RAHUL AUTO AGENCY PVT. LTD." | ||
const durationUnFiltered = excelData[durationRow][fieldName]; | ||
const duration = convertDate(durationUnFiltered); | ||
console.log("Duration", duration); | ||
return duration; | ||
|
||
|
||
// console.log("Duration", startDate, endDate); | ||
return convertDate("01-04-2021 - 31-03-2022"); | ||
|
||
} | ||
|
||
function getTransactionDetails(excelData: any): any[] { | ||
const transactionDetails = []; | ||
const transactionStartRow = 11; | ||
const transactionEndRow = excelData.length - 4; | ||
const creditFieldName = "__EMPTY_5"; | ||
const debitFieldName = "__EMPTY_4"; | ||
const dateFieldName = "PN Distributors"; | ||
for (let i = transactionStartRow; i <= transactionEndRow; i++) { | ||
let tempTransaction = { | ||
date: excelSerialToJSDate(excelData[i][dateFieldName]), | ||
type: excelData[i][creditFieldName] ? "PURCHASE" : "PAYMENT", | ||
credit: excelData[i][creditFieldName] ? Number(excelData[i][creditFieldName]) : 0, | ||
debit: excelData[i][debitFieldName] ? Number(excelData[i][debitFieldName]) : 0, | ||
} | ||
transactionDetails.push(tempTransaction); | ||
} | ||
console.log("Transaction Details", transactionDetails); | ||
return transactionDetails; | ||
} | ||
|
||
function getTotalCreditAndDebit(transactions: any[]): { totalCredit: number, totalDebit: number } { | ||
let totalCredit = 0; | ||
let totalDebit = 0; | ||
transactions.forEach(transaction => { | ||
totalCredit += transaction?.credit || 0; | ||
totalDebit += transaction?.debit || 0; | ||
}); | ||
|
||
console.log("Total Credit and Debit", totalCredit, totalDebit); | ||
|
||
return { | ||
totalCredit, | ||
totalDebit | ||
}; | ||
|
||
} | ||
|
||
function excelSerialToJSDate(serial: number): Date { | ||
const millisecondsPerDay = 24 * 60 * 60 * 1000; | ||
const excelStartDate = new Date('1900-01-01T00:00:00Z'); | ||
|
||
// Calculate the number of days from the Excel start date , Adjust for the Julian date bug | ||
const days = serial - 2; | ||
|
||
// Calculate the total milliseconds | ||
const totalMilliseconds = days * millisecondsPerDay; | ||
|
||
// Convert to JavaScript Date object | ||
const resultDate = new Date(excelStartDate.getTime() + totalMilliseconds); | ||
|
||
return resultDate; | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters