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

Commit

Permalink
PFM-4085
Browse files Browse the repository at this point in the history
  • Loading branch information
rahuldevgarg committed Jan 12, 2024
1 parent 960bcff commit a7676c9
Show file tree
Hide file tree
Showing 8 changed files with 286 additions and 1 deletion.
36 changes: 36 additions & 0 deletions frontend/mgramseva/lib/model/reports/vendor_report_data.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class VendorReportData {
String? tenantId;
String? vendorName;
String? mobileNo;
String? typeOfExpense;
String? billId;
String? ownerUuid;

VendorReportData(
{this.tenantId,
this.vendorName,
this.mobileNo,
this.typeOfExpense,
this.billId,
this.ownerUuid});

VendorReportData.fromJson(Map<String, dynamic> json) {
tenantId = json['tenantId'];
vendorName = json['vendor_name'];
mobileNo = json['mobile_no'];
typeOfExpense = json['type_of_expense'];
billId = json['bill_id'];
ownerUuid = json['owner_uuid'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['tenantId'] = this.tenantId;
data['vendor_name'] = this.vendorName;
data['mobile_no'] = this.mobileNo;
data['type_of_expense'] = this.typeOfExpense;
data['bill_id'] = this.billId;
data['owner_uuid'] = this.ownerUuid;
return data;
}
}
96 changes: 96 additions & 0 deletions frontend/mgramseva/lib/providers/reports_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';

import 'package:flutter/material.dart';
import 'package:mgramseva/model/reports/InactiveConsumerReportData.dart';
import 'package:mgramseva/model/reports/vendor_report_data.dart';
import 'package:provider/provider.dart';
import 'package:syncfusion_flutter_xlsio/xlsio.dart';

Expand Down Expand Up @@ -38,6 +39,7 @@ class ReportsProvider with ChangeNotifier {
List<CollectionReportData>? collectionreports;
List<InactiveConsumerReportData>? inactiveconsumers;
List<ExpenseBillReportData>? expenseBillReportData;
List<VendorReportData>? vendorReportData;
BillsTableData genericTableData = BillsTableData([], []);
int limit = 10;
int offset = 1;
Expand Down Expand Up @@ -104,6 +106,14 @@ class ReportsProvider with ChangeNotifier {
TableHeader(i18.expense.CANCELLED_BY),

];

List<TableHeader> get vendorReportHeaderList => [
TableHeader(i18.expense.VENDOR_NAME),
TableHeader(i18.common.MOBILE_NUMBER),
TableHeader(i18.expense.EXPENSE_TYPE),
TableHeader(i18.common.BILL_ID),
];

void onChangeOfPageLimit(
PaginationResponse response, String type, BuildContext context) {
if (type == i18.dashboard.BILL_REPORT) {
Expand All @@ -118,6 +128,9 @@ class ReportsProvider with ChangeNotifier {
if (type == i18.dashboard.EXPENSE_BILL_REPORT) {
getExpenseBillReport(limit: response.limit, offset: response.offset);
}
if (type == i18.dashboard.VENDOR_REPORT) {
getVendorReport(limit: response.limit, offset: response.offset);
}
}

List<TableDataRow> getDemandsData(List<BillReportData> list,
Expand Down Expand Up @@ -220,6 +233,23 @@ class ReportsProvider with ChangeNotifier {
TableData('${lastModifiedBy ?? '-'}'),
]);
}
List<TableDataRow> getVendorReportData(List<VendorReportData> list,
{bool isExcel = false}) {
return list.map((e) => getVendorReportDataRow(e, isExcel: isExcel)).toList();
}
TableDataRow getVendorReportDataRow(VendorReportData data,
{bool isExcel = false}) {
String? vendorName = CommonMethods.truncateWithEllipsis(20, data.vendorName!);
String? typeOfExpense = CommonMethods.truncateWithEllipsis(20, data.typeOfExpense!);
String? billId = CommonMethods.truncateWithEllipsis(20, data.billId!);
return TableDataRow([
TableData('${vendorName ?? '-'}'),
TableData('${data.mobileNo ?? '-'}'),
TableData('${ApplicationLocalizations.of(navigatorKey.currentContext!).translate(typeOfExpense ?? '-')}'),
TableData('${billId ?? '-'}'),
]);
}

void callNotifier() {
notifyListeners();
}
Expand Down Expand Up @@ -636,6 +666,72 @@ class ReportsProvider with ChangeNotifier {
callNotifier();
}
}

Future<void> getVendorReport(
{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().fetchVendorReport(params);
if (response != null) {
vendorReportData = response;
if (download) {
generateExcel(
vendorReportHeaderList
.map<String>((e) =>
'${ApplicationLocalizations.of(navigatorKey.currentContext!).translate(e.label)}')
.toList(),
getVendorReportData(vendorReportData!, isExcel: true)
.map<List<String>>(
(e) => e.tableRow.map((e) => e.label).toList())
.toList() ??
[],
title:
'VendorReport_${commonProvider.userDetails?.selectedtenant?.code?.substring(3)}_${selectedBillPeriod.toString().replaceAll('/', '_')}',
optionalData: [
'Vendor 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 (vendorReportData != null && vendorReportData!.isNotEmpty) {
this.limit = limit;
this.offset = offset;
this.genericTableData = BillsTableData(
vendorReportHeaderList, getVendorReportData(vendorReportData!));
}
}
streamController.add(response);
callNotifier();
} else {
streamController.add('error');
throw Exception('API Error');
}
}
catch (e, s) {
ErrorHandler().allExceptionsHandler(navigatorKey.currentContext!, e, s);
streamController.addError('error');
callNotifier();
}
}

void clearBuildTableData() {
genericTableData = BillsTableData([], []);
callNotifier();
Expand Down
36 changes: 36 additions & 0 deletions frontend/mgramseva/lib/repository/reports_repo.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:mgramseva/model/reports/expense_bill_report_data.dart';
import 'package:mgramseva/model/reports/vendor_report_data.dart';
import 'package:mgramseva/services/urls.dart';
import 'package:mgramseva/services/base_service.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -158,4 +159,39 @@ class ReportsRepo extends BaseService{
}
return expenseBillReports;
}
Future<List<VendorReportData>?> fetchVendorReport(Map<String,dynamic> params,
[String? token]) async {
var commonProvider = Provider.of<CommonProvider>(
navigatorKey.currentContext!,
listen: false);
List<VendorReportData>? vendorReports;
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.VENDOR_REPORT,
queryParameters: params,
requestInfo: requestInfo,
body: {},
method: RequestType.POST);
if (res != null && res['VendorReportData'] != null) {
try {
vendorReports = [];
res['VendorReportData'].forEach((val){
vendorReports?.add(VendorReportData.fromJson(val));
});
} catch (e) {
print(e);
vendorReports = null;
}
}
return vendorReports;
}
}
4 changes: 3 additions & 1 deletion frontend/mgramseva/lib/screeens/reports/reports.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:mgramseva/screeens/reports/expense_bill_report.dart';
import 'package:mgramseva/screeens/reports/inactive_consumer_report.dart';
import 'package:mgramseva/screeens/reports/vendor_report.dart';
import 'package:mgramseva/screeens/reports/view_table.dart';
import 'package:provider/provider.dart';

Expand Down Expand Up @@ -216,7 +217,8 @@ class _Reports extends State<Reports> with SingleTickerProviderStateMixin {
BillReport(onViewClick: showTable),
CollectionReport(onViewClick: showTable),
InactiveConsumerReport(onViewClick: showTable,),
ExpenseBillReport(onViewClick: showTable,)
ExpenseBillReport(onViewClick: showTable,),
VendorReport(onViewClick: showTable,)
],
),
),
Expand Down
112 changes: 112 additions & 0 deletions frontend/mgramseva/lib/screeens/reports/vendor_report.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import 'package:flutter/material.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';

class VendorReport extends StatefulWidget {
final Function onViewClick;

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

@override
State<StatefulWidget> createState() => _VendorReportState();
}

class _VendorReportState extends State<VendorReport>
with SingleTickerProviderStateMixin {
@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, constraints)
{
final isWideScreen = constraints.maxWidth > 700;
final containerMargin = isWideScreen
? const EdgeInsets.only(top: 5.0, bottom: 5, right: 20, left: 10)
: const EdgeInsets.symmetric(vertical: 5.0, horizontal: 8);
return Consumer<ReportsProvider>(builder: (_, reportProvider, child) {
return Container(
margin: containerMargin,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(
height: 30,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width: constraints.maxWidth > 344 ? constraints.maxWidth /
2.5 : constraints.maxWidth / 3,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"5. ",
style: TextStyle(
fontSize: 14, fontWeight: FontWeight.w700),
),
Expanded(
child: Text(
ApplicationLocalizations.of(context)
.translate(i18.dashboard.VENDOR_REPORT),
maxLines: 3,
style: TextStyle(
fontSize: 14, fontWeight: FontWeight.w700),
),
),
],
),
),
Row(
children: [
Container(
width: 50,
child: Button(
ApplicationLocalizations.of(context)
.translate(i18.common.VIEW),
() {
if (reportProvider.selectedBillPeriod == null) {
Notifiers.getToastMessage(
context, 'Select Billing Cycle', 'ERROR');
} else {
reportProvider.clearTableData();
reportProvider.getVendorReport();
widget.onViewClick(
true, i18.dashboard.VENDOR_REPORT);
}
},
key: Keys.billReport.VENDOR_REPORT_VIEW_BUTTON,
),
),
SizedBox(
width: 10,
),
TextButton.icon(
onPressed: () {
if (reportProvider.selectedBillPeriod == null) {
Notifiers.getToastMessage(
context, 'Select Billing Cycle', 'ERROR');
} else {
reportProvider.getVendorReport(
download: true);
}
},
icon: Icon(Icons.download_sharp),
label: Text(ApplicationLocalizations.of(context)
.translate(i18.common.CORE_DOWNLOAD))),
],
),
],
),
],
),
);
});
});
}
}
1 change: 1 addition & 0 deletions frontend/mgramseva/lib/services/urls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Url {
static const String FETCH_WC_CONNECTION = 'ws-services/wc/_search';
static const String VENDOR_SEARCH = 'vendor/v1/_search';
static const String CREATE_VENDOR = 'vendor/v1/_create';
static const String VENDOR_REPORT = 'vendor/v1/_vendorReport';
static const String EGOV_LOCATIONS =
'egov-location/location/v11/boundarys/_search';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ class _DashBoard {
String get CORE_REPORTS => 'CORE_REPORTS';
String get BILL_REPORT => 'BILL_REPORT';
String get COLLECTION_REPORT => 'COLLECTION_REPORT';
String get VENDOR_REPORT => 'VENDOR_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 @@ -139,4 +139,5 @@ class BillReportKeys {
Key get BILL_REPORT_BILLING_YEAR => Key("bill_report_billing_year");
Key get BILL_REPORT_BILLING_CYCLE => Key("bill_report_billing_cycle");
Key get EXPENSE_BILL_REPORT_VIEW_BUTTON => Key("expense_bill_report_view_button");
Key get VENDOR_REPORT_VIEW_BUTTON => Key("vendor_report_view_button");
}

0 comments on commit a7676c9

Please sign in to comment.