fix : sale in the province
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import 'package:flutter/material.dart' show Colors;
|
||||
import 'package:flutter/widgets.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/repositories/chicken_repository.dart';
|
||||
import 'package:rasadyar_chicken/data/repositories/chicken_repository_imp.dart';
|
||||
@@ -22,15 +24,13 @@ class RootLogic extends GetxController {
|
||||
Container(color: Colors.amber),
|
||||
];
|
||||
|
||||
|
||||
|
||||
late DioRemote dioRemote;
|
||||
var tokenService = Get.find<TokenStorageService>();
|
||||
late ChickenRepository chickenRepository;
|
||||
|
||||
RxList<ErrorLocationType> errorLocationType = RxList();
|
||||
RxMap<int, dynamic> inventoryExpandedList = RxMap();
|
||||
|
||||
Rxn<InventoryModel> inventoryModel = Rxn<InventoryModel>();
|
||||
RxList<IranProvinceCityModel> provinces = <IranProvinceCityModel>[].obs;
|
||||
|
||||
@override
|
||||
@@ -42,8 +42,8 @@ class RootLogic extends GetxController {
|
||||
|
||||
getProvinces();
|
||||
|
||||
/*getInventory();
|
||||
getKillHouseDistributionInfo();*/
|
||||
getInventory();
|
||||
//getKillHouseDistributionInfo();
|
||||
}
|
||||
|
||||
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) {
|
||||
handleGeneric(error, () {
|
||||
tokenService.deleteTokens();
|
||||
@@ -75,4 +98,10 @@ class RootLogic extends GetxController {
|
||||
provinces.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void errorHandler(DioException error) {
|
||||
handleGeneric(error, () {
|
||||
tokenService.deleteTokens();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,14 +11,18 @@ import 'package:rasadyar_core/core.dart';
|
||||
|
||||
class SalesInProvinceLogic extends GetxController {
|
||||
var rootLogic = Get.find<RootLogic>();
|
||||
Rxn<List<AllocatedMadeModel>?> allocatedMadeModel =
|
||||
Rxn<List<AllocatedMadeModel>?>();
|
||||
Rxn<List<AllocatedMadeModel>?> allocatedMadeModel = Rxn<List<AllocatedMadeModel>?>();
|
||||
RxList<int> isExpandedList = <int>[].obs;
|
||||
|
||||
RxList<ProductModel> rolesProductsModel = RxList<ProductModel>();
|
||||
|
||||
RxBool searchIsSelected = false.obs;
|
||||
RxnString searchedValue = RxnString();
|
||||
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<GuildModel> selectedGuildModel = Rxn<GuildModel>();
|
||||
Rxn<GuildProfile> guildProfile = Rxn<GuildProfile>();
|
||||
@@ -37,8 +41,8 @@ class SalesInProvinceLogic extends GetxController {
|
||||
final RxBool addPageAllocationsMade = false.obs;
|
||||
final RxBool hasMoreDataAllocationsMade = true.obs;
|
||||
|
||||
Rxn<AllocatedMadeModel> selectedAllocationModelForUpdate =
|
||||
Rxn<AllocatedMadeModel>();
|
||||
Rxn<AllocatedMadeModel> selectedAllocationModelForUpdate = Rxn<AllocatedMadeModel>();
|
||||
SubmitStewardAllocation? tmpStewardAllocation;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
@@ -51,17 +55,16 @@ class SalesInProvinceLogic extends GetxController {
|
||||
ever(saleType, (callback) {
|
||||
getGuilds();
|
||||
});
|
||||
|
||||
weight.listen((num) {
|
||||
totalCost.value = num * pricePerKilo.value;
|
||||
debounce(weight, time: Duration(milliseconds: 110), (callback) {
|
||||
totalCost.value = callback * weight.value;
|
||||
});
|
||||
|
||||
pricePerKilo.listen((num) {
|
||||
totalCost.value = num * weight.value;
|
||||
debounce(pricePerKilo, time: Duration(milliseconds: 100), (callback) {
|
||||
totalCost.value = callback * weight.value;
|
||||
});
|
||||
|
||||
totalCost.listen((data) {
|
||||
totalCostController.text = data.toString();
|
||||
totalCostController.text = data.toString().separatedByComma;
|
||||
|
||||
isValid.value =
|
||||
weight.value > 0 &&
|
||||
@@ -78,15 +81,23 @@ class SalesInProvinceLogic extends GetxController {
|
||||
getAllocatedMade();
|
||||
}
|
||||
});
|
||||
|
||||
debounce(searchedValue, (callback) => getAllocatedMade(), time: Duration(milliseconds: 2000));
|
||||
ever(searchIsSelected, (data) {
|
||||
if (data == false) {
|
||||
searchedValue.value = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> getAllocatedMade() async {
|
||||
if (isLoadingMoreAllocationsMade.value ||
|
||||
!hasMoreDataAllocationsMade.value) {
|
||||
if (isLoadingMoreAllocationsMade.value || !hasMoreDataAllocationsMade.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (addPageAllocationsMade.value) {
|
||||
if (searchIsSelected.value) {
|
||||
currentPageAllocationsMade.value = 1;
|
||||
} else if (addPageAllocationsMade.value) {
|
||||
currentPageAllocationsMade.value++;
|
||||
}
|
||||
safeCall(
|
||||
@@ -97,6 +108,7 @@ class SalesInProvinceLogic extends GetxController {
|
||||
pageSize: 20,
|
||||
search: 'filter',
|
||||
role: 'Steward',
|
||||
value: searchedValue.value,
|
||||
),
|
||||
),
|
||||
onSuccess: (result) {
|
||||
@@ -157,8 +169,7 @@ class SalesInProvinceLogic extends GetxController {
|
||||
safeCall(
|
||||
call: () async => await rootLogic.chickenRepository.confirmAllAllocation(
|
||||
token: rootLogic.tokenService.accessToken.value!,
|
||||
allocationTokens:
|
||||
allocatedMadeModel.value?.map((e) => e.key!).toList() ?? [],
|
||||
allocationTokens: allocatedMadeModel.value?.map((e) => e.key!).toList() ?? [],
|
||||
),
|
||||
onSuccess: (result) {
|
||||
getAllocatedMade();
|
||||
@@ -169,9 +180,8 @@ class SalesInProvinceLogic extends GetxController {
|
||||
|
||||
Future<void> getRolesProducts() async {
|
||||
safeCall(
|
||||
call: () async => await rootLogic.chickenRepository.getRolesProducts(
|
||||
token: rootLogic.tokenService.accessToken.value!,
|
||||
),
|
||||
call: () async =>
|
||||
await rootLogic.chickenRepository.getRolesProducts(token: rootLogic.tokenService.accessToken.value!),
|
||||
onSuccess: (result) {
|
||||
if (result != null) {
|
||||
rolesProductsModel.value = result;
|
||||
@@ -186,10 +196,7 @@ class SalesInProvinceLogic extends GetxController {
|
||||
safeCall(
|
||||
call: () async => await rootLogic.chickenRepository.getGuilds(
|
||||
token: rootLogic.tokenService.accessToken.value!,
|
||||
queryParameters: buildQueryParams(
|
||||
queryParams: {'free': saleType.value == 2 ? true : false},
|
||||
role: 'Steward',
|
||||
),
|
||||
queryParameters: buildQueryParams(queryParams: {'free': saleType.value == 2 ? true : false}, role: 'Steward'),
|
||||
),
|
||||
onSuccess: (result) {
|
||||
if (result != null) {
|
||||
@@ -215,9 +222,7 @@ class SalesInProvinceLogic extends GetxController {
|
||||
|
||||
Future<void> getGuildProfile() async {
|
||||
await safeCall(
|
||||
call: () async => await rootLogic.chickenRepository.getProfile(
|
||||
token: rootLogic.tokenService.accessToken.value!,
|
||||
),
|
||||
call: () async => await rootLogic.chickenRepository.getProfile(token: rootLogic.tokenService.accessToken.value!),
|
||||
onError: (error, stackTrace) {},
|
||||
onSuccess: (result) {
|
||||
guildProfile.value = result;
|
||||
@@ -225,30 +230,31 @@ class SalesInProvinceLogic extends GetxController {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> submitAllocation() async {
|
||||
SubmitStewardAllocation stewardAllocation = SubmitStewardAllocation(
|
||||
void setSubmitData() {
|
||||
tmpStewardAllocation = SubmitStewardAllocation(
|
||||
approvedPriceStatus: false,
|
||||
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",
|
||||
buyerType: selectedGuildModel.value?.steward == true
|
||||
? "Steward"
|
||||
: "Guild",
|
||||
buyerType: selectedGuildModel.value?.steward == true ? "Steward" : "Guild",
|
||||
amount: pricePerKilo.value,
|
||||
totalAmount: totalCost.value,
|
||||
weightOfCarcasses: weight.value,
|
||||
sellType:saleType.value ==2 ? "free" :'exclusive',
|
||||
numberOfCarcasses: 0,
|
||||
guildKey: selectedGuildModel.value?.key,
|
||||
productKey: selectedProductModel.value?.key,
|
||||
date: DateTime.now().formattedGregorianDate,
|
||||
date: DateTime.now().formattedDashedGregorian,
|
||||
type: "manual",
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> submitAllocation() async {
|
||||
safeCall(
|
||||
call: () async =>
|
||||
await rootLogic.chickenRepository.postSubmitStewardAllocation(
|
||||
token: rootLogic.tokenService.accessToken.value!,
|
||||
request: stewardAllocation,
|
||||
),
|
||||
call: () async => await rootLogic.chickenRepository.postSubmitStewardAllocation(
|
||||
token: rootLogic.tokenService.accessToken.value!,
|
||||
request: tmpStewardAllocation!,
|
||||
),
|
||||
|
||||
onSuccess: (result) {
|
||||
getAllocatedMade();
|
||||
@@ -259,11 +265,10 @@ class SalesInProvinceLogic extends GetxController {
|
||||
|
||||
Future<void> deleteAllocation(AllocatedMadeModel model) async {
|
||||
safeCall(
|
||||
call: () async =>
|
||||
await rootLogic.chickenRepository.deleteStewardAllocation(
|
||||
token: rootLogic.tokenService.accessToken.value!,
|
||||
queryParameters: {'steward_allocation_key': model.key},
|
||||
),
|
||||
call: () async => await rootLogic.chickenRepository.deleteStewardAllocation(
|
||||
token: rootLogic.tokenService.accessToken.value!,
|
||||
queryParameters: {'steward_allocation_key': model.key},
|
||||
),
|
||||
|
||||
onSuccess: (result) {
|
||||
getAllocatedMade();
|
||||
@@ -286,9 +291,7 @@ class SalesInProvinceLogic extends GetxController {
|
||||
pricePerKilo.value = item.amount ?? 0;
|
||||
totalCost.value = item.totalAmount ?? 0;
|
||||
weightController.text = weight.value.toString().separatedByComma;
|
||||
pricePerKiloController.text = pricePerKilo.value
|
||||
.toString()
|
||||
.separatedByComma;
|
||||
pricePerKiloController.text = pricePerKilo.value.toString().separatedByComma;
|
||||
totalCostController.text = totalCost.value.toString().separatedByComma;
|
||||
isValid.value = true;
|
||||
}
|
||||
@@ -314,11 +317,10 @@ class SalesInProvinceLogic extends GetxController {
|
||||
);
|
||||
|
||||
safeCall(
|
||||
call: () async =>
|
||||
await rootLogic.chickenRepository.updateStewardAllocation(
|
||||
token: rootLogic.tokenService.accessToken.value!,
|
||||
request: updatedAllocationModel,
|
||||
),
|
||||
call: () async => await rootLogic.chickenRepository.updateStewardAllocation(
|
||||
token: rootLogic.tokenService.accessToken.value!,
|
||||
request: updatedAllocationModel,
|
||||
),
|
||||
|
||||
onSuccess: (result) {
|
||||
getAllocatedMade();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,38 +1,35 @@
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:persian_datetime_picker/persian_datetime_picker.dart';
|
||||
|
||||
extension XDateTime on String{
|
||||
extension XDateTime on String {
|
||||
get toDateTime => DateTime.parse(this);
|
||||
|
||||
get formattedJalaliDate{
|
||||
final dateTime = DateTime.parse(this);
|
||||
String get formattedJalaliDate {
|
||||
String tmp = contains("/") ? replaceAll("/", "-") : this;
|
||||
final dateTime = DateTime.parse(tmp);
|
||||
final jalaliDate = Jalali.fromDateTime(dateTime);
|
||||
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 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')}";
|
||||
}
|
||||
|
||||
|
||||
get formattedYHMS{
|
||||
String get formattedYHMS {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ extension XString on String {
|
||||
return number != null ? formatter.format(number) : this;
|
||||
}
|
||||
|
||||
get clearComma {
|
||||
String get clearComma {
|
||||
return replaceAll(RegExp(r'\D'), '');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user