feat : sale in the province edit and delete
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:rasadyar_chicken/data/models/request/conform_allocation/conform_allocation.dart';
|
||||
import 'package:rasadyar_chicken/data/models/request/steward_free_sale_bar/steward_free_sale_bar_request.dart';
|
||||
import 'package:rasadyar_chicken/data/models/request/submit_steward_allocation/submit_steward_allocation.dart';
|
||||
import 'package:rasadyar_chicken/data/models/response/allocated_made/allocated_made.dart';
|
||||
@@ -81,6 +82,19 @@ abstract class ChickenRepository {
|
||||
required SubmitStewardAllocation request,
|
||||
});
|
||||
|
||||
Future<void> deleteStewardAllocation({
|
||||
required String token,
|
||||
Map<String, dynamic>? queryParameters,
|
||||
});
|
||||
|
||||
|
||||
Future<void> updateStewardAllocation({
|
||||
required String token,
|
||||
required ConformAllocation request,
|
||||
});
|
||||
|
||||
|
||||
|
||||
Future<StewardFreeBarDashboard?> getStewardDashboard({
|
||||
required String token,
|
||||
required String stratDate,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:rasadyar_chicken/data/models/request/conform_allocation/conform_allocation.dart';
|
||||
import 'package:rasadyar_chicken/data/models/request/create_steward_free_bar/create_steward_free_bar.dart';
|
||||
import 'package:rasadyar_chicken/data/models/request/steward_free_sale_bar/steward_free_sale_bar_request.dart';
|
||||
import 'package:rasadyar_chicken/data/models/request/submit_steward_allocation/submit_steward_allocation.dart';
|
||||
@@ -112,11 +113,11 @@ class ChickenRepositoryImpl implements ChickenRepository {
|
||||
}) async {
|
||||
var res = await _httpClient.get(
|
||||
'/steward-allocation/',
|
||||
queryParameters:queryParameters,
|
||||
queryParameters: queryParameters,
|
||||
headers: {'Authorization': 'Bearer $token'},
|
||||
fromJson: (json) => PaginationModel<AllocatedMadeModel>.fromJson(
|
||||
json,
|
||||
(json) => AllocatedMadeModel.fromJson(json as Map<String, dynamic>),
|
||||
(json) => AllocatedMadeModel.fromJson(json as Map<String, dynamic>),
|
||||
),
|
||||
);
|
||||
return res.data;
|
||||
@@ -207,6 +208,30 @@ class ChickenRepositoryImpl implements ChickenRepository {
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteStewardAllocation({
|
||||
required String token,
|
||||
Map<String, dynamic>? queryParameters,
|
||||
}) async {
|
||||
await _httpClient.delete(
|
||||
'/steward-allocation/0/',
|
||||
headers: {'Authorization': 'Bearer $token'},
|
||||
queryParameters: queryParameters,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateStewardAllocation({
|
||||
required String token,
|
||||
required ConformAllocation request,
|
||||
}) async {
|
||||
await _httpClient.put(
|
||||
'/steward-allocation/0/',
|
||||
headers: {'Authorization': 'Bearer $token'},
|
||||
queryParameters: request.toJson(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<StewardFreeBarDashboard?> getStewardDashboard({
|
||||
required String token,
|
||||
|
||||
@@ -37,10 +37,13 @@ class SalesInProvinceLogic extends GetxController {
|
||||
final RxBool addPageAllocationsMade = false.obs;
|
||||
final RxBool hasMoreDataAllocationsMade = true.obs;
|
||||
|
||||
Rxn<AllocatedMadeModel> selectedAllocationModelForUpdate =
|
||||
Rxn<AllocatedMadeModel>();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
//rootLogic.getInventory();
|
||||
|
||||
getAllocatedMade();
|
||||
getRolesProducts();
|
||||
getGuilds();
|
||||
@@ -254,12 +257,73 @@ 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},
|
||||
),
|
||||
|
||||
onSuccess: (result) {
|
||||
getAllocatedMade();
|
||||
},
|
||||
onError: (error, stackTrace) {},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
rootLogic.inventoryExpandedList.clear();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
//TODO
|
||||
void setEditData(AllocatedMadeModel item) {}
|
||||
void setEditData(AllocatedMadeModel item) {
|
||||
selectedAllocationModelForUpdate.value = item;
|
||||
selectedProductModel.value = rolesProductsModel.first;
|
||||
selectedGuildModel.value = GuildModel(guildsName: 'tst');
|
||||
weight.value = item.weightOfCarcasses ?? 0;
|
||||
pricePerKilo.value = item.amount ?? 0;
|
||||
totalCost.value = item.totalAmount ?? 0;
|
||||
weightController.text = weight.value.toString().separatedByComma;
|
||||
pricePerKiloController.text = pricePerKilo.value
|
||||
.toString()
|
||||
.separatedByComma;
|
||||
totalCostController.text = totalCost.value.toString().separatedByComma;
|
||||
isValid.value = true;
|
||||
}
|
||||
|
||||
void clearForm() {
|
||||
selectedGuildModel.value = null;
|
||||
weight.value = 0;
|
||||
pricePerKilo.value = 0;
|
||||
totalCost.value = 0;
|
||||
weightController.clear();
|
||||
pricePerKiloController.clear();
|
||||
totalCostController.clear();
|
||||
isValid.value = false;
|
||||
}
|
||||
|
||||
Future<void> updateAllocation() async {
|
||||
ConformAllocation updatedAllocationModel = ConformAllocation(
|
||||
allocation_key: selectedAllocationModelForUpdate.value?.key,
|
||||
amount: pricePerKilo.value,
|
||||
total_amount: totalCost.value,
|
||||
number_of_carcasses: 0,
|
||||
weight_of_carcasses: weight.value,
|
||||
);
|
||||
|
||||
safeCall(
|
||||
call: () async =>
|
||||
await rootLogic.chickenRepository.updateStewardAllocation(
|
||||
token: rootLogic.tokenService.accessToken.value!,
|
||||
request: updatedAllocationModel,
|
||||
),
|
||||
|
||||
onSuccess: (result) {
|
||||
getAllocatedMade();
|
||||
},
|
||||
onError: (error, stackTrace) {},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,9 +338,9 @@ class SalesInProvincePage extends GetView<SalesInProvinceLogic> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget showAddBottomSheet() {
|
||||
Widget showAddBottomSheet([bool isEditMode = false]) {
|
||||
return BaseBottomSheet(
|
||||
height: Get.height * 0.75,
|
||||
height: Get.height * (isEditMode ? 0.45 : 0.75),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 16,
|
||||
@@ -352,52 +352,63 @@ class SalesInProvincePage extends GetView<SalesInProvinceLogic> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'ثبت توزیع/ فروش',
|
||||
'${isEditMode ? 'ویرایش' :'ثبت' } توزیع/ فروش',
|
||||
style: AppFonts.yekan16Bold.copyWith(color: AppColor.blueNormal),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
RTextField(
|
||||
controller: TextEditingController(),
|
||||
label: 'تاریخ',
|
||||
enabled: false,
|
||||
initText: Jalali.now().formatCompactDate(),
|
||||
Visibility(
|
||||
visible: isEditMode == false,
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 12),
|
||||
RTextField(
|
||||
controller: TextEditingController(),
|
||||
label: 'تاریخ',
|
||||
enabled: false,
|
||||
initText: Jalali.now().formatCompactDate(),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Material(
|
||||
type: MaterialType.transparency,
|
||||
child: productDropDown(),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
SizedBox(
|
||||
height: 40,
|
||||
child: ObxValue((data) {
|
||||
return Row(
|
||||
children: [
|
||||
Radio(
|
||||
value: 1,
|
||||
groupValue: controller.saleType.value,
|
||||
onChanged: (value) {
|
||||
controller.saleType.value = value!;
|
||||
|
||||
controller.selectedGuildModel.value = null;
|
||||
controller.selectedGuildModel.refresh();
|
||||
},
|
||||
),
|
||||
Text('فروش اختصاصی', style: AppFonts.yekan14),
|
||||
SizedBox(width: 12),
|
||||
Radio(
|
||||
value: 2,
|
||||
groupValue: controller.saleType.value,
|
||||
onChanged: (value) {
|
||||
controller.saleType.value = value!;
|
||||
},
|
||||
),
|
||||
Text('فروش آزاد', style: AppFonts.yekan14),
|
||||
],
|
||||
);
|
||||
}, controller.saleType),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
guildsDropDown(),
|
||||
|
||||
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Material(type: MaterialType.transparency, child: productDropDown()),
|
||||
const SizedBox(height: 12),
|
||||
SizedBox(
|
||||
height: 40,
|
||||
child: ObxValue((data) {
|
||||
return Row(
|
||||
children: [
|
||||
Radio(
|
||||
value: 1,
|
||||
groupValue: controller.saleType.value,
|
||||
onChanged: (value) {
|
||||
controller.saleType.value = value!;
|
||||
|
||||
controller.selectedGuildModel.value = null;
|
||||
controller.selectedGuildModel.refresh();
|
||||
},
|
||||
),
|
||||
Text('فروش اختصاصی', style: AppFonts.yekan14),
|
||||
SizedBox(width: 12),
|
||||
Radio(
|
||||
value: 2,
|
||||
groupValue: controller.saleType.value,
|
||||
onChanged: (value) {
|
||||
controller.saleType.value = value!;
|
||||
},
|
||||
),
|
||||
Text('فروش آزاد', style: AppFonts.yekan14),
|
||||
],
|
||||
);
|
||||
}, controller.saleType),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
guildsDropDown(),
|
||||
|
||||
const SizedBox(height: 12),
|
||||
RTextField(
|
||||
controller: controller.weightController,
|
||||
@@ -423,7 +434,8 @@ class SalesInProvincePage extends GetView<SalesInProvinceLogic> {
|
||||
],
|
||||
|
||||
onChanged: (p0) {
|
||||
controller.pricePerKilo.value = int.tryParse(p0.clearComma) ?? 0;
|
||||
controller.pricePerKilo.value =
|
||||
int.tryParse(p0.clearComma) ?? 0;
|
||||
},
|
||||
keyboardType: TextInputType.number,
|
||||
label: 'قیمت هر کیلو',
|
||||
@@ -438,7 +450,9 @@ class SalesInProvincePage extends GetView<SalesInProvinceLogic> {
|
||||
SeparatorInputFormatter(),
|
||||
],
|
||||
borderColor: AppColor.darkGreyLight,
|
||||
initText: controller.totalCost.value.toString().separatedByComma,
|
||||
initText: controller.totalCost.value
|
||||
.toString()
|
||||
.separatedByComma,
|
||||
controller: controller.totalCostController,
|
||||
label: 'هزینه کل',
|
||||
),
|
||||
@@ -447,10 +461,16 @@ class SalesInProvincePage extends GetView<SalesInProvinceLogic> {
|
||||
const SizedBox(height: 20),
|
||||
ObxValue((data) {
|
||||
return RElevated(
|
||||
text: 'ثبت',
|
||||
text:isEditMode? 'ویرایش': 'ثبت',
|
||||
textStyle: AppFonts.yekan16.copyWith(color: Colors.white),
|
||||
height: 40,
|
||||
onPressed: data.value
|
||||
? () async{
|
||||
await controller.submitAllocation();
|
||||
? () async {
|
||||
isEditMode
|
||||
? await controller.submitAllocation()
|
||||
: await controller.updateAllocation();
|
||||
|
||||
controller.clearForm();
|
||||
controller.getAllocatedMade();
|
||||
Get.back();
|
||||
}
|
||||
@@ -680,13 +700,12 @@ class SalesInProvincePage extends GetView<SalesInProvinceLogic> {
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
controller.setEditData(item);
|
||||
//TODO
|
||||
/* Get.bottomSheet(
|
||||
addOrEditBuyerBottomSheet(true),
|
||||
isScrollControlled: true,
|
||||
).whenComplete(() {
|
||||
controller.resetSubmitForm();
|
||||
});*/
|
||||
Get.bottomSheet(
|
||||
showAddBottomSheet(true),
|
||||
isScrollControlled: true,
|
||||
).whenComplete(() {
|
||||
controller.clearForm();
|
||||
});
|
||||
},
|
||||
child: Assets.vec.editSvg.svg(
|
||||
width: 20,
|
||||
@@ -706,7 +725,22 @@ class SalesInProvincePage extends GetView<SalesInProvinceLogic> {
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
buildDeleteDialog(
|
||||
onConfirm: () =>
|
||||
controller.deleteAllocation(item),
|
||||
);
|
||||
},
|
||||
child: Assets.vec.trashSvg.svg(
|
||||
width: 16,
|
||||
height: 16,
|
||||
colorFilter: ColorFilter.mode(
|
||||
AppColor.error,
|
||||
BlendMode.srcIn,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -883,4 +917,30 @@ class SalesInProvincePage extends GetView<SalesInProvinceLogic> {
|
||||
return model.steward;
|
||||
}
|
||||
}
|
||||
|
||||
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.getAllocatedMade());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user