Skip to Content

Query to show BP year to date sales minus credits

Hi Experts,

I would like a query which will show me a single line for each BP:

BP Code, Salesperson, BP Name, Sales Group, Sales YTD (ex vat)

I want the Sales YTD to be be calculated as total invoiced sales less any credits,

Thanks in advance for any help..

regards

Geoff

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Sep 06, 2011 at 11:34 AM

    Hi Geoff,

    Try:

    SELECT T0.CardCode, T0.CardName, T3.SlpName, Sum(IsNull(T2.LineTotal,0)) 'YTD Total'
    FROM OCRD T0
    Left JOIN OINV T1 ON T0.CardCode = T1.CardCode 
    Left JOIN INV1 T2 ON T1.DocEntry = T2.DocEntry
    Left JOIN OSLP T3 ON T0.SlpCode = T3.SlpCode
    WHERE T0.CardType ='C' and  T2.TargetType != 14 
    And DateDiff(YY,T1.DocDate,GetDate()) = 0
    GROUP BY T0.CardCode, T0.CardName, T3.SlpName
    HAVING Sum(IsNull(T2.LineTotal,0))>0

    Please clarify what the sales group is in your context.

    Thanks,

    Gordon

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 06, 2011 at 10:40 AM

    Hi Geoff....

    Try this.....

    SELECT T0.[CardCode], T0.[CardName], T3.[SlpName], Sum(T2.[LineTotal]) 
    FROM OCRD T0  Left JOIN OINV T1 ON T0.CardCode = T1.CardCode 
    Left JOIN INV1 T2 ON T1.DocEntry = T2.DocEntry Left JOIN OSLP T3 
    ON T0.SlpCode = T3.SlpCode WHERE T0.[CardType] ='C' and  T2.[TargetType] <>14 
    And (T1.DocDate>='[%0]' and T1.DocDate<='[%1]') 
    GROUP BY T0.[CardCode], T0.[CardName], T3.[SlpName]

    Regards,

    Rahul

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 06, 2011 at 11:34 AM

    Hi,

    Check this if it helps :

    select t0.cardcode as 'Business Partner Code' ,t2.slpname as 'Sales Person Name',
    t0.cardname as 'Business Partner Name', t0.GroupCode as 'Sales Group',
    sum(t3.doctotal)- sum(t3.vatsum) as 'YTD Sales', 
    sum(t4.doctotal) - sum(t4.vatsum) as 'YTD Credit Memo',
    sum(t5.doctotal) as 'YTD Payments' 
    from OCRD t0 
    inner join JDT1 t1 on t0.cardcode = t1.shortname 
    inner join OSLP t2 on t0.slpcode = t2.slpcode
    left join OINV t3 on t3.objtype = t1.transtype and t3.docdate >= '2011.01.01' and t3.docdate <= '2011.12.31'
    left join ORIN t4 on t4.objtype = t1.transtype and t0.slpcode = t4.slpcode and t4.docdate >= '2011.01.01' and t4.docdate <= '2011.12.31'
    left join ORCT t5 on t5.transid = T1.transid and t5.docdate >= '2011.01.01' and t5.docdate <= '2011.12.31'
    where 
    cardtype = 'C' and t1.refdate >= '2011.01.01' and t1.refdate <= '2011.12.31'
    group by t0.cardcode, t2.slpname,t0.cardname,t0.groupcode
    order by t0.cardcode
    

    Kind Regards,

    Jitin

    SAP Business One Forum Team

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.