diff --git a/frontend/mgramseva/lib/model/mdms/wc_billing_slab.dart b/frontend/mgramseva/lib/model/mdms/wc_billing_slab.dart index 17299b140..62e0206c4 100644 --- a/frontend/mgramseva/lib/model/mdms/wc_billing_slab.dart +++ b/frontend/mgramseva/lib/model/mdms/wc_billing_slab.dart @@ -4,8 +4,6 @@ part 'wc_billing_slab.g.dart'; @JsonSerializable() class WCBillingSlab { - @JsonKey(name: "id") - String? id; @JsonKey(name: "buildingType") String? buildingType; @@ -17,7 +15,7 @@ class WCBillingSlab { String? calculationAttribute; @JsonKey(name: "minimumCharge") - String? minimumCharge; + double? minimumCharge; @JsonKey(name: "slabs") List? slabs; @@ -33,16 +31,16 @@ class WCBillingSlab { @JsonSerializable() class Slabs { @JsonKey(name: "from") - String? from; + int? from; @JsonKey(name: "to") - String? to; + int? to; @JsonKey(name: "charge") - String? charge; + double? charge; @JsonKey(name: "meterCharge") - String? meterCharge; + double? meterCharge; Slabs(); diff --git a/frontend/mgramseva/lib/model/mdms/wc_billing_slab.g.dart b/frontend/mgramseva/lib/model/mdms/wc_billing_slab.g.dart index 2dd60e591..31a870785 100644 --- a/frontend/mgramseva/lib/model/mdms/wc_billing_slab.g.dart +++ b/frontend/mgramseva/lib/model/mdms/wc_billing_slab.g.dart @@ -8,18 +8,16 @@ part of 'wc_billing_slab.dart'; WCBillingSlab _$WCBillingSlabFromJson(Map json) => WCBillingSlab() - ..id = json['id'] as String? ..buildingType = json['buildingType'] as String? ..connectionType = json['connectionType'] as String? ..calculationAttribute = json['calculationAttribute'] as String? - ..minimumCharge = json['minimumCharge'] as String? + ..minimumCharge = json['minimumCharge'] as double? ..slabs = (json['slabs'] as List?) ?.map((e) => Slabs.fromJson(e as Map)) .toList(); Map _$WCBillingSlabToJson(WCBillingSlab instance) => { - 'id': instance.id, 'buildingType': instance.buildingType, 'connectionType': instance.connectionType, 'calculationAttribute': instance.calculationAttribute, @@ -28,10 +26,10 @@ Map _$WCBillingSlabToJson(WCBillingSlab instance) => }; Slabs _$SlabsFromJson(Map json) => Slabs() - ..from = json['from'] as String? - ..to = json['to'] as String? - ..charge = json['charge'] as String? - ..meterCharge = json['meterCharge'] as String?; + ..from = json['from'] as int? + ..to = json['to'] as int? + ..charge = json['charge'] as double? + ..meterCharge = json['meterCharge'] as double?; Map _$SlabsToJson(Slabs instance) => { 'from': instance.from, diff --git a/frontend/mgramseva/lib/providers/ifix_hierarchy_provider.dart b/frontend/mgramseva/lib/providers/ifix_hierarchy_provider.dart index 40baeca14..444d6b19e 100644 --- a/frontend/mgramseva/lib/providers/ifix_hierarchy_provider.dart +++ b/frontend/mgramseva/lib/providers/ifix_hierarchy_provider.dart @@ -16,6 +16,7 @@ class IfixHierarchyProvider with ChangeNotifier { Map> hierarchy={}; WCBillingSlabs? wcBillingSlabs; var streamController = StreamController.broadcast(); + var streamControllerRate = StreamController.broadcast(); dispose() { streamController.close(); @@ -51,6 +52,7 @@ class IfixHierarchyProvider with ChangeNotifier { var mdmsRates = await CoreRepository().getRateFromMdms( commonProvider.userDetails!.selectedtenant!.code!); wcBillingSlabs = mdmsRates; + streamControllerRate.add(wcBillingSlabs); callNotifier(); } catch (e, s) { ErrorHandler().allExceptionsHandler(navigatorKey.currentContext!, e, s); diff --git a/frontend/mgramseva/lib/screeens/GpwscDetails/GpwscRateCard.dart b/frontend/mgramseva/lib/screeens/GpwscDetails/GpwscRateCard.dart index 0d2bd5e5d..bbe5bf987 100644 --- a/frontend/mgramseva/lib/screeens/GpwscDetails/GpwscRateCard.dart +++ b/frontend/mgramseva/lib/screeens/GpwscDetails/GpwscRateCard.dart @@ -3,7 +3,11 @@ import 'package:flutter/material.dart'; import 'package:mgramseva/utils/Constants/I18KeyConstants.dart'; import 'package:provider/provider.dart'; import '../../providers/ifix_hierarchy_provider.dart'; +import '../../repository/water_services_calculation.dart'; import '../../utils/Locilization/application_localizations.dart'; +import '../../utils/common_widgets.dart'; +import '../../utils/loaders.dart'; +import '../../utils/notifyers.dart'; import '../../widgets/LabelText.dart'; import 'GpwscCard.dart'; @@ -31,7 +35,9 @@ class GpwscRateCard extends StatelessWidget { } @override Widget build(BuildContext context) { + WCBillingSlabs? wcBillingSlabs; return LayoutBuilder(builder: (context, constraints) { + var ifixProvider = Provider.of(context, listen: false); return GpwscCard( children: [ constraints.maxWidth < 760?Column( @@ -40,29 +46,52 @@ class GpwscRateCard extends StatelessWidget { ):Row( children: getTableTitle(context,constraints,rateType), ), - Consumer( - key: key, - builder: (_, departmentProvider, child) { - return _getRateCard( - rateType, departmentProvider, context, constraints); + StreamBuilder( + stream: ifixProvider.streamControllerRate.stream, + builder: (context, AsyncSnapshot snapshot) { + if (snapshot.hasData) { + if (snapshot.data is String) { + return CommonWidgets.buildEmptyMessage(snapshot.data, context); + } + wcBillingSlabs = snapshot.data; + return Consumer( + key: key, + builder: (_, departmentProvider, child) { + return _getRateCard( + rateType, wcBillingSlabs!, context, constraints); + }); + } else if (snapshot.hasError) { + return Notifiers.networkErrorPage(context, () => {}); + } else { + switch (snapshot.connectionState) { + case ConnectionState.waiting: + return Loaders.CircularLoader(); + case ConnectionState.active: + return Loaders.CircularLoader(); + default: + return Container(); + } + } }) ], ); }); } - Widget _getRateCard(String type, IfixHierarchyProvider ifixHierarchyProvider, + Widget _getRateCard(String type, WCBillingSlabs wcBillingSlabs, context, BoxConstraints constraints) { List getMeteredRows(){ List rows = []; - ifixHierarchyProvider.wcBillingSlabs!.wCBillingSlabs?.where((element) => element.connectionType?.compareTo("Metered")==0).forEach((e) =>{ + wcBillingSlabs.wCBillingSlabs?.where((element) => element.connectionType?.compareTo("Metered")==0).forEach((e) =>{ e.slabs?.forEach((slabs) => rows.add(DataRow(cells: [ DataCell(Text("${ApplicationLocalizations.of(context) .translate(i18.common.WATER_CHARGES)}-10101")), - DataCell(Text("${e.calculationAttribute}")), + DataCell(Text("${ApplicationLocalizations.of(context) + .translate("${e.calculationAttribute}")}")), DataCell(Text("${slabs.from}-${slabs.to}")), - DataCell(Text("${e.buildingType}")), + DataCell(Text("${ApplicationLocalizations.of(context) + .translate("${e.buildingType}")}")), DataCell(Text("${slabs.charge}")) ]))) }); @@ -149,12 +178,14 @@ class GpwscRateCard extends StatelessWidget { TextStyle(color: Colors.black, fontWeight: FontWeight.bold), )), ], - rows: ifixHierarchyProvider.wcBillingSlabs!.wCBillingSlabs!.where((element) => element.connectionType?.compareTo("Metered")!=0) + rows: wcBillingSlabs.wCBillingSlabs!.where((element) => element.connectionType?.compareTo("Metered")!=0) .map((slab) => DataRow(cells: [ DataCell(Text("${ApplicationLocalizations.of(context) .translate(i18.common.WATER_CHARGES)}-10101")), - DataCell(Text("${slab.calculationAttribute}")), - DataCell(Text("${slab.buildingType}")), + DataCell(Text("${ApplicationLocalizations.of(context) + .translate("${slab.calculationAttribute}")}")), + DataCell(Text("${ApplicationLocalizations.of(context) + .translate("${slab.buildingType}")}")), DataCell(Text("${slab.minimumCharge}")) ])) .toList()),