136 lines
3.9 KiB
Go
136 lines
3.9 KiB
Go
package entity
|
|
|
|
import (
|
|
"enaklo-pos-be/internal/constants"
|
|
"time"
|
|
)
|
|
|
|
type OrderInquiry struct {
|
|
ID string `json:"id"`
|
|
PartnerID int64 `json:"partner_id"`
|
|
CustomerID int64 `json:"customer_id,omitempty"`
|
|
CustomerName string `json:"customer_name"`
|
|
CustomerPhoneNumber string `json:"customer_phone_number"`
|
|
CustomerEmail string `json:"customer_email"`
|
|
Status string `json:"status"`
|
|
Amount float64 `json:"amount"`
|
|
Tax float64 `json:"tax"`
|
|
Total float64 `json:"total"`
|
|
PaymentType string `json:"payment_type"`
|
|
Source string `json:"source"`
|
|
CreatedBy int64 `json:"created_by"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
ExpiresAt time.Time `json:"expires_at"`
|
|
OrderItems []OrderItem `json:"order_items"`
|
|
PaymentProvider string `json:"payment_provider"`
|
|
TableNumber string `json:"table_number"`
|
|
OrderType string `json:"order_type"`
|
|
CashierSessionID int64 `json:"cashier_session_id"`
|
|
}
|
|
|
|
type OrderCalculation struct {
|
|
Subtotal float64 `json:"subtotal"`
|
|
Tax float64 `json:"tax"`
|
|
Total float64 `json:"total"`
|
|
}
|
|
|
|
type OrderInquiryResponse struct {
|
|
OrderInquiry *OrderInquiry `json:"order_inquiry"`
|
|
Token string `json:"token"`
|
|
}
|
|
|
|
func NewOrderInquiry(
|
|
partnerID int64,
|
|
customerID int64,
|
|
amount float64,
|
|
tax float64,
|
|
total float64,
|
|
paymentType string,
|
|
source string,
|
|
createdBy int64,
|
|
customerName string,
|
|
customerPhoneNumber string,
|
|
customerEmail string,
|
|
paymentProvider string,
|
|
tableNumber string,
|
|
orderType string,
|
|
cashierSessionID int64,
|
|
) *OrderInquiry {
|
|
return &OrderInquiry{
|
|
ID: constants.GenerateUUID(),
|
|
PartnerID: partnerID,
|
|
Status: "PENDING",
|
|
Amount: amount,
|
|
Tax: tax,
|
|
Total: total,
|
|
PaymentType: paymentType,
|
|
CustomerID: customerID,
|
|
Source: source,
|
|
CreatedBy: createdBy,
|
|
CreatedAt: time.Now(),
|
|
ExpiresAt: time.Now().Add(2 * time.Minute),
|
|
OrderItems: []OrderItem{},
|
|
CustomerName: customerName,
|
|
CustomerEmail: customerEmail,
|
|
CustomerPhoneNumber: customerPhoneNumber,
|
|
PaymentProvider: paymentProvider,
|
|
TableNumber: tableNumber,
|
|
OrderType: orderType,
|
|
CashierSessionID: cashierSessionID,
|
|
}
|
|
}
|
|
|
|
func (oi *OrderInquiry) AddOrderItem(item OrderItemRequest, product *Product) {
|
|
oi.OrderItems = append(oi.OrderItems, OrderItem{
|
|
ItemID: item.ProductID,
|
|
ItemType: product.Type,
|
|
Price: product.Price,
|
|
ItemName: product.Name,
|
|
Quantity: item.Quantity,
|
|
CreatedBy: oi.CreatedBy,
|
|
Product: product,
|
|
Notes: item.Notes,
|
|
})
|
|
}
|
|
|
|
func (i *OrderInquiry) ToOrder(paymentMethod, paymentProvider string) *Order {
|
|
now := time.Now()
|
|
|
|
order := &Order{
|
|
PartnerID: i.PartnerID,
|
|
CustomerID: &i.CustomerID,
|
|
InquiryID: &i.ID,
|
|
Status: constants.StatusPaid,
|
|
Amount: i.Amount,
|
|
Tax: i.Tax,
|
|
Total: i.Total,
|
|
PaymentType: paymentMethod,
|
|
PaymentProvider: paymentProvider,
|
|
Source: i.Source,
|
|
CreatedBy: i.CreatedBy,
|
|
CreatedAt: now,
|
|
OrderItems: make([]OrderItem, len(i.OrderItems)),
|
|
OrderType: i.OrderType,
|
|
CustomerName: i.CustomerName,
|
|
TableNumber: i.TableNumber,
|
|
CashierSessionID: i.CashierSessionID,
|
|
}
|
|
|
|
for idx, item := range i.OrderItems {
|
|
order.OrderItems[idx] = OrderItem{
|
|
ItemID: item.ItemID,
|
|
ItemType: item.ItemType,
|
|
Price: item.Price,
|
|
ItemName: item.ItemName,
|
|
Quantity: item.Quantity,
|
|
CreatedBy: i.CreatedBy,
|
|
CreatedAt: now,
|
|
Product: item.Product,
|
|
Notes: item.Notes,
|
|
}
|
|
}
|
|
|
|
return order
|
|
}
|