mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Merge branch 'dev/albaranes_pdf_2' into 'main'
Implementada la logica para la creacion de albaranes en PDF See merge request jjimenez/safekat!277
This commit is contained in:
@ -8,50 +8,30 @@ use App\Controllers\BaseController;
|
||||
class PrintAlbaranes extends BaseController
|
||||
{
|
||||
|
||||
public function index($id_pedido)
|
||||
public function index($albaran_id)
|
||||
{
|
||||
|
||||
/*$presupuestoModel = model('App\Models\Presupuestos\PresupuestoModel');
|
||||
$lineasPresupuestoModel = model('App\Models\Presupuestos\PresupuestoLineaModel');
|
||||
$direccionesEnvioModel = model('App\Models\Presupuestos\PresupuestoDireccionesModel');
|
||||
$presupuestoAcabadosModel = model('App\Models\Presupuestos\PresupuestoAcabadosModel');
|
||||
$albaranModel = model('App\Models\Pedidos\AlbaranModel');
|
||||
$lineasAlbaranModel = model('App\Models\Pedidos\AlbaranLineaModel');
|
||||
|
||||
$data['presupuesto'] = $presupuestoModel->getResourceForPdf($id_pedido)->get()->getRow();
|
||||
$data['lp_ByN'] = $lineasPresupuestoModel->getResourceByNForPdf($id_pedido)->get()->getRow();
|
||||
$data['lp_Color'] = $lineasPresupuestoModel->getResourceColorForPdf($id_pedido)->get()->getRow();
|
||||
$data['lp_Cubierta'] = $lineasPresupuestoModel->getResourceCubiertaForPdf($id_pedido)->get()->getRow();
|
||||
$data['lp_Sobrecubierta'] = $lineasPresupuestoModel->getResourceSobrecubiertaForPdf($id_pedido)->get()->getRow();
|
||||
$data['acabado_cubierta'] = $presupuestoAcabadosModel->getAcabadoCubiertaForPdf($id_pedido)->get()->getRow();
|
||||
$data['acabado_sobrecubierta'] = $presupuestoAcabadosModel->getAcabadoSobrecubiertaForPdf($id_pedido)->get()->getRow();
|
||||
$data['acabado_reserva_uvi'] = $presupuestoAcabadosModel->getAcabadoReservaUviForPdf($id_pedido)->get()->getRow();
|
||||
$data['direccionesEnvio'] = $direccionesEnvioModel->getResourceForPdf($id_pedido)->get()->getResultObject();*/
|
||||
$data['albaran'] = $albaranModel->getResourceForPdf($albaran_id)->get()->getRow();
|
||||
$data['albaranLineas'] = $lineasAlbaranModel->getResourceForPdf($albaran_id)->get()->getResultObject();
|
||||
|
||||
$data = $id_pedido;
|
||||
|
||||
return view(getenv('theme.path') . 'pdfs/albaran');
|
||||
return view(getenv('theme.path') . 'pdfs/albaran', $data);
|
||||
}
|
||||
|
||||
public function generar($presupuesto_id)
|
||||
public function generar($albaran_id)
|
||||
{
|
||||
|
||||
// Cargar modelos
|
||||
/*$presupuestoModel = model('App\Models\Presupuestos\PresupuestoModel');
|
||||
$lineasPresupuestoModel = model('App\Models\Presupuestos\PresupuestoLineaModel');
|
||||
$direccionesEnvioModel = model('App\Models\Presupuestos\PresupuestoDireccionesModel');
|
||||
$presupuestoAcabadosModel = model('App\Models\Presupuestos\PresupuestoAcabadosModel');
|
||||
$albaranModel = model('App\Models\Pedidos\AlbaranModel');
|
||||
$lineasAlbaranModel = model('App\Models\Pedidos\AlbaranLineaModel');
|
||||
|
||||
// Informacion del presupuesto
|
||||
$data['presupuesto'] = $presupuestoModel->getResourceForPdf($presupuesto_id)->get()->getRow();
|
||||
$data['lp_ByN'] = $lineasPresupuestoModel->getResourceByNForPdf($presupuesto_id)->get()->getRow();
|
||||
$data['lp_Color'] = $lineasPresupuestoModel->getResourceColorForPdf($presupuesto_id)->get()->getRow();
|
||||
$data['lp_Cubierta'] = $lineasPresupuestoModel->getResourceCubiertaForPdf($presupuesto_id)->get()->getRow();
|
||||
$data['lp_Sobrecubierta'] = $lineasPresupuestoModel->getResourceSobrecubiertaForPdf($presupuesto_id)->get()->getRow();
|
||||
$data['acabado_cubierta'] = $presupuestoAcabadosModel->getAcabadoCubiertaForPdf($presupuesto_id)->get()->getRow();
|
||||
$data['acabado_sobrecubierta'] = $presupuestoAcabadosModel->getAcabadoSobrecubiertaForPdf($presupuesto_id)->get()->getRow();
|
||||
$data['acabado_reserva_uvi'] = $presupuestoAcabadosModel->getAcabadoReservaUviForPdf($presupuesto_id)->get()->getRow();
|
||||
$data['direccionesEnvio'] = $direccionesEnvioModel->getResourceForPdf($presupuesto_id)->get()->getResultObject();*/
|
||||
$data['albaran'] = $albaranModel->getResourceForPdf($albaran_id)->get()->getRow();
|
||||
$data['albaranLineas'] = $lineasAlbaranModel->getResourceForPdf($albaran_id)->get()->getResultObject();
|
||||
|
||||
$data = $presupuesto_id;
|
||||
|
||||
// Crear una instancia de Dompdf
|
||||
$options = new \Dompdf\Options();
|
||||
@ -61,7 +41,7 @@ class PrintAlbaranes extends BaseController
|
||||
$dompdf = new \Dompdf\Dompdf($options);
|
||||
|
||||
// Contenido HTML del documento
|
||||
$dompdf->loadHtml(view(getenv('theme.path').'pdfs/albaran'));
|
||||
$dompdf->loadHtml(view(getenv('theme.path').'pdfs/albaran', $data));
|
||||
|
||||
// Establecer el tamaño del papel
|
||||
$dompdf->setPaper('A4', 'portrait');
|
||||
@ -73,7 +53,7 @@ class PrintAlbaranes extends BaseController
|
||||
$output = $dompdf->output();
|
||||
|
||||
// Establecer las cabeceras para visualizar en lugar de descargar
|
||||
$file_name = "presupuesto-$presupuesto_id.pdf";
|
||||
$file_name = "presupuesto-$albaran_id.pdf";
|
||||
return $this->response
|
||||
->setStatusCode(200)
|
||||
->setHeader('Content-Type', 'application/pdf')
|
||||
|
||||
@ -38,4 +38,29 @@ class AlbaranLineaModel extends \App\Models\BaseModel
|
||||
protected $updatedField = 'updated_at';
|
||||
protected $deletedField = 'deleted_at';
|
||||
|
||||
/**
|
||||
* Get resource data for creating PDFs.
|
||||
*
|
||||
* @param string $search
|
||||
*
|
||||
* @return \CodeIgniter\Database\BaseBuilder
|
||||
*/
|
||||
public function getResourceForPdf($albaran_id = -1)
|
||||
{
|
||||
$builder = $this->db
|
||||
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.id AS id, t1.albaran_id AS albaran_id, t1.titulo AS titulo, t1.isbn AS isbn,
|
||||
t1.ref_cliente AS ref_cliente, t1.cantidad AS cantidad, t1.cajas AS cajas,
|
||||
t1.ejemplares_por_caja AS ejemplares_por_caja, t1.precio_unidad AS precio_unidad,
|
||||
t1.total AS total"
|
||||
);
|
||||
|
||||
$builder->where("t1.deleted_at IS NULL");
|
||||
$builder->where("t1.albaran_id", $albaran_id);
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
}
|
||||
@ -110,4 +110,33 @@ class AlbaranModel extends \App\Models\BaseModel
|
||||
|
||||
return $return_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get resource data for creating PDFs.
|
||||
*
|
||||
* @param string $search
|
||||
*
|
||||
* @return \CodeIgniter\Database\BaseBuilder
|
||||
*/
|
||||
public function getResourceForPdf($albaran_id = -1)
|
||||
{
|
||||
$builder = $this->db
|
||||
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.id AS id, t1.pedido_id AS pedido_id, t1.presupuesto_id AS presupuesto_id,
|
||||
t1.presupuesto_direccion_id AS presupuesto_direccion_id, t1.cliente_id AS cliente_id,
|
||||
t1.serie_id AS serie_id, t1.numero_albaran AS numero_albaran, t1.mostrar_precios AS mostrar_precios,
|
||||
t1.total AS total, t1.direccion_albaran AS direccion_albaran, t1.att_albaran AS att_albaran,
|
||||
t1.user_created_id AS user_created_id, t1.user_updated_id AS user_updated_id,
|
||||
t1.created_at AS created_at, t1.updated_at AS updated_at,
|
||||
t2.nombre AS cliente"
|
||||
);
|
||||
$builder->join("clientes t2", "t1.cliente_id = t2.id", "left");
|
||||
|
||||
$builder->where("t1.deleted_at IS NULL");
|
||||
$builder->where("t1.id", $albaran_id);
|
||||
|
||||
return $builder;
|
||||
}
|
||||
}
|
||||
@ -28,38 +28,8 @@
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php // Para probar
|
||||
$pedido = new stdClass();
|
||||
|
||||
$pedido->numero = 1234;
|
||||
$pedido->pedido_libro = new stdClass();
|
||||
$pedido->pedido_libro->id = 111;
|
||||
$pedido->customer_nombre = 'John Doe';
|
||||
$pedido->customer_address = '123 Main St, Anytown, USA';
|
||||
$pedido->customer_att = 'Jane Doe';
|
||||
$pedido->mostar_precios = true;
|
||||
|
||||
$linea1 = new stdClass();
|
||||
$linea1->cantidad = 10;
|
||||
$linea1->descripcion = 'Libro1';
|
||||
$linea1->isbn = '123-456-789';
|
||||
$linea1->ref_cliente = 'REF1';
|
||||
$linea1->cajas = 5;
|
||||
$linea1->ejemplares_por_caja = 2;
|
||||
$linea1->precio_unidad = 5;
|
||||
$linea1->total = 20;
|
||||
|
||||
$linea2 = new stdClass();
|
||||
$linea2->cantidad = 4;
|
||||
$linea2->descripcion = 'Libro2';
|
||||
$linea2->isbn = '987-654-321';
|
||||
$linea2->ref_cliente = 'REF2';
|
||||
$linea2->cajas = 2;
|
||||
$linea2->ejemplares_por_caja = 2;
|
||||
$linea2->precio_unidad = 10;
|
||||
$linea2->total = 40;
|
||||
|
||||
$pedido->lineas = [$linea1, $linea2];
|
||||
<?php
|
||||
$mostrarPrecios = $albaran->mostrar_precios == 1;
|
||||
?>
|
||||
|
||||
|
||||
@ -70,19 +40,19 @@
|
||||
Nº ALBARÁN:
|
||||
</th>
|
||||
<th class="num_albaran">
|
||||
<?= $pedido->numero ?>
|
||||
<?= $albaran->id ?>
|
||||
</th>
|
||||
<th class="intro_num_pedido">
|
||||
Nº PEDIDO:
|
||||
</th>
|
||||
<th class="num_pedido">
|
||||
<?= $pedido->pedido_libro->id ?>
|
||||
<?= $albaran->pedido_id ?>
|
||||
</th>
|
||||
<th class="intro_fecha">
|
||||
FECHA:
|
||||
</th>
|
||||
<th class="fecha">
|
||||
<?= date('d/m/Y'); ?>
|
||||
<?= date('d-m-Y', strtotime($albaran->created_at)) ?>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -90,13 +60,13 @@
|
||||
<tr>
|
||||
<td class="intro_cliente" colspan="6">Cliente:</td>
|
||||
<tr>
|
||||
<td class="cliente" colspan="6"><?= $pedido->customer_nombre ?></td>
|
||||
<td class="cliente" colspan="6"><?= $albaran->cliente ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="att" colspan="6">Att: <?= $pedido->customer_att ?></td>
|
||||
<td class="att" colspan="6">Att: <?= $albaran->att_albaran ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="direccion" colspan="6"><?= $pedido->customer_address ?></td>
|
||||
<td class="direccion" colspan="6"><?= $albaran->direccion_albaran ?></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@ -110,7 +80,7 @@
|
||||
<th class="concepto">Ref. Cliente</th>
|
||||
<th>Cajas</th>
|
||||
<th>Ejempl./Cajas</th>
|
||||
<?php if ($pedido->mostar_precios): ?>
|
||||
<?php if ($mostrarPrecios): ?>
|
||||
<th class="precio_unidad">€/ud.</th>
|
||||
<th class="subtotal">Subtotal</th>
|
||||
<?php endif; ?>
|
||||
@ -120,7 +90,7 @@
|
||||
<?php
|
||||
$total = 0;
|
||||
$total_precio = 0;
|
||||
foreach ($pedido->lineas as $linea):
|
||||
foreach ($albaranLineas as $linea):
|
||||
?>
|
||||
|
||||
<?php
|
||||
@ -130,7 +100,7 @@
|
||||
<tr>
|
||||
<td class="num_unidades"><?= $linea->cantidad ?></td>
|
||||
<td>
|
||||
<div><?= $linea->descripcion ?></div>
|
||||
<div><?= $linea->titulo ?></div>
|
||||
</td>
|
||||
<td>
|
||||
<div><?= $linea->isbn ?></div>
|
||||
@ -139,8 +109,8 @@
|
||||
<div><?= $linea->ref_cliente ?></div>
|
||||
</td>
|
||||
<td><?= $linea->cajas ?></td>
|
||||
<td class="ejemplares-caja <?= $pedido->mostar_precios ? 'precio' : '' ?>"><?= $linea->ejemplares_por_caja ?></td>
|
||||
<?php if ($pedido->mostar_precios): ?>
|
||||
<td class="ejemplares-caja <?= $mostrarPrecios ? 'precio' : '' ?>"><?= $linea->ejemplares_por_caja ?></td>
|
||||
<?php if ($mostrarPrecios): ?>
|
||||
<td class="precio_unidad">
|
||||
<div><?= $linea->precio_unidad ?></div>
|
||||
</td>
|
||||
@ -172,7 +142,7 @@
|
||||
<td class="ejemplares-caja">
|
||||
<div></div>
|
||||
</td>
|
||||
<?php if ($pedido->mostar_precios): ?>
|
||||
<?php if ($mostrarPrecios): ?>
|
||||
<td class="precio_unidad">
|
||||
<div></div>
|
||||
</td>
|
||||
@ -191,7 +161,7 @@
|
||||
<td class="intro_recibi">
|
||||
RECIBÍ
|
||||
</td>
|
||||
<?php if ($pedido->mostar_precios): ?>
|
||||
<?php if ($mostrarPrecios): ?>
|
||||
<td class="intro_total">
|
||||
TOTAL
|
||||
</td>
|
||||
@ -202,7 +172,6 @@
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -106,7 +106,7 @@ table.datos-albaran th.intro_fecha {
|
||||
}
|
||||
|
||||
table.datos-albaran th.fecha {
|
||||
width: 10%;
|
||||
width: 15%;
|
||||
text-align: right;
|
||||
font-weight: lighter;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user