diff --git a/lib/presentation/screens/payout/custom_dateRange.dart b/lib/presentation/screens/payout/custom_dateRange.dart index 660991b..7733dba 100644 --- a/lib/presentation/screens/payout/custom_dateRange.dart +++ b/lib/presentation/screens/payout/custom_dateRange.dart @@ -60,7 +60,7 @@ class _DateFilterRowState extends ConsumerState { dropDownKeyPartner = GlobalKey>>(); late ApiService apiService; - List? selectedPartnerIds = []; + // List? selectedPartnerIds = []; List> getPartnerData = []; List> filteredPartnerData = []; @@ -88,10 +88,10 @@ class _DateFilterRowState extends ConsumerState { final userID = ref.watch(userIdProvider); role = ref.watch(userRoleProvider); print("managerId - $managerId"); - if (userID != null && role != null) { - print('hansles'); - getPartnerDetails(userID); - } + // if (userID != null && role != null) { + // print('hansles'); + // getPartnerDetails(userID); + // } if (managerId != null) { print('managerId - $managerId'); @@ -165,40 +165,40 @@ class _DateFilterRowState extends ConsumerState { } } - Future getPartnerDetails(int id) async { - print('getPartnerDetails called By handler'); - setState(() { - isLoading = true; - }); - - try { - // final response = await apiService.fetchStaffUserList(id, role); - final response = await apiService.fetchStaffListForEnquiryAssignDropDown( - managerId, - id, - role, - ); - if (response['status'] == 'success') { - print('getStaffDetails - ${response['data']}'); - setState(() { - getPartnerData = List>.from(response['data']); - print('API Data - $getPartnerData'); - - filteredPartnerData = List.from(getPartnerData); - print('originalData - $filteredPartnerData'); - }); - } else { - getPartnerData = []; - filteredPartnerData = []; - } - } catch (e) { - print('Exception occurred: $e'); - } finally { - setState(() { - isLoading = false; - }); - } - } + // Future getPartnerDetails(int id) async { + // print('getPartnerDetails called By handler'); + // setState(() { + // isLoading = true; + // }); + // + // try { + // // final response = await apiService.fetchStaffUserList(id, role); + // final response = await apiService.fetchStaffListForEnquiryAssignDropDown( + // managerId, + // id, + // role, + // ); + // if (response['status'] == 'success') { + // print('getStaffDetails - ${response['data']}'); + // setState(() { + // getPartnerData = List>.from(response['data']); + // print('API Data - $getPartnerData'); + // + // filteredPartnerData = List.from(getPartnerData); + // print('originalData - $filteredPartnerData'); + // }); + // } else { + // getPartnerData = []; + // filteredPartnerData = []; + // } + // } catch (e) { + // print('Exception occurred: $e'); + // } finally { + // setState(() { + // isLoading = false; + // }); + // } + // } @override Widget build(BuildContext context) { @@ -350,7 +350,7 @@ class _DateFilterRowState extends ConsumerState { return null; // ✅ no error }, controller: widget.endController, - lastDate: DateTime.now(), + // lastDate: DateTime.now(), onDateSelected: (date) { print("Picked Date: $date"); widget.endController.text = DateFormat('dd-MM-yyyy').format(date); @@ -536,9 +536,15 @@ class _DateFilterRowState extends ConsumerState { // : null, selectedItems: filteredPartnerData .where( - (item) => (selectedPartnerIds ?? []).contains(item['id']), + (item) => (widget.selectedParnter ?? []).contains(item['id']), ) .toList(), + + // selectedItems: filteredPartnerData + // .where( + // (item) => (selectedPartnerIds ?? []).contains(item['id']), + // ) + // .toList(), items: (filter, infiniteScrollProps) { return filteredPartnerData; }, @@ -647,7 +653,7 @@ class _DateFilterRowState extends ConsumerState { // .map((v) => v['id'].toString()) // .toList(); final ids = selectedVals.map((v) => v['id'].toString()).toList(); - print("Selected PArnter IDs: $selectedPartnerIds"); + print("Selected PArnter IDs: $widget.selectedPartnerIds"); widget.onPartnerChanges?.call(ids); // widget.onPartnerChanges!(v['id']); }, @@ -657,153 +663,153 @@ class _DateFilterRowState extends ConsumerState { ); } - Widget buildSelectStaffMem(BuildContext context) { - Map? selectedVehicle; - if (widget.selectedStaffId == null) { - selectedVehicle = null; - } else if (widget.selectedStaffId != null) { - selectedVehicle = filteredPartnerData.firstWhere( - (item) => item['id'] == widget.selectedStaffId, - orElse: () => {}, // empty map - ); - if (selectedVehicle.isEmpty) selectedVehicle = null; - } else if (selectedStaff != null) { - selectedVehicle = filteredPartnerData.firstWhere( - (item) => item['id'] == selectedStaff, - orElse: () => {}, // empty map - ); - if (selectedVehicle.isEmpty) selectedVehicle = null; - } else { - selectedVehicle = null; - } - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // Text("Staff Name", style: _textStyle), - // SizedBox(height: 10), - SizedBox( - height: 35, - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(5.0), - border: Border.all(color: Color(0xFFE2E8F0)), - // color: Colors.black, - ), - - width: ResponsiveLayout.isMobile(context) - ? null - : MediaQuery.of(context).size.width * 0.13, - // height: 45, - child: DropdownSearch>( - // key: dropDownKey, - key: ValueKey(selectedStaff), - // selectedItem: selectedVehicle.isNotEmpty ? selectedVehicle : null, - selectedItem: selectedVehicle, - - items: (filter, infiniteScrollProps) { - return filteredPartnerData; - }, - - itemAsString: (val) => val['name'].toString(), - compareFn: (item, selectedItem) => - item['id'] == selectedItem['id'], // ✅ compare by id - dropdownBuilder: (context, selectedItem) => Align( - alignment: Alignment.centerLeft, - child: Text( - selectedItem != null ? selectedItem['name'].toString() : "", - style: GoogleFonts.poppins(fontSize: 11, color: Colors.black), - overflow: TextOverflow.ellipsis, - maxLines: 1, - softWrap: false, - ), - ), - decoratorProps: DropDownDecoratorProps( - decoration: - AppInputDecorations.dropdownDecoration( - label: "Select Staff ", - ).copyWith( - filled: true, - fillColor: - Colors.white, // 👈 makes the dropdown input white - contentPadding: const EdgeInsets.symmetric( - horizontal: 6, - vertical: 1, // 👈 adjust this to make the field shorter - ), - ), - ), - - popupProps: PopupProps.menu( - fit: FlexFit.loose, - constraints: BoxConstraints(maxHeight: 250), - menuProps: MenuProps( - backgroundColor: - Colors.white, // 👈 sets dropdown background to white - ), - showSearchBox: true, - searchFieldProps: TextFieldProps( - decoration: InputDecoration( - filled: true, - fillColor: Colors.white, - hintText: "Search Staff ...", - hintStyle: GoogleFonts.inter( - fontSize: 12, - color: Colors.black, - ), - enabledBorder: OutlineInputBorder( - borderSide: BorderSide( - color: Colors.white, - ), // 👈 Normal border - ), - focusedBorder: OutlineInputBorder( - borderSide: BorderSide( - color: Colors.white, - width: 1.5, - ), // 👈 Focused border - ), - ), - ), - - itemBuilder: (context, item, isDisabled, isSelected) { - return Container( - // color: isSelected ? Colors.blue.withOpacity(0.1) : null, - padding: const EdgeInsets.symmetric( - horizontal: 8, - vertical: 3, - ), - child: Text( - item['name'].toString(), - style: GoogleFonts.inter( - fontSize: 13, - color: Colors.black, - ), - ), - ); - }, - - // constraints: BoxConstraints(), - ), - - onChanged: (val) { - if (val != null) { - print("Selected Staff : ${val['name']}"); - print("Id: ${val['id']}"); - // selectedStaffName = val['name']; - // selectedStaff = val['id']; - widget.onBrokerChanged!(val['id']); - // if (widget.onFilterStaff != null) - // widget.onFilterStaff!(val['id']); - - // Future.microtask(() => widget.onFilter()); - // controllers['agentId']?.text = val['agent_code']; - // agentId = agent['id']; - } - }, - ), - ), - ), - ], - ); - } + // Widget buildSelectStaffMem(BuildContext context) { + // Map? selectedVehicle; + // if (widget.selectedStaffId == null) { + // selectedVehicle = null; + // } else if (widget.selectedStaffId != null) { + // selectedVehicle = filteredPartnerData.firstWhere( + // (item) => item['id'] == widget.selectedStaffId, + // orElse: () => {}, // empty map + // ); + // if (selectedVehicle.isEmpty) selectedVehicle = null; + // } else if (selectedStaff != null) { + // selectedVehicle = filteredPartnerData.firstWhere( + // (item) => item['id'] == selectedStaff, + // orElse: () => {}, // empty map + // ); + // if (selectedVehicle.isEmpty) selectedVehicle = null; + // } else { + // selectedVehicle = null; + // } + // return Column( + // crossAxisAlignment: CrossAxisAlignment.start, + // children: [ + // // Text("Staff Name", style: _textStyle), + // // SizedBox(height: 10), + // SizedBox( + // height: 35, + // child: Container( + // decoration: BoxDecoration( + // borderRadius: BorderRadius.circular(5.0), + // border: Border.all(color: Color(0xFFE2E8F0)), + // // color: Colors.black, + // ), + // + // width: ResponsiveLayout.isMobile(context) + // ? null + // : MediaQuery.of(context).size.width * 0.13, + // // height: 45, + // child: DropdownSearch>( + // // key: dropDownKey, + // key: ValueKey(selectedStaff), + // // selectedItem: selectedVehicle.isNotEmpty ? selectedVehicle : null, + // selectedItem: selectedVehicle, + // + // items: (filter, infiniteScrollProps) { + // return filteredPartnerData; + // }, + // + // itemAsString: (val) => val['name'].toString(), + // compareFn: (item, selectedItem) => + // item['id'] == selectedItem['id'], // ✅ compare by id + // dropdownBuilder: (context, selectedItem) => Align( + // alignment: Alignment.centerLeft, + // child: Text( + // selectedItem != null ? selectedItem['name'].toString() : "", + // style: GoogleFonts.poppins(fontSize: 11, color: Colors.black), + // overflow: TextOverflow.ellipsis, + // maxLines: 1, + // softWrap: false, + // ), + // ), + // decoratorProps: DropDownDecoratorProps( + // decoration: + // AppInputDecorations.dropdownDecoration( + // label: "Select Staff ", + // ).copyWith( + // filled: true, + // fillColor: + // Colors.white, // 👈 makes the dropdown input white + // contentPadding: const EdgeInsets.symmetric( + // horizontal: 6, + // vertical: 1, // 👈 adjust this to make the field shorter + // ), + // ), + // ), + // + // popupProps: PopupProps.menu( + // fit: FlexFit.loose, + // constraints: BoxConstraints(maxHeight: 250), + // menuProps: MenuProps( + // backgroundColor: + // Colors.white, // 👈 sets dropdown background to white + // ), + // showSearchBox: true, + // searchFieldProps: TextFieldProps( + // decoration: InputDecoration( + // filled: true, + // fillColor: Colors.white, + // hintText: "Search Staff ...", + // hintStyle: GoogleFonts.inter( + // fontSize: 12, + // color: Colors.black, + // ), + // enabledBorder: OutlineInputBorder( + // borderSide: BorderSide( + // color: Colors.white, + // ), // 👈 Normal border + // ), + // focusedBorder: OutlineInputBorder( + // borderSide: BorderSide( + // color: Colors.white, + // width: 1.5, + // ), // 👈 Focused border + // ), + // ), + // ), + // + // itemBuilder: (context, item, isDisabled, isSelected) { + // return Container( + // // color: isSelected ? Colors.blue.withOpacity(0.1) : null, + // padding: const EdgeInsets.symmetric( + // horizontal: 8, + // vertical: 3, + // ), + // child: Text( + // item['name'].toString(), + // style: GoogleFonts.inter( + // fontSize: 13, + // color: Colors.black, + // ), + // ), + // ); + // }, + // + // // constraints: BoxConstraints(), + // ), + // + // onChanged: (val) { + // if (val != null) { + // print("Selected Staff : ${val['name']}"); + // print("Id: ${val['id']}"); + // // selectedStaffName = val['name']; + // // selectedStaff = val['id']; + // widget.onBrokerChanged!(val['id']); + // // if (widget.onFilterStaff != null) + // // widget.onFilterStaff!(val['id']); + // + // // Future.microtask(() => widget.onFilter()); + // // controllers['agentId']?.text = val['agent_code']; + // // agentId = agent['id']; + // } + // }, + // ), + // ), + // ), + // ], + // ); + // } static final _textStyle = GoogleFonts.poppins( fontSize: 11, diff --git a/lib/presentation/screens/payout/payout_screen.dart b/lib/presentation/screens/payout/payout_screen.dart index 32831f8..e5386e8 100644 --- a/lib/presentation/screens/payout/payout_screen.dart +++ b/lib/presentation/screens/payout/payout_screen.dart @@ -226,6 +226,7 @@ class _PayOutScreenState extends ConsumerState { selectedPolicies = {}; totalPolicies = ''; totalCommission = ''; + // dropDownKeyPartner.currentState?.clear(); }); } diff --git a/lib/presentation/screens/staff/policy/policy_validation.dart b/lib/presentation/screens/staff/policy/policy_validation.dart index 7bf648a..2111cde 100644 --- a/lib/presentation/screens/staff/policy/policy_validation.dart +++ b/lib/presentation/screens/staff/policy/policy_validation.dart @@ -542,6 +542,18 @@ class _policyValidationState extends ConsumerState { return; } + final commissionAmount = + controllers["commission_amount"]?.text.trim() ?? ''; + + if (widget.item?['is_data_accuracy_checked']?.toString() == '0' && + commissionAmount.isEmpty) { + ToastHelper.showWarningToast( + context, + "Please calculate commission amount", + ); + return; + } + if (widget.item?['is_data_accuracy_checked'] == "1") { ToastHelper.showWarningToast(context, "Data already confirmed"); return; @@ -607,7 +619,7 @@ class _policyValidationState extends ConsumerState { final endDate = parseDate(controllers["endDate"]?.text); if (startDate != null && endDate != null && startDate.isAfter(endDate)) { - ToastHelper.showWarningToast( + ToastHelper.showErrorToast( context, 'Start Date cannot be greater than End Date', ); @@ -895,7 +907,7 @@ class _policyValidationState extends ConsumerState { "Fuel Type ", style: GoogleFonts.poppins(fontWeight: FontWeight.w500, fontSize: 11), ), - const SizedBox(width: 6), + const SizedBox(height: 6), DropdownSearch( key: dropDownKeyFuel, @@ -1043,8 +1055,16 @@ class _policyValidationState extends ConsumerState { onTap: onTap, inputFormatters: inputFormatters, // 👈 USE HERE validator: (val) { + // if (val == null || val.isEmpty) { + // return ""; // 👈 triggers error border, no text + // } + + if (!required) { + return null; // ✅ skip validation entirely + } + if (val == null || val.isEmpty) { - return ""; // 👈 triggers error border, no text + return ''; // show red border only when required } return null; }, @@ -1618,6 +1638,8 @@ class _policyValidationState extends ConsumerState { ], ), Row( + crossAxisAlignment: + CrossAxisAlignment.start, children: [ Expanded( child: buildFuelType(context), @@ -1689,6 +1711,8 @@ class _policyValidationState extends ConsumerState { ], ), Row( + crossAxisAlignment: + CrossAxisAlignment.start, children: [ Expanded( child: _buildInput( @@ -1762,7 +1786,7 @@ class _policyValidationState extends ConsumerState { child: _buildInput( 'Commission Amount *', controllers['commission_amount']!, - // required: true, + required: false, keyboardType: TextInputType.numberWithOptions( decimal: true,