From 9a02b8b61a1c72651cffdf648f8c253d542d443a Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Sun, 8 Nov 2026 12:23:37 +0300 Subject: [PATCH] Ancillary orders 0 payment handled --- .../ancillary_procedures_details_page.dart | 78 +++++++++++++++---- 1 file changed, 65 insertions(+), 13 deletions(-) diff --git a/lib/presentation/todo_section/ancillary_procedures_details_page.dart b/lib/presentation/todo_section/ancillary_procedures_details_page.dart index 24a6d97b..50998485 100644 --- a/lib/presentation/todo_section/ancillary_procedures_details_page.dart +++ b/lib/presentation/todo_section/ancillary_procedures_details_page.dart @@ -16,12 +16,15 @@ import 'package:hmg_patient_app_new/features/todo_section/models/resp_models/anc import 'package:hmg_patient_app_new/features/todo_section/models/resp_models/ancillary_order_procedures_detail_response_model.dart'; import 'package:hmg_patient_app_new/features/todo_section/todo_section_view_model.dart'; import 'package:hmg_patient_app_new/generated/locale_keys.g.dart'; +import 'package:hmg_patient_app_new/presentation/home/navigation_screen.dart'; import 'package:hmg_patient_app_new/presentation/todo_section/ancillary_order_payment_page.dart'; import 'package:hmg_patient_app_new/presentation/todo_section/widgets/ancillary_orders_list.dart'; import 'package:hmg_patient_app_new/theme/colors.dart'; import 'package:hmg_patient_app_new/widgets/appbar/collapsing_list_view.dart'; import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart'; import 'package:hmg_patient_app_new/widgets/chip/app_custom_chip_widget.dart'; +import 'package:hmg_patient_app_new/widgets/common_bottom_sheet.dart'; +import 'package:hmg_patient_app_new/widgets/loader/bottomsheet_loader.dart'; import 'package:hmg_patient_app_new/widgets/routes/custom_page_route.dart'; import 'package:provider/provider.dart'; @@ -678,20 +681,24 @@ class _AncillaryOrderDetailsListState extends State { onPressed: () { // Navigate to payment page with selected procedures todoSectionViewModel.setIsAncillaryOrdersNeedReloading(true); - Navigator.of(context).push( - CustomPageRoute( - page: AncillaryOrderPaymentPage( - appointmentNoVida: widget.appointmentNoVida, - orderNo: widget.orderNo, - projectID: widget.projectID, - clinicID: widget.clinicID, - selectedProcedures: selectedProcedures, - totalAmount: _getTotalAmount(), - appointmentDate: orderData.appointmentDate, - setupID: widget.setupID, + if (_getTotalAmount() == 0 || _getTotalAmount() == 0.0) { + _autoGenerateInvoice(); + } else { + Navigator.of(context).push( + CustomPageRoute( + page: AncillaryOrderPaymentPage( + appointmentNoVida: widget.appointmentNoVida, + orderNo: widget.orderNo, + projectID: widget.projectID, + clinicID: widget.clinicID, + selectedProcedures: selectedProcedures, + totalAmount: _getTotalAmount(), + appointmentDate: orderData.appointmentDate, + setupID: widget.setupID, + ), ), - ), - ); + ); + } }, isDisabled: !isButtonEnabled, textColor: Colors.white, @@ -704,4 +711,49 @@ class _AncillaryOrderDetailsListState extends State { ).paddingOnly(left: 16.h, top: 24.h, right: 16.h, bottom: 0.h), ); } + + void _autoGenerateInvoice() { + LoaderBottomSheet.showLoader(loadingText: LocaleKeys.generatingInvoicePleaseWait.tr(context: context)); + + List selectedProcListAPI = selectedProcedures.map((element) { + return { + "ApprovalLineItemNo": element.approvalLineItemNo, + "OrderLineItemNo": element.orderLineItemNo, + "ProcedureID": element.procedureID, + }; + }).toList(); + + todoSectionViewModel.autoGenerateAncillaryOrdersInvoice( + orderNo: widget.orderNo, + projectID: widget.projectID, + appointmentNo: widget.appointmentNoVida, + selectedProcedures: selectedProcListAPI, + languageID: appState.isArabic() ? 1 : 2, + onSuccess: (response) { + LoaderBottomSheet.hideLoader(); + final invoiceNo = response['AncillaryOrderInvoiceList']?[0]?['InvoiceNo']; + showCommonBottomSheetWithoutHeight(context, + child: Utils.getSuccessWidget(loadingText: "${LocaleKeys.paymentCompletedSuccessfully.tr(context: context)}, ${LocaleKeys.hereIsYourInvoiceNumber.tr(context: context)}$invoiceNo"), + isCloseButtonVisible: true, + isDismissible: true, + isFullScreen: false, + isAutoDismiss: true, callBackFunc: () { + // Pop until we reach the LandingPage + todoSectionViewModel.setIsAncillaryOrdersNeedReloading(true); + Navigator.pushAndRemoveUntil( + context, + CustomPageRoute( + page: LandingNavigation(), + ), + (r) => false); + }); + }, + onError: (error) { + LoaderBottomSheet.hideLoader(); + todoSectionViewModel.setProcessingPayment(false); + showCommonBottomSheetWithoutHeight(context, + child: Utils.getErrorWidget(loadingText: error.toString()), isCloseButtonVisible: true, isDismissible: true, isFullScreen: false, callBackFunc: () {}); + }, + ); + } }