Files
rasadyar_application/packages/chicken/lib/presentation/pages/steward/segmentation/view.dart

738 lines
30 KiB
Dart
Raw Normal View History

2025-07-13 16:17:17 +03:30
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
2025-07-21 09:16:13 +03:30
import 'package:rasadyar_chicken/data/models/response/guild/guild_model.dart';
2025-07-13 16:17:17 +03:30
import 'package:rasadyar_chicken/data/models/response/roles_products/roles_products.dart';
import 'package:rasadyar_chicken/data/models/response/segmentation_model/segmentation_model.dart';
import 'package:rasadyar_chicken/presentation/widget/base_page/view.dart';
import 'package:rasadyar_chicken/presentation/widget/filter_bottom_sheet.dart';
import 'package:rasadyar_core/core.dart';
import 'logic.dart';
class SegmentationPage extends GetView<SegmentationLogic> {
2025-11-02 15:45:31 +03:30
final today = Jalali.now();
final oneDayAgo = Jalali.now().addDays(-1);
final twoDaysAgo = Jalali.now().addDays(-2);
2025-07-13 16:17:17 +03:30
@override
Widget build(BuildContext context) {
2025-09-24 21:42:22 +03:30
return ChickenBasePage(
2025-07-13 16:17:17 +03:30
routes: controller.routesName,
onSearchChanged: (data) => controller.setSearchValue(data),
2025-09-27 14:32:33 +03:30
onFilterTap: () {
Get.bottomSheet(filterBottomSheet());
},
2025-10-07 14:21:09 +03:30
onRefresh: controller.onRefresh,
2025-07-15 09:03:11 +03:30
hasBack: false,
2025-10-01 11:07:47 +03:30
child: Stack(
children: [
2025-10-06 10:57:46 +03:30
Positioned.fill(
child: ObxValue((data) {
return RPaginatedListView(
onLoadMore: () async => controller.getAllSegmentation(true),
hasMore: data.value.data?.next != null,
listType: ListType.separated,
resource: data.value,
padding: EdgeInsets.fromLTRB(8, 8, 8, 80),
itemBuilder: (context, index) {
var item = data.value.data!.results![index];
return ObxValue((val) {
return ExpandableListItem2(
2025-10-12 12:48:20 +03:30
selected: val.value == index,
onTap: () => controller.toggleExpansion(index: index),
2025-10-06 10:57:46 +03:30
index: index,
child: itemListWidget(item),
secondChild: itemListExpandedWidget(item, index),
labelColor: AppColor.blueLight,
labelIconColor: AppColor.customGrey,
labelIcon: Assets.vec.convertCubeSvg.path,
);
2025-10-12 12:48:20 +03:30
}, controller.expandedListIndex);
2025-10-06 10:57:46 +03:30
},
itemCount: data.value.data?.results?.length ?? 0,
separatorBuilder: (context, index) => SizedBox(height: 8.h),
);
}, controller.segmentationList),
),
2025-10-01 11:07:47 +03:30
Positioned(
2025-10-06 10:57:46 +03:30
right: 10,
bottom: 90.h,
child: RFab.add(
onPressed: () {
Get.bottomSheet(
addOrEditBottomSheet(),
isScrollControlled: true,
ignoreSafeArea: false,
).whenComplete(() {
controller.clearForm();
//defaultShowSuccessMessage('با موفقیت ثبت شد');
});
},
),
),
2025-10-01 11:07:47 +03:30
],
2025-07-13 16:17:17 +03:30
),
);
}
Widget filterBottomSheet() => filterBottomSheetWidget(
fromDate: controller.fromDateFilter,
onChangedFromDate: (jalali) => controller.fromDateFilter.value = jalali,
toDate: controller.toDateFilter,
onChangedToDate: (jalali) => controller.toDateFilter.value = jalali,
onSubmit: () => controller.getAllSegmentation(),
);
itemListWidget(SegmentationModel item) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(width: 12),
Expanded(
flex: 3,
2025-07-21 12:04:43 +03:30
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
spacing: 4,
children: [
Text(
item.toGuild != null ? 'قطعه‌بند' : 'مباشر',
2025-07-21 12:04:43 +03:30
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(color: AppColor.blueNormal),
),
Text(
item.date?.formattedJalaliDate ?? 'N/A',
textAlign: TextAlign.center,
style: AppFonts.yekan12.copyWith(color: AppColor.bgDark),
),
],
2025-07-13 16:17:17 +03:30
),
),
SizedBox(width: 4),
Expanded(
flex: 5,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
2025-07-21 12:04:43 +03:30
item.toGuild != null
? item.toGuild?.user?.fullname ?? 'N/A'
: item.buyer?.fullname ?? 'N/A',
2025-07-13 16:17:17 +03:30
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(color: AppColor.blueNormal),
),
SizedBox(height: 2),
Text(
2025-07-21 12:04:43 +03:30
item.toGuild != null
? item.toGuild?.guildsName ?? 'N/A'
: item.buyer?.shop ?? 'N/A',
2025-07-13 16:17:17 +03:30
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(color: AppColor.bgDark),
),
],
),
),
SizedBox(width: 4),
Expanded(
flex: 2,
child: Column(
spacing: 4,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
item.weight.separatedByCommaFa.addKg,
textAlign: TextAlign.center,
textDirection: TextDirection.ltr,
style: AppFonts.yekan14Bold.copyWith(color: AppColor.blueNormal),
),
Text(
item.saleType == "governmental" ? 'دولتی' : 'آزاد',
textAlign: TextAlign.center,
textDirection: TextDirection.ltr,
style: AppFonts.yekan14Bold.copyWith(
color: item.saleType == "governmental"
? AppColor.blueNormal
: AppColor.greenNormal,
),
),
],
2025-07-13 16:17:17 +03:30
),
),
],
);
}
itemListExpandedWidget(SegmentationModel item, int index) {
return Container(
padding: EdgeInsets.symmetric(horizontal: 8),
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8)),
child: Column(
spacing: 8,
children: [
Container(
height: 32,
padding: EdgeInsets.symmetric(horizontal: 8),
decoration: ShapeDecoration(
color: AppColor.blueLight,
shape: RoundedRectangleBorder(
side: BorderSide(width: 1, color: AppColor.blueLightHover),
borderRadius: BorderRadius.circular(8),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
spacing: 3,
children: [
Text(
DateTimeExtensions(item.date)?.toJalali().formatter.wN ?? 'N/A',
style: AppFonts.yekan14.copyWith(color: AppColor.textColor),
),
Text(
'${DateTimeExtensions(item.date)?.toJalali().formatter.d} ${DateTimeExtensions(item.date)?.toJalali().formatter.mN ?? 'N/A'}',
style: AppFonts.yekan14.copyWith(color: AppColor.blueNormal),
),
],
),
Text(
'${DateTimeExtensions(item.date)?.toJalali().formatter.y}',
style: AppFonts.yekan20.copyWith(color: AppColor.textColor),
),
Text(
'${DateTimeExtensions(item.date)?.toJalali().formatter.tHH}:${DateTimeExtensions(item.date)?.toJalali().formatter.tMM ?? 'N/A'}',
style: AppFonts.yekan14.copyWith(color: AppColor.textColor),
),
],
),
),
2025-07-21 12:04:43 +03:30
buildRow(
title: 'مشخصات خریدار',
value: item.toGuild != null
? item.toGuild?.user?.fullname ?? 'N/A'
: item.buyer?.fullname ?? 'N/A',
),
buildRow(
title: 'تلفن خریدار',
value: item.toGuild != null
? item.toGuild?.user?.mobile ?? 'N/A'
: item.buyer?.mobile ?? 'N/A',
),
buildRow(
title: 'نام واحد',
value: item.toGuild != null
? item.toGuild?.guildsName ?? 'N/A'
: item.buyer?.shop ?? 'N/A',
),
buildRow(title: 'ماهیت', value: item.toGuild != null ? 'قطعه‌بند' : 'مباشر'),
buildRow(title: 'نوع فروش', value: item.saleType == "governmental" ? 'دولتی' : 'آزاد'),
buildRow(title: 'انبار فروش', value: item.quota == "governmental" ? 'دولتی' : 'آزاد'),
buildRow(
title: 'تاریخ تولید گوشت',
value: item.productionDate?.toJalali.formatCompactDate() ?? 'ندارد',
),
2025-10-29 15:44:24 +03:30
buildRow(
title: 'وزن قطعه‌بندی',
value: item.weight!.separatedByCommaFa,
valueLabel: 'کیلوگرم',
2025-10-14 16:24:46 +03:30
),
2025-07-13 16:17:17 +03:30
Row(
mainAxisAlignment: MainAxisAlignment.center,
spacing: 16.w,
children: [
RElevated(
text: 'ویرایش',
width: 150.w,
height: 40.h,
onPressed: () {
controller.setEditData(item);
Get.bottomSheet(
addOrEditBottomSheet(true),
isScrollControlled: true,
2025-07-20 15:34:13 +03:30
ignoreSafeArea: false,
2025-07-13 16:17:17 +03:30
).whenComplete(() {
controller.clearForm();
});
},
textStyle: AppFonts.yekan20.copyWith(color: Colors.white),
backgroundColor: AppColor.greenNormal,
),
ROutlinedElevated(
text: 'حذف',
textStyle: AppFonts.yekan20.copyWith(color: AppColor.redNormal),
width: 150.w,
height: 40.h,
onPressed: () {
buildDeleteDialog(
onConfirm: () async {
2025-10-12 12:48:20 +03:30
controller.toggleExpansion();
2025-07-13 16:17:17 +03:30
controller.deleteSegmentation(item.key!);
},
onRefresh: () => controller.onRefresh(),
2025-07-13 16:17:17 +03:30
);
},
borderColor: AppColor.redNormal,
),
],
),
],
),
);
}
Widget addOrEditBottomSheet([bool isOnEdit = false]) {
return BaseBottomSheet(
height: isOnEdit ? 350.h : 650.h,
2025-07-13 16:17:17 +03:30
child: SingleChildScrollView(
child: Form(
key: controller.formKey,
child: Column(
spacing: 16,
children: [
Text(
isOnEdit ? 'ویرایش قطعه‌بندی' : 'افزودن قطعه‌بندی',
style: AppFonts.yekan16Bold.copyWith(color: AppColor.blueNormal),
),
_productDropDown(),
Visibility(
visible: isOnEdit == false,
2025-07-21 09:16:13 +03:30
child: Column(
spacing: 12,
2025-07-21 09:16:13 +03:30
children: [
Container(
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: AppColor.darkGreyLight, width: 1),
),
2025-07-21 09:16:13 +03:30
child: Column(
children: [
const SizedBox(height: 8),
SizedBox(
height: 40,
child: ObxValue((data) {
return RadioGroup(
onChanged: (value) {
controller.segmentType.value = value!;
controller.selectedGuildModel.value = null;
controller.selectedGuildModel.refresh();
},
groupValue: controller.segmentType.value,
2025-10-29 15:44:24 +03:30
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
2025-10-29 15:44:24 +03:30
children: [
Radio(value: 1),
Text('قطعه‌بندی(کاربر)', style: AppFonts.yekan14),
SizedBox(width: 12),
2025-10-29 15:44:24 +03:30
Radio(value: 2),
Text('تخصیص به قطعه‌بند', style: AppFonts.yekan14),
2025-10-29 15:44:24 +03:30
],
),
);
}, controller.saleType),
),
const SizedBox(height: 12),
ObxValue((data) {
return Visibility(visible: data.value == 2, child: guildsDropDown());
}, controller.segmentType),
],
),
2025-10-06 10:57:46 +03:30
),
Container(
height: 50.h,
clipBehavior: Clip.none,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: AppColor.darkGreyLight, width: 1),
),
child: Stack(
fit: StackFit.expand,
alignment: Alignment.center,
clipBehavior: Clip.none,
children: [
Positioned(
child: Container(color: Colors.white, child: Text("نوع فروش")),
top: -10,
right: 8,
),
Obx(() {
return RadioGroup(
groupValue: controller.saleType.value,
onChanged: (value) {
controller.saleType.value = 2 ?? 0;
controller.selectedGuildModel.value = null;
controller.selectedGuildModel.refresh();
2025-10-29 15:44:24 +03:30
},
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
2025-10-29 15:44:24 +03:30
children: [
Expanded(
child: GestureDetector(
onTap: () {
//controller.saleType.value = 1;
},
child: Row(
children: [
Radio(value: 1, enabled: false),
Text(
'قیمت دولتی',
style: AppFonts.yekan14.copyWith(
color: AppColor.mediumGreyDark,
),
),
],
),
),
),
Expanded(
child: GestureDetector(
onTap: () {
controller.saleType.value = 2;
},
child: Row(
children: [
Radio(value: 2),
Text('قیمت آزاد', style: AppFonts.yekan14),
],
),
),
),
2025-10-29 15:44:24 +03:30
],
),
);
}),
],
),
),
Container(
height: 50.h,
clipBehavior: Clip.none,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: AppColor.darkGreyLight, width: 1),
),
child: Stack(
fit: StackFit.expand,
alignment: Alignment.center,
clipBehavior: Clip.none,
children: [
Positioned(
child: Container(color: Colors.white, child: Text("نوع انبار")),
top: -10,
right: 8,
),
Obx(() {
return RadioGroup(
groupValue: controller.quotaType.value,
onChanged: (value) {
controller.quotaType.value = value ?? 0;
2025-10-29 15:44:24 +03:30
},
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
child: GestureDetector(
2025-11-02 15:45:31 +03:30
onTap:
(controller
.rootLogic
.stewardSalesInfoDashboard
.value
?.totalGovernmentalRemainWeight ??
-1) >
0
? () {
controller.quotaType.value = 1;
}
: null,
child: Row(
children: [
2025-11-02 15:45:31 +03:30
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: GestureDetector(
2025-11-02 15:45:31 +03:30
onTap:
(controller
.rootLogic
.stewardSalesInfoDashboard
.value
?.totalFreeRemainWeight ??
-1) >
0
? () {
controller.quotaType.value = 2;
}
: null,
child: Row(
children: [
2025-11-02 15:45:31 +03:30
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,
),
),
],
),
),
),
],
2025-10-29 15:44:24 +03:30
),
);
}),
],
),
),
2025-11-02 15:45:31 +03:30
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,
);
}),
2025-07-21 09:16:13 +03:30
],
),
),
2025-10-29 15:44:24 +03:30
2025-07-13 16:17:17 +03:30
Container(
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: AppColor.darkGreyLight, width: 1),
),
child: Column(
spacing: 12,
children: [
2025-07-15 09:03:11 +03:30
UnitTextField(
hint: 'وزن',
unit: 'کیلوگرم',
2025-07-13 16:17:17 +03:30
controller: controller.weightController,
inputFormatters: [
FilteringTextInputFormatter.digitsOnly,
SeparatorInputFormatter(),
],
validator: (value) {
if (value == null) {
return 'لطفاً وزن لاشه را وارد کنید';
}
return null;
},
),
submitButtonWidget(isOnEdit),
],
),
),
SizedBox(),
],
),
),
),
);
}
Widget submitButtonWidget(bool isOnEdit) {
return ObxValue((data) {
return RElevated(
isFullWidth: true,
backgroundColor: AppColor.greenNormal,
text: isOnEdit ? 'ویرایش' : 'ثبت',
onPressed: data.value
? () async {
var res = isOnEdit
? await controller.editSegment()
: await controller.createSegment();
if (res) {
Get.back();
}
}
: null,
height: 40,
);
2025-07-15 09:03:11 +03:30
}, controller.isSubmitButtonEnabled);
2025-07-13 16:17:17 +03:30
}
Widget _productDropDown() {
return Obx(() {
return OverlayDropdownWidget<ProductModel>(
2025-07-15 09:03:11 +03:30
items: controller.rootLogic.rolesProductsModel,
2025-07-13 16:17:17 +03:30
height: 56,
hasDropIcon: false,
background: Colors.white,
onChanged: (value) {
controller.selectedProduct.value = value;
},
selectedItem: controller.selectedProduct.value,
initialValue: controller.selectedProduct.value,
itemBuilder: (item) => Text(item.name ?? 'بدون نام'),
labelBuilder: (item) => Row(
spacing: 8,
children: [
(item?.name?.contains('مرغ گرم') ?? false)
? Assets.images.chicken.image(width: 40, height: 40)
: Assets.vec.placeHolderSvg.svg(width: 40, height: 40),
Text(item?.name ?? 'انتخاب محصول'),
Spacer(),
Text(
'موجودی: ${controller.rootLogic.inventoryModel.value?.totalRemainWeight.separatedByCommaFa ?? 0} کیلوگرم',
2025-07-13 16:17:17 +03:30
),
],
),
);
});
}
2025-07-21 09:16:13 +03:30
Widget guildsDropDown() {
return Obx(() {
final item = controller.selectedGuildModel.value;
return OverlayDropdownWidget<GuildModel>(
key: ValueKey(item?.user?.fullname ?? ''),
items: controller.guildsModel,
onChanged: (value) {
controller.selectedGuildModel.value = value;
},
selectedItem: item,
itemBuilder: (item) => Text(
item.user != null
? '${item.steward == true ? 'مباشر' : 'صنف'} ${item.user!.fullname} (${item.user!.mobile})'
: 'بدون نام',
),
labelBuilder: (item) => Text(
item?.user != null
? '${item?.steward == true ? 'مباشر' : 'صنف'} ${item?.user!.fullname} (${item?.user!.mobile})'
: 'انتخاب مباشر/صنف',
),
);
});
}
Container modalDatePicker(ValueChanged<Jalali> onDateSelected) {
2025-11-02 15:45:31 +03:30
Jalali currentDate = Jalali.now();
Jalali? tempPickedDate;
return Container(
height: 250,
color: Colors.white,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
child: Row(
children: [
SizedBox(width: 20),
RElevated(
height: 35,
width: 70,
textStyle: AppFonts.yekan14.copyWith(color: Colors.white),
onPressed: () {
onDateSelected(tempPickedDate ?? Jalali.now());
Get.back();
},
text: 'تایید',
),
Spacer(),
RElevated(
height: 35,
width: 70,
backgroundColor: AppColor.error,
textStyle: AppFonts.yekan14.copyWith(color: Colors.white),
onPressed: () {
onDateSelected(tempPickedDate ?? Jalali.now());
Get.back();
},
text: 'لغو',
),
SizedBox(width: 20),
],
),
),
Divider(height: 0, thickness: 1),
Expanded(
child: Container(
child: PersianCupertinoDatePicker(
initialDateTime: controller.saleDate.value,
mode: PersianCupertinoDatePickerMode.date,
2025-11-02 15:45:31 +03:30
maximumDate: currentDate.addDays(3),
minimumDate: currentDate
.toDateTime()
.subtract(Duration(days: 1))
.toString()
.toJalali,
maximumYear: currentDate.year,
minimumYear: currentDate.year,
onDateTimeChanged: (dateTime) {
tempPickedDate = dateTime;
},
),
),
),
],
),
);
}
2025-07-13 16:17:17 +03:30
}