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/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/request/submit_steward_allocation/submit_steward_allocation.dart';
|
||||||
import 'package:rasadyar_chicken/data/models/response/allocated_made/allocated_made.dart';
|
import 'package:rasadyar_chicken/data/models/response/allocated_made/allocated_made.dart';
|
||||||
@@ -81,6 +82,19 @@ abstract class ChickenRepository {
|
|||||||
required SubmitStewardAllocation request,
|
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({
|
Future<StewardFreeBarDashboard?> getStewardDashboard({
|
||||||
required String token,
|
required String token,
|
||||||
required String stratDate,
|
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/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/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/request/submit_steward_allocation/submit_steward_allocation.dart';
|
||||||
@@ -112,7 +113,7 @@ class ChickenRepositoryImpl implements ChickenRepository {
|
|||||||
}) async {
|
}) async {
|
||||||
var res = await _httpClient.get(
|
var res = await _httpClient.get(
|
||||||
'/steward-allocation/',
|
'/steward-allocation/',
|
||||||
queryParameters:queryParameters,
|
queryParameters: queryParameters,
|
||||||
headers: {'Authorization': 'Bearer $token'},
|
headers: {'Authorization': 'Bearer $token'},
|
||||||
fromJson: (json) => PaginationModel<AllocatedMadeModel>.fromJson(
|
fromJson: (json) => PaginationModel<AllocatedMadeModel>.fromJson(
|
||||||
json,
|
json,
|
||||||
@@ -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
|
@override
|
||||||
Future<StewardFreeBarDashboard?> getStewardDashboard({
|
Future<StewardFreeBarDashboard?> getStewardDashboard({
|
||||||
required String token,
|
required String token,
|
||||||
|
|||||||
@@ -37,10 +37,13 @@ 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>();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
//rootLogic.getInventory();
|
|
||||||
getAllocatedMade();
|
getAllocatedMade();
|
||||||
getRolesProducts();
|
getRolesProducts();
|
||||||
getGuilds();
|
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
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
rootLogic.inventoryExpandedList.clear();
|
rootLogic.inventoryExpandedList.clear();
|
||||||
super.dispose();
|
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(
|
return BaseBottomSheet(
|
||||||
height: Get.height * 0.75,
|
height: Get.height * (isEditMode ? 0.45 : 0.75),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.only(
|
padding: EdgeInsets.only(
|
||||||
left: 16,
|
left: 16,
|
||||||
@@ -352,9 +352,13 @@ class SalesInProvincePage extends GetView<SalesInProvinceLogic> {
|
|||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
'ثبت توزیع/ فروش',
|
'${isEditMode ? 'ویرایش' :'ثبت' } توزیع/ فروش',
|
||||||
style: AppFonts.yekan16Bold.copyWith(color: AppColor.blueNormal),
|
style: AppFonts.yekan16Bold.copyWith(color: AppColor.blueNormal),
|
||||||
),
|
),
|
||||||
|
Visibility(
|
||||||
|
visible: isEditMode == false,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
RTextField(
|
RTextField(
|
||||||
controller: TextEditingController(),
|
controller: TextEditingController(),
|
||||||
@@ -363,7 +367,10 @@ class SalesInProvincePage extends GetView<SalesInProvinceLogic> {
|
|||||||
initText: Jalali.now().formatCompactDate(),
|
initText: Jalali.now().formatCompactDate(),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
Material(type: MaterialType.transparency, child: productDropDown()),
|
Material(
|
||||||
|
type: MaterialType.transparency,
|
||||||
|
child: productDropDown(),
|
||||||
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 40,
|
height: 40,
|
||||||
@@ -398,6 +405,10 @@ class SalesInProvincePage extends GetView<SalesInProvinceLogic> {
|
|||||||
|
|
||||||
guildsDropDown(),
|
guildsDropDown(),
|
||||||
|
|
||||||
|
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
RTextField(
|
RTextField(
|
||||||
controller: controller.weightController,
|
controller: controller.weightController,
|
||||||
@@ -423,7 +434,8 @@ class SalesInProvincePage extends GetView<SalesInProvinceLogic> {
|
|||||||
],
|
],
|
||||||
|
|
||||||
onChanged: (p0) {
|
onChanged: (p0) {
|
||||||
controller.pricePerKilo.value = int.tryParse(p0.clearComma) ?? 0;
|
controller.pricePerKilo.value =
|
||||||
|
int.tryParse(p0.clearComma) ?? 0;
|
||||||
},
|
},
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
label: 'قیمت هر کیلو',
|
label: 'قیمت هر کیلو',
|
||||||
@@ -438,7 +450,9 @@ class SalesInProvincePage extends GetView<SalesInProvinceLogic> {
|
|||||||
SeparatorInputFormatter(),
|
SeparatorInputFormatter(),
|
||||||
],
|
],
|
||||||
borderColor: AppColor.darkGreyLight,
|
borderColor: AppColor.darkGreyLight,
|
||||||
initText: controller.totalCost.value.toString().separatedByComma,
|
initText: controller.totalCost.value
|
||||||
|
.toString()
|
||||||
|
.separatedByComma,
|
||||||
controller: controller.totalCostController,
|
controller: controller.totalCostController,
|
||||||
label: 'هزینه کل',
|
label: 'هزینه کل',
|
||||||
),
|
),
|
||||||
@@ -447,10 +461,16 @@ class SalesInProvincePage extends GetView<SalesInProvinceLogic> {
|
|||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
ObxValue((data) {
|
ObxValue((data) {
|
||||||
return RElevated(
|
return RElevated(
|
||||||
text: 'ثبت',
|
text:isEditMode? 'ویرایش': 'ثبت',
|
||||||
|
textStyle: AppFonts.yekan16.copyWith(color: Colors.white),
|
||||||
|
height: 40,
|
||||||
onPressed: data.value
|
onPressed: data.value
|
||||||
? () async{
|
? () async {
|
||||||
await controller.submitAllocation();
|
isEditMode
|
||||||
|
? await controller.submitAllocation()
|
||||||
|
: await controller.updateAllocation();
|
||||||
|
|
||||||
|
controller.clearForm();
|
||||||
controller.getAllocatedMade();
|
controller.getAllocatedMade();
|
||||||
Get.back();
|
Get.back();
|
||||||
}
|
}
|
||||||
@@ -680,13 +700,12 @@ class SalesInProvincePage extends GetView<SalesInProvinceLogic> {
|
|||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
controller.setEditData(item);
|
controller.setEditData(item);
|
||||||
//TODO
|
Get.bottomSheet(
|
||||||
/* Get.bottomSheet(
|
showAddBottomSheet(true),
|
||||||
addOrEditBuyerBottomSheet(true),
|
|
||||||
isScrollControlled: true,
|
isScrollControlled: true,
|
||||||
).whenComplete(() {
|
).whenComplete(() {
|
||||||
controller.resetSubmitForm();
|
controller.clearForm();
|
||||||
});*/
|
});
|
||||||
},
|
},
|
||||||
child: Assets.vec.editSvg.svg(
|
child: Assets.vec.editSvg.svg(
|
||||||
width: 20,
|
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;
|
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