257 lines
9.1 KiB
Go
257 lines
9.1 KiB
Go
package response
|
|
|
|
import (
|
|
"enaklo-pos-be/internal/constants/order"
|
|
"enaklo-pos-be/internal/constants/transaction"
|
|
"enaklo-pos-be/internal/entity"
|
|
"time"
|
|
)
|
|
|
|
type Order struct {
|
|
ID int64 `json:"id" `
|
|
BranchID int64 `json:"branch_id" `
|
|
BranchName string `json:"branch_name" `
|
|
Amount float64 `json:"amount" `
|
|
Status order.OrderStatus `json:"status" `
|
|
CustomerName string `json:"customer_name" `
|
|
CustomerPhone string `json:"customer_phone" `
|
|
Pax int `json:"pax" `
|
|
PaymentMethod transaction.PaymentMethod `json:"payment_method" `
|
|
OrderItem []OrderItem `json:"order_items" `
|
|
CreatedAt string `json:"created_at"`
|
|
UpdatedAt string `json:"updated_at"`
|
|
}
|
|
|
|
type OrderAmount struct {
|
|
Amount float64 `json:"amount"`
|
|
}
|
|
|
|
type HistoryOrder struct {
|
|
ID int64 `json:"id"`
|
|
Employee string `json:"employee"`
|
|
Site string `json:"site"`
|
|
Timestamp string `json:"timestamp"`
|
|
BookingTime string `json:"booking_time"`
|
|
Tickets []string `json:"tickets"`
|
|
PaymentType string `json:"payment_type"`
|
|
Status string `json:"status"`
|
|
Amount float64 `json:"amount"`
|
|
VisitDate string `json:"visit_date"`
|
|
TicketStatus string `json:"ticket_status"`
|
|
Source string `json:"source"`
|
|
}
|
|
|
|
type OrderItem struct {
|
|
OrderItemID int64 `json:"order_item_id" `
|
|
ItemID int64 `json:"item_id" `
|
|
ItemType order.ItemType `json:"item_type" `
|
|
ItemName string `json:"item_name" `
|
|
Price float64 `json:"price" `
|
|
Qty int64 `json:"qty" `
|
|
CreatedAt string `json:"created_at"`
|
|
UpdatedAt string `json:"updated_at"`
|
|
}
|
|
|
|
type OrderList struct {
|
|
Orders []Order `json:"orders"`
|
|
Total int64 `json:"total"`
|
|
Limit int `json:"limit"`
|
|
Offset int `json:"offset"`
|
|
}
|
|
|
|
type HistoryOrderList struct {
|
|
Orders []HistoryOrder `json:"history_orders"`
|
|
Total int64 `json:"total"`
|
|
Limit int `json:"limit"`
|
|
Offset int `json:"offset"`
|
|
}
|
|
|
|
type TicketSold struct {
|
|
Count int64 `json:"count"`
|
|
}
|
|
|
|
type OrderMonthlyRevenue struct {
|
|
TotalRevenue float64 `json:"total_revenue"`
|
|
TotalTransaction int64 `json:"total_transaction"`
|
|
}
|
|
|
|
type OrderBranchRevenue struct {
|
|
BranchID string `json:"branch_id"`
|
|
BranchName string `json:"name"`
|
|
BranchLocation string `json:"location"`
|
|
TotalTransaction int `json:"total_trans"`
|
|
TotalAmount float64 `json:"total_amount"`
|
|
}
|
|
|
|
type CreateOrderResponse struct {
|
|
ID int64 `json:"id"`
|
|
PartnerID int64 `json:"partner_id"`
|
|
Status string `json:"status"`
|
|
Amount float64 `json:"amount"`
|
|
Total float64 `json:"total"`
|
|
Tax float64 `json:"tax"`
|
|
PaymentType string `json:"payment_type"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
OrderItems []CreateOrderItemResponse `json:"order_items"`
|
|
}
|
|
|
|
type PrintDetailResponse struct {
|
|
ID int64 `json:"id"`
|
|
Logo string `json:"logo"`
|
|
OrderID string `json:"order_id"`
|
|
PartnerName string `json:"partner_name"`
|
|
Total float64 `json:"total"`
|
|
Fee float64 `json:"fee"`
|
|
PaymentType string `json:"payment_type"`
|
|
Source string `json:"source"`
|
|
VisitDateAt string `json:"visit_date_at"`
|
|
VisitTime string `json:"visit_time"`
|
|
OrderItems []CreateOrderItemResponse `json:"order_items"`
|
|
CasheerName string `json:"casheer_name"`
|
|
}
|
|
|
|
type ExecuteOrderResponse struct {
|
|
ID int64 `json:"id"`
|
|
PartnerID int64 `json:"partner_id"`
|
|
Status string `json:"status"`
|
|
Amount float64 `json:"amount"`
|
|
PaymentType string `json:"payment_type"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
OrderItems []CreateOrderItemResponse `json:"order_items"`
|
|
PaymentToken string `json:"payment_token"`
|
|
RedirectURL string `json:"redirect_url"`
|
|
QRcode string `json:"qr_code"`
|
|
VirtualAccount string `json:"virtual_account"`
|
|
BankName string `json:"bank_name"`
|
|
BankCode string `json:"bank_code"`
|
|
}
|
|
|
|
type ExecuteCheckinResponse struct {
|
|
ID int64 `json:"id"`
|
|
PartnerID int64 `json:"partner_id"`
|
|
Status string `json:"status"`
|
|
Amount float64 `json:"amount"`
|
|
PaymentType string `json:"payment_type"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
OrderItems []CreateOrderItemResponse `json:"order_items"`
|
|
PaymentToken string `json:"payment_token"`
|
|
RedirectURL string `json:"redirect_url"`
|
|
QRcode string `json:"qr_code"`
|
|
}
|
|
|
|
type CheckingInquiryResponse struct {
|
|
Token string `json:"token"`
|
|
}
|
|
|
|
type CreateOrderItemResponse struct {
|
|
ID int64 `json:"id"`
|
|
ItemID int64 `json:"item_id"`
|
|
Quantity int `json:"quantity"`
|
|
Price float64 `json:"price"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
type ProductDailySales struct {
|
|
Day time.Time `json:"day"`
|
|
SiteID int64 `json:"site_id"`
|
|
SiteName string `json:"site_name"`
|
|
PaymentType string `json:"payment_type"`
|
|
Total float64 `json:"total"`
|
|
}
|
|
|
|
type PaymentDistribution struct {
|
|
PaymentType string `json:"payment_type"`
|
|
Count int `json:"count"`
|
|
}
|
|
|
|
type OrderDetail struct {
|
|
ID int64 `json:"id"`
|
|
QRCode string `json:"qr_code"`
|
|
SiteName string `json:"site_name"`
|
|
FullName string `json:"full_name"`
|
|
Email string `json:"email"`
|
|
PhoneNumber string `json:"phone_number"`
|
|
OrderItems []OrderDetailItem `json:"order_items"`
|
|
TotalAmount float64 `json:"total_amount"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
Status string `json:"status"`
|
|
PaymentLink string `json:"payment_link"`
|
|
PaymentToken string `json:"payment_token"`
|
|
Fee float64 `json:"fee"`
|
|
}
|
|
|
|
type OrderDetailItem struct {
|
|
Name string `json:"name"`
|
|
ItemType string `json:"item_type"`
|
|
Description string `json:"description"`
|
|
Quantity int `json:"quantity"` // Quantity of the item
|
|
UnitPrice float64 `json:"unit_price"` // Price per unit
|
|
TotalPrice float64 `json:"total_price"` // Total price for this item (Quantity * UnitPrice)
|
|
}
|
|
|
|
type OrderHistoryResponse struct {
|
|
ID int64 `json:"id"`
|
|
IsMember bool `json:"is_member"`
|
|
CustomerID *int64 `json:"customer_id"`
|
|
CustomerName string `json:"customer_name"`
|
|
Status string `json:"status"`
|
|
Amount float64 `json:"amount"`
|
|
Total float64 `json:"total"`
|
|
PaymentType string `json:"payment_type"`
|
|
TableNumber string `json:"table_number"`
|
|
OrderType string `json:"order_type"`
|
|
OrderItems []OrderItemResponse `json:"order_items"`
|
|
CreatedAt string `json:"created_at"`
|
|
Tax float64 `json:"tax"`
|
|
RestaurantName string `json:"restaurant_name"`
|
|
}
|
|
|
|
func MapOrderHistoryResponse(orders []*entity.Order) []OrderHistoryResponse {
|
|
responseData := make([]OrderHistoryResponse, 0, len(orders))
|
|
|
|
for _, order := range orders {
|
|
orderResponse := mapOrderToResponse(order)
|
|
responseData = append(responseData, orderResponse)
|
|
}
|
|
|
|
return responseData
|
|
}
|
|
|
|
func mapOrderToResponse(order *entity.Order) OrderHistoryResponse {
|
|
paymentFormatter := NewPaymentFormatter()
|
|
return OrderHistoryResponse{
|
|
ID: order.ID,
|
|
CustomerName: order.CustomerName,
|
|
CustomerID: order.CustomerID,
|
|
IsMember: order.IsMemberOrder(),
|
|
Status: order.Status,
|
|
Amount: order.Amount,
|
|
Total: order.Total,
|
|
PaymentType: paymentFormatter.Format(order.PaymentType, order.PaymentProvider),
|
|
TableNumber: order.TableNumber,
|
|
OrderType: order.OrderType,
|
|
OrderItems: mapOrderItems(order.OrderItems),
|
|
CreatedAt: order.CreatedAt.Format(time.RFC3339),
|
|
Tax: order.Tax,
|
|
}
|
|
}
|
|
|
|
func mapOrderItems(items []entity.OrderItem) []OrderItemResponse {
|
|
orderItems := make([]OrderItemResponse, 0, len(items))
|
|
|
|
for _, item := range items {
|
|
orderItems = append(orderItems, OrderItemResponse{
|
|
OrderItemID: item.ID,
|
|
ProductID: item.ItemID,
|
|
ProductName: item.ItemName,
|
|
Price: item.Price,
|
|
Quantity: item.Quantity,
|
|
Subtotal: item.Price * float64(item.Quantity),
|
|
Notes: item.Notes,
|
|
Status: item.Status,
|
|
})
|
|
}
|
|
|
|
return orderItems
|
|
}
|