Šī vietne anonīmi izseko apmeklējumus, lai padarītu vietni draudzīgāku Jums. Aizveriet šo dialogu, lai apstiprinātu, ka esat apmierināts ar to, vai arī uzziniet vairāk Privātuma politika
SELECT tba.product_energy_class, tba.product_energy_plate, tba.product_energy_data, tba.productcode, tba.producttitle_lv, tba.productispublic, tbi.productimageurl, tba.productunitid, tbu.productunittitle_lv, tba.productbrandid, tba.productgroupid1, tba.productgroupid2, tba.productgroupid3, tba.relatedproductmode, tba.relatedproductarray, tbg1.fbformid_retail, tbg1.fbformid_dealer, tbb.productbrandtitle_lv, tbb.productbrandimage, tbpsd.productstatusdata, tbssp.productsupplierid, tbssp.pricesale, tbssp.pricesaleold, tbssp.main_stock as in_stock, tbssp.arrive_stock as stock_arrive, tbssp.arrive_date as stock_arrive_date, coalesce(tbis.stockvalue,0)-coalesce(tbis.stockorder,0) as info_stock_value, tbg1.maxstockvalue_retail, tbg1.maxstockvalue_dealer, 0 as amount_ordered, 0 as amount_incart, 0 as amount_wishlist, tba.vatrate_allow_special as p_vatrate_allow_special, tbvd.vatrateid as v_vatrateid, tbvd.vatrate_code as v_vatrate_code, tbvd.vatrate_allow_special as v_vatrate_allow_special, tbvd.vatrate_private as v_vatrate_private, tbvd.vatrate_company as v_vatrate_company, tbvd.vatrate_special as v_vatrate_special, 'N' as c_vatrate_allow_special, tbvr.vatrate_title_lv as vatrate_title, tbvr.vatrate_title_special_lv as vatrate_title_special, 0 as cl_i_stock, tba.productseourl, tba.productid FROM tbproducts tba INNER JOIN (SELECT DISTINCT ON (s2.productid) s2.productid, s2.productsupplierid, coalesce(s2.price_sale_spec, coalesce(s2.price_sale_std,0)) pricesale, coalesce(s2.price_sale_std,0) pricesaleold, s2.main_stock, s2.arrive_stock, s2.arrive_date, s2.info_stock_name, s2.productsupplierpriority, s2.have_stock, (CASE WHEN coalesce(s2.price_sale_std,0)>0 THEN 1 ELSE 0 END) as have_price FROM ( SELECT s1.productid, s1.productsupplierid, (SELECT CASE WHEN coalesce(tbcsp.clientpriceid,0)>0 THEN tbcsp.salesprice else tbx1.pricesale END pricesale FROM tbproductprices tbx1 LEFT OUTER JOIN tbclientprices tbcsp on tbx1.productid=tbcsp.productid and tbx1.productsupplierid=tbcsp.productsupplierid and tbcsp.clientid=0 WHERE tbx1.productid=s1.productid and tbx1.productsupplierid=s1.productsupplierid and tbx1.pricelistid=coalesce(s1.pricelistid,1) and (tbx1.pricesale>0 and tbx1.pricesale is not null)) price_sale_std, (SELECT CASE WHEN coalesce(tbcsp.clientpriceid,0)>0 THEN tbcsp.salesprice else tbx2.pricesale END pricesale FROM tbproductprices tbx2 LEFT OUTER JOIN tbclientprices tbcsp on tbx2.productid=tbcsp.productid and tbx2.productsupplierid=tbcsp.productsupplierid and tbcsp.clientid=0 WHERE tbx2.productid=s1.productid and tbx2.productsupplierid=s1.productsupplierid and tbx2.pricelistid=coalesce(tb_pl.pricelistspecid,1) and tbx2.pricevalidfrom<=localtimestamp and tbx2.pricevalidto>=localtimestamp and (tbx2.pricesale>0 and tbx2.pricesale is not null)) price_sale_spec, s1.main_stock, s1.arrive_stock, s1.arrive_date, s1.info_stock_name, s1.productsupplierpriority, (CASE WHEN s1.arrive_stock>0 THEN 1 ELSE 0 END) as have_stock FROM ( SELECT tb_pro.productid, tb_psl.productsupplierid, (SELECT DISTINCT on (tb_pro.productid) tbx.pricelistid FROM tbclientpricelists tbx WHERE ( (tbx.supplierarray like '%['|| tb_psl.productsupplierid ||']%' or tbx.supplierarray='*') and (tbx.grouparray like '%['|| tb_pro.productgroupid1 ||']%' or tbx.grouparray='*' ) and (tbx.brandarray like '%['|| tb_pro.productbrandid ||']%' or tbx.brandarray='*' )) and tbx.clientid=0 ORDER BY tb_pro.productid, tbx.priority) pricelistid, tb_sd.main_stock, tb_sd.arrive_stock, tb_sd.arrive_date, tb_sd.info_stock_name,tb_ps.productsupplierpriority FROM tbproducts tb_pro INNER JOIN tbproductsupplierlinks tb_psl on tb_pro.productid=tb_psl.productid and tb_psl.linkactive='Y' and tb_pro.productisarchived='N' and tb_pro.productispublic='Y' INNER JOIN (SELECT tbx1.productid, tbx1.productsupplierid, sum(coalesce(tbx3.stockvalue,0) - coalesce(tbx3.stockorder,0)) as main_stock, sum(coalesce(tbx3.stockvalue,0) + coalesce(tbx3.stockarrive,0) - coalesce(tbx3.stockorder,0)) as arrive_stock, max(tbx3.stockarrivedate) as arrive_date, min(coalesce(tbx2.stockinfo,'')) as info_stock_name FROM tbproductsupplierlinks tbx1 INNER JOIN tbclientsuppliers tbx2 on tbx2.clientid=0 and tbx1.productsupplierid=tbx2.productsupplierid and tbx2.supplierallowed='Y' LEFT OUTER JOIN tbproductstocks tbx3 on tbx1.productid=tbx3.productid and tbx1.productsupplierid=tbx3.productsupplierid and ((tbx2.stockarray like '%['|| tbx3.stockname ||']%' and tbx3.stockmode in ('N','V')) or tbx3.stockmode=tbx2.stockmode_v) and tbx3.productid in (75981,2023,3460,16014,43423,82654,41412,14447,58669,1728,7801,92004,56420,45673,76992,1882,8218,29968,830,58729,55980,14927,93002,85389,61644,64592,20338,82010,3933,49953,12125,53169,4893,61620,829,32104,9991,89035,44069,68616,41173,43176,4141,42955,67039,67642,45666,41238,65051,96112,65629,83288,72226,2299,52324,52325,5136,43015,14421,40271,81476,52296,4386,52328,30988,92724,92008,12518,70225,88468,77924,1712,41497,51208,70596,56595,40280,52323,45310,84366,22395,94097,29967,75693,28768,39064,59530,43,76415,67047,30731,147,2017,34095,34177,43353,95863,49898,59528,59517,2213,59519,75644,65710,65566,87282,46684,89799,38350,64593,94723,32471,56447,41433,35627,64536,48440,37015,30307,5135,37466,47395,72209,35,64035,40732,3836,25022,53587,2376,60926,39055,59548,59547,10001,47613,34197,350,4359,22118,96336,970,18023,31141,4684,42820,88428,59193,13058,76412,88364,52297,83934,90670,59558,52301,45702,5515,67015,94398,30387,42739,85841,25024,40334,35589,81575,40726,53244,119,44784,95158,42738,65595,57637,55798,47870,52326,87980,20886,92729,96115,62206,59953,43640,69869,88427,52358,37018,71509,45674,47417,67046,46689,68716,96241,20906,91103,88017,47871,70303,82213,34162,75550,59573,56775,767,59575,14450,5042,12488,97893,71010,66334,59576,17369,20894,4469,55927,52354,5029,32114,17370,28972,91017,43386,93994) WHERE tbx1.linkactive='Y' and tbx1.productid in (75981,2023,3460,16014,43423,82654,41412,14447,58669,1728,7801,92004,56420,45673,76992,1882,8218,29968,830,58729,55980,14927,93002,85389,61644,64592,20338,82010,3933,49953,12125,53169,4893,61620,829,32104,9991,89035,44069,68616,41173,43176,4141,42955,67039,67642,45666,41238,65051,96112,65629,83288,72226,2299,52324,52325,5136,43015,14421,40271,81476,52296,4386,52328,30988,92724,92008,12518,70225,88468,77924,1712,41497,51208,70596,56595,40280,52323,45310,84366,22395,94097,29967,75693,28768,39064,59530,43,76415,67047,30731,147,2017,34095,34177,43353,95863,49898,59528,59517,2213,59519,75644,65710,65566,87282,46684,89799,38350,64593,94723,32471,56447,41433,35627,64536,48440,37015,30307,5135,37466,47395,72209,35,64035,40732,3836,25022,53587,2376,60926,39055,59548,59547,10001,47613,34197,350,4359,22118,96336,970,18023,31141,4684,42820,88428,59193,13058,76412,88364,52297,83934,90670,59558,52301,45702,5515,67015,94398,30387,42739,85841,25024,40334,35589,81575,40726,53244,119,44784,95158,42738,65595,57637,55798,47870,52326,87980,20886,92729,96115,62206,59953,43640,69869,88427,52358,37018,71509,45674,47417,67046,46689,68716,96241,20906,91103,88017,47871,70303,82213,34162,75550,59573,56775,767,59575,14450,5042,12488,97893,71010,66334,59576,17369,20894,4469,55927,52354,5029,32114,17370,28972,91017,43386,93994) GROUP BY tbx1.productid, tbx1.productsupplierid) tb_sd on tb_pro.productid=tb_sd.productid and tb_psl.productsupplierid=tb_sd.productsupplierid INNER JOIN tbproductsuppliers tb_ps on tb_psl.productsupplierid=tb_ps.productsupplierid and tb_ps.productsupplierispublic='Y' WHERE tb_pro.productisarchived='N' and tb_pro.productispublic='Y' ) s1 LEFT OUTER JOIN tbpricelists tb_pl on coalesce(s1.pricelistid,1)=tb_pl.pricelistid ) s2 ORDER BY s2.productid, have_price DESC, s2.have_stock DESC,s2.productsupplierpriority, coalesce(s2.price_sale_spec, coalesce(s2.price_sale_std,0))) tbssp on tba.productid=tbssp.productid and tbssp.pricesale>0 LEFT OUTER JOIN tbproductstocks tbis on tba.productid=tbis.productid and tbis.stockname=tbssp.info_stock_name INNER JOIN (SELECT tb_v.vatrateid, tb_v.countryid, tb_v.vatrate_code, tb_v.vatrate_private, tb_v.vatrate_company, tb_v.vatrate_special, tb_v.vatrate_allow_special FROM tbvatrates tb_v INNER JOIN (SELECT DISTINCT c1.countryid, c1.vatrate_code, (SELECT vatrateid FROM tbvatrates WHERE countryid=c1.countryid and vatrate_code=c1.vatrate_code and vatrate_validfrom<=localtimestamp ORDER BY vatrate_validfrom DESC LIMIT 1) as vatrateid FROM tbvatrates c1) tb_vd on tb_v.vatrateid=tb_vd.vatrateid WHERE tb_v.vatrateid>0) tbvd on tba.vatrate_code=tbvd.vatrate_code and tbvd.countryid=1 INNER JOIN tbvatrates tbvr on tbvd.vatrateid=tbvr.vatrateid INNER JOIN tbproductgroups tbg1 on tba.productgroupid1=tbg1.productgroupid LEFT OUTER JOIN tbproductgroups tbg2 on tba.productgroupid2=tbg2.productgroupid LEFT OUTER JOIN tbproductgroups tbg3 on tba.productgroupid3=tbg3.productgroupid INNER JOIN tbproductunits tbu on tba.productunitid=tbu.productunitid INNER JOIN tbproductbrands tbb on tba.productbrandid=tbb.productbrandid LEFT OUTER JOIN tbproductimages tbi on tba.productid=tbi.productid and tbi.productimageindex=1, get_product_status_data_array(tba.productid,'RETAIL') tbpsd WHERE tba.productisarchived='N' and tba.productispublic='Y' and ( (tba.productgroupid1>0 and tbg1.productgroupispublic='Y') or (tba.productgroupid2>0 and tbg2.productgroupispublic='Y') or (tba.productgroupid3>0 and tbg3.productgroupispublic='Y') ) and tba.productid in (75981,2023,3460,16014,43423,82654,41412,14447,58669,1728,7801,92004,56420,45673,76992,1882,8218,29968,830,58729,55980,14927,93002,85389,61644,64592,20338,82010,3933,49953,12125,53169,4893,61620,829,32104,9991,89035,44069,68616,41173,43176,4141,42955,67039,67642,45666,41238,65051,96112,65629,83288,72226,2299,52324,52325,5136,43015,14421,40271,81476,52296,4386,52328,30988,92724,92008,12518,70225,88468,77924,1712,41497,51208,70596,56595,40280,52323,45310,84366,22395,94097,29967,75693,28768,39064,59530,43,76415,67047,30731,147,2017,34095,34177,43353,95863,49898,59528,59517,2213,59519,75644,65710,65566,87282,46684,89799,38350,64593,94723,32471,56447,41433,35627,64536,48440,37015,30307,5135,37466,47395,72209,35,64035,40732,3836,25022,53587,2376,60926,39055,59548,59547,10001,47613,34197,350,4359,22118,96336,970,18023,31141,4684,42820,88428,59193,13058,76412,88364,52297,83934,90670,59558,52301,45702,5515,67015,94398,30387,42739,85841,25024,40334,35589,81575,40726,53244,119,44784,95158,42738,65595,57637,55798,47870,52326,87980,20886,92729,96115,62206,59953,43640,69869,88427,52358,37018,71509,45674,47417,67046,46689,68716,96241,20906,91103,88017,47871,70303,82213,34162,75550,59573,56775,767,59575,14450,5042,12488,97893,71010,66334,59576,17369,20894,4469,55927,52354,5029,32114,17370,28972,91017,43386,93994) ORDER BY sign(greatest(coalesce(tbssp.main_stock,0),0)) DESC, sign(greatest(coalesce(tbssp.arrive_stock,0),0)) DESC, case when tba.productbrandid in (729, 736) then 1 else 2 end, tbssp.productsupplierid ASC, coalesce(tba.rating_retail_value,0) DESC, tba.productcode session:N xa:4