-
Notifications
You must be signed in to change notification settings - Fork 707
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { DatabaseManager } from '../../database/manager'; | ||
|
||
async function execute(dm: DatabaseManager) { | ||
|
||
await dm.db!.knex!('AccountingLedgerEntry') | ||
.select('name','date', 'referenceName') | ||
.then((trx) => { | ||
trx.forEach(async entry => { | ||
Check warning on line 8 in backend/patches/v0_21_0/fixLedgerDateTime.ts GitHub Actions / setup_and_lint
|
||
await updateDateTimeForEntryType('PurchaseInvoice', entry.name, entry.referenceName, dm); | ||
Check warning on line 9 in backend/patches/v0_21_0/fixLedgerDateTime.ts GitHub Actions / setup_and_lint
Check failure on line 9 in backend/patches/v0_21_0/fixLedgerDateTime.ts GitHub Actions / setup_and_lint
Check failure on line 9 in backend/patches/v0_21_0/fixLedgerDateTime.ts GitHub Actions / setup_and_lint
|
||
await updateDateTimeForEntryType('SalesInvoice', entry.name, entry.referenceName, dm); | ||
Check warning on line 10 in backend/patches/v0_21_0/fixLedgerDateTime.ts GitHub Actions / setup_and_lint
Check failure on line 10 in backend/patches/v0_21_0/fixLedgerDateTime.ts GitHub Actions / setup_and_lint
Check failure on line 10 in backend/patches/v0_21_0/fixLedgerDateTime.ts GitHub Actions / setup_and_lint
|
||
await updateDateTimeForEntryType('JournalEntry', entry.name, entry.referenceName, dm); | ||
Check warning on line 11 in backend/patches/v0_21_0/fixLedgerDateTime.ts GitHub Actions / setup_and_lint
Check failure on line 11 in backend/patches/v0_21_0/fixLedgerDateTime.ts GitHub Actions / setup_and_lint
Check failure on line 11 in backend/patches/v0_21_0/fixLedgerDateTime.ts GitHub Actions / setup_and_lint
|
||
await updateDateTimeForEntryType('Payment', entry.name, entry.referenceName, dm); | ||
await updateDateTimeForEntryType('StockMovement', entry.name, entry.referenceName, dm); | ||
await updateDateTimeForEntryType('StockTransfer', entry.name, entry.referenceName, dm); | ||
}) | ||
}); | ||
} | ||
|
||
async function updateDateTimeForEntryType(entryTypeTable: any, entryName: any, referenceName: String, dm: DatabaseManager) { | ||
const refDate: Array<any> = await dm.db!.knex!(entryTypeTable) | ||
.select('name','date') | ||
.where({ 'name': referenceName }); | ||
|
||
if (refDate.length > 0) { | ||
const newDate = new Date(refDate[0].date) | ||
console.log(entryName, refDate, new Date(refDate[0].date)); | ||
dm.db!.knex!('AccountingLedgerEntry') | ||
.where({ name: entryName }) | ||
.update({ date: new Date(refDate[0].date) }); | ||
} | ||
} | ||
|
||
export default { execute, beforeMigrate: true }; |