This repository has been archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
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 #739 from egovernments/PFM-5064
PFM 5064 Restrict User creation to past two months
- Loading branch information
Showing
3 changed files
with
176 additions
and
24 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 |
---|---|---|
|
@@ -57,7 +57,64 @@ class CommonMethods { | |
* [email protected] | ||
* | ||
* */ | ||
|
||
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 daysToSubtract(int monthCount, int year,int currentMonth) { | ||
int days = 0; | ||
for (int i = 0; i < monthCount; i++) { | ||
if (currentMonth - i < 0) { | ||
days += isLeapYear(year - 1) | ||
? daysInMonthLeap[12 - (currentMonth - i).abs()] | ||
: daysInMonth[12 - (currentMonth - i).abs()]; | ||
} else { | ||
days += isLeapYear(year) | ||
? daysInMonthLeap[currentMonth - i] | ||
: daysInMonth[currentMonth - i]; | ||
} | ||
} | ||
return days; | ||
} | ||
static List<DatePeriod> getPastMonthUntilFinancialYTD(DatePeriod ytd, | ||
{bool showCurrentMonth = false}) { | ||
var monthList = <DateTime>[]; | ||
|
@@ -109,7 +166,58 @@ class CommonMethods { | |
.toList(); | ||
return list; | ||
} | ||
|
||
static List<DatePeriod> getPastMonthUntilFinancialYTDMonthCount(DatePeriod ytd, | ||
{int monthCount=2,bool showCurrentMonth = false}) { | ||
var monthList = <DateTime>[]; | ||
final currentTime = DateTime.now(); | ||
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 <DatePeriod>[]; | ||
} | ||
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<DatePeriod> getPastMonthIncludingCurrentMonthUntilFinancialYTD( | ||
DatePeriod ytd) { | ||
var monthList = <DateTime>[]; | ||
|