Calculate total when a field is a calc element

Folks

I'm having a bit of trouble with a calc element that is trying to calculate two fields. The set up is as follows

(A) - Rent Received is a field set as decimal with 2 decimal places
(B) - Agency Fee Due is a calc element which produces the right % fee to be charged

The final calc element should calculate A - B = Amount due to landlord

The code I have in the calc element is:

PHP:
$x=(float){rent_received___rent_paid} - {rent_received___rent_fee_due};
return '?'.number_format($x,2);

But its not working

If I change {rent_received___rent_fee_due} to be {rent_received___rent_fee} which is a CDD element displaying a number (for example 10) then the calc element displays the right number

It is clearly a problem with the the code I am using but I don't know what -

Any help appreciated

Thanks
 
After much brainache I have managed to do it by excluding the calc element (B) in the calculation and working out the amount due to the landlord by using the dbjoin and the cdd elements

PHP:
$x=(float)'{rent_received___rent_paid}'-'{rent_received___rent_paid}'/100*'{rent_received___rent_fee}';
return '?'.number_format($x,2);

It may not be the most elegant way of doing it but it works :)

Thanks
 
See the placeholder wiki entry.

All placeholders in php fields should be put inside quotes (in case they are empty or non-numeric) and cast to the appropriate type for the calculation. So, your calc:
PHP:
$x=(float){rent_received___rent_paid} - {rent_received___rent_fee_due};
should probably be:
PHP:
$x=(float)'{rent_received___rent_paid}' - (float)'{rent_received___rent_fee_due}';
Hope this helps.
S
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top