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

if (isset($_SESSION['uid'])) {
    $tabela = 'itemserv';
    $coluna = 'iditems ASC';
    $ret = "";
    $con = DB::conecta();
    $sql = "SELECT * FROM ".$tabela." WHERE PEDIDO='".$_SESSION['CODIGO']."' ORDER BY ".$coluna;
    $bs = $con->prepare($sql);
    $bs->execute();
    $row = $bs->fetchAll(PDO::FETCH_ASSOC);
    $con = null;
    if (count($row) == 0) {
        echo "<strong><h5>Nenhum Serviço adicionado!</h5></strong>";
    } else {

        $ret = "";
        foreach ($row as $r) {
            $ret .= "<tr>";
            $ret .= "<td>" . FC::nomeproduto($r['PRODUTO']) . "</td>";
            $ret .= "<td class='col-3 text-center'><a href='#'  id='" . $r['iditems'] . "' class='btn btn-secondary btn-sm rounded-2' onclick='alteraqtde2(" . $r['iditems'] . "," . $r['QUANTIDADE'] . "," . $r['PRECO'] . ");' >" . $r['QUANTIDADE'] . "<i class='fas fa-pen ms-1'></i></a></td>";
            $ret .= "<td class='col-2 text-center'>R$ ".number_format($r['TOTAL'],2,',','.')."</td>";
            $ret .= "<td class='col-2 text-end'><a href='#'  id='" . $r['iditems'] . "' class='btn btn-link btn-sm   text-secondary' onclick='excluirserv(" . $r['iditems'] . ");' ><i class='fas fa-trash'></i></a></td>";

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