Skip to content

Commit

Permalink
Merge pull request #391 from rahuldevgarg-egov/PFM-2962
Browse files Browse the repository at this point in the history
PFM-2962: added new function to generate months of a financial year
  • Loading branch information
Ramkrishna-egov authored Apr 26, 2023
2 parents 105fea4 + 7ca9e69 commit 15c2f5c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -466,38 +466,20 @@ class BillGenerationProvider with ChangeNotifier {
List<DropdownMenuItem<Object>> 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;

/// Get months based on selected billing year
var months = CommonMethods.getPastMonthUntilFinancialYear(date1.year);
ytd = DatePeriod(fromDate,toDate,DateType.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;
}
}
/// Get months based on selected billing year
var months = CommonMethods.getPastMonthUntilFinancialYTD(ytd);

/// 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;
Expand Down
38 changes: 9 additions & 29 deletions frontend/mgramseva/lib/providers/consumer_details_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -608,38 +608,18 @@ class ConsumerProvider with ChangeNotifier {
List<DropdownMenuItem<Object>> 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);

/// 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 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;
Expand Down
41 changes: 37 additions & 4 deletions frontend/mgramseva/lib/utils/common_methods.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,40 @@ class CommonMethods {
.toList();
}

static List<DatePeriod> getPastMonthUntilFinancialYTD(DatePeriod ytd) {
var monthList = <DateTime>[];
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<YearWithMonths> getFinancialYearList([int count = 5]) {
var yearWithMonths = <YearWithMonths>[];

Expand All @@ -60,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));
}

Expand All @@ -77,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;
Expand Down

0 comments on commit 15c2f5c

Please sign in to comment.