mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 21:41:55 +00:00
feat/BE/US-76/US-78/US-79/TASK-112,120,133,121-Recording growing/TASK-187,189,202,190-Recording Laying/TASK-191,192,194,197,203-Grading Telur
This commit is contained in:
@@ -13,6 +13,7 @@ type StockLogRepository interface {
|
||||
GetByFlaggable(ctx context.Context, logType string, logId uint) ([]*entity.StockLog, error)
|
||||
GetByProductWarehouse(ctx context.Context, productWarehouseId uint, limit int) ([]*entity.StockLog, error)
|
||||
GetByTransactionType(ctx context.Context, transactionType string, limit int) ([]*entity.StockLog, error)
|
||||
ApplyProductWarehouseFilters(db *gorm.DB, productID, warehouseID uint) *gorm.DB
|
||||
}
|
||||
|
||||
type StockLogRepositoryImpl struct {
|
||||
@@ -86,3 +87,20 @@ func (r *StockLogRepositoryImpl) GetByTransactionType(ctx context.Context, trans
|
||||
|
||||
return stockLogs, nil
|
||||
}
|
||||
|
||||
func (r *StockLogRepositoryImpl) ApplyProductWarehouseFilters(db *gorm.DB, productID, warehouseID uint) *gorm.DB {
|
||||
if productID == 0 && warehouseID == 0 {
|
||||
return db
|
||||
}
|
||||
|
||||
db = db.Joins("JOIN product_warehouses ON product_warehouses.id = stock_logs.product_warehouse_id")
|
||||
|
||||
if productID > 0 {
|
||||
db = db.Where("product_warehouses.product_id = ?", productID)
|
||||
}
|
||||
if warehouseID > 0 {
|
||||
db = db.Where("product_warehouses.warehouse_id = ?", warehouseID)
|
||||
}
|
||||
|
||||
return db
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user