add auth, format
This commit is contained in:
@@ -31,9 +31,7 @@ class PointsHistoryLocalDataSource {
|
||||
/// Get all points entries
|
||||
Future<List<LoyaltyPointEntryModel>> getAllEntries() async {
|
||||
final box = await entriesBox;
|
||||
final entries = box.values
|
||||
.whereType<LoyaltyPointEntryModel>()
|
||||
.toList();
|
||||
final entries = box.values.whereType<LoyaltyPointEntryModel>().toList();
|
||||
entries.sort((a, b) => b.timestamp.compareTo(a.timestamp)); // Newest first
|
||||
return entries;
|
||||
}
|
||||
@@ -42,9 +40,9 @@ class PointsHistoryLocalDataSource {
|
||||
Future<LoyaltyPointEntryModel?> getEntryById(String entryId) async {
|
||||
final box = await entriesBox;
|
||||
try {
|
||||
return box.values
|
||||
.whereType<LoyaltyPointEntryModel>()
|
||||
.firstWhere((entry) => entry.entryId == entryId);
|
||||
return box.values.whereType<LoyaltyPointEntryModel>().firstWhere(
|
||||
(entry) => entry.entryId == entryId,
|
||||
);
|
||||
} catch (e) {
|
||||
throw Exception('Entry not found');
|
||||
}
|
||||
|
||||
@@ -6,41 +6,81 @@ part 'gift_catalog_model.g.dart';
|
||||
|
||||
@HiveType(typeId: HiveTypeIds.giftCatalogModel)
|
||||
class GiftCatalogModel extends HiveObject {
|
||||
GiftCatalogModel({required this.catalogId, required this.name, required this.description, this.imageUrl, required this.category, required this.pointsCost, required this.cashValue, required this.quantityAvailable, required this.quantityRedeemed, this.termsConditions, required this.isActive, this.validFrom, this.validUntil, required this.createdAt, this.updatedAt});
|
||||
|
||||
@HiveField(0) final String catalogId;
|
||||
@HiveField(1) final String name;
|
||||
@HiveField(2) final String description;
|
||||
@HiveField(3) final String? imageUrl;
|
||||
@HiveField(4) final GiftCategory category;
|
||||
@HiveField(5) final int pointsCost;
|
||||
@HiveField(6) final double cashValue;
|
||||
@HiveField(7) final int quantityAvailable;
|
||||
@HiveField(8) final int quantityRedeemed;
|
||||
@HiveField(9) final String? termsConditions;
|
||||
@HiveField(10) final bool isActive;
|
||||
@HiveField(11) final DateTime? validFrom;
|
||||
@HiveField(12) final DateTime? validUntil;
|
||||
@HiveField(13) final DateTime createdAt;
|
||||
@HiveField(14) final DateTime? updatedAt;
|
||||
GiftCatalogModel({
|
||||
required this.catalogId,
|
||||
required this.name,
|
||||
required this.description,
|
||||
this.imageUrl,
|
||||
required this.category,
|
||||
required this.pointsCost,
|
||||
required this.cashValue,
|
||||
required this.quantityAvailable,
|
||||
required this.quantityRedeemed,
|
||||
this.termsConditions,
|
||||
required this.isActive,
|
||||
this.validFrom,
|
||||
this.validUntil,
|
||||
required this.createdAt,
|
||||
this.updatedAt,
|
||||
});
|
||||
|
||||
factory GiftCatalogModel.fromJson(Map<String, dynamic> json) => GiftCatalogModel(
|
||||
catalogId: json['catalog_id'] as String,
|
||||
name: json['name'] as String,
|
||||
description: json['description'] as String,
|
||||
imageUrl: json['image_url'] as String?,
|
||||
category: GiftCategory.values.firstWhere((e) => e.name == json['category']),
|
||||
pointsCost: json['points_cost'] as int,
|
||||
cashValue: (json['cash_value'] as num).toDouble(),
|
||||
quantityAvailable: json['quantity_available'] as int,
|
||||
quantityRedeemed: json['quantity_redeemed'] as int? ?? 0,
|
||||
termsConditions: json['terms_conditions'] as String?,
|
||||
isActive: json['is_active'] as bool? ?? true,
|
||||
validFrom: json['valid_from'] != null ? DateTime.parse(json['valid_from']?.toString() ?? '') : null,
|
||||
validUntil: json['valid_until'] != null ? DateTime.parse(json['valid_until']?.toString() ?? '') : null,
|
||||
createdAt: DateTime.parse(json['created_at']?.toString() ?? ''),
|
||||
updatedAt: json['updated_at'] != null ? DateTime.parse(json['updated_at']?.toString() ?? '') : null,
|
||||
);
|
||||
@HiveField(0)
|
||||
final String catalogId;
|
||||
@HiveField(1)
|
||||
final String name;
|
||||
@HiveField(2)
|
||||
final String description;
|
||||
@HiveField(3)
|
||||
final String? imageUrl;
|
||||
@HiveField(4)
|
||||
final GiftCategory category;
|
||||
@HiveField(5)
|
||||
final int pointsCost;
|
||||
@HiveField(6)
|
||||
final double cashValue;
|
||||
@HiveField(7)
|
||||
final int quantityAvailable;
|
||||
@HiveField(8)
|
||||
final int quantityRedeemed;
|
||||
@HiveField(9)
|
||||
final String? termsConditions;
|
||||
@HiveField(10)
|
||||
final bool isActive;
|
||||
@HiveField(11)
|
||||
final DateTime? validFrom;
|
||||
@HiveField(12)
|
||||
final DateTime? validUntil;
|
||||
@HiveField(13)
|
||||
final DateTime createdAt;
|
||||
@HiveField(14)
|
||||
final DateTime? updatedAt;
|
||||
|
||||
factory GiftCatalogModel.fromJson(Map<String, dynamic> json) =>
|
||||
GiftCatalogModel(
|
||||
catalogId: json['catalog_id'] as String,
|
||||
name: json['name'] as String,
|
||||
description: json['description'] as String,
|
||||
imageUrl: json['image_url'] as String?,
|
||||
category: GiftCategory.values.firstWhere(
|
||||
(e) => e.name == json['category'],
|
||||
),
|
||||
pointsCost: json['points_cost'] as int,
|
||||
cashValue: (json['cash_value'] as num).toDouble(),
|
||||
quantityAvailable: json['quantity_available'] as int,
|
||||
quantityRedeemed: json['quantity_redeemed'] as int? ?? 0,
|
||||
termsConditions: json['terms_conditions'] as String?,
|
||||
isActive: json['is_active'] as bool? ?? true,
|
||||
validFrom: json['valid_from'] != null
|
||||
? DateTime.parse(json['valid_from']?.toString() ?? '')
|
||||
: null,
|
||||
validUntil: json['valid_until'] != null
|
||||
? DateTime.parse(json['valid_until']?.toString() ?? '')
|
||||
: null,
|
||||
createdAt: DateTime.parse(json['created_at']?.toString() ?? ''),
|
||||
updatedAt: json['updated_at'] != null
|
||||
? DateTime.parse(json['updated_at']?.toString() ?? '')
|
||||
: null,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'catalog_id': catalogId,
|
||||
|
||||
@@ -7,24 +7,55 @@ part 'loyalty_point_entry_model.g.dart';
|
||||
|
||||
@HiveType(typeId: HiveTypeIds.loyaltyPointEntryModel)
|
||||
class LoyaltyPointEntryModel extends HiveObject {
|
||||
LoyaltyPointEntryModel({required this.entryId, required this.userId, required this.points, required this.entryType, required this.source, required this.description, this.referenceId, this.referenceType, this.complaint, required this.complaintStatus, required this.balanceAfter, this.expiryDate, required this.timestamp, this.erpnextEntryId});
|
||||
|
||||
@HiveField(0) final String entryId;
|
||||
@HiveField(1) final String userId;
|
||||
@HiveField(2) final int points;
|
||||
@HiveField(3) final EntryType entryType;
|
||||
@HiveField(4) final EntrySource source;
|
||||
@HiveField(5) final String description;
|
||||
@HiveField(6) final String? referenceId;
|
||||
@HiveField(7) final String? referenceType;
|
||||
@HiveField(8) final String? complaint;
|
||||
@HiveField(9) final ComplaintStatus complaintStatus;
|
||||
@HiveField(10) final int balanceAfter;
|
||||
@HiveField(11) final DateTime? expiryDate;
|
||||
@HiveField(12) final DateTime timestamp;
|
||||
@HiveField(13) final String? erpnextEntryId;
|
||||
LoyaltyPointEntryModel({
|
||||
required this.entryId,
|
||||
required this.userId,
|
||||
required this.points,
|
||||
required this.entryType,
|
||||
required this.source,
|
||||
required this.description,
|
||||
this.referenceId,
|
||||
this.referenceType,
|
||||
this.complaint,
|
||||
required this.complaintStatus,
|
||||
required this.balanceAfter,
|
||||
this.expiryDate,
|
||||
required this.timestamp,
|
||||
this.erpnextEntryId,
|
||||
});
|
||||
|
||||
factory LoyaltyPointEntryModel.fromJson(Map<String, dynamic> json) => LoyaltyPointEntryModel(
|
||||
@HiveField(0)
|
||||
final String entryId;
|
||||
@HiveField(1)
|
||||
final String userId;
|
||||
@HiveField(2)
|
||||
final int points;
|
||||
@HiveField(3)
|
||||
final EntryType entryType;
|
||||
@HiveField(4)
|
||||
final EntrySource source;
|
||||
@HiveField(5)
|
||||
final String description;
|
||||
@HiveField(6)
|
||||
final String? referenceId;
|
||||
@HiveField(7)
|
||||
final String? referenceType;
|
||||
@HiveField(8)
|
||||
final String? complaint;
|
||||
@HiveField(9)
|
||||
final ComplaintStatus complaintStatus;
|
||||
@HiveField(10)
|
||||
final int balanceAfter;
|
||||
@HiveField(11)
|
||||
final DateTime? expiryDate;
|
||||
@HiveField(12)
|
||||
final DateTime timestamp;
|
||||
@HiveField(13)
|
||||
final String? erpnextEntryId;
|
||||
|
||||
factory LoyaltyPointEntryModel.fromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => LoyaltyPointEntryModel(
|
||||
entryId: json['entry_id'] as String,
|
||||
userId: json['user_id'] as String,
|
||||
points: json['points'] as int,
|
||||
@@ -34,9 +65,13 @@ class LoyaltyPointEntryModel extends HiveObject {
|
||||
referenceId: json['reference_id'] as String?,
|
||||
referenceType: json['reference_type'] as String?,
|
||||
complaint: json['complaint'] != null ? jsonEncode(json['complaint']) : null,
|
||||
complaintStatus: ComplaintStatus.values.firstWhere((e) => e.name == (json['complaint_status'] ?? 'none')),
|
||||
complaintStatus: ComplaintStatus.values.firstWhere(
|
||||
(e) => e.name == (json['complaint_status'] ?? 'none'),
|
||||
),
|
||||
balanceAfter: json['balance_after'] as int,
|
||||
expiryDate: json['expiry_date'] != null ? DateTime.parse(json['expiry_date']?.toString() ?? '') : null,
|
||||
expiryDate: json['expiry_date'] != null
|
||||
? DateTime.parse(json['expiry_date']?.toString() ?? '')
|
||||
: null,
|
||||
timestamp: DateTime.parse(json['timestamp']?.toString() ?? ''),
|
||||
erpnextEntryId: json['erpnext_entry_id'] as String?,
|
||||
);
|
||||
@@ -67,6 +102,7 @@ class LoyaltyPointEntryModel extends HiveObject {
|
||||
}
|
||||
}
|
||||
|
||||
bool get isExpired => expiryDate != null && DateTime.now().isAfter(expiryDate!);
|
||||
bool get isExpired =>
|
||||
expiryDate != null && DateTime.now().isAfter(expiryDate!);
|
||||
bool get hasComplaint => complaintStatus != ComplaintStatus.none;
|
||||
}
|
||||
|
||||
@@ -7,39 +7,75 @@ part 'points_record_model.g.dart';
|
||||
|
||||
@HiveType(typeId: HiveTypeIds.pointsRecordModel)
|
||||
class PointsRecordModel extends HiveObject {
|
||||
PointsRecordModel({required this.recordId, required this.userId, required this.invoiceNumber, required this.storeName, required this.transactionDate, required this.invoiceAmount, this.notes, this.attachments, required this.status, this.rejectReason, this.pointsEarned, required this.submittedAt, this.processedAt, this.processedBy});
|
||||
|
||||
@HiveField(0) final String recordId;
|
||||
@HiveField(1) final String userId;
|
||||
@HiveField(2) final String invoiceNumber;
|
||||
@HiveField(3) final String storeName;
|
||||
@HiveField(4) final DateTime transactionDate;
|
||||
@HiveField(5) final double invoiceAmount;
|
||||
@HiveField(6) final String? notes;
|
||||
@HiveField(7) final String? attachments;
|
||||
@HiveField(8) final PointsStatus status;
|
||||
@HiveField(9) final String? rejectReason;
|
||||
@HiveField(10) final int? pointsEarned;
|
||||
@HiveField(11) final DateTime submittedAt;
|
||||
@HiveField(12) final DateTime? processedAt;
|
||||
@HiveField(13) final String? processedBy;
|
||||
PointsRecordModel({
|
||||
required this.recordId,
|
||||
required this.userId,
|
||||
required this.invoiceNumber,
|
||||
required this.storeName,
|
||||
required this.transactionDate,
|
||||
required this.invoiceAmount,
|
||||
this.notes,
|
||||
this.attachments,
|
||||
required this.status,
|
||||
this.rejectReason,
|
||||
this.pointsEarned,
|
||||
required this.submittedAt,
|
||||
this.processedAt,
|
||||
this.processedBy,
|
||||
});
|
||||
|
||||
factory PointsRecordModel.fromJson(Map<String, dynamic> json) => PointsRecordModel(
|
||||
recordId: json['record_id'] as String,
|
||||
userId: json['user_id'] as String,
|
||||
invoiceNumber: json['invoice_number'] as String,
|
||||
storeName: json['store_name'] as String,
|
||||
transactionDate: DateTime.parse(json['transaction_date']?.toString() ?? ''),
|
||||
invoiceAmount: (json['invoice_amount'] as num).toDouble(),
|
||||
notes: json['notes'] as String?,
|
||||
attachments: json['attachments'] != null ? jsonEncode(json['attachments']) : null,
|
||||
status: PointsStatus.values.firstWhere((e) => e.name == json['status']),
|
||||
rejectReason: json['reject_reason'] as String?,
|
||||
pointsEarned: json['points_earned'] as int?,
|
||||
submittedAt: DateTime.parse(json['submitted_at']?.toString() ?? ''),
|
||||
processedAt: json['processed_at'] != null ? DateTime.parse(json['processed_at']?.toString() ?? '') : null,
|
||||
processedBy: json['processed_by'] as String?,
|
||||
);
|
||||
@HiveField(0)
|
||||
final String recordId;
|
||||
@HiveField(1)
|
||||
final String userId;
|
||||
@HiveField(2)
|
||||
final String invoiceNumber;
|
||||
@HiveField(3)
|
||||
final String storeName;
|
||||
@HiveField(4)
|
||||
final DateTime transactionDate;
|
||||
@HiveField(5)
|
||||
final double invoiceAmount;
|
||||
@HiveField(6)
|
||||
final String? notes;
|
||||
@HiveField(7)
|
||||
final String? attachments;
|
||||
@HiveField(8)
|
||||
final PointsStatus status;
|
||||
@HiveField(9)
|
||||
final String? rejectReason;
|
||||
@HiveField(10)
|
||||
final int? pointsEarned;
|
||||
@HiveField(11)
|
||||
final DateTime submittedAt;
|
||||
@HiveField(12)
|
||||
final DateTime? processedAt;
|
||||
@HiveField(13)
|
||||
final String? processedBy;
|
||||
|
||||
factory PointsRecordModel.fromJson(Map<String, dynamic> json) =>
|
||||
PointsRecordModel(
|
||||
recordId: json['record_id'] as String,
|
||||
userId: json['user_id'] as String,
|
||||
invoiceNumber: json['invoice_number'] as String,
|
||||
storeName: json['store_name'] as String,
|
||||
transactionDate: DateTime.parse(
|
||||
json['transaction_date']?.toString() ?? '',
|
||||
),
|
||||
invoiceAmount: (json['invoice_amount'] as num).toDouble(),
|
||||
notes: json['notes'] as String?,
|
||||
attachments: json['attachments'] != null
|
||||
? jsonEncode(json['attachments'])
|
||||
: null,
|
||||
status: PointsStatus.values.firstWhere((e) => e.name == json['status']),
|
||||
rejectReason: json['reject_reason'] as String?,
|
||||
pointsEarned: json['points_earned'] as int?,
|
||||
submittedAt: DateTime.parse(json['submitted_at']?.toString() ?? ''),
|
||||
processedAt: json['processed_at'] != null
|
||||
? DateTime.parse(json['processed_at']?.toString() ?? '')
|
||||
: null,
|
||||
processedBy: json['processed_by'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'record_id': recordId,
|
||||
|
||||
@@ -6,43 +6,83 @@ part 'redeemed_gift_model.g.dart';
|
||||
|
||||
@HiveType(typeId: HiveTypeIds.redeemedGiftModel)
|
||||
class RedeemedGiftModel extends HiveObject {
|
||||
RedeemedGiftModel({required this.giftId, required this.userId, required this.catalogId, required this.name, required this.description, this.voucherCode, this.qrCodeImage, required this.giftType, required this.pointsCost, required this.cashValue, this.expiryDate, required this.status, required this.redeemedAt, this.usedAt, this.usedLocation, this.usedReference});
|
||||
|
||||
@HiveField(0) final String giftId;
|
||||
@HiveField(1) final String userId;
|
||||
@HiveField(2) final String catalogId;
|
||||
@HiveField(3) final String name;
|
||||
@HiveField(4) final String description;
|
||||
@HiveField(5) final String? voucherCode;
|
||||
@HiveField(6) final String? qrCodeImage;
|
||||
@HiveField(7) final GiftCategory giftType;
|
||||
@HiveField(8) final int pointsCost;
|
||||
@HiveField(9) final double cashValue;
|
||||
@HiveField(10) final DateTime? expiryDate;
|
||||
@HiveField(11) final GiftStatus status;
|
||||
@HiveField(12) final DateTime redeemedAt;
|
||||
@HiveField(13) final DateTime? usedAt;
|
||||
@HiveField(14) final String? usedLocation;
|
||||
@HiveField(15) final String? usedReference;
|
||||
RedeemedGiftModel({
|
||||
required this.giftId,
|
||||
required this.userId,
|
||||
required this.catalogId,
|
||||
required this.name,
|
||||
required this.description,
|
||||
this.voucherCode,
|
||||
this.qrCodeImage,
|
||||
required this.giftType,
|
||||
required this.pointsCost,
|
||||
required this.cashValue,
|
||||
this.expiryDate,
|
||||
required this.status,
|
||||
required this.redeemedAt,
|
||||
this.usedAt,
|
||||
this.usedLocation,
|
||||
this.usedReference,
|
||||
});
|
||||
|
||||
factory RedeemedGiftModel.fromJson(Map<String, dynamic> json) => RedeemedGiftModel(
|
||||
giftId: json['gift_id'] as String,
|
||||
userId: json['user_id'] as String,
|
||||
catalogId: json['catalog_id'] as String,
|
||||
name: json['name'] as String,
|
||||
description: json['description'] as String,
|
||||
voucherCode: json['voucher_code'] as String?,
|
||||
qrCodeImage: json['qr_code_image'] as String?,
|
||||
giftType: GiftCategory.values.firstWhere((e) => e.name == json['gift_type']),
|
||||
pointsCost: json['points_cost'] as int,
|
||||
cashValue: (json['cash_value'] as num).toDouble(),
|
||||
expiryDate: json['expiry_date'] != null ? DateTime.parse(json['expiry_date']?.toString() ?? '') : null,
|
||||
status: GiftStatus.values.firstWhere((e) => e.name == json['status']),
|
||||
redeemedAt: DateTime.parse(json['redeemed_at']?.toString() ?? ''),
|
||||
usedAt: json['used_at'] != null ? DateTime.parse(json['used_at']?.toString() ?? '') : null,
|
||||
usedLocation: json['used_location'] as String?,
|
||||
usedReference: json['used_reference'] as String?,
|
||||
);
|
||||
@HiveField(0)
|
||||
final String giftId;
|
||||
@HiveField(1)
|
||||
final String userId;
|
||||
@HiveField(2)
|
||||
final String catalogId;
|
||||
@HiveField(3)
|
||||
final String name;
|
||||
@HiveField(4)
|
||||
final String description;
|
||||
@HiveField(5)
|
||||
final String? voucherCode;
|
||||
@HiveField(6)
|
||||
final String? qrCodeImage;
|
||||
@HiveField(7)
|
||||
final GiftCategory giftType;
|
||||
@HiveField(8)
|
||||
final int pointsCost;
|
||||
@HiveField(9)
|
||||
final double cashValue;
|
||||
@HiveField(10)
|
||||
final DateTime? expiryDate;
|
||||
@HiveField(11)
|
||||
final GiftStatus status;
|
||||
@HiveField(12)
|
||||
final DateTime redeemedAt;
|
||||
@HiveField(13)
|
||||
final DateTime? usedAt;
|
||||
@HiveField(14)
|
||||
final String? usedLocation;
|
||||
@HiveField(15)
|
||||
final String? usedReference;
|
||||
|
||||
factory RedeemedGiftModel.fromJson(Map<String, dynamic> json) =>
|
||||
RedeemedGiftModel(
|
||||
giftId: json['gift_id'] as String,
|
||||
userId: json['user_id'] as String,
|
||||
catalogId: json['catalog_id'] as String,
|
||||
name: json['name'] as String,
|
||||
description: json['description'] as String,
|
||||
voucherCode: json['voucher_code'] as String?,
|
||||
qrCodeImage: json['qr_code_image'] as String?,
|
||||
giftType: GiftCategory.values.firstWhere(
|
||||
(e) => e.name == json['gift_type'],
|
||||
),
|
||||
pointsCost: json['points_cost'] as int,
|
||||
cashValue: (json['cash_value'] as num).toDouble(),
|
||||
expiryDate: json['expiry_date'] != null
|
||||
? DateTime.parse(json['expiry_date']?.toString() ?? '')
|
||||
: null,
|
||||
status: GiftStatus.values.firstWhere((e) => e.name == json['status']),
|
||||
redeemedAt: DateTime.parse(json['redeemed_at']?.toString() ?? ''),
|
||||
usedAt: json['used_at'] != null
|
||||
? DateTime.parse(json['used_at']?.toString() ?? '')
|
||||
: null,
|
||||
usedLocation: json['used_location'] as String?,
|
||||
usedReference: json['used_reference'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'gift_id': giftId,
|
||||
@@ -63,7 +103,8 @@ class RedeemedGiftModel extends HiveObject {
|
||||
'used_reference': usedReference,
|
||||
};
|
||||
|
||||
bool get isExpired => expiryDate != null && DateTime.now().isAfter(expiryDate!);
|
||||
bool get isExpired =>
|
||||
expiryDate != null && DateTime.now().isAfter(expiryDate!);
|
||||
bool get isUsed => status == GiftStatus.used;
|
||||
bool get isActive => status == GiftStatus.active && !isExpired;
|
||||
}
|
||||
|
||||
@@ -194,13 +194,7 @@ class GiftCatalog {
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(
|
||||
catalogId,
|
||||
name,
|
||||
category,
|
||||
pointsCost,
|
||||
isActive,
|
||||
);
|
||||
return Object.hash(catalogId, name, category, pointsCost, isActive);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -15,7 +15,7 @@ enum EntryType {
|
||||
adjustment,
|
||||
|
||||
/// Points expired
|
||||
expiry;
|
||||
expiry,
|
||||
}
|
||||
|
||||
/// Entry source enum
|
||||
@@ -45,7 +45,7 @@ enum EntrySource {
|
||||
welcome,
|
||||
|
||||
/// Other source
|
||||
other;
|
||||
other,
|
||||
}
|
||||
|
||||
/// Complaint status enum
|
||||
@@ -63,7 +63,7 @@ enum ComplaintStatus {
|
||||
approved,
|
||||
|
||||
/// Complaint rejected
|
||||
rejected;
|
||||
rejected,
|
||||
}
|
||||
|
||||
/// Loyalty Point Entry Entity
|
||||
|
||||
@@ -164,13 +164,7 @@ class PointsRecord {
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(
|
||||
recordId,
|
||||
userId,
|
||||
invoiceNumber,
|
||||
invoiceAmount,
|
||||
status,
|
||||
);
|
||||
return Object.hash(recordId, userId, invoiceNumber, invoiceAmount, status);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -190,13 +190,7 @@ class RedeemedGift {
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(
|
||||
giftId,
|
||||
userId,
|
||||
catalogId,
|
||||
voucherCode,
|
||||
status,
|
||||
);
|
||||
return Object.hash(giftId, userId, catalogId, voucherCode, status);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -204,9 +204,7 @@ class LoyaltyPage extends ConsumerWidget {
|
||||
return Card(
|
||||
elevation: 5,
|
||||
margin: EdgeInsets.zero,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
@@ -228,17 +226,11 @@ class LoyaltyPage extends ConsumerWidget {
|
||||
children: [
|
||||
Text(
|
||||
'Hạng hiện tại: DIAMOND',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: AppColors.grey500,
|
||||
),
|
||||
style: TextStyle(fontSize: 13, color: AppColors.grey500),
|
||||
),
|
||||
Text(
|
||||
'Hạng kế tiếp: PLATINUM',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: AppColors.grey500,
|
||||
),
|
||||
style: TextStyle(fontSize: 13, color: AppColors.grey500),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -265,10 +257,7 @@ class LoyaltyPage extends ConsumerWidget {
|
||||
child: RichText(
|
||||
textAlign: TextAlign.center,
|
||||
text: const TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: AppColors.grey500,
|
||||
),
|
||||
style: TextStyle(fontSize: 13, color: AppColors.grey500),
|
||||
children: [
|
||||
TextSpan(text: 'Còn '),
|
||||
TextSpan(
|
||||
@@ -414,9 +403,7 @@ class LoyaltyPage extends ConsumerWidget {
|
||||
return Card(
|
||||
elevation: 1,
|
||||
margin: EdgeInsets.zero,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
@@ -436,7 +423,10 @@ class LoyaltyPage extends ConsumerWidget {
|
||||
_buildBenefitItem('Ưu tiên xử lý đơn hàng'),
|
||||
_buildBenefitItem('Tặng 500 điểm vào ngày sinh nhật'),
|
||||
_buildBenefitItem('Tư vấn thiết kế miễn phí'),
|
||||
_buildBenefitItem('Mời tham gia sự kiện VIP độc quyền', isLast: true),
|
||||
_buildBenefitItem(
|
||||
'Mời tham gia sự kiện VIP độc quyền',
|
||||
isLast: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -450,11 +440,7 @@ class LoyaltyPage extends ConsumerWidget {
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.check_circle,
|
||||
size: 20,
|
||||
color: Color(0xFF4A00E0),
|
||||
),
|
||||
const Icon(Icons.check_circle, size: 20, color: Color(0xFF4A00E0)),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
|
||||
@@ -65,7 +65,9 @@ class PointsHistoryPage extends ConsumerWidget {
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Transaction List
|
||||
...entries.map((entry) => _buildTransactionCard(context, ref, entry)),
|
||||
...entries.map(
|
||||
(entry) => _buildTransactionCard(context, ref, entry),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -82,9 +84,7 @@ class PointsHistoryPage extends ConsumerWidget {
|
||||
return Card(
|
||||
elevation: 1,
|
||||
margin: EdgeInsets.zero,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
@@ -101,20 +101,13 @@ class PointsHistoryPage extends ConsumerWidget {
|
||||
color: AppColors.grey900,
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
Icons.filter_list,
|
||||
color: AppColors.primaryBlue,
|
||||
size: 20,
|
||||
),
|
||||
Icon(Icons.filter_list, color: AppColors.primaryBlue, size: 20),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const Text(
|
||||
'Thời gian hiệu lực: 01/01/2023 - 31/12/2023',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.grey500,
|
||||
),
|
||||
style: TextStyle(fontSize: 12, color: AppColors.grey500),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -137,14 +130,14 @@ class PointsHistoryPage extends ConsumerWidget {
|
||||
|
||||
// Get transaction amount if it's a purchase
|
||||
final datasource = ref.read(pointsHistoryLocalDataSourceProvider);
|
||||
final transactionAmount = datasource.getTransactionAmount(entry.description);
|
||||
final transactionAmount = datasource.getTransactionAmount(
|
||||
entry.description,
|
||||
);
|
||||
|
||||
return Card(
|
||||
elevation: 1,
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
@@ -199,11 +192,16 @@ class PointsHistoryPage extends ConsumerWidget {
|
||||
OutlinedButton(
|
||||
onPressed: () {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Chức năng khiếu nại đang phát triển')),
|
||||
const SnackBar(
|
||||
content: Text('Chức năng khiếu nại đang phát triển'),
|
||||
),
|
||||
);
|
||||
},
|
||||
style: OutlinedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 6,
|
||||
),
|
||||
side: const BorderSide(color: AppColors.grey500),
|
||||
foregroundColor: AppColors.grey900,
|
||||
textStyle: const TextStyle(fontSize: 12),
|
||||
@@ -235,8 +233,8 @@ class PointsHistoryPage extends ConsumerWidget {
|
||||
color: entry.points > 0
|
||||
? AppColors.success
|
||||
: entry.points < 0
|
||||
? AppColors.danger
|
||||
: AppColors.grey900,
|
||||
? AppColors.danger
|
||||
: AppColors.grey900,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
@@ -282,10 +280,7 @@ class PointsHistoryPage extends ConsumerWidget {
|
||||
const SizedBox(height: 8),
|
||||
const Text(
|
||||
'Kéo xuống để làm mới',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.grey500,
|
||||
),
|
||||
style: TextStyle(fontSize: 14, color: AppColors.grey500),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -316,10 +311,7 @@ class PointsHistoryPage extends ConsumerWidget {
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
error.toString(),
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.grey500,
|
||||
),
|
||||
style: const TextStyle(fontSize: 14, color: AppColors.grey500),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
|
||||
@@ -37,13 +37,20 @@ class RewardsPage extends ConsumerWidget {
|
||||
icon: const Icon(Icons.arrow_back, color: Colors.black),
|
||||
onPressed: () => context.pop(),
|
||||
),
|
||||
title: const Text('Đổi quà tặng', style: TextStyle(color: Colors.black)),
|
||||
title: const Text(
|
||||
'Đổi quà tặng',
|
||||
style: TextStyle(color: Colors.black),
|
||||
),
|
||||
elevation: AppBarSpecs.elevation,
|
||||
backgroundColor: AppColors.white,
|
||||
foregroundColor: AppColors.grey900,
|
||||
centerTitle: false,
|
||||
actions: const [
|
||||
SizedBox(width: AppSpacing.sm),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.info_outline, color: Colors.black),
|
||||
onPressed: () => _showInfoDialog(context),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
],
|
||||
),
|
||||
body: RefreshIndicator(
|
||||
@@ -72,26 +79,20 @@ class RewardsPage extends ConsumerWidget {
|
||||
sliver: filteredGifts.isEmpty
|
||||
? _buildEmptyState()
|
||||
: SliverGrid(
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
childAspectRatio: 0.7,
|
||||
crossAxisSpacing: 0,
|
||||
mainAxisSpacing: 0,
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
final gift = filteredGifts[index];
|
||||
return RewardCard(
|
||||
gift: gift,
|
||||
onRedeem: () => _handleRedeemGift(
|
||||
context,
|
||||
ref,
|
||||
gift,
|
||||
),
|
||||
);
|
||||
},
|
||||
childCount: filteredGifts.length,
|
||||
),
|
||||
gridDelegate:
|
||||
const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
childAspectRatio: 0.7,
|
||||
crossAxisSpacing: 0,
|
||||
mainAxisSpacing: 0,
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate((context, index) {
|
||||
final gift = filteredGifts[index];
|
||||
return RewardCard(
|
||||
gift: gift,
|
||||
onRedeem: () => _handleRedeemGift(context, ref, gift),
|
||||
);
|
||||
}, childCount: filteredGifts.length),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -100,6 +101,84 @@ class RewardsPage extends ConsumerWidget {
|
||||
);
|
||||
}
|
||||
|
||||
/// Show info dialog with usage instructions
|
||||
void _showInfoDialog(BuildContext context) {
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text(
|
||||
'Hướng dẫn sử dụng',
|
||||
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
|
||||
),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text(
|
||||
'Đây là nội dung hướng dẫn sử dụng cho tính năng Đổi quà tặng:',
|
||||
style: TextStyle(fontSize: 14),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoItem(
|
||||
'Sử dụng điểm tích lũy của bạn để đổi các phần quà giá trị trong danh mục.',
|
||||
),
|
||||
_buildInfoItem(
|
||||
'Bấm vào một phần quà để xem chi tiết và điều kiện áp dụng.',
|
||||
),
|
||||
_buildInfoItem(
|
||||
'Khi xác nhận đổi quà, bạn có thể chọn "Nhận hàng tại Showroom".',
|
||||
),
|
||||
_buildInfoItem(
|
||||
'Nếu chọn "Nhận hàng tại Showroom", bạn sẽ cần chọn Showroom bạn muốn đến nhận từ danh sách thả xuống.',
|
||||
),
|
||||
_buildInfoItem(
|
||||
'Quà đã đổi sẽ được chuyển vào mục "Quà của tôi" (trong trang Hội viên).',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColors.primaryBlue,
|
||||
foregroundColor: Colors.white,
|
||||
minimumSize: const Size(double.infinity, 44),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: const Text('Đóng'),
|
||||
),
|
||||
],
|
||||
actionsPadding: const EdgeInsets.fromLTRB(20, 0, 20, 20),
|
||||
contentPadding: const EdgeInsets.fromLTRB(20, 16, 20, 16),
|
||||
titlePadding: const EdgeInsets.fromLTRB(20, 20, 20, 8),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Build info item with bullet point
|
||||
Widget _buildInfoItem(String text) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(top: 6),
|
||||
child: Icon(Icons.circle, size: 6, color: AppColors.grey500),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(text, style: TextStyle(fontSize: 14, height: 1.5)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Build category filter pills
|
||||
Widget _buildCategoryFilter(
|
||||
BuildContext context,
|
||||
@@ -237,10 +316,7 @@ class RewardsPage extends ConsumerWidget {
|
||||
const SizedBox(height: 8),
|
||||
const Text(
|
||||
'Vui lòng thử lại sau',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.grey500,
|
||||
),
|
||||
style: TextStyle(fontSize: 14, color: AppColors.grey500),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -290,10 +366,7 @@ class RewardsPage extends ConsumerWidget {
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'Chi phí:',
|
||||
style: TextStyle(fontSize: 13),
|
||||
),
|
||||
const Text('Chi phí:', style: TextStyle(fontSize: 13)),
|
||||
Text(
|
||||
'${numberFormat.format(gift.pointsCost)} điểm',
|
||||
style: const TextStyle(
|
||||
@@ -363,9 +436,7 @@ class RewardsPage extends ConsumerWidget {
|
||||
children: [
|
||||
const Icon(Icons.check_circle, color: Colors.white),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text('Đổi quà "${gift.name}" thành công!'),
|
||||
),
|
||||
Expanded(child: Text('Đổi quà "${gift.name}" thành công!')),
|
||||
],
|
||||
),
|
||||
backgroundColor: AppColors.success,
|
||||
|
||||
@@ -38,7 +38,9 @@ class PointsHistory extends _$PointsHistory {
|
||||
Future<void> refresh() async {
|
||||
state = const AsyncValue.loading();
|
||||
state = await AsyncValue.guard(() async {
|
||||
return await ref.read(pointsHistoryLocalDataSourceProvider).getAllEntries();
|
||||
return await ref
|
||||
.read(pointsHistoryLocalDataSourceProvider)
|
||||
.getAllEntries();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,25 +22,17 @@ class RewardCard extends ConsumerWidget {
|
||||
/// Callback when redeem button is pressed
|
||||
final VoidCallback onRedeem;
|
||||
|
||||
const RewardCard({
|
||||
required this.gift,
|
||||
required this.onRedeem,
|
||||
super.key,
|
||||
});
|
||||
const RewardCard({required this.gift, required this.onRedeem, super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final hasEnoughPoints = ref.watch(
|
||||
hasEnoughPointsProvider(gift.pointsCost),
|
||||
);
|
||||
final hasEnoughPoints = ref.watch(hasEnoughPointsProvider(gift.pointsCost));
|
||||
final numberFormat = NumberFormat('#,###', 'vi_VN');
|
||||
|
||||
return Card(
|
||||
elevation: 2,
|
||||
margin: EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
@@ -158,9 +150,7 @@ class RewardCard extends ConsumerWidget {
|
||||
placeholder: (context, url) => Container(
|
||||
color: AppColors.grey100,
|
||||
child: const Center(
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
),
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
),
|
||||
),
|
||||
errorWidget: (context, url, error) => Container(
|
||||
|
||||
Reference in New Issue
Block a user