Skip to content

Instantly share code, notes, and snippets.

@aranajhonny
Created December 7, 2016 02:59
Show Gist options
  • Save aranajhonny/fdd819e447cb9f2475365a4eabb3c2de to your computer and use it in GitHub Desktop.
Save aranajhonny/fdd819e447cb9f2475365a4eabb3c2de to your computer and use it in GitHub Desktop.
public function all()
{
$c = new compra();
$compras = $c->get_compras() ;
$data = array();
foreach ($compras as $com) {
$fecha = date_create($com['fecha']);//funcion para voltear la fecha
$row = array($com['codigo'],
$com['proveedor'],
date_format($fecha, 'd-m-Y'),//se voltea la fecha
$com['monto'],
'<a data-toggle="tooltip" title="Ver" href="javascript:void(0)" onclick=""><i class=" btn btn-xs btn-ver
glyphicon glyphicon-eye-open"></i></a>
<a data-toggle="tooltip" title="Eliminar" href="javascript:void(0)" onclick="" ><i class=" btn btn-xs btn-delete
glyphicon glyphicon-trash"></i></a>');
$data[] = $row;
}
$output = array("data" => $data);
echo json_encode($output);
}
public function get_compras()
{
try
{
$query = $this->dbh->prepare('
SELECT
c.cod_compra AS codigo,
p.razon_social AS proveedor,
c.fecha_actual AS fecha,
c.tot AS monto
FROM
compras AS c
INNER JOIN
proveedores AS p
ON c.id_prov = p.id_prov
ORDER BY
c.cod_compra
DESC
');
$query->execute();
return $query->fetchAll();
$this->dbh = null;
}catch (PDOException $e)
{
$e->getMessage();
}
}
<section class="content-header">
<h1>
Listado de compras
<small></small>
</h1>
<ol class="breadcrumb">
<a href="views/reportes/todas_las_compras.php" role="button" class="btn btn-delete"><span class="fa fa-file-pdf-o"></span> Imprimir</a>
</section>
<hr>
<section class="content">
<div class="row">
<div class="col-xs-12">
<div class="box box-primary">
<div class="box-header">
<h3 class="box-title"><strong>Listado de compras</strong></h3>
</div><!-- /.box-header -->
<div class="box-body">
<table id="table" class="table table-bordered table-striped">
<thead>
<tr>
<th>Codigo</th>
<th>Proveedor</th>
<th>Fecha</th>
<th>Monto</th>
<th style="width: 80px;" >Acci&oacuten</th>
</tr>
</thead>
</table>
</div><!-- /.box-body -->
</div><!-- /.box -->
</div><!-- /.col -->
</div><!-- /.row -->
</section><!-- /.content -->
</div>
<script type="text/javascript">
var table;
$(document).ready(function() {
//datatables
table = $('#table').DataTable({
"scrollX": true,
"processing": true, //Feature control the processing indicator.
"ajax": {
"url": "?controller=compras&action=all",
"type": "POST"
},
});
});
function recargar(){
table.ajax.reload(null,false); //reload datatable ajax
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment