Files
efrilm 38850b281f
Build & Deploy iOS to TestFlight / build-and-deploy (push) Waiting to run
feat: integrate enakgame and voucher
2026-10-10 02:33:16 +07:00

131 lines
4.5 KiB
Dart

part of '../wallet_dtos.dart';
/// Satu DTO untuk daftar dan detail order; field detail kosong di daftar.
@freezed
abstract class CustomerOrderDto with _$CustomerOrderDto {
const factory CustomerOrderDto({
@JsonKey(name: 'id') String? id,
@JsonKey(name: 'order_number') String? orderNumber,
@JsonKey(name: 'outlet_name') String? outletName,
@JsonKey(name: 'order_type') String? orderType,
@JsonKey(name: 'status') String? status,
@JsonKey(name: 'payment_status') String? paymentStatus,
@JsonKey(name: 'total_amount') int? totalAmount,
@JsonKey(name: 'item_count') int? itemCount,
@JsonKey(name: 'is_void') bool? isVoid,
@JsonKey(name: 'is_refund') bool? isRefund,
@JsonKey(name: 'points_earned') int? pointsEarned,
@JsonKey(name: 'coins_earned') int? coinsEarned,
@JsonKey(name: 'created_at') String? createdAt,
// Detail
@JsonKey(name: 'table_number') String? tableNumber,
@JsonKey(name: 'subtotal') int? subtotal,
@JsonKey(name: 'discount_amount') int? discountAmount,
@JsonKey(name: 'tax_amount') int? taxAmount,
@JsonKey(name: 'refund_amount') int? refundAmount,
@JsonKey(name: 'items') List<CustomerOrderItemDto>? items,
@JsonKey(name: 'payments') List<CustomerOrderPaymentDto>? payments,
}) = _CustomerOrderDto;
factory CustomerOrderDto.fromJson(Map<String, dynamic> json) =>
_$CustomerOrderDtoFromJson(json);
const CustomerOrderDto._();
CustomerOrder toDomain() => CustomerOrder(
id: id ?? '',
orderNumber: orderNumber ?? '',
outletName: outletName ?? '',
orderType: orderType ?? '',
status: status ?? '',
paymentStatus: paymentStatus ?? '',
totalAmount: totalAmount ?? 0,
itemCount: itemCount ?? 0,
isVoid: isVoid ?? false,
isRefund: isRefund ?? false,
pointsEarned: pointsEarned ?? 0,
coinsEarned: coinsEarned ?? 0,
createdAt: _parseDateTime(createdAt),
);
CustomerOrderDetail toDetailDomain() => CustomerOrderDetail(
order: toDomain(),
tableNumber: (tableNumber?.isEmpty ?? true) ? null : tableNumber,
subtotal: subtotal ?? 0,
discountAmount: discountAmount ?? 0,
taxAmount: taxAmount ?? 0,
refundAmount: refundAmount ?? 0,
items: items?.map((e) => e.toDomain()).toList() ?? [],
payments: payments?.map((e) => e.toDomain()).toList() ?? [],
);
}
@freezed
abstract class CustomerOrderItemDto with _$CustomerOrderItemDto {
const factory CustomerOrderItemDto({
@JsonKey(name: 'id') String? id,
@JsonKey(name: 'product_name') String? productName,
@JsonKey(name: 'variant_name') String? variantName,
@JsonKey(name: 'quantity') int? quantity,
@JsonKey(name: 'weight') double? weight,
@JsonKey(name: 'unit_name') String? unitName,
@JsonKey(name: 'unit_price') int? unitPrice,
@JsonKey(name: 'total_price') int? totalPrice,
@JsonKey(name: 'refund_quantity') int? refundQuantity,
}) = _CustomerOrderItemDto;
factory CustomerOrderItemDto.fromJson(Map<String, dynamic> json) =>
_$CustomerOrderItemDtoFromJson(json);
const CustomerOrderItemDto._();
CustomerOrderItem toDomain() => CustomerOrderItem(
id: id ?? '',
productName: productName ?? '',
variantName: (variantName?.isEmpty ?? true) ? null : variantName,
quantity: quantity ?? 0,
weight: weight,
unitName: unitName,
unitPrice: unitPrice ?? 0,
totalPrice: totalPrice ?? 0,
refundQuantity: refundQuantity ?? 0,
);
}
@freezed
abstract class CustomerOrderPaymentDto with _$CustomerOrderPaymentDto {
const factory CustomerOrderPaymentDto({
@JsonKey(name: 'id') String? id,
@JsonKey(name: 'method_name') String? methodName,
@JsonKey(name: 'method_type') String? methodType,
@JsonKey(name: 'amount') int? amount,
@JsonKey(name: 'refund_amount') int? refundAmount,
}) = _CustomerOrderPaymentDto;
factory CustomerOrderPaymentDto.fromJson(Map<String, dynamic> json) =>
_$CustomerOrderPaymentDtoFromJson(json);
const CustomerOrderPaymentDto._();
CustomerOrderPayment toDomain() => CustomerOrderPayment(
id: id ?? '',
methodName: methodName ?? '',
methodType: methodType ?? '',
amount: amount ?? 0,
refundAmount: refundAmount ?? 0,
);
}
class CustomerOrderPageDto {
final List<CustomerOrderDto> items;
final WalletPaginationDto pagination;
const CustomerOrderPageDto({required this.items, required this.pagination});
CustomerOrderPage toDomain() => CustomerOrderPage(
items: items.map((e) => e.toDomain()).toList(),
page: pagination.page ?? 1,
totalPages: pagination.totalPages ?? 1,
);
}