feat: new date picker and new logic
This commit is contained in:
@@ -23,7 +23,7 @@ class SegmentationLogic extends GetxController {
|
||||
RxnString searchedValue = RxnString();
|
||||
RxInt segmentType = 1.obs;
|
||||
RxInt saleType = 2.obs;
|
||||
RxInt quotaType = 1.obs;
|
||||
RxInt quotaType = 2.obs;
|
||||
GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
||||
TextEditingController weightController = TextEditingController(text: '0');
|
||||
RxBool isSubmitButtonEnabled = false.obs;
|
||||
@@ -35,9 +35,12 @@ class SegmentationLogic extends GetxController {
|
||||
Resource<PaginationModel<SegmentationModel>>.loading().obs;
|
||||
|
||||
RxList<GuildModel> guildsModel = <GuildModel>[].obs;
|
||||
Rxn<Jalali?> productionData = Rxn();
|
||||
Rx<Jalali> saleDate = Jalali.now().obs;
|
||||
|
||||
Rxn<Jalali?> productionDate = Rxn(null);
|
||||
Map<String, DayData> freeProductionDateData = {};
|
||||
Map<String, DayData> governmentalProductionDateData = {};
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
@@ -45,6 +48,46 @@ class SegmentationLogic extends GetxController {
|
||||
once(rootLogic.rolesProductsModel, (callback) => selectedProduct.value = callback.first);
|
||||
getAllSegmentation();
|
||||
getGuilds();
|
||||
|
||||
_updateGovernmentalProductionDateData();
|
||||
_updateFreeProductionDateData();
|
||||
|
||||
ever(rootLogic.stewardSalesInfoDashboard, (callback) {
|
||||
_updateGovernmentalProductionDateData();
|
||||
_updateFreeProductionDateData();
|
||||
});
|
||||
}
|
||||
|
||||
void _updateGovernmentalProductionDateData() {
|
||||
var today = Jalali.now();
|
||||
governmentalProductionDateData = {
|
||||
today.formatCompactDate(): DayData(
|
||||
value: rootLogic.stewardSalesInfoDashboard.value?.totalGovernmentalRemainWeight?.toInt(),
|
||||
),
|
||||
|
||||
today.addDays(-1).formatCompactDate(): DayData(
|
||||
value: rootLogic.stewardSalesInfoDashboard.value?.totalGovernmentalRemainWeight?.toInt(),
|
||||
),
|
||||
|
||||
today.addDays(-2).formatCompactDate(): DayData(
|
||||
value: rootLogic.stewardSalesInfoDashboard.value?.totalGovernmentalRemainWeight?.toInt(),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
void _updateFreeProductionDateData() {
|
||||
var today = Jalali.now();
|
||||
freeProductionDateData = {
|
||||
today.formatCompactDate(): DayData(
|
||||
value: rootLogic.stewardSalesInfoDashboard.value?.totalFreeRemainWeight?.toInt(),
|
||||
),
|
||||
today.addDays(-1).formatCompactDate(): DayData(
|
||||
value: rootLogic.stewardSalesInfoDashboard.value?.totalFreeRemainWeight?.toInt(),
|
||||
),
|
||||
today.addDays(-2).formatCompactDate(): DayData(
|
||||
value: rootLogic.stewardSalesInfoDashboard.value?.totalFreeRemainWeight?.toInt(),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -55,7 +98,6 @@ class SegmentationLogic extends GetxController {
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
// TODO: implement onClose
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
@@ -69,7 +111,8 @@ class SegmentationLogic extends GetxController {
|
||||
(callback) => getAllSegmentation(),
|
||||
time: Duration(milliseconds: timeDebounce),
|
||||
);
|
||||
ever(selectedSegment, (_) {
|
||||
|
||||
everAll([selectedSegment, quotaType, saleType], (_) {
|
||||
validateForm();
|
||||
});
|
||||
|
||||
@@ -85,17 +128,26 @@ class SegmentationLogic extends GetxController {
|
||||
weightController.text = '0';
|
||||
selectedSegment.value = null;
|
||||
selectedGuildModel.value = null;
|
||||
productionData.value = null;
|
||||
productionDate.value = Jalali.now();
|
||||
segmentType.value = 1;
|
||||
saleType.value = 1;
|
||||
saleType.value = 2;
|
||||
quotaType.value = 1;
|
||||
}
|
||||
|
||||
void validateForm() {
|
||||
var weight = int.tryParse(weightController.text.trim().clearComma);
|
||||
var hasWeight = quotaType.value == 2
|
||||
? ((weight ?? 0) <= (rootLogic.stewardSalesInfoDashboard.value?.totalFreeRemainWeight ?? 0))
|
||||
: ((weight ?? 0) <=
|
||||
(rootLogic.stewardSalesInfoDashboard.value?.totalGovernmentalRemainWeight ?? 0));
|
||||
if (!hasWeight) {
|
||||
defaultShowErrorMessage("میزان وزن تخیصصی شده بیشتر از وزن باقیمانده است!");
|
||||
}
|
||||
|
||||
isSubmitButtonEnabled.value =
|
||||
selectedProduct.value != null &&
|
||||
weightController.text.isNotEmpty &&
|
||||
hasWeight &&
|
||||
weight! > 0 &&
|
||||
(segmentType.value == 1 || (segmentType.value == 2 && selectedGuildModel.value != null));
|
||||
}
|
||||
@@ -115,7 +167,6 @@ class SegmentationLogic extends GetxController {
|
||||
|
||||
await safeCall(
|
||||
showError: true,
|
||||
showSuccess: true,
|
||||
call: () async => await rootLogic.chickenRepository.getSegmentation(
|
||||
token: rootLogic.tokenService.accessToken.value!,
|
||||
queryParameters: buildQueryParams(
|
||||
@@ -171,7 +222,7 @@ class SegmentationLogic extends GetxController {
|
||||
model: SegmentationModel(
|
||||
key: selectedSegment.value?.key,
|
||||
weight: int.tryParse(weightController.text.clearComma) ?? 0,
|
||||
productionDate: productionData.value?.toDateTime().formattedDashedGregorian,
|
||||
productionDate: productionDate.value?.toDateTime().formattedDashedGregorian,
|
||||
),
|
||||
),
|
||||
onSuccess: (result) {
|
||||
@@ -196,22 +247,24 @@ class SegmentationLogic extends GetxController {
|
||||
if (segmentType.value == 2) {
|
||||
segmentationModel = segmentationModel.copyWith(guildKey: selectedGuildModel.value?.key);
|
||||
}
|
||||
if (productionData.value != null) {
|
||||
segmentationModel = segmentationModel.copyWith(
|
||||
productionDate: productionData.value?.toDateTime().formattedDashedGregorian,
|
||||
);
|
||||
}
|
||||
segmentationModel = segmentationModel.copyWith(
|
||||
productionDate: productionDate.value?.toDateTime().formattedDashedGregorian,
|
||||
);
|
||||
await safeCall(
|
||||
showError: true,
|
||||
showSuccess: true,
|
||||
call: () async => await rootLogic.chickenRepository.createSegmentation(
|
||||
token: rootLogic.tokenService.accessToken.value!,
|
||||
model: segmentationModel,
|
||||
),
|
||||
onSuccess: (result) {
|
||||
onSuccess: (result) async {
|
||||
res = true;
|
||||
isSubmitButtonEnabled.value = true;
|
||||
isSubmitButtonEnabled.value = false;
|
||||
onRefresh();
|
||||
Future.delayed(
|
||||
Duration(seconds: 1),
|
||||
() => defaultShowSuccessMessage("قطعهبندی با موفقیت ثبت شد!"),
|
||||
);
|
||||
Get.back();
|
||||
},
|
||||
onError: (error, stacktrace) {
|
||||
res = false;
|
||||
@@ -241,6 +294,8 @@ class SegmentationLogic extends GetxController {
|
||||
currentPage.value = 1;
|
||||
await rootLogic.onRefresh();
|
||||
await getAllSegmentation();
|
||||
_updateFreeProductionDateData();
|
||||
_updateGovernmentalProductionDateData();
|
||||
}
|
||||
|
||||
void toggleExpansion({int? index}) {
|
||||
|
||||
@@ -10,6 +10,10 @@ import 'package:rasadyar_core/core.dart';
|
||||
import 'logic.dart';
|
||||
|
||||
class SegmentationPage extends GetView<SegmentationLogic> {
|
||||
final today = Jalali.now();
|
||||
final oneDayAgo = Jalali.now().addDays(-1);
|
||||
final twoDaysAgo = Jalali.now().addDays(-2);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ChickenBasePage(
|
||||
@@ -342,24 +346,6 @@ class SegmentationPage extends GetView<SegmentationLogic> {
|
||||
],
|
||||
),
|
||||
),
|
||||
ObxValue((data) {
|
||||
return RTextField(
|
||||
controller: TextEditingController(),
|
||||
filledColor: AppColor.bgLight,
|
||||
filled: true,
|
||||
label: 'تاریخ تولید گوشت',
|
||||
onTap: () {
|
||||
Get.bottomSheet(
|
||||
modalDatePicker((value) {
|
||||
controller.productionData.value = value;
|
||||
controller.productionData.refresh();
|
||||
}),
|
||||
);
|
||||
},
|
||||
borderColor: AppColor.darkGreyLight,
|
||||
initText: data.value?.formatCompactDate(),
|
||||
);
|
||||
}, controller.productionData),
|
||||
|
||||
Container(
|
||||
height: 50.h,
|
||||
@@ -458,13 +444,46 @@ class SegmentationPage extends GetView<SegmentationLogic> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
controller.quotaType.value = 1;
|
||||
},
|
||||
onTap:
|
||||
(controller
|
||||
.rootLogic
|
||||
.stewardSalesInfoDashboard
|
||||
.value
|
||||
?.totalGovernmentalRemainWeight ??
|
||||
-1) >
|
||||
0
|
||||
? () {
|
||||
controller.quotaType.value = 1;
|
||||
}
|
||||
: null,
|
||||
child: Row(
|
||||
children: [
|
||||
Radio(value: 1),
|
||||
Text('انبار دولتی', style: AppFonts.yekan14),
|
||||
Radio(
|
||||
value: 1,
|
||||
enabled:
|
||||
(controller
|
||||
.rootLogic
|
||||
.stewardSalesInfoDashboard
|
||||
.value
|
||||
?.totalGovernmentalRemainWeight ??
|
||||
-1) >
|
||||
0,
|
||||
),
|
||||
Text(
|
||||
'انبار دولتی',
|
||||
style: AppFonts.yekan14.copyWith(
|
||||
color:
|
||||
((controller
|
||||
.rootLogic
|
||||
.stewardSalesInfoDashboard
|
||||
.value
|
||||
?.totalGovernmentalRemainWeight ??
|
||||
-1) >
|
||||
0)
|
||||
? AppColor.textColor
|
||||
: AppColor.labelTextColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -472,13 +491,46 @@ class SegmentationPage extends GetView<SegmentationLogic> {
|
||||
|
||||
Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
controller.quotaType.value = 2;
|
||||
},
|
||||
onTap:
|
||||
(controller
|
||||
.rootLogic
|
||||
.stewardSalesInfoDashboard
|
||||
.value
|
||||
?.totalFreeRemainWeight ??
|
||||
-1) >
|
||||
0
|
||||
? () {
|
||||
controller.quotaType.value = 2;
|
||||
}
|
||||
: null,
|
||||
child: Row(
|
||||
children: [
|
||||
Radio(value: 2),
|
||||
Text('انبار آزاد', style: AppFonts.yekan14),
|
||||
Radio(
|
||||
value: 2,
|
||||
enabled:
|
||||
(controller
|
||||
.rootLogic
|
||||
.stewardSalesInfoDashboard
|
||||
.value
|
||||
?.totalFreeRemainWeight ??
|
||||
-1) >
|
||||
0,
|
||||
),
|
||||
Text(
|
||||
'انبار آزاد',
|
||||
style: AppFonts.yekan14.copyWith(
|
||||
color:
|
||||
((controller
|
||||
.rootLogic
|
||||
.stewardSalesInfoDashboard
|
||||
.value
|
||||
?.totalFreeRemainWeight ??
|
||||
-1) >
|
||||
0)
|
||||
? AppColor.textColor
|
||||
: AppColor.labelTextColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -490,6 +542,17 @@ class SegmentationPage extends GetView<SegmentationLogic> {
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Obx(() {
|
||||
return MonthlyDataCalendar(
|
||||
label: 'تاریخ تولید گوشت',
|
||||
selectedDate: controller.productionDate.value?.formatCompactDate(),
|
||||
onDateSelect: (value) => controller.productionDate..value = value.date,
|
||||
dayData: controller.quotaType.value == 1
|
||||
? controller.governmentalProductionDateData
|
||||
: controller.freeProductionDateData,
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -609,6 +672,7 @@ class SegmentationPage extends GetView<SegmentationLogic> {
|
||||
}
|
||||
|
||||
Container modalDatePicker(ValueChanged<Jalali> onDateSelected) {
|
||||
Jalali currentDate = Jalali.now();
|
||||
Jalali? tempPickedDate;
|
||||
return Container(
|
||||
height: 250,
|
||||
@@ -652,6 +716,14 @@ class SegmentationPage extends GetView<SegmentationLogic> {
|
||||
child: PersianCupertinoDatePicker(
|
||||
initialDateTime: controller.saleDate.value,
|
||||
mode: PersianCupertinoDatePickerMode.date,
|
||||
maximumDate: currentDate.addDays(3),
|
||||
minimumDate: currentDate
|
||||
.toDateTime()
|
||||
.subtract(Duration(days: 1))
|
||||
.toString()
|
||||
.toJalali,
|
||||
maximumYear: currentDate.year,
|
||||
minimumYear: currentDate.year,
|
||||
onDateTimeChanged: (dateTime) {
|
||||
tempPickedDate = dateTime;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user