<?php
// require_once "config/init.php";
include "includes/header.php";?>

<?php include "includes/navbar.php";?>

  <div id="wrapper">

    <!-- Sidebar -->
   <?php include "includes/sidebar.php";?>

    <div id="content-wrapper">

      <div class="container-fluid">

        <!-- Breadcrumbs-->
        <ol class="breadcrumb">
          <li class="breadcrumb-item">
            <a href="#">Ola</a>
          </li>
          <li class="breadcrumb-item active"><?php echo $_SESSION['nome'];?></li>
        </ol>

        <!-- Icon Cards-->
        <div class="row">		
         <div class="container">    
            
    <button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#exampleModalCadastrar">
  <i class="fas fa-fw fa-plus"></i> Cadastrar fornecedores
</button>

<!-- Modal -->
<div class="modal fade" id="exampleModalCadastrar" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Fornecedores</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
          <div class="container">
              <div class="col-sm-10">
                  
             
          <form action="" method="post" enctype="multipart/form-data">
           <?php $novoFornecedor->Cadastrar();?>
          <div class="form-group">
			  <label for="nome">Nome</label>
			  <input type="text" name="nome" class="form-control" autocomplete="off" required/>
			 </div>
       
       	     <div class="form-group">
			  <label for="nome">Endereco</label>
			  <input type="text" name="endereco" class="form-control" autocomplete="off" required/>
			 </div>

             <div class="form-group">
			  <label for="nome">Contacto 1</label>
			  <input type="number" name="cell1" class="form-control" autocomplete="off" required/>
			 </div>

             <div class="form-group">
			  <label for="nome">Contacto 2</label>
			  <input type="number" name="cell2" class="form-control" autocomplete="off" required/>
			 </div>
       		
			 <div class="form-group">
			  <input type="submit" name="cadastrar" class="btn btn-primary btn-block" value="Enviar"/>
			 </div>
	
		   </form>
         </div>
          </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
      </div>
    </div>
  </div>
</div>     
         
   <button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#exampleModalLista">
  <i class="fas fa-fw fa-eye"></i> Lista de fornecedores
</button>

<!-- Modal -->
<div class="modal fade" id="exampleModalLista" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Lista de forcedores</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
          <div class="container">
                 <table class="table">
                    <thead>
                        <tr>
                            <th>Item</th>
                            <th>Nome</th>
                            <th>Cell 1</th>
                            <th>Cell 2</th>
                            <th>Accao</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
                        $novoFornecedor->Deletar();
                        $item = 1;
                        $lista = $novoFornecedor->ListarFornecedor();
                        while($row = $database->fetch_assoc($lista)){
                        ?>
                        <tr>
                            <td><?php echo $item++;?></td>
                            <td><?php echo $row['nome'];?></td>
                           <td><?php echo $row['cell1'];?></td>
                            <td><?php echo $row['cell2'];?></td>
                            <?php 
                            if($_SESSION['nivel'] == 1){
                            ?>
                            <td><button type="button" class="btn btn-danger btn-sm"><a href="fornecedores.php?delete=<?php echo $row['id'];?>" style="text-decoration:none; color:white"><span>Apagar</span></a></button></td>
                        <?php }else{
                          echo "<td>N/A</td>";
                        }?>
                          </tr>
                        <?php } ?>
                    </tbody>
                 </table> 
             
         
          </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
      </div>
    </div>
  </div>
</div>      
             <!-- Button trigger modal -->
<button type="button" class="btn btn-danger btn-sm" data-toggle="modal" data-target="#exampleModal">
  <i class="fas fa-fw fa-pen"></i> Txenekar Producto
</button>

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Productos</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
          <div class="container">
              <div class="col-sm-10">
                  
             
          <form action="" method="post" enctype="multipart/form-data">
         <?php $novoFornecedor->Txenekar();?>
        <div class="form-group">
			  <label for="cliente">Nome do fornecedor</label>
          <select required name="supplyerName" class="form-control">
          <option></option>
           <?php $novoFornecedor->ListarArray();?>
        </select>
            </div>

			<div class="form-group">
			  <label for="productName">Nome do producto</label>
                <select required name="productName" class="form-control">
          <option></option>
          <?php $producto->ListarSelect();?>
        </select>
            </div>
			 
			 
			 <div class="form-group">
			  <label for="productQtd">Quantidade</label>
			  <input type="number" name="productQtd" class="form-control" autocomplete="off" required/>
			 </div>
       
       	 <div class="form-group">
			  <label for="dataPagamento">Data limite de pagamento</label>
			  <input type="date" name="dataPagamento" class="form-control" autocomplete="off" required/>
			 </div>
       		
			 <div class="form-group">
			  <input type="submit" name="txenekar" class="btn btn-primary btn-block" value="Enviar"/>
			 </div>
	
		   </form>
         </div>
          </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
      </div>
    </div>
  </div>
</div>


<button type="button" class="btn btn-info btn-sm">Valor Total Em Divida: <?php echo $novoFornecedor->SomaDivida();?></button>
      
 <br> <br>
 <div class="container-fluid">

<!-- Breadcrumbs-->

<!-- DataTables Example -->
<div class="card mb-3">
  <div class="card-header">
    <i class="fas fa-table"></i>
    <b>Lista de vendas</b></div>
  <div class="card-body">
    <div class="table-responsive">
      <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
        <thead>
          <tr>
            <th>Item</th>
            <th>Producto</th>
            <th>Qtd</th>
            <th>Preco de compra</th>
            <th>Total</th>
            <th>Fornecedor</th>
            <th>Data Pagmt.</th>
            <th>Pagar</th>
          </tr>
        </thead>
       
        <tbody>
            
          <?php 
          $novoFornecedor->PagarTxenekaFornecedor();
          $item =1;
          $listarVendas = $novoFornecedor->Listar();
          while($row = $database->fetch_assoc($listarVendas)){
          $idPro = $row['id'];
          $idFornecedor = $row['supplyerName'];

          $buscar = $database->query("SELECT * FROM fornecedores WHERE id='$idFornecedor'");
          $assoc = $database->fetch_assoc($buscar);
          $nomeFornecedor = $assoc['nome'];
            ?>
           <tr>   
            <td><?php echo $item++;?></td>
            <td><?php echo $row['productName'];?></td>
            <td><?php echo $row['productQtd'];?></td>
            <td><?php echo number_format($row['productPrice'],2,",",".");?> Mzn</td>
            <td><?php echo number_format($row['productTotal'],2,",",".");?> Mzn</td>
            <td><?php echo $nomeFornecedor;?></td>
             <td><?php echo $row['dataPagamento'];?></td>
                  
        
        <?php 
if($_SESSION['nivel']==1){
    ?>      
                        <!-- Button trigger modal -->
<td><button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#exampleModalLong1<?php echo $idPro;?>">
  <span><i class="fa fa-coins" aria-hidden="true"></i></span>
</button></td>

<!-- Modal -->
<div class="modal fade" id="exampleModalLong1<?php echo $idPro;?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle1" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLongTitle1"></h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
                <p><h3>Confirmar pagamento de <font color="red"><?php echo $row['productName'];?>  de <?php echo $nomeFornecedor;?> ?</font></h3> </p>
        <button type="button" class="btn btn-danger btn-sm"><a href="fornecedores.php?pagar=<?php echo $idPro;?>" style="text-decoration:none; color:white"><span>Confirmar</span></a></button>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">Cancelar</button>
      </div>
    </div>
  </div>
</div>

 <?php }else{
     echo "<td>N/A</td>";
 }
          
          ?>  
          
          </tr>
        
        <?php }
          
          ?>  

         
      
   
               </tbody>
      </table>
    </div>
  </div>
  <div class="card-footer small text-muted">Jonas Dinis Chambela</div>
</div>



</div>

        </div>
      </div>
      <!-- /.container-fluid -->
		  </div>

		 </div>
        
        
        </div>

     
        

      <!-- /.container-fluid -->

      <!-- Sticky Footer -->
      <?php include "includes/footer.php";?>

    </div>
    <!-- /.content-wrapper -->

  </div>
  <!-- /#wrapper -->

  <!-- Scroll to Top Button-->
  <a class="scroll-to-top rounded" href="#page-top">
    <i class="fas fa-angle-up"></i>
  </a>

  <!-- Logout Modal-->
 <?php include "includes/logout_modal.php";?>
 <?php include "includes/sweatscripFooter.php";?>

  <!-- Bootstrap core JavaScript-->
  <script src="vendor/jquery/jquery.min.js"></script>
  <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

  <!-- Core plugin JavaScript-->
  <script src="vendor/jquery-easing/jquery.easing.min.js"></script>

  <!-- Page level plugin JavaScript-->
  <script src="vendor/chart.js/Chart.min.js"></script>
  <script src="vendor/datatables/jquery.dataTables.js"></script>
  <script src="vendor/datatables/dataTables.bootstrap4.js"></script>

  <!-- Custom scripts for all pages-->
  <script src="js/sb-admin.min.js"></script>

  <!-- Demo scripts for this page-->
  <script src="js/demo/datatables-demo.js"></script>
  <script src="js/demo/chart-area-demo.js"></script>

</body>

</html>
