fix filter purchase supplier repport

This commit is contained in:
ragilap
2026-04-02 11:43:44 +07:00
parent 434ae2f246
commit 8be4b54127
6 changed files with 303 additions and 53 deletions
@@ -60,24 +60,24 @@ func (r *purchaseSupplierRepositoryImpl) baseSupplierQuery(ctx context.Context,
Where("(la.action IS NULL OR la.action != ?)", string(entity.ApprovalActionRejected)).
Where("purchase_items.received_date IS NOT NULL")
if filters.SupplierId > 0 {
db = db.Where("suppliers.id = ?", filters.SupplierId)
if len(filters.SupplierIDs) > 0 {
db = db.Where("suppliers.id IN ?", filters.SupplierIDs)
}
if filters.ProductId > 0 {
db = db.Where("purchase_items.product_id = ?", filters.ProductId)
if len(filters.ProductIDs) > 0 {
db = db.Where("purchase_items.product_id IN ?", filters.ProductIDs)
}
if filters.ProductCategoryId > 0 {
if len(filters.ProductCategoryIDs) > 0 {
db = db.
Joins("JOIN products ON products.id = purchase_items.product_id").
Where("products.product_category_id = ?", filters.ProductCategoryId)
Where("products.product_category_id IN ?", filters.ProductCategoryIDs)
}
if filters.AreaId > 0 || filters.AllowedAreaIDs != nil {
if len(filters.AreaIDs) > 0 || filters.AllowedAreaIDs != nil {
db = db.Joins("JOIN warehouses ON warehouses.id = purchase_items.warehouse_id")
if filters.AreaId > 0 {
db = db.Where("warehouses.area_id = ?", filters.AreaId)
if len(filters.AreaIDs) > 0 {
db = db.Where("warehouses.area_id IN ?", filters.AreaIDs)
}
if filters.AllowedAreaIDs != nil {
if len(filters.AllowedAreaIDs) == 0 {
@@ -187,20 +187,19 @@ func (r *purchaseSupplierRepositoryImpl) GetItemsBySuppliers(ctx context.Context
Where("(la.action IS NULL OR la.action != ?)", string(entity.ApprovalActionRejected)).
Where("purchase_items.received_date IS NOT NULL")
if filters.ProductId > 0 {
db = db.Where("purchase_items.product_id = ?", filters.ProductId)
if len(filters.ProductIDs) > 0 {
db = db.Where("purchase_items.product_id IN ?", filters.ProductIDs)
}
if filters.ProductCategoryId > 0 {
if len(filters.ProductCategoryIDs) > 0 {
db = db.
Joins("JOIN products ON products.id = purchase_items.product_id").
Where("products.product_category_id = ?", filters.ProductCategoryId)
Where("products.product_category_id IN ?", filters.ProductCategoryIDs)
}
if filters.AreaId > 0 || filters.AllowedAreaIDs != nil {
if len(filters.AreaIDs) > 0 || filters.AllowedAreaIDs != nil {
db = db.Joins("JOIN warehouses ON warehouses.id = purchase_items.warehouse_id")
if filters.AreaId > 0 {
db = db.Where("warehouses.area_id = ?", filters.AreaId)
if len(filters.AreaIDs) > 0 {
db = db.Where("warehouses.area_id IN ?", filters.AreaIDs)
}
if filters.AllowedAreaIDs != nil {
if len(filters.AllowedAreaIDs) == 0 {