From f1ed382f8bb98efd3de24fd10f855183d1319581 Mon Sep 17 00:00:00 2001 From: Rahul Dev Garg <34365102+rahuldevgarg@users.noreply.github.com> Date: Tue, 5 Mar 2024 22:29:33 +0530 Subject: [PATCH 1/5] PFM-5064 Restrict to show path two months only --- .../providers/consumer_details_provider.dart | 33 ++++++ .../consumer_details/consumer_details.dart | 7 +- .../mgramseva/lib/utils/common_methods.dart | 108 +++++++++++++++++- 3 files changed, 143 insertions(+), 5 deletions(-) diff --git a/frontend/mgramseva/lib/providers/consumer_details_provider.dart b/frontend/mgramseva/lib/providers/consumer_details_provider.dart index 2048a5d92..138a88e35 100644 --- a/frontend/mgramseva/lib/providers/consumer_details_provider.dart +++ b/frontend/mgramseva/lib/providers/consumer_details_provider.dart @@ -625,6 +625,39 @@ class ConsumerProvider with ChangeNotifier { } return >[]; } + //Displaying Billing Cycle Vaule (EX- JAN-2021,,) + List> getBillingCycleMonthCountCurrent(TaxPeriod? billYear) { + var dates = >[]; + if (billYear!=null) { + DatePeriod ytd; + var fromDate = DateFormats.getFormattedDateToDateTime( + DateFormats.timeStampToDate(billYear?.fromDate)) as DateTime; + + var toDate = DateFormats.getFormattedDateToDateTime( + DateFormats.timeStampToDate(billYear?.toDate)) as DateTime; + + ytd = DatePeriod(fromDate,toDate,DateType.YTD); + + /// Get months based on selected billing year + var months = CommonMethods.getPastMonthUntilFinancialYTDMonthCount(ytd); + + /// if selected year is future year means all the months will be removed + if(fromDate.year > ytd.endDate.year) months.clear(); + + for (var i = 0; i < months.length; i++) { + var prevMonth = months[i].startDate; + var r = {"code": prevMonth, "name": '${ApplicationLocalizations.of(navigatorKey.currentContext!) + .translate((Constants.MONTHS[prevMonth.month - 1])) + + " - " + + prevMonth.year.toString()}'}; + dates.add(r); + } + } + if (dates.length > 0 && waterconnection.connectionType == 'Non_Metered') { + return dates; + } + return >[]; + } incrementIndex(index, consumerGenderKey) async { if (boundaryList.length > 1) { diff --git a/frontend/mgramseva/lib/screeens/consumer_details/consumer_details.dart b/frontend/mgramseva/lib/screeens/consumer_details/consumer_details.dart index 226c66d02..7b71d911d 100644 --- a/frontend/mgramseva/lib/screeens/consumer_details/consumer_details.dart +++ b/frontend/mgramseva/lib/screeens/consumer_details/consumer_details.dart @@ -512,8 +512,8 @@ class _ConsumerDetailsState extends State { '', consumerProvider .onChangeOfBillYear, - consumerProvider - .getFinancialYearList(), + [consumerProvider + .getFinancialYearList().first], true, itemAsString: (i) =>'${ApplicationLocalizations.of(context).translate(i.financialYear)}', controller: consumerProvider @@ -532,7 +532,8 @@ class _ConsumerDetailsState extends State { consumerProvider .onChangeBillingCycle, consumerProvider - .getBillingCycle(), + .getBillingCycleMonthCountCurrent(consumerProvider + .billYear), true, itemAsString: (i) =>"${ApplicationLocalizations.of(context).translate(i['name'])}", controller: consumerProvider diff --git a/frontend/mgramseva/lib/utils/common_methods.dart b/frontend/mgramseva/lib/utils/common_methods.dart index 633b4d38f..5443a7d2c 100644 --- a/frontend/mgramseva/lib/utils/common_methods.dart +++ b/frontend/mgramseva/lib/utils/common_methods.dart @@ -57,7 +57,60 @@ class CommonMethods { * rahul.dev@egovernments.org * * */ - + static var daysInMonthLeap = [ + 31, + 29, + 31, + 30, + 31, + 30, + 31, + 31, + 30, + 31, + 30, + 31 + ]; + static var daysInMonth = [ + 31, + 28, + 31, + 30, + 31, + 30, + 31, + 31, + 30, + 31, + 30, + 31 + ]; + static bool isLeapYear(int year) { + if (year % 4 == 0) { + if (year % 100 == 0) { + if (year % 400 == 0) { + return true; + } else { + return false; + } + } else { + return true; + } + } else { + return false; + } + } + static int daysToSub(int monthCount, int year) { + var days = 0; + for (int i = 0; i < monthCount; i++) { + if (isLeapYear(year)) { + days += daysInMonthLeap[i]; + } else { + days += daysInMonth[i]; + } + } + return days; + } static List getPastMonthUntilFinancialYTD(DatePeriod ytd, {bool showCurrentMonth = false}) { var monthList = []; @@ -109,7 +162,58 @@ class CommonMethods { .toList(); return list; } - + static List getPastMonthUntilFinancialYTDMonthCount(DatePeriod ytd, + {int monthCount=2,bool showCurrentMonth = false}) { + var monthList = []; + final currentTime = DateTime.now(); + DatePeriod newDT = DatePeriod(ytd.endDate.subtract(Duration(days: daysToSub(monthCount,currentTime.year))), ytd.endDate, DateType.MONTH); + if (currentTime.year < newDT.startDate.year) { + return []; + } + if (currentTime.year == newDT.startDate.year) { + //when current year is same as start year of financial year + for (int i = newDT.startDate.month; + i <= (showCurrentMonth ? currentTime.month : currentTime.month - 1); + i++) { + monthList.add(DateTime(currentTime.year, i)); + } + } else if (currentTime.year == newDT.endDate.year) { + //when current year is same as end year of financial year + for (int i = newDT.startDate.month; i <= 12; i++) { + monthList.add(DateTime(newDT.startDate.year, i)); + } + for (int i = 1; + i <= + (currentTime.month <= newDT.endDate.month + ? showCurrentMonth + ? currentTime.month + : currentTime.month - 1 + : newDT.endDate.month); + /* + * if current month is less than or equal to end month of financial year + * we are using months less than current month and if it is more than + * end month of financial year we are using till end month of financial + * year + */ + i++) { + monthList.add(DateTime(newDT.endDate.year, i)); + } + } else { + for (int i = newDT.startDate.month; i <= 12; i++) { + monthList.add(DateTime(newDT.startDate.year, i)); + } + for (int i = 1; i <= newDT.endDate.month; i++) { + monthList.add(DateTime(newDT.endDate.year, i)); + } + } + var list = monthList + .map((e) => DatePeriod(DateTime(e.year, e.month, 1), + DateTime(e.year, e.month + 1, 0, 23, 59, 59, 999), DateType.MONTH)) + .toList() + .reversed + .toList(); + return list; + } static List getPastMonthIncludingCurrentMonthUntilFinancialYTD( DatePeriod ytd) { var monthList = []; From f8649496be8b1ab5281eb3af365664059ba4a93d Mon Sep 17 00:00:00 2001 From: Rahul Dev Garg <34365102+rahuldevgarg@users.noreply.github.com> Date: Tue, 5 Mar 2024 22:34:04 +0530 Subject: [PATCH 2/5] PFM-5064 fix daysToSub --- frontend/mgramseva/lib/utils/common_methods.dart | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/frontend/mgramseva/lib/utils/common_methods.dart b/frontend/mgramseva/lib/utils/common_methods.dart index 5443a7d2c..6964be456 100644 --- a/frontend/mgramseva/lib/utils/common_methods.dart +++ b/frontend/mgramseva/lib/utils/common_methods.dart @@ -100,13 +100,17 @@ class CommonMethods { return false; } } - static int daysToSub(int monthCount, int year) { - var days = 0; + static int daysToSubtract(int monthCount, int year,int currentMonth) { + int days = 0; for (int i = 0; i < monthCount; i++) { - if (isLeapYear(year)) { - days += daysInMonthLeap[i]; + if (currentMonth - i < 0) { + days += isLeapYear(year - 1) + ? daysInMonthLeap[12 - (currentMonth - i).abs()] + : daysInMonth[12 - (currentMonth - i).abs()]; } else { - days += daysInMonth[i]; + days += isLeapYear(year) + ? daysInMonthLeap[currentMonth - i] + : daysInMonth[currentMonth - i]; } } return days; From 0b2d86be8f94a2a560e6990694385651f1bfeda1 Mon Sep 17 00:00:00 2001 From: Rahul Dev Garg <34365102+rahuldevgarg@users.noreply.github.com> Date: Tue, 5 Mar 2024 22:37:11 +0530 Subject: [PATCH 3/5] PFM-5064 fix daysToSubtract --- frontend/mgramseva/lib/utils/common_methods.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/mgramseva/lib/utils/common_methods.dart b/frontend/mgramseva/lib/utils/common_methods.dart index 6964be456..4f671094c 100644 --- a/frontend/mgramseva/lib/utils/common_methods.dart +++ b/frontend/mgramseva/lib/utils/common_methods.dart @@ -170,7 +170,7 @@ class CommonMethods { {int monthCount=2,bool showCurrentMonth = false}) { var monthList = []; final currentTime = DateTime.now(); - DatePeriod newDT = DatePeriod(ytd.endDate.subtract(Duration(days: daysToSub(monthCount,currentTime.year))), ytd.endDate, DateType.MONTH); + DatePeriod newDT = DatePeriod(ytd.endDate.subtract(Duration(days: daysToSubtract(monthCount,currentTime.year,currentTime.month))), ytd.endDate, DateType.MONTH); if (currentTime.year < newDT.startDate.year) { return []; } From 77d5a9521baeb6be218eb309983b861b9af8ab8d Mon Sep 17 00:00:00 2001 From: Rahul Dev Garg <34365102+rahuldevgarg@users.noreply.github.com> Date: Mon, 11 Mar 2024 12:19:49 +0530 Subject: [PATCH 4/5] PFM-5064 consumer_details_provider.dart --- .../lib/providers/consumer_details_provider.dart | 15 +++++++++++++-- .../consumer_details/consumer_details.dart | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/frontend/mgramseva/lib/providers/consumer_details_provider.dart b/frontend/mgramseva/lib/providers/consumer_details_provider.dart index 138a88e35..54dcdd62a 100644 --- a/frontend/mgramseva/lib/providers/consumer_details_provider.dart +++ b/frontend/mgramseva/lib/providers/consumer_details_provider.dart @@ -639,7 +639,7 @@ class ConsumerProvider with ChangeNotifier { ytd = DatePeriod(fromDate,toDate,DateType.YTD); /// Get months based on selected billing year - var months = CommonMethods.getPastMonthUntilFinancialYTDMonthCount(ytd); + var months = CommonMethods.getPastMonthUntilFinancialYTD(ytd); /// if selected year is future year means all the months will be removed if(fromDate.year > ytd.endDate.year) months.clear(); @@ -700,7 +700,18 @@ class ConsumerProvider with ChangeNotifier { } return []; } - + List getLastFinancialYearList(int count) { + return getFinancialYearList().length>count?getFinancialYearList().sublist(0,count):getFinancialYearList(); + } + List> newFunction({int pastMonthCount = 2}){ + List financialYears = getFinancialYearList(); + var dates = >[]; + financialYears.forEach((year) { + dates.addAll(getBillingCycleMonthCountCurrent(year)); + }); + dates.sort((a, b) => b['code'].compareTo(a['code'])); + return dates.toList().length>2?dates.toList().sublist(0,2):dates.toList(); + } void onChangeOfAmountType(value) { waterconnection.paymentType = value; diff --git a/frontend/mgramseva/lib/screeens/consumer_details/consumer_details.dart b/frontend/mgramseva/lib/screeens/consumer_details/consumer_details.dart index 7b71d911d..808d2a8eb 100644 --- a/frontend/mgramseva/lib/screeens/consumer_details/consumer_details.dart +++ b/frontend/mgramseva/lib/screeens/consumer_details/consumer_details.dart @@ -438,7 +438,7 @@ class _ConsumerDetailsState extends State { .waterconnection .previousReadingDateCtrl, firstDate: - DateTime.fromMillisecondsSinceEpoch(consumerProvider.languageList?.mdmsRes?.billingService?.taxPeriodList!.first.fromDate??0), + DateTime.fromMillisecondsSinceEpoch(consumerProvider.getLastFinancialYearList(2).reversed.first.fromDate??0), lastDate: DateTime.now(), onChangeOfDate: From 94e656f737c8106ac6f81bcb4ac21c60e88315fc Mon Sep 17 00:00:00 2001 From: Rahul Dev Garg <34365102+rahuldevgarg@users.noreply.github.com> Date: Mon, 11 Mar 2024 12:23:25 +0530 Subject: [PATCH 5/5] PFM-5064 consumer_details_provider.dart --- .../providers/consumer_details_provider.dart | 2 +- .../consumer_details/consumer_details.dart | 41 +++++++++---------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/frontend/mgramseva/lib/providers/consumer_details_provider.dart b/frontend/mgramseva/lib/providers/consumer_details_provider.dart index 54dcdd62a..5fbb5efc5 100644 --- a/frontend/mgramseva/lib/providers/consumer_details_provider.dart +++ b/frontend/mgramseva/lib/providers/consumer_details_provider.dart @@ -703,7 +703,7 @@ class ConsumerProvider with ChangeNotifier { List getLastFinancialYearList(int count) { return getFinancialYearList().length>count?getFinancialYearList().sublist(0,count):getFinancialYearList(); } - List> newFunction({int pastMonthCount = 2}){ + List> newBillingCycleFunction({int pastMonthCount = 2}){ List financialYears = getFinancialYearList(); var dates = >[]; financialYears.forEach((year) { diff --git a/frontend/mgramseva/lib/screeens/consumer_details/consumer_details.dart b/frontend/mgramseva/lib/screeens/consumer_details/consumer_details.dart index 808d2a8eb..c1b7e490c 100644 --- a/frontend/mgramseva/lib/screeens/consumer_details/consumer_details.dart +++ b/frontend/mgramseva/lib/screeens/consumer_details/consumer_details.dart @@ -503,25 +503,25 @@ class _ConsumerDetailsState extends State { false ? Wrap( children: [ - SelectFieldBuilder( - i18.demandGenerate - .BILLING_YEAR_LABEL, - consumerProvider - .billYear, - '', - '', - consumerProvider - .onChangeOfBillYear, - [consumerProvider - .getFinancialYearList().first], - true, - itemAsString: (i) =>'${ApplicationLocalizations.of(context).translate(i.financialYear)}', - controller: consumerProvider - .waterconnection - .billingCycleYearCtrl, - key: Keys.bulkDemand - .BULK_DEMAND_BILLING_YEAR, - ), + // SelectFieldBuilder( + // i18.demandGenerate + // .BILLING_YEAR_LABEL, + // consumerProvider + // .billYear, + // '', + // '', + // consumerProvider + // .onChangeOfBillYear, + // consumerProvider + // .getFinancialYearList(), + // true, + // itemAsString: (i) =>'${ApplicationLocalizations.of(context).translate(i.financialYear)}', + // controller: consumerProvider + // .waterconnection + // .billingCycleYearCtrl, + // key: Keys.bulkDemand + // .BULK_DEMAND_BILLING_YEAR, + // ), SelectFieldBuilder( i18.consumer .CONSUMER_BILLING_CYCLE, @@ -532,8 +532,7 @@ class _ConsumerDetailsState extends State { consumerProvider .onChangeBillingCycle, consumerProvider - .getBillingCycleMonthCountCurrent(consumerProvider - .billYear), + .newBillingCycleFunction(), true, itemAsString: (i) =>"${ApplicationLocalizations.of(context).translate(i['name'])}", controller: consumerProvider