fix: expectedAmount calculation

This commit is contained in:
akshayitzme
2023-12-04 14:42:57 +05:30
parent a76953776b
commit 7ed2a0841e
5 changed files with 36 additions and 20 deletions
+21 -10
View File
@@ -396,17 +396,28 @@ export class BespokeQueries {
static async getPOSTransactedAmount(
db: DatabaseCore,
fromDate: Date,
toDate: Date
toDate: Date,
lastShiftClosingDate?: Date
): Promise<Record<string, Money> | undefined> {
const sinvNames = (
await db.knex!(ModelNameEnum.SalesInvoice)
.select('name')
.where('isPOS', true)
.andWhereBetween('date', [
DateTime.fromJSDate(fromDate).toISODate(),
DateTime.fromJSDate(toDate).toISODate(),
])
).map((row: { name: string }) => row.name);
const sinvNamesQuery = db.knex!(ModelNameEnum.SalesInvoice)
.select('name')
.where('isPOS', true)
.andWhereBetween('date', [
DateTime.fromJSDate(fromDate).toSQLDate(),
DateTime.fromJSDate(toDate).toSQLDate(),
]);
if (lastShiftClosingDate) {
sinvNamesQuery.andWhere(
'created',
'>',
DateTime.fromJSDate(lastShiftClosingDate).toUTC().toString()
);
}
const sinvNames = (await sinvNamesQuery).map(
(row: { name: string }) => row.name
);
if (!sinvNames.length) {
return;