Skip to content

Commit cbb182d

Browse files
authored
Merge pull request #46 from MVVYSHNAV/dev
Feat : Autofill Final Amount with Default mode of payment
2 parents 891e394 + c3b0ec6 commit cbb182d

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

pos/src/components/PaymentDialog.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { usePOSStore } from '../store/pos-store';
44
import { cn, formatCurrency } from '../lib/utils';
55
import { Button, Input, Dialog, DialogContent } from './ui';
66
import { call } from '../lib/frappe-sdk';
7+
import { DEFAULT_PAYMENT_MODE } from '../data/order-types';
78

89

910
interface PaymentDialogProps {
@@ -83,6 +84,19 @@ const PaymentDialog: React.FC<PaymentDialogProps> = ({
8384
const roundedFinalAdjustment = Math.round(finalAdjustment * 100) / 100;
8485
const showFinalAdjustment = Math.abs(roundedFinalAdjustment) > 0.001;
8586

87+
useEffect(()=>{
88+
const defaultPaymentModePresent=paymentModes.find((mode)=>mode===DEFAULT_PAYMENT_MODE)
89+
//only one payment mode should be present, then autofill the final amount, if not do not fill
90+
const otherPaymentModesNotEntered=Object.keys(paymentInputs).length<=1;
91+
if(finalTotal && paymentModes && DEFAULT_PAYMENT_MODE && defaultPaymentModePresent && otherPaymentModesNotEntered){
92+
//check if default payment mode is present in paymentModes
93+
setPaymentInputs((prev)=>({
94+
...prev,
95+
[DEFAULT_PAYMENT_MODE]:String(finalTotal)
96+
}))
97+
}
98+
},[finalTotal,paymentModes])
99+
86100
// Helper to calculate remaining balance
87101
const getRemainingBalance = (currentId: string) => {
88102
const totalEntered = Object.entries(paymentInputs)

pos/src/data/order-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const ORDER_TYPES: OrderTypes[] = [
3838

3939
export const DINE_IN="Dine In"
4040
export const DEFAULT_ORDER_TYPE="Take Away"
41+
export const DEFAULT_PAYMENT_MODE="Cash"
4142

4243
export type OrderStatusType = "Draft" | "Unbilled" | "Recently Paid" | "Paid" | "Consolidated" | "Return";
4344

0 commit comments

Comments
 (0)