Quantcast
Channel: SCN: Message List - Reporting and Printing
Viewing all articles
Browse latest Browse all 2719

Sales Order Query

$
0
0

Hi,

 

I need a query or a way to get/compute a fee based on the following condition:

 

If ORDR.DocStatus='O' then Fee:= ORDR.DOCTOTAL

else

     if ODLN.DocStatues ='O' then Fee:= ORDR.DOCTOTAL

     else

          if OINV.DocTotal='O' then Fee:=Sum(OINV.DocTotal)

          else ORCT.SumApplied

 

complication: multiple A/R invoice

     example

          3 invoices, the 1st invoice has been paid then

     ORCT.SumApplied(1st Invoice) + 2nd Invoice DocTotal + 3rd Invoice DocTotal

 

currently, I have this query and I don't know how to compute based on above conditions

any help would be greatly appreciated.

 

select

    a.DocEntry,

    a.DocNum,

    a.DocDate,

     b.LineNum as SOLineNum,

    b.TrgetEntry as SOTrgetDoc,

    b.TargetType as SOTargetType,

    isnull((b.Quantity * b.PriceAfVAT),0) as SOPrice,

    c.LineNum as DNLineNum,

    c.TrgetEntry as DNTrgetDoc,

    c.TargetType as DNTargetType,

    isnull((c.Quantity * c.PriceAfVAT),0) as DNPrice,

    d.LineNum as InvLineNum,

    d.TrgetEntry as InvTrgetDoc,

    d.TargetType as InvTargetType,

    d.Quantity * d.PriceAfVAT as InvPrice,

    isnull((e.SumApplied + e.WtAppld),0) as PaidAmt

      

    from ORDR a

    left join RDR1 b on a.DocEntry=b.DocEntry

    left join DLN1 c on b.TrgetEntry=c.DocEntry and b.LineNum=c.BaseLine

    left join INV1 d on c.TrgetEntry=d.DocEntry and c.LineNum=d.BaseLine

    left join RCT2 e on d.DocEntry=e.DocEntry


Viewing all articles
Browse latest Browse all 2719

Trending Articles