I have 2 functions working successfully but unable to find a way so that a value in function 1 as made of $r can be used in function 2 (there are many other functions like function 2 with slight modified calculations)' so how to see that $r as fetched through function 1 is added in function 2 and others
if($NewCarVariantDetail){
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select($db->qn(array('id','v_price','v_fuel_type','v_capacity')))
->from($db->qn('#__newprod_variants'))
->where([$db->qn('state') . ' = 1',
$db->qn('id') . ' = ' . (int)$NewCarVariantDetail])
->order('v_price/2 asc','v_fuel_type desc');
$db->setQuery($query);
$rows = $db->loadObject();
$a = $rows->v_price;
$b = $rows->v_fuel_type;
$eng = $rows->v_capacity;
$z=.02034;
$p=.01809;
$q=.01779;
$qr=.01737;
$sma=7325;
$mid=11975;
$lar=27930;
if ($eng < 1000)
{
$r = (($z*$a)+$sma);
}
else if((($eng >= 1000) and ($eng < 1500)))
{
$r = (($p*$a)+$mid);
}
else if(($eng >= 1500) and ($a < 1900000))
{
$r = (($q*$a)+$lar);
}
else if(($eng >= 1500) and ($a > 1900000))
{
$r = (($qr*$a)+$lar);
}
$list='
<div class="common-box">
<div class="common-box-left">Basic Prem</div>
<div class="common-box-right">
<input name="voluntary_excess" type="text" class="text-box" value="Rs. '.(round($r)) .'" readonly=""/>
</div>
</div>
';
die($list);
}
2nd Function where wish to use $r as fetched in 1st function
if($RtoDetail){
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select($db->qn(array('id','v_price','v_fuel_type','v_capacity')))
->from($db->qn('#__newprod_variants'))
->where([$db->qn('state') . ' = 1',
$db->qn('id') . ' = ' . (int)$RtoDetail]);
$db->setQuery($query);
$rows = $db->loadObject();
$a = $rows->v_price;
$b = trim($rows->v_fuel_type);
$eng = $rows->v_capacity;
$calculatedtax = '';
if (($a < 400000) && ($b == 'Petrol'))
{
$calculatedtax = (.04*$a);
}
else if((($a >= 400000) and ($a < 600000)) and ($b == 'Petrol'))
{
$calculatedtax = (.05*$a);
}
else if((($a >= 600000) and ($a < 1000000)) and ($b == 'Petrol'))
{
$calculatedtax = (.07*$a);
}
else if((($a >= 1000000)) and ($b == 'Petrol'))
{
$calculatedtax = (.10*$a);
}
$list='
<h2><u> Fees </u></h2>
<div class="common-box">
<div class="common-box-left">Total Fee </div>
<div class="common-box-right">
<input name="roadtax" type="text" class="text-box" value="Rs. '.(round($calculatedtax)) .'" readonly=""/>
</div>
</div>
<div class="common-box">
<div class="common-box-left">Basic Prem</div>
<div class="common-box-right">
<input name="voluntary_excess" type="text" class="text-box" value="Rs. '.(round($r)) .'" readonly=""/>
</div>
</div>
<div class="common-box">
<div class="common-box-left">Final Price </div>
<div class="common-box-right">
<input name="reg" type="text" class="text-box" value="Rs. '.((round($a+ $calculatedtax + $r))) .'" readonly=""/>
</div>
</div>
';
die($list);
}