Add Print Detail
This commit is contained in:
parent
ddc2c4b4f4
commit
0ebeb73f76
@ -18,6 +18,7 @@ type Context interface {
|
||||
IsCasheer() bool
|
||||
GetPartnerID() *int64
|
||||
GetSiteID() *int64
|
||||
GetName() string
|
||||
}
|
||||
|
||||
type MyContextImpl struct {
|
||||
@ -28,6 +29,7 @@ type MyContextImpl struct {
|
||||
partnerID int64
|
||||
roleID int
|
||||
siteID int64
|
||||
name string
|
||||
}
|
||||
|
||||
func (m *MyContextImpl) RequestedBy() int64 {
|
||||
@ -64,6 +66,10 @@ func (m *MyContextImpl) GetSiteID() *int64 {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MyContextImpl) GetName() string {
|
||||
return m.name
|
||||
}
|
||||
|
||||
func NewMyContext(parent context.Context, claims *entity.JWTAuthClaims) (*MyContextImpl, error) {
|
||||
return &MyContextImpl{
|
||||
Context: parent,
|
||||
@ -71,6 +77,7 @@ func NewMyContext(parent context.Context, claims *entity.JWTAuthClaims) (*MyCont
|
||||
partnerID: claims.PartnerID,
|
||||
roleID: claims.Role,
|
||||
siteID: claims.SiteID,
|
||||
name: claims.Name,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@ -224,3 +224,16 @@ type PaymentTypeDistribution struct {
|
||||
PaymentType string
|
||||
Count int
|
||||
}
|
||||
|
||||
type OrderPrintDetail struct {
|
||||
ID int64 `gorm:"column:id"`
|
||||
PartnerName string `gorm:"column:partner_name"`
|
||||
OrderID string `gorm:"column:order_id"`
|
||||
VisitDate time.Time `gorm:"column:visit_date"`
|
||||
PaymentType string `gorm:"column:payment_type"`
|
||||
OrderItems []OrderItem `gorm:"foreignKey:OrderID;constraint:OnDelete:CASCADE;"`
|
||||
Source string `gorm:"column:source"`
|
||||
TicketStatus string `gorm:"column:ticket_status"`
|
||||
Total float64 `gorm:"column:total"`
|
||||
Fee float64 `gorm:"column:fee"`
|
||||
}
|
||||
|
||||
@ -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"`
|
||||
|
||||
@ -64,6 +64,30 @@ func (r *OrderRepository) FindByID(ctx context.Context, id int64) (*entity.Order
|
||||
return &order, nil
|
||||
}
|
||||
|
||||
func (r *OrderRepository) FindPrintDetailByID(ctx context.Context, id int64) (*entity.OrderPrintDetail, error) {
|
||||
var printDetail entity.OrderPrintDetail
|
||||
|
||||
err := r.db.WithContext(ctx).
|
||||
Table("orders").
|
||||
Select("orders.id, partners.name as partner_name, orders.ref_id as order_id, "+
|
||||
"orders.visit_date, orders.payment_type, orders.source, "+
|
||||
"orders.ticket_status, orders.total, orders.fee").
|
||||
Joins("JOIN partners ON partners.id = orders.partner_id").
|
||||
Where("orders.id = ?", id).
|
||||
Scan(&printDetail).Error
|
||||
|
||||
if err == nil {
|
||||
err = r.db.WithContext(ctx).Where("order_id = ?", id).Preload("Product").Find(&printDetail.OrderItems).Error
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
logger.ContextLogger(ctx).Error("error when finding print detail by ID", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &printDetail, nil
|
||||
}
|
||||
|
||||
func (r *OrderRepository) FindByQRCode(ctx context.Context, refID string) (*entity.Order, error) {
|
||||
var order entity.Order
|
||||
|
||||
|
||||
@ -142,6 +142,7 @@ type Product interface {
|
||||
type Order interface {
|
||||
Create(ctx context.Context, order *entity.Order) (*entity.Order, error)
|
||||
FindByID(ctx context.Context, id int64) (*entity.Order, error)
|
||||
FindPrintDetailByID(ctx context.Context, id int64) (*entity.OrderPrintDetail, error)
|
||||
FindByQRCode(ctx context.Context, refID string) (*entity.Order, error)
|
||||
Update(ctx context.Context, order *entity.Order) (*entity.Order, error)
|
||||
SetOrderStatus(ctx context.Context, db *gorm.DB, orderID int64, status string) error
|
||||
|
||||
@ -540,3 +540,13 @@ func (s *OrderService) GetByID(ctx mycontext.Context, id int64, referenceID stri
|
||||
|
||||
return order, nil
|
||||
}
|
||||
|
||||
func (s *OrderService) GetPrintDetail(ctx mycontext.Context, id int64) (*entity.OrderPrintDetail, error) {
|
||||
order, err := s.repo.FindPrintDetailByID(ctx, id)
|
||||
if err != nil {
|
||||
logger.ContextLogger(ctx).Error("error when getting products by IDs", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return order, nil
|
||||
}
|
||||
|
||||
@ -124,6 +124,7 @@ type Order interface {
|
||||
GetDailySales(ctx mycontext.Context, req entity.OrderSearch) ([]entity.ProductDailySales, error)
|
||||
GetPaymentDistribution(ctx mycontext.Context, req entity.OrderSearch) ([]entity.PaymentTypeDistribution, error)
|
||||
GetByID(ctx mycontext.Context, id int64, referenceID string) (*entity.Order, error)
|
||||
GetPrintDetail(ctx mycontext.Context, id int64) (*entity.OrderPrintDetail, error)
|
||||
}
|
||||
|
||||
type OSSService interface {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user