Merge branch 'dev' into 312-feature-integrate-google-maps-places-autocomplete-for-hub-address-validation
This commit is contained in:
@@ -1,67 +0,0 @@
|
||||
// ignore: depend_on_referenced_packages
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../../domain/entities/payment_summary.dart';
|
||||
import '../../domain/entities/payment_transaction.dart';
|
||||
import 'payments_remote_datasource.dart';
|
||||
|
||||
class PaymentsMockDataSource implements PaymentsRemoteDataSource {
|
||||
@override
|
||||
Future<PaymentSummary> fetchPaymentSummary() async {
|
||||
// Simulate network delay
|
||||
await Future.delayed(const Duration(milliseconds: 800));
|
||||
|
||||
// Mock data matching the prototype
|
||||
return const PaymentSummary(
|
||||
weeklyEarnings: 847.50,
|
||||
monthlyEarnings: 3240.0,
|
||||
pendingEarnings: 285.0,
|
||||
totalEarnings: 12450.0,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<PaymentTransaction>> fetchPaymentHistory(String period) async {
|
||||
await Future.delayed(const Duration(milliseconds: 1000));
|
||||
|
||||
// Mock data matching the prototype
|
||||
// In a real scenario, this would filter by 'period' (week/month/year)
|
||||
return [
|
||||
PaymentTransaction(
|
||||
id: '1',
|
||||
title: 'Cook',
|
||||
location: 'LA Convention Center',
|
||||
address: '1201 S Figueroa St, Los Angeles, CA 90015',
|
||||
workedTime: '2:00 PM - 10:00 PM',
|
||||
amount: 160.00,
|
||||
status: 'PAID',
|
||||
hours: 8,
|
||||
rate: 20.0,
|
||||
date: DateTime(2025, 12, 6), // "Sat, Dec 6" (Using future date to match context if needed, but keeping it simple)
|
||||
),
|
||||
PaymentTransaction(
|
||||
id: '2',
|
||||
title: 'Server',
|
||||
location: 'The Grand Hotel',
|
||||
address: '456 Main St, Los Angeles, CA 90012',
|
||||
workedTime: '5:00 PM - 11:00 PM',
|
||||
amount: 176.00,
|
||||
status: 'PAID',
|
||||
hours: 8,
|
||||
rate: 22.0,
|
||||
date: DateTime(2025, 12, 5), // "Fri, Dec 5"
|
||||
),
|
||||
PaymentTransaction(
|
||||
id: '3',
|
||||
title: 'Bartender',
|
||||
location: 'Club Luxe',
|
||||
address: '789 Sunset Blvd, Los Angeles, CA 90028',
|
||||
workedTime: '6:00 PM - 2:00 AM',
|
||||
amount: 225.00,
|
||||
status: 'PAID',
|
||||
hours: 9,
|
||||
rate: 25.0,
|
||||
date: DateTime(2025, 12, 4), // "Thu, Dec 4"
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import '../../domain/entities/payment_summary.dart';
|
||||
import '../../domain/entities/payment_transaction.dart';
|
||||
|
||||
abstract class PaymentsRemoteDataSource {
|
||||
Future<PaymentSummary> fetchPaymentSummary();
|
||||
Future<List<PaymentTransaction>> fetchPaymentHistory(String period);
|
||||
}
|
||||
@@ -1,20 +1,75 @@
|
||||
import 'package:krow_data_connect/krow_data_connect.dart';
|
||||
import 'package:krow_data_connect/src/session/staff_session_store.dart';
|
||||
import 'package:krow_domain/krow_domain.dart';
|
||||
import '../../domain/entities/payment_summary.dart';
|
||||
import '../../domain/entities/payment_transaction.dart';
|
||||
import '../../domain/repositories/payments_repository.dart';
|
||||
import '../datasources/payments_remote_datasource.dart';
|
||||
|
||||
class PaymentsRepositoryImpl implements PaymentsRepository {
|
||||
final PaymentsRemoteDataSource remoteDataSource;
|
||||
|
||||
PaymentsRepositoryImpl({required this.remoteDataSource});
|
||||
PaymentsRepositoryImpl();
|
||||
|
||||
@override
|
||||
Future<PaymentSummary> getPaymentSummary() async {
|
||||
return await remoteDataSource.fetchPaymentSummary();
|
||||
// Current requirement: Mock data only for summary
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
return const PaymentSummary(
|
||||
weeklyEarnings: 847.50,
|
||||
monthlyEarnings: 3240.0,
|
||||
pendingEarnings: 285.0,
|
||||
totalEarnings: 12450.0,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<PaymentTransaction>> getPaymentHistory(String period) async {
|
||||
return await remoteDataSource.fetchPaymentHistory(period);
|
||||
Future<List<StaffPayment>> getPaymentHistory(String period) async {
|
||||
final session = StaffSessionStore.instance.session;
|
||||
if (session?.staff?.id == null) return [];
|
||||
|
||||
final String currentStaffId = session!.staff!.id;
|
||||
|
||||
try {
|
||||
final response = await ExampleConnector.instance
|
||||
.listRecentPaymentsByStaffId(staffId: currentStaffId)
|
||||
.execute();
|
||||
|
||||
return response.data.recentPayments.map((payment) {
|
||||
return StaffPayment(
|
||||
id: payment.id,
|
||||
staffId: payment.staffId,
|
||||
assignmentId: payment.applicationId,
|
||||
amount: payment.invoice.amount,
|
||||
status: _mapStatus(payment.status),
|
||||
paidAt: payment.invoice.issueDate?.toDate(),
|
||||
);
|
||||
}).toList();
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
PaymentStatus _mapStatus(EnumValue<RecentPaymentStatus>? status) {
|
||||
if (status == null || status is! Known) return PaymentStatus.pending;
|
||||
|
||||
switch ((status as Known).value) {
|
||||
case RecentPaymentStatus.PAID:
|
||||
return PaymentStatus.paid;
|
||||
case RecentPaymentStatus.PENDING:
|
||||
return PaymentStatus.pending;
|
||||
case RecentPaymentStatus.FAILED:
|
||||
return PaymentStatus.failed;
|
||||
default:
|
||||
return PaymentStatus.pending;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension on DateTime {
|
||||
// Simple toDate if needed, but Data Connect Timestamp has toDate() usually
|
||||
// or we need the extension from earlier
|
||||
}
|
||||
|
||||
extension TimestampExt on Timestamp {
|
||||
DateTime toDate() {
|
||||
return DateTime.fromMillisecondsSinceEpoch(seconds.toInt() * 1000 + nanoseconds ~/ 1000000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
import 'package:krow_data_connect/krow_data_connect.dart';
|
||||
import 'package:firebase_data_connect/firebase_data_connect.dart';
|
||||
import 'package:krow_data_connect/src/session/staff_session_store.dart';
|
||||
import 'package:krow_domain/krow_domain.dart';
|
||||
import '../../domain/repositories/payments_repository.dart';
|
||||
import '../datasources/payments_remote_datasource.dart';
|
||||
|
||||
extension TimestampExt on Timestamp {
|
||||
DateTime toDate() {
|
||||
return DateTime.fromMillisecondsSinceEpoch(seconds.toInt() * 1000 + nanoseconds ~/ 1000000);
|
||||
}
|
||||
}
|
||||
|
||||
/// Implementation of [PaymentsRepository].
|
||||
class PaymentsRepositoryImpl implements PaymentsRepository {
|
||||
PaymentsRepositoryImpl();
|
||||
|
||||
Future<List<StaffPayment>> getPayments() async {
|
||||
// Get current staff ID from session
|
||||
final session = StaffSessionStore.instance.session;
|
||||
|
||||
if (session?.staff?.id == null) return [];
|
||||
final String currentStaffId = session!.staff!.id;
|
||||
|
||||
|
||||
try {
|
||||
final response = await ExampleConnector.instance
|
||||
.listRecentPaymentsByStaffId(staffId: currentStaffId)
|
||||
.execute();
|
||||
|
||||
return response.data.recentPayments.map((payment) {
|
||||
return StaffPayment(
|
||||
id: payment.id,
|
||||
staffId: payment.staffId,
|
||||
assignmentId: payment.applicationId, // Application implies assignment
|
||||
amount: payment.invoice.amount,
|
||||
status: _mapStatus(payment.status),
|
||||
paidAt: payment.invoice.issueDate.toDate(),
|
||||
);
|
||||
}).toList();
|
||||
} catch (e) {
|
||||
// Fallback or empty list on error
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
PaymentStatus _mapStatus(EnumValue<RecentPaymentStatus>? status) {
|
||||
if (status == null || status is! Known) return PaymentStatus.pending;
|
||||
|
||||
switch ((status as Known).value) {
|
||||
case RecentPaymentStatus.PAID:
|
||||
return PaymentStatus.paid;
|
||||
case RecentPaymentStatus.PENDING:
|
||||
return PaymentStatus.pending;
|
||||
case RecentPaymentStatus.FAILED:
|
||||
return PaymentStatus.failed;
|
||||
default:
|
||||
return PaymentStatus.pending;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
class PaymentTransaction extends Equatable {
|
||||
final String id;
|
||||
final String title;
|
||||
final String location;
|
||||
final String address;
|
||||
final String workedTime;
|
||||
final double amount;
|
||||
final String status;
|
||||
final int hours;
|
||||
final double rate;
|
||||
final DateTime date;
|
||||
|
||||
const PaymentTransaction({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.location,
|
||||
required this.address,
|
||||
required this.workedTime,
|
||||
required this.amount,
|
||||
required this.status,
|
||||
required this.hours,
|
||||
required this.rate,
|
||||
required this.date,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
title,
|
||||
location,
|
||||
address,
|
||||
workedTime,
|
||||
amount,
|
||||
status,
|
||||
hours,
|
||||
rate,
|
||||
date,
|
||||
];
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:krow_domain/krow_domain.dart';
|
||||
import '../entities/payment_summary.dart';
|
||||
import '../entities/payment_transaction.dart';
|
||||
|
||||
/// Repository interface for Payments feature.
|
||||
///
|
||||
@@ -10,5 +10,5 @@ abstract class PaymentsRepository {
|
||||
Future<PaymentSummary> getPaymentSummary();
|
||||
|
||||
/// Fetches the payment history for a specific period.
|
||||
Future<List<PaymentTransaction>> getPaymentHistory(String period);
|
||||
Future<List<StaffPayment>> getPaymentHistory(String period);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import 'package:krow_core/core.dart';
|
||||
import 'package:krow_domain/krow_domain.dart';
|
||||
import '../arguments/get_payment_history_arguments.dart';
|
||||
import '../entities/payment_transaction.dart';
|
||||
import '../repositories/payments_repository.dart';
|
||||
|
||||
/// Use case to retrieve payment history filtered by a period.
|
||||
///
|
||||
/// This use case delegates the data retrieval to [PaymentsRepository].
|
||||
class GetPaymentHistoryUseCase extends UseCase<GetPaymentHistoryArguments, List<PaymentTransaction>> {
|
||||
class GetPaymentHistoryUseCase extends UseCase<GetPaymentHistoryArguments, List<StaffPayment>> {
|
||||
final PaymentsRepository repository;
|
||||
|
||||
/// Creates a [GetPaymentHistoryUseCase].
|
||||
GetPaymentHistoryUseCase(this.repository);
|
||||
|
||||
@override
|
||||
Future<List<PaymentTransaction>> call(GetPaymentHistoryArguments arguments) async {
|
||||
Future<List<StaffPayment>> call(GetPaymentHistoryArguments arguments) async {
|
||||
return await repository.getPaymentHistory(arguments.period);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import 'package:krow_data_connect/krow_data_connect.dart';
|
||||
import 'domain/repositories/payments_repository.dart';
|
||||
import 'domain/usecases/get_payment_summary_usecase.dart';
|
||||
import 'domain/usecases/get_payment_history_usecase.dart';
|
||||
import 'data/repositories_impl/payments_repository_impl.dart';
|
||||
import 'data/repositories/payments_repository_impl.dart';
|
||||
import 'presentation/blocs/payments/payments_bloc.dart';
|
||||
import 'presentation/pages/payments_page.dart';
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:krow_domain/krow_domain.dart';
|
||||
import '../../../domain/arguments/get_payment_history_arguments.dart';
|
||||
import '../../../domain/entities/payment_summary.dart';
|
||||
import '../../../domain/entities/payment_transaction.dart';
|
||||
import '../../../domain/usecases/get_payment_history_usecase.dart';
|
||||
import '../../../domain/usecases/get_payment_summary_usecase.dart';
|
||||
import 'payments_event.dart';
|
||||
@@ -27,7 +27,7 @@ class PaymentsBloc extends Bloc<PaymentsEvent, PaymentsState> {
|
||||
try {
|
||||
final PaymentSummary currentSummary = await getPaymentSummary();
|
||||
|
||||
final List<PaymentTransaction> history = await getPaymentHistory(
|
||||
final List<StaffPayment> history = await getPaymentHistory(
|
||||
const GetPaymentHistoryArguments('week'),
|
||||
);
|
||||
emit(PaymentsLoaded(
|
||||
@@ -47,7 +47,7 @@ class PaymentsBloc extends Bloc<PaymentsEvent, PaymentsState> {
|
||||
final PaymentsState currentState = state;
|
||||
if (currentState is PaymentsLoaded) {
|
||||
try {
|
||||
final List<PaymentTransaction> newHistory = await getPaymentHistory(
|
||||
final List<StaffPayment> newHistory = await getPaymentHistory(
|
||||
GetPaymentHistoryArguments(event.period),
|
||||
);
|
||||
emit(currentState.copyWith(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:krow_domain/krow_domain.dart';
|
||||
import '../../../domain/entities/payment_summary.dart';
|
||||
import '../../../domain/entities/payment_transaction.dart';
|
||||
|
||||
abstract class PaymentsState extends Equatable {
|
||||
const PaymentsState();
|
||||
@@ -15,7 +15,7 @@ class PaymentsLoading extends PaymentsState {}
|
||||
|
||||
class PaymentsLoaded extends PaymentsState {
|
||||
final PaymentSummary summary;
|
||||
final List<PaymentTransaction> history;
|
||||
final List<StaffPayment> history;
|
||||
final String activePeriod;
|
||||
|
||||
const PaymentsLoaded({
|
||||
@@ -26,7 +26,7 @@ class PaymentsLoaded extends PaymentsState {
|
||||
|
||||
PaymentsLoaded copyWith({
|
||||
PaymentSummary? summary,
|
||||
List<PaymentTransaction>? history,
|
||||
List<StaffPayment>? history,
|
||||
String? activePeriod,
|
||||
}) {
|
||||
return PaymentsLoaded(
|
||||
|
||||
@@ -3,7 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_modular/flutter_modular.dart';
|
||||
import 'package:lucide_icons/lucide_icons.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../../domain/entities/payment_transaction.dart';
|
||||
import 'package:krow_domain/krow_domain.dart';
|
||||
import '../blocs/payments/payments_bloc.dart';
|
||||
import '../blocs/payments/payments_event.dart';
|
||||
import '../blocs/payments/payments_state.dart';
|
||||
@@ -184,19 +184,21 @@ class _PaymentsPageState extends State<PaymentsPage> {
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Column(
|
||||
children: state.history.map((PaymentTransaction payment) {
|
||||
children: state.history.map((StaffPayment payment) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: PaymentHistoryItem(
|
||||
amount: payment.amount,
|
||||
title: payment.title,
|
||||
location: payment.location,
|
||||
address: payment.address,
|
||||
date: DateFormat('E, MMM d').format(payment.date),
|
||||
workedTime: payment.workedTime,
|
||||
hours: payment.hours,
|
||||
rate: payment.rate,
|
||||
status: payment.status,
|
||||
title: "Shift Payment",
|
||||
location: "Varies",
|
||||
address: "Payment ID: ${payment.id}",
|
||||
date: payment.paidAt != null
|
||||
? DateFormat('E, MMM d').format(payment.paidAt!)
|
||||
: 'Pending',
|
||||
workedTime: "Completed",
|
||||
hours: 0,
|
||||
rate: 0.0,
|
||||
status: payment.status.name.toUpperCase(),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
|
||||
Reference in New Issue
Block a user