From f8a5b28447a91cadea207e3d94a6b6aa17dcfc13 Mon Sep 17 00:00:00 2001 From: akshayitzme Date: Mon, 30 Dec 2024 11:04:56 +0530 Subject: [PATCH] feat: mention pos shift closing and opening in each documents --- backend/database/bespoke.ts | 3 +-- .../Point of Sale/POSClosingShift.ts | 1 + .../Point of Sale/POSOpeningShift.ts | 1 + .../Point of Sale/POSClosingShift.json | 6 ++++++ .../Point of Sale/POSOpeningShift.json | 6 ++++++ src/pages/POS/ClosePOSShiftModal.vue | 21 ++++++++++++++++++- 6 files changed, 35 insertions(+), 3 deletions(-) diff --git a/backend/database/bespoke.ts b/backend/database/bespoke.ts index f2c855dc..4a088e9c 100644 --- a/backend/database/bespoke.ts +++ b/backend/database/bespoke.ts @@ -8,7 +8,6 @@ import { import { ModelNameEnum } from '../../models/types'; import DatabaseCore from './core'; import { BespokeFunction } from './types'; -import { DateTime } from 'luxon'; import { DocItem, ReturnDocItem } from 'models/inventory/types'; import { safeParseFloat } from 'utils/index'; import { Money } from 'pesa'; @@ -408,7 +407,7 @@ export class BespokeQueries { sinvNamesQuery.andWhere( 'created', '>', - DateTime.fromJSDate(lastShiftClosingDate).toUTC().toString() + lastShiftClosingDate.toISOString() ); } diff --git a/models/inventory/Point of Sale/POSClosingShift.ts b/models/inventory/Point of Sale/POSClosingShift.ts index 3d80754f..a1e4986a 100644 --- a/models/inventory/Point of Sale/POSClosingShift.ts +++ b/models/inventory/Point of Sale/POSClosingShift.ts @@ -7,6 +7,7 @@ export class POSClosingShift extends Doc { closingAmounts?: ClosingAmounts[]; closingCash?: ClosingCash[]; closingDate?: Date; + openingShift?: string; get closingCashAmount() { if (!this.closingCash) { diff --git a/models/inventory/Point of Sale/POSOpeningShift.ts b/models/inventory/Point of Sale/POSOpeningShift.ts index b9e023ad..82cab6cc 100644 --- a/models/inventory/Point of Sale/POSOpeningShift.ts +++ b/models/inventory/Point of Sale/POSOpeningShift.ts @@ -7,6 +7,7 @@ export class POSOpeningShift extends Doc { openingAmounts?: OpeningAmounts[]; openingCash?: OpeningCash[]; openingDate?: Date; + closingShift?: string; get openingCashAmount() { if (!this.openingCash) { diff --git a/schemas/app/inventory/Point of Sale/POSClosingShift.json b/schemas/app/inventory/Point of Sale/POSClosingShift.json index 16ddce86..401d5252 100644 --- a/schemas/app/inventory/Point of Sale/POSClosingShift.json +++ b/schemas/app/inventory/Point of Sale/POSClosingShift.json @@ -19,6 +19,12 @@ "fieldtype": "Table", "label": "Closing Amounts", "target": "ClosingAmounts" + }, + { + "fieldname": "openingShift", + "fieldtype": "Link", + "label": "Opening Shift", + "target": "POSOpeningShift" } ] } diff --git a/schemas/app/inventory/Point of Sale/POSOpeningShift.json b/schemas/app/inventory/Point of Sale/POSOpeningShift.json index e3927926..39adf621 100644 --- a/schemas/app/inventory/Point of Sale/POSOpeningShift.json +++ b/schemas/app/inventory/Point of Sale/POSOpeningShift.json @@ -19,6 +19,12 @@ "fieldtype": "Table", "label": "Opening Amounts", "target": "OpeningAmounts" + }, + { + "fieldname": "closingShift", + "fieldtype": "Link", + "label": "Closing Shift", + "target": "POSClosingShift" } ] } diff --git a/src/pages/POS/ClosePOSShiftModal.vue b/src/pages/POS/ClosePOSShiftModal.vue index 78011137..bb0dc6a0 100644 --- a/src/pages/POS/ClosePOSShiftModal.vue +++ b/src/pages/POS/ClosePOSShiftModal.vue @@ -75,6 +75,7 @@ import { getPOSOpeningShiftDoc, } from 'src/utils/pos'; import { POSClosingShift } from 'models/inventory/Point of Sale/POSClosingShift'; +import { ForbiddenError } from 'fyo/utils/errors'; export default defineComponent({ name: 'ClosePOSShiftModal', @@ -100,6 +101,11 @@ export default defineComponent({ transactedAmount: {} as Record | undefined, }; }, + computed: { + isOnline() { + return !!navigator.onLine; + }, + }, watch: { openModal: { async handler() { @@ -190,10 +196,23 @@ export default defineComponent({ }, async handleSubmit() { try { + if (!this.isOnline) { + throw new ForbiddenError( + t`Device is offline. Please connect to a network to continue.` + ); + } + validateClosingAmounts(this.posClosingShiftDoc as POSClosingShift); - await this.posClosingShiftDoc?.set('isShiftOpen', false); await this.posClosingShiftDoc?.set('closingDate', new Date()); + await this.posClosingShiftDoc?.set( + 'openingShift', + this.posOpeningShiftDoc?.name + ); await this.posClosingShiftDoc?.sync(); + await this.posOpeningShiftDoc?.setAndSync( + 'closingShift', + this.posClosingShiftDoc?.name + ); await transferPOSCashAndWriteOff( fyo, this.posClosingShiftDoc as POSClosingShift