@@ -61,18 +61,6 @@ const PaymentDialog: React.FC<PaymentDialogProps> = ({
6161 fetchPaymentModes ( ) ;
6262 } , [ fetchPaymentModes ] ) ;
6363
64- // Calculate split payment total
65- const payments = paymentModes
66- . map ( ( mode : any ) => {
67- const id = typeof mode === 'string' ? mode : mode . id ;
68- const amount = parseFloat ( paymentInputs [ id ] || '' ) ;
69- return amount > 0 ? { mode_of_payment : id , amount } : null ;
70- } )
71- . filter ( Boolean ) ;
72- const paymentsTotal = payments . reduce ( ( sum , p : any ) => sum + p . amount , 0 ) ;
73- const shortfall = finalTotal - paymentsTotal ;
74- const isShort = shortfall > 0.005 ;
75-
7664 // baseTotal represents the amount before any invoice-level discount (like pricing rule or manual discount)
7765 const baseTotal = grandTotal + ( discountAmount || 0 ) ;
7866
@@ -100,6 +88,19 @@ const PaymentDialog: React.FC<PaymentDialogProps> = ({
10088 const discountedTotal = Math . max ( 0 , subtotal - totalDiscount ) ;
10189 // If discount is applied, round up; else, round normally
10290 const finalTotal = appliedDiscount > 0 ? Math . ceil ( discountedTotal ) : Math . round ( discountedTotal ) ;
91+
92+ // Calculate split payment total
93+ const payments = paymentModes
94+ . map ( ( mode : any ) => {
95+ const id = typeof mode === 'string' ? mode : mode . id ;
96+ const amount = parseFloat ( paymentInputs [ id ] || '' ) ;
97+ return amount > 0 ? { mode_of_payment : id , amount } : null ;
98+ } )
99+ . filter ( Boolean ) ;
100+ const paymentsTotal = payments . reduce ( ( sum , p : any ) => sum + p . amount , 0 ) ;
101+ const shortfall = finalTotal - paymentsTotal ;
102+ const isShort = shortfall > 0.005 ;
103+
103104 const finalAdjustment = finalTotal - discountedTotal ;
104105 const roundedFinalAdjustment = Math . round ( finalAdjustment * 100 ) / 100 ;
105106 const showFinalAdjustment = Math . abs ( roundedFinalAdjustment ) > 0.001 ;
0 commit comments