From 7cbe5c684013cb179a2f0694758639dde6ce0c6a Mon Sep 17 00:00:00 2001 From: akshayitzme Date: Thu, 26 Dec 2024 20:08:12 +0530 Subject: [PATCH] feat: multiple payment methods in pos --- backend/database/bespoke.ts | 5 +---- src/pages/POS/ClosePOSShiftModal.vue | 24 +++++++----------------- src/pages/POS/OpenPOSShiftModal.vue | 17 +++++++---------- 3 files changed, 15 insertions(+), 31 deletions(-) diff --git a/backend/database/bespoke.ts b/backend/database/bespoke.ts index c5ab61b8a..f2c855dc6 100644 --- a/backend/database/bespoke.ts +++ b/backend/database/bespoke.ts @@ -402,10 +402,7 @@ export class BespokeQueries { const sinvNamesQuery = db.knex!(ModelNameEnum.SalesInvoice) .select('name') .where('isPOS', true) - .andWhereBetween('date', [ - DateTime.fromJSDate(fromDate).toSQLDate(), - DateTime.fromJSDate(toDate).toSQLDate(), - ]); + .andWhereBetween('date', [fromDate.toISOString(), toDate.toISOString()]); if (lastShiftClosingDate) { sinvNamesQuery.andWhere( diff --git a/src/pages/POS/ClosePOSShiftModal.vue b/src/pages/POS/ClosePOSShiftModal.vue index c97254eb8..780111377 100644 --- a/src/pages/POS/ClosePOSShiftModal.vue +++ b/src/pages/POS/ClosePOSShiftModal.vue @@ -121,14 +121,16 @@ export default defineComponent({ }, methods: { async setTransactedAmount() { - if (!fyo.singles.POSShift?.openingDate) { + this.posOpeningShiftDoc = await getPOSOpeningShiftDoc(fyo); + + const fromDate = this.posOpeningShiftDoc?.openingDate as Date; + if (!fromDate) { return; } - const fromDate = this.posOpeningShiftDoc?.openingDate as Date; + this.transactedAmount = await fyo.db.getPOSTransactedAmount( fromDate, - new Date(), - fyo.singles.POSShift.closingDate as Date + new Date() ); }, seedClosingCash() { @@ -160,19 +162,7 @@ export default defineComponent({ return; } - let expectedAmount = fyo.pesa(0); - - if (row.paymentMethod === 'Cash') { - expectedAmount = expectedAmount.add( - this.posOpeningShiftDoc?.openingCashAmount as Money - ); - } - - if (row.paymentMethod === 'Transfer') { - expectedAmount = expectedAmount.add( - this.posOpeningShiftDoc?.openingTransferAmount as Money - ); - } + let expectedAmount = row.amount ?? fyo.pesa(0); if (this.transactedAmount) { expectedAmount = expectedAmount.add( diff --git a/src/pages/POS/OpenPOSShiftModal.vue b/src/pages/POS/OpenPOSShiftModal.vue index 36c7dce03..7a1c9588f 100644 --- a/src/pages/POS/OpenPOSShiftModal.vue +++ b/src/pages/POS/OpenPOSShiftModal.vue @@ -141,16 +141,13 @@ export default defineComponent({ this.posShiftDoc.openingAmounts = []; - await this.posShiftDoc.set('openingAmounts', [ - { - paymentMethod: 'Cash', - amount: fyo.pesa(0), - }, - { - paymentMethod: 'Transfer', - amount: fyo.pesa(0), - }, - ]); + const paymentMethods = ( + (await this.fyo.db.getAll(ModelNameEnum.PaymentMethod, { + fields: ['name'], + })) as { name: string }[] + ).map((doc) => ({ paymentMethod: doc.name, amount: fyo.pesa(0) })); + + await this.posShiftDoc.set('openingAmounts', paymentMethods); }, async seedDefaults() { if (!!this.posShiftDoc?.isShiftOpen) {