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

@@ -69,21 +69,21 @@ class ProfilePage extends GetView<ProfileLogic> {
),
Expanded(
flex: 3,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
rolesWidget(),
SizedBox(height: 12.h),
children: [
rolesWidget(),
SizedBox(height: 12.h),
ObxValue((data) {
if (data.value.status == ResourceStatus.loading) {
return LoadingWidget();
} else if (data.value.status == ResourceStatus.error) {
return ErrorWidget('خطا در دریافت اطلاعات کاربر');
} else if (data.value.status == ResourceStatus.success) {
return SingleChildScrollView(
child: Column(
ObxValue((data) {
if (data.value.status == ResourceStatus.loading) {
return LoadingWidget();
} else if (data.value.status == ResourceStatus.error) {
return ErrorWidget('خطا در دریافت اطلاعات کاربر');
} else if (data.value.status == ResourceStatus.success) {
return Column(
spacing: 6,
children: [
ObxValue((isOpen) {
@@ -122,75 +122,75 @@ class ProfilePage extends GetView<ProfileLogic> {
}, controller.isUnitInformationOpen),
),
],
);
} else {
return SizedBox.shrink();
}
}, controller.userProfile),
GestureDetector(
onTap: () {
Get.bottomSheet(changePasswordBottomSheet(), isScrollControlled: true);
},
child: Container(
height: 47.h,
margin: EdgeInsets.symmetric(horizontal: 8, vertical: 8.h),
padding: EdgeInsets.symmetric(horizontal: 11.h, vertical: 8.h),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
border: Border.all(width: 1, color: const Color(0xFFD6D6D6)),
),
child: Row(
spacing: 6,
children: [
Assets.vec.lockSvg.svg(
width: 24.w,
height: 24.h,
colorFilter: ColorFilter.mode(AppColor.blueNormal, BlendMode.srcIn),
),
Text(
'تغییر رمز عبور',
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(color: AppColor.blueNormal),
),
],
),
);
} else {
return SizedBox.shrink();
}
}, controller.userProfile),
GestureDetector(
onTap: () {
Get.bottomSheet(changePasswordBottomSheet(), isScrollControlled: true);
},
child: Container(
height: 47.h,
margin: EdgeInsets.symmetric(horizontal: 8, vertical: 8.h),
padding: EdgeInsets.symmetric(horizontal: 11.h, vertical: 8.h),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
border: Border.all(width: 1, color: const Color(0xFFD6D6D6)),
),
child: Row(
spacing: 6,
children: [
Assets.vec.lockSvg.svg(
width: 24.w,
height: 24.h,
colorFilter: ColorFilter.mode(AppColor.blueNormal, BlendMode.srcIn),
),
Text(
'تغییر رمز عبور',
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(color: AppColor.blueNormal),
),
],
),
),
),
GestureDetector(
onTap: () {
Get.bottomSheet(exitBottomSheet(), isScrollControlled: true);
},
child: Container(
height: 47.h,
margin: EdgeInsets.symmetric(horizontal: 8),
padding: EdgeInsets.symmetric(horizontal: 11.h, vertical: 8.h),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
border: Border.all(width: 1, color: const Color(0xFFD6D6D6)),
),
child: Row(
spacing: 6,
children: [
Assets.vec.logoutSvg.svg(
width: 24.w,
height: 24.h,
colorFilter: ColorFilter.mode(AppColor.redNormal, BlendMode.srcIn),
),
Text(
'خروج',
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(color: AppColor.redNormal),
),
],
GestureDetector(
onTap: () {
Get.bottomSheet(exitBottomSheet(), isScrollControlled: true);
},
child: Container(
height: 47.h,
margin: EdgeInsets.symmetric(horizontal: 8),
padding: EdgeInsets.symmetric(horizontal: 11.h, vertical: 8.h),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
border: Border.all(width: 1, color: const Color(0xFFD6D6D6)),
),
child: Row(
spacing: 6,
children: [
Assets.vec.logoutSvg.svg(
width: 24.w,
height: 24.h,
colorFilter: ColorFilter.mode(AppColor.redNormal, BlendMode.srcIn),
),
Text(
'خروج',
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(color: AppColor.redNormal),
),
],
),
),
),
),
SizedBox(height: 100),
],
SizedBox(height: 100),
],
),
),
),
],

View File

@@ -35,12 +35,11 @@ class SalesInProvinceLogic extends GetxController {
Rx<Jalali> fromDateFilter = Jalali.now().obs;
Rx<Jalali> toDateFilter = Jalali.now().obs;
Rxn<Jalali?> productionData = Rxn();
Rxn<ProductModel> selectedProductModel = Rxn<ProductModel>();
Rxn<GuildModel> selectedGuildModel = Rxn<GuildModel>();
Rxn<GuildProfile> guildProfile = Rxn<GuildProfile>();
RxInt saleType = 1.obs;
RxInt priceType = 1.obs;
RxInt priceType = 2.obs;
RxInt quotaType = 1.obs;
RxInt weight = 0.obs;
RxInt pricePerKilo = 0.obs;
@@ -59,6 +58,10 @@ class SalesInProvinceLogic extends GetxController {
Rxn<AllocatedMadeModel> selectedAllocationModelForUpdate = Rxn<AllocatedMadeModel>();
SubmitStewardAllocation? tmpStewardAllocation;
Rxn<Jalali> productionDate = Rxn(null);
Map<String, DayData> freeProductionDateData = {};
Map<String, DayData> governmentalProductionDateData = {};
@override
void onInit() {
super.onInit();
@@ -97,6 +100,7 @@ class SalesInProvinceLogic extends GetxController {
totalCost,
selectedProductModel,
selectedGuildModel,
productionDate,
], (callback) => checkVerification());
scrollControllerAllocationsMade.addListener(() {
@@ -112,6 +116,45 @@ class SalesInProvinceLogic extends GetxController {
(callback) => getAllocatedMade(),
time: Duration(milliseconds: timeDebounce),
);
_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(),
),
};
}
Future<void> getAllocatedMade([bool isLoadingMore = false]) async {
@@ -168,10 +211,18 @@ class SalesInProvinceLogic extends GetxController {
}
void checkVerification() {
var hasWeight = quotaType.value == 1
? weight.value <=
(governmentalProductionDateData[productionDate.value?.formatCompactDate()]?.value ??
0)
: weight.value <=
(freeProductionDateData[productionDate.value?.formatCompactDate()]?.value ?? 0);
isValid.value =
weight.value > 0 &&
pricePerKilo.value > 0 &&
totalCost.value > 0 &&
hasWeight &&
selectedProductModel.value != null &&
selectedGuildModel.value != null;
}
@@ -285,7 +336,7 @@ class SalesInProvinceLogic extends GetxController {
weightOfCarcasses: weight.value,
sellType: saleType.value == 2 ? "free" : 'exclusive',
numberOfCarcasses: 0,
productionDate: productionData.value?.toDateTime().formattedDashedGregorian,
productionDate: productionDate.value?.toDateTime().formattedDashedGregorian,
quota: quotaType.value == 1 ? 'governmental' : 'free',
guildKey: selectedGuildModel.value?.key,
productKey: selectedProductModel.value?.key,
@@ -308,6 +359,8 @@ class SalesInProvinceLogic extends GetxController {
clearForm();
onRefresh();
rootLogic.onRefresh();
Future.delayed(Duration(seconds: 1), () => defaultShowSuccessMessage("ثبت موفق بود"));
Get.back();
},
onError: (error, stackTrace) {},
);
@@ -345,7 +398,7 @@ class SalesInProvinceLogic extends GetxController {
pricePerKiloController.text = pricePerKilo.value.toString().separatedByComma;
totalCostController.text = totalCost.value.toString().separatedByComma;
isValid.value = true;
productionData.value = item.productionDate.toJalali;
productionDate.value = item.productionDate.toJalali;
}
void clearForm() {
@@ -359,7 +412,10 @@ class SalesInProvinceLogic extends GetxController {
}
totalCostController.clear();
isValid.value = false;
productionData.value = null;
productionDate.value = null;
quotaType.value = 1;
priceType.value = 2;
saleType.value = 2;
}
Future<void> updateAllocation() async {
@@ -382,6 +438,8 @@ class SalesInProvinceLogic extends GetxController {
clearForm();
onRefresh();
rootLogic.onRefresh();
Future.delayed(Duration(seconds: 1), () => defaultShowSuccessMessage("ویرایش موفق بود"));
Get.back();
},
onError: (error, stackTrace) {},
);
@@ -427,6 +485,7 @@ class SalesInProvinceLogic extends GetxController {
if (broadcastPrice.value?.active == true) {
pricePerKilo.value = broadcastPrice.value?.stewardPrice ?? 0;
pricePerKiloController.text = pricePerKilo.value.toString().separatedByComma;
priceType.value = 2;
}
},
onError: (error, stacktrace) {},

View File

@@ -404,7 +404,7 @@ class SalesInProvincePage extends GetView<SalesInProvinceLogic> {
Widget addOrEditBottomSheet([bool isEditMode = false]) {
return BaseBottomSheet(
height: Get.height * (isEditMode ? 0.55 : 0.75),
height: Get.height * (isEditMode ? 0.60 : 0.75),
child: Form(
key: controller.formKey,
child: Column(
@@ -528,32 +528,25 @@ class SalesInProvincePage extends GetView<SalesInProvinceLogic> {
label: 'وزن لاشه (کیلوگرم)',
),
ObxValue((data) {
return RTextField(
controller: TextEditingController(),
filledColor: AppColor.bgLight,
filled: true,
Obx(() {
return MonthlyDataCalendar(
label: 'تاریخ تولید گوشت',
onTap: () {
Get.bottomSheet(
modalDatePicker((value) {
controller.productionData.value = value;
controller.productionData.refresh();
}),
);
selectedDate: controller.productionDate.value?.formatCompactDate(),
onDateSelect: (value) {
controller.productionDate.value = value.date;
},
borderColor: AppColor.darkGreyLight,
initText: data.value?.formatCompactDate(),
dayData: controller.quotaType.value == 1
? controller.governmentalProductionDateData
: controller.freeProductionDateData,
);
}, controller.productionData),
}),
Visibility(
visible: isEditMode == false,
child: Column(
spacing: 12,
children: [
SizedBox(height: 12.h),
SizedBox(height: 12),
Container(
height: 58.h,
height: 50.h,
clipBehavior: Clip.none,
decoration: BoxDecoration(
color: Colors.white,
@@ -574,26 +567,102 @@ class SalesInProvincePage extends GetView<SalesInProvinceLogic> {
return RadioGroup(
groupValue: controller.quotaType.value,
onChanged: (value) {
controller.quotaType.value = value!;
controller.quotaType.value = value ?? 0;
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
child: Row(
children: [
Radio(value: 1),
Text('انبار دولتی', style: AppFonts.yekan14),
],
child: GestureDetector(
onTap:
(controller
.rootLogic
.stewardSalesInfoDashboard
.value
?.totalGovernmentalRemainWeight ??
-1) >
0
? () {
controller.quotaType.value = 1;
}
: null,
child: Row(
children: [
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,
),
),
],
),
),
),
Expanded(
child: Row(
children: [
Radio(value: 2),
Text('انبار آزاد', style: AppFonts.yekan14),
],
child: GestureDetector(
onTap:
(controller
.rootLogic
.stewardSalesInfoDashboard
.value
?.totalFreeRemainWeight ??
-1) >
0
? () {
controller.quotaType.value = 2;
}
: null,
child: Row(
children: [
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,
),
),
],
),
),
),
],
@@ -603,7 +672,7 @@ class SalesInProvincePage extends GetView<SalesInProvinceLogic> {
],
),
),
SizedBox(height: 12.h),
SizedBox(height: 12),
Container(
height: 58.h,
clipBehavior: Clip.none,
@@ -631,20 +700,46 @@ class SalesInProvincePage extends GetView<SalesInProvinceLogic> {
child: Row(
children: [
Expanded(
child: Row(
children: [
Radio(value: 1),
Text('قیمت دولتی', style: AppFonts.yekan14),
],
child: GestureDetector(
onTap: (controller.broadcastPrice.value?.active ?? false)
? () {
controller.priceType.value = 1;
}
: null,
child: Row(
children: [
Radio(
value: 1,
enabled:
controller.broadcastPrice.value?.active ??
false,
),
Text(
'قیمت دولتی',
style: AppFonts.yekan14.copyWith(
color:
(controller.broadcastPrice.value?.active ??
false)
? AppColor.textColor
: AppColor.labelTextColor,
),
),
],
),
),
),
Expanded(
child: Row(
children: [
Radio(value: 2),
Text('قیمت آزاد', style: AppFonts.yekan14),
],
child: GestureDetector(
onTap: () {
controller.priceType.value = 2;
},
child: Row(
children: [
Radio(value: 2),
Text('قیمت آزاد', style: AppFonts.yekan14),
],
),
),
),
],
@@ -657,30 +752,25 @@ class SalesInProvincePage extends GetView<SalesInProvinceLogic> {
],
),
),
Obx(() {
return Visibility(
visible: controller.broadcastPrice.value?.active == true,
child: RTextField(
variant: RTextFieldVariant.noBorder,
controller: controller.pricePerKiloController,
borderColor: AppColor.darkGreyLight,
inputFormatters: [
FilteringTextInputFormatter.digitsOnly,
SeparatorInputFormatter(),
],
filledColor: AppColor.bgLight,
filled: true,
enabled:
(controller.priceType.value == 2 ||
(controller.selectedProductModel.value?.approvedPriceStatus == false)),
onChanged: (p0) {
controller.pricePerKilo.value = int.tryParse(p0.clearComma) ?? 0;
},
keyboardType: TextInputType.number,
label: 'قیمت هر کیلو (ريال)',
),
);
}),
RTextField(
variant: RTextFieldVariant.noBorder,
controller: controller.pricePerKiloController,
borderColor: AppColor.darkGreyLight,
inputFormatters: [
FilteringTextInputFormatter.digitsOnly,
SeparatorInputFormatter(),
],
filledColor: AppColor.bgLight,
filled: true,
enabled:
(controller.priceType.value == 2 ||
(controller.selectedProductModel.value?.approvedPriceStatus == false)),
onChanged: (p0) {
controller.pricePerKilo.value = int.tryParse(p0.clearComma) ?? 0;
},
keyboardType: TextInputType.number,
label: 'قیمت هر کیلو (ريال)',
),
RTextField(
variant: RTextFieldVariant.noBorder,
@@ -711,11 +801,9 @@ class SalesInProvincePage extends GetView<SalesInProvinceLogic> {
onPressed: isEditMode
? () async {
await controller.updateAllocation();
Get.back();
}
: () async {
await controller.submitAllocation();
Get.back();
},
);
}, controller.isValid),

View File

@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:rasadyar_chicken/data/models/request/steward_free_sale_bar/steward_free_sale_bar_request.dart';
import 'package:rasadyar_chicken/data/models/response/broadcast_price/broadcast_price.dart';
import 'package:rasadyar_chicken/data/models/response/iran_province_city/iran_province_city_model.dart';
import 'package:rasadyar_chicken/data/models/response/out_province_carcasses_buyer/out_province_carcasses_buyer.dart';
import 'package:rasadyar_chicken/data/models/response/roles_products/roles_products.dart';
@@ -30,7 +31,7 @@ class SalesOutOfProvinceLogic extends GetxController {
RxList<String> routesName = RxList();
RxBool isLoadingMoreAllocationsMade = false.obs;
Rxn<IranProvinceCityModel> selectedCity = Rxn();
Rxn<Jalali?> productionData = Rxn();
Rxn<BroadcastPrice> broadcastPrice = Rxn<BroadcastPrice>();
GlobalKey<FormState> formKey = GlobalKey<FormState>();
TextEditingController quarantineCodeController = TextEditingController();
TextEditingController saleWeightController = TextEditingController();
@@ -46,6 +47,9 @@ class SalesOutOfProvinceLogic extends GetxController {
RxInt saleType = 2.obs;
RxInt quotaType = 1.obs;
Rxn<Jalali> productionDate = Rxn();
Map<String, DayData> freeProductionDateData = {};
Map<String, DayData> governmentalProductionDateData = {};
@override
void onInit() {
@@ -57,6 +61,7 @@ class SalesOutOfProvinceLogic extends GetxController {
void onReady() {
super.onReady();
getOutProvinceSales();
getBroadcastPrice();
selectedProduct.value = rootLogic.rolesProductsModel.first;
debounce(
searchedValue,
@@ -64,6 +69,46 @@ class SalesOutOfProvinceLogic extends GetxController {
time: Duration(milliseconds: timeDebounce),
);
setupListeners();
_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(),
),
};
}
void setSearchValue(String? value) {
@@ -151,7 +196,7 @@ class SalesOutOfProvinceLogic extends GetxController {
saleType.value = item.saleType == 'free' ? 2 : 1;
quotaType.value = item.quota == 'governmental' ? 1 : 2;
isSaleSubmitButtonEnabled.value = true;
productionData.value = item.productionDate.toJalali;
productionDate.value = item.productionDate.toJalali;
}
Future<void> deleteStewardPurchaseOutOfProvince(String key) async {
@@ -174,6 +219,7 @@ class SalesOutOfProvinceLogic extends GetxController {
productKey: selectedProduct.value?.key,
saleType: saleType.value == 2 ? 'free' : 'exclusive',
quota: quotaType.value == 1 ? 'governmental' : 'free',
productionDate: productionDate.value?.toDateTime().formattedDashedGregorian,
);
await safeCall(
showError: true,
@@ -185,6 +231,11 @@ class SalesOutOfProvinceLogic extends GetxController {
res = true;
onRefresh();
rootLogic.onRefresh();
Future.delayed(
Duration(seconds: 1),
() => defaultShowSuccessMessage("عملیات با موفقیت انجام شد"),
);
Get.back();
},
);
return res;
@@ -194,9 +245,9 @@ class SalesOutOfProvinceLogic extends GetxController {
quarantineCodeController.clear();
saleWeightController.clear();
saleDate.value = Jalali.now();
productionData.value = null;
productionDate.value = null;
saleType.value = 2;
quotaType.value = 1;
quotaType.value = 2;
selectedBuyer.value = null;
}
@@ -219,6 +270,11 @@ class SalesOutOfProvinceLogic extends GetxController {
onSuccess: (_) {
res = true;
onRefresh();
Future.delayed(
Duration(seconds: 1),
() => defaultShowSuccessMessage("عملیات با موفقیت انجام شد"),
);
Get.back();
},
);
return res;
@@ -246,4 +302,16 @@ class SalesOutOfProvinceLogic extends GetxController {
expandedListIndex.value = index;
}
}
Future<void> getBroadcastPrice() async {
safeCall(
call: () async => await rootLogic.chickenRepository.getBroadcastPrice(
token: rootLogic.tokenService.accessToken.value!,
),
onSuccess: (result) {
broadcastPrice.value = result;
},
onError: (error, stacktrace) {},
);
}
}

View File

@@ -324,7 +324,7 @@ class SalesOutOfProvincePage extends GetView<SalesOutOfProvinceLogic> {
Widget addOrEditSaleBottomSheet([bool isOnEdit = false]) {
return BaseBottomSheet(
height: 600.h,
height: 670.h,
child: SingleChildScrollView(
child: Form(
key: controller.formKey,
@@ -357,13 +357,12 @@ class SalesOutOfProvincePage extends GetView<SalesOutOfProvinceLogic> {
Get.bottomSheet(
modalDatePicker((value) {
controller.saleDate.value = value;
controller.saleDate.refresh();
}),
);
},
borderColor: AppColor.darkGreyLight,
initText: data.value?.formatCompactDate(),
initText: data.value.formatCompactDate(),
);
}, controller.saleDate),
Visibility(visible: isOnEdit == false, child: _buyerWidget()),
@@ -386,24 +385,18 @@ class SalesOutOfProvincePage extends GetView<SalesOutOfProvinceLogic> {
child: Column(
spacing: 12,
children: [
ObxValue((data) {
return RTextField(
controller: TextEditingController(),
filledColor: AppColor.bgLight,
filled: true,
Obx(() {
return MonthlyDataCalendar(
label: 'تاریخ تولید گوشت',
onTap: () {
Get.bottomSheet(
modalDatePicker((value) {
controller.productionData.value = value;
controller.productionData.refresh();
}),
);
selectedDate: controller.productionDate.value?.formatCompactDate(),
onDateSelect: (value) {
controller.productionDate.value = value.date;
},
borderColor: AppColor.darkGreyLight,
initText: data.value?.formatCompactDate(),
dayData: controller.quotaType.value == 1
? controller.governmentalProductionDateData
: controller.freeProductionDateData,
);
}, controller.productionData),
}),
Container(
height: 50.h,
@@ -434,13 +427,46 @@ class SalesOutOfProvincePage extends GetView<SalesOutOfProvinceLogic> {
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,
),
),
],
),
),
@@ -448,13 +474,46 @@ class SalesOutOfProvincePage extends GetView<SalesOutOfProvinceLogic> {
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,
),
),
],
),
),
@@ -496,13 +555,30 @@ class SalesOutOfProvincePage extends GetView<SalesOutOfProvinceLogic> {
children: [
Expanded(
child: GestureDetector(
onTap: () {
controller.saleType.value = 1;
},
onTap:
(controller.broadcastPrice.value?.active ?? false)
? () {
controller.saleType.value = 1;
}
: null,
child: Row(
children: [
Radio(value: 1),
Text('قیمت دولتی', style: AppFonts.yekan14),
Radio(
value: 1,
enabled:
(controller.broadcastPrice.value?.active ??
false),
),
Text(
'قیمت دولتی',
style: AppFonts.yekan14.copyWith(
color:
(controller.broadcastPrice.value?.active ??
false)
? AppColor.textColor
: AppColor.labelTextColor,
),
),
],
),
),
@@ -594,9 +670,6 @@ class SalesOutOfProvincePage extends GetView<SalesOutOfProvinceLogic> {
onPressed: data.value
? () async {
var res = isOnEdit ? await controller.editSale() : await controller.createSale();
if (res) {
Get.back();
}
}
: null,
height: 40,

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

View File

@@ -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;
},