refactor: Enhance StaffPayment model and PaymentHistoryItem widget with shift details
This commit is contained in:
@@ -28,6 +28,12 @@ class StaffPayment extends Equatable {
|
||||
required this.amount,
|
||||
required this.status,
|
||||
this.paidAt,
|
||||
this.shiftTitle,
|
||||
this.shiftLocation,
|
||||
this.locationAddress,
|
||||
this.hoursWorked,
|
||||
this.hourlyRate,
|
||||
this.workedTime,
|
||||
});
|
||||
/// Unique identifier.
|
||||
final String id;
|
||||
@@ -47,6 +53,24 @@ class StaffPayment extends Equatable {
|
||||
/// When the payment was successfully processed.
|
||||
final DateTime? paidAt;
|
||||
|
||||
/// Title of the shift worked.
|
||||
final String? shiftTitle;
|
||||
|
||||
/// Location/hub name of the shift.
|
||||
final String? shiftLocation;
|
||||
|
||||
/// Address of the shift location.
|
||||
final String? locationAddress;
|
||||
|
||||
/// Number of hours worked.
|
||||
final double? hoursWorked;
|
||||
|
||||
/// Hourly rate for the shift.
|
||||
final double? hourlyRate;
|
||||
|
||||
/// Work session duration or status.
|
||||
final String? workedTime;
|
||||
|
||||
@override
|
||||
List<Object?> get props => <Object?>[id, staffId, assignmentId, amount, status, paidAt];
|
||||
List<Object?> get props => <Object?>[id, staffId, assignmentId, amount, status, paidAt, shiftTitle, shiftLocation, locationAddress, hoursWorked, hourlyRate, workedTime];
|
||||
}
|
||||
@@ -67,6 +67,16 @@ class PaymentsRepositoryImpl
|
||||
.execute();
|
||||
|
||||
return response.data.recentPayments.map((dc.ListRecentPaymentsByStaffIdRecentPayments payment) {
|
||||
// Extract shift details from nested application structure
|
||||
final String? shiftTitle = payment.application.shiftRole.shift.title;
|
||||
final String? locationAddress = payment.application.shiftRole.shift.locationAddress;
|
||||
final double? hoursWorked = payment.application.shiftRole.hours;
|
||||
final double? hourlyRate = payment.application.shiftRole.role.costPerHour;
|
||||
// Extract hub details from order
|
||||
final String? locationHub = payment.invoice.order.teamHub.hubName;
|
||||
final String? hubAddress = payment.invoice.order.teamHub.address;
|
||||
final String? shiftLocation = locationAddress ?? hubAddress;
|
||||
|
||||
return StaffPayment(
|
||||
id: payment.id,
|
||||
staffId: payment.staffId,
|
||||
@@ -74,6 +84,12 @@ class PaymentsRepositoryImpl
|
||||
amount: payment.invoice.amount,
|
||||
status: PaymentAdapter.toPaymentStatus(payment.status?.stringValue ?? 'UNKNOWN'),
|
||||
paidAt: _service.toDateTime(payment.invoice.issueDate),
|
||||
shiftTitle: shiftTitle,
|
||||
shiftLocation: locationHub,
|
||||
locationAddress: shiftLocation,
|
||||
hoursWorked: hoursWorked,
|
||||
hourlyRate: hourlyRate,
|
||||
workedTime: payment.workedTime,
|
||||
);
|
||||
}).toList();
|
||||
});
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'package:design_system/design_system.dart';
|
||||
import 'package:krow_core/core.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_modular/flutter_modular.dart';
|
||||
@@ -10,7 +9,6 @@ import '../blocs/payments/payments_bloc.dart';
|
||||
import '../blocs/payments/payments_event.dart';
|
||||
import '../blocs/payments/payments_state.dart';
|
||||
import '../widgets/payment_stats_card.dart';
|
||||
import '../widgets/pending_pay_card.dart';
|
||||
import '../widgets/payment_history_item.dart';
|
||||
import '../widgets/earnings_graph.dart';
|
||||
|
||||
@@ -191,16 +189,16 @@ class _PaymentsPageState extends State<PaymentsPage> {
|
||||
bottom: UiConstants.space2),
|
||||
child: PaymentHistoryItem(
|
||||
amount: payment.amount,
|
||||
title: "Shift Payment",
|
||||
location: "Varies",
|
||||
address: "Payment ID: ${payment.id}",
|
||||
title: payment.shiftTitle ?? "Shift Payment",
|
||||
location: payment.shiftLocation ?? "Varies",
|
||||
address: payment.locationAddress ?? payment.id,
|
||||
date: payment.paidAt != null
|
||||
? DateFormat('E, MMM d')
|
||||
.format(payment.paidAt!)
|
||||
: 'Pending',
|
||||
workedTime: "Completed",
|
||||
hours: 0,
|
||||
rate: 0.0,
|
||||
workedTime: payment.workedTime ?? "Completed",
|
||||
hours: (payment.hoursWorked ?? 0).toInt(),
|
||||
rate: payment.hourlyRate ?? 0.0,
|
||||
status: payment.status.name.toUpperCase(),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -71,7 +71,7 @@ class PaymentHistoryItem extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(UiConstants.radiusBase),
|
||||
),
|
||||
child: const Icon(
|
||||
UiIcons.chart,
|
||||
UiIcons.dollar,
|
||||
color: UiColors.mutedForeground,
|
||||
size: 24,
|
||||
),
|
||||
@@ -92,7 +92,7 @@ class PaymentHistoryItem extends StatelessWidget {
|
||||
children: <Widget>[
|
||||
Text(
|
||||
title,
|
||||
style: UiTypography.body2b.textPrimary,
|
||||
style: UiTypography.body2m,
|
||||
),
|
||||
Text(
|
||||
location,
|
||||
@@ -106,7 +106,7 @@ class PaymentHistoryItem extends StatelessWidget {
|
||||
children: <Widget>[
|
||||
Text(
|
||||
"\$${amount.toStringAsFixed(0)}",
|
||||
style: UiTypography.headline4m.textPrimary,
|
||||
style: UiTypography.headline4b,
|
||||
),
|
||||
Text(
|
||||
"\$${rate.toStringAsFixed(0)}/hr · ${hours}h",
|
||||
|
||||
Reference in New Issue
Block a user