second commit

This commit is contained in:
2026-07-29 11:41:53 +05:30
parent fcccf22bac
commit d72522e737
211 changed files with 19260 additions and 0 deletions

View File

@@ -0,0 +1,133 @@
import 'package:equatable/equatable.dart';
import '../../core/utils/extensions.dart';
import 'cart.dart';
import 'customer.dart';
enum PaymentMethod {
cash('Cash', '💵', true),
card('Card', '💳', false),
upi('UPI', '📱', false),
wallet('Wallet', '👛', false),
giftCard('Gift Card', '🎁', false),
loyalty('Loyalty Points', '', false);
const PaymentMethod(this.label, this.emoji, this.needsChange);
final String label;
final String emoji;
/// Only cash tenders can be over-paid and produce change.
final bool needsChange;
/// Non-cash tenders normally capture a reference number.
bool get needsReference =>
this == PaymentMethod.card ||
this == PaymentMethod.upi ||
this == PaymentMethod.giftCard;
}
/// A single tender against a bill. A split payment holds several of these.
class PaymentSplit extends Equatable {
const PaymentSplit({
required this.method,
required this.amount,
this.tendered,
this.reference,
});
final PaymentMethod method;
/// Amount settled by this tender.
final double amount;
/// Cash handed over — may exceed [amount].
final double? tendered;
/// Card approval code, UPI txn id, gift card number.
final String? reference;
double get change {
if (!method.needsChange || tendered == null) return 0;
final diff = tendered! - amount;
return diff > 0 ? diff.asMoney : 0;
}
@override
List<Object?> get props => [method, amount, tendered, reference];
}
enum TransactionStatus { completed, parked, voided, refunded }
/// An immutable record of a finished sale.
class SaleTransaction extends Equatable {
const SaleTransaction({
required this.id,
required this.invoiceNumber,
required this.cart,
required this.payments,
required this.createdAt,
required this.cashierName,
this.status = TransactionStatus.completed,
this.terminalId = 'TERM-01',
});
final String id;
final String invoiceNumber;
final Cart cart;
final List<PaymentSplit> payments;
final DateTime createdAt;
final String cashierName;
final TransactionStatus status;
final String terminalId;
Customer? get customer => cart.customer;
double get total => cart.grandTotal;
double get amountPaid =>
payments.fold(0.0, (sum, p) => sum + p.amount).asMoney;
double get amountTendered => payments
.fold(0.0, (sum, p) => sum + (p.tendered ?? p.amount))
.asMoney;
double get changeDue =>
payments.fold(0.0, (sum, p) => sum + p.change).asMoney;
double get balanceDue => (total - amountPaid).clamp(0, double.infinity);
bool get isFullySettled => balanceDue <= 0.001;
bool get isSplit => payments.length > 1;
int get pointsEarned => cart.pointsEarned;
int get pointsRedeemed => cart.pointsRedeemed;
String get paymentSummary =>
payments.map((p) => p.method.label).toSet().join(' + ');
@override
List<Object?> get props => [id, invoiceNumber, createdAt, status];
}
/// A bill set aside so the cashier can serve the next shopper.
class ParkedBill extends Equatable {
const ParkedBill({
required this.id,
required this.cart,
required this.parkedAt,
this.label,
});
final String id;
final Cart cart;
final DateTime parkedAt;
final String? label;
String get displayLabel =>
label ?? cart.customer?.name ?? 'Walk-in #${id.substring(0, 4)}';
@override
List<Object?> get props => [id, parkedAt];
}