257 lines
9.1 KiB
Go
Raw Normal View History

2023-10-08 15:59:42 +07:00
package response
import (
2025-03-04 20:36:17 +07:00
"enaklo-pos-be/internal/constants/order"
"enaklo-pos-be/internal/constants/transaction"
2025-06-27 13:01:39 +07:00
"enaklo-pos-be/internal/entity"
2024-06-04 02:59:31 +07:00
"time"
2023-10-08 15:59:42 +07:00
)
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"`
}
2024-07-26 11:37:22 +07:00
type HistoryOrder struct {
2024-08-13 23:09:05 +07:00
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"`
2024-07-26 11:37:22 +07:00
}
2023-10-08 15:59:42 +07:00
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"`
}
2024-07-26 11:37:22 +07:00
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"`
}
2023-10-08 15:59:42 +07:00
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"`
}
2024-06-04 02:59:31 +07:00
type CreateOrderResponse struct {
ID int64 `json:"id"`
PartnerID int64 `json:"partner_id"`
Status string `json:"status"`
Amount float64 `json:"amount"`
2024-08-09 10:02:05 +07:00
Total float64 `json:"total"`
2025-04-10 11:21:08 +07:00
Tax float64 `json:"tax"`
2024-06-04 02:59:31 +07:00
PaymentType string `json:"payment_type"`
CreatedAt time.Time `json:"created_at"`
OrderItems []CreateOrderItemResponse `json:"order_items"`
}
2024-08-21 15:48:50 +07:00
type PrintDetailResponse struct {
ID int64 `json:"id"`
2024-08-21 15:51:40 +07:00
Logo string `json:"logo"`
2024-08-21 15:48:50 +07:00
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"`
}
2024-06-04 02:59:31 +07:00
type ExecuteOrderResponse struct {
2024-10-15 11:52:34 +07:00
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"`
2024-06-04 02:59:31 +07:00
}
2024-08-13 23:09:05 +07:00
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"`
}
2024-06-04 02:59:31 +07:00
type CreateOrderItemResponse struct {
2024-12-20 16:52:48 +07:00
ID int64 `json:"id"`
ItemID int64 `json:"item_id"`
2025-03-08 00:35:23 +07:00
Quantity int `json:"quantity"`
2024-12-20 16:52:48 +07:00
Price float64 `json:"price"`
Name string `json:"name"`
2024-06-04 02:59:31 +07:00
}
2024-08-02 02:27:57 +07:00
type ProductDailySales struct {
2024-08-02 14:41:41 +07:00
Day time.Time `json:"day"`
SiteID int64 `json:"site_id"`
SiteName string `json:"site_name"`
PaymentType string `json:"payment_type"`
Total float64 `json:"total"`
2024-08-02 02:27:57 +07:00
}
type PaymentDistribution struct {
PaymentType string `json:"payment_type"`
Count int `json:"count"`
}
2024-08-04 01:14:59 +07:00
type OrderDetail struct {
2024-08-19 18:26:57 +07:00
ID int64 `json:"id"`
QRCode string `json:"qr_code"`
2024-08-21 22:27:05 +07:00
SiteName string `json:"site_name"`
2024-08-19 18:26:57 +07:00
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"`
2024-08-22 01:32:24 +07:00
Fee float64 `json:"fee"`
2024-08-04 01:14:59 +07:00
}
type OrderDetailItem struct {
2024-08-22 03:23:58 +07:00
Name string `json:"name"`
2024-08-04 01:14:59 +07:00
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)
}
2025-04-10 11:21:08 +07:00
type OrderHistoryResponse struct {
2025-05-03 10:50:41 +07:00
ID int64 `json:"id"`
2025-05-06 00:40:43 +07:00
IsMember bool `json:"is_member"`
CustomerID *int64 `json:"customer_id"`
2025-05-03 10:50:41 +07:00
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"`
2025-04-10 11:21:08 +07:00
}
2025-06-27 13:01:39 +07:00
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
}