@php
    $tblStats = '<table class="table table-bordered"><tr class="bg-info text-black"><td class="font-weight-bold">کل کرایہ</td>
    <td class="font-weight-bold">کل خرچ</td><td class="font-weight-bold">کل آئل</td><td class="font-weight-bold">کل دن</td></tr>';
    $tblStats .= '<tr class="text-black">';
    $avg = 0;
    $total_freight =$trips->trip_details !=null? $trips->trip_details->sum('final_total_amount'):0;
    $total_expenses = $trips->trip_expenses!=null?$trips->trip_expenses->sum('total_amount'):0;
    $total_oil = $trips->trip_oils!=null?$trips->trip_oils->sum('total_amount'):0;
    $profit = $total_freight -($total_expenses + $total_oil);
    $datetime1 = new DateTime($trips->starting_date);
    $datetime2 = new DateTime($trips->ending_date);
    if ($datetime1 == $datetime2) {
        $days = 1;
    } else {
        $interval = $datetime1->diff($datetime2);
        $days = $interval->format('%a'); //now do whatever you like with $days
             $days=$days+1;
    }
    $tblStats .= '<td>' . number_format($total_freight, 0) . '</td>';
    $tblStats .= '<td>' . number_format($total_expenses, 0) . '</td>';
    $tblStats .= '<td>' . number_format($total_oil, 0) . '</td>';
    $tblStats .= '<td>' . number_format($days, 0) . '</td>';
    $avg = $profit/$days;

    $tblStats .= '</tr><tr><td colspan="4"></td></tr>';
    $tblStats .= '<tr class="text-black">';
    $tblStats .= '<td colspan="2" class="font-weight-bold">فی دن بچت</td>';
    $tblStats .= '<td colspan="2">' . number_format($avg, 0) . ' </td>';
    $tblStats .= '</tr><tr><td colspan="4"></td></tr>';
    $tblStats .= '<tr class="text-black">';
    $tblStats .= '<td colspan="2" class="font-weight-bold"> کل بچت</td>';
    $tblStats .= '<td colspan="2">' . number_format($profit, 0) . ' </td>';
    $tblStats .= '</tr><tr><td colspan="4"></td></tr>';
    $tblStats .= '</table>';
@endphp
<span class="tooltip1 pull-left text-danger" style="text-align: left!important;">
    <i class="fa fa-info-circle"></i> فی دن بچت
    <span class="tooltiptext" style="margin-left: -130px;">{!! $tblStats !!}</span>
</span>
