Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a737d7f83 | ||
|
|
312ea94e62 |
@@ -27,6 +27,7 @@ type OrderRepository interface {
|
|||||||
UpdatePaymentStatus(ctx context.Context, id uuid.UUID, status entities.PaymentStatus) error
|
UpdatePaymentStatus(ctx context.Context, id uuid.UUID, status entities.PaymentStatus) error
|
||||||
UpdateStatus(ctx context.Context, id uuid.UUID, status entities.OrderStatus) error
|
UpdateStatus(ctx context.Context, id uuid.UUID, status entities.OrderStatus) error
|
||||||
GetNextOrderNumber(ctx context.Context, organizationID, outletID uuid.UUID) (string, error)
|
GetNextOrderNumber(ctx context.Context, organizationID, outletID uuid.UUID) (string, error)
|
||||||
|
ListByOutletID(ctx context.Context, outletID uuid.UUID, limit, offset int) ([]*entities.Order, int64, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type OrderRepositoryImpl struct {
|
type OrderRepositoryImpl struct {
|
||||||
@@ -270,3 +271,27 @@ func (r *OrderRepositoryImpl) GetNextOrderNumber(ctx context.Context, organizati
|
|||||||
orderNumber := fmt.Sprintf("ORD/%04d%02d/%06d", year, month, sequence.SequenceNumber)
|
orderNumber := fmt.Sprintf("ORD/%04d%02d/%06d", year, month, sequence.SequenceNumber)
|
||||||
return orderNumber, nil
|
return orderNumber, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *OrderRepositoryImpl) ListByOutletID(ctx context.Context, outletID uuid.UUID, limit, offset int) ([]*entities.Order, int64, error) {
|
||||||
|
var orders []*entities.Order
|
||||||
|
var total int64
|
||||||
|
|
||||||
|
query := r.db.WithContext(ctx).Model(&entities.Order{}).
|
||||||
|
Preload("Organization").
|
||||||
|
Preload("Outlet").
|
||||||
|
Preload("User").
|
||||||
|
Preload("OrderItems").
|
||||||
|
Preload("OrderItems.Product").
|
||||||
|
Preload("OrderItems.ProductVariant").
|
||||||
|
Preload("Payments").
|
||||||
|
Preload("Payments.PaymentMethod").
|
||||||
|
Preload("Payments.PaymentOrderItems").
|
||||||
|
Where("outlet_id = ?", outletID)
|
||||||
|
|
||||||
|
if err := query.Count(&total).Error; err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err := query.Limit(limit).Offset(offset).Order("created_at DESC").Find(&orders).Error
|
||||||
|
return orders, total, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ func (r *OrganizationRepositoryImpl) GetTotalOmset(ctx context.Context, organiza
|
|||||||
var total float64
|
var total float64
|
||||||
err := r.db.WithContext(ctx).
|
err := r.db.WithContext(ctx).
|
||||||
Table("orders").
|
Table("orders").
|
||||||
Where("organization_id = ? AND payment_status = ?", organizationID, "completed").
|
Where("organization_id = ? AND payment_status = ? AND is_void = ? AND is_refund = ?", organizationID, "completed", false, false).
|
||||||
Select("COALESCE(SUM(total_amount), 0)").
|
Select("COALESCE(SUM(total_amount), 0)").
|
||||||
Scan(&total).Error
|
Scan(&total).Error
|
||||||
return total, err
|
return total, err
|
||||||
|
|||||||
Reference in New Issue
Block a user