FIX_bug
This commit is contained in:
parent
6c91f141d5
commit
aebb7271d0
@ -2192,13 +2192,26 @@ class ApiService {
|
||||
return response;
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> getPayoutList() async {
|
||||
Future<Map<String, dynamic>> getPayoutList({
|
||||
String? fromDate,
|
||||
String? toDate,
|
||||
}) async {
|
||||
// print(_token);
|
||||
if (_token == null) {
|
||||
await _initializeToken();
|
||||
}
|
||||
|
||||
final url = Uri.parse('${Env.apiUrl}invoice/list');
|
||||
final Uri url;
|
||||
if (fromDate != null &&
|
||||
fromDate.isNotEmpty &&
|
||||
toDate != null &&
|
||||
toDate.isNotEmpty) {
|
||||
url = Uri.parse('${Env.apiUrl}invoice/list').replace(
|
||||
queryParameters: {'from_date': fromDate, 'to_date': toDate},
|
||||
);
|
||||
} else {
|
||||
url = Uri.parse('${Env.apiUrl}invoice/list');
|
||||
}
|
||||
|
||||
final headers = {
|
||||
'Authorization': 'Bearer $_token' ?? '',
|
||||
|
||||
@ -70,7 +70,12 @@ class _PayoutListState extends ConsumerState<PayoutList> {
|
||||
});
|
||||
|
||||
try {
|
||||
final response = await apiService.getPayoutList();
|
||||
final from = controllers['startDate']?.text.trim() ?? '';
|
||||
final to = controllers['endDate']?.text.trim() ?? '';
|
||||
final response = await apiService.getPayoutList(
|
||||
fromDate: from.isNotEmpty ? from : null,
|
||||
toDate: to.isNotEmpty ? to : null,
|
||||
);
|
||||
|
||||
if (response['status'] == 'success') {
|
||||
print('PL 3 => getPayoutList - ${response['data']}');
|
||||
@ -78,7 +83,8 @@ class _PayoutListState extends ConsumerState<PayoutList> {
|
||||
print(' PL 4 => getPayoutList => ${response['data']}');
|
||||
|
||||
setState(() {
|
||||
|
||||
currentPage = 1;
|
||||
|
||||
if (data is List) {
|
||||
// Already a list of maps
|
||||
getPayoutData = List<Map<String, dynamic>>.from(data);
|
||||
@ -145,7 +151,9 @@ class _PayoutListState extends ConsumerState<PayoutList> {
|
||||
return sortedData.sublist(startIndex, endIndex);
|
||||
}
|
||||
|
||||
void filterDateRange() {}
|
||||
void filterDateRange() {
|
||||
getPayoutList();
|
||||
}
|
||||
|
||||
void refrshfilterDateRange() {
|
||||
setState(() {
|
||||
@ -166,22 +174,17 @@ class _PayoutListState extends ConsumerState<PayoutList> {
|
||||
final q = query.toLowerCase();
|
||||
setState(() {
|
||||
filteredData = getPayoutData.where((item) {
|
||||
// Search against the same display strings as the table (not raw API values).
|
||||
final updatedAtSearch = _exportUpdatedAtForExcel(item['updated_at'])
|
||||
.toLowerCase();
|
||||
// Search matches visible table columns only (broker / referer / updated hidden).
|
||||
final invoiceDateSearch = _formatDateSafe(item['invoice_date'])
|
||||
.toLowerCase();
|
||||
final statusSearch =
|
||||
_exportPayoutStatusLabel(item['payout_status']).toLowerCase();
|
||||
|
||||
return updatedAtSearch.contains(q) ||
|
||||
invoiceDateSearch.contains(q) ||
|
||||
return invoiceDateSearch.contains(q) ||
|
||||
(item['invoice_no'] ?? '-').toLowerCase().contains(q) ||
|
||||
(item['invoice_amount_indian_format'] ?? '-')
|
||||
.toLowerCase()
|
||||
.contains(q) ||
|
||||
(item['broker_name'] ?? '-').toLowerCase().contains(q) ||
|
||||
(item['partner_names'] ?? '-').toLowerCase().contains(q) ||
|
||||
(item['utr_numbers'] ?? '-').toLowerCase().contains(q) ||
|
||||
(item['invoiced_amount'] ?? '0').toLowerCase().contains(q) ||
|
||||
(item['payout_amount'] ?? '0').toLowerCase().contains(q) ||
|
||||
@ -214,15 +217,6 @@ class _PayoutListState extends ConsumerState<PayoutList> {
|
||||
}
|
||||
}
|
||||
|
||||
String _formatTime(String rawDate) {
|
||||
try {
|
||||
final dateTime = DateTime.parse(rawDate);
|
||||
return DateFormat('HH:mm').format(dateTime);
|
||||
} catch (e) {
|
||||
return '-';
|
||||
}
|
||||
}
|
||||
|
||||
/// Excel export: match table (1 = Pending, 2 = Completed).
|
||||
String _exportPayoutStatusLabel(dynamic v) {
|
||||
if (v == null) return '-';
|
||||
@ -233,19 +227,6 @@ class _PayoutListState extends ConsumerState<PayoutList> {
|
||||
return 'Completed';
|
||||
}
|
||||
|
||||
/// Excel export: same as table — dd-MM-yyyy + 24h time in one cell.
|
||||
String _exportUpdatedAtForExcel(dynamic v) {
|
||||
if (v == null) return '-';
|
||||
final raw = v.toString().trim();
|
||||
if (raw.isEmpty || raw.toLowerCase() == 'null') return '-';
|
||||
try {
|
||||
final dateTime = DateTime.parse(raw);
|
||||
return '${DateFormat('dd-MM-yyyy').format(dateTime)} ${DateFormat('HH:mm').format(dateTime)}';
|
||||
} catch (_) {
|
||||
return raw;
|
||||
}
|
||||
}
|
||||
|
||||
String _displayText(dynamic value) {
|
||||
if (value == null) return '-';
|
||||
final text = value.toString().trim();
|
||||
@ -258,18 +239,6 @@ class _PayoutListState extends ConsumerState<PayoutList> {
|
||||
return '${value.substring(0, maxChars)}...';
|
||||
}
|
||||
|
||||
String _partnerTooltipText(dynamic value) {
|
||||
final text = _displayText(value);
|
||||
if (text == '-') return text;
|
||||
final items = text
|
||||
.split(',')
|
||||
.map((e) => e.trim())
|
||||
.where((e) => e.isNotEmpty)
|
||||
.toList();
|
||||
if (items.isEmpty) return text;
|
||||
return items.join('\n');
|
||||
}
|
||||
|
||||
String _utrTooltipText(dynamic value) {
|
||||
final text = _displayText(value);
|
||||
if (text == '-') return text;
|
||||
@ -685,14 +654,36 @@ class _PayoutListState extends ConsumerState<PayoutList> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _payoutInvoiceDateFilter(BuildContext context) {
|
||||
return DateFilterRow(
|
||||
compactDateFiltersOnly: true,
|
||||
dataFrom: 'Payout',
|
||||
role: roleId,
|
||||
id: userId,
|
||||
selectedStaffId: null,
|
||||
startController: controllers['startDate']!,
|
||||
endController: controllers['endDate']!,
|
||||
onStatusChanged: (_) {},
|
||||
formKey: _formKey,
|
||||
isMobile: ResponsiveLayout.isMobile(context),
|
||||
onFilter: filterDateRange,
|
||||
onRefresh: refrshfilterDateRange,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContent(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
if (ResponsiveLayout.isMobile(context))
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: _payoutInvoiceDateFilter(context),
|
||||
),
|
||||
Container(
|
||||
// height: 40,
|
||||
// color: Colors.pink,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
@ -702,8 +693,20 @@ class _PayoutListState extends ConsumerState<PayoutList> {
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
),
|
||||
|
||||
Spacer(),
|
||||
if (!ResponsiveLayout.isMobile(context)) ...[
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: _payoutInvoiceDateFilter(context),
|
||||
),
|
||||
),
|
||||
),
|
||||
] else ...[
|
||||
const Spacer(),
|
||||
],
|
||||
ThemedSearchField(
|
||||
hintText: 'Search',
|
||||
// backgroundColor: Color(0xFFF6F8F8),
|
||||
@ -753,31 +756,24 @@ class _PayoutListState extends ConsumerState<PayoutList> {
|
||||
"S.No",
|
||||
"Invoice No",
|
||||
"Invoice Date",
|
||||
"Broker Name",
|
||||
"Referer",
|
||||
"UTR Details",
|
||||
"UTR Number",
|
||||
"Invoiced Amount",
|
||||
"Payout Amount",
|
||||
"Balance Amount",
|
||||
"Status",
|
||||
"Updated Date",
|
||||
],
|
||||
keys: [
|
||||
"id",
|
||||
"invoice_no",
|
||||
"invoice_date",
|
||||
"broker_name",
|
||||
"partner_names",
|
||||
"utr_numbers",
|
||||
"invoiced_amount",
|
||||
"payout_amount",
|
||||
"balance_amount",
|
||||
"payout_status",
|
||||
"updated_at",
|
||||
],
|
||||
valueFormatters: {
|
||||
'payout_status': (v, _) => _exportPayoutStatusLabel(v),
|
||||
'updated_at': (v, _) => _exportUpdatedAtForExcel(v),
|
||||
},
|
||||
),
|
||||
],
|
||||
@ -801,29 +797,17 @@ class _PayoutListState extends ConsumerState<PayoutList> {
|
||||
flex: 3,
|
||||
child: Text('Invoice No', style: _headerStyle),
|
||||
),
|
||||
Expanded(flex: 2, child: Text('UTR Number', style: _headerStyle)),
|
||||
Expanded(flex: 2, child: Text('Invoiced Amount', style: _headerStyle),),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text('Broker Name', style: _headerStyle),
|
||||
),
|
||||
Expanded(flex: 3, child: Text('Referer', style: _headerStyle)),
|
||||
Expanded(flex: 2, child: Text('UTR Details', style: _headerStyle)),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text('Invoiced\nAmount', style: _headerStyle),
|
||||
child: Text('Payout Amount', style: _headerStyle),
|
||||
),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text('Payout\nAmount', style: _headerStyle),
|
||||
),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text('Balance\nAmount', style: _headerStyle),
|
||||
child: Text('Balance Amount', style: _headerStyle),
|
||||
),
|
||||
Expanded(flex: 2, child: Text('Status', style: _headerStyle)),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text('Updated Date', style: _headerStyle),
|
||||
),
|
||||
Expanded(flex: 2, child: Text('Action', style: _headerStyle)),
|
||||
],
|
||||
),
|
||||
@ -897,29 +881,6 @@ class _PayoutListState extends ConsumerState<PayoutList> {
|
||||
maxLines: 3,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text(
|
||||
_displayText(item['broker_name']),
|
||||
style: _dataBold,
|
||||
softWrap: true,
|
||||
maxLines: 3,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Tooltip(
|
||||
message: _partnerTooltipText(item['partner_names']),
|
||||
waitDuration: const Duration(milliseconds: 250),
|
||||
child: Text(
|
||||
_truncateText(_displayText(item['partner_names']), maxChars: 25),
|
||||
style: _dataBold,
|
||||
softWrap: false,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Tooltip(
|
||||
@ -976,30 +937,6 @@ class _PayoutListState extends ConsumerState<PayoutList> {
|
||||
),
|
||||
),
|
||||
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: item['updated_at'] != null
|
||||
? Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
_formatDate(item['updated_at']),
|
||||
style: _dataBold,
|
||||
softWrap: false,
|
||||
maxLines: 1,
|
||||
),
|
||||
Text(
|
||||
_formatTime(item['updated_at']),
|
||||
style: _dataBold,
|
||||
softWrap: false,
|
||||
maxLines: 1,
|
||||
),
|
||||
],
|
||||
)
|
||||
: Text('-', style: _dataBold),
|
||||
),
|
||||
|
||||
// ACTION ICONS (Edit + Delete)
|
||||
Expanded(
|
||||
flex: 2,
|
||||
|
||||
@ -61,6 +61,14 @@ class _PayoutReportScreenState extends ConsumerState<PayoutReportScreen> {
|
||||
return v == 'no';
|
||||
}
|
||||
|
||||
/// UI / export: capitalize first letter, lowercase the rest (e.g. `yes` → `Yes`).
|
||||
String _receivedLabel(dynamic v) {
|
||||
final s = v?.toString().trim() ?? '';
|
||||
if (s.isEmpty) return '-';
|
||||
return s[0].toUpperCase() +
|
||||
(s.length > 1 ? s.substring(1).toLowerCase() : '');
|
||||
}
|
||||
|
||||
String? _agentIdForApi() {
|
||||
if (_isAgentRole()) {
|
||||
final uid = ref.read(userIdProvider);
|
||||
@ -746,6 +754,9 @@ class _PayoutReportScreenState extends ConsumerState<PayoutReportScreen> {
|
||||
'utr_no',
|
||||
'received_or_not',
|
||||
],
|
||||
valueFormatters: {
|
||||
'received_or_not': (v, _) => _receivedLabel(v),
|
||||
},
|
||||
);
|
||||
if (mounted) {
|
||||
ToastHelper.showSuccessToast(context, 'Export finished');
|
||||
@ -1052,7 +1063,7 @@ class _PayoutReportScreenState extends ConsumerState<PayoutReportScreen> {
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text(
|
||||
_cell(item, ['received_or_not']),
|
||||
_receivedLabel(item['received_or_not']),
|
||||
style: rowStyle,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
|
||||
@ -54,6 +54,9 @@ class DateFilterRow extends ConsumerStatefulWidget {
|
||||
final VoidCallback onRefresh;
|
||||
final GlobalKey<FormState> formKey;
|
||||
final bool isMobile;
|
||||
/// When true, only start/end date fields and filter/refresh actions are shown
|
||||
/// (no status, staff, insurer, or partner controls).
|
||||
final bool compactDateFiltersOnly;
|
||||
final role;
|
||||
final id;
|
||||
|
||||
@ -77,6 +80,7 @@ class DateFilterRow extends ConsumerStatefulWidget {
|
||||
required this.role,
|
||||
required this.id,
|
||||
this.isMobile = false,
|
||||
this.compactDateFiltersOnly = false,
|
||||
this.dataFrom,
|
||||
});
|
||||
|
||||
@ -116,6 +120,7 @@ class _DateFilterRowState extends ConsumerState<DateFilterRow> {
|
||||
// final handlerId = ref.watch(handlerIdProvider);
|
||||
role = ref.watch(userRoleProvider);
|
||||
print("managerId - $managerId");
|
||||
if (widget.compactDateFiltersOnly) return;
|
||||
if (userID != null && role != null) {
|
||||
print('hansles');
|
||||
getStaffDetails(userID);
|
||||
@ -235,7 +240,8 @@ class _DateFilterRowState extends ConsumerState<DateFilterRow> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (widget.role == 'Accounts' &&
|
||||
if (!widget.compactDateFiltersOnly &&
|
||||
widget.role == 'Accounts' &&
|
||||
widget.dataFrom == 'Policy' &&
|
||||
filteredPartnerData.isEmpty &&
|
||||
!_partnerFetchAttempted) {
|
||||
@ -275,23 +281,24 @@ class _DateFilterRowState extends ConsumerState<DateFilterRow> {
|
||||
buildEndDate(context),
|
||||
SizedBox(width: spacing),
|
||||
|
||||
if (widget.dataFrom == null && widget.dataFrom != 'Policy') ...[
|
||||
buildStatusSearch(context,widget.role),
|
||||
SizedBox(width: spacing),
|
||||
],
|
||||
if (!widget.compactDateFiltersOnly) ...[
|
||||
if (widget.dataFrom == null && widget.dataFrom != 'Policy') ...[
|
||||
buildStatusSearch(context, widget.role),
|
||||
SizedBox(width: spacing),
|
||||
],
|
||||
|
||||
if (widget.role == 'manager' || widget.role == 'handler') ...[
|
||||
buildSelectStaffMem(context),
|
||||
SizedBox(width: spacing),
|
||||
if (widget.role == 'manager' || widget.role == 'handler') ...[
|
||||
buildSelectStaffMem(context),
|
||||
SizedBox(width: spacing),
|
||||
],
|
||||
if (widget.role == 'Accounts' && widget.dataFrom == 'Policy') ...[
|
||||
buildSelectPartnerAccountsPolicy(context),
|
||||
SizedBox(width: spacing),
|
||||
buildPolicyReportFlagSearch(context),
|
||||
SizedBox(width: spacing),
|
||||
buildSelectInsurer(context),
|
||||
],
|
||||
],
|
||||
if (widget.role == 'Accounts' && widget.dataFrom == 'Policy') ...[
|
||||
buildSelectPartnerAccountsPolicy(context),
|
||||
SizedBox(width: spacing),
|
||||
buildPolicyReportFlagSearch(context),
|
||||
SizedBox(width: spacing),
|
||||
buildSelectInsurer(context),
|
||||
],
|
||||
|
||||
];
|
||||
|
||||
final buttons = [
|
||||
|
||||
Loading…
Reference in New Issue
Block a user