Skip to content

Commit

Permalink
Merge pull request #402 from rahuldevgarg-egov/PFM-2962-Months_in_Dro…
Browse files Browse the repository at this point in the history
…pDown

fixed dropdown month list
  • Loading branch information
egov-arindam authored May 4, 2023
2 parents 2583b68 + 7d3d148 commit 05f3fcc
Show file tree
Hide file tree
Showing 3 changed files with 72 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 > ytd.endDate.year) months.clear();

for (var i = 0; i < months.length; i++) {
var prevMonth = months[i].startDate;
Expand Down
40 changes: 11 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,20 @@ 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 > ytd.endDate.year) months.clear();

for (var i = 0; i < months.length; i++) {
var prevMonth = months[i].startDate;
Expand Down
57 changes: 53 additions & 4 deletions frontend/mgramseva/lib/utils/common_methods.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,57 @@ class CommonMethods {
.reversed
.toList();
}
/*
* @author Rahul Dev Garg
* [email protected]
*
* */

static List<DatePeriod> getPastMonthUntilFinancialYTD(DatePeriod ytd) {
var monthList = <DateTime>[];
final currentTime = DateTime.now();
if(currentTime.year < ytd.startDate.year){
return <DatePeriod>[];
}
if (currentTime.year == ytd.startDate.year) {
//when current year is same as start year of financial year
for (int i = ytd.startDate.month; i < currentTime.month; i++) {
monthList.add(DateTime(currentTime.year, i));
}
} else if(currentTime.year == ytd.endDate.year){
//when current year is same as end year of financial year
for (int i = ytd.startDate.month; i <= 12; i++) {
monthList.add(DateTime(ytd.startDate.year, i));
}
for (int i = 1;
i <= (currentTime.month <= ytd.endDate.month ? currentTime.month-1: ytd.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(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 +110,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 +126,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 05f3fcc

Please sign in to comment.