Ideas for an alghorithm - aging report

Hello,
I have to create an aging report (financial) which shows the invoices of a client, the total amount paid, and then the unpaid invoices.
I have managed to gather from different tables the information in this way:
with
aging
as
select 9406 as "account_no", 0 as "jan_07", 77 as "feb_07", 104 as "mar_07", 103 as "apr_07", 102 as "may_07", 100 as "jun_07", 488 as "total_billed", 0 as "total_payments", 488 as "balance", '' as "pjan_07", '' as "pfeb_07", '' as "pmar_07", '' as "papr_07", '' as "pmay_07", '' as "pjun_07"
from dual
union
select 9965 as "account_no", 0 as "jan_07", 0 as "feb_07", 84 as "mar_07", 45 as "apr_07", 51 as "may_07", 50 as "jun_07", 231 as "total_billed", 130 as "total_payments", 101 as "balance", '' as "pjan_07", '' as "pfeb_07", '' as "pmar_07", '' as "papr_07", '' as "pmay_07", '' as "pjun_07"
from dual
union
select 9981 as "account_no", 201 as "jan_07", -33 as "feb_07", 19 as "mar_07", 48 as "apr_07", 48 as "may_07", 47 as "jun_07", 331 as "total_billed", 332 as "total_payments", -1 as "balance", '' as "pjan_07", '' as "pfeb_07", '' as "pmar_07", '' as "papr_07", '' as "pmay_07", '' as "pjun_07"
from dual
select * from aging;
NOW, i find the most difficult part. I need to populate the empty columns in the right that are named as "pjan_07", "pfeb_07" etc., it means payed month, or payed bill in that month.
The ideea is that i use the FIFO method, from total_payments i need to substract from the first bills, until the total_payments is <=0.
for example, for account_no: 9965, i have no bills in jan and feb, so i will substract like this:
total_payments - mar_07 = 130 - 84 = 46 credit left (I WILL UPDATE the pmar_07 = 0, because that bill is payed) so i can go on
(total_payments - mar_07) - apr_07 = 46 - 45 = 1 credit left (I WILL UPDATE the papr_07 = 0, because that bill is payed) still i can go on
((total_payments - mar_07) - apr_07) - may_07 = 1 - 51 = -50 STOP no credit, so i should take the result "50" and update the pmay_07 = 50 (because it still has 50 to pay for may_07 bill).
And here i stop, i will go for other account_no.
The right side of the table is just for informational purposes and it is totally dinamic, based on the every day collections, i will run such kind of aging report so to see the "aging" of the clients regarding invoices and collections.
I have tried with some SQL scripts, but i have reached nowhere, i supose PL/SQL will definatelly solve this issue, but i have few knowledge.
Can you please offer me at least one idea of how to start this one?
Thank you so much,
Michael

No need for PL/SQL if SQL will do just fine.
I modified your query a bit, and btw, I think sample data for "total_billed" is incorrect.
with aging as (
  select 9406 as "account_no", 0 as "jan_07", 77 as "feb_07", 104 as "mar_07", 103 as "apr_07"
       , 102 as "may_07", 100 as "jun_07", 488 as "total_billed", 0 as "total_payments", 488 as "balance"
  from dual
  union
  select 9965 as "account_no", 0 as "jan_07", 0 as "feb_07", 84 as "mar_07", 45 as "apr_07"
       , 51 as "may_07", 50 as "jun_07", 231 as "total_billed", 130 as "total_payments", 101 as "balance"
  from dual
  union
  select 9981 as "account_no", 201 as "jan_07", -33 as "feb_07", 19 as "mar_07", 48 as "apr_07"
       , 48 as "may_07", 47 as "jun_07", 331 as "total_billed", 332 as "total_payments", -1 as "balance"
from dual
select aging.*
     , case when "total_payments" > "jan_07" then 0
            else "jan_07"-"total_payments" end "pjan_07"
     , case when "total_payments"-"jan_07" > "feb_07" then 0
            else "feb_07"-("total_payments"-"jan_07") end "pfeb_07"
     , case when "total_payments"-"jan_07"-"feb_07" > "mar_07" then 0
            else "mar_07"-("total_payments"-"jan_07"-"feb_07") end "pmar_07"
     , case when "total_payments"-"jan_07"-"feb_07"-"mar_07" > "apr_07" then 0
            else "apr_07"-("total_payments"-"jan_07"-"feb_07"-"mar_07") end "papr_07"
     , case when "total_payments"-"jan_07"-"feb_07"-"mar_07"-"apr_07" > "may_07" then 0
            else "may_07"-("total_payments"-"jan_07"-"feb_07"-"mar_07"-"apr_07") end "pmay_07"
     , case when "total_payments"-"jan_07"-"feb_07"-"mar_07"-"apr_07"-"may_07" > "jun_07" then 0
            else "jun_07"-("total_payments"-"jan_07"-"feb_07"-"mar_07"-"apr_07"-"may_07") end "pjun_07"
from agingNH

Similar Messages

  • Any Insight for PDO WIP aging report

    Hi All,
    Anyone have experience to create a report for PDO WIP aging report ?
    By using KKAO or use GL account WIP cal. to do it ? I am interesting to know the logic or example
    because we needs to build a month-end report for Inventory analysis include Raw Materials, WIP, and Finished Goods.
    For Raw Materials and Finsihed Goods, for sure by using MM module data. But not sure WIP
    thanks

    Hi All,
    Anyone have experience to create a report for PDO WIP aging report ?
    By using KKAO or use GL account WIP cal. to do it ? I am interesting to know the logic or example
    because we needs to build a month-end report for Inventory analysis include Raw Materials, WIP, and Finished Goods.
    For Raw Materials and Finsihed Goods, for sure by using MM module data. But not sure WIP
    thanks

  • Need help for creation of aging report of customer

    Hi Experts,
                     I am going to create aging report for custer so have a need of basic concept of creation of aging report.
    Thanks and Regards
    vijay
    Edited by: vijay dwivedi on Mar 9, 2009 1:19 AM

    Hi here is a guide of how to understand the components in an ageing report.Hope this helps
    Customer Receivables Aging Report
    Field
    Description/Activity
    Currency - Click This graphic is explained in the accompanying text and choose the currency in which you want to display the report results.
    The available options include:
    ●     Local currency
    ●     System currency
    ●     Business partner currency
    ●     Any additional currencies defined in SAP Business One
    Aging Date - Displays the aging date entered in the selection criteria window.
    Age By - Choose whether you calculate the age of the receivable according to the due date, posting date, or document date of the document/journal entry.
    Customer Code - Displays the code of the customer.
    Click This graphic is explained in the accompanying text to open the corresponding Business Partner Master Data.
    Customer Name - Displays the name of the customer.
    Total - Displays the total amount of open receivables.
    Figures in brackets mean that you have already received payments from a customer that exceed the amount of the receivables for the period.
    Future Remit. - Displays all open receivables owed by the customer according to the date selected in the Age By field for which the date specified in the Aging Date field has not yet been reached.
    Example:
    The customer has an open A/R Invoice for USD100, due on May 1st.
    Due Date is selected in the Age By field.
    The Aging Date is April 28th.
    Since the invoice is due after the aging date, the invoice amount is displayed in the Future Remit column..
    Letter - Indicates whether a dunning letter was created.
    This column is displayed only when generating the report by Sales Documents and by Due Date
    Time Intervals - These four columns are constructed according to the specifications you made in the Interval field in the selection criteria window.
    SAP Business One displays the relevant open receivables in four columns for the time interval. The amount of future remit is first subtracted from the total sum of receivables.
    ·         Days u2013 Each column represents the number of days entered in the selection criteria window starting from the aging date and backwards. The fourth column includes open receivables for the days prior to the first three columns.
    ·         Months u2013 Each column represents one month starting from the aging date month and backwards. The last column includes open receivables for months prior to the first three months.
    ·         Periods u2013 Each column represents one period (as defined in Administration ® System Initialization ® Posting Periods tab) starting from the aging date period and backwards. The last column includes open receivables for periods prior to the first three periods.
    If the number of periods in your company is less than the 4, the non-relevant columns will be titled as Not Valid.
    Doubtful Debt - Displays the doubtful debt amount if exists.
    Top Total Row - The top total row displays the sum of amounts listed in one column.
    Bottom Total Row - The bottom total row displays the percentage of open receivables for each time interval.
    Thanks
    Kevin

  • Query for Customer Receivables Aging Report

    What is the query to the Customer Receivables Aging Report? I cannot seem to reproduce the same results that SAP has in my Crystal Report.
    Thanks

    To reproduce it by query would not be an easy job.  Crystal Report is a better tool for report.
    Thanks,
    Gordon

  • Importing BP opening balance  for AP&AR aging report

    I use DTW import BP opening balance,
    for example Maybe AR  posting date is 20080908 and 20090808 ,but I importing GL opening balance at the time of 20091231.
    I wonder whether I shoud import posting date  of  AR templete and datatime of databaseserver is the same year.
    Please advise.

    Thank you for your reply. You understand correctly  What I exactly want to realize the situation.
    But  in fact ,I have just  imported  the AR doc  which column of    docdate is 2010001 in his templete.
    I cannot  import  AR doc of others year  . The DTW prompt error "no matching record odbc(...)"..
    Maybe I need the set the posting period to currecnt  period .but I cannot find the setting In sbo 2007B
    Please advise!

  • Aging Report for A/p

    I mean is there anyway to user decode for showing sum(amount) for different period of dates
    is there any idea to make faster ageing report for accounts payable module.
    Thanks AHON
    Edited by: [email protected] on Nov 22, 2009 7:09 AM

    plz write more clear requirements...... ur table structures and report output ....
    i have few aging reports and all working without any problem.....it depends on ur table structure also.

  • Variables in aging report for PLD

    Hi,
    I am looking to find a list of the variables for a PLD aging report in SAP 8.8, the Excel I found doesn't list report starting with the code AGE...... In fact I am looking for the variable for the project number and the project name. The system information shows variable 41 but when I run the report I get an error.
    Thank you for your help
    Jac

    Hi,
    Welcome you post on the forum. I believe there is only one excel file for PLD available for a certain version.
    If the variable is not in this file, you will be out of luck.
    The system variable showed under system info is not the same as in the PLD.
    Thanks,
    Gordon

  • Page Numbering for the aging report

    Hi,
    Does any one know how I can achieve the following:
    For the customer ageing report we need to print all customer statements at once. On our print layout we currently use the following CurrentPage()/TotalPages() formula fields to dispaly the page number. The result we get is 1/10, 2/10, 3/10....etc.
    We actually need the following, for total 10 pages statement would like to display the page number as follows:
    Customer A: 1/1
    Customer B: 1/3, 2/3, 3/3
    Customer C: 1/1
    Customer D: 1/5, 2/5, 3/5, 4/5, 5/5
    Does anyone know how to achieve the above for continuous print?
    Your assistance in this matter is highly appreciated.
    BR,
    Jimmy

    Hi,
    You are trying to print the detailed aging report. Right?
    It seems that there is no way of "splitting" the page numbers within a collection report.
    The system could not count the pages for EACH customer.The total number per pages will be per whole document, and cannot be per business partner within the same document when using the formula currentpage().
    Regards,
    Jitin

  • AP Aging Report

    Hi, I've got a few questions to ask regarding AP Aging
    1. I've tried to pull out the Document Date in AP Aging using PLD but there's no such field to be selected. It seems that most of the fields in the standard PLD AP Aging report are consists of variables, and in this instance, how can i retrieve the Document Date in the report?
    2. Anybody has any idea what are the tables involve to extract all the required data for an AP Aging report? Cause if I can't get PLD to retrieve the required fields, then I will have to resort to use Crystal Report to design AP Aging.
    Please advice. Thanks!

    To know what the table names are, you must click on View -> System Information (or Ctrl + Shift + D).  Then you will notice the information on your status bar.  You only have to put your cursor over the field to know where it is.
    In your case, you have to use the "Posting Date", there is no "Document Date" for that.
    You must use Crystal Report for doing your aging report, it's SAP B1's weak point.  Sorry I couldn't help you better.

  • Ageing Report A/P

    I mean is there anyway to user decode for showing sum(amount) for different period of dates
    Is there any idea to make faster ageing report for accounts payable module using report 6i
    Thanks
    AHon
    Edited by: [email protected] on Nov 22, 2009 7:07 AM

    Hi,
    Looks to me like an Apps question. You might want to post it in [Financials Forum|http://forums.oracle.com/forums/forum.jspa?forumID=111]
    -Arun

  • Regarding aging reports

    Hi Experts/Gurus
    I need the standard reports and transaction for customer aging report and vendor aging report.(I need only standard reports not the custom reports)
    Need immediate replies.
    Your answers can be rewarded with good points.
    Regards,
    kumar

    Hello,
    Check the link
    Aging Report for AR
    Vendor Ageing Report ?
    If useful reward.
    Vasanth

  • AR Aging Report by Invoice

    Is there any report with B1 for an AR aging report By Customer/By Invoice? Any help will be much appreciated.

    Hi Mark......
    Ok.... Try this.....
    SELECT T0.[DocNum], T0.[DocDate], T0.[DocDueDate], T0.[CardCode], T0.[CardName],
    T0.[DocTotal], T0.[PaidToDate], DateDiff (Day,T0.[DocDate], T0.[DocDueDate]) Overdue FROM OINV T0
    Where T0.[DocTotal]>T0.[PaidToDate] And T0.CardName='[%0]' or '[%0]'=' '
    Above report if you run it will ask you to select any of the customer and if you select report will run for that customer and if you dont select anything report will run for every customer.
    I guess this one is better for you........
    Regards,
    Rahul

  • AR Aging Report aside from S_ALR_87012085

    Hi Experts,
    We are searching a Standard AR Aging Report that will show Aging by Document Date. And when we checked the S_ALR_87012085, it was aging by due date. The users want to be the same format as the AR Aging Report.
    Thanks a lot!

    S_ALR_87012085  is for Vendor Payment History with OI sorted Items.
    For Customer (AR) Aging report is S_ALR_87012178 by customer and S_ALR_87012168 by invoice
    The aging report is based on Payment terms, Payment terms are assigned in customer master OBB8
    In case no Z report or query is to be created for the same then twek the setting of payment terms.
    Regards
    Lavanya
    Edited by: Lavi sam on Sep 2, 2011 12:19 AM

  • REPOST -Summarizing a Detailed Debtors Aging Report

    Dear All,
    I use a Query (SAP B1 8.8) for Detailed Debtors Aging Report - i.e a report which lists all unpaid invoices and sends each amount to a column representing the age bracket.
    Now, I want to create a Summary Debtors Aging Report which groups all the unpaid invoices for a particular debtor and displays only 1 row for each debtor. The total due by the debtor is analysed in 1 or more Age Brackets.
    I use the SUM() and GROUP BY claused to modify the original query.
    A very simplified version of my Detailed report is in Screen 1.
    The modifications I made to it to convert it to a Summarized report are in Screen 2. It does not work!
    I have traced the error to the following:
    SUM ((SELECT T0.BalDueDeb - T0.BalDueCred
    WHERE DateDiff(mm, T0.TaxDate,@taxdt) = 1))
    AS '1 Mth Ago'
    Error is:
    Cannot perform an aggregate function on an expression containing an aggregate or a sub query
    I also tried this code:
    (SELECT
    SUM (T6.BalDueDeb - T0.BalDueCred)
    FROM JDT1 T6
    WHERE DateDiff(mm, T0.TaxDate, @taxdt) = 1
    AND T6.TransID = T0.TransID)
    AS '1 Mth Ago'
    Error is:
    'JDT1.TransID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
    Could you help me write the code correctly?
    Thanks
    Leon Lai
    ADDITIONAL INFO
    Screen 1 : The Original DETAILED report
    declare @taxdt datetime
    set @taxdt
    /*select 1 from jdt1 t0 where t0.TaxDate*/ = [%1]
    SELECT
    CASE
                 WHEN T0.Account = 1220101 THEN 'Prim Cust'
                 WHEN T0.Account = 1220102 THEN 'Fgn Cust'
                 WHEN T0.Account = 1220103 THEN 'Local Cust'
                 WHEN T0.Account = 1220104 THEN 'Staff Loan' 
                 WHEN T0.Account = 1220105 THEN 'Dep with TP'
                 WHEN T0.Account = 1220106 THEN 'Adv to Cust'
                 WHEN T0.Account = 1220108 THEN 'Sund Drs'
                 ELSE 'Error ! ! !'
    END AS 'Control A/c',
    T1.CardCode AS 'BP Code',
    T2.Notes2 AS 'BP Name',
    (T0.Debit - T0.Credit) AS 'Orig. Rs',
    (T0.BalDueDeb - T0.BalDueCred) AS 'Bal. Rs',
    (SELECT T0.BalDueDeb - T0.BalDueCred WHERE DateDiff(mm, T0.TaxDate, @taxdt) = 1)
    AS '1 Mth Ago'
    FROM JDT1 T0
    INNER JOIN OCRD T1 ON T0.ShortName = T1.CardCode
    LEFT OUTER JOIN OCPR T2 ON T1.CardCode = T2.Cardcode
    LEFT OUTER JOIN OJDT T3 ON T0.TransID = T3.TransID
    LEFT OUTER JOIN OINV  T4 ON T3.TransID = T4.TransID
    LEFT OUTER JOIN ORIN  T5 ON T3.TransID = T5.TransID
    WHERE
    T1.CardType = 'C'
    and (Balance) != 0
    and (T0.BalDueDeb - T0.BalDueCred) != 0
    Screen 2 : The Modified SUMMARY report
    declare @taxdt datetime
    set @taxdt
    /*select 1 from jdt1 t0 where t0.TaxDate*/ = [%1]
    SELECT
    CASE
                 WHEN T0.Account = 1220101 THEN 'Prim Cust'
                 WHEN T0.Account = 1220102 THEN 'Fgn Cust'
                 WHEN T0.Account = 1220103 THEN 'Local Cust'
                 WHEN T0.Account = 1220104 THEN 'Staff Loan' 
                 WHEN T0.Account = 1220105 THEN 'Dep with TP'
                 WHEN T0.Account = 1220106 THEN 'Adv to Cust'
                 WHEN T0.Account = 1220108 THEN 'Sund Drs'
                 ELSE 'Error ! ! !'
    END AS 'Control A/c',
    T1.CardCode AS 'BP Code',
    T2.Notes2 AS 'BP Name',
    SUM ((T0.Debit - T0.Credit)) AS 'Orig. Rs',                 /* Added SUM()*/
    SUM ((T0.BalDueDeb - T0.BalDueCred)) AS 'Bal. Rs',         /*Added SUM()*/
    SUM ((SELECT T0.BalDueDeb - T0.BalDueCred
        WHERE DateDiff(mm, T0.TaxDate, @taxdt) = 1))    
        AS '1 Mth Ago'               /*Added SUM() PROBLEM IS HERE! */
    FROM JDT1 T0
    INNER JOIN OCRD T1 ON T0.ShortName = T1.CardCode
    LEFT OUTER JOIN OCPR T2 ON T1.CardCode = T2.Cardcode
    LEFT OUTER JOIN OJDT T3 ON T0.TransID = T3.TransID
    LEFT OUTER JOIN OINV  T4 ON T3.TransID = T4.TransID
    LEFT OUTER JOIN ORIN  T5 ON T3.TransID = T5.TransID
    WHERE
    T1.CardType = 'C'
    and (Balance) != 0
    and (T0.BalDueDeb - T0.BalDueCred) != 0
    GROUP BY T0.Account, T1.CardCode, T2.Notes2                   /*Added GROUP BY*/

    Hi ,
    Try this:
    declare @taxdt datetime
    set @taxdt
    /*select 1 from jdt1 t0 where t0.TaxDate*/ = [%1]
    SELECT
    CASE
                 WHEN T0.Account = 1220101 THEN 'Prim Cust'
                 WHEN T0.Account = 1220102 THEN 'Fgn Cust'
                 WHEN T0.Account = 1220103 THEN 'Local Cust'
                 WHEN T0.Account = 1220104 THEN 'Staff Loan' 
                 WHEN T0.Account = 1220105 THEN 'Dep with TP'
                 WHEN T0.Account = 1220106 THEN 'Adv to Cust'
                 WHEN T0.Account = 1220108 THEN 'Sund Drs'
                 ELSE 'Error ! ! !'
    END AS 'Control A/c',
    T1.CardCode AS 'BP Code',
    T2.Notes2 AS 'BP Name',
    SUM ((T0.Debit - T0.Credit)) AS 'Orig. Rs',                 /* Added SUM()*/
    SUM ((T0.BalDueDeb - T0.BalDueCred)) AS 'Bal. Rs',         /*Added SUM()*/
    ((SELECT SUM(T0.BalDueDeb) - Sum(T0.BalDueCred)
        WHERE DateDiff(mm, T0.TaxDate, @taxdt) = 1))    
        AS '1 Mth Ago'               /*Added SUM() PROBLEM IS HERE! */
    FROM JDT1 T0
    INNER JOIN OCRD T1 ON T0.ShortName = T1.CardCode
    LEFT OUTER JOIN OCPR T2 ON T1.CardCode = T2.Cardcode
    LEFT OUTER JOIN OJDT T3 ON T0.TransID = T3.TransID
    LEFT OUTER JOIN OINV  T4 ON T3.TransID = T4.TransID
    LEFT OUTER JOIN ORIN  T5 ON T3.TransID = T5.TransID
    WHERE
    T1.CardType = 'C'
    and (Balance) != 0
    and (T0.BalDueDeb - T0.BalDueCred) != 0
    GROUP BY T0.Account, T1.CardCode, T2.Notes2         ,T0.TaxDate          
    Thanks,
    Neetu

  • Stock ageing report by profit center

    hi I am new to abap, please kindly send the code for the stock ageing report by profit center in MM module

    hi,
    for getting stock ageing report in  profit center in MM
    use the tcode :
    S_ALR_87013348
    from this u can get the necessary data.
    rewards points if useful.
    regards
    sandhya

Maybe you are looking for

  • Wrap not working in Muse 2014

    Wrap function not working at all. I have a text box, with text, and a picture picture, with picture. The picture is arranged to the front and all the items are on the same layer, but when I go to the Wrap box everything is greyed out. I've tried mult

  • Why won't open in new tab work?

    '''When I try to open a link in a new tab nothing happens'''

  • Airport drops out randomly

    Hello.. Am trying to get to the bottom of why my airport drops out at random times roughly once every hour. I then just need to select my router again and it reconnects. This isn't a massive dilemma unless i'm downloading a large file - can't leave i

  • Month End Stocks of Sub-Contractor

    Hi, Our compney is doing lot of sub-contractor activity . I need a month end stocks of Raw Materials with sub-contractors . Is there any standard report available ? Thanks & Regards Shyam Kogta

  • How to creating pdf documents using c# and Adobe SDK

    I downloaded Adobe SDK and go through the samples given in sdk. But i couldn't find any sample code how to create PDF file using C# code. Please, help me with this. Thanks.