Field Calculations

Hi again…

I am so close to finishing my last report but can not get a simple calculation going. I have been experimenting with the beforeprint scripts etc but I am either missing something obvious or I just need to stop thinking that I know how to script.

My dilemma is to provide accounts a printable purchase order, as per the attachment I have edited the report right to the point in which the totals are calculated. Your help would be gratefully appreciated.

  1. The Parts Net Total and Shipping Totals are appearing ok.

  2. I then need VAT to be calculated on (Parts Net Total & Shipping) and showed as a value

  3. Subsequently all three (Parts Net+Shipping+VAT) would present a Grand Total

Hopefully this makes sense…

VAT =(Parts Net Total + Shipping) x 15%

xrLabel30 = (xrLabel16 + xrLabel31) x 15%

Any assistance in getting into the right direction will be appreciated

Hi Ian

What you will want to do is keep a running total of the Net so that you can add it to the shipping and multiple it by 15%; andadd the running total of the Net to the shipping as well as to the vat to get your PO total.

There are a number of running total examples:
topic Sample-Labor-Cost-for-Displayed-Workorders-report-template
topic No-Charge-Hours-Calculation-report&highlight=Charge+Hours+Calculation+report
etc

I’ll post again later with examples using a copy of your report template too

  • Joyce

Hi again Ian

I’ve attached a copy of your report template with the following:

In reportHeaderBand1 OnBeforePrint to set the totals we will be using in this report: " "

decimal NetTotal = 0;
decimal CarriageTotal = 0;
double dVATTotal = 0;
decimal POTotal = 0;

In Detail1 band’s OnBefore Print have the following: " "

private void OnBeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
//obtain what the Net is for this record
decimal NetPrice = Convert.ToDecimal(Convert.ToDouble(DetailReport1.GetCurrentColumnValue(“LT_UI_Label_NetValue”)));

//Add that Net to the running NetTotal
NetTotal += (NetPrice);
}

In the xrLabel30 VAT data field OnBeforePrint: " "

private void OnBeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
//obtain the amount for shipping (in the event the custom field doesn’t have anything, have to parse it out)
decimal d = 0;
decimal.TryParse(DetailReport.GetCurrentColumnValue(“LT_PurchaseOrder_Label_Custom0”).ToString(), out d);
CarriageTotal = d;

//Add this amount to the running total for the PO
POTotal += CarriageTotal;

//add the shipping to NetTotal
decimal nt = (CarriageTotal + NetTotal);

//declare the VAT %
decimal vtp = Convert.ToDecimal(0.15);

//obtain the VAT total and show it in the field and add it to the running POTotal
dVATTotal = decimal.Multiply(nt, vtp);
xrLabel30.Text = string.Format("{0:n2}", dVATTotal);
POTotal += Convert.ToDecimal(dVATTotal);
}

In the Total for the PO field’s OnBeforePrint " "

private void OnBeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
//display the final running total for the PO
xrLabel32.Text = string.Format("{0:c}", (POTotal + NetTotal));
}

And then finally to zero out for the next report in the event you are printing multiple PO’s, the AfterPrint script: " "

private void OnAfterPrint(object sender, System.EventArgs e)
{
NetTotal = 0;
CarriageTotal = 0;
dVATTotal = 0;
POTotal = 0;
}

I’ve attached a copy of the custom report template showing this for your benefit, as well as for others that may want to do something similar. Have a good weekend.

  • Joyce