feat : sale in the province

This commit is contained in:
MrM
2025-06-27 18:08:53 +03:30
parent 701e8e0fbe
commit 751d48c02e
13 changed files with 1542 additions and 1896 deletions

View File

@@ -11,6 +11,14 @@ extension xStringUtils on String {
get faItem => utilsMap[this] ?? this;
get buyerIsGuild {
final tmp = split('_');
if (tmp.length > 1) {
return tmp.last == 'guild';
} else {
return false;
}
}
}
Map<String, String> utilsMap = {
@@ -21,5 +29,5 @@ Map<String, String> utilsMap = {
'free': 'آزاد',
'pending': 'در انتظار',
'accepted': 'تایید شده',
'guild':'صنف'
'guild': 'صنف',
};

View File

@@ -10,7 +10,8 @@ import 'package:rasadyar_core/core.dart';
class OutOfProvinceLogic extends GetxController {
var rootLogic = Get.find<RootLogic>();
Rxn<AllocatedMadeModel> allocatedMadeModel = Rxn<AllocatedMadeModel>();
Rxn<List<AllocatedMadeModel>?> allocatedMadeModel =
Rxn<List<AllocatedMadeModel>?>();
RxList<ProductModel> rolesProductsModel = RxList<ProductModel>();
RxList<GuildModel> guildsModel = <GuildModel>[].obs;
@@ -29,11 +30,16 @@ class OutOfProvinceLogic extends GetxController {
safeCall(
call: () async => await rootLogic.chickenRepository.getAllocatedMade(
token: rootLogic.tokenService.accessToken.value!,
page: 1,
queryParameters: buildQueryParams(
page: 1,
pageSize: 20,
search: 'filter',
role: 'Steward',
),
),
onSuccess: (result) {
if (result != null) {
allocatedMadeModel.value = result;
allocatedMadeModel.value = result.results;
}
},
onError: (error, stacktrace) {},
@@ -73,8 +79,7 @@ class OutOfProvinceLogic extends GetxController {
call: () async => await rootLogic.chickenRepository.confirmAllAllocation(
token: rootLogic.tokenService.accessToken.value!,
allocationTokens:
allocatedMadeModel.value?.results?.map((e) => e.key!).toList() ??
[],
allocatedMadeModel.value?.map((e) => e.key!).toList() ?? [],
),
onSuccess: (result) {
getAllocatedMade();

View File

@@ -6,6 +6,7 @@ import 'package:rasadyar_chicken/data/repositories/chicken_repository.dart';
import 'package:rasadyar_chicken/data/repositories/chicken_repository_imp.dart';
import 'package:rasadyar_chicken/presentation/pages/home/view.dart';
import 'package:rasadyar_chicken/presentation/pages/out_of_province/view.dart';
import 'package:rasadyar_chicken/presentation/pages/sales_in_province/view.dart';
import 'package:rasadyar_chicken/presentation/utils/utils.dart';
import 'package:rasadyar_core/core.dart';
@@ -14,7 +15,7 @@ enum ErrorLocationType { serviceDisabled, permissionDenied, none }
class RootLogic extends GetxController {
RxInt currentPage = 2.obs;
List<Widget> pages = [
Container(color: Colors.red),
SalesInProvincePage(),
OutOfProvincePage(),
HomePage(),
Container(color: Colors.blue),

View File

@@ -11,7 +11,10 @@ import 'package:rasadyar_core/core.dart';
class SalesInProvinceLogic extends GetxController {
var rootLogic = Get.find<RootLogic>();
Rxn<AllocatedMadeModel> allocatedMadeModel = Rxn<AllocatedMadeModel>();
Rxn<List<AllocatedMadeModel>?> allocatedMadeModel =
Rxn<List<AllocatedMadeModel>?>();
RxList<int> isExpandedList = <int>[].obs;
RxList<ProductModel> rolesProductsModel = RxList<ProductModel>();
RxList<GuildModel> guildsModel = <GuildModel>[].obs;
@@ -86,15 +89,21 @@ class SalesInProvinceLogic extends GetxController {
safeCall(
call: () async => await rootLogic.chickenRepository.getAllocatedMade(
token: rootLogic.tokenService.accessToken.value!,
page: currentPageAllocationsMade.value,
queryParameters: buildQueryParams(
page: currentPageAllocationsMade.value,
pageSize: 20,
search: 'filter',
role: 'Steward',
),
),
onSuccess: (result) {
if (result != null) {
if (isLoadingMoreAllocationsMade.value &&
allocatedMadeModel.value?.results != null) {
allocatedMadeModel.value?.results?.addAll(result.results!);
allocatedMadeModel.value != null &&
(allocatedMadeModel.value?.isNotEmpty ?? false)) {
allocatedMadeModel.value?.addAll(result.results!);
} else {
allocatedMadeModel.value = result;
allocatedMadeModel.value = result.results;
}
}
@@ -146,8 +155,7 @@ class SalesInProvinceLogic extends GetxController {
call: () async => await rootLogic.chickenRepository.confirmAllAllocation(
token: rootLogic.tokenService.accessToken.value!,
allocationTokens:
allocatedMadeModel.value?.results?.map((e) => e.key!).toList() ??
[],
allocatedMadeModel.value?.map((e) => e.key!).toList() ?? [],
),
onSuccess: (result) {
getAllocatedMade();
@@ -164,6 +172,7 @@ class SalesInProvinceLogic extends GetxController {
onSuccess: (result) {
if (result != null) {
rolesProductsModel.value = result;
selectedProductModel.value = result.first;
}
},
onError: (error, stacktrace) {},
@@ -174,7 +183,10 @@ class SalesInProvinceLogic extends GetxController {
safeCall(
call: () async => await rootLogic.chickenRepository.getGuilds(
token: rootLogic.tokenService.accessToken.value!,
isFree: saleType.value == 2 ? true : false,
queryParameters: buildQueryParams(
queryParams: {'free': saleType.value == 2 ? true : false},
role: 'Steward',
),
),
onSuccess: (result) {
if (result != null) {
@@ -242,11 +254,12 @@ class SalesInProvinceLogic extends GetxController {
);
}
@override
void dispose() {
rootLogic.inventoryExpandedList.clear();
super.dispose();
}
//TODO
void setEditData(AllocatedMadeModel item) {}
}

View File

@@ -106,272 +106,11 @@ class SalesOutOfProvincePage extends GetView<SalesOutOfProvinceLogic> {
),
],
),
),
);
}, controller.currentIndex);
}
Widget salePage(){
return SizedBox();
}
/*
Widget saleListWidget() {
return ObxValue((data) {
switch (data.value.status) {
case Status.initial:
case Status.loading:
return Center(child: CupertinoActivityIndicator());
case Status.success:
return ListView.separated(
shrinkWrap: true,
physics: BouncingScrollPhysics(),
padding: EdgeInsets.fromLTRB(8, 8, 18, 80),
itemBuilder: (context, index) {
return ObxValue(
(expandList) => saleListItem(expandList: expandList, index: index, item: data.value.data![index]),
controller.isExpandedList,
);
},
separatorBuilder: (context, index) => SizedBox(height: 8),
itemCount: data.value.data?.length ?? 0,
);
case Status.error:
return Center(
child: Text(
data.value.message ?? 'خطا در دریافت اطلاعات',
style: AppFonts.yekan16.copyWith(color: AppColor.error),
),
);
case Status.empty:
return emptyWidget();
}
}, controller.purchaseOutOfProvinceList);
}
*/
/* GestureDetector saleListItem({required RxList<int> expandList, required int index, required StewardFreeBar item}) {
return GestureDetector(
onTap: () {
if (expandList.contains(index)) {
controller.isExpandedList.remove(index);
} else {
controller.isExpandedList.add(index);
}
},
child: AnimatedSize(
duration: Duration(milliseconds: 400),
alignment: Alignment.center,
child: Stack(
clipBehavior: Clip.none,
alignment: Alignment.centerRight,
children: [
AnimatedSize(
duration: Duration(milliseconds: 300),
child: Container(
width: Get.width - 30,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.transparent,
borderRadius: BorderRadius.circular(8),
border: Border.all(width: 0.5, color: AppColor.darkGreyNormal),
),
child: AnimatedCrossFade(
alignment: Alignment.center,
firstChild: Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(width: 12),
Expanded(
flex: 2,
child: Text(
item.date?.formattedJalaliDate ?? 'N/A',
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(color: AppColor.bgDark),
),
),
Expanded(
flex: 3,
child: Text(
item.killHouseName ?? 'N/A',
textAlign: TextAlign.center,
style: AppFonts.yekan12.copyWith(color: AppColor.blueNormal),
),
),
SizedBox(width: 8,),
Expanded(
flex: 2,
child: Column(
children: [
Text(
'${item.weightOfCarcasses?.separatedByComma}kg',
textAlign: TextAlign.left,
style: AppFonts.yekan12.copyWith(color: AppColor.blueNormal),
),
SizedBox(height: 2,),
Visibility(
visible: item.product?.name?.contains('مرغ گرم') ?? false,
child: Assets.vec.hotChickenSvg.svg(width: 24,
height: 24,
colorFilter: ColorFilter.mode(AppColor.blueNormal, BlendMode.srcIn))),
],
),
),
Expanded(
flex: 2,
child: Text(
'${item.province}\n${item.city}',
textAlign: TextAlign.center,
style: AppFonts.yekan12.copyWith(color: AppColor.bgDark),
),
),
Icon(CupertinoIcons.chevron_down, size: 12),
SizedBox(width: 8),
],
),
),
secondChild: Container(
padding: EdgeInsets.fromLTRB(8, 12, 14, 12),
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8)),
child: Column(
spacing: 8,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
GestureDetector(
onTap: () {
controller.setEditData(item);
Get.bottomSheet(
addPurchasedInformationBottomSheet(true),
isScrollControlled: true,
).whenComplete(() {
controller.resetSubmitForm();
});
},
child: Assets.vec.editSvg.svg(
width: 20,
height: 20,
colorFilter: ColorFilter.mode(AppColor.blueNormal, BlendMode.srcIn),
),
),
Text(
'${item.province}-${item.city}',
textAlign: TextAlign.center,
style: AppFonts.yekan16.copyWith(color: AppColor.greenDark),
),
GestureDetector(
onTap: () {
// buildDeleteDialog(
// onConfirm: () => controller.deleteStewardPurchaseOutOfProvince(item.key!),
// );
},
child: Assets.vec.trashSvg.svg(
width: 20,
height: 20,
colorFilter: ColorFilter.mode(AppColor.error, BlendMode.srcIn),
),
),
],
),
Container(
height: 32,
padding: EdgeInsets.symmetric(horizontal: 4),
decoration: ShapeDecoration(
color: AppColor.blueLight,
shape: RoundedRectangleBorder(
side: BorderSide(width: 1, color: AppColor.blueLightHover),
borderRadius: BorderRadius.circular(8),
),
),
child: buildRow('تاریخ', item.date?.formattedJalaliDateYHMS ?? 'N/A'),
),
buildRow('مشخصات فروشنده', '${item.killHouseName} - ${item.killHouseMobile ?? 'N/A'}'),
buildRow('محصول', item.product?.name ?? 'N/A'),
buildRow('وزن خریداری شده', '${item.weightOfCarcasses?.separatedByComma} کیلوگرم'),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
GestureDetector(
onTap: () {
Get.bottomSheet(
BaseBottomSheet(
height: 400,
child: Column(
spacing: 16,
children: [
Text(
'بارنامه',
style: AppFonts.yekan16Bold.copyWith(color: AppColor.darkGreyDarkHover),
),
Image.network(
item.barImage ?? '',
fit: BoxFit.cover,
height: 300,
errorBuilder: (context, error, stackTrace) {
eLog(error.toString());
return Center(child: Text('خطایی پیش آمده!'));
},
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress == null) return child;
print('Loading progress: $loadingProgress');
return CupertinoActivityIndicator();
},
),
],
),
),
);
},
child: Text(
'مشاهده بارنامه', style: AppFonts.yekan14.copyWith(color: AppColor.blueNormal)),
),
Icon(CupertinoIcons.chevron_up, size: 12),
],
),
],
),
),
crossFadeState: expandList.contains(index) ? CrossFadeState.showSecond : CrossFadeState.showFirst,
duration: Duration(milliseconds: 300),
),
),
),
Positioned(
right: -12,
child: Container(
width: index < 999 ? 24 : null,
height: index < 999 ? 24 : null,
padding: EdgeInsets.all(2),
decoration: BoxDecoration(
color: AppColor.greenLightHover,
borderRadius: BorderRadius.circular(4),
border: Border.all(width: 0.50, color: AppColor.greenDarkActive),
),
alignment: Alignment.center,
child: Text((index + 1).toString(), style: AppFonts.yekan12.copyWith(color: Colors.black)),
),
),
],
),
),
);
}*/
Row routePageWidget() {
return Row(
children: [
@@ -431,246 +170,6 @@ class SalesOutOfProvincePage extends GetView<SalesOutOfProvinceLogic> {
);
}
/* Widget addPurchasedInformationBottomSheet([bool isOnEdit = false]) {
return BaseBottomSheet(
child: SingleChildScrollView(
child: Form(
key: controller.formKey,
child: Column(
spacing: 16,
children: [
Text(
isOnEdit ? 'ویرایش اطلاعات خرید' : 'ثبت اطلاعات خرید',
style: AppFonts.yekan16Bold.copyWith(color: AppColor.darkGreyDarkHover),
),
_productTypeWidget(),
RTextField(
controller: controller.sellerNameController,
label: 'نام فروشنده',
borderColor: AppColor.darkGreyLight,
),
RTextField(
controller: controller.sellerPhoneController,
label: 'تلفن فروشنده',
keyboardType: TextInputType.phone,
borderColor: AppColor.darkGreyLight,
maxLength: 11,
validator: (value) {
if (value == null || value.isEmpty) {
return 'لطفاً شماره موبایل را وارد کنید';
}
// حذف کاماها برای اعتبارسنجی
String cleaned = value.replaceAll(',', '');
if (cleaned.length != 11) {
return 'شماره موبایل باید ۱۱ رقم باشد';
}
if (!cleaned.startsWith('09')) {
return 'شماره موبایل باید با 09 شروع شود';
}
return null;
},
),
_provinceWidget(),
_cityWidget(),
RTextField(
controller: controller.carcassWeightController,
label: 'وزن لاشه',
keyboardType: TextInputType.number,
borderColor: AppColor.darkGreyLight,
inputFormatters: [FilteringTextInputFormatter.digitsOnly, SeparatorInputFormatter()],
),
_imageCarcasesWidget(isOnEdit),
submitButtonWidget(isOnEdit),
SizedBox(),
],
),
),
),
);
}*/
/* Widget submitButtonWidget(bool isOnEdit) {
return ObxValue((data) {
return RElevated(
text: isOnEdit ? 'ویرایش' : 'ثبت خرید',
onPressed: data.value
? () async {
var res = await controller.createStewardPurchaseOutOfProvince();
if (res) {
Get.back();
}
}
: null,
height: 40,
);
}, controller.isSubmitButtonEnabled);
}*/
Widget _productTypeWidget() {
tLog(controller.outOfTheProvinceLogic.rolesProductsModel);
iLog(controller.selectedProduct.value);
return Obx(() {
return OverlayDropdownWidget<ProductModel>(
items: controller.outOfTheProvinceLogic.rolesProductsModel,
onChanged: (value) {
controller.selectedProduct.value = value;
},
selectedItem: controller.selectedProduct.value,
initialValue: controller.selectedProduct.value,
itemBuilder: (item) => Text(item.name ?? 'بدون نام'),
labelBuilder: (item) => Text(item?.name ?? 'انتخاب محصول'),
);
});
}
Widget _provinceWidget() {
return Obx(() {
return OverlayDropdownWidget<IranProvinceCityModel>(
items: controller.rootLogic.provinces,
onChanged: (value) {
controller.selectedProvince.value = value;
print('Selected Product: ${value.name}');
},
selectedItem: controller.selectedProvince.value,
itemBuilder: (item) => Text(item.name ?? 'بدون نام'),
labelBuilder: (item) => Text(item?.name ?? 'انتخاب استان'),
);
});
}
Widget _cityWidget() {
return ObxValue((data) {
return OverlayDropdownWidget<IranProvinceCityModel>(
items: data,
onChanged: (value) {
controller.selectedCity.value = value;
print('Selected Product: ${value.name}');
},
selectedItem: controller.selectedCity.value,
itemBuilder: (item) => Text(item.name ?? 'بدون نام'),
labelBuilder: (item) => Text(item?.name ?? 'انتخاب شهر'),
);
}, controller.cites);
}
/* SizedBox _imageCarcasesWidget(bool isOnEdit) {
return SizedBox(
width: Get.width,
height: 250,
child: Card(
color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
Expanded(
child: ObxValue((data) {
return Container(
width: Get.width,
decoration: BoxDecoration(color: AppColor.lightGreyNormal, borderRadius: BorderRadius.circular(8)),
child: Center(
child: isOnEdit
? Image.network(controller.editImageUrl.value ?? '')
: data.value == null
? Assets.images.placeHolder.image(height: 150, width: 200)
: Image.file(File(data.value!.path), fit: BoxFit.cover),
),
);
}, controller.selectedImage),
),
SizedBox(height: 15),
Container(
width: Get.width,
height: 40,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('تصویر بار', style: AppFonts.yekan16Bold.copyWith(color: AppColor.blueNormal)),
Spacer(),
GestureDetector(
onTap: () async {
controller.selectedImage.value = await controller.imagePicker.pickImage(
source: ImageSource.camera,
imageQuality: 60,
maxWidth: 1080,
maxHeight: 720,
);
},
child: Container(
decoration: ShapeDecoration(
color: AppColor.blueNormal,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
padding: EdgeInsetsGeometry.symmetric(horizontal: 6, vertical: 4),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('دوربین', style: AppFonts.yekan14.copyWith(color: Colors.white)),
SizedBox(width: 8),
Icon(CupertinoIcons.camera, color: Colors.white),
],
),
),
),
SizedBox(width: 16),
GestureDetector(
onTap: () async {
controller.selectedImage.value = await controller.imagePicker.pickImage(
source: ImageSource.gallery,
imageQuality: 60,
maxWidth: 1080,
maxHeight: 720,
);
},
child: Container(
decoration: ShapeDecoration(
color: AppColor.blueNormal,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
padding: EdgeInsetsGeometry.symmetric(horizontal: 6, vertical: 4),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('گالری', style: AppFonts.yekan14.copyWith(color: Colors.white)),
SizedBox(width: 8),
Icon(CupertinoIcons.photo, color: Colors.white),
],
),
),
),
],
),
),
],
),
),
),
);
}*/
/* Future<void> buildDeleteDialog({required Future<void> Function() onConfirm}) async {
await Get.defaultDialog(
title: 'حذف خرید',
middleText: 'آیا از حذف این خرید مطمئن هستید؟',
confirm: ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: AppColor.error, foregroundColor: Colors.white),
onPressed: () async {
await onConfirm();
Get.back();
},
child: Text('بله'),
),
cancel: ElevatedButton(
onPressed: () {
Get.back();
},
child: Text('خیر'),
),
).whenComplete(() => controller.getStewardPurchaseOutOfProvince());
}
*/
Widget filterBottomSheet() {
return BaseBottomSheet(
height: 250,
@@ -806,5 +305,4 @@ class SalesOutOfProvincePage extends GetView<SalesOutOfProvinceLogic> {
);
}
}