<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
    <thead>
        <tr>
            <th>ID</th>
            <th>Kunde</th>
            <th>Job</th>
            <th>Dispo-Start</th>
            <th>Dispo-Ende</th>
            <th>Summe Netto (Brutto)</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th>ID</th>
            <th>Kunde</th>
            <th>Job</th>
            <th>Dispo-Start</th>
            <th>Dispo-Ende</th>
            <th>Summe Netto (Brutto)</th>
        </tr>
    </tfoot>
    <tbody>

        <?php
        require('../config.php');
        require('../EpiApi.php');
        require('../vendor/autoload.php');
        $Epi = new Epirent();


        $result = $Epi->requestEpiApi('/v1/order/filter?ir=True&ico=True&ia=False&icl=False&cl=' . Epirent_Mandant);

        $data_output = json_decode($result)->payload;


        foreach ($data_output as $order) {

            
            echo "<a class='button btn' href='/order'>";
            if ($order->is_confirmed == 1) {
                if($order->order_state != null){
                if ($order->order_state->is_invoice == 1) {

                    echo "<tr class='bg-info' >";
                } else {
                  echo "<tr class='bg-success clickable-row'>";
                }
            }
            else{
                  echo "<tr class='clickable-row'>";
            }
                } else {
                echo '<tr>';
            }
            echo "<td><a type='button' class='btn btn-secondary' href='orderdetails.php?OrderID=".$order->primary_key."'>" . $order->primary_key . "</a></td>";
            echo "<td>" . $order->contact->name . "</td>";
            echo "<td>" . $order->event . "</td>";
            echo "<td>" . date_format(new \DateTime($order->order_schedule[0]->date_start), 'd.m.Y') . " " . getTimeFromSeconds($order->order_schedule[0]->time_start) . "</td>";
            echo "<td>" . date_format(new \DateTime($order->order_schedule[0]->date_end), 'd.m.Y') . " " . getTimeFromSeconds($order->order_schedule[0]->time_end) . "</td>";
            echo "<td>" . $order->sum_net . " (" . $order->sum_gro . ")</td>";
            echo "</tr>";
           
        }

        function getTimeFromSeconds(string $timestring) {

            $hours = floor($timestring / 3600);
            $mins = floor($timestring / 60 % 60);
            $secs = floor($timestring % 60);

            $timeFormat = sprintf('%02d:%02d', $hours, $mins);

            return $timeFormat;
        }
        ?>

    </tbody>
</table>