About the Calcsums

njaiku
njaiku Member Posts: 116
Hi everybody,
I have a doubt regarding calcsums. Suppose there are two tables
a) Contract
b) Contract Ledger Entry

Contract Ledger Entry fields are Entry No,Contract No,Subtype,Debit Amount,Credit Amount,Amount

There is a Subtype option field in the Contract Ledger Entry

options string are : ,Invoice Value,Initial Amount,Amount Financed,Finance Charges,DMA Payment,Subvention,Security Deposit,Processing Fee,Insurance,Installment,AFC,Repossession,Garage Rent,Others,Loan,Memorandum,FC Rebate,Contingency,Tyre Advance,Tyre Interest,Oil Advance,Oil Interest,TDS,AFC Rebate

In the report i have to get the total for the debit Amount once if the option is Insurance,it must total and show it in the single line

ex: Contract No Subtype Debit Amount
12345 Insurance 2000
12345 Insurance 2000
12345 Insurance 2000


Now I have to show the report like this:
ex: Contract No Subtype Debit Amount
12345 Insurance 6000

so i have written the coding in Onpredataitem of the report
I have created the variable as recContractLedger (Datatype Record)

reccontractLedger.setrange("No","No");
reccontractLedger.setrange("Subtype","Subtype"::Insurance);
if reccontractLedger.find('-') then
begin
reccontractLedger.setcurrentkey("Contract No","Subtype");
reccontract.calcsums("Debit Amount");
(created one variable decDebit)
decDebit := reccontract. "Debit Amount";
end;

So please anyone help me out
Jai

Comments

  • ara3n
    ara3n Member Posts: 9,258
    on contractledger entry you have to have a key for
    contract no, subtype, and sumindex for "Debit Amount".

    Now in your code you do this.

    reccontractLedger.setrange("No","No");
    reccontractLedger.setrange("Subtype","Subtype"::Insurance);
    reccontractLedger.calcsums("Debit Amount");
    (created one variable decDebit)
    decDebit := reccontractLedger."Debit Amount";
    end;
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • njaiku
    njaiku Member Posts: 116
    Hi,

    Thank you very much, it's working fine.Suppose there are so many options in the subtype,if i want to calculate for Amount financed,Finance charges...... Can i be able to use the CASE Statement

    recContractLedgEntry.COPY("Contract Ledger Entry");
    recContractLedgEntry.SETRANGE(" Contract No."," Contract No." );
    recContractLedgEntry.SETRANGE("Sub Type","Sub Type");
    case "subtype" of:
    "subtype" :: Finance charges
    begin
    recContractLedgEntry.CALCSUMS("Debit Amount (LCY)");
    recContractLedgEntry.CALCSUMS("Credit Amount (LCY)");
    recContractLedgEntry.CALCSUMS("Amount (LCY)");
    decDebit := recContractLedgEntry."Debit Amount (LCY)";
    decCredit := recContractLedgEntry."Credit Amount (LCY)";
    decAmount := recContractLedgEntry."Amount (LCY)";
    end

    "subtype" :: Amount Financed
    begin
    recContractLedgEntry.CALCSUMS("Debit Amount (LCY)");
    recContractLedgEntry.CALCSUMS("Credit Amount (LCY)");
    recContractLedgEntry.CALCSUMS("Amount (LCY)");
    decDebit := recContractLedgEntry."Debit Amount (LCY)";
    decCredit := recContractLedgEntry."Credit Amount (LCY)";
    decAmount := recContractLedgEntry."Amount (LCY)";
    end;

    If i begin to code for the other options, I tried this. It's not working.
    Please help me out
    Jai
  • ara3n
    ara3n Member Posts: 9,258
    You need to create different variables for each sub type. Or create an array

    recContractLedgEntry.COPY("Contract Ledger Entry");
    recContractLedgEntry.SETRANGE(" Contract No."," Contract No." );
    recContractLedgEntry.SETRANGE("Sub Type","Sub Type");
    recContractLedgEntry.CALCSUMS("Debit Amount (LCY)");
    recContractLedgEntry.CALCSUMS("Credit Amount (LCY)");
    recContractLedgEntry.CALCSUMS("Amount (LCY)");
    case "subtype" of:
    "subtype" :: Finance charges
    begin
    FinChrgdecDebit := recContractLedgEntry."Debit Amount (LCY)";
    FinChrgdecCredit := recContractLedgEntry."Credit Amount (LCY)";
    FinChrgdecAmount := recContractLedgEntry."Amount (LCY)";
    end

    "subtype" :: Amount Financed
    begin
    AmtFindecDebit := recContractLedgEntry."Debit Amount (LCY)";
    AmtFindecCredit := recContractLedgEntry."Credit Amount (LCY)";
    AmtFindecAmount := recContractLedgEntry."Amount (LCY)";
    end;






    to create an array

    recContractLedgEntry.COPY("Contract Ledger Entry");
    recContractLedgEntry.SETRANGE(" Contract No."," Contract No." );
    recContractLedgEntry.SETRANGE("Sub Type","Sub Type");
    recContractLedgEntry.CALCSUMS("Debit Amount (LCY)");
    recContractLedgEntry.CALCSUMS("Credit Amount (LCY)");
    recContractLedgEntry.CALCSUMS("Amount (LCY)");
    case "subtype" of:
    "subtype" :: Finance charges
    begin
    decDebit[1] := recContractLedgEntry."Debit Amount (LCY)";
    decDebit[2] := recContractLedgEntry."Credit Amount (LCY)";
    decDebit[1] := recContractLedgEntry."Amount (LCY)";
    end

    "subtype" :: Amount Financed
    begin
    decDebit[2] := recContractLedgEntry."Debit Amount (LCY)";
    decDebit[2] := recContractLedgEntry."Credit Amount (LCY)";
    decDebit[2] := recContractLedgEntry."Amount (LCY)";
    end;
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n