fix : sale in the province

This commit is contained in:
2025-06-28 13:12:17 +03:30
parent 7bb19a7ffc
commit 9a098acf00
5 changed files with 519 additions and 482 deletions

View File

@@ -1,6 +1,8 @@
import 'package:flutter/material.dart' show Colors; import 'package:flutter/material.dart' show Colors;
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:rasadyar_auth/data/services/token_storage_service.dart'; import 'package:rasadyar_auth/data/services/token_storage_service.dart';
import 'package:rasadyar_auth/data/utils/safe_call.dart';
import 'package:rasadyar_chicken/data/models/response/inventory/inventory_model.dart';
import 'package:rasadyar_chicken/data/models/response/iran_province_city/iran_province_city_model.dart'; import 'package:rasadyar_chicken/data/models/response/iran_province_city/iran_province_city_model.dart';
import 'package:rasadyar_chicken/data/repositories/chicken_repository.dart'; import 'package:rasadyar_chicken/data/repositories/chicken_repository.dart';
import 'package:rasadyar_chicken/data/repositories/chicken_repository_imp.dart'; import 'package:rasadyar_chicken/data/repositories/chicken_repository_imp.dart';
@@ -22,15 +24,13 @@ class RootLogic extends GetxController {
Container(color: Colors.amber), Container(color: Colors.amber),
]; ];
late DioRemote dioRemote; late DioRemote dioRemote;
var tokenService = Get.find<TokenStorageService>(); var tokenService = Get.find<TokenStorageService>();
late ChickenRepository chickenRepository; late ChickenRepository chickenRepository;
RxList<ErrorLocationType> errorLocationType = RxList(); RxList<ErrorLocationType> errorLocationType = RxList();
RxMap<int, dynamic> inventoryExpandedList = RxMap(); RxMap<int, dynamic> inventoryExpandedList = RxMap();
Rxn<InventoryModel> inventoryModel = Rxn<InventoryModel>();
RxList<IranProvinceCityModel> provinces = <IranProvinceCityModel>[].obs; RxList<IranProvinceCityModel> provinces = <IranProvinceCityModel>[].obs;
@override @override
@@ -42,8 +42,8 @@ class RootLogic extends GetxController {
getProvinces(); getProvinces();
/*getInventory(); getInventory();
getKillHouseDistributionInfo();*/ //getKillHouseDistributionInfo();
} }
void toggleExpanded(int index) { void toggleExpanded(int index) {
@@ -54,6 +54,29 @@ class RootLogic extends GetxController {
} }
} }
Future<void> getInventory() async {
await safeCall<List<InventoryModel>?>(
call: () async => await chickenRepository.getInventory(token: tokenService.accessToken.value!),
onSuccess: (result) {
if (result != null) {
inventoryModel.value = result.first;
}
},
onError: (error, stackTrace) {
switch (error.response?.statusCode) {
case 401:
errorHandler(error);
break;
case 403:
errorHandler(error);
break;
default:
errorHandler(error);
}
},
);
}
void rootErrorHandler(DioException error) { void rootErrorHandler(DioException error) {
handleGeneric(error, () { handleGeneric(error, () {
tokenService.deleteTokens(); tokenService.deleteTokens();
@@ -75,4 +98,10 @@ class RootLogic extends GetxController {
provinces.clear(); provinces.clear();
} }
} }
void errorHandler(DioException error) {
handleGeneric(error, () {
tokenService.deleteTokens();
});
}
} }

View File

@@ -11,14 +11,18 @@ import 'package:rasadyar_core/core.dart';
class SalesInProvinceLogic extends GetxController { class SalesInProvinceLogic extends GetxController {
var rootLogic = Get.find<RootLogic>(); var rootLogic = Get.find<RootLogic>();
Rxn<List<AllocatedMadeModel>?> allocatedMadeModel = Rxn<List<AllocatedMadeModel>?> allocatedMadeModel = Rxn<List<AllocatedMadeModel>?>();
Rxn<List<AllocatedMadeModel>?>();
RxList<int> isExpandedList = <int>[].obs; RxList<int> isExpandedList = <int>[].obs;
RxList<ProductModel> rolesProductsModel = RxList<ProductModel>(); RxList<ProductModel> rolesProductsModel = RxList<ProductModel>();
RxBool searchIsSelected = false.obs;
RxnString searchedValue = RxnString();
RxList<GuildModel> guildsModel = <GuildModel>[].obs; RxList<GuildModel> guildsModel = <GuildModel>[].obs;
GlobalKey<FormState> formKey = GlobalKey<FormState>();
Rxn<Jalali> fromDateFilter = Rxn<Jalali>(null);
Rxn<Jalali> toDateFilter = Rxn<Jalali>(null);
Rxn<ProductModel> selectedProductModel = Rxn<ProductModel>(); Rxn<ProductModel> selectedProductModel = Rxn<ProductModel>();
Rxn<GuildModel> selectedGuildModel = Rxn<GuildModel>(); Rxn<GuildModel> selectedGuildModel = Rxn<GuildModel>();
Rxn<GuildProfile> guildProfile = Rxn<GuildProfile>(); Rxn<GuildProfile> guildProfile = Rxn<GuildProfile>();
@@ -37,8 +41,8 @@ class SalesInProvinceLogic extends GetxController {
final RxBool addPageAllocationsMade = false.obs; final RxBool addPageAllocationsMade = false.obs;
final RxBool hasMoreDataAllocationsMade = true.obs; final RxBool hasMoreDataAllocationsMade = true.obs;
Rxn<AllocatedMadeModel> selectedAllocationModelForUpdate = Rxn<AllocatedMadeModel> selectedAllocationModelForUpdate = Rxn<AllocatedMadeModel>();
Rxn<AllocatedMadeModel>(); SubmitStewardAllocation? tmpStewardAllocation;
@override @override
void onInit() { void onInit() {
@@ -51,17 +55,16 @@ class SalesInProvinceLogic extends GetxController {
ever(saleType, (callback) { ever(saleType, (callback) {
getGuilds(); getGuilds();
}); });
debounce(weight, time: Duration(milliseconds: 110), (callback) {
weight.listen((num) { totalCost.value = callback * weight.value;
totalCost.value = num * pricePerKilo.value;
}); });
pricePerKilo.listen((num) { debounce(pricePerKilo, time: Duration(milliseconds: 100), (callback) {
totalCost.value = num * weight.value; totalCost.value = callback * weight.value;
}); });
totalCost.listen((data) { totalCost.listen((data) {
totalCostController.text = data.toString(); totalCostController.text = data.toString().separatedByComma;
isValid.value = isValid.value =
weight.value > 0 && weight.value > 0 &&
@@ -78,15 +81,23 @@ class SalesInProvinceLogic extends GetxController {
getAllocatedMade(); getAllocatedMade();
} }
}); });
debounce(searchedValue, (callback) => getAllocatedMade(), time: Duration(milliseconds: 2000));
ever(searchIsSelected, (data) {
if (data == false) {
searchedValue.value = null;
}
});
} }
Future<void> getAllocatedMade() async { Future<void> getAllocatedMade() async {
if (isLoadingMoreAllocationsMade.value || if (isLoadingMoreAllocationsMade.value || !hasMoreDataAllocationsMade.value) {
!hasMoreDataAllocationsMade.value) {
return; return;
} }
if (addPageAllocationsMade.value) { if (searchIsSelected.value) {
currentPageAllocationsMade.value = 1;
} else if (addPageAllocationsMade.value) {
currentPageAllocationsMade.value++; currentPageAllocationsMade.value++;
} }
safeCall( safeCall(
@@ -97,6 +108,7 @@ class SalesInProvinceLogic extends GetxController {
pageSize: 20, pageSize: 20,
search: 'filter', search: 'filter',
role: 'Steward', role: 'Steward',
value: searchedValue.value,
), ),
), ),
onSuccess: (result) { onSuccess: (result) {
@@ -157,8 +169,7 @@ class SalesInProvinceLogic extends GetxController {
safeCall( safeCall(
call: () async => await rootLogic.chickenRepository.confirmAllAllocation( call: () async => await rootLogic.chickenRepository.confirmAllAllocation(
token: rootLogic.tokenService.accessToken.value!, token: rootLogic.tokenService.accessToken.value!,
allocationTokens: allocationTokens: allocatedMadeModel.value?.map((e) => e.key!).toList() ?? [],
allocatedMadeModel.value?.map((e) => e.key!).toList() ?? [],
), ),
onSuccess: (result) { onSuccess: (result) {
getAllocatedMade(); getAllocatedMade();
@@ -169,9 +180,8 @@ class SalesInProvinceLogic extends GetxController {
Future<void> getRolesProducts() async { Future<void> getRolesProducts() async {
safeCall( safeCall(
call: () async => await rootLogic.chickenRepository.getRolesProducts( call: () async =>
token: rootLogic.tokenService.accessToken.value!, await rootLogic.chickenRepository.getRolesProducts(token: rootLogic.tokenService.accessToken.value!),
),
onSuccess: (result) { onSuccess: (result) {
if (result != null) { if (result != null) {
rolesProductsModel.value = result; rolesProductsModel.value = result;
@@ -186,10 +196,7 @@ class SalesInProvinceLogic extends GetxController {
safeCall( safeCall(
call: () async => await rootLogic.chickenRepository.getGuilds( call: () async => await rootLogic.chickenRepository.getGuilds(
token: rootLogic.tokenService.accessToken.value!, token: rootLogic.tokenService.accessToken.value!,
queryParameters: buildQueryParams( queryParameters: buildQueryParams(queryParams: {'free': saleType.value == 2 ? true : false}, role: 'Steward'),
queryParams: {'free': saleType.value == 2 ? true : false},
role: 'Steward',
),
), ),
onSuccess: (result) { onSuccess: (result) {
if (result != null) { if (result != null) {
@@ -215,9 +222,7 @@ class SalesInProvinceLogic extends GetxController {
Future<void> getGuildProfile() async { Future<void> getGuildProfile() async {
await safeCall( await safeCall(
call: () async => await rootLogic.chickenRepository.getProfile( call: () async => await rootLogic.chickenRepository.getProfile(token: rootLogic.tokenService.accessToken.value!),
token: rootLogic.tokenService.accessToken.value!,
),
onError: (error, stackTrace) {}, onError: (error, stackTrace) {},
onSuccess: (result) { onSuccess: (result) {
guildProfile.value = result; guildProfile.value = result;
@@ -225,30 +230,31 @@ class SalesInProvinceLogic extends GetxController {
); );
} }
Future<void> submitAllocation() async { void setSubmitData() {
SubmitStewardAllocation stewardAllocation = SubmitStewardAllocation( tmpStewardAllocation = SubmitStewardAllocation(
approvedPriceStatus: false, approvedPriceStatus: false,
allocationType: allocationType:
'${guildProfile.value?.steward == true ? "steward" : "guild"}-${selectedGuildModel.value?.steward == true ? "steward" : "guild"}', '${guildProfile.value?.steward == true ? "steward" : "guild"}_${selectedGuildModel.value?.steward == true ? "steward" : "guild"}',
sellerType: guildProfile.value?.steward == true ? "Steward" : "Guild", sellerType: guildProfile.value?.steward == true ? "Steward" : "Guild",
buyerType: selectedGuildModel.value?.steward == true buyerType: selectedGuildModel.value?.steward == true ? "Steward" : "Guild",
? "Steward"
: "Guild",
amount: pricePerKilo.value, amount: pricePerKilo.value,
totalAmount: totalCost.value, totalAmount: totalCost.value,
weightOfCarcasses: weight.value, weightOfCarcasses: weight.value,
sellType:saleType.value ==2 ? "free" :'exclusive',
numberOfCarcasses: 0,
guildKey: selectedGuildModel.value?.key, guildKey: selectedGuildModel.value?.key,
productKey: selectedProductModel.value?.key, productKey: selectedProductModel.value?.key,
date: DateTime.now().formattedGregorianDate, date: DateTime.now().formattedDashedGregorian,
type: "manual", type: "manual",
); );
}
Future<void> submitAllocation() async {
safeCall( safeCall(
call: () async => call: () async => await rootLogic.chickenRepository.postSubmitStewardAllocation(
await rootLogic.chickenRepository.postSubmitStewardAllocation( token: rootLogic.tokenService.accessToken.value!,
token: rootLogic.tokenService.accessToken.value!, request: tmpStewardAllocation!,
request: stewardAllocation, ),
),
onSuccess: (result) { onSuccess: (result) {
getAllocatedMade(); getAllocatedMade();
@@ -259,11 +265,10 @@ class SalesInProvinceLogic extends GetxController {
Future<void> deleteAllocation(AllocatedMadeModel model) async { Future<void> deleteAllocation(AllocatedMadeModel model) async {
safeCall( safeCall(
call: () async => call: () async => await rootLogic.chickenRepository.deleteStewardAllocation(
await rootLogic.chickenRepository.deleteStewardAllocation( token: rootLogic.tokenService.accessToken.value!,
token: rootLogic.tokenService.accessToken.value!, queryParameters: {'steward_allocation_key': model.key},
queryParameters: {'steward_allocation_key': model.key}, ),
),
onSuccess: (result) { onSuccess: (result) {
getAllocatedMade(); getAllocatedMade();
@@ -286,9 +291,7 @@ class SalesInProvinceLogic extends GetxController {
pricePerKilo.value = item.amount ?? 0; pricePerKilo.value = item.amount ?? 0;
totalCost.value = item.totalAmount ?? 0; totalCost.value = item.totalAmount ?? 0;
weightController.text = weight.value.toString().separatedByComma; weightController.text = weight.value.toString().separatedByComma;
pricePerKiloController.text = pricePerKilo.value pricePerKiloController.text = pricePerKilo.value.toString().separatedByComma;
.toString()
.separatedByComma;
totalCostController.text = totalCost.value.toString().separatedByComma; totalCostController.text = totalCost.value.toString().separatedByComma;
isValid.value = true; isValid.value = true;
} }
@@ -314,11 +317,10 @@ class SalesInProvinceLogic extends GetxController {
); );
safeCall( safeCall(
call: () async => call: () async => await rootLogic.chickenRepository.updateStewardAllocation(
await rootLogic.chickenRepository.updateStewardAllocation( token: rootLogic.tokenService.accessToken.value!,
token: rootLogic.tokenService.accessToken.value!, request: updatedAllocationModel,
request: updatedAllocationModel, ),
),
onSuccess: (result) { onSuccess: (result) {
getAllocatedMade(); getAllocatedMade();

View File

@@ -1,38 +1,35 @@
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:persian_datetime_picker/persian_datetime_picker.dart'; import 'package:persian_datetime_picker/persian_datetime_picker.dart';
extension XDateTime on String{ extension XDateTime on String {
get toDateTime => DateTime.parse(this); get toDateTime => DateTime.parse(this);
get formattedJalaliDate{ String get formattedJalaliDate {
final dateTime = DateTime.parse(this); String tmp = contains("/") ? replaceAll("/", "-") : this;
final dateTime = DateTime.parse(tmp);
final jalaliDate = Jalali.fromDateTime(dateTime); final jalaliDate = Jalali.fromDateTime(dateTime);
return "${jalaliDate.year}/${jalaliDate.month.toString().padLeft(2, '0')}/${jalaliDate.day.toString().padLeft(2, '0')}"; return "${jalaliDate.year}/${jalaliDate.month.toString().padLeft(2, '0')}/${jalaliDate.day.toString().padLeft(2, '0')}";
} }
get formattedJalaliDateYHMS { String get formattedJalaliDateYHMS {
final dateTime = DateTime.parse(this); final dateTime = DateTime.parse(this);
final jalaliDate = Jalali.fromDateTime(dateTime); final jalaliDate = Jalali.fromDateTime(dateTime);
return "${jalaliDate.hour.toString().padLeft(2, '0')}:${jalaliDate.minute.toString().padLeft(2, '0')} - ${jalaliDate.year}/${jalaliDate.month.toString().padLeft(2, '0')}/${jalaliDate.day.toString().padLeft(2, '0')}"; return "${jalaliDate.hour.toString().padLeft(2, '0')}:${jalaliDate.minute.toString().padLeft(2, '0')} - ${jalaliDate.year}/${jalaliDate.month.toString().padLeft(2, '0')}/${jalaliDate.day.toString().padLeft(2, '0')}";
} }
String get formattedYHMS {
get formattedYHMS{
return DateFormat('yyyy-MM-dd HH:mm:ss').format(toDateTime); return DateFormat('yyyy-MM-dd HH:mm:ss').format(toDateTime);
} }
} }
extension XDateTime2 on DateTime {
get formattedJalaliDate {
extension XDateTime2 on DateTime{
get formattedJalaliDate{
final jalaliDate = Jalali.fromDateTime(this); final jalaliDate = Jalali.fromDateTime(this);
return "${jalaliDate.year}/${jalaliDate.month.toString().padLeft(2, '0')}/${jalaliDate.day.toString().padLeft(2, '0')}"; return "${jalaliDate.year}/${jalaliDate.month.toString().padLeft(2, '0')}/${jalaliDate.day.toString().padLeft(2, '0')}";
} }
get formattedYHMS{ get formattedYHMS {
return DateFormat('yyyy-MM-dd HH:mm:ss').format(this); return DateFormat('yyyy-MM-dd HH:mm:ss').format(this);
} }
} }

View File

@@ -7,7 +7,7 @@ extension XString on String {
return number != null ? formatter.format(number) : this; return number != null ? formatter.format(number) : this;
} }
get clearComma { String get clearComma {
return replaceAll(RegExp(r'\D'), ''); return replaceAll(RegExp(r'\D'), '');
} }
} }