2
0
mirror of https://github.com/frappe/books.git synced 2024-10-18 01:46:29 +00:00

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

View File

@ -396,17 +396,28 @@ export class BespokeQueries {
static async getPOSTransactedAmount( static async getPOSTransactedAmount(
db: DatabaseCore, db: DatabaseCore,
fromDate: Date, fromDate: Date,
toDate: Date toDate: Date,
lastShiftClosingDate?: Date
): Promise<Record<string, Money> | undefined> { ): Promise<Record<string, Money> | undefined> {
const sinvNames = ( const sinvNamesQuery = db.knex!(ModelNameEnum.SalesInvoice)
await db.knex!(ModelNameEnum.SalesInvoice) .select('name')
.select('name') .where('isPOS', true)
.where('isPOS', true) .andWhereBetween('date', [
.andWhereBetween('date', [ DateTime.fromJSDate(fromDate).toSQLDate(),
DateTime.fromJSDate(fromDate).toISODate(), DateTime.fromJSDate(toDate).toSQLDate(),
DateTime.fromJSDate(toDate).toISODate(), ]);
])
).map((row: { name: string }) => row.name); if (lastShiftClosingDate) {
sinvNamesQuery.andWhere(
'created',
'>',
DateTime.fromJSDate(lastShiftClosingDate).toUTC().toString()
);
}
const sinvNames = (await sinvNamesQuery).map(
(row: { name: string }) => row.name
);
if (!sinvNames.length) { if (!sinvNames.length) {
return; return;

View File

@ -345,12 +345,14 @@ export class DatabaseHandler extends DatabaseBase {
async getPOSTransactedAmount( async getPOSTransactedAmount(
fromDate: Date, fromDate: Date,
toDate: Date toDate: Date,
lastShiftClosingDate?: Date
): Promise<Record<string, Money> | undefined> { ): Promise<Record<string, Money> | undefined> {
return (await this.#demux.callBespoke( return (await this.#demux.callBespoke(
'getPOSTransactedAmount', 'getPOSTransactedAmount',
fromDate, fromDate,
toDate toDate,
lastShiftClosingDate
)) as Promise<Record<string, Money> | undefined>; )) as Promise<Record<string, Money> | undefined>;
} }

View File

@ -46,10 +46,7 @@ export class InventorySettings extends Doc {
return !!this.enableStockReturns; return !!this.enableStockReturns;
}, },
enablePointOfSale: () => { enablePointOfSale: () => {
return ( return !!this.fyo.singles.POSShift?.isShiftOpen;
!!this.fyo.singles.POSShift?.isShiftOpen &&
!!this.fyo.singles.AccountingSettings?.enableDiscounting
);
}, },
}; };
} }

View File

@ -111,7 +111,8 @@ export default defineComponent({
const fromDate = fyo.singles.POSShift?.openingDate; const fromDate = fyo.singles.POSShift?.openingDate;
this.transactedAmount = await fyo.db.getPOSTransactedAmount( this.transactedAmount = await fyo.db.getPOSTransactedAmount(
fromDate, fromDate,
new Date() new Date(),
fyo.singles.POSShift.closingDate as Date
); );
}, },
seedClosingCash() { seedClosingCash() {
@ -190,6 +191,7 @@ export default defineComponent({
try { try {
validateClosingAmounts(this.posShiftDoc as POSShift); validateClosingAmounts(this.posShiftDoc as POSShift);
await this.posShiftDoc?.set('isShiftOpen', false); await this.posShiftDoc?.set('isShiftOpen', false);
await this.posShiftDoc?.set('closingDate', new Date());
await this.posShiftDoc?.sync(); await this.posShiftDoc?.sync();
await transferPOSCashAndWriteOff(fyo, this.posShiftDoc as POSShift); await transferPOSCashAndWriteOff(fyo, this.posShiftDoc as POSShift);

View File

@ -211,11 +211,11 @@ export async function transferPOSCashAndWriteOff(
fyo: Fyo, fyo: Fyo,
posShiftDoc: POSShift posShiftDoc: POSShift
) { ) {
const differenceAmount = posShiftDoc?.closingAmounts?.find( const expectedCashAmount = posShiftDoc.closingAmounts?.find(
(row) => row.paymentMethod === 'Cash' (row) => row.paymentMethod === 'Cash'
)?.differenceAmount as Money; )?.expectedAmount as Money;
if (differenceAmount.isZero()) { if (expectedCashAmount.isZero()) {
return; return;
} }
@ -237,6 +237,10 @@ export async function transferPOSCashAndWriteOff(
credit: closingCashAmount, credit: closingCashAmount,
}); });
const differenceAmount = posShiftDoc?.closingAmounts?.find(
(row) => row.paymentMethod === 'Cash'
)?.differenceAmount as Money;
if (differenceAmount.isNegative()) { if (differenceAmount.isNegative()) {
await jvDoc.append('accounts', { await jvDoc.append('accounts', {
account: AccountTypeEnum.Cash, account: AccountTypeEnum.Cash,