forked from egovernments/punjab-mgramseva
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #402 from rahuldevgarg-egov/PFM-2962-Months_in_Dro…
…pDown fixed dropdown month list
- Loading branch information
Showing
3 changed files
with
72 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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>[]; | ||
|
||
|
@@ -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)); | ||
} | ||
|
||
|
@@ -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; | ||
|