mirror of
https://github.com/frappe/books.git
synced 2024-12-22 10:58:59 +00:00
fix: expectedAmount calculation
This commit is contained in:
parent
a76953776b
commit
7ed2a0841e
@ -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)
|
||||
const sinvNamesQuery = 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);
|
||||
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;
|
||||
|
@ -345,12 +345,14 @@ export class DatabaseHandler extends DatabaseBase {
|
||||
|
||||
async getPOSTransactedAmount(
|
||||
fromDate: Date,
|
||||
toDate: Date
|
||||
toDate: Date,
|
||||
lastShiftClosingDate?: Date
|
||||
): Promise<Record<string, Money> | undefined> {
|
||||
return (await this.#demux.callBespoke(
|
||||
'getPOSTransactedAmount',
|
||||
fromDate,
|
||||
toDate
|
||||
toDate,
|
||||
lastShiftClosingDate
|
||||
)) as Promise<Record<string, Money> | undefined>;
|
||||
}
|
||||
|
||||
|
@ -46,10 +46,7 @@ export class InventorySettings extends Doc {
|
||||
return !!this.enableStockReturns;
|
||||
},
|
||||
enablePointOfSale: () => {
|
||||
return (
|
||||
!!this.fyo.singles.POSShift?.isShiftOpen &&
|
||||
!!this.fyo.singles.AccountingSettings?.enableDiscounting
|
||||
);
|
||||
return !!this.fyo.singles.POSShift?.isShiftOpen;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@ -111,7 +111,8 @@ export default defineComponent({
|
||||
const fromDate = fyo.singles.POSShift?.openingDate;
|
||||
this.transactedAmount = await fyo.db.getPOSTransactedAmount(
|
||||
fromDate,
|
||||
new Date()
|
||||
new Date(),
|
||||
fyo.singles.POSShift.closingDate as Date
|
||||
);
|
||||
},
|
||||
seedClosingCash() {
|
||||
@ -190,6 +191,7 @@ export default defineComponent({
|
||||
try {
|
||||
validateClosingAmounts(this.posShiftDoc as POSShift);
|
||||
await this.posShiftDoc?.set('isShiftOpen', false);
|
||||
await this.posShiftDoc?.set('closingDate', new Date());
|
||||
await this.posShiftDoc?.sync();
|
||||
await transferPOSCashAndWriteOff(fyo, this.posShiftDoc as POSShift);
|
||||
|
||||
|
@ -211,11 +211,11 @@ export async function transferPOSCashAndWriteOff(
|
||||
fyo: Fyo,
|
||||
posShiftDoc: POSShift
|
||||
) {
|
||||
const differenceAmount = posShiftDoc?.closingAmounts?.find(
|
||||
const expectedCashAmount = posShiftDoc.closingAmounts?.find(
|
||||
(row) => row.paymentMethod === 'Cash'
|
||||
)?.differenceAmount as Money;
|
||||
)?.expectedAmount as Money;
|
||||
|
||||
if (differenceAmount.isZero()) {
|
||||
if (expectedCashAmount.isZero()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -237,6 +237,10 @@ export async function transferPOSCashAndWriteOff(
|
||||
credit: closingCashAmount,
|
||||
});
|
||||
|
||||
const differenceAmount = posShiftDoc?.closingAmounts?.find(
|
||||
(row) => row.paymentMethod === 'Cash'
|
||||
)?.differenceAmount as Money;
|
||||
|
||||
if (differenceAmount.isNegative()) {
|
||||
await jvDoc.append('accounts', {
|
||||
account: AccountTypeEnum.Cash,
|
||||
|
Loading…
Reference in New Issue
Block a user