add payments screen
This commit is contained in:
@@ -0,0 +1,168 @@
|
||||
/// Providers: Invoices
|
||||
///
|
||||
/// Riverpod providers for managing invoices state.
|
||||
library;
|
||||
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:worker/core/database/models/enums.dart';
|
||||
import 'package:worker/features/orders/data/datasources/invoices_local_datasource.dart';
|
||||
import 'package:worker/features/orders/data/models/invoice_model.dart';
|
||||
|
||||
part 'invoices_provider.g.dart';
|
||||
|
||||
/// Invoices Local Data Source Provider
|
||||
@riverpod
|
||||
InvoicesLocalDataSource invoicesLocalDataSource(Ref ref) {
|
||||
return InvoicesLocalDataSource();
|
||||
}
|
||||
|
||||
/// Invoices Provider
|
||||
///
|
||||
/// Provides list of all invoices from local data source.
|
||||
@riverpod
|
||||
class Invoices extends _$Invoices {
|
||||
@override
|
||||
Future<List<InvoiceModel>> build() async {
|
||||
return await ref.read(invoicesLocalDataSourceProvider).getAllInvoices();
|
||||
}
|
||||
|
||||
/// Refresh invoices
|
||||
Future<void> refresh() async {
|
||||
state = const AsyncValue.loading();
|
||||
state = await AsyncValue.guard(() async {
|
||||
return await ref.read(invoicesLocalDataSourceProvider).getAllInvoices();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Selected Invoice Status Filter Provider
|
||||
///
|
||||
/// Tracks the currently selected invoice status filter for tabs.
|
||||
/// null means "All" invoices.
|
||||
@riverpod
|
||||
class SelectedInvoiceStatusFilter extends _$SelectedInvoiceStatusFilter {
|
||||
@override
|
||||
String? build() {
|
||||
return null; // Default: show all invoices
|
||||
}
|
||||
|
||||
/// Select a status filter
|
||||
void selectStatus(String? status) {
|
||||
state = status;
|
||||
}
|
||||
|
||||
/// Clear selection (show all)
|
||||
void clearSelection() {
|
||||
state = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Filtered Invoices Provider
|
||||
///
|
||||
/// Filters invoices by selected status tab.
|
||||
@riverpod
|
||||
Future<List<InvoiceModel>> filteredInvoices(Ref ref) async {
|
||||
final invoicesAsync = ref.watch(invoicesProvider);
|
||||
final selectedStatus = ref.watch(selectedInvoiceStatusFilterProvider);
|
||||
|
||||
return invoicesAsync.when(
|
||||
data: (invoices) {
|
||||
var filtered = invoices;
|
||||
|
||||
// Filter by status tab
|
||||
if (selectedStatus != null) {
|
||||
if (selectedStatus == 'unpaid') {
|
||||
// Unpaid tab: issued status only
|
||||
filtered = filtered
|
||||
.where((invoice) => invoice.status == InvoiceStatus.issued && !invoice.isPaid)
|
||||
.toList();
|
||||
} else if (selectedStatus == 'overdue') {
|
||||
// Overdue tab: overdue status
|
||||
filtered = filtered
|
||||
.where((invoice) => invoice.status == InvoiceStatus.overdue || invoice.isOverdue)
|
||||
.toList();
|
||||
} else if (selectedStatus == 'paid') {
|
||||
// Paid tab: paid status
|
||||
filtered = filtered
|
||||
.where((invoice) => invoice.status == InvoiceStatus.paid || invoice.isPaid)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by issue date (newest first)
|
||||
filtered.sort((a, b) => b.issueDate.compareTo(a.issueDate));
|
||||
|
||||
return filtered;
|
||||
},
|
||||
loading: () => [],
|
||||
error: (error, stack) => [],
|
||||
);
|
||||
}
|
||||
|
||||
/// Invoices Count by Status Provider
|
||||
///
|
||||
/// Returns count of invoices for each status tab.
|
||||
@riverpod
|
||||
Future<Map<String, int>> invoicesCountByStatus(Ref ref) async {
|
||||
final invoicesAsync = ref.watch(invoicesProvider);
|
||||
|
||||
return invoicesAsync.when(
|
||||
data: (invoices) {
|
||||
final counts = <String, int>{};
|
||||
|
||||
// All tab
|
||||
counts['all'] = invoices.length;
|
||||
|
||||
// Unpaid tab (issued status)
|
||||
counts['unpaid'] = invoices
|
||||
.where((invoice) => invoice.status == InvoiceStatus.issued && !invoice.isPaid)
|
||||
.length;
|
||||
|
||||
// Overdue tab
|
||||
counts['overdue'] = invoices
|
||||
.where((invoice) => invoice.status == InvoiceStatus.overdue || invoice.isOverdue)
|
||||
.length;
|
||||
|
||||
// Paid tab
|
||||
counts['paid'] = invoices
|
||||
.where((invoice) => invoice.status == InvoiceStatus.paid || invoice.isPaid)
|
||||
.length;
|
||||
|
||||
return counts;
|
||||
},
|
||||
loading: () => {},
|
||||
error: (error, stack) => {},
|
||||
);
|
||||
}
|
||||
|
||||
/// Total Invoices Amount Provider
|
||||
///
|
||||
/// Returns total amount of all invoices.
|
||||
@riverpod
|
||||
Future<double> totalInvoicesAmount(Ref ref) async {
|
||||
final invoicesAsync = ref.watch(invoicesProvider);
|
||||
|
||||
return invoicesAsync.when(
|
||||
data: (invoices) {
|
||||
return invoices.fold<double>(0.0, (sum, invoice) => sum + invoice.totalAmount);
|
||||
},
|
||||
loading: () => 0.0,
|
||||
error: (error, stack) => 0.0,
|
||||
);
|
||||
}
|
||||
|
||||
/// Total Unpaid Amount Provider
|
||||
///
|
||||
/// Returns total amount remaining across all unpaid invoices.
|
||||
@riverpod
|
||||
Future<double> totalUnpaidAmount(Ref ref) async {
|
||||
final invoicesAsync = ref.watch(invoicesProvider);
|
||||
|
||||
return invoicesAsync.when(
|
||||
data: (invoices) {
|
||||
return invoices.fold<double>(0.0, (sum, invoice) => sum + invoice.amountRemaining);
|
||||
},
|
||||
loading: () => 0.0,
|
||||
error: (error, stack) => 0.0,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,387 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'invoices_provider.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
/// Invoices Local Data Source Provider
|
||||
|
||||
@ProviderFor(invoicesLocalDataSource)
|
||||
const invoicesLocalDataSourceProvider = InvoicesLocalDataSourceProvider._();
|
||||
|
||||
/// Invoices Local Data Source Provider
|
||||
|
||||
final class InvoicesLocalDataSourceProvider
|
||||
extends
|
||||
$FunctionalProvider<
|
||||
InvoicesLocalDataSource,
|
||||
InvoicesLocalDataSource,
|
||||
InvoicesLocalDataSource
|
||||
>
|
||||
with $Provider<InvoicesLocalDataSource> {
|
||||
/// Invoices Local Data Source Provider
|
||||
const InvoicesLocalDataSourceProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'invoicesLocalDataSourceProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$invoicesLocalDataSourceHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$ProviderElement<InvoicesLocalDataSource> $createElement(
|
||||
$ProviderPointer pointer,
|
||||
) => $ProviderElement(pointer);
|
||||
|
||||
@override
|
||||
InvoicesLocalDataSource create(Ref ref) {
|
||||
return invoicesLocalDataSource(ref);
|
||||
}
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(InvoicesLocalDataSource value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<InvoicesLocalDataSource>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$invoicesLocalDataSourceHash() =>
|
||||
r'1fd77b210353e5527515abb2e8d53a4771f9320b';
|
||||
|
||||
/// Invoices Provider
|
||||
///
|
||||
/// Provides list of all invoices from local data source.
|
||||
|
||||
@ProviderFor(Invoices)
|
||||
const invoicesProvider = InvoicesProvider._();
|
||||
|
||||
/// Invoices Provider
|
||||
///
|
||||
/// Provides list of all invoices from local data source.
|
||||
final class InvoicesProvider
|
||||
extends $AsyncNotifierProvider<Invoices, List<InvoiceModel>> {
|
||||
/// Invoices Provider
|
||||
///
|
||||
/// Provides list of all invoices from local data source.
|
||||
const InvoicesProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'invoicesProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$invoicesHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
Invoices create() => Invoices();
|
||||
}
|
||||
|
||||
String _$invoicesHash() => r'8a0d534b4fbb0367f9727f1baa3d48339cf44ab6';
|
||||
|
||||
/// Invoices Provider
|
||||
///
|
||||
/// Provides list of all invoices from local data source.
|
||||
|
||||
abstract class _$Invoices extends $AsyncNotifier<List<InvoiceModel>> {
|
||||
FutureOr<List<InvoiceModel>> build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final created = build();
|
||||
final ref =
|
||||
this.ref as $Ref<AsyncValue<List<InvoiceModel>>, List<InvoiceModel>>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<AsyncValue<List<InvoiceModel>>, List<InvoiceModel>>,
|
||||
AsyncValue<List<InvoiceModel>>,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleValue(ref, created);
|
||||
}
|
||||
}
|
||||
|
||||
/// Selected Invoice Status Filter Provider
|
||||
///
|
||||
/// Tracks the currently selected invoice status filter for tabs.
|
||||
/// null means "All" invoices.
|
||||
|
||||
@ProviderFor(SelectedInvoiceStatusFilter)
|
||||
const selectedInvoiceStatusFilterProvider =
|
||||
SelectedInvoiceStatusFilterProvider._();
|
||||
|
||||
/// Selected Invoice Status Filter Provider
|
||||
///
|
||||
/// Tracks the currently selected invoice status filter for tabs.
|
||||
/// null means "All" invoices.
|
||||
final class SelectedInvoiceStatusFilterProvider
|
||||
extends $NotifierProvider<SelectedInvoiceStatusFilter, String?> {
|
||||
/// Selected Invoice Status Filter Provider
|
||||
///
|
||||
/// Tracks the currently selected invoice status filter for tabs.
|
||||
/// null means "All" invoices.
|
||||
const SelectedInvoiceStatusFilterProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'selectedInvoiceStatusFilterProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$selectedInvoiceStatusFilterHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
SelectedInvoiceStatusFilter create() => SelectedInvoiceStatusFilter();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(String? value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<String?>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$selectedInvoiceStatusFilterHash() =>
|
||||
r'677627b34d7754c224b53a03ef61c8da13dee26a';
|
||||
|
||||
/// Selected Invoice Status Filter Provider
|
||||
///
|
||||
/// Tracks the currently selected invoice status filter for tabs.
|
||||
/// null means "All" invoices.
|
||||
|
||||
abstract class _$SelectedInvoiceStatusFilter extends $Notifier<String?> {
|
||||
String? build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final created = build();
|
||||
final ref = this.ref as $Ref<String?, String?>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<String?, String?>,
|
||||
String?,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleValue(ref, created);
|
||||
}
|
||||
}
|
||||
|
||||
/// Filtered Invoices Provider
|
||||
///
|
||||
/// Filters invoices by selected status tab.
|
||||
|
||||
@ProviderFor(filteredInvoices)
|
||||
const filteredInvoicesProvider = FilteredInvoicesProvider._();
|
||||
|
||||
/// Filtered Invoices Provider
|
||||
///
|
||||
/// Filters invoices by selected status tab.
|
||||
|
||||
final class FilteredInvoicesProvider
|
||||
extends
|
||||
$FunctionalProvider<
|
||||
AsyncValue<List<InvoiceModel>>,
|
||||
List<InvoiceModel>,
|
||||
FutureOr<List<InvoiceModel>>
|
||||
>
|
||||
with
|
||||
$FutureModifier<List<InvoiceModel>>,
|
||||
$FutureProvider<List<InvoiceModel>> {
|
||||
/// Filtered Invoices Provider
|
||||
///
|
||||
/// Filters invoices by selected status tab.
|
||||
const FilteredInvoicesProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'filteredInvoicesProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$filteredInvoicesHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$FutureProviderElement<List<InvoiceModel>> $createElement(
|
||||
$ProviderPointer pointer,
|
||||
) => $FutureProviderElement(pointer);
|
||||
|
||||
@override
|
||||
FutureOr<List<InvoiceModel>> create(Ref ref) {
|
||||
return filteredInvoices(ref);
|
||||
}
|
||||
}
|
||||
|
||||
String _$filteredInvoicesHash() => r'778c8762e13c620d48e21d240c397f13c03de00e';
|
||||
|
||||
/// Invoices Count by Status Provider
|
||||
///
|
||||
/// Returns count of invoices for each status tab.
|
||||
|
||||
@ProviderFor(invoicesCountByStatus)
|
||||
const invoicesCountByStatusProvider = InvoicesCountByStatusProvider._();
|
||||
|
||||
/// Invoices Count by Status Provider
|
||||
///
|
||||
/// Returns count of invoices for each status tab.
|
||||
|
||||
final class InvoicesCountByStatusProvider
|
||||
extends
|
||||
$FunctionalProvider<
|
||||
AsyncValue<Map<String, int>>,
|
||||
Map<String, int>,
|
||||
FutureOr<Map<String, int>>
|
||||
>
|
||||
with $FutureModifier<Map<String, int>>, $FutureProvider<Map<String, int>> {
|
||||
/// Invoices Count by Status Provider
|
||||
///
|
||||
/// Returns count of invoices for each status tab.
|
||||
const InvoicesCountByStatusProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'invoicesCountByStatusProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$invoicesCountByStatusHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$FutureProviderElement<Map<String, int>> $createElement(
|
||||
$ProviderPointer pointer,
|
||||
) => $FutureProviderElement(pointer);
|
||||
|
||||
@override
|
||||
FutureOr<Map<String, int>> create(Ref ref) {
|
||||
return invoicesCountByStatus(ref);
|
||||
}
|
||||
}
|
||||
|
||||
String _$invoicesCountByStatusHash() =>
|
||||
r'c21acf5db26120dc6b4bb27e9c1f84eebe315b59';
|
||||
|
||||
/// Total Invoices Amount Provider
|
||||
///
|
||||
/// Returns total amount of all invoices.
|
||||
|
||||
@ProviderFor(totalInvoicesAmount)
|
||||
const totalInvoicesAmountProvider = TotalInvoicesAmountProvider._();
|
||||
|
||||
/// Total Invoices Amount Provider
|
||||
///
|
||||
/// Returns total amount of all invoices.
|
||||
|
||||
final class TotalInvoicesAmountProvider
|
||||
extends $FunctionalProvider<AsyncValue<double>, double, FutureOr<double>>
|
||||
with $FutureModifier<double>, $FutureProvider<double> {
|
||||
/// Total Invoices Amount Provider
|
||||
///
|
||||
/// Returns total amount of all invoices.
|
||||
const TotalInvoicesAmountProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'totalInvoicesAmountProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$totalInvoicesAmountHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$FutureProviderElement<double> $createElement($ProviderPointer pointer) =>
|
||||
$FutureProviderElement(pointer);
|
||||
|
||||
@override
|
||||
FutureOr<double> create(Ref ref) {
|
||||
return totalInvoicesAmount(ref);
|
||||
}
|
||||
}
|
||||
|
||||
String _$totalInvoicesAmountHash() =>
|
||||
r'7800e2be935dfe91d382957539b151bbf4f936fe';
|
||||
|
||||
/// Total Unpaid Amount Provider
|
||||
///
|
||||
/// Returns total amount remaining across all unpaid invoices.
|
||||
|
||||
@ProviderFor(totalUnpaidAmount)
|
||||
const totalUnpaidAmountProvider = TotalUnpaidAmountProvider._();
|
||||
|
||||
/// Total Unpaid Amount Provider
|
||||
///
|
||||
/// Returns total amount remaining across all unpaid invoices.
|
||||
|
||||
final class TotalUnpaidAmountProvider
|
||||
extends $FunctionalProvider<AsyncValue<double>, double, FutureOr<double>>
|
||||
with $FutureModifier<double>, $FutureProvider<double> {
|
||||
/// Total Unpaid Amount Provider
|
||||
///
|
||||
/// Returns total amount remaining across all unpaid invoices.
|
||||
const TotalUnpaidAmountProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'totalUnpaidAmountProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$totalUnpaidAmountHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$FutureProviderElement<double> $createElement($ProviderPointer pointer) =>
|
||||
$FutureProviderElement(pointer);
|
||||
|
||||
@override
|
||||
FutureOr<double> create(Ref ref) {
|
||||
return totalUnpaidAmount(ref);
|
||||
}
|
||||
}
|
||||
|
||||
String _$totalUnpaidAmountHash() => r'9a81800149d8809e1c3be065bc3c5357792c4aee';
|
||||
@@ -59,7 +59,7 @@ final class OrdersLocalDataSourceProvider
|
||||
}
|
||||
|
||||
String _$ordersLocalDataSourceHash() =>
|
||||
r'5fb1c0b212ea6874bd42ae1f5b3f9f1db7197d7b';
|
||||
r'753fcc2a4000c4c9843fba022d1bf398daba6c7a';
|
||||
|
||||
/// Orders Provider
|
||||
///
|
||||
@@ -308,7 +308,7 @@ final class FilteredOrdersProvider
|
||||
}
|
||||
}
|
||||
|
||||
String _$filteredOrdersHash() => r'3bef3cc2b8c98297510134d10ceb5ef1618cc3a8';
|
||||
String _$filteredOrdersHash() => r'4cc009352d3b09159c0fe107645634c3a4a81a7c';
|
||||
|
||||
/// Orders Count by Status Provider
|
||||
///
|
||||
@@ -361,7 +361,7 @@ final class OrdersCountByStatusProvider
|
||||
}
|
||||
|
||||
String _$ordersCountByStatusHash() =>
|
||||
r'3a656b9c70510f34702a636b9bda5a7b7660e6ff';
|
||||
r'85fe4fb85410855bb434b19fdc05c933c6e76235';
|
||||
|
||||
/// Total Orders Count Provider
|
||||
|
||||
@@ -399,4 +399,4 @@ final class TotalOrdersCountProvider
|
||||
}
|
||||
}
|
||||
|
||||
String _$totalOrdersCountHash() => r'71f2e2f890b4e3d5a5beaa7bf06a0d78faf039cb';
|
||||
String _$totalOrdersCountHash() => r'ec1ab3a8d432033aa1f02d28e841e78eba06d63e';
|
||||
|
||||
Reference in New Issue
Block a user