<?php
session_start();
include "../classes/db.class.php";
include "../classes/fc.class.php";

if (isset($_SESSION['uid'])) {
    $tabela = $_SESSION['tabela'];
    $coluna = $_SESSION['coluna'];
    $ret = "";
    $con = DB::conecta();
    $sql = "SELECT * FROM ".$tabela." ORDER BY ".$coluna;
    $bs = $con->prepare($sql);
    $bs->execute();
    $row = $bs->fetchAll(PDO::FETCH_ASSOC);
    $con = null;
    if (count($row) == 0) {
        echo "<p><div class='alert alert-warning  texte-center w-100' ><h5><i class='fas fa-exclamation-triangle me-2'></i>Nenhuma OS cadastrada!</h5></div></p>";
    } else {

        $ret = "";
        foreach ($row as $r) {
            $ret .= "<tr>";
            
            $ret .= "<td class='col-2 text-center'>" . FC::dataBRhora($r['ABERTURA']) . "</td>";
            $ret .= "<td  class='col-5 text-start'>" . $r['SOLICITADO'] . "</td>";
            $ret .= "<td class='col-2 text-center'>R$ " . number_format($r['TOTAL'],2,',','.') . "</td>";
            $ret .= "<td class='col-3 text-end'><a href='#' id='" . $r['idservicos'] . "' class='btn btn-link btn-sm text-secondary' onclick='dados(" . $r['idservicos'] . ",1)'><i class='fas fa-edit'></i></a><a href='#' data-bs-toggle='modal' data-bs-target='#mDados' id='" . $r['idservicos'] . "' class='btn btn-link btn-sm   text-secondary' onclick='dados(" . $r['idservicos'] . ",2);' ><i class='fas fa-eye'></i></a></td>";

            $ret .="</tr>";
            
        }
        echo $ret;
        
    }
} else {
    echo "erro";
}
