From 223c92e64efe67864e57dc1e1237f7dfd70b1df4 Mon Sep 17 00:00:00 2001 From: Rahul Dev Garg <34365102+rahuldevgarg@users.noreply.github.com> Date: Wed, 26 Apr 2023 15:54:40 +0530 Subject: [PATCH 1/4] added new function to generate months of a financial year --- .../bill_generation_details_provider.dart | 57 ++++++++++--------- .../providers/consumer_details_provider.dart | 56 +++++++++--------- .../mgramseva/lib/utils/common_methods.dart | 34 +++++++++++ 3 files changed, 92 insertions(+), 55 deletions(-) diff --git a/frontend/mgramseva/lib/providers/bill_generation_details_provider.dart b/frontend/mgramseva/lib/providers/bill_generation_details_provider.dart index a53abcbea..4615b01c0 100644 --- a/frontend/mgramseva/lib/providers/bill_generation_details_provider.dart +++ b/frontend/mgramseva/lib/providers/bill_generation_details_provider.dart @@ -466,38 +466,43 @@ class BillGenerationProvider with ChangeNotifier { List> getBillingCycle() { dates = []; if (billGenerateDetails.billYear != null && selectedBillYear != null) { - late DatePeriod ytd; - if(DateTime.now().month >= 4) { - ytd = DatePeriod(DateTime(DateTime.now().year, 4) , DateTime(DateTime.now().year + 1, 4, 0, 23,59, 59, 999), DateType.YTD); - }else{ - ytd = DatePeriod(DateTime( DateTime.now().year - 1, 4), DateTime.now(), DateType.YTD); - } - - var date1 = DateFormats.getFormattedDateToDateTime( + DatePeriod ytd; + var fromDate = DateFormats.getFormattedDateToDateTime( DateFormats.timeStampToDate(selectedBillYear.fromDate)) as DateTime; - var isCurrentYtdSelected = date1.year == ytd.startDate.year; + var toDate = DateFormats.getFormattedDateToDateTime( + DateFormats.timeStampToDate(selectedBillYear.toDate)) as DateTime; + // if(DateTime.now().month > 4) { + // ytd = DatePeriod(DateTime(selectedBillYear.fromDate) , DateTime(selectedBillYear.toDate), DateType.YTD); + // }else{ + // ytd = DatePeriod(DateTime( selectedBillYear.fromDate.year - 1, 4), DateTime.now(), DateType.YTD); + // } + ytd = DatePeriod(fromDate,toDate,DateType.YTD); + + + + // var isCurrentYtdSelected = date1.year == ytd.startDate.year; /// Get months based on selected billing year - var months = CommonMethods.getPastMonthUntilFinancialYear(date1.year); - - /// if its current ytd year means removing till current month - if (isCurrentYtdSelected) { - switch (DateTime.now().month) { - case 1: - months.removeRange(0, 3); - break; - case 2: - months.removeRange(0, 2); - break; - case 3: - months.removeRange(0, 1); - break; - } - } + var months = CommonMethods.getPastMonthUntilFinancialYTD(ytd); + + // /// if its current ytd year means removing till current month + // if (isCurrentYtdSelected) { + // switch (DateTime.now().month) { + // case 1: + // months.removeRange(0, 3); + // break; + // case 2: + // months.removeRange(0, 2); + // break; + // case 3: + // months.removeRange(0, 1); + // break; + // } + // } /// if selected year is future year means all the months will be removed - if(date1.year >= ytd.endDate.year) months.clear(); + if(fromDate.year >= DateTime.now().year) months.clear(); for (var i = 0; i < months.length; i++) { var prevMonth = months[i].startDate; diff --git a/frontend/mgramseva/lib/providers/consumer_details_provider.dart b/frontend/mgramseva/lib/providers/consumer_details_provider.dart index 4d15130aa..43d6d49ab 100644 --- a/frontend/mgramseva/lib/providers/consumer_details_provider.dart +++ b/frontend/mgramseva/lib/providers/consumer_details_provider.dart @@ -608,38 +608,36 @@ class ConsumerProvider with ChangeNotifier { List> getBillingCycle() { dates = []; if (billYear != null) { - late DatePeriod ytd; - if (DateTime.now().month >= 4) { - ytd = DatePeriod( - DateTime(DateTime.now().year, 4), - DateTime(DateTime.now().year + 1, 4, 0, 23, 59, 59, 999), - DateType.YTD); - } else { - ytd = DatePeriod( - DateTime(DateTime.now().year - 1, 4), DateTime.now(), DateType.YTD); - } - - var date1 = DateFormats.getFormattedDateToDateTime( + DatePeriod ytd; + var fromDate = DateFormats.getFormattedDateToDateTime( DateFormats.timeStampToDate(billYear?.fromDate)) as DateTime; - var isCurrentYtdSelected = date1.year == ytd.startDate.year; + var toDate = DateFormats.getFormattedDateToDateTime( + DateFormats.timeStampToDate(billYear?.toDate)) as DateTime; + ytd = DatePeriod(fromDate,toDate,DateType.YTD); + + var date1 = DateTime(DateTime.now().year); + // var isCurrentYtdSelected = date1.year == ytd.startDate.year; /// Get months based on selected billing year - var months = CommonMethods.getPastMonthUntilFinancialYear(date1.year); - - /// if its current ytd year means removing till current month - if (isCurrentYtdSelected) { - switch (DateTime.now().month) { - case 1: - months.removeRange(0, 3); - break; - case 2: - months.removeRange(0, 2); - break; - case 3: - months.removeRange(0, 1); - break; - } - } + var months = CommonMethods.getPastMonthUntilFinancialYTD(ytd); + + // /// if its current ytd year means removing till current month + // if (isCurrentYtdSelected) { + // switch (DateTime.now().month) { + // case 1: + // months.removeRange(0, 3); + // break; + // case 2: + // months.removeRange(0, 2); + // break; + // case 3: + // months.removeRange(0, 1); + // break; + // } + // } + + /// if selected year is future year means all the months will be removed + if(fromDate.year >= DateTime.now().year) months.clear(); for (var i = 0; i < months.length; i++) { var prevMonth = months[i].startDate; diff --git a/frontend/mgramseva/lib/utils/common_methods.dart b/frontend/mgramseva/lib/utils/common_methods.dart index 916d6afe9..c35932a1a 100644 --- a/frontend/mgramseva/lib/utils/common_methods.dart +++ b/frontend/mgramseva/lib/utils/common_methods.dart @@ -52,6 +52,40 @@ class CommonMethods { .toList(); } + static List getPastMonthUntilFinancialYTD(DatePeriod ytd) { + var monthList = []; + if (DateTime.now().year == ytd.startDate.year) { + for (int i = ytd.startDate.month; i < DateTime.now().month; i++) { + monthList.add(DateTime(DateTime.now().year, i)); + } + } else if(DateTime.now().year == ytd.endDate.year){ + for (int i = ytd.startDate.month; i <= 12; i++) { + monthList.add(DateTime(ytd.startDate.year, i)); + } + for (int i = 1; + i <= (DateTime.now().month <= ytd.endDate.month ? DateTime.now().month : ytd.endDate.month); + i++) { + monthList.add(DateTime(ytd.endDate.year, i)); + } + }else{ + for (int i = ytd.startDate.month; i <= 12; i++) { + monthList.add(DateTime(ytd.startDate.year, i)); + } + for (int i = 1; + i <= ytd.endDate.month; + i++) { + monthList.add(DateTime(ytd.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 getFinancialYearList([int count = 5]) { var yearWithMonths = []; From bf5f7291258de240a99f38df1a31f7161f14ca85 Mon Sep 17 00:00:00 2001 From: Rahul Dev Garg <34365102+rahuldevgarg@users.noreply.github.com> Date: Wed, 26 Apr 2023 16:14:43 +0530 Subject: [PATCH 2/4] fixed getFinancialYearList([int count = 5]) in common_methods.dart --- frontend/mgramseva/lib/utils/common_methods.dart | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/frontend/mgramseva/lib/utils/common_methods.dart b/frontend/mgramseva/lib/utils/common_methods.dart index c35932a1a..71d66022c 100644 --- a/frontend/mgramseva/lib/utils/common_methods.dart +++ b/frontend/mgramseva/lib/utils/common_methods.dart @@ -94,13 +94,12 @@ class CommonMethods { DateTime(DateTime.now().year, 4), DateTime(DateTime.now().year + 1, 4, 0, 23, 59, 59, 999), DateType.YTD); - var monthList = getPastMonthUntilFinancialYear(DateTime.now().year); + var monthList = getPastMonthUntilFinancialYTD(year); yearWithMonths.add(YearWithMonths(monthList, year)); } else { var year = DatePeriod( DateTime(DateTime.now().year - 1, 4), DateTime.now(), DateType.YTD); - var monthList = getPastMonthUntilFinancialYear(year.startDate.year, - dateType: DateType.YTD); + var monthList = getPastMonthUntilFinancialYTD(year); yearWithMonths.add(YearWithMonths(monthList, year)); } @@ -111,7 +110,7 @@ class CommonMethods { : DateTime(currentDate.year - i); year = DatePeriod(DateTime(year.year - 1, 4), DateTime(year.year, 4, 0, 23, 59, 59, 999), DateType.YEAR); - var monthList = getPastMonthUntilFinancialYear(year.startDate.year); + var monthList = getPastMonthUntilFinancialYTD(year); yearWithMonths.add(YearWithMonths(monthList, year)); } return yearWithMonths; From 58f398392aea58204146e6e488c2bd86d3ddac67 Mon Sep 17 00:00:00 2001 From: Rahul Dev Garg <34365102+rahuldevgarg@users.noreply.github.com> Date: Wed, 26 Apr 2023 16:31:35 +0530 Subject: [PATCH 3/4] future months clear --- .../lib/providers/bill_generation_details_provider.dart | 2 +- frontend/mgramseva/lib/providers/consumer_details_provider.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/mgramseva/lib/providers/bill_generation_details_provider.dart b/frontend/mgramseva/lib/providers/bill_generation_details_provider.dart index 4615b01c0..f4705cb5c 100644 --- a/frontend/mgramseva/lib/providers/bill_generation_details_provider.dart +++ b/frontend/mgramseva/lib/providers/bill_generation_details_provider.dart @@ -502,7 +502,7 @@ class BillGenerationProvider with ChangeNotifier { // } /// if selected year is future year means all the months will be removed - if(fromDate.year >= DateTime.now().year) months.clear(); + if(fromDate.year > DateTime.now().year) months.clear(); for (var i = 0; i < months.length; i++) { var prevMonth = months[i].startDate; diff --git a/frontend/mgramseva/lib/providers/consumer_details_provider.dart b/frontend/mgramseva/lib/providers/consumer_details_provider.dart index 43d6d49ab..50ab06355 100644 --- a/frontend/mgramseva/lib/providers/consumer_details_provider.dart +++ b/frontend/mgramseva/lib/providers/consumer_details_provider.dart @@ -637,7 +637,7 @@ class ConsumerProvider with ChangeNotifier { // } /// if selected year is future year means all the months will be removed - if(fromDate.year >= DateTime.now().year) months.clear(); + if(fromDate.year > DateTime.now().year) months.clear(); for (var i = 0; i < months.length; i++) { var prevMonth = months[i].startDate; From 7ca9e699d6a1beba487f80c16c9deccda0d07edc Mon Sep 17 00:00:00 2001 From: Rahul Dev Garg <34365102+rahuldevgarg@users.noreply.github.com> Date: Wed, 26 Apr 2023 17:04:05 +0530 Subject: [PATCH 4/4] removed unnecessary comments --- .../bill_generation_details_provider.dart | 25 +------------------ .../providers/consumer_details_provider.dart | 18 ------------- 2 files changed, 1 insertion(+), 42 deletions(-) diff --git a/frontend/mgramseva/lib/providers/bill_generation_details_provider.dart b/frontend/mgramseva/lib/providers/bill_generation_details_provider.dart index f4705cb5c..4eb3bf902 100644 --- a/frontend/mgramseva/lib/providers/bill_generation_details_provider.dart +++ b/frontend/mgramseva/lib/providers/bill_generation_details_provider.dart @@ -472,35 +472,12 @@ class BillGenerationProvider with ChangeNotifier { var toDate = DateFormats.getFormattedDateToDateTime( DateFormats.timeStampToDate(selectedBillYear.toDate)) as DateTime; - // if(DateTime.now().month > 4) { - // ytd = DatePeriod(DateTime(selectedBillYear.fromDate) , DateTime(selectedBillYear.toDate), DateType.YTD); - // }else{ - // ytd = DatePeriod(DateTime( selectedBillYear.fromDate.year - 1, 4), DateTime.now(), DateType.YTD); - // } - ytd = DatePeriod(fromDate,toDate,DateType.YTD); - - - // var isCurrentYtdSelected = date1.year == ytd.startDate.year; + ytd = DatePeriod(fromDate,toDate,DateType.YTD); /// Get months based on selected billing year var months = CommonMethods.getPastMonthUntilFinancialYTD(ytd); - // /// if its current ytd year means removing till current month - // if (isCurrentYtdSelected) { - // switch (DateTime.now().month) { - // case 1: - // months.removeRange(0, 3); - // break; - // case 2: - // months.removeRange(0, 2); - // break; - // case 3: - // months.removeRange(0, 1); - // break; - // } - // } - /// if selected year is future year means all the months will be removed if(fromDate.year > DateTime.now().year) months.clear(); diff --git a/frontend/mgramseva/lib/providers/consumer_details_provider.dart b/frontend/mgramseva/lib/providers/consumer_details_provider.dart index 50ab06355..c50e00566 100644 --- a/frontend/mgramseva/lib/providers/consumer_details_provider.dart +++ b/frontend/mgramseva/lib/providers/consumer_details_provider.dart @@ -615,27 +615,9 @@ class ConsumerProvider with ChangeNotifier { DateFormats.timeStampToDate(billYear?.toDate)) as DateTime; ytd = DatePeriod(fromDate,toDate,DateType.YTD); - var date1 = DateTime(DateTime.now().year); - // var isCurrentYtdSelected = date1.year == ytd.startDate.year; - /// Get months based on selected billing year var months = CommonMethods.getPastMonthUntilFinancialYTD(ytd); - // /// if its current ytd year means removing till current month - // if (isCurrentYtdSelected) { - // switch (DateTime.now().month) { - // case 1: - // months.removeRange(0, 3); - // break; - // case 2: - // months.removeRange(0, 2); - // break; - // case 3: - // months.removeRange(0, 1); - // break; - // } - // } - /// if selected year is future year means all the months will be removed if(fromDate.year > DateTime.now().year) months.clear();