<?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 ABERTURA,idservicos,CODIGO,RAZAO,TOTAL,STATUS FROM servicos WHERE STATUS<>'F' ORDER BY ABERTURA DESC";
    $bs = $con->prepare($sql);
    $bs->execute();
    $row = $bs->fetchAll(PDO::FETCH_ASSOC);
    //$con = null;
    if (count($row) == 0) {
        echo "<h5><i class='fas fa-exclamation-triangle me-2'></i>Nenhuma OS cadastrada!</h5>";
    } else {

        $ret = "";
        foreach ($row as $r) {
            $ret .= "<tr>";
            
            $ret .= "<td class='col-2 text-center'>" . FC::dataBR($r['ABERTURA']) . "</td>";
            $ret .= "<td  class='text-start'>" . $r['RAZAO'] . "</td>";
            $ret .= "<td class='col-2 text-center'>R$ " . number_format($r['TOTAL'],2,',','.') . "</td>";
            $ret .= "<td class='col-1 text-center'>" . $r['STATUS']. "</td>";
            $ret .= "<td class='col-3 text-end'><a href='#' id='".$r['idservicos']."' class='btn btn-link btn-sm   text-secondary' onclick='dados($(this).attr(\"id\"));' ><i class='fas fa-pen '></i></a><a href='#' id='".$r['CODIGO']."' class='btn btn-link btn-sm   text-secondary' onclick='excluiros($(this).attr(\"id\"));' ><i class='fas fa-trash'></i></a></td>";

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