third commit
This commit is contained in:
@@ -51,6 +51,7 @@ class Product extends Equatable {
|
||||
this.imageUrl,
|
||||
this.unit = UnitOfMeasure.piece,
|
||||
this.gstRate = AppConstants.defaultGstRate,
|
||||
this.hsnCode,
|
||||
this.brand,
|
||||
this.isActive = true,
|
||||
});
|
||||
@@ -72,6 +73,11 @@ class Product extends Equatable {
|
||||
final String? imageUrl;
|
||||
final UnitOfMeasure unit;
|
||||
final double gstRate;
|
||||
|
||||
/// HSN/SAC code. Printed on the tax invoice — legally required on a GST
|
||||
/// invoice above the turnover threshold. Blank when the catalogue omits it.
|
||||
final String? hsnCode;
|
||||
|
||||
final String? brand;
|
||||
final bool isActive;
|
||||
|
||||
@@ -124,6 +130,7 @@ class Product extends Equatable {
|
||||
imageUrl: imageUrl,
|
||||
unit: unit,
|
||||
gstRate: gstRate,
|
||||
hsnCode: hsnCode,
|
||||
brand: brand,
|
||||
isActive: isActive ?? this.isActive,
|
||||
);
|
||||
|
||||
@@ -124,6 +124,76 @@ class ShiftReport extends Equatable {
|
||||
);
|
||||
}
|
||||
|
||||
/// Rebuilds a report from an archived day row.
|
||||
factory ShiftReport.fromArchive({
|
||||
required Map<String, Object?> row,
|
||||
required Map<PaymentMethod, double> payments,
|
||||
required DateTime businessDate,
|
||||
required String terminalId,
|
||||
required String cashierName,
|
||||
}) {
|
||||
DateTime? at(Object? v) =>
|
||||
v == null ? null : DateTime.fromMillisecondsSinceEpoch(v as int);
|
||||
|
||||
return ShiftReport(
|
||||
businessDate: businessDate,
|
||||
terminalId: terminalId,
|
||||
cashierName: cashierName,
|
||||
billCount: (row['bill_count'] as int?) ?? 0,
|
||||
itemCount: (row['item_count'] as num?)?.toDouble() ?? 0,
|
||||
grossSales: (row['gross_sales'] as num?)?.toDouble() ?? 0,
|
||||
taxCollected: (row['tax_collected'] as num?)?.toDouble() ?? 0,
|
||||
discountGiven: (row['discount_given'] as num?)?.toDouble() ?? 0,
|
||||
roundOff: (row['round_off'] as num?)?.toDouble() ?? 0,
|
||||
paymentBreakdown: payments,
|
||||
loyaltyPointsIssued: (row['points_issued'] as int?) ?? 0,
|
||||
loyaltyPointsRedeemed: (row['points_redeemed'] as int?) ?? 0,
|
||||
firstBillAt: at(row['first_bill_at']),
|
||||
lastBillAt: at(row['last_bill_at']),
|
||||
);
|
||||
}
|
||||
|
||||
/// Adds two reports for the same day.
|
||||
///
|
||||
/// Needed because synced bills are deleted from the terminal: the day's true
|
||||
/// figures are the archived totals plus whatever is still held locally.
|
||||
ShiftReport operator +(ShiftReport other) {
|
||||
final payments = <PaymentMethod, double>{...paymentBreakdown};
|
||||
other.paymentBreakdown.forEach((k, v) {
|
||||
payments[k] = ((payments[k] ?? 0) + v).asMoney;
|
||||
});
|
||||
|
||||
DateTime? earliest(DateTime? a, DateTime? b) {
|
||||
if (a == null) return b;
|
||||
if (b == null) return a;
|
||||
return a.isBefore(b) ? a : b;
|
||||
}
|
||||
|
||||
DateTime? latest(DateTime? a, DateTime? b) {
|
||||
if (a == null) return b;
|
||||
if (b == null) return a;
|
||||
return a.isAfter(b) ? a : b;
|
||||
}
|
||||
|
||||
return ShiftReport(
|
||||
businessDate: businessDate,
|
||||
terminalId: terminalId,
|
||||
cashierName: cashierName,
|
||||
billCount: billCount + other.billCount,
|
||||
itemCount: itemCount + other.itemCount,
|
||||
grossSales: (grossSales + other.grossSales).asMoney,
|
||||
taxCollected: (taxCollected + other.taxCollected).asMoney,
|
||||
discountGiven: (discountGiven + other.discountGiven).asMoney,
|
||||
roundOff: (roundOff + other.roundOff).asMoney,
|
||||
paymentBreakdown: payments,
|
||||
loyaltyPointsIssued: loyaltyPointsIssued + other.loyaltyPointsIssued,
|
||||
loyaltyPointsRedeemed:
|
||||
loyaltyPointsRedeemed + other.loyaltyPointsRedeemed,
|
||||
firstBillAt: earliest(firstBillAt, other.firstBillAt),
|
||||
lastBillAt: latest(lastBillAt, other.lastBillAt),
|
||||
);
|
||||
}
|
||||
|
||||
/// The JSON body that would be sent to the back office.
|
||||
Map<String, Object?> toPayload() => {
|
||||
'business_date': businessDate.toIso8601String().substring(0, 10),
|
||||
|
||||
Reference in New Issue
Block a user