Untitled
unknown
dart
3 years ago
3.8 kB
7
Indexable
import 'package:get/get.dart';
import 'package:iktifaa/App/Common/Services/AuthenticationService/Core/manager.dart';
import 'package:iktifaa/App/Mall/backend/Dto/storeIncome.dart';
import 'package:iktifaa/App/Mall/backend/storesAPIs.dart';
class SalesIncomereportController extends GetxController {
RxInt selectedMonthIndex = 0.obs;
final AuthenticationManager authManager = Get.find();
Rx<StoreIncome> storeIncome = StoreIncome().obs;
RxInt currentMonth = 0.obs;
RxBool isLoading = true.obs;
List<YearData> yearData = <YearData>[];
RxInt YearName = 2022.obs;
RxInt yearIndexValue = 0.obs;
List<SalesData> data = [
SalesData('Week 1', 100),
SalesData('Week 2', 200),
SalesData('Week 3', 300),
SalesData('Week 4', 400),
];
List<dynamic> monthList = [
{
'id': '1',
'name': 'Jan',
'nameAr': 'يناير',
},
{
'id': '2',
'name': 'Feb',
'nameAr': 'فبراير',
},
{
'id': '3',
'name': 'Mar',
'nameAr': 'مارس',
},
{
'id': '4',
'name': 'Apr',
'nameAr': 'أبريل',
},
{
'id': '5',
'name': 'May',
'nameAr': 'مايو',
},
{
'id': '6',
'name': 'Jun',
'nameAr': 'يونيو',
},
{
'id': '7',
'name': 'Jul',
'nameAr': 'يوليو',
},
{
'id': '8',
'name': 'Aug',
'nameAr': 'أغسطس',
},
{
'id': '9',
'name': 'Sep',
'nameAr': 'سبتمبر',
},
{
'id': '10',
'name': 'Oct',
'nameAr': 'أكتوبر',
},
{
'id': '11',
'name': 'Nov',
'nameAr': 'نوفمبر',
},
{
'id': '12',
'name': 'Dec',
'nameAr': 'ديسمبر',
},
].obs;
void SelectedMonth(int year, int index) {
yearData =
storeIncome.value.yearData!.where((element) => element.yearNo.toString() == year.toString()).toList();
if (index <= (yearData[0].monthdata!.length - 1)) {
selectedMonthIndex.value = index;
}
// selectedMonthIndex.value = index;
update();
}
double getMonthlyIncome(int year, int month) {
yearData =
storeIncome.value.yearData!.where((element) => element.yearNo.toString() == year.toString()).toList();
print('0000000');
print(yearData.length);
if (yearData.length > 0) {
return yearData[0].monthdata![month].totalMonth ?? 0;
} else {
return 0;
}
}
double getPercentage(int month) {
if (month == 0) {
return 0;
}
if (storeIncome.value.monthData?[month].totalMonth == null) {
return 0;
}
if (storeIncome.value.monthData?[month].totalMonth == 0 &&
storeIncome.value.monthData?[month - 1].totalMonth == 0) {
return 0;
}
if (storeIncome.value.monthData?[month - 1].totalMonth == 0 &&
storeIncome.value.monthData![month].totalMonth! > 0) {
return storeIncome.value.monthData![month].totalMonth ?? 0;
} else {
return (((storeIncome.value.monthData?[month].totalMonth ?? 0) -
(storeIncome.value.monthData?[month - 1].totalMonth ?? 0)) /
(storeIncome.value.monthData?[month - 1].totalMonth ?? 0)) *
100;
}
}
@override
void onInit() async {
currentMonth.value = DateTime.now().month;
selectedMonthIndex.value = currentMonth.value - 1;
storeIncome.value = await StoresAPIs.getStoresBusinessStatistic();
isLoading.value = false;
super.onInit();
}
// @override
// void onReady() async {
// super.onReady();
// }
}
class SalesData {
SalesData(this.year, this.sales);
final String year;
final double sales;
}
Editor is loading...