Fix Split Bill

This commit is contained in:
Aditya Siregar
2025-08-07 22:45:02 +07:00
parent 3696451dc6
commit 93a3b29ae9
24 changed files with 894 additions and 197 deletions
+90 -17
View File
@@ -111,24 +111,45 @@ func OrderModelToContract(resp *models.OrderResponse) *contract.OrderResponse {
PrinterType: item.PrinterType,
}
}
// Map payments
payments := make([]contract.PaymentResponse, len(resp.Payments))
for i, payment := range resp.Payments {
payments[i] = *PaymentModelToContract(&payment)
}
return &contract.OrderResponse{
ID: resp.ID,
OrderNumber: resp.OrderNumber,
OutletID: resp.OutletID,
UserID: resp.UserID,
TableNumber: resp.TableNumber,
OrderType: string(resp.OrderType),
Status: string(resp.Status),
Subtotal: resp.Subtotal,
TaxAmount: resp.TaxAmount,
DiscountAmount: resp.DiscountAmount,
TotalAmount: resp.TotalAmount,
Notes: resp.Notes,
Metadata: resp.Metadata,
CreatedAt: resp.CreatedAt,
UpdatedAt: resp.UpdatedAt,
OrderItems: items,
IsRefund: resp.IsRefund,
ID: resp.ID,
OrderNumber: resp.OrderNumber,
OutletID: resp.OutletID,
UserID: resp.UserID,
TableNumber: resp.TableNumber,
OrderType: string(resp.OrderType),
Status: string(resp.Status),
Subtotal: resp.Subtotal,
TaxAmount: resp.TaxAmount,
DiscountAmount: resp.DiscountAmount,
TotalAmount: resp.TotalAmount,
TotalCost: resp.TotalCost,
RemainingAmount: resp.RemainingAmount,
PaymentStatus: string(resp.PaymentStatus),
RefundAmount: resp.RefundAmount,
IsVoid: resp.IsVoid,
IsRefund: resp.IsRefund,
VoidReason: resp.VoidReason,
VoidedAt: resp.VoidedAt,
VoidedBy: resp.VoidedBy,
RefundReason: resp.RefundReason,
RefundedAt: resp.RefundedAt,
RefundedBy: resp.RefundedBy,
Notes: resp.Notes,
Metadata: resp.Metadata,
CreatedAt: resp.CreatedAt,
UpdatedAt: resp.UpdatedAt,
OrderItems: items,
Payments: payments,
TotalPaid: resp.TotalPaid,
PaymentCount: resp.PaymentCount,
SplitType: resp.SplitType,
}
}
@@ -257,8 +278,14 @@ func ListOrdersModelToContract(resp *models.ListOrdersResponse) *contract.ListOr
orders[i] = *OrderModelToContract(&order)
}
payments := make([]contract.PaymentResponse, len(resp.Payments))
for i, payment := range resp.Payments {
payments[i] = *PaymentModelToContract(&payment)
}
return &contract.ListOrdersResponse{
Orders: orders,
Payments: payments,
TotalCount: resp.TotalCount,
Page: resp.Page,
Limit: resp.Limit,
@@ -309,11 +336,14 @@ func PaymentModelToContract(resp *models.PaymentResponse) *contract.PaymentRespo
ID: resp.ID,
OrderID: resp.OrderID,
PaymentMethodID: resp.PaymentMethodID,
PaymentMethodName: resp.PaymentMethodName,
PaymentMethodType: string(resp.PaymentMethodType),
Amount: resp.Amount,
Status: string(resp.Status),
TransactionID: resp.TransactionID,
SplitNumber: resp.SplitNumber,
SplitTotal: resp.SplitTotal,
SplitType: resp.SplitType,
SplitDescription: resp.SplitDescription,
RefundAmount: resp.RefundAmount,
RefundReason: resp.RefundReason,
@@ -342,3 +372,46 @@ func RefundOrderContractToModel(req *contract.RefundOrderRequest) *models.Refund
OrderItems: orderItems,
}
}
func SplitBillContractToModel(req *contract.SplitBillRequest) *models.SplitBillRequest {
items := make([]models.SplitBillItemRequest, len(req.Items))
for i, item := range req.Items {
items[i] = models.SplitBillItemRequest{
OrderItemID: item.OrderItemID,
Amount: item.Amount,
}
}
return &models.SplitBillRequest{
OrderID: req.OrderID,
PaymentMethodID: req.PaymentMethodID,
CustomerID: req.CustomerID,
Type: req.Type,
Items: items,
Amount: req.Amount,
OrganizationID: req.OrganizationID,
}
}
func SplitBillModelToContract(resp *models.SplitBillResponse) *contract.SplitBillResponse {
if resp == nil {
return nil
}
items := make([]contract.SplitBillItemResponse, len(resp.Items))
for i, item := range resp.Items {
items[i] = contract.SplitBillItemResponse{
OrderItemID: item.OrderItemID,
Amount: item.Amount,
}
}
return &contract.SplitBillResponse{
PaymentID: resp.PaymentID,
OrderID: resp.OrderID,
CustomerID: resp.CustomerID,
Type: resp.Type,
Amount: resp.Amount,
Items: items,
Message: resp.Message,
}
}