Quelle est la requete exacte de calcul HT des lignes de commandes Vinistoria ?
select ordnoorder, odlarrangement,ordeffectiveexpdate,ordnosocaux,ordnature,ordtypefiscalisation,ordtypetitre,ordnocustomer,
odlnoarticle,stotypefiscal,odlcodetypefiscal,odlquantityorder,odlvoleffectif,
case when ordmakeinvoice=0 then 0 else (Odlhtbaseprice - Odlorderdiscountht-Odlescompteht)+Coalesce(sum(Odptotalht),0) end as CAHT,
case when ordmakeinvoice=0 then 'NON' else 'OUI' end as Fact, invinvoicenumber,artspecies,cusname
from orders
inner join orderline on odlnoorder=ordnoorder
inner join article on artnoarticle=odlnoarticle
inner join customer on cusnocustomer=ordnocustomer
left outer join lotstock on stoidlotstock=odlnolotstock
left outer join invoice on invnoinvoice=ordinvoiced
left outer join orderlinepricedef on odpnoorder=odlnoorder and odpnoorderline=odlnoorderline and odpdatatype in (1,3,20,21,22) and odpcalcinbase=2
where (ordeffectiveexpdate>='01/01/2022' and ordeffectiveexpdate<'01/01/2023') and ordnosocaux in (1,11)
group by ordnoorder,odlarrangement,ordeffectiveexpdate,ordnosocaux,ordnature,ordtypefiscalisation,ordtypetitre,ordnocustomer,odlnoarticle,stotypefiscal,odlcodetypefiscal,odlquantityorder,odlvoleffectif,Odlhtbaseprice,Odlorderdiscountht,Odlescompteht,ordmakeinvoice,orddepottransfer,invinvoicenumber,artspecies, cusname
order by ordeffectiveexpdate,ordnoorder, odlarrangement