From 376e892e1d6b3cf190801af7a164b00f1d43ba8e Mon Sep 17 00:00:00 2001 From: Rahul Dev Garg <34365102+rahuldevgarg@users.noreply.github.com> Date: Fri, 28 Apr 2023 14:59:45 +0530 Subject: [PATCH 1/2] removed id from Billing SLab Model --- .../lib/model/mdms/wc_billing_slab.dart | 12 +++--- .../lib/model/mdms/wc_billing_slab.g.dart | 12 +++--- .../providers/ifix_hierarchy_provider.dart | 2 + .../screeens/GpwscDetails/GpwscRateCard.dart | 43 +++++++++++++++---- 4 files changed, 47 insertions(+), 22 deletions(-) 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..5a226ecfa 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,22 +46,43 @@ 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) @@ -149,7 +176,7 @@ 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")), From ccc1f873f7711de9a3f06df1f8f5657a508fa254 Mon Sep 17 00:00:00 2001 From: Rahul Dev Garg <34365102+rahuldevgarg@users.noreply.github.com> Date: Fri, 28 Apr 2023 15:05:45 +0530 Subject: [PATCH 2/2] added localization --- .../lib/screeens/GpwscDetails/GpwscRateCard.dart | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/frontend/mgramseva/lib/screeens/GpwscDetails/GpwscRateCard.dart b/frontend/mgramseva/lib/screeens/GpwscDetails/GpwscRateCard.dart index 5a226ecfa..bbe5bf987 100644 --- a/frontend/mgramseva/lib/screeens/GpwscDetails/GpwscRateCard.dart +++ b/frontend/mgramseva/lib/screeens/GpwscDetails/GpwscRateCard.dart @@ -87,9 +87,11 @@ class GpwscRateCard extends StatelessWidget { 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}")) ]))) }); @@ -180,8 +182,10 @@ class GpwscRateCard extends StatelessWidget { .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()),