diff --git a/frontend/mgramseva/lib/model/connection/water_connection.dart b/frontend/mgramseva/lib/model/connection/water_connection.dart index 37e2937b8..720e7333c 100644 --- a/frontend/mgramseva/lib/model/connection/water_connection.dart +++ b/frontend/mgramseva/lib/model/connection/water_connection.dart @@ -219,6 +219,66 @@ class WaterConnection { factory WaterConnection.fromJson(Map json) => _$WaterConnectionFromJson(json); Map toJson() => _$WaterConnectionToJson(this); + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is WaterConnection && + other.id == id && + other.connectionNo == connectionNo && + other.propertyId == propertyId && + other.applicationNo == applicationNo && + other.tenantId == tenantId && + other.action == action && + other.status == status && + other.meterInstallationDate == meterInstallationDate && + other.documents == documents && + other.proposedTaps == proposedTaps && + other.noOfTaps == noOfTaps && + other.arrears == arrears && + other.connectionType == connectionType && + other.oldConnectionNo == oldConnectionNo && + other.meterId == meterId && + other.propertyType == propertyType && + other.previousReadingDate == previousReadingDate && + other.previousReading == previousReading && + other.proposedPipeSize == proposedPipeSize && + other.connectionHolders == connectionHolders && + other.additionalDetails == additionalDetails && + other.processInstance == processInstance && + other.paymentType == paymentType && + other.penalty == penalty && + other.advance == advance; + } + + @override + int get hashCode { + return id.hashCode ^ + connectionNo.hashCode ^ + propertyId.hashCode ^ + applicationNo.hashCode ^ + tenantId.hashCode ^ + action.hashCode ^ + status.hashCode ^ + meterInstallationDate.hashCode ^ + documents.hashCode ^ + proposedTaps.hashCode ^ + noOfTaps.hashCode ^ + arrears.hashCode ^ + connectionType.hashCode ^ + oldConnectionNo.hashCode ^ + meterId.hashCode ^ + propertyType.hashCode ^ + previousReadingDate.hashCode ^ + previousReading.hashCode ^ + proposedPipeSize.hashCode ^ + connectionHolders.hashCode ^ + additionalDetails.hashCode ^ + processInstance.hashCode ^ + paymentType.hashCode ^ + penalty.hashCode ^ + advance.hashCode; + } } @JsonSerializable() diff --git a/frontend/mgramseva/lib/model/reports/WaterConnectionCount.dart b/frontend/mgramseva/lib/model/reports/WaterConnectionCount.dart new file mode 100644 index 000000000..30d77a4a9 --- /dev/null +++ b/frontend/mgramseva/lib/model/reports/WaterConnectionCount.dart @@ -0,0 +1,59 @@ +class WaterConnectionCount { + int? count; + int? taxperiodto; + + WaterConnectionCount({this.count, this.taxperiodto}); + + WaterConnectionCount.fromJson(Map json) { + count = json['count']??0; + taxperiodto = json['taxperiodto']??0; + } + + Map toJson() { + final Map data = new Map(); + data['count'] = this.count; + data['taxperiodto'] = this.taxperiodto; + return data; + } +} +class WaterConnectionCountResponse { + List? waterConnectionsDemandGenerated; + List? waterConnectionsDemandNotGenerated; + + WaterConnectionCountResponse( + {this.waterConnectionsDemandGenerated, + this.waterConnectionsDemandNotGenerated}); + + WaterConnectionCountResponse.fromJson(Map json) { + if (json['WaterConnectionsDemandGenerated'] != null) { + waterConnectionsDemandGenerated = []; + json['WaterConnectionsDemandGenerated'].forEach((v) { + waterConnectionsDemandGenerated! + .add(new WaterConnectionCount.fromJson(v)); + }); + } + if (json['WaterConnectionsDemandNotGenerated'] != null) { + waterConnectionsDemandNotGenerated = + []; + json['WaterConnectionsDemandNotGenerated'].forEach((v) { + waterConnectionsDemandNotGenerated! + .add(new WaterConnectionCount.fromJson(v)); + }); + } + } + + Map toJson() { + final Map data = new Map(); + if (this.waterConnectionsDemandGenerated != null) { + data['WaterConnectionsDemandGenerated'] = + this.waterConnectionsDemandGenerated!.map((v) => v.toJson()).toList(); + } + if (this.waterConnectionsDemandNotGenerated != null) { + data['WaterConnectionsDemandNotGenerated'] = this + .waterConnectionsDemandNotGenerated! + .map((v) => v.toJson()) + .toList(); + } + return data; + } +} \ No newline at end of file diff --git a/frontend/mgramseva/lib/providers/bill_generation_details_provider.dart b/frontend/mgramseva/lib/providers/bill_generation_details_provider.dart index c9d5e3216..16dc0647e 100644 --- a/frontend/mgramseva/lib/providers/bill_generation_details_provider.dart +++ b/frontend/mgramseva/lib/providers/bill_generation_details_provider.dart @@ -371,11 +371,11 @@ class BillGenerationProvider with ChangeNotifier { children: [ Text('${ApplicationLocalizations.of(context).translate(i18.demandGenerate.ARE_YOU_SURE_TO_GENERATE_DEMAND_FOR)} "${ApplicationLocalizations.of(context).translate(billGenerateDetails.serviceType!)}" ${ApplicationLocalizations.of(context).translate(i18.demandGenerate.WITH_MINIMUM_CHARGE_OF)} : '), SizedBox(height: 10,), - SingleChildScrollView( - scrollDirection: Axis.horizontal, + FittedBox( child: DataTable( border: TableBorder.all( - width: 0.5, borderRadius: BorderRadius.all(Radius.circular(5))), columns: [ + width: 0.5, borderRadius: BorderRadius.all(Radius.circular(5)), + color: Colors.grey,), columns: [ DataColumn( label: Text( "${ApplicationLocalizations.of(context).translate(i18.searchWaterConnection.CONNECTION_TYPE)}", diff --git a/frontend/mgramseva/lib/providers/reports_provider.dart b/frontend/mgramseva/lib/providers/reports_provider.dart index bbc0480b1..395e5e86f 100644 --- a/frontend/mgramseva/lib/providers/reports_provider.dart +++ b/frontend/mgramseva/lib/providers/reports_provider.dart @@ -9,6 +9,7 @@ import 'package:syncfusion_flutter_xlsio/xlsio.dart'; import '../model/common/BillsTableData.dart'; import '../model/localization/language.dart'; import '../model/mdms/tax_period.dart'; +import '../model/reports/WaterConnectionCount.dart'; import '../model/reports/bill_report_data.dart'; import '../model/reports/collection_report_data.dart'; import '../model/reports/expense_bill_report_data.dart'; @@ -40,6 +41,7 @@ class ReportsProvider with ChangeNotifier { List? inactiveconsumers; List? expenseBillReportData; List? vendorReportData; + WaterConnectionCountResponse? waterConnectionCount; BillsTableData genericTableData = BillsTableData([], []); int limit = 10; int offset = 1; @@ -805,4 +807,28 @@ class ReportsProvider with ChangeNotifier { //Save and launch the file. await saveAndLaunchFile(bytes, '$title.xlsx'); } + Future getWaterConnectionsCount() async { + try { + var commonProvider = Provider.of( + navigatorKey.currentContext!, + listen: false); + Map params = { + 'tenantId': commonProvider.userDetails!.selectedtenant!.code, + }; + var response = await ReportsRepo().fetchWaterConnectionsCount(params); + if (response != null) { + waterConnectionCount = response; + streamController.add(response); + callNotifier(); + } else { + streamController.add('error'); + throw Exception('API Error'); + } + callNotifier(); + } catch (e, s) { + ErrorHandler().allExceptionsHandler(navigatorKey.currentContext!, e, s); + streamController.addError('error'); + callNotifier(); + } + } } diff --git a/frontend/mgramseva/lib/repository/reports_repo.dart b/frontend/mgramseva/lib/repository/reports_repo.dart index 4dc71a920..cc6559857 100644 --- a/frontend/mgramseva/lib/repository/reports_repo.dart +++ b/frontend/mgramseva/lib/repository/reports_repo.dart @@ -5,6 +5,7 @@ import 'package:mgramseva/services/base_service.dart'; import 'package:provider/provider.dart'; import '../model/reports/InactiveConsumerReportData.dart'; +import '../model/reports/WaterConnectionCount.dart'; import '../model/reports/bill_report_data.dart'; import '../model/reports/collection_report_data.dart'; import '../providers/common_provider.dart'; @@ -194,4 +195,36 @@ class ReportsRepo extends BaseService{ } return vendorReports; } + Future fetchWaterConnectionsCount(Map params, + [String? token]) async { + var commonProvider = Provider.of( + navigatorKey.currentContext!, + listen: false); + WaterConnectionCountResponse? waterConnectionResponse = WaterConnectionCountResponse(); + final requestInfo = RequestInfo( + APIConstants.API_MODULE_NAME, + APIConstants.API_VERSION, + APIConstants.API_TS, + '_get', + 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_COUNT, + queryParameters: params, + requestInfo: requestInfo, + body: {}, + method: RequestType.POST); + if (res != null ){ + try { + waterConnectionResponse = WaterConnectionCountResponse.fromJson(res); + } catch (e) { + print(e); + waterConnectionResponse = null; + } + } + return waterConnectionResponse; + } } \ No newline at end of file diff --git a/frontend/mgramseva/lib/screeens/generate_bill/generate_bill.dart b/frontend/mgramseva/lib/screeens/generate_bill/generate_bill.dart index b8260fa2a..c3e31cc22 100644 --- a/frontend/mgramseva/lib/screeens/generate_bill/generate_bill.dart +++ b/frontend/mgramseva/lib/screeens/generate_bill/generate_bill.dart @@ -1,4 +1,6 @@ import 'package:flutter/material.dart'; +import 'package:mgramseva/providers/reports_provider.dart'; +import 'package:mgramseva/screeens/generate_bill/widgets/water_connection_count_widget.dart'; import 'package:mgramseva/widgets/keyboard_focus_watcher.dart'; import 'package:mgramseva/model/bill/bill_generation_details/bill_generation_details.dart'; import 'package:mgramseva/model/connection/water_connection.dart'; @@ -78,6 +80,7 @@ class _GenerateBillState extends State { Provider.of(context, listen: false).clearBillYear(); Navigator.pop(context); },), + WaterConnectionCountWidget(), Container( width: MediaQuery.of(context).size.width, child: Card( 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 new file mode 100644 index 000000000..51587cbfd --- /dev/null +++ b/frontend/mgramseva/lib/screeens/generate_bill/widgets/count_table_widget.dart @@ -0,0 +1,113 @@ +import 'package:flutter/material.dart'; +import 'package:mgramseva/model/reports/WaterConnectionCount.dart'; +import 'package:mgramseva/utils/constants/i18_key_constants.dart'; +import '../../../utils/date_formats.dart'; +import '../../../utils/localization/application_localizations.dart'; + +class CountTableWidget extends StatefulWidget { + final List? waterConnectionCount; + + const CountTableWidget({Key? key, this.waterConnectionCount}) + : super(key: key); + + @override + _CountTableWidgetState createState() => _CountTableWidgetState(); +} + +class _CountTableWidgetState extends State { + bool _isCollapsed = true; + + @override + Widget build(BuildContext context) { + final List? connectionCount = + widget.waterConnectionCount; + + return Container( + child: Column( + children: [ + LayoutBuilder( + builder: (context, constraints) { + if (constraints.maxWidth <= 760) { + return Container( + width: MediaQuery.of(context).size.width, + child: FittedBox( + child: _buildDataTable(connectionCount!), + ), + ); + } else { + return Container( + width: MediaQuery.of(context).size.width, + child: _buildDataTable(connectionCount!)); + } + }, + ), + if (connectionCount!.length > 5) + Align( + alignment: Alignment.bottomRight, + child: TextButton( + onPressed: () { + setState(() { + _isCollapsed = !_isCollapsed; + }); + }, + child: Text(_isCollapsed + ? "${ApplicationLocalizations.of(context).translate(i18.common.VIEW_ALL)}" + : "${ApplicationLocalizations.of(context).translate(i18.common.COLLAPSE)}"), + ), + ), + ], + ), + ); + } + + Widget _buildDataTable(List connectionCount) { + return DataTable( + border: TableBorder.all( + width: 0.5, + 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 + columns: [ + DataColumn( + label: FittedBox( + child: Text( + "${ApplicationLocalizations.of(context).translate(i18.common.LAST_BILL_CYCLE_MONTH)}", + ), + ), + ), + DataColumn( + label: FittedBox( + child: Text( + "${ApplicationLocalizations.of(context).translate(i18.common.CONSUMER_COUNT)}", + ), + ), + ) + ], + rows: _isCollapsed + ? connectionCount.take(5).map((e) => _buildDataRow(e)).toList() + : connectionCount.map((e) => _buildDataRow(e)).toList(), + ); + } + + 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 + + return DataRow( + color: MaterialStateColor.resolveWith((states) => rowColor!), // Apply alternate row background color + cells: [ + DataCell( + Text( + DateFormats.getMonthAndYearFromDateTime( + DateTime.fromMillisecondsSinceEpoch(count.taxperiodto!), + ), + ), + ), + DataCell( + Text(count.count.toString()), + ), + ], + ); + } +} 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 new file mode 100644 index 000000000..feb66b3a0 --- /dev/null +++ b/frontend/mgramseva/lib/screeens/generate_bill/widgets/water_connection_count_widget.dart @@ -0,0 +1,154 @@ +import 'package:flutter/material.dart'; +import 'package:mgramseva/model/reports/WaterConnectionCount.dart'; +import 'package:mgramseva/providers/reports_provider.dart'; +import 'package:mgramseva/utils/constants/i18_key_constants.dart'; +import 'package:provider/provider.dart'; + +import '../../../utils/localization/application_localizations.dart'; +import '../../../widgets/label_text.dart'; +import 'count_table_widget.dart'; + +class WaterConnectionCountWidget extends StatefulWidget { + @override + _WaterConnectionCountWidgetState createState() => + _WaterConnectionCountWidgetState(); +} + +class _WaterConnectionCountWidgetState + extends State { + @override + void initState() { + WidgetsBinding.instance.addPostFrameCallback((_) => afterViewBuild()); + super.initState(); + } + + afterViewBuild() { + Provider.of(context, listen: false) + ..getWaterConnectionsCount(); + } + + @override + Widget build(BuildContext context) { + return Container( + width: MediaQuery.of(context).size.width, + child: Card( + child: Padding( + padding: const EdgeInsets.only(bottom: 20.0), + child: Container( + child: Column( + children: [ + LabelText( + '${"${ApplicationLocalizations.of(context).translate(i18.common.WS_REPORTS_WATER_CONNECTION_COUNT)}"}'), + Container( + margin: MediaQuery.of(context).size.width > 760 + ? EdgeInsets.only( + top: 5.0, bottom: 5, right: 20, left: 20) + : EdgeInsets.only(top: 5.0, bottom: 5, right: 8, left: 8), + child: LayoutBuilder( + builder: (context, constraints) { + final provider = Provider.of(context); + final waterConnectionCount = + provider.waterConnectionCount; + if (waterConnectionCount == null) { + return SizedBox(); + } + return Column( + children: [ + if (waterConnectionCount.waterConnectionsDemandGenerated != + null && + waterConnectionCount + .waterConnectionsDemandGenerated + ?.length != + 0 && + constraints.maxWidth > 760) + _buildDataTableRow( + context, + "${ApplicationLocalizations.of(context).translate(i18.common.LAST_BILL_CYCLE_DEMAND_GENERATED)}", + waterConnectionCount + .waterConnectionsDemandGenerated, + ), + if (waterConnectionCount.waterConnectionsDemandGenerated != + null && + waterConnectionCount + .waterConnectionsDemandGenerated + ?.length != + 0 && + constraints.maxWidth <= 760) + _buildDataTableColumn( + context, + "${ApplicationLocalizations.of(context).translate(i18.common.LAST_BILL_CYCLE_DEMAND_GENERATED)}", + waterConnectionCount + .waterConnectionsDemandGenerated, + ), + SizedBox(height: 20), + if (waterConnectionCount.waterConnectionsDemandNotGenerated != + null && + waterConnectionCount + .waterConnectionsDemandNotGenerated + ?.length != + 0 && + constraints.maxWidth > 760) + _buildDataTableRow( + context, + "${ApplicationLocalizations.of(context).translate(i18.common.LAST_BILL_CYCLE_DEMAND_NOT_GENERATED)}", + waterConnectionCount + .waterConnectionsDemandNotGenerated, + ), + if (waterConnectionCount.waterConnectionsDemandNotGenerated != + null && + waterConnectionCount + .waterConnectionsDemandNotGenerated + ?.length != + 0 && + constraints.maxWidth <= 760) + _buildDataTableColumn( + context, + "${ApplicationLocalizations.of(context).translate(i18.common.LAST_BILL_CYCLE_DEMAND_NOT_GENERATED)}", + waterConnectionCount + .waterConnectionsDemandNotGenerated, + ), + ], + ); + }, + ), + ), + ], + ), + ), + ), + ), + ); + } + + Widget _buildDataTableRow(BuildContext context, String title, + List? waterConnections) { + 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), + ), + Container( + width: MediaQuery.of(context).size.width / 2.5, + padding: EdgeInsets.only(top: 18, bottom: 3), + child: CountTableWidget(waterConnectionCount: waterConnections), + ), + ], + ); + } + + Widget _buildDataTableColumn(BuildContext context, String title, + List? waterConnections) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(title), + SizedBox(height: 10), + CountTableWidget(waterConnectionCount: waterConnections), + ], + ); + } +} diff --git a/frontend/mgramseva/lib/services/urls.dart b/frontend/mgramseva/lib/services/urls.dart index d99b7ae45..7a467755b 100644 --- a/frontend/mgramseva/lib/services/urls.dart +++ b/frontend/mgramseva/lib/services/urls.dart @@ -96,6 +96,8 @@ class Url { 'ws-services/wc/_inactiveConsumerReport'; static const String EXPENSE_BILL_REPORT= 'echallan-services/eChallan/v1/_expenseBillReport'; + static const String WATER_CONNECTION_COUNT= + 'ws-services/wc/_countWCbyDemandGenerationDate'; } diff --git a/frontend/mgramseva/lib/utils/constants/i18_key_constants.dart b/frontend/mgramseva/lib/utils/constants/i18_key_constants.dart index 1b1573ec4..1a6634757 100644 --- a/frontend/mgramseva/lib/utils/constants/i18_key_constants.dart +++ b/frontend/mgramseva/lib/utils/constants/i18_key_constants.dart @@ -38,6 +38,12 @@ class Login { class Common { const Common(); String get CONTINUE => 'CORE_COMMON_CONTINUE'; + String get LAST_BILL_CYCLE_MONTH => 'LAST_BILL_CYCLE_MONTH'; + String get CONSUMER_COUNT => 'CONSUMER_COUNT'; + String get LAST_BILL_CYCLE_DEMAND_NOT_GENERATED => 'LAST_BILL_CYCLE_DEMAND_NOT_GENERATED'; + String get LAST_BILL_CYCLE_DEMAND_GENERATED => 'LAST_BILL_CYCLE_DEMAND_GENERATED'; + String get WS_REPORTS_WATER_CONNECTION_COUNT => 'WS_REPORTS_WATER_CONNECTION_COUNT'; + String get COLLAPSE => 'COLLAPSE'; String get NAME => 'CORE_COMMON_NAME'; String get CONTINUE_TO_LOGIN => 'CONTINUE_TO_LOGIN'; String get PHONE_NUMBER => 'CORE_COMMON_PHONE_NUMBER'; diff --git a/frontend/mgramseva/lib/utils/date_formats.dart b/frontend/mgramseva/lib/utils/date_formats.dart index 7007c13b1..ef1844984 100644 --- a/frontend/mgramseva/lib/utils/date_formats.dart +++ b/frontend/mgramseva/lib/utils/date_formats.dart @@ -119,7 +119,7 @@ class DateFormats { static String getMonthAndYearFromDateTime(DateTime date) { try { - return '${DateFormat.MMM().format(date)}-${DateFormat.y().format(date)}'; + return '${ApplicationLocalizations.of(navigatorKey.currentContext!).translate(Constants.MONTHS[date.month-1])}-${DateFormat.y().format(date)}'; } catch (e) { return ''; } diff --git a/frontend/mgramseva/lib/widgets/select_field_builder.dart b/frontend/mgramseva/lib/widgets/select_field_builder.dart index 2945df97c..d7b74773d 100644 --- a/frontend/mgramseva/lib/widgets/select_field_builder.dart +++ b/frontend/mgramseva/lib/widgets/select_field_builder.dart @@ -124,6 +124,11 @@ class SelectFieldBuilderState extends State { items: widget.options, onChanged: widget.widget, enabled: !widget.readOnly!, + dropdownDecoratorProps: DropDownDecoratorProps( + baseStyle: TextStyle( + color: !widget.readOnly!?Theme.of(context).primaryColorDark:Colors.grey + ) + ), popupProps: PopupProps.menu( showSearchBox: widget.showSearchBox, fit: FlexFit.loose, diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/WaterDaoImpl.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/WaterDaoImpl.java index 9fbfdfd01..c95a6aa18 100644 --- a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/WaterDaoImpl.java +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/WaterDaoImpl.java @@ -2,7 +2,6 @@ import java.math.BigDecimal; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -12,7 +11,6 @@ import javax.validation.Valid; -import org.apache.commons.lang3.StringUtils; import org.egov.common.contract.request.RequestInfo; import org.egov.common.contract.request.Role; import org.egov.common.contract.request.User; @@ -67,6 +65,9 @@ public class WaterDaoImpl implements WaterDao { @Autowired private OpenWaterRowMapper openWaterRowMapper; + + @Autowired + private WcbyDemandRowMapper wcbyDemandRowMapper; @Autowired private ReportRowMapper reportRowMapper; @@ -159,7 +160,26 @@ public void updateWaterConnection(WaterConnectionRequest waterConnectionRequest, waterConnectionProducer.push(wsConfiguration.getWorkFlowUpdateTopic(), waterConnectionRequest); } } - + public WaterConnectionByDemandGenerationDateResponse getWaterConnectionByDemandDate (SearchCriteria criteria, RequestInfo requestInfo) { + + List waterConnectionByPreviousReadingDateList = new ArrayList<>(); + List waterConnectionByDemandGenerationDateList = new ArrayList<>(); + WaterConnectionByDemandGenerationDateResponse response = new WaterConnectionByDemandGenerationDateResponse(); + List preparedStatement = new ArrayList<>(); + String query1 = wsQueryBuilder.getQueryForWCCountForPreviousreadingdate(criteria, preparedStatement, requestInfo); + if (query1 == null) + return null; + waterConnectionByPreviousReadingDateList = jdbcTemplate.query(query1, preparedStatement.toArray(), wcbyDemandRowMapper); + String query2 = wsQueryBuilder.getQueryForWCCountbyDemandDate(criteria, preparedStatement, requestInfo); + + if (query2 == null) + return null; + waterConnectionByDemandGenerationDateList = jdbcTemplate.query(query2, preparedStatement.toArray(), wcbyDemandRowMapper); + response.setWaterConnectionByDemandGenerationDates(waterConnectionByDemandGenerationDateList); + response.setWaterConnectionByDemandNotGeneratedDates(waterConnectionByPreviousReadingDateList); + return response; + } + /** * push object to create meter reading * diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/builder/WsQueryBuilder.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/builder/WsQueryBuilder.java index 90915b808..df462936f 100644 --- a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/builder/WsQueryBuilder.java +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/builder/WsQueryBuilder.java @@ -66,6 +66,12 @@ public class WsQueryBuilder { + "eg_ws_connectionholder connectionholder ON connectionholder.connectionid = conn.id" + LEFT_OUTER_JOIN_STRING + "eg_ws_roadcuttinginfo roadcuttingInfo ON roadcuttingInfo.wsid = conn.id"; + private static final String WATER_CONNNECTION_BY_DEMANNDDATE = "SELECT ((select distinct d.taxperiodto as taxperiodto from egbs_demand_v1 d where d.status = 'ACTIVE' and d.businessservice = 'WS' and d.consumercode = conn.connectionno order by d.taxperiodto desc limit 1)) as taxperiodto, count(*) as count" + + " FROM eg_ws_connection conn INNER JOIN eg_ws_service wc ON wc.connection_id = conn.id and wc.connectiontype='Non_Metered'and conn.status='Active'"; + + private static final String WATER_CONNECTION_BY_PREVIOUSREADINNDATE = "select previousreadingdate as taxperiodto , count(*) as count from eg_ws_connection conn"; + + private static final String CONSUMERCODE_IN_DEMANDTABLE= "select consumercode from egbs_demand_v1 d"; private static final String PAGINATION_WRAPPER = "{} {orderby} {pagination}"; private static final String ORDER_BY_CLAUSE = " ORDER BY wc.appCreatedDate DESC"; @@ -704,4 +710,24 @@ private String addOrderByClauseForPlaneSearch(SearchCriteria criteria) { return builder.toString(); } + public String getQueryForWCCountbyDemandDate(SearchCriteria criteria, List preparedStatement, + RequestInfo requestInfo) { + if (criteria.isEmpty() || criteria.getTenantId().isEmpty()) + return null; + StringBuilder query = new StringBuilder(WATER_CONNNECTION_BY_DEMANNDDATE); + applyFiltersForPlaneSearch(query,preparedStatement,criteria); + query.append(" GROUP BY taxperiodto "); + return query.toString(); + } + + public String getQueryForWCCountForPreviousreadingdate(SearchCriteria criteria, List preparedStatement, + RequestInfo requestInfo) { + if (criteria.isEmpty() || criteria.getTenantId().isEmpty()) + return null; + StringBuilder query = new StringBuilder(WATER_CONNECTION_BY_PREVIOUSREADINNDATE); + query.append(" INNER JOIN eg_ws_service wc ON wc.connection_id = conn.id WHERE conn.status='Active' AND conn.tenantid='"+criteria.getTenantId()+"' and wc.connectiontype='Non_Metered' and connectionno NOT IN (" + CONSUMERCODE_IN_DEMANDTABLE+" where d.status ='ACTIVE' and d.businessservice='WS' and d.tenantid='"+criteria.getTenantId()+"') "); + query.append(" GROUP BY taxperiodto "); + return query.toString(); + } + } diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/rowmapper/WcbyDemandRowMapper.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/rowmapper/WcbyDemandRowMapper.java new file mode 100644 index 000000000..c45544f94 --- /dev/null +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/rowmapper/WcbyDemandRowMapper.java @@ -0,0 +1,32 @@ +package org.egov.waterconnection.repository.rowmapper; + +import lombok.extern.slf4j.Slf4j; +import org.egov.waterconnection.web.models.WaterConnectionByDemandGenerationDate; +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.ResultSetExtractor; +import org.springframework.stereotype.Component; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +@Component +@Slf4j +public class WcbyDemandRowMapper implements ResultSetExtractor> { + + @Override + public List extractData(ResultSet rs) throws SQLException, DataAccessException { + List waterDemandGenerationDateResponseList = new ArrayList(); + while (rs.next()) { + String taxperiodto = String.valueOf(rs.getLong("taxperiodto")); + if (!taxperiodto.isEmpty() && !taxperiodto.equalsIgnoreCase("0")) { + WaterConnectionByDemandGenerationDate waterDemandGenerationDateResponse = new WaterConnectionByDemandGenerationDate(); + waterDemandGenerationDateResponse.setDate(Long.valueOf(taxperiodto)); + waterDemandGenerationDateResponse.setCount(Integer.valueOf(rs.getInt("count"))); + waterDemandGenerationDateResponseList.add(waterDemandGenerationDateResponse); + } + + } + return waterDemandGenerationDateResponseList; + } +} diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/WaterService.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/WaterService.java index ac3d91a67..0c72cd1f8 100644 --- a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/WaterService.java +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/WaterService.java @@ -7,9 +7,7 @@ import org.egov.common.contract.request.RequestInfo; import org.egov.waterconnection.web.models.*; import org.egov.waterconnection.web.models.BillReportData; -import org.egov.waterconnection.web.models.BillReportResponse; import org.egov.waterconnection.web.models.CollectionReportData; -import org.egov.waterconnection.web.models.Feedback; import org.egov.waterconnection.web.models.FeedbackRequest; import org.egov.waterconnection.web.models.FeedbackSearchCriteria; @@ -30,7 +28,8 @@ public interface WaterService { List createWaterConnection(WaterConnectionRequest waterConnectionRequest); WaterConnectionResponse search(SearchCriteria criteria, RequestInfo requestInfo); - + + WaterConnectionByDemandGenerationDateResponse countWCbyDemandGennerationDate(SearchCriteria criteria, RequestInfo requestInfo); List updateWaterConnection(WaterConnectionRequest waterConnectionRequest); void submitFeedback( FeedbackRequest feedbackrequest); diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/WaterServiceImpl.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/WaterServiceImpl.java index 2782ef0f1..704683d4b 100644 --- a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/WaterServiceImpl.java +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/WaterServiceImpl.java @@ -201,6 +201,10 @@ public WaterConnectionResponse search(SearchCriteria criteria, RequestInfo reque return waterConnection; } + public WaterConnectionByDemandGenerationDateResponse countWCbyDemandGennerationDate(SearchCriteria criteria, RequestInfo requestInfo) { + return getWCbyDemandGennerationDate(criteria, requestInfo); + } + /** * * @param criteria WaterConnectionSearchCriteria contains search criteria on @@ -211,6 +215,9 @@ public WaterConnectionResponse search(SearchCriteria criteria, RequestInfo reque public WaterConnectionResponse getWaterConnectionsList(SearchCriteria criteria, RequestInfo requestInfo) { return waterDaoImpl.getWaterConnectionList(criteria, requestInfo); } + public WaterConnectionByDemandGenerationDateResponse getWCbyDemandGennerationDate(SearchCriteria criteria, RequestInfo requestInfo) { + return waterDaoImpl.getWaterConnectionByDemandDate(criteria, requestInfo); + } /** * diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/controller/WaterController.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/controller/WaterController.java index 5a9e6be54..cd462ba50 100644 --- a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/controller/WaterController.java +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/controller/WaterController.java @@ -41,7 +41,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; -import io.swagger.models.parameters.QueryParameter; import lombok.Builder; import lombok.Getter; import lombok.Setter; @@ -230,4 +229,10 @@ public ResponseEntity inactiveConsumerReport(@Va return new ResponseEntity<>(response,HttpStatus.OK); } + @RequestMapping(value = "/_countWCbyDemandGenerationDate", method = RequestMethod.POST) + public ResponseEntity countWCbyDemandGenerationDate(@Valid @RequestBody RequestInfoWrapper requestInfoWrapper, @Valid @ModelAttribute SearchCriteria criteria) { + WaterConnectionByDemandGenerationDateResponse response = waterService.countWCbyDemandGennerationDate(criteria, requestInfoWrapper.getRequestInfo()); + return new ResponseEntity<>(response, HttpStatus.OK); + } + } diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/WaterConnectionByDemandGenerationDate.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/WaterConnectionByDemandGenerationDate.java new file mode 100644 index 000000000..d54b10281 --- /dev/null +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/WaterConnectionByDemandGenerationDate.java @@ -0,0 +1,16 @@ +package org.egov.waterconnection.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Setter +@Builder +public class WaterConnectionByDemandGenerationDate { + @JsonProperty("count") + Integer count; + @JsonProperty("taxperiodto") + private Long date; +} diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/WaterConnectionByDemandGenerationDateResponse.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/WaterConnectionByDemandGenerationDateResponse.java new file mode 100644 index 000000000..9f661f603 --- /dev/null +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/WaterConnectionByDemandGenerationDateResponse.java @@ -0,0 +1,18 @@ +package org.egov.waterconnection.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; + +import java.util.List; +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Setter +@Builder +public class WaterConnectionByDemandGenerationDateResponse { + + @JsonProperty("WaterConnectionsDemandGenerated") + List waterConnectionByDemandGenerationDates; + @JsonProperty("WaterConnectionsDemandNotGenerated") + List waterConnectionByDemandNotGeneratedDates; +}