mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 05:21:57 +00:00
FIX[BE]: Fixing filter area and location
This commit is contained in:
@@ -140,7 +140,7 @@ func (r *MarketingDeliveryProductRepositoryImpl) GetAllWithFilters(ctx context.C
|
||||
Joins("JOIN marketings ON marketings.id = marketing_products.marketing_id").
|
||||
Where("marketing_delivery_products.delivery_date IS NOT NULL")
|
||||
|
||||
if filters.ProductId > 0 || filters.WarehouseId > 0 || filters.Search != "" || filters.MarketingType != "" {
|
||||
if filters.ProductId > 0 || filters.WarehouseId > 0 || filters.AreaId > 0 || filters.LocationId > 0 || filters.Search != "" || filters.MarketingType != "" {
|
||||
db = db.Joins("LEFT JOIN product_warehouses ON product_warehouses.id = marketing_products.product_warehouse_id")
|
||||
}
|
||||
|
||||
@@ -178,6 +178,19 @@ func (r *MarketingDeliveryProductRepositoryImpl) GetAllWithFilters(ctx context.C
|
||||
db = db.Where("product_warehouses.warehouse_id = ?", filters.WarehouseId)
|
||||
}
|
||||
|
||||
if filters.AreaId > 0 || filters.LocationId > 0 {
|
||||
db = db.Joins("LEFT JOIN project_flock_kandangs ON project_flock_kandangs.id = product_warehouses.project_flock_kandang_id").
|
||||
Joins("LEFT JOIN project_flocks ON project_flocks.id = project_flock_kandangs.project_flock_id")
|
||||
|
||||
if filters.AreaId > 0 {
|
||||
db = db.Where("project_flocks.area_id = ?", filters.AreaId)
|
||||
}
|
||||
|
||||
if filters.LocationId > 0 {
|
||||
db = db.Where("project_flocks.location_id = ?", filters.LocationId)
|
||||
}
|
||||
}
|
||||
|
||||
if filters.MarketingType != "" {
|
||||
db = db.Joins("LEFT JOIN flags ON flags.flagable_id = products.id AND flags.flagable_type = 'products'").
|
||||
Group("marketing_delivery_products.id")
|
||||
@@ -186,7 +199,6 @@ func (r *MarketingDeliveryProductRepositoryImpl) GetAllWithFilters(ctx context.C
|
||||
case "ayam":
|
||||
db = db.Where("flags.name IN (?)", []string{
|
||||
string(utils.FlagDOC), string(utils.FlagPullet), string(utils.FlagLayer),
|
||||
string(utils.FlagAyamAfkir), string(utils.FlagAyamCulling), string(utils.FlagAyamMati),
|
||||
})
|
||||
case "telur":
|
||||
db = db.Where("flags.name IN (?)", []string{
|
||||
|
||||
@@ -82,6 +82,8 @@ func (c *RepportController) GetMarketing(ctx *fiber.Ctx) error {
|
||||
ProductId: int64(ctx.QueryInt("product_id", 0)),
|
||||
WarehouseId: int64(ctx.QueryInt("warehouse_id", 0)),
|
||||
SalesPersonId: int64(ctx.QueryInt("sales_person_id", 0)),
|
||||
AreaId: int64(ctx.QueryInt("area_id", 0)),
|
||||
LocationId: int64(ctx.QueryInt("location_id", 0)),
|
||||
MarketingType: ctx.Query("marketing_type", ""),
|
||||
FilterBy: ctx.Query("filter_by", ""),
|
||||
StartDate: ctx.Query("start_date", ""),
|
||||
|
||||
@@ -23,6 +23,8 @@ type MarketingQuery struct {
|
||||
ProductId int64 `query:"product_id" validate:"omitempty"`
|
||||
WarehouseId int64 `query:"warehouse_id" validate:"omitempty"`
|
||||
SalesPersonId int64 `query:"sales_person_id" validate:"omitempty"`
|
||||
AreaId int64 `query:"area_id" validate:"omitempty"`
|
||||
LocationId int64 `query:"location_id" validate:"omitempty"`
|
||||
MarketingType string `query:"marketing_type" validate:"omitempty,oneof=ayam telur trading"`
|
||||
FilterBy string `query:"filter_by" validate:"omitempty,oneof=so_date realization_date"`
|
||||
StartDate string `query:"start_date" validate:"omitempty,datetime=2006-01-02"`
|
||||
|
||||
Reference in New Issue
Block a user