Summing Columns

kolaboykolaboy Member Posts: 446
Hi Experts,
I have developed a report which is giving values in column form. I now wanted to sum all the values in each column, but my values are not correct.
I placed the code that is summing the columns in different positions but it is still giving me wrong values.
Below is all the codes i wrote:



Cust. Ledger Entry - OnPreDataItem()

//"Cust. Ledger Entry".SETFILTER("Posting Date",DateFilt);

FinchargeTotal:=0;
PrincipalTotal:=0;
ArreasVarTotal:=0;
CustBal1 := 0;
TotCustBal1:=0;
NumPayments := 0;
//GTotArrs := 0;
GPrincipalTotal := 0;

Cust. Ledger Entry - OnAfterGetRecord()
Fincharge:=0;
Principal:=0;
ArreasVar:=0;
CustBal :=CustBal+"Cust. Ledger Entry".Amount;
TotalCustBal := "Detailed Cust. Ledg. Entry"."Amount (LCY)";
CustBal1 := "Cust. Ledger Entry". Amount;

//CustBal :=CustBal + "Cust. Ledger Entry". Amount;
TotCustBal1 += CustBal1;

//Code to count no. of payments
IF "Document Type"="Document Type"::Payment THEN BEGIN
NumPayments := NumPayments +1;
END;


//IF Amt = 0 THEN
//  CurrReport.SKIP;

IF "Document Type"="Document Type"::Payment THEN  BEGIN
 // NumPayments := NumPayments +1;
  Principal:= "Closed by Amount";
  Fincharge :=ABS(Amount)-ABS(Principal);
  FinchargeTotal:=FinchargeTotal+ ABS(Fincharge);
  PrincipalTotal :=PrincipalTotal+ABS(Principal);
  ArreasVar:= -Customer."Monthly Install" - "Cust. Ledger Entry".Amount;
  ArreasVarTotal:=ArreasVarTotal+ArreasVar;
END;
TotalCustBal := "Detailed Cust. Ledg. Entry"."Amount (LCY)";



FromDate := 010107D;
ToDate := "Posting Date";
Amount := 0;
CustLedEntryMonth := '';
MonthsArrears := 0;

//Code to Count Months
IF (FromDate <> 0D) AND (ToDate > FromDate) THEN BEGIN
    Calendar.RESET;
    Calendar.SETRANGE("Period Type",Calendar."Period Type"::Month);
    Calendar.SETRANGE("Period Start",FromDate,ToDate);
   Months := Calendar.COUNT;
END ELSE
   Months := 0;




MonOwed:=  Months - NumPayments;
OtherArrears := MonOwed * -Customer."Monthly Install";
TotArrs := OtherArrears + ArreasVarTotal;

GTotArrs += TotArrs;
GTotCustBal1 += TotCustBal1;
GPrincipalTotal += PrincipalTotal;
GFinchargeTotal += FinchargeTotal;


The above last four code are suppose to do the summing.
Is there any problem with my code ? can you please help me solve this problem.
Thanks.

Answers

  • SavatageSavatage Member Posts: 7,142
    edited 2007-08-13
    Did you look at the application Designers Guide under reports?

    there is a whole section about Grouping & Totaling?

    have you defined any CREATETOTALS, TOTALFIELDS or GROUPTOTALFIELDS?

    see C/side help for more
  • kolaboykolaboy Member Posts: 446
    The fields that i am trying to sum are not fields in the cust. Ledger Entry table.

    I called the field Acc. Amount. Under this field we have the total amounts which are calculated from fields like Monthly install which is from the customer table. the below code is the code that does the calculation:

    IF "Document Type"="Document Type"::Payment THEN  BEGIN
     // NumPayments := NumPayments +1;
      Principal:= "Closed by Amount";
      Fincharge :=ABS(Amount)-ABS(Principal);
      FinchargeTotal:=FinchargeTotal+ ABS(Fincharge);
      PrincipalTotal :=PrincipalTotal+ABS(Principal);
      ArreasVar:= -Customer."Monthly Install" - "Cust. Ledger Entry".Amount;
      ArreasVarTotal:=ArreasVarTotal+ArreasVar;
    END;
    TotalCustBal := "Detailed Cust. Ledg. Entry"."Amount (LCY)";
    

    The fields FinchargeTotal,PrincipalTotal,TotCustBal1 and TotArrs are the fileds i want to total. Already they are all totals from calculation.
    Now i want to total them for each customer so that i can have a grand total for each customer.
    The fields: GTotArrs ,GTotCustBal1,GPrincipalTotal and GFinchargeTotal are defined in the global variable so that i can use them as fields for the result of the calculation i will get from the formulas below:

    GTotArrs += TotArrs;
    GTotCustBal1 += TotCustBal1;
    GPrincipalTotal += PrincipalTotal;
    GFinchargeTotal += FinchargeTotal;

    So they are not fields in the Cust. ledger Entry Table which i am using as one of the dataitems. Therefore i can't define them under the Grouptotals and Total fields in the properties of the Cust. Ledger Entry. The other dataitem i am using is Customer table.

    Did anyone have a suggestion that can be a solution to my problem? I need you suggestions Please!!! (*,)
    Thanks.
  • AlbertvhAlbertvh Member Posts: 516
    Hi Kolaboy,

    Use the CurrReport.CREATETOTALS(GTotArrs,.....,GFinchargeTotal); in the PreDataItem section.

    Hope this helps.

    Albert
  • kolaboykolaboy Member Posts: 446
    Thanks you very much Albert, I have tried you suggestion, But it was give me Zeros. I has not worked.

    I have finally solved it by putting the codes calculating the grand totals at the PostDataitem trigger and initialising the required variables.

    Thanks for your ideas it really gave me some hint.
  • AlbertvhAlbertvh Member Posts: 516
    Hi Kolaboy,

    Remember that most of the fields of the Customer Ledger Entry table are flowfields so you must do a CALCFIELDS in the OnAfterGetRecord


    Albert
  • David_SingletonDavid_Singleton Member Posts: 5,479
    kolaboy wrote:
    Thanks you very much Albert, I have tried you suggestion, But it was give me Zeros. I has not worked.

    I have finally solved it by putting the codes calculating the grand totals at the PostDataitem trigger and initialising the required variables.

    Thanks for your ideas it really gave me some hint.

    Hi Kolaboy,

    Albert's solution is the correct and proper way to do this. My guess is that you forgot to insert the correct Group Totals section to display the results.
    David Singleton
Sign In or Register to comment.