split bill

This commit is contained in:
efrilm
2025-10-31 20:43:37 +07:00
parent 6b42cd86ff
commit 35f02e6b76
18 changed files with 1763 additions and 27 deletions
@@ -69,3 +69,102 @@ class PaymentItemRequestDto with _$PaymentItemRequestDto {
amount: request.amount,
);
}
@freezed
class PaymentSplitBillRequestDto with _$PaymentSplitBillRequestDto {
const PaymentSplitBillRequestDto._();
const factory PaymentSplitBillRequestDto({
@JsonKey(name: "order_id") String? orderId,
@JsonKey(name: "payment_method_id") String? paymentMethodId,
@JsonKey(name: "customer_id") String? customerId,
@JsonKey(name: "customer_name") String? customerName,
@JsonKey(name: "type") String? type, // e.g., "AMOUNT" or "ITEM"
@JsonKey(name: "amount") int? amount,
@JsonKey(name: "items") List<PaymentItemSplitBillRequestDto>? items,
}) = _PaymentSplitBillRequestDto;
factory PaymentSplitBillRequestDto.fromJson(Map<String, dynamic> json) =>
_$PaymentSplitBillRequestDtoFromJson(json);
// Optional mapper ke domain
PaymentSplitBillRequest toDomain() => PaymentSplitBillRequest(
orderId: orderId ?? '',
paymentMethodId: paymentMethodId ?? '',
customerId: customerId ?? '',
type: type?.toSplitType() ?? SplitType.unknown,
amount: amount ?? 0,
items: items?.map((e) => e.toDomain()).toList() ?? [],
customerName: customerName ?? '',
);
factory PaymentSplitBillRequestDto.fromDomain(
PaymentSplitBillRequest request,
) => PaymentSplitBillRequestDto(
orderId: request.orderId,
paymentMethodId: request.paymentMethodId,
customerId: request.customerId,
type: request.type.toStringType(),
amount: request.amount,
items: request.items
.map((e) => PaymentItemSplitBillRequestDto.fromDomain(e))
.toList(),
);
Map<String, dynamic> toRequest() {
Map<String, dynamic> data = {
'order_id': orderId,
'payment_method_id': paymentMethodId,
'type': type,
};
if (customerId != null && customerId != '') {
data['customer_id'] = customerId;
}
if (customerName != null && customerName != '') {
data['customer_name'] = customerName;
}
if (type == 'AMOUNT') {
data['amount'] = amount;
}
if (type == 'ITEM') {
data['items'] = items?.map((item) => item.toRequest()).toList();
}
return data;
}
}
@freezed
class PaymentItemSplitBillRequestDto with _$PaymentItemSplitBillRequestDto {
const PaymentItemSplitBillRequestDto._();
const factory PaymentItemSplitBillRequestDto({
@JsonKey(name: "order_item_id") String? orderItemId,
@JsonKey(name: "quantity") int? quantity,
}) = _PaymentItemSplitBillRequestDto;
factory PaymentItemSplitBillRequestDto.fromJson(Map<String, dynamic> json) =>
_$PaymentItemSplitBillRequestDtoFromJson(json);
// Optional mapper ke domain
PaymentItemSplitBillRequest toDomain() => PaymentItemSplitBillRequest(
orderItemId: orderItemId ?? '',
quantity: quantity ?? 0,
);
factory PaymentItemSplitBillRequestDto.fromDomain(
PaymentItemSplitBillRequest request,
) => PaymentItemSplitBillRequestDto(
orderItemId: request.orderItemId,
quantity: request.quantity,
);
Map<String, dynamic> toRequest() => {
'order_item_id': orderItemId,
'quantity': quantity,
};
}