Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #739 from egovernments/PFM-5064
Browse files Browse the repository at this point in the history
PFM 5064 Restrict User creation to past two months
  • Loading branch information
pradeepkumarcm-egov authored Mar 11, 2024
2 parents 9a146c6 + 94e656f commit fd03301
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 24 deletions.
46 changes: 45 additions & 1 deletion frontend/mgramseva/lib/providers/consumer_details_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,39 @@ class ConsumerProvider with ChangeNotifier {
}
return <Map<String,dynamic>>[];
}
//Displaying Billing Cycle Vaule (EX- JAN-2021,,)
List<Map<String,dynamic>> getBillingCycleMonthCountCurrent(TaxPeriod? billYear) {
var dates = <Map<String,dynamic>>[];
if (billYear!=null) {
DatePeriod ytd;
var fromDate = DateFormats.getFormattedDateToDateTime(
DateFormats.timeStampToDate(billYear?.fromDate)) as DateTime;

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.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;
var r = {"code": prevMonth, "name": '${ApplicationLocalizations.of(navigatorKey.currentContext!)
.translate((Constants.MONTHS[prevMonth.month - 1])) +
" - " +
prevMonth.year.toString()}'};
dates.add(r);
}
}
if (dates.length > 0 && waterconnection.connectionType == 'Non_Metered') {
return dates;
}
return <Map<String,dynamic>>[];
}

incrementIndex(index, consumerGenderKey) async {
if (boundaryList.length > 1) {
Expand Down Expand Up @@ -667,7 +700,18 @@ class ConsumerProvider with ChangeNotifier {
}
return <TaxPeriod>[];
}

List<TaxPeriod> getLastFinancialYearList(int count) {
return getFinancialYearList().length>count?getFinancialYearList().sublist(0,count):getFinancialYearList();
}
List<Map<String,dynamic>> newBillingCycleFunction({int pastMonthCount = 2}){
List<TaxPeriod> financialYears = getFinancialYearList();
var dates = <Map<String,dynamic>>[];
financialYears.forEach((year) {
dates.addAll(getBillingCycleMonthCountCurrent(year));
});
dates.sort((a, b) => b['code'].compareTo(a['code']));
return dates.toList().length>2?dates.toList().sublist(0,2):dates.toList();
}
void onChangeOfAmountType(value) {
waterconnection.paymentType = value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ class _ConsumerDetailsState extends State<ConsumerDetails> {
.waterconnection
.previousReadingDateCtrl,
firstDate:
DateTime.fromMillisecondsSinceEpoch(consumerProvider.languageList?.mdmsRes?.billingService?.taxPeriodList!.first.fromDate??0),
DateTime.fromMillisecondsSinceEpoch(consumerProvider.getLastFinancialYearList(2).reversed.first.fromDate??0),
lastDate:
DateTime.now(),
onChangeOfDate:
Expand Down Expand Up @@ -503,25 +503,25 @@ class _ConsumerDetailsState extends State<ConsumerDetails> {
false
? Wrap(
children: [
SelectFieldBuilder(
i18.demandGenerate
.BILLING_YEAR_LABEL,
consumerProvider
.billYear,
'',
'',
consumerProvider
.onChangeOfBillYear,
consumerProvider
.getFinancialYearList(),
true,
itemAsString: (i) =>'${ApplicationLocalizations.of(context).translate(i.financialYear)}',
controller: consumerProvider
.waterconnection
.billingCycleYearCtrl,
key: Keys.bulkDemand
.BULK_DEMAND_BILLING_YEAR,
),
// SelectFieldBuilder(
// i18.demandGenerate
// .BILLING_YEAR_LABEL,
// consumerProvider
// .billYear,
// '',
// '',
// consumerProvider
// .onChangeOfBillYear,
// consumerProvider
// .getFinancialYearList(),
// true,
// itemAsString: (i) =>'${ApplicationLocalizations.of(context).translate(i.financialYear)}',
// controller: consumerProvider
// .waterconnection
// .billingCycleYearCtrl,
// key: Keys.bulkDemand
// .BULK_DEMAND_BILLING_YEAR,
// ),
SelectFieldBuilder(
i18.consumer
.CONSUMER_BILLING_CYCLE,
Expand All @@ -532,7 +532,7 @@ class _ConsumerDetailsState extends State<ConsumerDetails> {
consumerProvider
.onChangeBillingCycle,
consumerProvider
.getBillingCycle(),
.newBillingCycleFunction(),
true,
itemAsString: (i) =>"${ApplicationLocalizations.of(context).translate(i['name'])}",
controller: consumerProvider
Expand Down
112 changes: 110 additions & 2 deletions frontend/mgramseva/lib/utils/common_methods.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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>[];
Expand Down Expand Up @@ -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>[];
Expand Down

0 comments on commit fd03301

Please sign in to comment.