I have a problem making a calculation on laravel this is the calculation:
$inc = round(100*($Incom->total_amount/$TotalRewenue), 2);
I tested if $Incom is 0, $Incom->total_amount is 0 and $TotalRewenue is 0 and neather of theme are 0 and if i putt a dd of $inc i actually get the value of the calculation correct.
this is the full code:
$TotalIncome = DB::table('actuals_report')->where('companyId',$id)->Where('dataYear',$dataYear)->where('type','LIKE','TotlaIncome%')->first();
$TotalExpense = DB::table('actuals_report')->where('companyId',$id)->Where('dataYear',$dataYear)->where('type','LIKE','TotlaExpense%')->first();
$TotalRewenue = $TotalIncome->year - $TotalExpense->year;
foreach($TopTwentyIncomers as $topIncomer)
{
foreach($TopTwentyExpensers as $topExpenser)
{
if($topIncomer->name == $topExpenser->name)
{
$topTwentyRevenuers[] = (object) array('name' => $topIncomer->name, 'total_amount' => $topIncomer->total_amount - $topExpenser->total_amount);
}
}
}
foreach($topTwentyRevenuers as $Incom)
{
$inc = round(100*($Incom->total_amount/$TotalRewenue), 2);
//dd($Incom->total_amount);
$yearlyReportExists = DB::table('yearly_report')
->where('company_id', $id)
->where('year', $dataYear)
->where('client_name', $Incom->name)
->Where('type','LIKE','%highestGenerator%')
->first();
if(!empty($yearlyReportExists)){
DB::table('yearly_report')
->where('id', $yearlyReportExists->id)
->update(['company_id'=>$id,'year'=>$dataYear,'type'=>"highestGenerator",'client_name'=>$Incom->name,'amount'=>round($Incom->total_amount, 2),'inc'=>$inc]);
}
else{
dd($inc);
DB::table('yearly_report')->insert(['company_id'=>$id,'year'=>$dataYear,'type'=>"highestGenerator",'client_name'=>$Incom->name,'amount'=>round($Incom->total_amount, 2),'inc'=>$inc]);
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire