Add Print Detail
This commit is contained in:
@@ -21,6 +21,7 @@ func (h *Handler) Route(group *gin.RouterGroup, jwt gin.HandlerFunc) {
|
||||
route := group.Group("/order")
|
||||
|
||||
route.POST("/inquiry", jwt, h.Inquiry)
|
||||
route.GET("/print-detail", jwt, h.PrintDetail)
|
||||
route.POST("/execute", jwt, h.Execute)
|
||||
route.GET("/history", jwt, h.GetAllHistoryOrders)
|
||||
route.GET("/ticket-sold", jwt, h.CountSoldOfTicket)
|
||||
@@ -73,6 +74,28 @@ func (h *Handler) Inquiry(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) PrintDetail(c *gin.Context) {
|
||||
ctx := request.GetMyContext(c)
|
||||
|
||||
var req request.OrderPrintDetail
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
order, err := h.service.GetPrintDetail(ctx, req.ID)
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response.BaseResponse{
|
||||
Success: true,
|
||||
Status: http.StatusOK,
|
||||
Data: MapOrderToPrintDetailResponse(order, ctx.GetName()),
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) Execute(c *gin.Context) {
|
||||
ctx := request.GetMyContext(c)
|
||||
|
||||
@@ -418,3 +441,30 @@ func (h *Handler) toPaymentDistributionChart(resp []entity.PaymentTypeDistributi
|
||||
}
|
||||
return dailySales
|
||||
}
|
||||
|
||||
func MapOrderToPrintDetailResponse(order *entity.OrderPrintDetail, casherName string) response.PrintDetailResponse {
|
||||
orderItems := make([]response.CreateOrderItemResponse, len(order.OrderItems))
|
||||
for i, item := range order.OrderItems {
|
||||
orderItems[i] = response.CreateOrderItemResponse{
|
||||
ID: item.ID,
|
||||
ItemID: item.ItemID,
|
||||
Quantity: item.Quantity,
|
||||
Price: item.Price,
|
||||
Name: item.Product.Name,
|
||||
}
|
||||
}
|
||||
|
||||
return response.PrintDetailResponse{
|
||||
ID: order.ID,
|
||||
OrderID: order.OrderID,
|
||||
Total: order.Total,
|
||||
Fee: order.Fee,
|
||||
PaymentType: order.PaymentType,
|
||||
Source: order.Source,
|
||||
VisitDateAt: order.VisitDate.Format("2006-01-02"),
|
||||
VisitTime: time.Now().Format("15:04:05"),
|
||||
OrderItems: orderItems,
|
||||
CasheerName: casherName,
|
||||
PartnerName: order.PartnerName,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,3 +133,7 @@ func (o *OrderParamCustomer) ToOrderEntity(ctx mycontext.Context) entity.OrderSe
|
||||
IsCustomer: true,
|
||||
}
|
||||
}
|
||||
|
||||
type OrderPrintDetail struct {
|
||||
ID int64 `form:"id" json:"id" example:"10"`
|
||||
}
|
||||
|
||||
@@ -96,6 +96,20 @@ type CreateOrderResponse struct {
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
type PrintDetailResponse struct {
|
||||
ID int64 `json:"id"`
|
||||
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"`
|
||||
RefID string `json:"ref_id"`
|
||||
|
||||
Reference in New Issue
Block a user