@@ -4,6 +4,7 @@ import { usePOSStore } from '../store/pos-store';
44import { cn , formatCurrency } from '../lib/utils' ;
55import { Button , Input , Dialog , DialogContent } from './ui' ;
66import { call } from '../lib/frappe-sdk' ;
7+ import { DEFAULT_PAYMENT_MODE } from '../data/order-types' ;
78
89
910interface 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 )
0 commit comments