Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #605 from egovernments/PFM-4087-frontend
Browse files Browse the repository at this point in the history
Pfm 4087 frontend
  • Loading branch information
rahuldevgarg authored Oct 10, 2023
2 parents 3275bd8 + 8d29289 commit 18ae373
Show file tree
Hide file tree
Showing 8 changed files with 281 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class InactiveConsumerReportData {
String? tenantName;
String? connectionNo;
String? status;
num? inactiveDate;
String? inactivatedByUuid;
String? inactivatedByName;

InactiveConsumerReportData(this.tenantName, this.connectionNo, this.status,
this.inactiveDate, this.inactivatedByUuid, this.inactivatedByName);

InactiveConsumerReportData.fromJson(Map<String, dynamic> json) {
tenantName = json['tenantName'];
connectionNo = json['connectionno'];
status = json['status'];
inactiveDate = json['inactiveDate'];
inactivatedByUuid = json['inactivatedByUuid'];
inactivatedByName = json['inactivatedByName'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['tenantName'] = this.tenantName;
data['connectionno'] = this.connectionNo;
data['status'] = this.status;
data['inactiveDate'] = this.inactiveDate;
data['inactivatedByUuid'] = this.inactivatedByUuid;
data['inactivatedByName'] = this.inactivatedByName;
return data;
}
}
100 changes: 100 additions & 0 deletions frontend/mgramseva/lib/providers/reports_provider.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:mgramseva/model/reports/InactiveConsumerReportData.dart';
import 'package:mgramseva/utils/common_widgets.dart';
import 'package:provider/provider.dart';
import 'package:syncfusion_flutter_xlsio/xlsio.dart';
Expand Down Expand Up @@ -35,6 +36,7 @@ class ReportsProvider with ChangeNotifier {
var billingcycleCtrl = TextEditingController();
List<BillReportData>? demandreports;
List<CollectionReportData>? collectionreports;
List<InactiveConsumerReportData>? inactiveconsumers;
BillsTableData genericTableData = BillsTableData([], []);
int limit = 10;
int offset = 1;
Expand Down Expand Up @@ -81,6 +83,13 @@ class ReportsProvider with ChangeNotifier {
TableHeader(i18.common.PAYMENT_METHOD),
TableHeader(i18.billDetails.TOTAL_AMOUNT),
];
List<TableHeader> get inactiveConsumerHeaderList => [
TableHeader(i18.common.CONNECTION_ID),
TableHeader(i18.common.STATUS),
TableHeader(i18.common.INACTIVATED_DATE),
TableHeader(i18.common.INACTIVATED_BY_NAME),
TableHeader(i18.common.INACTIVATED_BY_UUID),
];

void onChangeOfPageLimit(
PaginationResponse response, String type, BuildContext context) {
Expand All @@ -90,6 +99,9 @@ class ReportsProvider with ChangeNotifier {
if (type == i18.dashboard.COLLECTION_REPORT) {
getCollectionReport(limit: response.limit, offset: response.offset);
}
if (type == i18.dashboard.INACTIVE_CONSUMER_REPORT) {
getInactiveConsumerReport(limit: response.limit, offset: response.offset);
}
}

List<TableDataRow> getDemandsData(List<BillReportData> list,
Expand Down Expand Up @@ -139,7 +151,30 @@ class ReportsProvider with ChangeNotifier {
TableData('${data.paymentAmount ?? '0'}'),
]);
}
List<TableDataRow> getInactiveConsumersData(List<InactiveConsumerReportData> list,
{bool isExcel = false}) {
return list.map((e) => getInactiveConsumersDataRow(e, isExcel: isExcel)).toList();
}

TableDataRow getInactiveConsumersDataRow(InactiveConsumerReportData data,
{bool isExcel = false}) {
String? inactivatedBy = CommonMethods.truncateWithEllipsis(20, data.inactivatedByName!);
if (data.connectionNo != null && data.connectionNo!.isEmpty) {
data.connectionNo = '-';
}
var inactivatedDate = DateFormats.timeStampToDate(data.inactiveDate?.toInt(),format: "dd/MM/yyyy");
return TableDataRow([
TableData(
isExcel
? '${data.connectionNo ?? '-'}'
: '${data.connectionNo?.split('/').first ?? ''}/...${data.connectionNo?.split('/').last ?? ''}',
),
TableData('${data.status??'-'}'),
TableData('${inactivatedDate ?? '-'}'),
TableData('${inactivatedBy ?? '-'}'),
TableData('${data.inactivatedByUuid ?? ''}'),
]);
}
void callNotifier() {
notifyListeners();
}
Expand Down Expand Up @@ -378,6 +413,71 @@ class ReportsProvider with ChangeNotifier {
}
}

Future<void> getInactiveConsumerReport(
{bool download = false,
int offset = 1,
int limit = 10,
String sortOrder = "ASC"}) async {
try {
var commonProvider = Provider.of<CommonProvider>(
navigatorKey.currentContext!,
listen: false);
if (selectedBillPeriod == null) {
throw Exception('Select Billing Cycle');
}
Map<String, dynamic> params = {
'tenantId': commonProvider.userDetails!.selectedtenant!.code,
'monthStartDate': selectedBillPeriod?.split('-')[0],
'monthEndDate': selectedBillPeriod?.split('-')[1],
'offset': '${offset - 1}',
'limit': '${download ? -1 : limit}',
'sortOrder': '$sortOrder'
};
var response = await ReportsRepo().fetchInactiveConsumerReport(params);
if (response != null) {
inactiveconsumers = response;
if (download) {
generateExcel(
inactiveConsumerHeaderList
.map<String>((e) =>
'${ApplicationLocalizations.of(navigatorKey.currentContext!).translate(e.label)}')
.toList(),
getInactiveConsumersData(inactiveconsumers!, isExcel: true)
.map<List<String>>(
(e) => e.tableRow.map((e) => e.label).toList())
.toList() ??
[],
title:
'InactiveConsumers_${commonProvider.userDetails?.selectedtenant?.code?.substring(3)}_${selectedBillPeriod.toString().replaceAll('/', '_')}',
optionalData: [
'Collection Report',
'$selectedBillPeriod',
'${ApplicationLocalizations.of(navigatorKey.currentContext!).translate(commonProvider.userDetails!.selectedtenant!.code!)} ${commonProvider.userDetails?.selectedtenant?.code?.substring(3)}',
'Downloaded On ${DateFormats.timeStampToDate(DateTime.now().millisecondsSinceEpoch, format: 'dd/MMM/yyyy')}'
]);
} else {
if (inactiveconsumers != null && inactiveconsumers!.isNotEmpty) {
this.limit = limit;
this.offset = offset;
this.genericTableData = BillsTableData(
inactiveConsumerHeaderList, getInactiveConsumersData(inactiveconsumers!));
}
}
streamController.add(response);
callNotifier();
} else {
streamController.add('error');
throw Exception('API Error');
}
callNotifier();
} catch (e, s) {
inactiveconsumers = [];
ErrorHandler().allExceptionsHandler(navigatorKey.currentContext!, e, s);
streamController.addError('error');
callNotifier();
}
}

void clearBuildTableData() {
genericTableData = BillsTableData([], []);
callNotifier();
Expand Down
38 changes: 38 additions & 0 deletions frontend/mgramseva/lib/repository/reports_repo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:mgramseva/services/urls.dart';
import 'package:mgramseva/services/base_service.dart';
import 'package:provider/provider.dart';

import '../model/reports/InactiveConsumerReportData.dart';
import '../model/reports/bill_report_data.dart';
import '../model/reports/collection_report_data.dart';
import '../providers/common_provider.dart';
Expand Down Expand Up @@ -83,4 +84,41 @@ class ReportsRepo extends BaseService{
}
return billreports;
}

Future<List<InactiveConsumerReportData>?> fetchInactiveConsumerReport(Map<String,dynamic> params,
[String? token]) async {
var commonProvider = Provider.of<CommonProvider>(
navigatorKey.currentContext!,
listen: false);
List<InactiveConsumerReportData>? inactiveConsumers;
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.INACTIVE_CONSUMER_REPORT,
queryParameters: params,
requestInfo: requestInfo,
body: {},
method: RequestType.POST);
if (res != null && res['InactiveConsumerReportData'] != null) {
try {
inactiveConsumers = [];
res['InactiveConsumerReportData'].forEach((val){
inactiveConsumers?.add(InactiveConsumerReportData.fromJson(val));
});
} catch (e) {
print(e);
inactiveConsumers = null;
}
}
return inactiveConsumers;
}
}
103 changes: 103 additions & 0 deletions frontend/mgramseva/lib/screeens/reports/inactive_consumer_report.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import 'package:flutter/material.dart';
import 'package:mgramseva/model/common/BillsTableData.dart';
import 'package:provider/provider.dart';

import '../../providers/reports_provider.dart';
import '../../utils/localization/application_localizations.dart';

import 'package:mgramseva/utils/constants/i18_key_constants.dart';

import '../../utils/notifiers.dart';
import '../../utils/testing_keys/testing_keys.dart';
import '../../widgets/button.dart';
import 'generic_report_table.dart';

class InactiveConsumerReport extends StatefulWidget {
final Function onViewClick;

InactiveConsumerReport({Key? key, required this.onViewClick}) : super(key: key);

@override
State<StatefulWidget> createState() {
return _CollectionReport();
}
}

class _CollectionReport extends State<InactiveConsumerReport>
with SingleTickerProviderStateMixin {
@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, constraints) {
return Consumer<ReportsProvider>(builder: (_, reportProvider, child) {
return Container(
margin: constraints.maxWidth > 700
? const EdgeInsets.only(top: 5.0, bottom: 5, right: 20, left: 10)
: const EdgeInsets.only(top: 5.0, bottom: 5, right: 8, left: 8),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(
height: 30,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Text("3. ",
style: TextStyle(
fontSize: 16, fontWeight: FontWeight.w700)),
Text(
ApplicationLocalizations.of(context)
.translate(i18.dashboard.INACTIVE_CONSUMER_REPORT),
style: TextStyle(
fontSize: 16, fontWeight: FontWeight.w700)),
],
),
Row(
children: [
Container(
width: 50,
child: Button(
"View",
() {
if (reportProvider.selectedBillPeriod == null) {
Notifiers.getToastMessage(
context, 'Select Billing Cycle', 'ERROR');
} else {
reportProvider.clearTableData();
reportProvider.getInactiveConsumerReport();
widget.onViewClick(
true, i18.dashboard.INACTIVE_CONSUMER_REPORT);
}
},
key: Keys.billReport.INACTIVE_CONSUMER_REPORT_VIEW_BUTTON,
),
),
SizedBox(
width: 10,
),
TextButton.icon(
onPressed: () {
if (reportProvider.selectedBillPeriod == null) {
Notifiers.getToastMessage(
context, 'Select Billing Cycle', 'ERROR');
} else {
reportProvider.getInactiveConsumerReport(
download: true);
}
},
icon: Icon(Icons.download_sharp),
label: Text(ApplicationLocalizations.of(context)
.translate(i18.common.CORE_DOWNLOAD))),
],
),
],
),
],
),
);
});
});
}
}
2 changes: 2 additions & 0 deletions frontend/mgramseva/lib/screeens/reports/reports.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:mgramseva/screeens/reports/inactive_consumer_report.dart';
import 'package:mgramseva/screeens/reports/view_table.dart';
import 'package:provider/provider.dart';

Expand Down Expand Up @@ -212,6 +213,7 @@ class _Reports extends State<Reports> with SingleTickerProviderStateMixin {
children: [
BillReport(onViewClick: showTable),
CollectionReport(onViewClick: showTable),
InactiveConsumerReport(onViewClick: showTable,)
],
),
),
Expand Down
2 changes: 2 additions & 0 deletions frontend/mgramseva/lib/services/urls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class Url {
'ws-services/wc/_billReport';
static const String COLLECTION_REPORT=
'ws-services/wc/_collectionReport';
static const String INACTIVE_CONSUMER_REPORT=
'ws-services/wc/_inactiveConsumerReport';
}


Expand Down
4 changes: 4 additions & 0 deletions frontend/mgramseva/lib/utils/constants/i18_key_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ class Common {
String get RATE_PERCENTAGE => 'RATE_PERCENTAGE';

String get REGION_NAME => 'REGION_NAME';
String get INACTIVATED_BY_NAME => 'INACTIVATED_BY_NAME';
String get INACTIVATED_DATE => 'INACTIVATED_DATE';
String get INACTIVATED_BY_UUID => 'INACTIVATED_BY_UUID';
}

class Password {
Expand Down Expand Up @@ -671,6 +674,7 @@ class _DashBoard {
String get CORE_REPORTS => 'CORE_REPORTS';
String get BILL_REPORT => 'BILL_REPORT';
String get COLLECTION_REPORT => 'COLLECTION_REPORT';
String get INACTIVE_CONSUMER_REPORT => 'INACTIVE_CONSUMER_REPORT';
String get GPWSC_RATE_INFO => 'GPWSC_RATE_INFO';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class BillReportKeys {
Key get BILL_REPORT_VIEW_BUTTON => Key("bill_report_view_button");
Key get BILL_REPORT_DOWNLOAD_BUTTON => Key("bill_report_download_button");
Key get COLLECTION_REPORT_VIEW_BUTTON => Key("collection_report_view_button");
Key get INACTIVE_CONSUMER_REPORT_VIEW_BUTTON => Key("inactive_consumer_report_view_button");
Key get COLLECTION_REPORT_DOWNLOAD_BUTTON => Key("collection_report_download_button");
Key get BILL_REPORT_BILLING_YEAR => Key("bill_report_billing_year");
Key get BILL_REPORT_BILLING_CYCLE => Key("bill_report_billing_cycle");
Expand Down

0 comments on commit 18ae373

Please sign in to comment.