Skip to content

Commit

Permalink
DOLPHIN MOTOR AGENCY ADDED
Browse files Browse the repository at this point in the history
  • Loading branch information
subhranshuchoudhury committed Mar 4, 2024
1 parent a429e66 commit 8db3e5c
Show file tree
Hide file tree
Showing 5 changed files with 271 additions and 11 deletions.
16 changes: 9 additions & 7 deletions renderer/pages/menu/calculate-new/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,17 @@ export default function CalculatePage() {

const handlePDFInput = (e: React.ChangeEvent<HTMLInputElement>) => {
console.log("Hello World")
console.log(e.target.files);
console.log("PDF INPUT");
}

const handleExecutionFunction = (e: React.ChangeEvent<HTMLInputElement>) => {
const selectedFile = e.target.files?.[0];
const handleName = e.target.name;
console.log(selectedFile);
console.log(handleName);
const remoteFunction = new Function("handlePDFInput")(e);

if (SelectedCreditorName[0].type === "XLSX") {
handleFileInput(e);
} else {
handlePDFInput(e);
}

}


Expand Down Expand Up @@ -181,7 +183,7 @@ export default function CalculatePage() {

<p className='text-white uppercase mb-3'>Select Creditor' s Ledger File <span className='text-red-500'>*</span></p>

<input ref={otherPartySelectRef} name='other' id='otherdata' onChange={handleFileInput} accept={(handleAcceptType(SelectedCreditorName[0].type).accept)} type="file" title='Creditors Ledger Excel File' className="file-input file-input-bordered file-input-success w-full max-w-xs" />
<input ref={otherPartySelectRef} name='other' id='otherdata' onChange={handleExecutionFunction} accept={(handleAcceptType(SelectedCreditorName[0].type).accept)} type="file" title='Creditors Ledger Excel File' className="file-input file-input-bordered file-input-success w-full max-w-xs" />
{
OtherPartyData && <div className='flex justify-center mt-4'>
<img onClick={() => {
Expand Down
21 changes: 19 additions & 2 deletions renderer/validation-new/creditors-list.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const creditorsList = [
export const creditorsList: CreditorsList[] = [
{
label: "TOPSEL MARKETING PVT. LTD.",
value: "TOPSEL",
Expand All @@ -23,5 +23,22 @@ export const creditorsList = [
label: "SUNDARAM MOTORS",
value: "SUNDARAM_MOTORS",
type: "PDF"
},
{
label: "DOLPHIN MOTOR AGENCY",
value: "DOLPHIN_MOTOR_AGENCY",
type: "XLSX"
},
{
label: "PN DISTRIBUTORS",
value: "PN_DISTRIBUTORS",
type: "XLSX"
}
]

]

type CreditorsList = {
label: string,
value: string,
type: string
}
120 changes: 120 additions & 0 deletions renderer/validation-new/modules/DOLPHIN_MOTOR_AGENCY.ts
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;
}



121 changes: 121 additions & 0 deletions renderer/validation-new/modules/PN_DISTRIBUTORS.ts
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;
}



4 changes: 2 additions & 2 deletions renderer/validation-new/utils/generateReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const generateReport = (dataOne: MismatchSchema[], dataTwoReversed: Misma

obj.indexes.ledgerOne.forEach((index) => {
let report: Report = {
accountName: transactionsCreditorsLedger.account.accountName,
accountName: isPayment ? transactionsCreditorsLedger.account.accountName : transactionsOwnLedger.account.accountName,
amount: obj.amount,
date: transactionsOwnLedger.transactions[index].date,
isPayment: isPayment
Expand All @@ -51,7 +51,7 @@ export const generateReport = (dataOne: MismatchSchema[], dataTwoReversed: Misma

obj.indexes.ledgerTwo.forEach((index) => {
let report: Report = {
accountName: transactionsOwnLedger.account.accountName,
accountName: isPayment ? transactionsCreditorsLedger.account.accountName : transactionsOwnLedger.account.accountName,
amount: obj.amount,
date: transactionsCreditorsLedger.transactions[index].date,
isPayment: isPayment
Expand Down

0 comments on commit 8db3e5c

Please sign in to comment.