Topic: Need a help with calculations

Hi Guys,


With guidence of a sample project, I managed to apply "Price" calculation but failed on "TaxAmt" and "Total" calc.


Please see the attached sample project:

Post's attachments

Attachment icon Expenses.zip 26.16 kb, 363 downloads since 2016-12-03 

Adam
God... please help me become the person my dog thinks I am.

Re: Need a help with calculations

Hello.


Corrected:

procedure CalculateTotal;
var
    TaxRate: double;
begin
    TaxRate := 0;
    frmExpenses.edExpenseNetPrice.Value := frmExpenses.edExpenseUnitPrice.value * frmExpenses.edExpenseQty.Value;

    TaxRate := SQLExecute('SELECT tax_rate FROM TaxRates WHERE id='+frmExpenses.cbExpenseTaxRate.sqlValue);
    frmExpenses.edExpenseTaxAmt.Value := frmExpenses.edExpenseNetPrice.Value * (TaxRate / 100);

    frmExpenses.edExpenseTotal.Value := frmExpenses.edExpenseNetPrice.Value + frmExpenses.edExpenseTaxAmt.Value;
end;
Dmitry.

Re: Need a help with calculations

Hi Dmitry,


Thanks a lot....


procedure CalculateTotal;
begin
    if ValidFloat(frmExpenses.edExpenseUnitPrice.Text) and ValidInt(frmExpenses.edExpenseQty.Text) and ValidInt(frmExpenses.cbExpenseTaxRate.Text) then // check the correctness of the values
    begin
        frmExpenses.edExpenseNetPrice.Text := FloatToStr( StrToFloat(frmExpenses.edExpenseUnitPrice.Text) * StrToInt(frmExpenses.edExpenseQty.Text)); // calculate
        frmExpenses.edExpenseTaxAmt.Text := FloatToStr( StrToFloat(frmExpenses.edExpenseUnitPrice.Text) * StrToInt(frmExpenses.edExpenseQty.Text)) * StrToInt(cbExpenseTaxRate.Text / 100 );
        frmExpenses.edExpenseTotal.Text := FloatToStr( StrToFloat(frmExpenses.edExpenseUnitPrice.Text) * StrToInt(frmExpenses.edExpenseQty.Text)) * StrToInt(cbExpenseTaxRate.Text / 100 ) + StrToFloat(frmExpenses.edExpenseUnitPrice.Text);
    end else
    begin
        frmExpenses.edExpenseNetPrice.Text := '0';
        frmExpenses.edExpenseTaxAmt.Text := '0';
    end;
end;

procedure frmExpenses_edExpenseQty_OnChange (Sender: string);
begin
    CalculateTotal;
end;

procedure frmExpenses_edExpenseUnitPrice_OnChange (Sender: string);
begin
    CalculateTotal;
end;

procedure frmExpenses_cbExpenseTaxRate_OnChange (Sender: string);
begin
    CalculateTotal;
end;

I couldn't apply  your correction to above sample project script. Would you be so kind to apply it to above code please, so that when I enter Qty, Unit price and Tax Rate it automatically calculates Net Price, Tax Amt and Total Amt.

Adam
God... please help me become the person my dog thinks I am.

Re: Need a help with calculations

Just copy and paste corrected procedure.

Dmitry.