@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>
    <td class="font-weight-bold">موجودہ کل بچت</td></tr>';
    $tblStats .= '<tr class="text-black">';

    $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;
    $current_profit = $total_freight -($total_oil +$total_expenses );
    $datetime1 = new DateTime($trips->starting_date);
    $datetime2 = new DateTime($trips->ending_date);
    if ($datetime1 == $datetime2) {
        $current_days=1;
    } else {
        $interval = $datetime1->diff($datetime2);
        $days = $interval->format('%a'); //now do whatever you like with $days
             $current_days =($days== 0) ? 1 : ($days +1);

    }
        $previous_trip=$trips->calculate_previous_profit($trips->id);
    $previous_profit=$previous_trip['profit'];
    $previous_days=$previous_trip['days'];
    $last_trip_id=$previous_trip['last_trip_id'];
     $tblStats .= '<td>' . $last_trip_id . '</td>';
     $tblStats .= '<td>' . number_format($previous_days, 0) . '</td>';
    $tblStats .= '<td>' . number_format($previous_profit, 0) . '</td>';
    $tblStats .= '<td>' . number_format($current_days, 0) . '</td>';
    $tblStats .= '<td>' . number_format($current_profit, 0) . '</td>';
    $total_profit= $current_profit+$previous_profit;
    $avg = ($total_profit)/($current_days+$previous_days);
    $tblStats .= '</tr><tr><td colspan="4"></td></tr>';
    $tblStats .= '<tr class="text-black">';
    $tblStats .= '<td class="font-weight-bold" colspan="2">فی دن بچت</td>';
    $tblStats .= '<td colspan="3">' . number_format($avg, 0) . ' </td>';
    $tblStats .= '</tr><tr><td colspan="5"></td></tr>';
    $tblStats .= '<tr class="text-black">';
    $tblStats .= '<td class="font-weight-bold" colspan="2">کل بچت</td>';
    $tblStats .= '<td colspan="3">' . number_format($total_profit, 0) . ' </td>';
    $tblStats .= '</tr><tr><td colspan="5"></td></tr>';
    $tblStats .= '</table>';
@endphp
<span class="tooltip1 pull-right text-danger" style="text-align: right!important;">
    <i class="fa fa-info-circle"></i> کل بچت
    <span class="tooltiptext" style="margin-left: -130px;">{!! $tblStats !!}</span>
</span>
