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
|
class PrintAlbaranes extends BaseController
|
||||||
{
|
{
|
||||||
|
|
||||||
public function index($id_pedido)
|
public function index($albaran_id)
|
||||||
{
|
{
|
||||||
|
|
||||||
/*$presupuestoModel = model('App\Models\Presupuestos\PresupuestoModel');
|
$albaranModel = model('App\Models\Pedidos\AlbaranModel');
|
||||||
$lineasPresupuestoModel = model('App\Models\Presupuestos\PresupuestoLineaModel');
|
$lineasAlbaranModel = model('App\Models\Pedidos\AlbaranLineaModel');
|
||||||
$direccionesEnvioModel = model('App\Models\Presupuestos\PresupuestoDireccionesModel');
|
|
||||||
$presupuestoAcabadosModel = model('App\Models\Presupuestos\PresupuestoAcabadosModel');
|
|
||||||
|
|
||||||
$data['presupuesto'] = $presupuestoModel->getResourceForPdf($id_pedido)->get()->getRow();
|
$data['albaran'] = $albaranModel->getResourceForPdf($albaran_id)->get()->getRow();
|
||||||
$data['lp_ByN'] = $lineasPresupuestoModel->getResourceByNForPdf($id_pedido)->get()->getRow();
|
$data['albaranLineas'] = $lineasAlbaranModel->getResourceForPdf($albaran_id)->get()->getResultObject();
|
||||||
$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 = $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
|
// Cargar modelos
|
||||||
/*$presupuestoModel = model('App\Models\Presupuestos\PresupuestoModel');
|
$albaranModel = model('App\Models\Pedidos\AlbaranModel');
|
||||||
$lineasPresupuestoModel = model('App\Models\Presupuestos\PresupuestoLineaModel');
|
$lineasAlbaranModel = model('App\Models\Pedidos\AlbaranLineaModel');
|
||||||
$direccionesEnvioModel = model('App\Models\Presupuestos\PresupuestoDireccionesModel');
|
|
||||||
$presupuestoAcabadosModel = model('App\Models\Presupuestos\PresupuestoAcabadosModel');
|
|
||||||
|
|
||||||
// Informacion del presupuesto
|
// Informacion del presupuesto
|
||||||
$data['presupuesto'] = $presupuestoModel->getResourceForPdf($presupuesto_id)->get()->getRow();
|
$data['albaran'] = $albaranModel->getResourceForPdf($albaran_id)->get()->getRow();
|
||||||
$data['lp_ByN'] = $lineasPresupuestoModel->getResourceByNForPdf($presupuesto_id)->get()->getRow();
|
$data['albaranLineas'] = $lineasAlbaranModel->getResourceForPdf($albaran_id)->get()->getResultObject();
|
||||||
$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 = $presupuesto_id;
|
|
||||||
|
|
||||||
// Crear una instancia de Dompdf
|
// Crear una instancia de Dompdf
|
||||||
$options = new \Dompdf\Options();
|
$options = new \Dompdf\Options();
|
||||||
@ -61,7 +41,7 @@ class PrintAlbaranes extends BaseController
|
|||||||
$dompdf = new \Dompdf\Dompdf($options);
|
$dompdf = new \Dompdf\Dompdf($options);
|
||||||
|
|
||||||
// Contenido HTML del documento
|
// 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
|
// Establecer el tamaño del papel
|
||||||
$dompdf->setPaper('A4', 'portrait');
|
$dompdf->setPaper('A4', 'portrait');
|
||||||
@ -73,7 +53,7 @@ class PrintAlbaranes extends BaseController
|
|||||||
$output = $dompdf->output();
|
$output = $dompdf->output();
|
||||||
|
|
||||||
// Establecer las cabeceras para visualizar en lugar de descargar
|
// Establecer las cabeceras para visualizar en lugar de descargar
|
||||||
$file_name = "presupuesto-$presupuesto_id.pdf";
|
$file_name = "presupuesto-$albaran_id.pdf";
|
||||||
return $this->response
|
return $this->response
|
||||||
->setStatusCode(200)
|
->setStatusCode(200)
|
||||||
->setHeader('Content-Type', 'application/pdf')
|
->setHeader('Content-Type', 'application/pdf')
|
||||||
|
|||||||
@ -38,4 +38,29 @@ class AlbaranLineaModel extends \App\Models\BaseModel
|
|||||||
protected $updatedField = 'updated_at';
|
protected $updatedField = 'updated_at';
|
||||||
protected $deletedField = 'deleted_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;
|
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>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<?php // Para probar
|
<?php
|
||||||
$pedido = new stdClass();
|
$mostrarPrecios = $albaran->mostrar_precios == 1;
|
||||||
|
|
||||||
$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];
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
@ -70,19 +40,19 @@
|
|||||||
Nº ALBARÁN:
|
Nº ALBARÁN:
|
||||||
</th>
|
</th>
|
||||||
<th class="num_albaran">
|
<th class="num_albaran">
|
||||||
<?= $pedido->numero ?>
|
<?= $albaran->id ?>
|
||||||
</th>
|
</th>
|
||||||
<th class="intro_num_pedido">
|
<th class="intro_num_pedido">
|
||||||
Nº PEDIDO:
|
Nº PEDIDO:
|
||||||
</th>
|
</th>
|
||||||
<th class="num_pedido">
|
<th class="num_pedido">
|
||||||
<?= $pedido->pedido_libro->id ?>
|
<?= $albaran->pedido_id ?>
|
||||||
</th>
|
</th>
|
||||||
<th class="intro_fecha">
|
<th class="intro_fecha">
|
||||||
FECHA:
|
FECHA:
|
||||||
</th>
|
</th>
|
||||||
<th class="fecha">
|
<th class="fecha">
|
||||||
<?= date('d/m/Y'); ?>
|
<?= date('d-m-Y', strtotime($albaran->created_at)) ?>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -90,13 +60,13 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="intro_cliente" colspan="6">Cliente:</td>
|
<td class="intro_cliente" colspan="6">Cliente:</td>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="cliente" colspan="6"><?= $pedido->customer_nombre ?></td>
|
<td class="cliente" colspan="6"><?= $albaran->cliente ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="att" colspan="6">Att: <?= $pedido->customer_att ?></td>
|
<td class="att" colspan="6">Att: <?= $albaran->att_albaran ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="direccion" colspan="6"><?= $pedido->customer_address ?></td>
|
<td class="direccion" colspan="6"><?= $albaran->direccion_albaran ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@ -110,7 +80,7 @@
|
|||||||
<th class="concepto">Ref. Cliente</th>
|
<th class="concepto">Ref. Cliente</th>
|
||||||
<th>Cajas</th>
|
<th>Cajas</th>
|
||||||
<th>Ejempl./Cajas</th>
|
<th>Ejempl./Cajas</th>
|
||||||
<?php if ($pedido->mostar_precios): ?>
|
<?php if ($mostrarPrecios): ?>
|
||||||
<th class="precio_unidad">€/ud.</th>
|
<th class="precio_unidad">€/ud.</th>
|
||||||
<th class="subtotal">Subtotal</th>
|
<th class="subtotal">Subtotal</th>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
@ -120,7 +90,7 @@
|
|||||||
<?php
|
<?php
|
||||||
$total = 0;
|
$total = 0;
|
||||||
$total_precio = 0;
|
$total_precio = 0;
|
||||||
foreach ($pedido->lineas as $linea):
|
foreach ($albaranLineas as $linea):
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
@ -130,7 +100,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="num_unidades"><?= $linea->cantidad ?></td>
|
<td class="num_unidades"><?= $linea->cantidad ?></td>
|
||||||
<td>
|
<td>
|
||||||
<div><?= $linea->descripcion ?></div>
|
<div><?= $linea->titulo ?></div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div><?= $linea->isbn ?></div>
|
<div><?= $linea->isbn ?></div>
|
||||||
@ -139,8 +109,8 @@
|
|||||||
<div><?= $linea->ref_cliente ?></div>
|
<div><?= $linea->ref_cliente ?></div>
|
||||||
</td>
|
</td>
|
||||||
<td><?= $linea->cajas ?></td>
|
<td><?= $linea->cajas ?></td>
|
||||||
<td class="ejemplares-caja <?= $pedido->mostar_precios ? 'precio' : '' ?>"><?= $linea->ejemplares_por_caja ?></td>
|
<td class="ejemplares-caja <?= $mostrarPrecios ? 'precio' : '' ?>"><?= $linea->ejemplares_por_caja ?></td>
|
||||||
<?php if ($pedido->mostar_precios): ?>
|
<?php if ($mostrarPrecios): ?>
|
||||||
<td class="precio_unidad">
|
<td class="precio_unidad">
|
||||||
<div><?= $linea->precio_unidad ?></div>
|
<div><?= $linea->precio_unidad ?></div>
|
||||||
</td>
|
</td>
|
||||||
@ -172,7 +142,7 @@
|
|||||||
<td class="ejemplares-caja">
|
<td class="ejemplares-caja">
|
||||||
<div></div>
|
<div></div>
|
||||||
</td>
|
</td>
|
||||||
<?php if ($pedido->mostar_precios): ?>
|
<?php if ($mostrarPrecios): ?>
|
||||||
<td class="precio_unidad">
|
<td class="precio_unidad">
|
||||||
<div></div>
|
<div></div>
|
||||||
</td>
|
</td>
|
||||||
@ -191,7 +161,7 @@
|
|||||||
<td class="intro_recibi">
|
<td class="intro_recibi">
|
||||||
RECIBÍ
|
RECIBÍ
|
||||||
</td>
|
</td>
|
||||||
<?php if ($pedido->mostar_precios): ?>
|
<?php if ($mostrarPrecios): ?>
|
||||||
<td class="intro_total">
|
<td class="intro_total">
|
||||||
TOTAL
|
TOTAL
|
||||||
</td>
|
</td>
|
||||||
@ -202,7 +172,6 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</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 {
|
table.datos-albaran th.fecha {
|
||||||
width: 10%;
|
width: 15%;
|
||||||
text-align: right;
|
text-align: right;
|
||||||
font-weight: lighter;
|
font-weight: lighter;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user