feat: new date picker and new logic

This commit is contained in:
2025-11-02 15:45:31 +03:30
parent 627497a840
commit 858fb48f68
13 changed files with 1090 additions and 247 deletions

View File

@@ -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}) {