diff --git a/frontend/mgramseva/lib/providers/search_connection_provider.dart b/frontend/mgramseva/lib/providers/search_connection_provider.dart index 5c2e1529a..f44738a6e 100644 --- a/frontend/mgramseva/lib/providers/search_connection_provider.dart +++ b/frontend/mgramseva/lib/providers/search_connection_provider.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:convert'; import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:mgramseva/model/connection/search_connection.dart'; @@ -54,7 +55,6 @@ class SearchConnectionProvider with ChangeNotifier { var commonProvider = Provider.of( navigatorKey.currentContext!, listen: false); - if (formKey.currentState!.validate()) { searchconnection.setValues(); try { @@ -105,4 +105,49 @@ class SearchConnectionProvider with ChangeNotifier { autoValidation = true; } } + + void fetchNonDemandGeneratedConnectionDetails( + context, String previousMeterReading) async { + FocusScope.of(context).unfocus(); + var commonProvider = Provider.of( + navigatorKey.currentContext!, + listen: false); + try { + Loaders.showLoadingDialog(context); + Map query = { + 'previousMeterReading': previousMeterReading.toString(), + 'tenantId': commonProvider.userDetails?.selectedtenant?.code + }; + var arguments ={"Mode": "update"}; + var connectionresults = + SearchConnectionRepository().getNonDemandGeneratedWC(query); + // popping the loader + connectionresults.then( + (value) => { + Navigator.pop(context), + if (value.waterConnectionData!.length > 0 || + value.waterConnection!.length > 0) + { + waterConnections = value, + Navigator.pushNamed(context, Routes.SEARCH_CONSUMER_RESULT, + arguments: { + ...query, + ...arguments, + "isNameSearch": false + }) + } + else + { + Notifiers.getToastMessage(context, + i18.searchWaterConnection.NO_CONNECTION_FOUND, "ERROR") + } + }, onError: (e, s) { + Navigator.pop(context); + ErrorHandler().allExceptionsHandler(context, e, s); + }); + } catch (e, s) { + Navigator.pop(context); + ErrorHandler().allExceptionsHandler(context, e, s); + } + } } diff --git a/frontend/mgramseva/lib/repository/search_connection_repo.dart b/frontend/mgramseva/lib/repository/search_connection_repo.dart index 6e49c7ffa..c939c4a17 100644 --- a/frontend/mgramseva/lib/repository/search_connection_repo.dart +++ b/frontend/mgramseva/lib/repository/search_connection_repo.dart @@ -66,4 +66,36 @@ class SearchConnectionRepository extends BaseService { } return waterConnections; } + + Future getNonDemandGeneratedWC(Map query) async { + var commonProvider = Provider.of( + navigatorKey.currentContext!, + listen: false); + + final requestInfo = RequestInfo( + APIConstants.API_MODULE_NAME, + APIConstants.API_VERSION, + APIConstants.API_TS, + "_search", + APIConstants.API_DID, + APIConstants.API_KEY, + APIConstants.API_MESSAGE_ID, + commonProvider.userDetails!.accessToken, + commonProvider.userDetails?.userRequest?.toJson(), + ); + var res = await makeRequest( + url: Url.WATER_CONNECTION_DEMAND_NOT_GENERATED, + queryParameters: query, + method: RequestType.POST, + body: {}, + requestInfo: requestInfo); + + if (res != null) { + waterConnections = WaterConnections.fromJson(res); + } + return waterConnections; + } + + + } diff --git a/frontend/mgramseva/lib/screeens/generate_bill/widgets/count_table_widget.dart b/frontend/mgramseva/lib/screeens/generate_bill/widgets/count_table_widget.dart index 06d99ffb1..4371cf2bd 100644 --- a/frontend/mgramseva/lib/screeens/generate_bill/widgets/count_table_widget.dart +++ b/frontend/mgramseva/lib/screeens/generate_bill/widgets/count_table_widget.dart @@ -2,14 +2,17 @@ import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:mgramseva/model/reports/WaterConnectionCount.dart'; +import 'package:mgramseva/providers/search_connection_provider.dart'; import 'package:mgramseva/utils/constants/i18_key_constants.dart'; +import 'package:provider/provider.dart'; import '../../../utils/date_formats.dart'; import '../../../utils/localization/application_localizations.dart'; class CountTableWidget extends StatefulWidget { final List? waterConnectionCount; + final bool? isWCDemandNotGenerated; - const CountTableWidget({Key? key, this.waterConnectionCount}) + const CountTableWidget({Key? key, this.waterConnectionCount, this.isWCDemandNotGenerated}) : super(key: key); @override @@ -61,7 +64,7 @@ class _CountTableWidgetState extends State { borderRadius: BorderRadius.all(Radius.circular(5)), color: Colors.grey, // Set border color to grey ),// Set heading row background color to grey - headingTextStyle: TextStyle(color: Colors.black, fontWeight: FontWeight.bold), // Set heading text color to black and bold + headingTextStyle: TextStyle(color: Colors.black, fontWeight: FontWeight.bold), // Set heading text color to black and bold columns: [ DataColumn( label: FittedBox( @@ -84,10 +87,31 @@ class _CountTableWidgetState extends State { ); } + Widget buildLinkText(int count, bool isWCDemandNotGenerated, {VoidCallback? onTap, Uri? launchUri}) { + final Color linkColor = isWCDemandNotGenerated ? Colors.blue : Colors.black; + final MouseCursor? hoverCursor = SystemMouseCursors.click; // Optional hand cursor + + return GestureDetector( + onTap: () { + // onTap?.call(); + + // if (launchUri != null) { + // } + }, + child: Text( + count.toString(), + style: TextStyle( + color: linkColor, + decoration: TextDecoration.underline, // Optional underline + ), + ), + ); +} + DataRow _buildDataRow(WaterConnectionCount count) { final bool isEvenRow = widget.waterConnectionCount!.indexOf(count) % 2 == 0; final Color? rowColor = isEvenRow ? Colors.grey[100] : Colors.white; // Set alternate row background color to grey - + final status = widget.isWCDemandNotGenerated == true; return DataRow( color: MaterialStateColor.resolveWith((states) => rowColor!), // Apply alternate row background color @@ -100,7 +124,25 @@ class _CountTableWidgetState extends State { ), ), DataCell( - Text(count.count.toString()), + MouseRegion( + cursor: status ? SystemMouseCursors.click : SystemMouseCursors.basic, + child: GestureDetector( + child: + Text(count.count.toString(), + style: TextStyle( + decoration: status ? TextDecoration.underline :TextDecoration.none , + color: status ? Colors.blue : Colors.black + ), + ), + onTap: () { + if(status){ + var searchConnectionProvider = + Provider.of(context, listen: false); + searchConnectionProvider.fetchNonDemandGeneratedConnectionDetails(context,"${count.taxperiodto!}"); + } + }, + ), + ), ), ], ); diff --git a/frontend/mgramseva/lib/screeens/generate_bill/widgets/water_connection_count_widget.dart b/frontend/mgramseva/lib/screeens/generate_bill/widgets/water_connection_count_widget.dart index feb66b3a0..3065b1e63 100644 --- a/frontend/mgramseva/lib/screeens/generate_bill/widgets/water_connection_count_widget.dart +++ b/frontend/mgramseva/lib/screeens/generate_bill/widgets/water_connection_count_widget.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:flutter/material.dart'; import 'package:mgramseva/model/reports/WaterConnectionCount.dart'; import 'package:mgramseva/providers/reports_provider.dart'; @@ -66,6 +68,7 @@ class _WaterConnectionCountWidgetState "${ApplicationLocalizations.of(context).translate(i18.common.LAST_BILL_CYCLE_DEMAND_GENERATED)}", waterConnectionCount .waterConnectionsDemandGenerated, + ), if (waterConnectionCount.waterConnectionsDemandGenerated != null && @@ -79,6 +82,7 @@ class _WaterConnectionCountWidgetState "${ApplicationLocalizations.of(context).translate(i18.common.LAST_BILL_CYCLE_DEMAND_GENERATED)}", waterConnectionCount .waterConnectionsDemandGenerated, + ), SizedBox(height: 20), if (waterConnectionCount.waterConnectionsDemandNotGenerated != @@ -93,6 +97,8 @@ class _WaterConnectionCountWidgetState "${ApplicationLocalizations.of(context).translate(i18.common.LAST_BILL_CYCLE_DEMAND_NOT_GENERATED)}", waterConnectionCount .waterConnectionsDemandNotGenerated, + isWCDemandNotGenerated: true + ), if (waterConnectionCount.waterConnectionsDemandNotGenerated != null && @@ -106,6 +112,7 @@ class _WaterConnectionCountWidgetState "${ApplicationLocalizations.of(context).translate(i18.common.LAST_BILL_CYCLE_DEMAND_NOT_GENERATED)}", waterConnectionCount .waterConnectionsDemandNotGenerated, + isWCDemandNotGenerated: true ), ], ); @@ -121,33 +128,38 @@ class _WaterConnectionCountWidgetState } Widget _buildDataTableRow(BuildContext context, String title, - List? waterConnections) { + List? waterConnections,{bool isWCDemandNotGenerated = false}) { return Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( + alignment: Alignment.centerLeft, width: MediaQuery.of(context).size.width / 3, padding: EdgeInsets.only(top: 18, bottom: 3), - child: Text(title), + child: Text(title ), ), Container( width: MediaQuery.of(context).size.width / 2.5, padding: EdgeInsets.only(top: 18, bottom: 3), - child: CountTableWidget(waterConnectionCount: waterConnections), + child: CountTableWidget(waterConnectionCount: waterConnections, + isWCDemandNotGenerated: isWCDemandNotGenerated, + ), ), ], ); } Widget _buildDataTableColumn(BuildContext context, String title, - List? waterConnections) { + List? waterConnections,{bool isWCDemandNotGenerated = false}) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(title), SizedBox(height: 10), - CountTableWidget(waterConnectionCount: waterConnections), + CountTableWidget(waterConnectionCount: waterConnections, + isWCDemandNotGenerated: isWCDemandNotGenerated, + ), ], ); } diff --git a/frontend/mgramseva/lib/services/urls.dart b/frontend/mgramseva/lib/services/urls.dart index ed2e833dc..5fbee2fd2 100644 --- a/frontend/mgramseva/lib/services/urls.dart +++ b/frontend/mgramseva/lib/services/urls.dart @@ -99,6 +99,8 @@ class Url { 'echallan-services/eChallan/v1/_expenseBillReport'; static const String WATER_CONNECTION_COUNT = 'ws-services/wc/_countWCbyDemandGenerationDate'; + static const String WATER_CONNECTION_DEMAND_NOT_GENERATED = + 'ws-services/wc/consumers/demand-not-generated'; } class UserUrl {