refactor: Enhance StaffPayment model and PaymentHistoryItem widget with shift details

This commit is contained in:
Achintha Isuru
2026-03-04 13:37:42 -05:00
parent 256f9fd678
commit 38007d32bc
4 changed files with 50 additions and 12 deletions

View File

@@ -28,6 +28,12 @@ class StaffPayment extends Equatable {
required this.amount, required this.amount,
required this.status, required this.status,
this.paidAt, this.paidAt,
this.shiftTitle,
this.shiftLocation,
this.locationAddress,
this.hoursWorked,
this.hourlyRate,
this.workedTime,
}); });
/// Unique identifier. /// Unique identifier.
final String id; final String id;
@@ -47,6 +53,24 @@ class StaffPayment extends Equatable {
/// When the payment was successfully processed. /// When the payment was successfully processed.
final DateTime? paidAt; 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 @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];
} }

View File

@@ -67,6 +67,16 @@ class PaymentsRepositoryImpl
.execute(); .execute();
return response.data.recentPayments.map((dc.ListRecentPaymentsByStaffIdRecentPayments payment) { 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( return StaffPayment(
id: payment.id, id: payment.id,
staffId: payment.staffId, staffId: payment.staffId,
@@ -74,6 +84,12 @@ class PaymentsRepositoryImpl
amount: payment.invoice.amount, amount: payment.invoice.amount,
status: PaymentAdapter.toPaymentStatus(payment.status?.stringValue ?? 'UNKNOWN'), status: PaymentAdapter.toPaymentStatus(payment.status?.stringValue ?? 'UNKNOWN'),
paidAt: _service.toDateTime(payment.invoice.issueDate), paidAt: _service.toDateTime(payment.invoice.issueDate),
shiftTitle: shiftTitle,
shiftLocation: locationHub,
locationAddress: shiftLocation,
hoursWorked: hoursWorked,
hourlyRate: hourlyRate,
workedTime: payment.workedTime,
); );
}).toList(); }).toList();
}); });

View File

@@ -1,5 +1,4 @@
import 'package:design_system/design_system.dart'; import 'package:design_system/design_system.dart';
import 'package:krow_core/core.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_modular/flutter_modular.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_event.dart';
import '../blocs/payments/payments_state.dart'; import '../blocs/payments/payments_state.dart';
import '../widgets/payment_stats_card.dart'; import '../widgets/payment_stats_card.dart';
import '../widgets/pending_pay_card.dart';
import '../widgets/payment_history_item.dart'; import '../widgets/payment_history_item.dart';
import '../widgets/earnings_graph.dart'; import '../widgets/earnings_graph.dart';
@@ -191,16 +189,16 @@ class _PaymentsPageState extends State<PaymentsPage> {
bottom: UiConstants.space2), bottom: UiConstants.space2),
child: PaymentHistoryItem( child: PaymentHistoryItem(
amount: payment.amount, amount: payment.amount,
title: "Shift Payment", title: payment.shiftTitle ?? "Shift Payment",
location: "Varies", location: payment.shiftLocation ?? "Varies",
address: "Payment ID: ${payment.id}", address: payment.locationAddress ?? payment.id,
date: payment.paidAt != null date: payment.paidAt != null
? DateFormat('E, MMM d') ? DateFormat('E, MMM d')
.format(payment.paidAt!) .format(payment.paidAt!)
: 'Pending', : 'Pending',
workedTime: "Completed", workedTime: payment.workedTime ?? "Completed",
hours: 0, hours: (payment.hoursWorked ?? 0).toInt(),
rate: 0.0, rate: payment.hourlyRate ?? 0.0,
status: payment.status.name.toUpperCase(), status: payment.status.name.toUpperCase(),
), ),
); );

View File

@@ -71,7 +71,7 @@ class PaymentHistoryItem extends StatelessWidget {
borderRadius: BorderRadius.circular(UiConstants.radiusBase), borderRadius: BorderRadius.circular(UiConstants.radiusBase),
), ),
child: const Icon( child: const Icon(
UiIcons.chart, UiIcons.dollar,
color: UiColors.mutedForeground, color: UiColors.mutedForeground,
size: 24, size: 24,
), ),
@@ -92,7 +92,7 @@ class PaymentHistoryItem extends StatelessWidget {
children: <Widget>[ children: <Widget>[
Text( Text(
title, title,
style: UiTypography.body2b.textPrimary, style: UiTypography.body2m,
), ),
Text( Text(
location, location,
@@ -106,7 +106,7 @@ class PaymentHistoryItem extends StatelessWidget {
children: <Widget>[ children: <Widget>[
Text( Text(
"\$${amount.toStringAsFixed(0)}", "\$${amount.toStringAsFixed(0)}",
style: UiTypography.headline4m.textPrimary, style: UiTypography.headline4b,
), ),
Text( Text(
"\$${rate.toStringAsFixed(0)}/hr · ${hours}h", "\$${rate.toStringAsFixed(0)}/hr · ${hours}h",