From 1ee02c793fd496e296184020ddc69d86c61984ad Mon Sep 17 00:00:00 2001 From: SurendarSuri30 Date: Wed, 22 Jul 2026 11:42:57 +0530 Subject: [PATCH] summary hide and show --- android/app/build.gradle | 4 +- lib/pages/enrollment/addons.dart | 1891 +++++++++++++------------- lib/pages/enrollment/empDetails.dart | 557 ++++---- lib/pages/enrollment/empReview.dart | 1034 ++++++-------- pubspec.yaml | 4 +- 5 files changed, 1640 insertions(+), 1850 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 2f7c3bb..ebec86e 100755 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -19,12 +19,12 @@ if (project.hasProperty('google-services.json')) { def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { - flutterVersionCode = '69' + flutterVersionCode = '70' } def flutterVersionName = localProperties.getProperty('flutter.versionName') if (flutterVersionName == null) { - flutterVersionName = '2.0.30' + flutterVersionName = '2.0.31' } def keystoreProperties = new Properties() diff --git a/lib/pages/enrollment/addons.dart b/lib/pages/enrollment/addons.dart index c04baf6..bf2f5b6 100755 --- a/lib/pages/enrollment/addons.dart +++ b/lib/pages/enrollment/addons.dart @@ -104,7 +104,8 @@ class _addOnsDetailsState extends State { dynamic opdSiPremiumValue; dynamic opdSiPremiumGst; dynamic opdSiTotalAmt; - bool opdIsPremiumSummary = false; + /// 0 = hide, 1 = full summary, 2 = total only + int opdIsPremiumSummary = 0; dynamic topUpSiParentPolicies = []; dynamic topUpParentClientPolicyId; dynamic topUpParentSlabRates; @@ -118,7 +119,8 @@ class _addOnsDetailsState extends State { dynamic topUpParentSiPremiumValue; dynamic topUpParentSiPremiumGst; dynamic topUpParentSiTotalAmt; - bool topUpParentIsPremiumSummary = false; + /// 0 = hide, 1 = full summary, 2 = total only + int topUpParentIsPremiumSummary = 0; dynamic topUpParentTypeName; int topUpParentOpenForEnrollment = 0; dynamic addOnsDependentPolicies = []; @@ -130,7 +132,8 @@ class _addOnsDetailsState extends State { dynamic addOnsDependentPolicyName; dynamic addOnsDependentPolicyType; dynamic addOnsDependentECardDownload; - bool addOnsDependentIsPremiumSummary = false; + /// 0 = hide, 1 = full summary, 2 = total only + int addOnsDependentIsPremiumSummary = 0; dynamic addOnsDependentRelationShip; int addOnsDependentOpenForEnrollment = 0; dynamic siValue; @@ -142,7 +145,8 @@ class _addOnsDetailsState extends State { dynamic addOnsDependentTotalAmt; // dynamic topUpSiTotalAmt; dynamic topUpSiTotalAmt; - bool topUpIsPremiumSummary = false; + /// 0 = hide, 1 = full summary, 2 = total only + int topUpIsPremiumSummary = 0; late TextEditingController _relationShipController; late TextEditingController _dobController; late TextEditingController _memberNameController; @@ -259,25 +263,107 @@ class _addOnsDetailsState extends State { } bool isPremiumEnabled(dynamic value) { - if (value == null) return false; - if (value is bool) return value; - if (value is num) return value.toInt() != 0; - final normalized = value.toString().trim().toLowerCase(); - if (normalized == 'true' || normalized == 'yes') return true; - final intValue = int.tryParse(normalized) ?? 0; - return intValue != 0; + return parsePremiumSummaryMode(value) != 0; } - bool shouldShowPremiumSummary({ - required bool isPremiumSummary, - dynamic premiumValue, - dynamic gstValue, - dynamic totalValue, + /// 0 = hide premium summary, 1 = full summary, 2 = total only + int parsePremiumSummaryMode(dynamic value) { + if (value == null) return 0; + if (value is bool) return value ? 1 : 0; + if (value is num) return value.toInt(); + final normalized = value.toString().trim().toLowerCase(); + if (normalized == 'true' || normalized == 'yes') return 1; + if (normalized == 'false' || normalized == 'no') return 0; + return int.tryParse(normalized) ?? 0; + } + + bool shouldShowPremiumSummary(int mode) => mode == 1 || mode == 2; + + bool shouldShowFullPremiumBreakdown(int mode) => mode == 1; + + bool _policyListHasFullPremiumBreakdown(dynamic policies) { + if (policies is! List) return false; + for (final policy in policies) { + if (policy is! Map) continue; + if (shouldShowFullPremiumBreakdown( + parsePremiumSummaryMode(policy['is_premium_summery']))) { + return true; + } + } + return false; + } + + /// True when any visible premium-summary row needs Additional Premium / GST columns. + bool hasAnyFullPremiumBreakdown() { + return _policyListHasFullPremiumBreakdown(gpaPolicies) || + _policyListHasFullPremiumBreakdown(gmcPolicies); + } + + Widget _premiumSummaryHeaderCell( + BuildContext context, + String label, { + TextAlign textAlign = TextAlign.start, }) { - return isPremiumSummary || - premiumValue != null || - gstValue != null || - totalValue != null; + return TableCell( + child: Padding( + padding: EdgeInsets.all(8.0), + child: SizedBox( + width: double.infinity, + child: Text( + label, + textAlign: textAlign, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) ? 16 : 13, + fontWeight: FontWeight.bold, + ), + ), + ), + ), + ); + } + + Widget _premiumSummaryValueCell( + BuildContext context, + String value, { + TextAlign textAlign = TextAlign.start, + }) { + return TableCell( + child: Padding( + padding: EdgeInsets.all(8.0), + child: SizedBox( + width: double.infinity, + child: Text( + value, + textAlign: textAlign, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) ? 14 : 12, + ), + ), + ), + ), + ); + } + + List buildPremiumSummaryRowCells({ + required BuildContext context, + required String policyLabel, + required String premiumValue, + required String gstValue, + required String totalValue, + required bool includeBreakdownColumns, + required bool showBreakdownValues, + }) { + final totalAlign = + includeBreakdownColumns ? TextAlign.start : TextAlign.end; + return [ + _premiumSummaryValueCell(context, policyLabel), + if (includeBreakdownColumns) ...[ + _premiumSummaryValueCell( + context, showBreakdownValues ? premiumValue : ''), + _premiumSummaryValueCell(context, showBreakdownValues ? gstValue : ''), + ], + _premiumSummaryValueCell(context, totalValue, textAlign: totalAlign), + ]; } List _extractUniqueSiValues(dynamic slabRates) { @@ -598,7 +684,7 @@ class _addOnsDetailsState extends State { topUpSiTotalAmt = topUpSiPremiumValue + topUpSiPremiumGst; setState(() { - topUpIsPremiumSummary = isPremiumEnabled(topUpSiPolicies['gmc_si_topup']?['is_premium_summery']); + topUpIsPremiumSummary = parsePremiumSummaryMode(topUpSiPolicies['gmc_si_topup']?['is_premium_summery']); }); @@ -688,7 +774,7 @@ class _addOnsDetailsState extends State { opdSiTotalAmt = opdSiPremiumValue + opdSiPremiumGst; setState(() { - opdIsPremiumSummary = isPremiumEnabled(opdPolicies['gmc_opd']?['is_premium_summery']); + opdIsPremiumSummary = parsePremiumSummaryMode(opdPolicies['gmc_opd']?['is_premium_summery']); }); @@ -817,7 +903,7 @@ class _addOnsDetailsState extends State { topUpParentSiPremiumValue + topUpParentSiPremiumGst; setState(() { - topUpParentIsPremiumSummary = isPremiumEnabled(topUpSiParentPolicies['gmc_si_parent_topup']?['is_premium_summery']); + topUpParentIsPremiumSummary = parsePremiumSummaryMode(topUpSiParentPolicies['gmc_si_parent_topup']?['is_premium_summery']); logDebug(topUpParentECardDownload); }); @@ -938,7 +1024,7 @@ class _addOnsDetailsState extends State { ['eCardDownload']; setState(() { - addOnsDependentIsPremiumSummary = isPremiumEnabled(addOnsDependentPolicies['gmc_dependent_addon']?['is_premium_summery']); + addOnsDependentIsPremiumSummary = parsePremiumSummaryMode(addOnsDependentPolicies['gmc_dependent_addon']?['is_premium_summery']); }); logDebug('addOnsDependentIsPremiumSummery $addOnsDependentIsPremiumSummary'); @@ -1488,8 +1574,6 @@ class _addOnsDetailsState extends State { print('topUpSiPremiumGst $topUpSiPremiumGst'); print('topUpSiTotalAmt $topUpSiTotalAmt'); - topUpIsPremiumSummary = true; - // topUpSiTotalAmt = (topUpSum as double).toInt(); }); sendAddonsGmcSiToAPI(); @@ -1616,7 +1700,6 @@ class _addOnsDetailsState extends State { opdSiPremiumGst = opdGstSum.toInt(); opdSiTotalAmt = opdSiPremiumValue + opdSiPremiumGst; print('opdSiPremiumValue $opdSiTotalAmt'); - opdIsPremiumSummary = true; }); sendAddonsGmcOPDToAPI(); } @@ -2813,93 +2896,92 @@ class _addOnsDetailsState extends State { if (Responsive.isDesktop(context) && _addOnsDependentSwitcher && shouldShowPremiumSummary( - isPremiumSummary: addOnsDependentIsPremiumSummary, - premiumValue: addOnDependentPremiumValue, - gstValue: addOnsDependentPremiumGst, - totalValue: addOnsDependentTotalAmt, - )) + addOnsDependentIsPremiumSummary)) Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Expanded( - flex: 5, - child: Container( - alignment: - Alignment.center, - child: Column( - mainAxisAlignment: - MainAxisAlignment - .center, - crossAxisAlignment: - CrossAxisAlignment - .center, - children: [ - Text( - 'Additional Premium', - textAlign: - TextAlign.start, - style: GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 16 : 13, - fontWeight: - FontWeight - .w500, + if (shouldShowFullPremiumBreakdown( + addOnsDependentIsPremiumSummary)) ...[ + Expanded( + flex: 5, + child: Container( + alignment: + Alignment.center, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'Additional Premium', + textAlign: + TextAlign.start, + style: GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 16 : 13, + fontWeight: + FontWeight + .w500, + ), ), - ), - Text( - addOnDependentPremiumValue != - null - ? '₹ $addOnDependentPremiumValue/Year' - : 'N/A', - textAlign: - TextAlign.start, - style: GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12, + Text( + addOnDependentPremiumValue != + null + ? '₹ $addOnDependentPremiumValue/Year' + : 'N/A', + textAlign: + TextAlign.start, + style: GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 14 : 12, + ), ), - ), - ], - ))), - Expanded( - flex: 2, - child: Container( - alignment: - Alignment.center, - child: Column( - mainAxisAlignment: - MainAxisAlignment - .center, - crossAxisAlignment: - CrossAxisAlignment - .center, - children: [ - Text( - 'GST', - textAlign: - TextAlign.start, - style: GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 16 : 13, - fontWeight: - FontWeight - .w500, + ], + ))), + Expanded( + flex: 2, + child: Container( + alignment: + Alignment.center, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'GST', + textAlign: + TextAlign.start, + style: GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 16 : 13, + fontWeight: + FontWeight + .w500, + ), ), - ), - Text( - addOnsDependentPremiumGst != - null - ? '₹ $addOnsDependentPremiumGst/-' - : 'N/A', - textAlign: - TextAlign.start, - style: GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12, + Text( + addOnsDependentPremiumGst != + null + ? '₹ $addOnsDependentPremiumGst/-' + : 'N/A', + textAlign: + TextAlign.start, + style: GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 14 : 12, + ), ), - ), - ], - ))), + ], + ))), + ], Expanded( flex: 5, child: Container( @@ -2944,16 +3026,14 @@ class _addOnsDetailsState extends State { if (!Responsive.isDesktop(context) && _addOnsDependentSwitcher == true && shouldShowPremiumSummary( - isPremiumSummary: addOnsDependentIsPremiumSummary, - premiumValue: addOnDependentPremiumValue, - gstValue: addOnsDependentPremiumGst, - totalValue: addOnsDependentTotalAmt, - )) + addOnsDependentIsPremiumSummary)) Container( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ + if (shouldShowFullPremiumBreakdown( + addOnsDependentIsPremiumSummary)) ...[ Row( crossAxisAlignment: CrossAxisAlignment.start, @@ -3082,6 +3162,7 @@ class _addOnsDetailsState extends State { ))), ], ), + ], Row( crossAxisAlignment: CrossAxisAlignment.start, @@ -3466,90 +3547,87 @@ class _addOnsDetailsState extends State { SizedBox(height: 20), if (Responsive.isDesktop(context) && _topUpSiSwitcher == true && - shouldShowPremiumSummary( - isPremiumSummary: topUpIsPremiumSummary, - premiumValue: topUpSiPremiumValue, - gstValue: topUpSiPremiumGst, - totalValue: topUpSiTotalAmt, - )) + shouldShowPremiumSummary(topUpIsPremiumSummary)) Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Expanded( - flex: 5, - child: Container( - alignment: Alignment.center, - child: Column( - mainAxisAlignment: - MainAxisAlignment - .center, - crossAxisAlignment: - CrossAxisAlignment - .center, - children: [ - Text( - 'Additional Premium', - textAlign: - TextAlign.start, - style: GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 16 : 13, - fontWeight: - FontWeight.w500, + if (shouldShowFullPremiumBreakdown(topUpIsPremiumSummary)) ...[ + Expanded( + flex: 5, + child: Container( + alignment: Alignment.center, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'Additional Premium', + textAlign: + TextAlign.start, + style: GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 16 : 13, + fontWeight: + FontWeight.w500, + ), ), - ), - Text( - topUpSiPremiumValue != - null - ? '₹ $topUpSiPremiumValue/Year' - : 'N/A', - textAlign: - TextAlign.start, - style: GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12, + Text( + topUpSiPremiumValue != + null + ? '₹ $topUpSiPremiumValue/Year' + : 'N/A', + textAlign: + TextAlign.start, + style: GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 14 : 12, + ), ), - ), - ], - ))), - Expanded( - flex: 2, - child: Container( - alignment: Alignment.center, - child: Column( - mainAxisAlignment: - MainAxisAlignment - .center, - crossAxisAlignment: - CrossAxisAlignment - .center, - children: [ - Text( - 'GST', - textAlign: - TextAlign.start, - style: GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 16 : 13, - fontWeight: - FontWeight.w500, + ], + ))), + Expanded( + flex: 2, + child: Container( + alignment: Alignment.center, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'GST', + textAlign: + TextAlign.start, + style: GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 16 : 13, + fontWeight: + FontWeight.w500, + ), ), - ), - Text( - topUpSiPremiumGst != - null - ? '₹ $topUpSiPremiumGst/-' - : 'N/A', - textAlign: - TextAlign.start, - style: GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12, + Text( + topUpSiPremiumGst != + null + ? '₹ $topUpSiPremiumGst/-' + : 'N/A', + textAlign: + TextAlign.start, + style: GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 14 : 12, + ), ), - ), - ], - ))), + ], + ))), + ], Expanded( flex: 5, child: Container( @@ -3591,145 +3669,142 @@ class _addOnsDetailsState extends State { ), if (!Responsive.isDesktop(context) && _topUpSiSwitcher == true && - shouldShowPremiumSummary( - isPremiumSummary: topUpIsPremiumSummary, - premiumValue: topUpSiPremiumValue, - gstValue: topUpSiPremiumGst, - totalValue: topUpSiTotalAmt, - )) + shouldShowPremiumSummary(topUpIsPremiumSummary)) Container( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Row( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Expanded( - flex: 6, - child: Container( - alignment: Alignment - .centerLeft, - child: Column( - mainAxisAlignment: - MainAxisAlignment - .center, - crossAxisAlignment: - CrossAxisAlignment - .center, - children: [ - Text( - 'Additional Premium', - textAlign: - TextAlign - .start, - style: - GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 16 : 13, - fontWeight: - FontWeight - .w500, + if (shouldShowFullPremiumBreakdown(topUpIsPremiumSummary)) ...[ + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'Additional Premium', + textAlign: + TextAlign + .start, + style: + GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 16 : 13, + fontWeight: + FontWeight + .w500, + ), ), - ), - ], - ))), - Expanded( - flex: 6, - child: Container( - alignment: Alignment - .centerRight, - child: Column( - mainAxisAlignment: - MainAxisAlignment - .center, - crossAxisAlignment: - CrossAxisAlignment - .center, - children: [ - Text( - topUpSiPremiumValue != - null - ? '₹ $topUpSiPremiumValue/Year' - : 'N/A', - textAlign: - TextAlign - .start, - style: - GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12, + ], + ))), + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + topUpSiPremiumValue != + null + ? '₹ $topUpSiPremiumValue/Year' + : 'N/A', + textAlign: + TextAlign + .start, + style: + GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 14 : 12, + ), ), - ), - ], - ))), - ], - ), - Row( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Expanded( - flex: 6, - child: Container( - alignment: Alignment - .centerLeft, - child: Column( - mainAxisAlignment: - MainAxisAlignment - .center, - crossAxisAlignment: - CrossAxisAlignment - .center, - children: [ - Text( - 'GST', - textAlign: - TextAlign - .start, - style: - GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 16 : 13, - fontWeight: - FontWeight - .w500, + ], + ))), + ], + ), + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'GST', + textAlign: + TextAlign + .start, + style: + GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 16 : 13, + fontWeight: + FontWeight + .w500, + ), ), - ), - ], - ))), - Expanded( - flex: 6, - child: Container( - alignment: Alignment - .centerRight, - child: Column( - mainAxisAlignment: - MainAxisAlignment - .center, - crossAxisAlignment: - CrossAxisAlignment - .center, - children: [ - Text( - topUpSiPremiumGst != - null - ? '₹ $topUpSiPremiumGst/-' - : 'N/A', - textAlign: - TextAlign - .start, - style: - GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12, + ], + ))), + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + topUpSiPremiumGst != + null + ? '₹ $topUpSiPremiumGst/-' + : 'N/A', + textAlign: + TextAlign + .start, + style: + GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 14 : 12, + ), ), - ), - ], - ))), - ], - ), + ], + ))), + ], + ), + ], Row( crossAxisAlignment: CrossAxisAlignment.start, @@ -4115,90 +4190,87 @@ class _addOnsDetailsState extends State { SizedBox(height: 20), if (Responsive.isDesktop(context) && _opdSwitcher == true && - shouldShowPremiumSummary( - isPremiumSummary: opdIsPremiumSummary, - premiumValue: opdSiPremiumValue, - gstValue: opdSiPremiumGst, - totalValue: opdSiTotalAmt, - )) + shouldShowPremiumSummary(opdIsPremiumSummary)) Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Expanded( - flex: 5, - child: Container( - alignment: Alignment.center, - child: Column( - mainAxisAlignment: - MainAxisAlignment - .center, - crossAxisAlignment: - CrossAxisAlignment - .center, - children: [ - Text( - 'Additional Premium', - textAlign: - TextAlign.start, - style: GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 16 : 13, - fontWeight: - FontWeight.w500, + if (shouldShowFullPremiumBreakdown(opdIsPremiumSummary)) ...[ + Expanded( + flex: 5, + child: Container( + alignment: Alignment.center, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'Additional Premium', + textAlign: + TextAlign.start, + style: GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 16 : 13, + fontWeight: + FontWeight.w500, + ), ), - ), - Text( - opdSiPremiumValue != - null - ? '₹ $opdSiPremiumValue/Year' - : 'N/A', - textAlign: - TextAlign.start, - style: GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12, + Text( + opdSiPremiumValue != + null + ? '₹ $opdSiPremiumValue/Year' + : 'N/A', + textAlign: + TextAlign.start, + style: GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 14 : 12, + ), ), - ), - ], - ))), - Expanded( - flex: 2, - child: Container( - alignment: Alignment.center, - child: Column( - mainAxisAlignment: - MainAxisAlignment - .center, - crossAxisAlignment: - CrossAxisAlignment - .center, - children: [ - Text( - 'GST', - textAlign: - TextAlign.start, - style: GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 16 : 13, - fontWeight: - FontWeight.w500, + ], + ))), + Expanded( + flex: 2, + child: Container( + alignment: Alignment.center, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'GST', + textAlign: + TextAlign.start, + style: GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 16 : 13, + fontWeight: + FontWeight.w500, + ), ), - ), - Text( - opdSiPremiumGst != - null - ? '₹ $opdSiPremiumGst/-' - : 'N/A', - textAlign: - TextAlign.start, - style: GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12, + Text( + opdSiPremiumGst != + null + ? '₹ $opdSiPremiumGst/-' + : 'N/A', + textAlign: + TextAlign.start, + style: GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 14 : 12, + ), ), - ), - ], - ))), + ], + ))), + ], Expanded( flex: 5, child: Container( @@ -4240,145 +4312,142 @@ class _addOnsDetailsState extends State { ), if (!Responsive.isDesktop(context) && _opdSwitcher == true && - shouldShowPremiumSummary( - isPremiumSummary: opdIsPremiumSummary, - premiumValue: opdSiPremiumValue, - gstValue: opdSiPremiumGst, - totalValue: opdSiTotalAmt, - )) + shouldShowPremiumSummary(opdIsPremiumSummary)) Container( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Row( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Expanded( - flex: 6, - child: Container( - alignment: Alignment - .centerLeft, - child: Column( - mainAxisAlignment: - MainAxisAlignment - .center, - crossAxisAlignment: - CrossAxisAlignment - .center, - children: [ - Text( - 'Additional Premium', - textAlign: - TextAlign - .start, - style: - GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 16 : 13, - fontWeight: - FontWeight - .w500, + if (shouldShowFullPremiumBreakdown(opdIsPremiumSummary)) ...[ + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'Additional Premium', + textAlign: + TextAlign + .start, + style: + GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 16 : 13, + fontWeight: + FontWeight + .w500, + ), ), - ), - ], - ))), - Expanded( - flex: 6, - child: Container( - alignment: Alignment - .centerRight, - child: Column( - mainAxisAlignment: - MainAxisAlignment - .center, - crossAxisAlignment: - CrossAxisAlignment - .center, - children: [ - Text( - opdSiPremiumValue != - null - ? '₹ $opdSiPremiumValue/Year' - : 'N/A', - textAlign: - TextAlign - .start, - style: - GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12, + ], + ))), + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + opdSiPremiumValue != + null + ? '₹ $opdSiPremiumValue/Year' + : 'N/A', + textAlign: + TextAlign + .start, + style: + GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 14 : 12, + ), ), - ), - ], - ))), - ], - ), - Row( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Expanded( - flex: 6, - child: Container( - alignment: Alignment - .centerLeft, - child: Column( - mainAxisAlignment: - MainAxisAlignment - .center, - crossAxisAlignment: - CrossAxisAlignment - .center, - children: [ - Text( - 'GST', - textAlign: - TextAlign - .start, - style: - GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 16 : 13, - fontWeight: - FontWeight - .w500, + ], + ))), + ], + ), + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'GST', + textAlign: + TextAlign + .start, + style: + GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 16 : 13, + fontWeight: + FontWeight + .w500, + ), ), - ), - ], - ))), - Expanded( - flex: 6, - child: Container( - alignment: Alignment - .centerRight, - child: Column( - mainAxisAlignment: - MainAxisAlignment - .center, - crossAxisAlignment: - CrossAxisAlignment - .center, - children: [ - Text( - opdSiPremiumGst != - null - ? '₹ $opdSiPremiumGst/-' - : 'N/A', - textAlign: - TextAlign - .start, - style: - GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12, + ], + ))), + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + opdSiPremiumGst != + null + ? '₹ $opdSiPremiumGst/-' + : 'N/A', + textAlign: + TextAlign + .start, + style: + GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 14 : 12, + ), ), - ), - ], - ))), - ], - ), + ], + ))), + ], + ), + ], Row( crossAxisAlignment: CrossAxisAlignment.start, @@ -4763,90 +4832,87 @@ class _addOnsDetailsState extends State { SizedBox(height: 20), if (Responsive.isDesktop(context) && _topUpParentSiSwitcher == true && - shouldShowPremiumSummary( - isPremiumSummary: topUpParentIsPremiumSummary, - premiumValue: topUpParentSiPremiumValue, - gstValue: topUpParentSiPremiumGst, - totalValue: topUpParentSiTotalAmt, - )) + shouldShowPremiumSummary(topUpParentIsPremiumSummary)) Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Expanded( - flex: 5, - child: Container( - alignment: Alignment.center, - child: Column( - mainAxisAlignment: - MainAxisAlignment - .center, - crossAxisAlignment: - CrossAxisAlignment - .center, - children: [ - Text( - 'Additional Premium', - textAlign: - TextAlign.start, - style: GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 16 : 13, - fontWeight: - FontWeight.w500, + if (shouldShowFullPremiumBreakdown(topUpParentIsPremiumSummary)) ...[ + Expanded( + flex: 5, + child: Container( + alignment: Alignment.center, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'Additional Premium', + textAlign: + TextAlign.start, + style: GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 16 : 13, + fontWeight: + FontWeight.w500, + ), ), - ), - Text( - topUpParentSiPremiumValue != - null - ? '₹ $topUpParentSiPremiumValue/Year' - : 'N/A', - textAlign: - TextAlign.start, - style: GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12, + Text( + topUpParentSiPremiumValue != + null + ? '₹ $topUpParentSiPremiumValue/Year' + : 'N/A', + textAlign: + TextAlign.start, + style: GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 14 : 12, + ), ), - ), - ], - ))), - Expanded( - flex: 2, - child: Container( - alignment: Alignment.center, - child: Column( - mainAxisAlignment: - MainAxisAlignment - .center, - crossAxisAlignment: - CrossAxisAlignment - .center, - children: [ - Text( - 'GST', - textAlign: - TextAlign.start, - style: GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 16 : 13, - fontWeight: - FontWeight.w500, + ], + ))), + Expanded( + flex: 2, + child: Container( + alignment: Alignment.center, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'GST', + textAlign: + TextAlign.start, + style: GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 16 : 13, + fontWeight: + FontWeight.w500, + ), ), - ), - Text( - topUpParentSiPremiumGst != - null - ? '₹ $topUpParentSiPremiumGst/-' - : 'N/A', - textAlign: - TextAlign.start, - style: GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12, + Text( + topUpParentSiPremiumGst != + null + ? '₹ $topUpParentSiPremiumGst/-' + : 'N/A', + textAlign: + TextAlign.start, + style: GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 14 : 12, + ), ), - ), - ], - ))), + ], + ))), + ], Expanded( flex: 5, child: Container( @@ -4888,145 +4954,142 @@ class _addOnsDetailsState extends State { ), if (!Responsive.isDesktop(context) && _topUpParentSiSwitcher == true && - shouldShowPremiumSummary( - isPremiumSummary: topUpParentIsPremiumSummary, - premiumValue: topUpParentSiPremiumValue, - gstValue: topUpParentSiPremiumGst, - totalValue: topUpParentSiTotalAmt, - )) + shouldShowPremiumSummary(topUpParentIsPremiumSummary)) Container( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Row( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Expanded( - flex: 6, - child: Container( - alignment: Alignment - .centerLeft, - child: Column( - mainAxisAlignment: - MainAxisAlignment - .center, - crossAxisAlignment: - CrossAxisAlignment - .center, - children: [ - Text( - 'Additional Premium', - textAlign: - TextAlign - .start, - style: - GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 16 : 13, - fontWeight: - FontWeight - .w500, + if (shouldShowFullPremiumBreakdown(topUpParentIsPremiumSummary)) ...[ + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'Additional Premium', + textAlign: + TextAlign + .start, + style: + GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 16 : 13, + fontWeight: + FontWeight + .w500, + ), ), - ), - ], - ))), - Expanded( - flex: 6, - child: Container( - alignment: Alignment - .centerRight, - child: Column( - mainAxisAlignment: - MainAxisAlignment - .center, - crossAxisAlignment: - CrossAxisAlignment - .center, - children: [ - Text( - topUpParentSiPremiumValue != - null - ? '₹ $topUpParentSiPremiumValue/Year' - : 'N/A', - textAlign: - TextAlign - .start, - style: - GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12, + ], + ))), + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + topUpParentSiPremiumValue != + null + ? '₹ $topUpParentSiPremiumValue/Year' + : 'N/A', + textAlign: + TextAlign + .start, + style: + GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 14 : 12, + ), ), - ), - ], - ))), - ], - ), - Row( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Expanded( - flex: 6, - child: Container( - alignment: Alignment - .centerLeft, - child: Column( - mainAxisAlignment: - MainAxisAlignment - .center, - crossAxisAlignment: - CrossAxisAlignment - .center, - children: [ - Text( - 'GST', - textAlign: - TextAlign - .start, - style: - GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 16 : 13, - fontWeight: - FontWeight - .w500, + ], + ))), + ], + ), + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'GST', + textAlign: + TextAlign + .start, + style: + GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 16 : 13, + fontWeight: + FontWeight + .w500, + ), ), - ), - ], - ))), - Expanded( - flex: 6, - child: Container( - alignment: Alignment - .centerRight, - child: Column( - mainAxisAlignment: - MainAxisAlignment - .center, - crossAxisAlignment: - CrossAxisAlignment - .center, - children: [ - Text( - topUpParentSiPremiumGst != - null - ? '₹ $topUpParentSiPremiumGst/-' - : 'N/A', - textAlign: - TextAlign - .start, - style: - GoogleFonts - .poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12, + ], + ))), + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + topUpParentSiPremiumGst != + null + ? '₹ $topUpParentSiPremiumGst/-' + : 'N/A', + textAlign: + TextAlign + .start, + style: + GoogleFonts + .poppins( + fontSize: Responsive.isDesktop(context) ? 14 : 12, + ), ), - ), - ], - ))), - ], - ), + ], + ))), + ], + ), + ], Row( crossAxisAlignment: CrossAxisAlignment.start, @@ -5155,111 +5218,65 @@ class _addOnsDetailsState extends State { child: Container( alignment: Alignment .centerLeft, // Adjust padding as needed - child: Table( - columnWidths: { - 0: FlexColumnWidth( - 2), // Adjust column width as needed - 1: FlexColumnWidth(2), - 2: FlexColumnWidth( - 2), // Adjust column width as needed - 3: FlexColumnWidth(2), - }, - children: [ - TableRow( + child: Builder( + builder: (context) { + final bool includeBreakdownColumns = + hasAnyFullPremiumBreakdown(); + return Table( + columnWidths: includeBreakdownColumns + ? { + 0: FlexColumnWidth(2), + 1: FlexColumnWidth(2), + 2: FlexColumnWidth(2), + 3: FlexColumnWidth(2), + } + : { + 0: FlexColumnWidth(3), + 1: FlexColumnWidth(1), + }, children: [ - TableCell( - child: Padding( - padding: - EdgeInsets.all(8.0), - child: Text( - 'Policy', - textAlign: - TextAlign.start, - style: GoogleFonts.poppins( - fontSize: Responsive - .isDesktop( - context) - ? 16 - : 13, - fontWeight: - FontWeight - .bold), - ), - ), - ), - TableCell( - child: Padding( - padding: - EdgeInsets.all(8.0), - child: Text( - 'Additional Premium', - textAlign: - TextAlign.start, - style: GoogleFonts.poppins( - fontSize: Responsive - .isDesktop( - context) - ? 16 - : 13, - fontWeight: - FontWeight - .bold), - ), - ), - ), - TableCell( - child: Padding( - padding: - EdgeInsets.all(8.0), - child: Text( - 'GST', - textAlign: - TextAlign.start, - style: GoogleFonts.poppins( - fontSize: Responsive - .isDesktop( - context) - ? 16 - : 13, - fontWeight: - FontWeight - .bold), - ), - ), - ), - TableCell( - child: Padding( - padding: - EdgeInsets.all(8.0), - child: Text( + TableRow( + children: [ + _premiumSummaryHeaderCell( + context, 'Policy'), + if (includeBreakdownColumns) ...[ + _premiumSummaryHeaderCell( + context, + 'Additional Premium'), + _premiumSummaryHeaderCell( + context, 'GST'), + ], + _premiumSummaryHeaderCell( + context, 'Total', - textAlign: - TextAlign.start, - style: GoogleFonts.poppins( - fontSize: Responsive - .isDesktop( - context) - ? 16 - : 13, - fontWeight: - FontWeight - .bold), + textAlign: includeBreakdownColumns + ? TextAlign.start + : TextAlign.end, ), - ), + ], ), + if (gpaPolicies != null && + gpaPolicies.length > 0) + ...gpaBuildPolicyRows( + gpaPolicies, + context, + includeBreakdownColumns: + includeBreakdownColumns, + ), + if (gmcPolicies != null && + gmcPolicies.length > 0) + ...gmcBuildPolicyRows( + gmcPolicies, + context, + includeBreakdownColumns: + includeBreakdownColumns, + ), ], - ), - if (gpaPolicies != null && - gpaPolicies.length > 0) - ...gpaBuildPolicyRows( - gpaPolicies, context), - if (gmcPolicies != null && - gmcPolicies.length > 0) - ...gmcBuildPolicyRows( - gmcPolicies, context), - ], + ); + }, ), - )) + ), + ), ], ), ), @@ -6407,6 +6424,13 @@ class _addOnsDetailsState extends State { double gmcTotalableValue = gmcGstValue + gmcSiPremiumValue; bool gmcIsValueValid = (gmcSiPremiumValue > 0 && gmcGstValue > 0); + final int gmcPremiumSummaryMode = + parsePremiumSummaryMode(item['is_premium_summery']); + // 0 = hide, 1 = full summary, 2 = total only + final bool showFullGmcPremiumSummary = + gmcPremiumSummaryMode == 1 && gmcIsValueValid; + final bool showGmcPremiumTotalOnly = + gmcPremiumSummaryMode == 2 && gmcTotalableValue != 0; List gmcMappedFamilyFloaters = item['mapped_family_floaters'] ?? []; @@ -6577,10 +6601,12 @@ class _addOnsDetailsState extends State { }).toList(), ), ), - if (Responsive.isDesktop(context) && gmcIsValueValid) + if (Responsive.isDesktop(context) && + (showFullGmcPremiumSummary || showGmcPremiumTotalOnly)) Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ + if (showFullGmcPremiumSummary) ...[ Expanded( flex: 5, child: Container( @@ -6633,6 +6659,7 @@ class _addOnsDetailsState extends State { ), ], ))), + ], Expanded( flex: 5, child: Container( @@ -6661,11 +6688,13 @@ class _addOnsDetailsState extends State { ))), ], ), - if (!Responsive.isDesktop(context) && gmcIsValueValid) + if (!Responsive.isDesktop(context) && + (showFullGmcPremiumSummary || showGmcPremiumTotalOnly)) Container( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ + if (showFullGmcPremiumSummary) ...[ Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -6754,6 +6783,7 @@ class _addOnsDetailsState extends State { ))), ], ), + ], Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -6825,6 +6855,13 @@ class _addOnsDetailsState extends State { double gpaTotalableValue = gpaSiPremiumValue + gpaGstValue; bool isValueValid = gpaSiPremiumValue != 0 && gpaGstValue != 0; + final int premiumSummaryMode = + parsePremiumSummaryMode(item['is_premium_summery']); + // 0 = hide, 1 = full summary, 2 = total only + final bool showFullPremiumSummary = + premiumSummaryMode == 1 && isValueValid; + final bool showPremiumTotalOnly = + premiumSummaryMode == 2 && gpaTotalableValue != 0; // ------------------------------- // FIX: mapped_family_floaters is ALREADY a list @@ -7011,10 +7048,12 @@ class _addOnsDetailsState extends State { Column( children: familyFloaterContainers, ), - if (Responsive.isDesktop(context) && isValueValid) + if (Responsive.isDesktop(context) && + (showFullPremiumSummary || showPremiumTotalOnly)) Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ + if (showFullPremiumSummary) ...[ Expanded( flex: 5, child: Container( @@ -7065,6 +7104,7 @@ class _addOnsDetailsState extends State { ), ], ))), + ], Expanded( flex: 5, child: Container( @@ -7092,11 +7132,13 @@ class _addOnsDetailsState extends State { ))), ], ), - if (!Responsive.isDesktop(context) && isValueValid) + if (!Responsive.isDesktop(context) && + (showFullPremiumSummary || showPremiumTotalOnly)) Container( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ + if (showFullPremiumSummary) ...[ Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -7181,6 +7223,7 @@ class _addOnsDetailsState extends State { ))), ], ), + ], Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -7237,16 +7280,23 @@ class _addOnsDetailsState extends State { double calculateGpaTotalAmt(List> policies) { double total = policies - .where((policy) => policy is Map) + .where((policy) => + policy is Map && + shouldShowPremiumSummary( + parsePremiumSummaryMode(policy['is_premium_summery']))) .map((policy) => - (policy["si_gst_value"] ?? 0) + (policy["si_premium_value"] ?? 0)) + (policy["si_gst_value"] ?? 0) + (policy["si_premium_value"] ?? 0)) .fold(0.0, (sum, value) => sum + value); logDebug('Calculated gpaTotalAmt: $total'); // Debug print return total; } - List gpaBuildPolicyRows(dynamic policies, BuildContext context) { + List gpaBuildPolicyRows( + dynamic policies, + BuildContext context, { + bool includeBreakdownColumns = true, + }) { if (policies is! List) { return []; // Return empty list if policies is not a list } @@ -7259,59 +7309,36 @@ class _addOnsDetailsState extends State { .map((policy) { var siGstValue = policy["si_gst_value"] ?? 0; var siPremiumValue = policy["si_premium_value"] ?? 0; + final int premiumMode = + parsePremiumSummaryMode(policy['is_premium_summery']); + final total = (siPremiumValue is num ? siPremiumValue.toDouble() : 0.0) + + (siGstValue is num ? siGstValue.toDouble() : 0.0); - if (siGstValue == 0 || siPremiumValue == 0) - return null; // Skip invalid policies + // 0 = hide, 1 = full, 2 = total only + if (premiumMode == 0) return null; + if (premiumMode == 1 && (siGstValue == 0 || siPremiumValue == 0)) { + return null; + } + if (premiumMode == 2 && total == 0) return null; + + final bool showBreakdownValues = + shouldShowFullPremiumBreakdown(premiumMode); + final policyLabel = Responsive.isDesktop(context) + ? (policy["Policy_Name"] ?? 'Default Policy Name') + : policy['type']; + final totalValue = + '₹${(policy["si_premium_value"] ?? 0) + (policy["si_gst_value"] ?? 0)}/-'; return TableRow( - children: [ - TableCell( - child: Padding( - padding: EdgeInsets.all(8.0), - child: Text( - Responsive.isDesktop(context) - ? (policy["Policy_Name"] ?? 'Default Policy Name') - : policy['type'], - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12), - ), - ), - ), - TableCell( - child: Padding( - padding: EdgeInsets.all(8.0), - child: Text( - '₹${policy["si_premium_value"]}/Year', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12), - ), - ), - ), - TableCell( - child: Padding( - padding: EdgeInsets.all(8.0), - child: Text( - '₹${policy["si_gst_value"]}/-', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12), - ), - ), - ), - TableCell( - child: Padding( - padding: EdgeInsets.all(8.0), - child: Text( - '₹${(policy["si_premium_value"] ?? 0) + (policy["si_gst_value"] ?? 0)}/-', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12), - ), - ), - ), - ], + children: buildPremiumSummaryRowCells( + context: context, + policyLabel: policyLabel?.toString() ?? '', + premiumValue: '₹${policy["si_premium_value"]}/Year', + gstValue: '₹${policy["si_gst_value"]}/-', + totalValue: totalValue, + includeBreakdownColumns: includeBreakdownColumns, + showBreakdownValues: showBreakdownValues, + ), ); }) .whereType() // Filter out null values @@ -7320,17 +7347,24 @@ class _addOnsDetailsState extends State { double calculateGmcTotalAmt(List> policies) { double total = policies - .where((policy) => policy is Map) + .where((policy) => + policy is Map && + shouldShowPremiumSummary( + parsePremiumSummaryMode(policy['is_premium_summery']))) .map((policy) => - (policy["family_floaters_of_dependent_and_gst_value"] ?? 0) + - (policy["family_floaters_of_dependent_and_si_premium_value"] ?? 0)) + (policy["family_floaters_of_dependent_and_gst_value"] ?? 0) + + (policy["family_floaters_of_dependent_and_si_premium_value"] ?? 0)) .fold(0.0, (sum, value) => sum + value); logDebug('Calculated gmcTotalAmt: $total'); // Debug print return total; } - List gmcBuildPolicyRows(dynamic policies, BuildContext context) { + List gmcBuildPolicyRows( + dynamic policies, + BuildContext context, { + bool includeBreakdownColumns = true, + }) { logDebug('gmcBuildPolicyRows $policies'); if (policies is! List) { @@ -7347,59 +7381,38 @@ class _addOnsDetailsState extends State { policy["family_floaters_of_dependent_and_gst_value"] ?? 0; var siPremiumValue = policy["family_floaters_of_dependent_and_si_premium_value"] ?? 0; + final int premiumMode = + parsePremiumSummaryMode(policy['is_premium_summery']); + final total = (siPremiumValue is num ? siPremiumValue.toDouble() : 0.0) + + (siGstValue is num ? siGstValue.toDouble() : 0.0); - if (siGstValue == 0 || siPremiumValue == 0) - return null; // Skip invalid policies + // 0 = hide, 1 = full, 2 = total only + if (premiumMode == 0) return null; + if (premiumMode == 1 && (siGstValue == 0 || siPremiumValue == 0)) { + return null; + } + if (premiumMode == 2 && total == 0) return null; + + final bool showBreakdownValues = + shouldShowFullPremiumBreakdown(premiumMode); + final policyLabel = Responsive.isDesktop(context) + ? (policy["Policy_Name"] ?? 'Default Policy Name') + : policy['type']; + final totalValue = + '₹${(policy["family_floaters_of_dependent_and_si_premium_value"] ?? 0) + (policy["family_floaters_of_dependent_and_gst_value"] ?? 0)}/-'; return TableRow( - children: [ - TableCell( - child: Padding( - padding: EdgeInsets.all(8.0), - child: Text( - Responsive.isDesktop(context) - ? (policy["Policy_Name"] ?? 'Default Policy Name') - : policy['type'], - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12), - ), - ), - ), - TableCell( - child: Padding( - padding: EdgeInsets.all(8.0), - child: Text( - '₹${policy["family_floaters_of_dependent_and_si_premium_value"]}/Year', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12), - ), - ), - ), - TableCell( - child: Padding( - padding: EdgeInsets.all(8.0), - child: Text( - '₹${policy["family_floaters_of_dependent_and_gst_value"]}/-', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12), - ), - ), - ), - TableCell( - child: Padding( - padding: EdgeInsets.all(8.0), - child: Text( - '₹${(policy["family_floaters_of_dependent_and_si_premium_value"] ?? 0) + (policy["family_floaters_of_dependent_and_gst_value"] ?? 0)}/-', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12), - ), - ), - ), - ], + children: buildPremiumSummaryRowCells( + context: context, + policyLabel: policyLabel?.toString() ?? '', + premiumValue: + '₹${policy["family_floaters_of_dependent_and_si_premium_value"]}/Year', + gstValue: + '₹${policy["family_floaters_of_dependent_and_gst_value"]}/-', + totalValue: totalValue, + includeBreakdownColumns: includeBreakdownColumns, + showBreakdownValues: showBreakdownValues, + ), ); }) .whereType() // Filter out null values diff --git a/lib/pages/enrollment/empDetails.dart b/lib/pages/enrollment/empDetails.dart index f94795c..2dcabd1 100755 --- a/lib/pages/enrollment/empDetails.dart +++ b/lib/pages/enrollment/empDetails.dart @@ -1930,6 +1930,13 @@ class _empDetailsState extends State { double gpaTotalableValue = gpaSiPremiumValue + gpaGstValue; bool isValueValid = gpaSiPremiumValue != 0 && gpaGstValue != 0; + final int premiumSummaryMode = + parsePremiumSummaryMode(item['is_premium_summery']); + // 0 = hide, 1 = full summary, 2 = total only + final bool showFullPremiumSummary = + premiumSummaryMode == 1 && isValueValid; + final bool showPremiumTotalOnly = + premiumSummaryMode == 2 && gpaTotalableValue != 0; List gpaMappedFamilyFloaters = []; @@ -2179,60 +2186,63 @@ class _empDetailsState extends State { Column( children: familyFloaterContainers, ), - if (Responsive.isDesktop(context) && isValueValid) + if (Responsive.isDesktop(context) && + (showFullPremiumSummary || showPremiumTotalOnly)) Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Expanded( - flex: 5, - child: Container( - alignment: Alignment.center, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - 'Additional Premium', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: 20, - fontWeight: FontWeight.w500, + if (showFullPremiumSummary) ...[ + Expanded( + flex: 5, + child: Container( + alignment: Alignment.center, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + 'Additional Premium', + textAlign: TextAlign.start, + style: GoogleFonts.poppins( + fontSize: 20, + fontWeight: FontWeight.w500, + ), ), - ), - Text( - (gpaSiPremiumValue ?? '').toString(), - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: 18, + Text( + (gpaSiPremiumValue ?? '').toString(), + textAlign: TextAlign.start, + style: GoogleFonts.poppins( + fontSize: 18, + ), ), - ), - ], - ))), - Expanded( - flex: 2, - child: Container( - alignment: Alignment.center, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - 'GST', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: 20, - fontWeight: FontWeight.w500, + ], + ))), + Expanded( + flex: 2, + child: Container( + alignment: Alignment.center, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + 'GST', + textAlign: TextAlign.start, + style: GoogleFonts.poppins( + fontSize: 20, + fontWeight: FontWeight.w500, + ), ), - ), - Text( - (gpaGstValue ?? '').toString(), - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: 18, + Text( + (gpaGstValue ?? '').toString(), + textAlign: TextAlign.start, + style: GoogleFonts.poppins( + fontSize: 18, + ), ), - ), - ], - ))), + ], + ))), + ], Expanded( flex: 5, child: Container( @@ -2260,95 +2270,98 @@ class _empDetailsState extends State { ))), ], ), - if (!Responsive.isDesktop(context) && isValueValid) + if (!Responsive.isDesktop(context) && + (showFullPremiumSummary || showPremiumTotalOnly)) Container( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - flex: 6, - child: Container( - alignment: Alignment.centerLeft, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: - CrossAxisAlignment.center, - children: [ - Text( - 'Additional Premium', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: 18, - fontWeight: FontWeight.w500, + if (showFullPremiumSummary) ...[ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 6, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.center, + children: [ + Text( + 'Additional Premium', + textAlign: TextAlign.start, + style: GoogleFonts.poppins( + fontSize: 18, + fontWeight: FontWeight.w500, + ), ), - ), - ], - ))), - Expanded( - flex: 6, - child: Container( - alignment: Alignment.centerRight, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: - CrossAxisAlignment.center, - children: [ - Text( - (gpaSiPremiumValue ?? '').toString(), - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: 16, + ], + ))), + Expanded( + flex: 6, + child: Container( + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.center, + children: [ + Text( + (gpaSiPremiumValue ?? '').toString(), + textAlign: TextAlign.start, + style: GoogleFonts.poppins( + fontSize: 16, + ), ), - ), - ], - ))), - ], - ), - Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - flex: 6, - child: Container( - alignment: Alignment.centerLeft, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: - CrossAxisAlignment.center, - children: [ - Text( - 'GST', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: 18, - fontWeight: FontWeight.w500, + ], + ))), + ], + ), + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 6, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.center, + children: [ + Text( + 'GST', + textAlign: TextAlign.start, + style: GoogleFonts.poppins( + fontSize: 18, + fontWeight: FontWeight.w500, + ), ), - ), - ], - ))), - Expanded( - flex: 6, - child: Container( - alignment: Alignment.centerRight, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: - CrossAxisAlignment.center, - children: [ - Text( - (gpaGstValue ?? '').toString(), - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: 16, + ], + ))), + Expanded( + flex: 6, + child: Container( + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.center, + children: [ + Text( + (gpaGstValue ?? '').toString(), + textAlign: TextAlign.start, + style: GoogleFonts.poppins( + fontSize: 16, + ), ), - ), - ], - ))), - ], - ), + ], + ))), + ], + ), + ], Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -2409,6 +2422,17 @@ class _empDetailsState extends State { : value.toStringAsFixed(2); } + /// 0 = hide premium summary, 1 = full summary, 2 = total only + int parsePremiumSummaryMode(dynamic value) { + if (value == null) return 0; + if (value is bool) return value ? 1 : 0; + if (value is num) return value.toInt(); + final normalized = value.toString().trim().toLowerCase(); + if (normalized == 'true' || normalized == 'yes') return 1; + if (normalized == 'false' || normalized == 'no') return 0; + return int.tryParse(normalized) ?? 0; + } + List generateCards(List data) { List cards = []; @@ -2444,6 +2468,13 @@ class _empDetailsState extends State { double gmcTotalableValue = gmcGstValue + gmcSiPremiumValue; bool gmcIsValueValid = (gmcSiPremiumValue > 0 && gmcGstValue > 0); + final int gmcPremiumSummaryMode = + parsePremiumSummaryMode(item['is_premium_summery']); + // 0 = hide, 1 = full summary, 2 = total only + final bool showFullGmcPremiumSummary = + gmcPremiumSummaryMode == 1 && gmcIsValueValid; + final bool showGmcPremiumTotalOnly = + gmcPremiumSummaryMode == 2 && gmcTotalableValue != 0; List gmcRelationShip = item['relationship']; @@ -2954,60 +2985,63 @@ class _empDetailsState extends State { ], SizedBox(height: 15), - if (Responsive.isDesktop(context) && gmcIsValueValid) + if (Responsive.isDesktop(context) && + (showFullGmcPremiumSummary || showGmcPremiumTotalOnly)) Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Expanded( - flex: 5, - child: Container( - alignment: Alignment.center, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - 'Additional Premium', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: 20, - fontWeight: FontWeight.w500, + if (showFullGmcPremiumSummary) ...[ + Expanded( + flex: 5, + child: Container( + alignment: Alignment.center, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + 'Additional Premium', + textAlign: TextAlign.start, + style: GoogleFonts.poppins( + fontSize: 20, + fontWeight: FontWeight.w500, + ), ), - ), - Text( - formatAmount(gmcSiPremiumValue), - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: 18, + Text( + formatAmount(gmcSiPremiumValue), + textAlign: TextAlign.start, + style: GoogleFonts.poppins( + fontSize: 18, + ), ), - ), - ], - ))), - Expanded( - flex: 2, - child: Container( - alignment: Alignment.center, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - 'GST', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: 20, - fontWeight: FontWeight.w500, + ], + ))), + Expanded( + flex: 2, + child: Container( + alignment: Alignment.center, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + 'GST', + textAlign: TextAlign.start, + style: GoogleFonts.poppins( + fontSize: 20, + fontWeight: FontWeight.w500, + ), ), - ), - Text( - formatAmount(gmcGstValue), - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: 18, + Text( + formatAmount(gmcGstValue), + textAlign: TextAlign.start, + style: GoogleFonts.poppins( + fontSize: 18, + ), ), - ), - ], - ))), + ], + ))), + ], Expanded( flex: 5, child: Container( @@ -3035,99 +3069,102 @@ class _empDetailsState extends State { ))), ], ), - if (!Responsive.isDesktop(context) && gmcIsValueValid) + if (!Responsive.isDesktop(context) && + (showFullGmcPremiumSummary || showGmcPremiumTotalOnly)) Container( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - flex: 6, - child: Container( - alignment: Alignment.centerLeft, - child: Column( - mainAxisAlignment: - MainAxisAlignment.center, - crossAxisAlignment: - CrossAxisAlignment.center, - children: [ - Text( - 'Additional Premium', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: 18, - fontWeight: FontWeight.w500, + if (showFullGmcPremiumSummary) ...[ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 6, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.center, + children: [ + Text( + 'Additional Premium', + textAlign: TextAlign.start, + style: GoogleFonts.poppins( + fontSize: 18, + fontWeight: FontWeight.w500, + ), ), - ), - ], - ))), - Expanded( - flex: 6, - child: Container( - alignment: Alignment.centerRight, - child: Column( - mainAxisAlignment: - MainAxisAlignment.center, - crossAxisAlignment: - CrossAxisAlignment.center, - children: [ - Text( - formatAmount(gmcSiPremiumValue), - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: 16, + ], + ))), + Expanded( + flex: 6, + child: Container( + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.center, + children: [ + Text( + formatAmount(gmcSiPremiumValue), + textAlign: TextAlign.start, + style: GoogleFonts.poppins( + fontSize: 16, + ), ), - ), - ], - ))), - ], - ), - Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - flex: 6, - child: Container( - alignment: Alignment.centerLeft, - child: Column( - mainAxisAlignment: - MainAxisAlignment.center, - crossAxisAlignment: - CrossAxisAlignment.center, - children: [ - Text( - 'GST', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: 18, - fontWeight: FontWeight.w500, + ], + ))), + ], + ), + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 6, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.center, + children: [ + Text( + 'GST', + textAlign: TextAlign.start, + style: GoogleFonts.poppins( + fontSize: 18, + fontWeight: FontWeight.w500, + ), ), - ), - ], - ))), - Expanded( - flex: 6, - child: Container( - alignment: Alignment.centerRight, - child: Column( - mainAxisAlignment: - MainAxisAlignment.center, - crossAxisAlignment: - CrossAxisAlignment.center, - children: [ - Text( - formatAmount(gmcGstValue), - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: 16, + ], + ))), + Expanded( + flex: 6, + child: Container( + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.center, + children: [ + Text( + formatAmount(gmcGstValue), + textAlign: TextAlign.start, + style: GoogleFonts.poppins( + fontSize: 16, + ), ), - ), - ], - ))), - ], - ), + ], + ))), + ], + ), + ], Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ diff --git a/lib/pages/enrollment/empReview.dart b/lib/pages/enrollment/empReview.dart index 804a877..227fa9c 100755 --- a/lib/pages/enrollment/empReview.dart +++ b/lib/pages/enrollment/empReview.dart @@ -114,7 +114,7 @@ class _empReviewDetailsState extends State { dynamic topUpFloaterTextHeading; dynamic opdFloaterTextHeading; dynamic topUpECardDownload; - bool topUpIsPremiumSummary = false; + int topUpIsPremiumSummary = 0; dynamic topUpDisclaimer; int showHideTopUpCard = 0; @@ -130,7 +130,7 @@ class _empReviewDetailsState extends State { dynamic topUpParentFamilyFloater; dynamic topUpParentMappedFamilyFloatersSi; dynamic topUpParentECardDownload; - bool topUpParentIsPremiumSummary = false; + int topUpParentIsPremiumSummary = 0; dynamic topUpParentSiValue; dynamic topUpParentSiSelectedSI; dynamic topUpParentTypeName; @@ -152,7 +152,7 @@ class _empReviewDetailsState extends State { dynamic opdSiPremiumValue; dynamic opdSiPremiumGst; dynamic opdSiTotalAmt; - bool opdIsPremiumSummary = false; + int opdIsPremiumSummary = 0; dynamic opdDisclaimer; int activeSiData = 0; int activeOPDSiData = 0; @@ -166,7 +166,7 @@ class _empReviewDetailsState extends State { dynamic topUpOpenForEnrollment; dynamic topUpParentOpenForEnrollment; dynamic addOnsDependentOpenForEnrollment; - bool addOnsDependentIsPremiumSummary = false; + int addOnsDependentIsPremiumSummary = 0; bool gmcEnrollmentStatus = false; bool gpahasPremiumSummary = false; bool gmchasPremiumSummary = false; @@ -286,9 +286,115 @@ class _empReviewDetailsState extends State { // } // } + /// 0 = hide, 1 = full summary, 2 = total only + int parsePremiumSummaryMode(dynamic value) { + if (value == null) return 0; + if (value is bool) return value ? 1 : 0; + if (value is num) return value.toInt(); + final normalized = value.toString().trim().toLowerCase(); + if (normalized == 'true' || normalized == 'yes') return 1; + if (normalized == 'false' || normalized == 'no') return 0; + return int.tryParse(normalized) ?? 0; + } + + bool shouldShowPremiumSummary(int mode) => mode == 1 || mode == 2; + bool shouldShowFullPremiumBreakdown(int mode) => mode == 1; + + bool _policyListHasFullPremiumBreakdown(dynamic policies) { + if (policies is! List) return false; + for (final policy in policies) { + if (policy is! Map) continue; + if (shouldShowFullPremiumBreakdown( + parsePremiumSummaryMode(policy['is_premium_summery']))) { + return true; + } + } + return false; + } + + /// True when any visible premium-summary row needs Additional Premium / GST columns. + bool hasAnyFullPremiumBreakdown() { + return _policyListHasFullPremiumBreakdown(gpaPolicies) || + _policyListHasFullPremiumBreakdown(gmcPolicies) || + (activeSiData == 1 && + shouldShowFullPremiumBreakdown(topUpIsPremiumSummary)) || + (activeOPDSiData == 1 && + shouldShowFullPremiumBreakdown(opdIsPremiumSummary)) || + (activeSiParentData == 1 && + shouldShowFullPremiumBreakdown(topUpParentIsPremiumSummary)) || + (activeDependentData == 1 && + shouldShowFullPremiumBreakdown(addOnsDependentIsPremiumSummary)); + } + + Widget _premiumSummaryHeaderCell( + BuildContext context, + String label, { + TextAlign textAlign = TextAlign.start, + }) { + return TableCell( + child: Padding( + padding: EdgeInsets.all(8.0), + child: SizedBox( + width: double.infinity, + child: Text( + label, + textAlign: textAlign, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) ? 16 : 14, + fontWeight: FontWeight.bold, + ), + ), + ), + ), + ); + } + + Widget _premiumSummaryValueCell( + BuildContext context, + String value, { + TextAlign textAlign = TextAlign.start, + }) { + return TableCell( + child: Padding( + padding: EdgeInsets.all(8.0), + child: SizedBox( + width: double.infinity, + child: Text( + value, + textAlign: textAlign, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) ? 14 : 12, + ), + ), + ), + ), + ); + } + + List buildPremiumSummaryRowCells({ + required BuildContext context, + required String policyLabel, + required String premiumValue, + required String gstValue, + required String totalValue, + required bool includeBreakdownColumns, + required bool showBreakdownValues, + }) { + final totalAlign = + includeBreakdownColumns ? TextAlign.start : TextAlign.end; + return [ + _premiumSummaryValueCell(context, policyLabel), + if (includeBreakdownColumns) ...[ + _premiumSummaryValueCell( + context, showBreakdownValues ? premiumValue : ''), + _premiumSummaryValueCell(context, showBreakdownValues ? gstValue : ''), + ], + _premiumSummaryValueCell(context, totalValue, textAlign: totalAlign), + ]; + } + bool isPremiumEnabled(dynamic value) { - final intValue = int.tryParse(value?.toString() ?? '0') ?? 0; - return intValue != 0; + return parsePremiumSummaryMode(value) != 0; } bool _isOpenForEnrollment(dynamic value) { @@ -664,7 +770,7 @@ class _empReviewDetailsState extends State { topUpSiPolicies['gmc_si_topup']['eCardDownload']; setState(() { - topUpIsPremiumSummary = isPremiumEnabled(topUpSiPolicies['gmc_si_topup']?['is_premium_summery']); + topUpIsPremiumSummary = parsePremiumSummaryMode(topUpSiPolicies['gmc_si_topup']?['is_premium_summery']); }); @@ -798,7 +904,7 @@ class _empReviewDetailsState extends State { _toInt(opdNode['family_floaters_of_only_si_gst_value']); opdSiTotalAmt = opdSiPremiumValue + opdSiPremiumGst; opdIsPremiumSummary = - isPremiumEnabled(opdNode?['is_premium_summery']); + parsePremiumSummaryMode(opdNode?['is_premium_summery']); }); opdDisclaimer = opdNode['disclaimer']; @@ -912,7 +1018,7 @@ class _empReviewDetailsState extends State { topUpSiParentPolicies['gmc_si_parent_topup']['eCardDownload']; setState(() { - topUpParentIsPremiumSummary = isPremiumEnabled(topUpSiParentPolicies['gmc_si_parent_topup']?['is_premium_summery']); + topUpParentIsPremiumSummary = parsePremiumSummaryMode(topUpSiParentPolicies['gmc_si_parent_topup']?['is_premium_summery']); logDebug(topUpParentECardDownload); }); @@ -1091,7 +1197,7 @@ class _empReviewDetailsState extends State { ['OpenForEnrollment']; setState(() { - addOnsDependentIsPremiumSummary = isPremiumEnabled(addOnsDependentPolicies['gmc_dependent_addon']?['is_premium_summery']); + addOnsDependentIsPremiumSummary = parsePremiumSummaryMode(addOnsDependentPolicies['gmc_dependent_addon']?['is_premium_summery']); }); @@ -1428,10 +1534,22 @@ setState(() { double allTotalSum() { double total = 0.0; // Initialize to avoid unwanted accumulation - if (topUpSiTotalAmt != null) total += topUpSiTotalAmt!; - if (opdSiTotalAmt != null) total += opdSiTotalAmt!; - if (topUpParentSiTotalAmt != null) total += topUpParentSiTotalAmt!; - if (addOnsDependentTotalAmt != null) total += addOnsDependentTotalAmt!; + if (topUpSiTotalAmt != null && + shouldShowPremiumSummary(topUpIsPremiumSummary)) { + total += topUpSiTotalAmt!; + } + if (opdSiTotalAmt != null && + shouldShowPremiumSummary(opdIsPremiumSummary)) { + total += opdSiTotalAmt!; + } + if (topUpParentSiTotalAmt != null && + shouldShowPremiumSummary(topUpParentIsPremiumSummary)) { + total += topUpParentSiTotalAmt!; + } + if (addOnsDependentTotalAmt != null && + shouldShowPremiumSummary(addOnsDependentIsPremiumSummary)) { + total += addOnsDependentTotalAmt!; + } if (gpaTotalAmt != null) total += gpaTotalAmt!; if (gmcTotalAmt != null) total += gmcTotalAmt!; @@ -1810,9 +1928,10 @@ setState(() { SizedBox(height: 16), if (gpahasPremiumSummary || gmchasPremiumSummary || - topUpIsPremiumSummary || - topUpParentIsPremiumSummary || - addOnsDependentIsPremiumSummary || opdIsPremiumSummary)...[ + shouldShowPremiumSummary(topUpIsPremiumSummary) || + shouldShowPremiumSummary(topUpParentIsPremiumSummary) || + shouldShowPremiumSummary(addOnsDependentIsPremiumSummary) || + shouldShowPremiumSummary(opdIsPremiumSummary))...[ Card( elevation: 0, color: Colors.white, @@ -2910,9 +3029,10 @@ setState(() { children: [ if (gpahasPremiumSummary || gmchasPremiumSummary || - topUpIsPremiumSummary || - topUpParentIsPremiumSummary || - addOnsDependentIsPremiumSummary || opdIsPremiumSummary)...[ + shouldShowPremiumSummary(topUpIsPremiumSummary) || + shouldShowPremiumSummary(topUpParentIsPremiumSummary) || + shouldShowPremiumSummary(addOnsDependentIsPremiumSummary) || + shouldShowPremiumSummary(opdIsPremiumSummary))...[ Container( child: Row( crossAxisAlignment: @@ -2964,495 +3084,157 @@ setState(() { child: Container( alignment: Alignment .centerLeft, // Adjust padding as needed - child: Table( - columnWidths: { - 0: FlexColumnWidth( - 2), // Adjust column width as needed - 1: FlexColumnWidth(2), - 2: FlexColumnWidth( - 2), // Adjust column width as needed - 3: FlexColumnWidth(2), - }, - children: [ - TableRow( + child: Builder( + builder: (context) { + final bool includeBreakdownColumns = + hasAnyFullPremiumBreakdown(); + return Table( + columnWidths: includeBreakdownColumns + ? { + 0: FlexColumnWidth(2), + 1: FlexColumnWidth(2), + 2: FlexColumnWidth(2), + 3: FlexColumnWidth(2), + } + : { + 0: FlexColumnWidth(3), + 1: FlexColumnWidth(1), + }, children: [ - TableCell( - child: Padding( - padding: - EdgeInsets - .all(8.0), - child: Text( - 'Policy ', - textAlign: - TextAlign - .start, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) - ? 16 - : 14, - fontWeight: - FontWeight - .bold), - ), - ), - ), - TableCell( - child: Padding( - padding: - EdgeInsets - .all(8.0), - child: Text( - 'Additional Premium', - textAlign: - TextAlign - .start, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) - ? 16 - : 14, - fontWeight: - FontWeight - .bold), - ), - ), - ), - TableCell( - child: Padding( - padding: - EdgeInsets - .all(8.0), - child: Text( - 'GST', - textAlign: - TextAlign - .start, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) - ? 16 - : 14, - fontWeight: - FontWeight - .bold), - ), - ), - ), - TableCell( - child: Padding( - padding: - EdgeInsets - .all(8.0), - child: Text( + TableRow( + children: [ + _premiumSummaryHeaderCell( + context, 'Policy '), + if (includeBreakdownColumns) ...[ + _premiumSummaryHeaderCell( + context, + 'Additional Premium'), + _premiumSummaryHeaderCell( + context, 'GST'), + ], + _premiumSummaryHeaderCell( + context, 'Total', - textAlign: - TextAlign - .start, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) - ? 16 - : 14, - fontWeight: - FontWeight - .bold), + textAlign: includeBreakdownColumns + ? TextAlign.start + : TextAlign.end, ), - ), + ], ), + if (gpaPolicies != null && + gpaPolicies.length > 0) + ...gpaBuildPolicyRows( + gpaPolicies, + context, + includeBreakdownColumns: + includeBreakdownColumns, + ), + if (gmcPolicies != null && + gmcPolicies.length > 0) + ...gmcBuildPolicyRows( + gmcPolicies, + context, + includeBreakdownColumns: + includeBreakdownColumns, + ), + if (activeSiData == 1 && + shouldShowPremiumSummary( + topUpIsPremiumSummary)) + TableRow( + children: buildPremiumSummaryRowCells( + context: context, + policyLabel: Responsive.isDesktop(context) + ? (topUpPolicyName ?? + 'Default Top Up Name') + : 'GMC - Top Up', + premiumValue: + '₹$topUpSiPremiumValue/Year', + gstValue: + '₹$topUpSiPremiumGst/-', + totalValue: + '₹$topUpSiTotalAmt/Year', + includeBreakdownColumns: + includeBreakdownColumns, + showBreakdownValues: + shouldShowFullPremiumBreakdown( + topUpIsPremiumSummary), + ), + ), + if (activeOPDSiData == 1 && + shouldShowPremiumSummary( + opdIsPremiumSummary)) + TableRow( + children: buildPremiumSummaryRowCells( + context: context, + policyLabel: Responsive.isDesktop(context) + ? (opdPolicyName ?? + 'Default OPD Name') + : 'GMC - OPD', + premiumValue: + '₹$opdSiPremiumValue/Year', + gstValue: + '₹$opdSiPremiumGst/-', + totalValue: + '₹$opdSiTotalAmt/Year', + includeBreakdownColumns: + includeBreakdownColumns, + showBreakdownValues: + shouldShowFullPremiumBreakdown( + opdIsPremiumSummary), + ), + ), + if (activeSiParentData == 1 && + shouldShowPremiumSummary( + topUpParentIsPremiumSummary)) + TableRow( + children: buildPremiumSummaryRowCells( + context: context, + policyLabel: Responsive.isDesktop(context) + ? (topUpParentPolicyName ?? + 'Default Parent Top Up Name') + : 'GMC - Parents Top Up', + premiumValue: + '₹$topUpParentSiPremiumValue/Year', + gstValue: + '₹$topUpParentSiPremiumGst/-', + totalValue: + '₹$topUpParentSiTotalAmt/Year', + includeBreakdownColumns: + includeBreakdownColumns, + showBreakdownValues: + shouldShowFullPremiumBreakdown( + topUpParentIsPremiumSummary), + ), + ), + if (activeDependentData == 1 && + shouldShowPremiumSummary( + addOnsDependentIsPremiumSummary)) + TableRow( + children: buildPremiumSummaryRowCells( + context: context, + policyLabel: Responsive.isDesktop(context) + ? (addOnsDependentPolicyName ?? + 'Default Add Dependent Up Name') + : 'GMC - Dependent', + premiumValue: + '₹$addOnDependentPremiumValue/Year', + gstValue: + '₹$addOnsDependentPremiumGst/-', + totalValue: + '₹$addOnsDependentTotalAmt/Year', + includeBreakdownColumns: + includeBreakdownColumns, + showBreakdownValues: + shouldShowFullPremiumBreakdown( + addOnsDependentIsPremiumSummary), + ), + ), ], - ), - if (gpaPolicies != null && - gpaPolicies.length > 0) - ...gpaBuildPolicyRows( - gpaPolicies, context), - if (gmcPolicies != null && - gmcPolicies.length > 0) - ...gmcBuildPolicyRows( - gmcPolicies, context), - if (activeSiData == 1 && - topUpIsPremiumSummary) - TableRow( - children: [ - TableCell( - child: Padding( - padding: - EdgeInsets - .all(8.0), - child: Text( - (Responsive.isDesktop( - context) - ? (topUpPolicyName ?? - 'Default Top Up Name') - : 'GMC - Top Up'), - textAlign: - TextAlign - .start, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) - ? 14 - : 12), - ), - ), - ), - TableCell( - child: Padding( - padding: - EdgeInsets - .all(8.0), - child: Text( - '₹$topUpSiPremiumValue/Year', - textAlign: Responsive - .isDesktop( - context) - ? TextAlign - .start - : TextAlign - .start, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) - ? 14 - : 12), - ), - ), - ), - TableCell( - child: Padding( - padding: - EdgeInsets - .all(8.0), - child: Text( - '₹$topUpSiPremiumGst/-', - textAlign: Responsive - .isDesktop( - context) - ? TextAlign - .start - : TextAlign - .start, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) - ? 14 - : 12), - ), - ), - ), - TableCell( - child: Padding( - padding: - EdgeInsets - .all(8.0), - child: Text( - '₹$topUpSiTotalAmt/Year', - textAlign: Responsive - .isDesktop( - context) - ? TextAlign - .start - : TextAlign - .start, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) - ? 14 - : 12), - ), - ), - ), - ], - ), - - if (activeOPDSiData == 1 && - opdIsPremiumSummary) - TableRow( - children: [ - TableCell( - child: Padding( - padding: - EdgeInsets - .all(8.0), - child: Text( - (Responsive.isDesktop( - context) - ? (opdPolicyName ?? - 'Default OPD Name') - : 'GMC - OPD'), - textAlign: - TextAlign - .start, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) - ? 14 - : 12), - ), - ), - ), - TableCell( - child: Padding( - padding: - EdgeInsets - .all(8.0), - child: Text( - '₹$opdSiPremiumValue/Year', - textAlign: Responsive - .isDesktop( - context) - ? TextAlign - .start - : TextAlign - .start, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) - ? 14 - : 12), - ), - ), - ), - TableCell( - child: Padding( - padding: - EdgeInsets - .all(8.0), - child: Text( - '₹$opdSiPremiumGst/-', - textAlign: Responsive - .isDesktop( - context) - ? TextAlign - .start - : TextAlign - .start, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) - ? 14 - : 12), - ), - ), - ), - TableCell( - child: Padding( - padding: - EdgeInsets - .all(8.0), - child: Text( - '₹$opdSiTotalAmt/Year', - textAlign: Responsive - .isDesktop( - context) - ? TextAlign - .start - : TextAlign - .start, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) - ? 14 - : 12), - ), - ), - ), - ], - ), - - if (activeSiParentData == - 1 && - topUpParentIsPremiumSummary) - TableRow( - children: [ - TableCell( - child: Padding( - padding: - EdgeInsets - .all(8.0), - child: Text( - (Responsive.isDesktop( - context) - ? (topUpParentPolicyName ?? - 'Default Parent Top Up Name') - : 'GMC - Parents Top Up'), - textAlign: - TextAlign - .start, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) - ? 14 - : 12), - ), - ), - ), - TableCell( - child: Padding( - padding: - EdgeInsets - .all(8.0), - child: Text( - '₹$topUpParentSiPremiumValue/Year', - textAlign: Responsive - .isDesktop( - context) - ? TextAlign - .start - : TextAlign - .start, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) - ? 14 - : 12), - ), - ), - ), - TableCell( - child: Padding( - padding: - EdgeInsets - .all(8.0), - child: Text( - '₹$topUpParentSiPremiumGst/-', - textAlign: Responsive - .isDesktop( - context) - ? TextAlign - .start - : TextAlign - .start, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) - ? 14 - : 12), - ), - ), - ), - TableCell( - child: Padding( - padding: - EdgeInsets - .all(8.0), - child: Text( - '₹$topUpParentSiTotalAmt/Year', - textAlign: Responsive - .isDesktop( - context) - ? TextAlign - .start - : TextAlign - .start, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) - ? 14 - : 12), - ), - ), - ), - ], - ), - if (activeDependentData == - 1 && - addOnsDependentIsPremiumSummary) - TableRow( - children: [ - TableCell( - child: Padding( - padding: - EdgeInsets - .all(8.0), - child: Text( - Responsive.isDesktop( - context) - ? (addOnsDependentPolicyName ?? - 'Default Add Dependent Up Name') - : 'GMC - Dependent', - textAlign: - TextAlign - .start, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) - ? 14 - : 12), - ), - ), - ), - TableCell( - child: Padding( - padding: - EdgeInsets - .all(8.0), - child: Text( - '₹$addOnDependentPremiumValue/Year', - textAlign: Responsive - .isDesktop( - context) - ? TextAlign - .start - : TextAlign - .start, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) - ? 14 - : 12), - ), - ), - ), - TableCell( - child: Padding( - padding: - EdgeInsets - .all(8.0), - child: Text( - '₹$addOnsDependentPremiumGst/-', - textAlign: Responsive - .isDesktop( - context) - ? TextAlign - .start - : TextAlign - .start, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) - ? 14 - : 12), - ), - ), - ), - TableCell( - child: Padding( - padding: - EdgeInsets - .all(8.0), - child: Text( - '₹$addOnsDependentTotalAmt/Year', - textAlign: Responsive - .isDesktop( - context) - ? TextAlign - .start - : TextAlign - .start, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) - ? 14 - : 12), - ), - ), - ), - ], - ), - ], + ); + }, ), - )) + ), + ), ], ), ), @@ -3828,22 +3610,16 @@ setState(() { double gpaGstValue = toDoubleSafe(item['si_gst_value']); double gpaSiPremiumValue = toDoubleSafe(item['si_premium_value']); - // bool gpaIsPremiumSummery = item['is_premium_summery'] ?? false; - bool gpaIsPremiumSummery = false; - dynamic summery = item['is_premium_summery']; - - if (summery is bool) { - gpaIsPremiumSummery = summery; - } else if (summery is String) { - gpaIsPremiumSummery = (summery == "1"); - } else if (summery is int) { - gpaIsPremiumSummery = (summery == 1); - } - - double gpaTotalableValue = gpaSiPremiumValue + gpaGstValue; bool isValueValid = (gpaSiPremiumValue != 0 && gpaGstValue != 0); + final int premiumSummaryMode = + parsePremiumSummaryMode(item['is_premium_summery']); + // 0 = hide, 1 = full summary, 2 = total only + final bool showFullPremiumSummary = + premiumSummaryMode == 1 && isValueValid; + final bool showPremiumTotalOnly = + premiumSummaryMode == 2 && gpaTotalableValue != 0; String? gpaSumInsured; @@ -4040,11 +3816,11 @@ setState(() { children: familyFloaterContainers, ), if (Responsive.isDesktop(context) && - isValueValid && - gpaIsPremiumSummery == '1') + (showFullPremiumSummary || showPremiumTotalOnly)) Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ + if (showFullPremiumSummary) ...[ Expanded( flex: 5, child: Container( @@ -4095,6 +3871,7 @@ setState(() { ), ], ))), + ], Expanded( flex: 5, child: Container( @@ -4123,12 +3900,12 @@ setState(() { ], ), if (!Responsive.isDesktop(context) && - isValueValid && - gpaIsPremiumSummery == '1') + (showFullPremiumSummary || showPremiumTotalOnly)) Container( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ + if (showFullPremiumSummary) ...[ Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -4213,11 +3990,7 @@ setState(() { ))), ], ), - if (gpahasPremiumSummary || - gmchasPremiumSummary || - topUpIsPremiumSummary || - topUpParentIsPremiumSummary || - addOnsDependentIsPremiumSummary || opdIsPremiumSummary) + ], Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -4300,19 +4073,6 @@ setState(() { String gmcNotes = item['notes'] ?? ''; String gmcECardDownload = item['eCardDownload'] ?? ''; - // bool gmcIsPremiumSummery = item['is_premium_summery'] ?? false; - bool gmcIsPremiumSummery = false; - dynamic summery = item['is_premium_summery']; - - if (summery is bool) { - gmcIsPremiumSummery = summery; - } else if (summery is String) { - gmcIsPremiumSummery = (summery == "1"); - } else if (summery is int) { - gmcIsPremiumSummery = (summery == 1); - } - - // ------------------------------- // SAFE numeric conversion // ------------------------------- @@ -4325,6 +4085,13 @@ setState(() { double gmcTotalableValue = gmcGstValue + gmcSiPremiumValue; bool gmcIsValueValid = (gmcSiPremiumValue > 0 && gmcGstValue > 0); + final int gmcPremiumSummaryMode = + parsePremiumSummaryMode(item['is_premium_summery']); + // 0 = hide, 1 = full summary, 2 = total only + final bool showFullGmcPremiumSummary = + gmcPremiumSummaryMode == 1 && gmcIsValueValid; + final bool showGmcPremiumTotalOnly = + gmcPremiumSummaryMode == 2 && gmcTotalableValue != 0; // ------------------------------- // SAFE list handling @@ -4510,11 +4277,11 @@ setState(() { ), ), if (Responsive.isDesktop(context) && - gmcIsValueValid && - gmcIsPremiumSummery == '1') + (showFullGmcPremiumSummary || showGmcPremiumTotalOnly)) Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ + if (showFullGmcPremiumSummary) ...[ Expanded( flex: 5, child: Container( @@ -4567,6 +4334,7 @@ setState(() { ), ], ))), + ], Expanded( flex: 5, child: Container( @@ -4596,12 +4364,12 @@ setState(() { ], ), if (!Responsive.isDesktop(context) && - gmcIsValueValid && - gmcIsPremiumSummery == '1') + (showFullGmcPremiumSummary || showGmcPremiumTotalOnly)) Container( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ + if (showFullGmcPremiumSummary) ...[ Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -4690,6 +4458,7 @@ setState(() { ))), ], ), + ], Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -4748,7 +4517,10 @@ setState(() { double calculateGpaTotalAmt(List> policies) { double total = policies - .where((policy) => policy is Map) + .where((policy) => + policy is Map && + shouldShowPremiumSummary( + parsePremiumSummaryMode(policy['is_premium_summery']))) .map((policy) => (policy["si_gst_value"] ?? 0) + (policy["si_premium_value"] ?? 0)) .fold(0.0, (sum, value) => sum + value); @@ -4759,7 +4531,10 @@ setState(() { double calculateGmcTotalAmt(List> policies) { double total = policies - .where((policy) => policy is Map) + .where((policy) => + policy is Map && + shouldShowPremiumSummary( + parsePremiumSummaryMode(policy['is_premium_summery']))) .map((policy) => (policy["family_floaters_of_dependent_and_gst_value"] ?? 0) + (policy["family_floaters_of_dependent_and_si_premium_value"] ?? 0)) @@ -4769,7 +4544,11 @@ setState(() { return total; } - List gpaBuildPolicyRows(dynamic policies, BuildContext context) { + List gpaBuildPolicyRows( + dynamic policies, + BuildContext context, { + bool includeBreakdownColumns = true, + }) { if (policies is! List) { return []; // Return empty list if policies is not a list } @@ -4782,67 +4561,48 @@ setState(() { .map((policy) { var siGstValue = policy["si_gst_value"] ?? 0; var siPremiumValue = policy["si_premium_value"] ?? 0; - dynamic si_is_premium_summery = policy['is_premium_summery']; + final int premiumMode = + parsePremiumSummaryMode(policy['is_premium_summery']); + final total = + (siPremiumValue is num ? siPremiumValue.toDouble() : 0.0) + + (siGstValue is num ? siGstValue.toDouble() : 0.0); - if (siGstValue == 0 || siPremiumValue == 0) - return null; // Skip invalid policies + // 0 = hide, 1 = full, 2 = total only + if (premiumMode == 0) return null; + if (premiumMode == 1 && (siGstValue == 0 || siPremiumValue == 0)) { + return null; + } + if (premiumMode == 2 && total == 0) return null; + + final bool showBreakdownValues = + shouldShowFullPremiumBreakdown(premiumMode); + final policyLabel = Responsive.isDesktop(context) + ? (policy["Policy_Name"] ?? 'Default Policy Name') + : policy['type']; + final totalValue = + '₹${(policy["si_premium_value"] ?? 0) + (policy["si_gst_value"] ?? 0)}/Year'; return TableRow( - children: [ - TableCell( - child: Padding( - padding: EdgeInsets.all(8.0), - child: Text( - Responsive.isDesktop(context) - ? (policy["Policy_Name"] ?? 'Default Policy Name') - : policy['type'], - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12), - ), - ), - ), - TableCell( - child: Padding( - padding: EdgeInsets.all(8.0), - child: Text( - '₹${policy["si_premium_value"]}/Year', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12), - ), - ), - ), - TableCell( - child: Padding( - padding: EdgeInsets.all(8.0), - child: Text( - '₹${policy["si_gst_value"]}/-', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12), - ), - ), - ), - TableCell( - child: Padding( - padding: EdgeInsets.all(8.0), - child: Text( - '₹${(policy["si_premium_value"] ?? 0) + (policy["si_gst_value"] ?? 0)}/Year', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12), - ), - ), - ), - ], + children: buildPremiumSummaryRowCells( + context: context, + policyLabel: policyLabel?.toString() ?? '', + premiumValue: '₹${policy["si_premium_value"]}/Year', + gstValue: '₹${policy["si_gst_value"]}/-', + totalValue: totalValue, + includeBreakdownColumns: includeBreakdownColumns, + showBreakdownValues: showBreakdownValues, + ), ); }) .whereType() // Filter out null values .toList(); } - List gmcBuildPolicyRows(dynamic policies, BuildContext context) { + List gmcBuildPolicyRows( + dynamic policies, + BuildContext context, { + bool includeBreakdownColumns = true, + }) { logDebug('gmcBuildPolicyRows $policies'); if (policies is! List) { @@ -4859,59 +4619,39 @@ setState(() { policy["family_floaters_of_dependent_and_gst_value"] ?? 0; var siPremiumValue = policy["family_floaters_of_dependent_and_si_premium_value"] ?? 0; + final int premiumMode = + parsePremiumSummaryMode(policy['is_premium_summery']); + final total = + (siPremiumValue is num ? siPremiumValue.toDouble() : 0.0) + + (siGstValue is num ? siGstValue.toDouble() : 0.0); - if (siGstValue == 0 || siPremiumValue == 0) - return null; // Skip invalid policies + // 0 = hide, 1 = full, 2 = total only + if (premiumMode == 0) return null; + if (premiumMode == 1 && (siGstValue == 0 || siPremiumValue == 0)) { + return null; + } + if (premiumMode == 2 && total == 0) return null; + + final bool showBreakdownValues = + shouldShowFullPremiumBreakdown(premiumMode); + final policyLabel = Responsive.isDesktop(context) + ? (policy["Policy_Name"] ?? 'Default Policy Name') + : policy['type']; + final totalValue = + '₹${(policy["family_floaters_of_dependent_and_si_premium_value"] ?? 0) + (policy["family_floaters_of_dependent_and_gst_value"] ?? 0)}/Year'; return TableRow( - children: [ - TableCell( - child: Padding( - padding: EdgeInsets.all(8.0), - child: Text( - Responsive.isDesktop(context) - ? (policy["Policy_Name"] ?? 'Default Policy Name') - : policy['type'], - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12), - ), - ), - ), - TableCell( - child: Padding( - padding: EdgeInsets.all(8.0), - child: Text( - '₹${policy["family_floaters_of_dependent_and_si_premium_value"]}/Year', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12), - ), - ), - ), - TableCell( - child: Padding( - padding: EdgeInsets.all(8.0), - child: Text( - '₹${policy["family_floaters_of_dependent_and_gst_value"]}/-', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12), - ), - ), - ), - TableCell( - child: Padding( - padding: EdgeInsets.all(8.0), - child: Text( - '₹${(policy["family_floaters_of_dependent_and_si_premium_value"] ?? 0) + (policy["family_floaters_of_dependent_and_gst_value"] ?? 0)}/Year', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: Responsive.isDesktop(context) ? 14 : 12), - ), - ), - ), - ], + children: buildPremiumSummaryRowCells( + context: context, + policyLabel: policyLabel?.toString() ?? '', + premiumValue: + '₹${policy["family_floaters_of_dependent_and_si_premium_value"]}/Year', + gstValue: + '₹${policy["family_floaters_of_dependent_and_gst_value"]}/-', + totalValue: totalValue, + includeBreakdownColumns: includeBreakdownColumns, + showBreakdownValues: showBreakdownValues, + ), ); }) .whereType() // Filter out null values diff --git a/pubspec.yaml b/pubspec.yaml index b689936..2fb09ba 100755 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -17,8 +17,8 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. #version: 1.2.42+99 -version: 1.0.42+49 -#version: 2.0.30+69 +version: 1.0.43+50 +#version: 2.0.31+70 environment: sdk: '>=3.3.3 <4.0.0'