Skip to content

Commit 352ecee

Browse files
authored
Merge pull request #1065 from AbleKSaju/feat-submit-inv
feat: submit and hold invoice for later use in POS
2 parents cdeb7a9 + 3a1a692 commit 352ecee

File tree

6 files changed

+135
-33
lines changed

6 files changed

+135
-33
lines changed

models/inventory/Point of Sale/POSSettings.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export class POSSettings extends Doc {
1414
checkDigits?: number;
1515
itemCodeDigits?: number;
1616
itemWeightDigits?: number;
17-
1817
posUI?: 'Classic' | 'Modern';
1918

2019
static filters: FiltersMap = {

src/pages/POS/ClassicPOS.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
(date) => emitEvent('setTransferClearanceDate', date)
5353
"
5454
@create-transaction="
55-
(createTransaction) => emitEvent('createTransaction', createTransaction)
55+
(print, status) => emitEvent('createTransaction', print, status)
5656
"
5757
/>
5858

@@ -287,7 +287,7 @@
287287
>
288288
<slot>
289289
<p class="uppercase text-lg text-white font-semibold">
290-
{{ t`Pay` }}
290+
{{ t`Buy` }}
291291
</p>
292292
</slot>
293293
</Button>

src/pages/POS/ModernPOS.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
(date) => emitEvent('setTransferClearanceDate', date)
5353
"
5454
@create-transaction="
55-
(createTransaction) => emitEvent('createTransaction', createTransaction)
55+
(print, status) => emitEvent('createTransaction', print, status)
5656
"
5757
/>
5858

@@ -210,7 +210,7 @@
210210
>
211211
<slot>
212212
<p class="uppercase text-lg text-white font-semibold">
213-
{{ t`Pay` }}
213+
{{ t`Buy` }}
214214
</p>
215215
</slot>
216216
</Button>

src/pages/POS/POS.vue

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ import {
138138
ItemQtyMap,
139139
ItemSerialNumbers,
140140
} from 'src/components/POS/types';
141+
import { ValidationError } from 'fyo/utils/errors';
141142
142143
const COMPONENT_NAME = 'POS';
143144
@@ -466,6 +467,10 @@ export default defineComponent({
466467
467468
this.sinvDoc = salesInvoiceDoc;
468469
this.toggleModal('SavedInvoice', false);
470+
471+
if (doc.submitted) {
472+
this.toggleModal('Payment');
473+
}
469474
},
470475
setTransferAmount(amount: Money = fyo.pesa(0)) {
471476
this.transferAmount = amount;
@@ -478,19 +483,25 @@ export default defineComponent({
478483
},
479484
480485
async addItem(item: POSItem | Item | undefined, quantity?: number) {
481-
await this.sinvDoc.runFormulas();
486+
try {
487+
await this.sinvDoc.runFormulas();
482488
483-
if (!item) {
484-
return;
485-
}
489+
if (this.sinvDoc.isSubmitted) {
490+
throw new ValidationError(
491+
t`Cannot add an item to a submitted invoice.`
492+
);
493+
}
494+
495+
if (!item) {
496+
return;
497+
}
486498
487-
const existingItems =
488-
this.sinvDoc.items?.filter(
489-
(invoiceItem) =>
490-
invoiceItem.item === item.name && !invoiceItem.isFreeItem
491-
) ?? [];
499+
const existingItems =
500+
this.sinvDoc.items?.filter(
501+
(invoiceItem) =>
502+
invoiceItem.item === item.name && !invoiceItem.isFreeItem
503+
) ?? [];
492504
493-
try {
494505
if (item.hasBatch) {
495506
for (const invItem of existingItems) {
496507
const itemQty = invItem.quantity ?? 0;
@@ -571,13 +582,26 @@ export default defineComponent({
571582
await this.applyPricingRule();
572583
await this.sinvDoc.runFormulas();
573584
},
574-
575-
async createTransaction(shouldPrint = false) {
585+
async createTransaction(shouldPrint = false, isPay = false) {
576586
try {
577587
await this.validate();
578588
await this.submitSinvDoc();
579-
await this.makePayment(shouldPrint);
580-
await this.makeStockTransfer();
589+
590+
if (this.sinvDoc.stockNotTransferred) {
591+
await this.makeStockTransfer();
592+
}
593+
594+
if (isPay) {
595+
await this.makePayment(shouldPrint);
596+
}
597+
598+
if (shouldPrint) {
599+
await routeTo(
600+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
601+
`/print/${this.sinvDoc.schemaName}/${this.sinvDoc.name}`
602+
);
603+
}
604+
581605
await this.afterTransaction();
582606
await this.setItems();
583607
} catch (error) {

src/pages/POS/PaymentModal.vue

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,30 @@
130130
/>
131131
</div>
132132

133-
<div class="grid grid-cols-2 gap-4 fixed bottom-8" style="width: 25rem">
134-
<div class="col-span-2">
133+
<div class="grid grid-cols-2 gap-4 bottom-8">
134+
<div class="col-span-1">
135+
<Button
136+
class="w-full bg-violet-500 dark:bg-violet-700"
137+
style="padding: 1.35rem"
138+
:disabled="disableSubmitButton"
139+
@click="submitTransaction()"
140+
>
141+
<slot>
142+
<p
143+
class="uppercase text-lg text-white font-semibold"
144+
:disabled="sinvDoc.submitted"
145+
>
146+
{{ t`Submit` }}
147+
</p>
148+
</slot>
149+
</Button>
150+
</div>
151+
152+
<div class="col-span-1">
135153
<Button
136154
class="w-full bg-red-500 dark:bg-red-700"
137155
style="padding: 1.35rem"
138-
@click="$emit('toggleModal', 'Payment')"
156+
@click="cancelTransaction()"
139157
>
140158
<slot>
141159
<p class="uppercase text-lg text-white font-semibold">
@@ -149,26 +167,27 @@
149167
<Button
150168
class="w-full bg-blue-500 dark:bg-blue-700"
151169
style="padding: 1.35rem"
152-
:disabled="disableSubmitButton"
153-
@click="submitTransaction()"
170+
:disabled="disablePayButton"
171+
@click="payTransaction()"
154172
>
155173
<slot>
156174
<p class="uppercase text-lg text-white font-semibold">
157-
{{ t`Submit` }}
175+
{{ t`Pay` }}
158176
</p>
159177
</slot>
160178
</Button>
161179
</div>
180+
162181
<div class="col-span-1">
163182
<Button
164183
class="w-full bg-green-500 dark:bg-green-700"
165184
style="padding: 1.35rem"
166-
:disabled="disableSubmitButton"
167-
@click="$emit('createTransaction', true)"
185+
:disabled="disablePayButton"
186+
@click="$emit('createTransaction', true, true)"
168187
>
169188
<slot>
170189
<p class="uppercase text-lg text-white font-semibold">
171-
{{ t`Submit & Print` }}
190+
{{ t`Pay & Print` }}
172191
</p>
173192
</slot>
174193
</Button>
@@ -293,6 +312,26 @@ export default defineComponent({
293312
return false;
294313
},
295314
disableSubmitButton(): boolean {
315+
if (this.sinvDoc.submitted) {
316+
return true;
317+
}
318+
319+
if (
320+
(this.sinvDoc.grandTotal?.float as number) < 1 &&
321+
this.fyo.pesa(this.paidAmount.float).isZero()
322+
) {
323+
return true;
324+
}
325+
326+
if (
327+
this.paymentMethod !== 'Cash' &&
328+
(!this.transferRefNo || !this.transferClearanceDate)
329+
) {
330+
return true;
331+
}
332+
return false;
333+
},
334+
disablePayButton(): boolean {
296335
if (
297336
(this.sinvDoc.grandTotal?.float as number) < 1 &&
298337
this.fyo.pesa(this.paidAmount.float).isZero()
@@ -332,6 +371,13 @@ export default defineComponent({
332371
submitTransaction() {
333372
this.$emit('createTransaction');
334373
},
374+
payTransaction() {
375+
this.$emit('createTransaction', false, true);
376+
},
377+
cancelTransaction() {
378+
this.$emit('setPaidAmount', fyo.pesa(0));
379+
this.$emit('toggleModal', 'Payment');
380+
},
335381
},
336382
});
337383
</script>

src/pages/POS/SavedInvoiceModal.vue

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
11
<template>
2-
<Modal class="h-auto w-auto p-6" :set-close-listener="false">
3-
<p class="text-center font-semibold">{{ t`Saved Invoices` }}</p>
2+
<Modal class="h-auto w-auto p-5" :set-close-listener="false">
3+
<p class="text-center font-semibold">{{ t`Invoices` }}</p>
44

55
<hr class="mt-2 dark:border-gray-800" />
66

7+
<div class="flex justify-around items-center">
8+
<Button
9+
:background="false"
10+
class="w-full h-full p-2 mt-2"
11+
:class="{ 'dark:bg-gray-890 underline': savedInvoiceList }"
12+
@click="savedInvoiceList = true"
13+
>Saved</Button
14+
>
15+
16+
<Button
17+
:background="false"
18+
class="w-full h-full p-2 mt-2"
19+
:class="{ 'dark:bg-gray-890 underline': !savedInvoiceList }"
20+
@click="savedInvoiceList = false"
21+
>Submitted</Button
22+
>
23+
</div>
724
<Row
825
:ratio="ratio"
926
class="
1027
border
1128
flex
1229
items-center
13-
mt-4
30+
mt-2
1431
px-2
1532
w-full
1633
rounded-t-md
@@ -28,12 +45,12 @@
2845
</Row>
2946

3047
<div
31-
v-if="savedInvoices.length"
48+
v-if="savedInvoiceList ? savedInvoices.length : submittedInvoices.length"
3249
class="overflow-y-auto custom-scroll custom-scroll-thumb2"
3350
style="height: 65vh; width: 60vh"
3451
>
3552
<Row
36-
v-for="row in savedInvoices as SalesInvoice[]"
53+
v-for="row in savedInvoiceList ? savedInvoices : submittedInvoices"
3754
:key="row.name"
3855
:ratio="ratio"
3956
:border="true"
@@ -88,6 +105,7 @@ import { SalesInvoice } from 'models/baseModels/SalesInvoice/SalesInvoice';
88105
import { defineComponent, inject } from 'vue';
89106
import { ModelNameEnum } from 'models/types';
90107
import { Field } from 'schemas/types';
108+
import { Money } from 'pesa';
91109
92110
export default defineComponent({
93111
name: 'SavedInvoiceModal',
@@ -108,7 +126,9 @@ export default defineComponent({
108126
},
109127
data() {
110128
return {
129+
savedInvoiceList: true,
111130
savedInvoices: [] as SalesInvoice[],
131+
submittedInvoices: [] as SalesInvoice[],
112132
isModalVisible: false,
113133
};
114134
},
@@ -152,14 +172,17 @@ export default defineComponent({
152172
async modalStatus(newVal) {
153173
if (newVal) {
154174
await this.setSavedInvoices();
175+
await this.setSubmittedInvoices();
155176
}
156177
},
157178
},
158179
async mounted() {
159180
await this.setSavedInvoices();
181+
await this.setSubmittedInvoices();
160182
},
161183
async activated() {
162184
await this.setSavedInvoices();
185+
await this.setSubmittedInvoices();
163186
},
164187
165188
methods: {
@@ -172,6 +195,16 @@ export default defineComponent({
172195
}
173196
)) as SalesInvoice[];
174197
},
198+
async setSubmittedInvoices() {
199+
const invoices = (await this.fyo.db.getAll(ModelNameEnum.SalesInvoice, {
200+
fields: [],
201+
filters: { isPOS: true, submitted: true, returnAgainst: null },
202+
})) as SalesInvoice[];
203+
204+
this.submittedInvoices = invoices.filter(
205+
(invoice) => !(invoice.outstandingAmount as Money).isZero()
206+
);
207+
},
175208
async selectedInvoice(row: SalesInvoice) {
176209
let selectedInvoiceDoc = (await this.fyo.doc.getDoc(
177210
ModelNameEnum.SalesInvoice,

0 commit comments

Comments
 (0)