Keep track of two different sums Amounts?

nvermanverma Member Posts: 396
I have been asked to a create a report.

I am suppose to look at all the records where the program type is Passport Services. I got that working.

Each passport Service has a Transaction type which could either be 'cheque' or 'receipt'. Each record can have multiple Transacation types. For each record I have been asked to keep track of the total amount if the transaction type is cheque and if the transaction type if receipt.

I have been able to get receipt working and it gives me the correct total amount. But when I try to apply the same code and get the total amount for cheque. It doesnt work. It gives me the same answer. I even know why its giving me the same answer. I just dont know how to fix it.
(OnAfterGetRecord)
IF "Consumer Disbursement"."Transaction Type" = "Consumer Disbursement"."Transaction Type"::Receipt THEN
BEGIN
  "Consumer Disbursement".CALCSUMS(Amount);
END;

IF "Consumer Disbursement"."Transaction Type" = "Consumer Disbursement"."Transaction Type"::ChequeTHEN
BEGIN
  "Consumer Disbursement".CALCSUMS(Amount);
  //TotalAmountCheque := "Consumer Disbursement".Amount;
END;
(OnPostDateItem)

TotalAmountReceipt := "Consumer Disbursement".Amount + TotalAmountReceipt;
TotalAmountCheque := "Consumer Disbursement".Amount + TotalAmountCheque;

I see the problem with this code, but I am just not sure how to fix it.
Any Suggestions???

This is just to provide you with an idea of what I mean. This is just one record (REC00031) with multiple Transaction Type.
http://www.zshare.net/image/992983510e280437/

Answers

  • SavatageSavatage Member Posts: 7,142
    you're calling "Consumer Disbursement".CALCSUMS(Amount); regardless so just make it the first line.

    some quick thoughts...haven't tested
    I would split up the amount with different variables.

    CREATETOTALS(checkamt, receiptamt);
    OnAfterGetRecord()
    CALCFIELDS(Amount);
    if check type then
    checkamt := checkamt + amount else
    checkamt := 0;
    if receipt type then
    receiptamt := receiptamt + amount else
    receiptamt := 0;

    then keep Createtotals of receiptamt & checkamt.

    you can also look at the customer statement report.
    depending on the type it splits it into Debit or Credit and total's it.
    Sounds just like what you're doing.

    CREATETOTALS
    Use this function to maintain totals for a variable in the same way as totals are maintained for fields by using the TotalFields property.
  • nvermanverma Member Posts: 396
    I tried what you suggested.

    It still doesnt work. For some weird reason its only detects the negative values. It never seem to find any of the transaction type 'cheque'.
    I dont think i will need calfields(amount) because amount is not a flowfield.
    (OnAfterGetRecord)
    IF "Consumer Disbursement"."Transaction Type" = "Consumer Disbursement"."Transaction Type"::Cheque THEN
    BEGIN
    TotalAmountCheque := TotalAmountCheque + Amount;
    END;
    
    
    IF "Consumer Disbursement"."Transaction Type" = "Consumer Disbursement"."Transaction Type"::Receipt THEN
    BEGIN
    TotalAmountReceipt := TotalAmountReceipt + Amount;
    END;
    
    (OnPostDataItem)
    CurrReport.CREATETOTALS(TotalAmountCheque) ;
    CurrReport.CREATETOTALS(TotalAmountReceipt);
    

    It still doesnt work any suggestions.
  • nvermanverma Member Posts: 396
    Nevermind. My manager helped me figure out the problem. The reason it wasnt able to find any transacation type of 'cheque' was because I did something stupid.

    Thanks anways.
  • SavatageSavatage Member Posts: 7,142
    edited 2012-03-06
    Add a message if you think it's not finding a cheque type.
    And you can add messages to see if everything is working as you expect.
    Once it does work the messages can be removed.


    IF "Consumer Disbursement"."Transaction Type" = "Consumer Disbursement"."Transaction Type"::Cheque THEN BEGIN
    MESSAGE('Check Type Found! TOTAL AMOUNT %1 - Amount %2',totalamountcheque,amount);
    TotalAmountCheque := TotalAmountCheque + Amount;
    message('%1', totalamountcheque); //to see if it changed
    END;
  • SavatageSavatage Member Posts: 7,142
    nverma wrote:
    Nevermind. My manager helped me figure out the problem. The reason it wasnt able to find any transacation type of 'cheque' was because I did something stupid.

    Thanks anways.
    :thumbsup:
Sign In or Register to comment.