feat : wearhouse home page
This commit is contained in:
@@ -43,7 +43,7 @@ class HomeLogic extends GetxController {
|
||||
getTodayBars(),
|
||||
getDistributionInformation(),
|
||||
rootLogic.getRolesProducts(),
|
||||
rootLogic.getInventory(),
|
||||
rootLogic.getRolesProduct(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/cupertino.dart' hide LinearGradient;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rasadyar_chicken/data/models/response/kill_house_distribution_info/kill_house_distribution_info.dart';
|
||||
import 'package:rasadyar_chicken/data/models/response/roles_products/roles_products.dart';
|
||||
import 'package:rasadyar_chicken/presentation/widget/base_page/view.dart';
|
||||
import 'package:rasadyar_chicken/presentation/widget/steward/widely_used/view.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
@@ -74,7 +74,7 @@ class StewardRootLogic extends GetxController {
|
||||
getProvinces();
|
||||
}
|
||||
if (inventoryModel.value == null) {
|
||||
getInventory();
|
||||
getRolesProduct();
|
||||
}
|
||||
if (rolesProductsModel.isEmpty) {
|
||||
getRolesProducts();
|
||||
@@ -100,7 +100,7 @@ class StewardRootLogic extends GetxController {
|
||||
|
||||
Future<void> onRefresh() async {
|
||||
await Future.wait([
|
||||
getInventory(),
|
||||
getRolesProduct(),
|
||||
getRolesProducts(),
|
||||
getStewardSaleDashboard(),
|
||||
getStewardRemainWeightData(),
|
||||
@@ -117,13 +117,13 @@ class StewardRootLogic extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> getInventory() async {
|
||||
Future<void> getRolesProduct() async {
|
||||
// Cancel previous request if still running
|
||||
_inventoryCancelToken?.cancel();
|
||||
_inventoryCancelToken = CancelToken();
|
||||
|
||||
await safeCall<List<ProductModel>?>(
|
||||
call: () async => await chickenRepository.getInventory(
|
||||
call: () async => await chickenRepository.getRolesProduct(
|
||||
token: tokenService.accessToken.value!,
|
||||
cancelToken: _inventoryCancelToken,
|
||||
role: 'Steward',
|
||||
@@ -178,6 +178,7 @@ class StewardRootLogic extends GetxController {
|
||||
safeCall(
|
||||
call: () async => await chickenRepository.getRolesProducts(
|
||||
token: tokenService.accessToken.value!,
|
||||
queryParameters: buildQueryParams(role: 'Steward'),
|
||||
),
|
||||
onSuccess: (result) {
|
||||
if (result != null) {
|
||||
|
||||
@@ -56,7 +56,8 @@ class SalesInProvinceLogic extends GetxController {
|
||||
final RxBool hasMoreDataAllocationsMade = true.obs;
|
||||
|
||||
Rxn<BroadcastPrice> broadcastPrice = Rxn<BroadcastPrice>();
|
||||
Rxn<AllocatedMadeModel> selectedAllocationModelForUpdate = Rxn<AllocatedMadeModel>();
|
||||
Rxn<AllocatedMadeModel> selectedAllocationModelForUpdate =
|
||||
Rxn<AllocatedMadeModel>();
|
||||
SubmitStewardAllocation? tmpStewardAllocation;
|
||||
|
||||
Rxn<Jalali> productionDate = Rxn(null);
|
||||
@@ -133,7 +134,8 @@ class SalesInProvinceLogic extends GetxController {
|
||||
}
|
||||
|
||||
void _updateGovernmentalProductionDateData() {
|
||||
List<RemainWeightDay> dates = rootLogic.stewardRemainWeight.value?.governmental ?? [];
|
||||
List<RemainWeightDay> dates =
|
||||
rootLogic.stewardRemainWeight.value?.governmental ?? [];
|
||||
governmentalProductionDateData = {
|
||||
for (var element in dates)
|
||||
element.day.toString().toJalali.formatCompactDate(): DayData(
|
||||
@@ -156,7 +158,8 @@ class SalesInProvinceLogic extends GetxController {
|
||||
if (isLoadingMore) {
|
||||
isLoadingMoreAllocationsMade.value = true;
|
||||
} else {
|
||||
allocatedList.value = Resource<PaginationModel<AllocatedMadeModel>>.loading();
|
||||
allocatedList.value =
|
||||
Resource<PaginationModel<AllocatedMadeModel>>.loading();
|
||||
}
|
||||
|
||||
if (searchedValue.value != null &&
|
||||
@@ -181,18 +184,23 @@ class SalesInProvinceLogic extends GetxController {
|
||||
onSuccess: (res) async {
|
||||
await Future.delayed(Duration(milliseconds: 200));
|
||||
if ((res?.count ?? 0) == 0) {
|
||||
allocatedList.value = Resource<PaginationModel<AllocatedMadeModel>>.empty();
|
||||
allocatedList.value =
|
||||
Resource<PaginationModel<AllocatedMadeModel>>.empty();
|
||||
} else {
|
||||
allocatedList.value = Resource<PaginationModel<AllocatedMadeModel>>.success(
|
||||
PaginationModel<AllocatedMadeModel>(
|
||||
count: res?.count ?? 0,
|
||||
next: res?.next,
|
||||
previous: res?.previous,
|
||||
results: isLoadingMore
|
||||
? [...(allocatedList.value.data?.results ?? []), ...(res?.results ?? [])]
|
||||
: res?.results ?? [],
|
||||
),
|
||||
);
|
||||
allocatedList.value =
|
||||
Resource<PaginationModel<AllocatedMadeModel>>.success(
|
||||
PaginationModel<AllocatedMadeModel>(
|
||||
count: res?.count ?? 0,
|
||||
next: res?.next,
|
||||
previous: res?.previous,
|
||||
results: isLoadingMore
|
||||
? [
|
||||
...(allocatedList.value.data?.results ?? []),
|
||||
...(res?.results ?? []),
|
||||
]
|
||||
: res?.results ?? [],
|
||||
),
|
||||
);
|
||||
isLoadingMoreAllocationsMade.value = false;
|
||||
if ((allocatedList.value.data?.results?.length ?? 0) > 1) {
|
||||
flashingFabBgColor();
|
||||
@@ -208,10 +216,14 @@ class SalesInProvinceLogic extends GetxController {
|
||||
void checkVerification() {
|
||||
var hasWeight = quotaType.value == 1
|
||||
? weight.value <=
|
||||
(governmentalProductionDateData[productionDate.value?.formatCompactDate()]?.value ??
|
||||
(governmentalProductionDateData[productionDate.value
|
||||
?.formatCompactDate()]
|
||||
?.value ??
|
||||
0)
|
||||
: weight.value <=
|
||||
(freeProductionDateData[productionDate.value?.formatCompactDate()]?.value ?? 0);
|
||||
(freeProductionDateData[productionDate.value?.formatCompactDate()]
|
||||
?.value ??
|
||||
0);
|
||||
|
||||
isValid.value =
|
||||
weight.value > 0 &&
|
||||
@@ -252,7 +264,9 @@ class SalesInProvinceLogic extends GetxController {
|
||||
safeCall(
|
||||
call: () async => await rootLogic.chickenRepository.confirmAllAllocation(
|
||||
token: rootLogic.tokenService.accessToken.value!,
|
||||
allocationTokens: allocatedList.value.data?.results?.map((e) => e.key!).toList() ?? [],
|
||||
allocationTokens:
|
||||
allocatedList.value.data?.results?.map((e) => e.key!).toList() ??
|
||||
[],
|
||||
),
|
||||
onSuccess: (result) {
|
||||
getAllocatedMade();
|
||||
@@ -265,6 +279,7 @@ class SalesInProvinceLogic extends GetxController {
|
||||
safeCall(
|
||||
call: () async => await rootLogic.chickenRepository.getRolesProducts(
|
||||
token: rootLogic.tokenService.accessToken.value!,
|
||||
queryParameters: buildQueryParams(role: 'Steward'),
|
||||
),
|
||||
onSuccess: (result) {
|
||||
if (result != null) {
|
||||
@@ -326,13 +341,17 @@ class SalesInProvinceLogic extends GetxController {
|
||||
allocationType:
|
||||
'${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,
|
||||
productionDate: productionDate.value?.toDateTime().formattedDashedGregorian,
|
||||
productionDate: productionDate.value
|
||||
?.toDateTime()
|
||||
.formattedDashedGregorian,
|
||||
quota: quotaType.value == 1 ? 'governmental' : 'free',
|
||||
guildKey: selectedGuildModel.value?.key,
|
||||
productKey: selectedProductModel.value?.key,
|
||||
@@ -346,16 +365,20 @@ class SalesInProvinceLogic extends GetxController {
|
||||
|
||||
safeCall(
|
||||
showError: true,
|
||||
call: () async => await rootLogic.chickenRepository.postSubmitStewardAllocation(
|
||||
token: rootLogic.tokenService.accessToken.value!,
|
||||
request: tmpStewardAllocation!,
|
||||
),
|
||||
call: () async =>
|
||||
await rootLogic.chickenRepository.postSubmitStewardAllocation(
|
||||
token: rootLogic.tokenService.accessToken.value!,
|
||||
request: tmpStewardAllocation!,
|
||||
),
|
||||
|
||||
onSuccess: (result) {
|
||||
clearForm();
|
||||
onRefresh();
|
||||
rootLogic.onRefresh();
|
||||
Future.delayed(Duration(seconds: 1), () => defaultShowSuccessMessage("ثبت موفق بود"));
|
||||
Future.delayed(
|
||||
Duration(seconds: 1),
|
||||
() => defaultShowSuccessMessage("ثبت موفق بود"),
|
||||
);
|
||||
Get.back();
|
||||
},
|
||||
onError: (error, stackTrace) {},
|
||||
@@ -364,10 +387,11 @@ 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();
|
||||
@@ -391,7 +415,9 @@ 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;
|
||||
productionDate.value = item.productionDate.toJalali;
|
||||
@@ -425,16 +451,20 @@ class SalesInProvinceLogic extends GetxController {
|
||||
|
||||
safeCall(
|
||||
showError: true,
|
||||
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) {
|
||||
clearForm();
|
||||
onRefresh();
|
||||
rootLogic.onRefresh();
|
||||
Future.delayed(Duration(seconds: 1), () => defaultShowSuccessMessage("ویرایش موفق بود"));
|
||||
Future.delayed(
|
||||
Duration(seconds: 1),
|
||||
() => defaultShowSuccessMessage("ویرایش موفق بود"),
|
||||
);
|
||||
Get.back();
|
||||
},
|
||||
onError: (error, stackTrace) {},
|
||||
@@ -480,7 +510,9 @@ class SalesInProvinceLogic extends GetxController {
|
||||
broadcastPrice.value = result;
|
||||
if (broadcastPrice.value?.active == true) {
|
||||
pricePerKilo.value = broadcastPrice.value?.stewardPrice ?? 0;
|
||||
pricePerKiloController.text = pricePerKilo.value.toString().separatedByComma;
|
||||
pricePerKiloController.text = pricePerKilo.value
|
||||
.toString()
|
||||
.separatedByComma;
|
||||
priceType.value = 2;
|
||||
}
|
||||
},
|
||||
@@ -492,7 +524,11 @@ class SalesInProvinceLogic extends GetxController {
|
||||
toggleExpansion();
|
||||
currentPage.value = 1;
|
||||
hasMoreDataAllocationsMade.value = true;
|
||||
await Future.wait([getAllocatedMade(), getRolesProducts(), rootLogic.onRefresh()]);
|
||||
await Future.wait([
|
||||
getAllocatedMade(),
|
||||
getRolesProducts(),
|
||||
rootLogic.onRefresh(),
|
||||
]);
|
||||
}
|
||||
|
||||
void toggleExpansion({int? index}) {
|
||||
|
||||
@@ -101,7 +101,7 @@ class SalesInProvincePage extends GetView<SalesInProvinceLogic> {
|
||||
onPressed: () async {
|
||||
await controller.confirmAllAllocations();
|
||||
controller.getAllocatedMade();
|
||||
controller.rootLogic.getInventory();
|
||||
controller.rootLogic.getRolesProduct();
|
||||
Get.back();
|
||||
},
|
||||
child: Text('تایید'),
|
||||
|
||||
Reference in New Issue
Block a user