diff --git a/backend/patches/index.ts b/backend/patches/index.ts index 9e05d37e4..90802e86d 100644 --- a/backend/patches/index.ts +++ b/backend/patches/index.ts @@ -5,6 +5,7 @@ import fixRoundOffAccount from './fixRoundOffAccount'; import testPatch from './testPatch'; import updateSchemas from './updateSchemas'; import setPaymentReferenceType from './setPaymentReferenceType'; +import fixLedgerDateTime from './v0_21_0/fixLedgerDateTime'; export default [ { name: 'testPatch', version: '0.5.0-beta.0', patch: testPatch }, @@ -34,4 +35,10 @@ export default [ version: '0.20.1', patch: setPaymentReferenceType, }, + { + name: 'fixLedgerDateTime', + version: '0.21.1', + patch: fixLedgerDateTime + + } ] as Patch[]; diff --git a/backend/patches/v0_21_0/fixLedgerDateTime.ts b/backend/patches/v0_21_0/fixLedgerDateTime.ts new file mode 100644 index 000000000..d8999f124 --- /dev/null +++ b/backend/patches/v0_21_0/fixLedgerDateTime.ts @@ -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 => { + 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); + }) + }); +} + +async function updateDateTimeForEntryType(entryTypeTable: any, entryName: any, referenceName: String, dm: DatabaseManager) { + const refDate: Array = 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 }; \ No newline at end of file diff --git a/models/Transactional/LedgerPosting.ts b/models/Transactional/LedgerPosting.ts index ad8c2c027..e33b28303 100644 --- a/models/Transactional/LedgerPosting.ts +++ b/models/Transactional/LedgerPosting.ts @@ -105,6 +105,7 @@ export class LedgerPosting { dtFixedValue.setHours(0 - dtHours); dtFixedValue.setMinutes(0 - dtMinutes); dtFixedValue.setSeconds(0); + dtFixedValue.setMilliseconds(0); // end ugly timezone fix code