<?php 
ob_start();
session_start();
include ("../_init.php");

if (!is_loggedin()) {
  redirect(root_url() . '/index.php?redirect_to=' . url());
}

if (user_group_id() != 1 && !has_permission('access', 'read_supplier')) {
  redirect(root_url() . '/'.ADMINDIRNAME.'/dashboard.php');
}

$document->setTitle(trans('Proveedores'));
include("header.php"); 
include("left_sidebar.php");
?>

<div class="content-wrapper">
  <section class="content-header">
    <h1>
      <?php echo trans('Proveedores'); ?>
      <small><?php echo store('name'); ?></small>
    </h1>
    <ol class="breadcrumb">
      <li><a href="dashboard.php"><i class="fa fa-dashboard"></i> Inicio</a></li>
      <li class="active">Proveedores</li>
    </ol>
  </section>

  <section class="content">
    <?php if (user_group_id() == 1 || has_permission('access', 'create_supplier')) : ?>
      <div class="box box-info<?php echo create_box_state(); ?>">
        <div class="box-header with-border">
          <h3 class="box-title">
            <span class="fa fa-fw fa-plus"></span> Agregar/Editar Proveedor
          </h3>
          <button type="button" class="btn btn-box-tool" data-widget="collapse">
            <i class="fa <?php echo !create_box_state() ? 'fa-minus' : 'fa-plus'; ?>"></i>
          </button>
        </div>

        <!-- Reutiliza el mismo formulario -->
        <div class="box-body">
          <?php include('proveedores.php'); ?>
        </div>
      </div>
    <?php endif; ?>
  </div>
    <div class="box box-success">
      <div class="box-header">
        <h3 class="box-title">Listado de Proveedores</h3>
      </div>
      <div class="box-body">
        <div class="table-responsive">
          <!-- Reutiliza la tabla de proveedores.php -->
          <?php include('proveedores_tabla.php'); ?>
        </div>
      </div>
    </div>
  </section>
</div>

<?php include("footer.php"); ?>
