feat: add otp code for sell order
fix: form for segmentation
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rasadyar_chicken/data/models/response/broadcast_price/broadcast_price.dart';
|
||||
import 'package:rasadyar_chicken/data/models/response/guild/guild_model.dart';
|
||||
import 'package:rasadyar_chicken/data/models/response/roles_products/roles_products.dart';
|
||||
import 'package:rasadyar_chicken/data/models/response/segmentation_model/segmentation_model.dart';
|
||||
@@ -23,7 +24,7 @@ class SegmentationLogic extends GetxController {
|
||||
Rx<Jalali> toDateFilter = Jalali.now().obs;
|
||||
RxnString searchedValue = RxnString();
|
||||
RxInt segmentType = 1.obs;
|
||||
RxInt saleType = 2.obs;
|
||||
RxInt priceType = 2.obs;
|
||||
RxInt quotaType = 2.obs;
|
||||
GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
||||
TextEditingController weightController = TextEditingController(text: '0');
|
||||
@@ -31,14 +32,15 @@ class SegmentationLogic extends GetxController {
|
||||
Rxn<GuildModel> selectedGuildModel = Rxn<GuildModel>();
|
||||
Rxn<ProductModel> selectedProduct = Rxn<ProductModel>();
|
||||
Rxn<SegmentationModel> selectedSegment = Rxn<SegmentationModel>();
|
||||
|
||||
Rxn<BroadcastPrice> broadcastPrice = Rxn<BroadcastPrice>();
|
||||
Rx<Resource<PaginationModel<SegmentationModel>>> segmentationList =
|
||||
Resource<PaginationModel<SegmentationModel>>.loading().obs;
|
||||
|
||||
RxList<GuildModel> guildsModel = <GuildModel>[].obs;
|
||||
Rx<Jalali> saleDate = Jalali.now().obs;
|
||||
|
||||
Rxn<Jalali?> productionDate = Rxn(null);
|
||||
RxInt weight = 0.obs;
|
||||
Rxn<Jalali> productionDate = Rxn(null);
|
||||
Rxn<int> remainingStock = Rxn(null);
|
||||
Map<String, DayData> freeProductionDateData = {};
|
||||
Map<String, DayData> governmentalProductionDateData = {};
|
||||
|
||||
@@ -50,6 +52,10 @@ class SegmentationLogic extends GetxController {
|
||||
getAllSegmentation();
|
||||
getGuilds();
|
||||
|
||||
ever(quotaType, (_) {
|
||||
remainingStock.value = null;
|
||||
productionDate.value = null;
|
||||
});
|
||||
_updateGovernmentalProductionDateData();
|
||||
_updateFreeProductionDateData();
|
||||
ever(rootLogic.stewardRemainWeight, (callback) {
|
||||
@@ -100,7 +106,7 @@ class SegmentationLogic extends GetxController {
|
||||
time: Duration(milliseconds: timeDebounce),
|
||||
);
|
||||
|
||||
everAll([selectedSegment, quotaType, saleType], (_) {
|
||||
everAll([selectedSegment, quotaType, priceType], (_) {
|
||||
validateForm();
|
||||
});
|
||||
|
||||
@@ -116,27 +122,22 @@ class SegmentationLogic extends GetxController {
|
||||
weightController.text = '0';
|
||||
selectedSegment.value = null;
|
||||
selectedGuildModel.value = null;
|
||||
productionDate.value = Jalali.now();
|
||||
productionDate.value = null;
|
||||
segmentType.value = 1;
|
||||
saleType.value = 2;
|
||||
priceType.value = 2;
|
||||
quotaType.value = 1;
|
||||
remainingStock.value = null;
|
||||
}
|
||||
|
||||
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("میزان وزن تخیصصی شده بیشتر از وزن باقیمانده است!");
|
||||
}
|
||||
|
||||
var weight = int.tryParse(weightController.text.trim().clearComma) ?? 0;
|
||||
var hasWeight = (remainingStock.value ?? 0) > weight;
|
||||
isSubmitButtonEnabled.value =
|
||||
selectedProduct.value != null &&
|
||||
weightController.text.isNotEmpty &&
|
||||
hasWeight &&
|
||||
weight! > 0 &&
|
||||
productionDate.value != null &&
|
||||
weight > 0 &&
|
||||
(segmentType.value == 1 || (segmentType.value == 2 && selectedGuildModel.value != null));
|
||||
}
|
||||
|
||||
@@ -229,7 +230,7 @@ class SegmentationLogic extends GetxController {
|
||||
SegmentationModel segmentationModel = SegmentationModel(
|
||||
productKey: selectedProduct.value?.key,
|
||||
weight: int.tryParse(weightController.text.clearComma) ?? 0,
|
||||
saleType: saleType.value == 1 ? 'governmental' : 'free',
|
||||
saleType: priceType.value == 1 ? 'governmental' : 'free',
|
||||
quota: quotaType.value == 1 ? 'governmental' : 'free',
|
||||
);
|
||||
if (segmentType.value == 2) {
|
||||
@@ -282,10 +283,26 @@ class SegmentationLogic extends GetxController {
|
||||
currentPage.value = 1;
|
||||
await rootLogic.onRefresh();
|
||||
await getAllSegmentation();
|
||||
await getBroadcastPrice();
|
||||
_updateFreeProductionDateData();
|
||||
_updateGovernmentalProductionDateData();
|
||||
}
|
||||
|
||||
Future<void> getBroadcastPrice() async {
|
||||
safeCall(
|
||||
call: () async => await rootLogic.chickenRepository.getBroadcastPrice(
|
||||
token: rootLogic.tokenService.accessToken.value!,
|
||||
),
|
||||
onSuccess: (result) {
|
||||
broadcastPrice.value = result;
|
||||
if (broadcastPrice.value?.active == true) {
|
||||
priceType.value = 2;
|
||||
}
|
||||
},
|
||||
onError: (error, stacktrace) {},
|
||||
);
|
||||
}
|
||||
|
||||
void toggleExpansion({int? index}) {
|
||||
if (expandedListIndex.value == index || index == null) {
|
||||
expandedListIndex.value = -1;
|
||||
|
||||
Reference in New Issue
Block a user