feat: filter order history
This commit is contained in:
parent
2fd676ef3e
commit
b1c1c0260b
BIN
internal/.DS_Store
vendored
Normal file
BIN
internal/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
internal/common/.DS_Store
vendored
Normal file
BIN
internal/common/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
internal/constants/.DS_Store
vendored
Normal file
BIN
internal/constants/.DS_Store
vendored
Normal file
Binary file not shown.
@ -117,6 +117,9 @@ type HistoryOrder struct {
|
|||||||
PaymentType string `gorm:"type:varchar;column:payment_type"`
|
PaymentType string `gorm:"type:varchar;column:payment_type"`
|
||||||
Status string `gorm:"type:varchar;column:status"`
|
Status string `gorm:"type:varchar;column:status"`
|
||||||
Amount float64 `gorm:"type:numeric;column:amount"`
|
Amount float64 `gorm:"type:numeric;column:amount"`
|
||||||
|
VisitDate time.Time `gorm:"type:date;column:visit_date"`
|
||||||
|
TicketStatus string `gorm:"type:varchar;column:ticket_status"`
|
||||||
|
Source string `gorm:"type:numeric;column:source"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type HistoryOrderDB struct {
|
type HistoryOrderDB struct {
|
||||||
@ -136,6 +139,7 @@ type OrderSearch struct {
|
|||||||
EndDate string
|
EndDate string
|
||||||
Period string
|
Period string
|
||||||
IsCustomer bool
|
IsCustomer bool
|
||||||
|
Source string
|
||||||
}
|
}
|
||||||
|
|
||||||
type HistoryOrderList []*HistoryOrderDB
|
type HistoryOrderList []*HistoryOrderDB
|
||||||
@ -158,6 +162,9 @@ func (e *HistoryOrderDB) ToHistoryOrder() *HistoryOrder {
|
|||||||
PaymentType: e.PaymentType,
|
PaymentType: e.PaymentType,
|
||||||
Status: e.Status,
|
Status: e.Status,
|
||||||
Amount: e.Amount,
|
Amount: e.Amount,
|
||||||
|
VisitDate: e.VisitDate,
|
||||||
|
TicketStatus: e.TicketStatus,
|
||||||
|
Source: e.Source,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
BIN
internal/handlers/.DS_Store
vendored
Normal file
BIN
internal/handlers/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
internal/handlers/http/.DS_Store
vendored
Normal file
BIN
internal/handlers/http/.DS_Store
vendored
Normal file
Binary file not shown.
@ -173,6 +173,9 @@ func (h *Handler) toHistoryOrderResponse(resp *entity.HistoryOrder) response.His
|
|||||||
PaymentType: resp.PaymentType,
|
PaymentType: resp.PaymentType,
|
||||||
Status: resp.Status,
|
Status: resp.Status,
|
||||||
Amount: resp.Amount,
|
Amount: resp.Amount,
|
||||||
|
VisitDate: resp.VisitDate.Format(time.RFC3339),
|
||||||
|
TicketStatus: resp.TicketStatus,
|
||||||
|
Source: resp.Source,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -44,6 +44,7 @@ type OrderParam struct {
|
|||||||
Limit int `form:"limit" json:"limit" example:"10"`
|
Limit int `form:"limit" json:"limit" example:"10"`
|
||||||
Offset int `form:"offset" json:"offset" example:"0"`
|
Offset int `form:"offset" json:"offset" example:"0"`
|
||||||
Period string `form:"period" json:"period" example:"1d,7d,1m"`
|
Period string `form:"period" json:"period" example:"1d,7d,1m"`
|
||||||
|
Source string `form:"source" json:"source" example:"tes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OrderParam) ToOrderEntity(ctx mycontext.Context) entity.OrderSearch {
|
func (o *OrderParam) ToOrderEntity(ctx mycontext.Context) entity.OrderSearch {
|
||||||
@ -58,6 +59,7 @@ func (o *OrderParam) ToOrderEntity(ctx mycontext.Context) entity.OrderSearch {
|
|||||||
EndDate: o.EndDate,
|
EndDate: o.EndDate,
|
||||||
Status: o.Status,
|
Status: o.Status,
|
||||||
Period: o.Period,
|
Period: o.Period,
|
||||||
|
Source: o.Source,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -35,6 +35,9 @@ type HistoryOrder struct {
|
|||||||
PaymentType string `json:"payment_type"`
|
PaymentType string `json:"payment_type"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Amount float64 `json:"amount"`
|
Amount float64 `json:"amount"`
|
||||||
|
VisitDate string `json:"visit_date"`
|
||||||
|
TicketStatus string `json:"ticket_status"`
|
||||||
|
Source string `json:"source"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OrderItem struct {
|
type OrderItem struct {
|
||||||
|
|||||||
BIN
internal/repository/.DS_Store
vendored
Normal file
BIN
internal/repository/.DS_Store
vendored
Normal file
Binary file not shown.
@ -94,10 +94,11 @@ func (b *OrderRepository) GetAllHystoryOrders(ctx context.Context, req entity.Or
|
|||||||
var total int64
|
var total int64
|
||||||
|
|
||||||
query := b.db.Table("orders").
|
query := b.db.Table("orders").
|
||||||
Select("orders.id as id, users.name as employee, sites.name as site, orders.created_at as timestamp, orders.created_at as booking_time, STRING_AGG(ticket_summary.name || ' x' || ticket_summary.total_qty, ', ') AS tickets, orders.payment_type as payment_type, orders.status as status, orders.amount as amount").
|
Select("orders.id as id, users.name as employee, sites.name as site, orders.created_at as timestamp, orders.created_at as booking_time, STRING_AGG(ticket_summary.name || ' x' || ticket_summary.total_qty, ', ') AS tickets, orders.payment_type as payment_type, orders.status as status, orders.amount as amount, orders.visit_date as visit_date, orders.ticket_status as ticket_status, orders.source as source").
|
||||||
Joins("left join (SELECT items.order_id, products.name, SUM(items.qty) AS total_qty FROM order_items items LEFT JOIN products ON items.item_id = products.id GROUP BY items.order_id, products.name) AS ticket_summary ON orders.id = ticket_summary.order_id").
|
Joins("left join (SELECT items.order_id, products.name, SUM(items.qty) AS total_qty FROM order_items items LEFT JOIN products ON items.item_id = products.id GROUP BY items.order_id, products.name) AS ticket_summary ON orders.id = ticket_summary.order_id").
|
||||||
Joins("left join users on orders.created_by = users.id").
|
Joins("left join users on orders.created_by = users.id").
|
||||||
Joins("left join sites on orders.site_id = sites.id")
|
Joins("left join sites on orders.site_id = sites.id").
|
||||||
|
Where("orders.status != ?", "NEW")
|
||||||
|
|
||||||
if req.PaymentType != "" {
|
if req.PaymentType != "" {
|
||||||
query = query.Where("orders.payment_type = ?", req.PaymentType)
|
query = query.Where("orders.payment_type = ?", req.PaymentType)
|
||||||
@ -131,6 +132,10 @@ func (b *OrderRepository) GetAllHystoryOrders(ctx context.Context, req entity.Or
|
|||||||
query = query.Where("orders.site_id = ?", req.SiteID)
|
query = query.Where("orders.site_id = ?", req.SiteID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if req.Source != "" {
|
||||||
|
query = query.Where("orders.source = ?", req.Source)
|
||||||
|
}
|
||||||
|
|
||||||
query = query.Group("orders.id, users.name, sites.name, orders.created_at, orders.payment_type, orders.status")
|
query = query.Group("orders.id, users.name, sites.name, orders.created_at, orders.payment_type, orders.status")
|
||||||
|
|
||||||
query = query.Order("orders.created_at DESC")
|
query = query.Order("orders.created_at DESC")
|
||||||
|
|||||||
BIN
internal/services/.DS_Store
vendored
Normal file
BIN
internal/services/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
internal/utils/.DS_Store
vendored
Normal file
BIN
internal/utils/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
k8s/.DS_Store
vendored
Normal file
BIN
k8s/.DS_Store
vendored
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user