SELECT
material.OfferPos,
material.CODE,
New,
Best,
FreeSend,
Eukairia,
ShopOnly,BARCODE,
Mini_DescrLANG,
WHSPRICE,RTLPRICE, StockHouse,
material.Timh_x_katast,
Timh_l_katast,
material.TitleLANG,
material_category.CT1,
material_category.CT2,
material_category.CT3,
material_category.CT4,
material.DescrLANG,
material_color.COLORGROUP as Color,
Offer,
OfferPrice,
OfferDate,
OfferDateTo,
VAT_ID,
material.Active,Synthesi,mainszlid,material.ID,material.Availability,material.FileName,DATE_FORMAT(material.AvailExpected,'%d/%m/%Y') as _AvailExpected,
(select TitleLANG from manufacture where manufacture.Active=1 and manufacture.ManufID=material.ManufacturerID) as Manufacture,
(select TitleLANG from marka where marka.Active=1 and marka.MarkID=material.MarkaID) as Marka,
material.QTY,RESERVED,AvailExpected
FROM material
inner join material_category on material_category.MaterialID=material.ID
left join material_filterXM on material_filterXM.MaterialID = material.ID
left join material_color on material_color.ID = material.ID
WHERE material.Active=1 and FilterID4= '1' and ((OfferPrice!=0 and Offer=1 and OfferDate='0000-00-00' and OfferDateTo='0000-00-00') or (OfferPrice!=0 and Offer=1 and OfferDate='2026-06-05' ) or (OfferPrice!=0 and Offer=1 and '2026-06-05' BETWEEN OfferDate and OfferDateTo)) AND material.FilterID3 IN ('1') group by material.ID ORDER BY OfferPos desc