2
0
mirror of https://github.com/frappe/books.git synced 2024-11-15 09:54:04 +00:00
books/backend/patches/v0_21_0/fixLedgerDateTime.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.3 KiB
TypeScript
Raw Normal View History

import { DatabaseManager } from '../../database/manager';
/* eslint-disable */
async function execute(dm: DatabaseManager) {
2024-02-08 04:12:30 +00:00
const sourceTables = [
"PurchaseInvoice",
"SalesInvoice",
"JournalEntry",
"Payment",
"StockMovement",
"StockTransfer"
];
2024-02-08 04:12:30 +00:00
await dm.db!.knex!('AccountingLedgerEntry')
.select('name', 'date', 'referenceName')
.then((trx: Array<{name: string; date: Date; referenceName: string;}> ) => {
trx.forEach(async entry => {
2024-02-08 04:12:30 +00:00
sourceTables.forEach(async table => {
await dm.db!.knex!
.select('name','date')
.from(table)
.where({ name: entry['referenceName'] })
.then(async (resp: Array<{name: string; date: Date;}>) => {
if (resp.length !== 0) {
const dateTimeValue = new Date(resp[0]['date']);
await dm.db!.knex!('AccountingLedgerEntry')
.where({ name: entry['name'] })
.update({ date: dateTimeValue.toISOString() });
}
})
});
});
});
}
export default { execute, beforeMigrate: true };
/* eslint-enable */