mirror of
https://github.com/frappe/books.git
synced 2025-03-14 23:22:22 +00:00
feat: get pos transacted amount
This commit is contained in:
parent
746b3b26ee
commit
218547269d
@ -10,6 +10,7 @@ import DatabaseCore from './core';
|
||||
import { BespokeFunction } from './types';
|
||||
import { DocItem, ReturnDocItem } from 'models/inventory/types';
|
||||
import { safeParseFloat } from 'utils/index';
|
||||
import { Money } from 'pesa';
|
||||
|
||||
export class BespokeQueries {
|
||||
[key: string]: BespokeFunction;
|
||||
@ -390,4 +391,47 @@ export class BespokeQueries {
|
||||
}
|
||||
return returnBalanceItems;
|
||||
}
|
||||
|
||||
static async getPOSTransactedAmount(
|
||||
db: DatabaseCore,
|
||||
fromDate: Date
|
||||
): Promise<Record<string, Money> | undefined> {
|
||||
const sinvNames = (
|
||||
await db.knex!(ModelNameEnum.SalesInvoice)
|
||||
.select('name')
|
||||
.where('isPOS', true)
|
||||
.andWhereRaw('datetime(date) > datetime(?)', [
|
||||
new Date(fromDate.setHours(0, 0, 0)).toISOString(),
|
||||
])
|
||||
.andWhereRaw('datetime(date) < datetime(?)', [new Date().toISOString()])
|
||||
).map((row: { name: string }) => row.name);
|
||||
|
||||
if (!sinvNames.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const paymentEntryNames: string[] = (
|
||||
await db.knex!(ModelNameEnum.PaymentFor)
|
||||
.select('parent')
|
||||
.whereIn('referenceName', sinvNames)
|
||||
).map((doc: { parent: string }) => doc.parent);
|
||||
|
||||
const groupedAmounts = (await db.knex!(ModelNameEnum.Payment)
|
||||
.select('paymentMethod')
|
||||
.whereIn('name', paymentEntryNames)
|
||||
.groupBy('paymentMethod')
|
||||
.sum({ amount: 'amount' })) as { paymentMethod: string; amount: Money }[];
|
||||
|
||||
const transactedAmounts = {} as { [paymentMethod: string]: Money };
|
||||
|
||||
if (!groupedAmounts) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const row of groupedAmounts) {
|
||||
transactedAmounts[row.paymentMethod] = row.amount;
|
||||
}
|
||||
|
||||
return transactedAmounts;
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import {
|
||||
RawValueMap,
|
||||
} from './types';
|
||||
import { ReturnDocItem } from 'models/inventory/types';
|
||||
import { Money } from 'pesa';
|
||||
|
||||
type FieldMap = Record<string, Record<string, Field>>;
|
||||
|
||||
@ -342,6 +343,15 @@ export class DatabaseHandler extends DatabaseBase {
|
||||
)) as Promise<Record<string, ReturnDocItem> | undefined>;
|
||||
}
|
||||
|
||||
async getPOSTransactedAmount(
|
||||
fromDate: Date
|
||||
): Promise<Record<string, Money> | undefined> {
|
||||
return (await this.#demux.callBespoke(
|
||||
'getPOSTransactedAmount',
|
||||
fromDate
|
||||
)) as Promise<Record<string, Money> | undefined>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal methods
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user