diff --git a/packages/chicken/lib/presentation/pages/sales_in_province/sales_out_of_province_sales_list/logic.dart b/packages/chicken/lib/presentation/pages/sales_in_province/sales_out_of_province_sales_list/logic.dart new file mode 100644 index 0000000..b3526a0 --- /dev/null +++ b/packages/chicken/lib/presentation/pages/sales_in_province/sales_out_of_province_sales_list/logic.dart @@ -0,0 +1,15 @@ +import 'package:get/get.dart'; + +class SalesOutOfProvinceSalesListLogic extends GetxController { + @override + void onReady() { + // TODO: implement onReady + super.onReady(); + } + + @override + void onClose() { + // TODO: implement onClose + super.onClose(); + } +} diff --git a/packages/chicken/lib/presentation/pages/sales_in_province/sales_out_of_province_sales_list/view.dart b/packages/chicken/lib/presentation/pages/sales_in_province/sales_out_of_province_sales_list/view.dart new file mode 100644 index 0000000..b34e56f --- /dev/null +++ b/packages/chicken/lib/presentation/pages/sales_in_province/sales_out_of_province_sales_list/view.dart @@ -0,0 +1,15 @@ +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; + +import 'logic.dart'; + +class SalesOutOfProvinceSalesListPage extends StatelessWidget { + const SalesOutOfProvinceSalesListPage({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + final SalesOutOfProvinceSalesListLogic logic = Get.put(SalesOutOfProvinceSalesListLogic()); + + return Container(); + } +} diff --git a/packages/chicken/lib/presentation/pages/sales_out_of_province/logic.dart b/packages/chicken/lib/presentation/pages/sales_out_of_province/logic.dart index 2961438..91c25d8 100644 --- a/packages/chicken/lib/presentation/pages/sales_out_of_province/logic.dart +++ b/packages/chicken/lib/presentation/pages/sales_out_of_province/logic.dart @@ -11,13 +11,17 @@ import 'package:rasadyar_chicken/presentation/pages/sale/logic.dart'; import 'package:rasadyar_core/core.dart'; class SalesOutOfProvinceLogic extends GetxController { - RxInt currentIndex = 0.obs; - + RootLogic get rootLogic => Get.find(); + SaleLogic get saleLogic => Get.find(); + RxInt selectedSegmentIndex = 0.obs; RxBool isExpanded = false.obs; RxBool isBuyerSubmitButtonEnabled = false.obs; RxBool isSaleSubmitButtonEnabled = false.obs; RxList isExpandedList = [].obs; - RxBool searchIsSelected = false.obs; + Rx fromDateFilter = Jalali.now().obs; + Rx toDateFilter = Jalali.now().obs; + RxnString searchedValue = RxnString(); + RxList routesName = RxList(); //TODO add this to Di ImagePicker imagePicker = ImagePicker(); @@ -34,11 +38,6 @@ class SalesOutOfProvinceLogic extends GetxController { Rxn selectedProvince = Rxn(); Rxn selectedCity = Rxn(); - RootLogic get rootLogic => Get.find(); - - SaleLogic get outOfTheProvinceLogic => - Get.find(); - GlobalKey formKey = GlobalKey(); TextEditingController buyerNameController = TextEditingController(); TextEditingController buyerLastNameController = TextEditingController(); @@ -48,41 +47,27 @@ class SalesOutOfProvinceLogic extends GetxController { //Sale TextEditingController quarantineCodeController = TextEditingController(); TextEditingController saleWeightController = TextEditingController(); - Rx saleDate = Jalali - .now() - .obs; + Rx saleDate = Jalali.now().obs; String? key; - Rx fromDateFilter = Jalali - .now() - .obs; - Rx toDateFilter = Jalali - .now() - .obs; - RxnString searchedValue = RxnString(); - @override void onReady() { super.onReady(); getOutProvinceCarcassesBuyer(); getOutProvinceSales(); - + routesName.value = [...saleLogic.routesName, 'داخل استان'].toList(); selectedProvince.listen((p0) => getCites()); tLog(selectedProduct.value); - outOfTheProvinceLogic.rolesProductsModel.listen((lists) { + saleLogic.rolesProductsModel.listen((lists) { selectedProduct.value = lists.first; }); setupListeners(); debounce( searchedValue, - (callback) => getOutProvinceCarcassesBuyer(), + (callback) => getOutProvinceCarcassesBuyer(), time: Duration(milliseconds: 2000), ); - ever(searchIsSelected, (data) { - if (data == false) { - searchedValue.value = null; - } - }); + } @override @@ -100,25 +85,22 @@ class SalesOutOfProvinceLogic extends GetxController { Future getOutProvinceCarcassesBuyer() async { await safeCall( - call: () => - rootLogic.chickenRepository.getOutProvinceCarcassesBuyer( - token: rootLogic.tokenService.accessToken.value!, - queryParameters: buildQueryParams( - pageSize: 10, - page: 1, - state: 'buyer-list', - search: 'filter', - role: 'Steward', - value: searchedValue.value ?? '', - ), - ), + call: () => rootLogic.chickenRepository.getOutProvinceCarcassesBuyer( + token: rootLogic.tokenService.accessToken.value!, + queryParameters: buildQueryParams( + pageSize: 10, + page: 1, + state: 'buyer-list', + search: 'filter', + role: 'Steward', + value: searchedValue.value ?? '', + ), + ), onSuccess: (res) { if ((res?.count ?? 0) == 0) { buyerList.value = Resource>.empty(); } else { - buyerList.value = Resource>.success( - res!.results!, - ); + buyerList.value = Resource>.success(res!.results!); } }, ); @@ -126,27 +108,24 @@ class SalesOutOfProvinceLogic extends GetxController { Future getOutProvinceSales() async { await safeCall( - call: () => - rootLogic.chickenRepository.getStewardFreeSaleBar( - token: rootLogic.tokenService.accessToken.value!, - queryParameters: buildQueryParams( - pageSize: 10, - page: 1, - state: 'buyer-list', - search: 'filter', - role: 'Steward', - value: searchedValue.value ?? '', - fromDate: fromDateFilter.value.toDateTime(), - toDate: toDateFilter.value.toDateTime(), - ), - ), + call: () => rootLogic.chickenRepository.getStewardFreeSaleBar( + token: rootLogic.tokenService.accessToken.value!, + queryParameters: buildQueryParams( + pageSize: 10, + page: 1, + state: 'buyer-list', + search: 'filter', + role: 'Steward', + value: searchedValue.value ?? '', + fromDate: fromDateFilter.value.toDateTime(), + toDate: toDateFilter.value.toDateTime(), + ), + ), onSuccess: (res) { if ((res?.count ?? 0) == 0) { salesList.value = Resource>.empty(); } else { - salesList.value = Resource>.success( - res!.results!, - ); + salesList.value = Resource>.success(res!.results!); } }, ); @@ -155,9 +134,7 @@ class SalesOutOfProvinceLogic extends GetxController { Future getCites() async { await safeCall( call: () => - rootLogic.chickenRepository.getCity( - provinceName: selectedProvince.value?.name ?? '', - ), + rootLogic.chickenRepository.getCity(provinceName: selectedProvince.value?.name ?? ''), onSuccess: (result) { if (result != null && result.isNotEmpty) { cites.value = result; @@ -188,23 +165,21 @@ class SalesOutOfProvinceLogic extends GetxController { void checkBuyerFormValid() { isBuyerSubmitButtonEnabled.value = buyerNameController.text.isNotEmpty && - buyerLastNameController.text.isNotEmpty && - buyerPhoneController.text.isNotEmpty && - buyerUnitNameController.text.isNotEmpty && - selectedProvince.value != null && - selectedCity.value != null && - selectedProduct.value != null; + buyerLastNameController.text.isNotEmpty && + buyerPhoneController.text.isNotEmpty && + buyerUnitNameController.text.isNotEmpty && + selectedProvince.value != null && + selectedCity.value != null && + selectedProduct.value != null; } void checkSalesFormValid() { isSaleSubmitButtonEnabled.value = - saleDate.value - .toString() - .isNotEmpty && - selectedProduct.value != null && - selectedBuyer.value != null && - saleWeightController.text.isNotEmpty && - quarantineCodeController.text.isNotEmpty; + saleDate.value.toString().isNotEmpty && + selectedProduct.value != null && + selectedBuyer.value != null && + saleWeightController.text.isNotEmpty && + quarantineCodeController.text.isNotEmpty; } Future createBuyer() async { @@ -223,8 +198,7 @@ class SalesOutOfProvinceLogic extends GetxController { mobile: buyerPhoneController.text, role: 'Steward', ); - final res = await rootLogic.chickenRepository - .createOutProvinceCarcassesBuyer( + final res = await rootLogic.chickenRepository.createOutProvinceCarcassesBuyer( token: rootLogic.tokenService.accessToken.value!, body: buyer, ); @@ -262,27 +236,23 @@ class SalesOutOfProvinceLogic extends GetxController { void setEditDataSales(StewardFreeSaleBar item) { quarantineCodeController.text = item.clearanceCode ?? ''; - saleWeightController.text = - item.weightOfCarcasses?.toInt().toString() ?? ''; + saleWeightController.text = item.weightOfCarcasses?.toInt().toString() ?? ''; saleDate.value = Jalali.fromDateTime(DateTime.parse(item.date!)); selectedCity.value = IranProvinceCityModel(name: item.city); selectedBuyer.value = buyerList.value.data?.firstWhere( - (element) => element.key == item.buyer?.key, + (element) => element.key == item.buyer?.key, ); - selectedProduct.value = - outOfTheProvinceLogic.rolesProductsModel.value.first; + selectedProduct.value = saleLogic.rolesProductsModel.value.first; key = item.key; isSaleSubmitButtonEnabled.value = true; } Future deleteStewardPurchaseOutOfProvince(String key) async { await safeCall( - call: () => - rootLogic.chickenRepository - .deleteStewardPurchasesOutSideOfTheProvince( - token: rootLogic.tokenService.accessToken.value!, - stewardFreeBarKey: key, - ), + call: () => rootLogic.chickenRepository.deleteStewardPurchasesOutSideOfTheProvince( + token: rootLogic.tokenService.accessToken.value!, + stewardFreeBarKey: key, + ), ); } @@ -292,18 +262,15 @@ class SalesOutOfProvinceLogic extends GetxController { buyerKey: selectedBuyer.value?.key, numberOfCarcasses: 0, weightOfCarcasses: int.tryParse(saleWeightController.text.clearComma), - date: saleDate.value - .toDateTime() - .formattedDashedGregorian, + date: saleDate.value.toDateTime().formattedDashedGregorian, clearanceCode: quarantineCodeController.text, productKey: selectedProduct.value?.key, ); await safeCall( - call: () => - rootLogic.chickenRepository.createOutProvinceStewardFreeBar( - token: rootLogic.tokenService.accessToken.value!, - body: requestBody, - ), + call: () => rootLogic.chickenRepository.createOutProvinceStewardFreeBar( + token: rootLogic.tokenService.accessToken.value!, + body: requestBody, + ), onSuccess: (_) { res = true; }, @@ -323,24 +290,29 @@ class SalesOutOfProvinceLogic extends GetxController { Future editSale() async { bool res = false; StewardFreeSaleBarRequest requestBody = StewardFreeSaleBarRequest( - numberOfCarcasses: 0, - weightOfCarcasses: int.tryParse(saleWeightController.text.clearComma), - date: saleDate.value - .toDateTime() - .formattedDashedGregorian, - clearanceCode: quarantineCodeController.text, - key:key + numberOfCarcasses: 0, + weightOfCarcasses: int.tryParse(saleWeightController.text.clearComma), + date: saleDate.value.toDateTime().formattedDashedGregorian, + clearanceCode: quarantineCodeController.text, + key: key, ); await safeCall( - call: () => - rootLogic.chickenRepository.updateOutProvinceStewardFreeBar( - token: rootLogic.tokenService.accessToken.value!, - body: requestBody, - ), + call: () => rootLogic.chickenRepository.updateOutProvinceStewardFreeBar( + token: rootLogic.tokenService.accessToken.value!, + body: requestBody, + ), onSuccess: (_) { res = true; }, ); return res; } + + void setSearchValue(String value) { + searchedValue.value = value.trim(); + } + + void submitFilter() { + //TODO: Implement filter logic + } } diff --git a/packages/chicken/lib/presentation/pages/sales_out_of_province/pages/sales_page.dart b/packages/chicken/lib/presentation/pages/sales_out_of_province/pages/sales_page.dart index 17ef768..7072bcb 100644 --- a/packages/chicken/lib/presentation/pages/sales_out_of_province/pages/sales_page.dart +++ b/packages/chicken/lib/presentation/pages/sales_out_of_province/pages/sales_page.dart @@ -19,12 +19,12 @@ class SalesPage extends GetView { return Scaffold( body: Column( children: [ - searchWidget(controller.searchIsSelected, (data) { + /* searchWidget(controller.searchIsSelected, (data) { controller.searchedValue.value = data; //TODO: Implement search functionality controller.getOutProvinceSales(); - }), + }),*/ salesListWidget(), ], @@ -454,7 +454,7 @@ class SalesPage extends GetView { Widget _productWidget() { return ObxValue((data) { return OverlayDropdownWidget( - items: controller.outOfTheProvinceLogic.rolesProductsModel, + items: controller.saleLogic.rolesProductsModel, onChanged: (value) { controller.selectedProduct.value = value; }, diff --git a/packages/chicken/lib/presentation/pages/sales_out_of_province/view.dart b/packages/chicken/lib/presentation/pages/sales_out_of_province/view.dart index 1459091..565c964 100644 --- a/packages/chicken/lib/presentation/pages/sales_out_of_province/view.dart +++ b/packages/chicken/lib/presentation/pages/sales_out_of_province/view.dart @@ -7,6 +7,7 @@ import 'package:rasadyar_chicken/data/models/response/roles_products/roles_produ import 'package:rasadyar_chicken/data/models/response/steward_free_bar/steward_free_bar.dart'; import 'package:rasadyar_chicken/presentation/pages/sales_out_of_province/pages/buyers_page.dart'; import 'package:rasadyar_chicken/presentation/pages/sales_out_of_province/pages/sales_page.dart'; +import 'package:rasadyar_chicken/presentation/widget/base_page/view.dart'; import 'package:rasadyar_core/core.dart'; import 'logic.dart'; @@ -16,153 +17,31 @@ class SalesOutOfProvincePage extends GetView { @override Widget build(BuildContext context) { - return ObxValue((index) { - return DefaultTabController( - length: 2, - initialIndex: index.value, - child: Scaffold( - appBar: RAppBar( - titleTextStyle: AppFonts.yekan16Bold.copyWith(color: Colors.white), - centerTitle: true, - hasBack: true, - onBackPressed: () { - Get.back(id: 1); - }, - leadingWidth: 155, - leading: Row( - mainAxisSize: MainAxisSize.min, - spacing: 6, - children: [ - Assets.vec.chickenSvg.svg( - width: 24, - height: 24, - colorFilter: const ColorFilter.mode(Colors.white, BlendMode.srcIn), - ), - Text('رصدطیور', style: AppFonts.yekan16Bold.copyWith(color: Colors.white)), - ], - ), - additionalActions: [ - GestureDetector( - onTap: () { - controller.searchIsSelected.value = !controller.searchIsSelected.value; - }, - child: Assets.vec.searchSvg.svg( - width: 24, - height: 24, - colorFilter: const ColorFilter.mode(Colors.white, BlendMode.srcIn), - ), - ), - SizedBox(width: 8), - Visibility( - visible: controller.currentIndex.value==0, - child: GestureDetector( - onTap: () { - Get.bottomSheet(filterBottomSheet()); - }, - child: Assets.vec.filterOutlineSvg.svg( - width: 20, - height: 20, - colorFilter: const ColorFilter.mode(Colors.white, BlendMode.srcIn), - ), - ), - ), - SizedBox(width: 8), - ], - ), - body: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - routePageWidget(), - Container( - child: TabBar( - tabs: [ - Tab(text: 'فروش' ), - Tab(text: 'خریداران'), - ], - onTap: (value) { - controller.currentIndex.value= value; - }, - labelColor: AppColor.blueNormal, - unselectedLabelColor: AppColor.mediumGreyDarkHover, - indicatorColor: AppColor.blueNormal, - indicatorSize: TabBarIndicatorSize.tab, - indicator: BoxDecoration( - color: AppColor.blueLight, - border: Border( - bottom: BorderSide( - color:AppColor.blueNormal, - ), - ), - ), - ), - ), - Expanded( - child: TabBarView( - children: [ - SalesPage(), - BuyersPage() - ], - ), - ), - ], - ), - ), - ); - }, controller.currentIndex); - } - - Row routePageWidget() { - return Row( - children: [ - SizedBox(width: 8), - RichText( - text: TextSpan( - style: AppFonts.yekan14.copyWith(color: AppColor.blueNormal), - children: [ - WidgetSpan( - child: Row( - children: [ - Assets.vec.cubeSearchSvg.svg( - width: 24, - height: 24, - colorFilter: const ColorFilter.mode(AppColor.blueNormal, BlendMode.srcIn), - ), - SizedBox(width: 6), - ], - ), - ), - - TextSpan(text: 'خارج استان'), - TextSpan(text: '/'), - TextSpan(text: 'فروش'), - ], - ), - ), + return BasePage( + routes: controller.routesName, + onBackPressed: () => Get.back(id: 1), + onSearchChanged: (data) => controller.setSearchValue(data), + filteringWidget: filterBottomSheet(), + widgets: [ + segmentWidget() ], ); } - Widget buildRow(String title, String value) { + Padding segmentWidget() { return Padding( - padding: const EdgeInsets.symmetric(vertical: 4.0), + padding: const EdgeInsets.fromLTRB(8, 0, 8, 8), child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Flexible( - flex: 2, - child: Text( - title, - textAlign: TextAlign.right, - style: AppFonts.yekan14.copyWith(color: AppColor.darkGreyDarkHover), - ), - ), - Flexible( - flex: 2, - child: Text( - value, - textAlign: TextAlign.left, - - style: AppFonts.yekan14.copyWith(color: AppColor.darkGreyDarkHover), + Expanded( + child: RSegment( + children: ['در انتظار', 'همه'], + selectedIndex: 0, + borderColor: const Color(0xFFB4B4B4), + selectedBorderColor: AppColor.blueNormal, + selectedBackgroundColor: AppColor.blueLight, + onSegmentSelected: (index) => controller.selectedSegmentIndex.value = index, + backgroundColor: AppColor.whiteGreyNormal, ), ), ], @@ -181,13 +60,13 @@ class SalesOutOfProvincePage extends GetView { spacing: 8, children: [ Expanded( - child: timeFilterWidget( + child: dateFilterWidget( date: controller.fromDateFilter, onChanged: (jalali) => controller.fromDateFilter.value = jalali, ), ), Expanded( - child: timeFilterWidget( + child: dateFilterWidget( isFrom: false, date: controller.toDateFilter, onChanged: (jalali) => controller.toDateFilter.value = jalali, @@ -199,7 +78,7 @@ class SalesOutOfProvincePage extends GetView { RElevated( text: 'اعمال فیلتر', onPressed: () { - controller.getOutProvinceSales(); + controller.submitFilter(); Get.back(); }, height: 40, @@ -210,99 +89,4 @@ class SalesOutOfProvincePage extends GetView { ); } - GestureDetector timeFilterWidget({ - isFrom = true, - required Rx date, - required Function(Jalali jalali) onChanged, - }) { - return GestureDetector( - onTap: () { - Get.bottomSheet(modalDatePicker((value) => onChanged(value))); - }, - child: Container( - height: 35, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(8), - border: Border.all(width: 1, color: AppColor.blueNormal), - ), - padding: EdgeInsets.symmetric(horizontal: 11, vertical: 4), - child: Row( - spacing: 8, - children: [ - Assets.vec.calendarSvg.svg( - width: 24, - height: 24, - colorFilter: const ColorFilter.mode(AppColor.blueNormal, BlendMode.srcIn), - ), - Text(isFrom ? 'از' : 'تا', style: AppFonts.yekan16.copyWith(color: AppColor.blueNormal)), - Expanded( - child: ObxValue((data) { - return Text( - date.value.formatCompactDate(), - textAlign: TextAlign.center, - style: AppFonts.yekan16.copyWith(color: AppColor.lightGreyNormalActive), - ); - }, date), - ), - ], - ), - ), - ); - } - - Container modalDatePicker(ValueChanged onDateSelected) { - Jalali? tempPickedDate; - return Container( - height: 250, - color: Colors.white, - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Container( - child: Row( - children: [ - SizedBox(width: 20), - RElevated( - height: 35, - width: 70, - textStyle: AppFonts.yekan14.copyWith(color: Colors.white), - onPressed: () { - onDateSelected(tempPickedDate ?? Jalali.now()); - Get.back(); - }, - text: 'تایید', - ), - Spacer(), - RElevated( - height: 35, - width: 70, - backgroundColor: AppColor.error, - textStyle: AppFonts.yekan14.copyWith(color: Colors.white), - onPressed: () { - onDateSelected(tempPickedDate ?? Jalali.now()); - Get.back(); - }, - text: 'لغو', - ), - SizedBox(width: 20), - ], - ), - ), - Divider(height: 0, thickness: 1), - Expanded( - child: Container( - child: PersianCupertinoDatePicker( - initialDateTime: Jalali.now(), - mode: PersianCupertinoDatePickerMode.date, - onDateTimeChanged: (dateTime) { - tempPickedDate = dateTime; - }, - ), - ), - ), - ], - ), - ); - } - } diff --git a/packages/chicken/lib/presentation/pages/sales_out_of_province_buyers/logic.dart b/packages/chicken/lib/presentation/pages/sales_out_of_province_buyers/logic.dart new file mode 100644 index 0000000..0afd06b --- /dev/null +++ b/packages/chicken/lib/presentation/pages/sales_out_of_province_buyers/logic.dart @@ -0,0 +1,15 @@ +import 'package:get/get.dart'; + +class SalesOutOfProvinceBuyersLogic extends GetxController { + @override + void onReady() { + // TODO: implement onReady + super.onReady(); + } + + @override + void onClose() { + // TODO: implement onClose + super.onClose(); + } +} diff --git a/packages/chicken/lib/presentation/pages/sales_out_of_province_buyers/view.dart b/packages/chicken/lib/presentation/pages/sales_out_of_province_buyers/view.dart new file mode 100644 index 0000000..74e9a24 --- /dev/null +++ b/packages/chicken/lib/presentation/pages/sales_out_of_province_buyers/view.dart @@ -0,0 +1,15 @@ +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; + +import 'logic.dart'; + +class SalesOutOfProvinceBuyersPage extends StatelessWidget { + const SalesOutOfProvinceBuyersPage({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + final SalesOutOfProvinceBuyersLogic logic = Get.put(SalesOutOfProvinceBuyersLogic()); + + return Container(); + } +}