-
Notifications
You must be signed in to change notification settings - Fork 703
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
Showing
2 changed files
with
61 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,67 @@ | ||
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 => { | ||
await updateDateTimeForEntryType('PurchaseInvoice', entry.name, entry.referenceName, dm); | ||
await updateDateTimeForEntryType('SalesInvoice', entry.name, entry.referenceName, dm); | ||
await updateDateTimeForEntryType('JournalEntry', entry.name, entry.referenceName, dm); | ||
await updateDateTimeForEntryType('Payment', entry.name, entry.referenceName, dm); | ||
await updateDateTimeForEntryType('StockMovement', entry.name, entry.referenceName, dm); | ||
await updateDateTimeForEntryType('StockTransfer', entry.name, entry.referenceName, dm); | ||
}) | ||
}); | ||
await dm.db!.knex!('AccountingLedgerEntry') | ||
.select('name', 'date', 'referenceName') | ||
.then((trx) => { | ||
trx.forEach(async (entry) => { | ||
await updateDateTimeForEntryType( | ||
'PurchaseInvoice', | ||
entry.name, | ||
entry.referenceName, | ||
Check failure on line 11 in backend/patches/v0_21_0/fixLedgerDateTime.ts GitHub Actions / setup_and_lint
|
||
dm | ||
); | ||
await updateDateTimeForEntryType( | ||
'SalesInvoice', | ||
entry.name, | ||
entry.referenceName, | ||
Check failure on line 17 in backend/patches/v0_21_0/fixLedgerDateTime.ts GitHub Actions / setup_and_lint
|
||
dm | ||
); | ||
await updateDateTimeForEntryType( | ||
'JournalEntry', | ||
entry.name, | ||
entry.referenceName, | ||
Check failure on line 23 in backend/patches/v0_21_0/fixLedgerDateTime.ts GitHub Actions / setup_and_lint
|
||
dm | ||
); | ||
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 }); | ||
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) }); | ||
} | ||
if (refDate.length > 0) { | ||
const newDate = new Date(refDate[0].date); | ||
console.log(entryName, refDate, new Date(refDate[0].date)); | ||
dm.db!.knex!('AccountingLedgerEntry') | ||
Check warning on line 61 in backend/patches/v0_21_0/fixLedgerDateTime.ts GitHub Actions / setup_and_lint
|
||
.where({ name: entryName }) | ||
.update({ date: new Date(refDate[0].date) }); | ||
} | ||
} | ||
|
||
export default { execute, beforeMigrate: true }; | ||
export default { execute, beforeMigrate: true }; |