diff --git a/ci4/app/Controllers/Pdf/PrintAlbaranes.php b/ci4/app/Controllers/Pdf/PrintAlbaranes.php index 6cd83907..506d9114 100644 --- a/ci4/app/Controllers/Pdf/PrintAlbaranes.php +++ b/ci4/app/Controllers/Pdf/PrintAlbaranes.php @@ -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') diff --git a/ci4/app/Models/Pedidos/AlbaranLineaModel.php b/ci4/app/Models/Pedidos/AlbaranLineaModel.php index 62f6ccd4..9253b2a2 100644 --- a/ci4/app/Models/Pedidos/AlbaranLineaModel.php +++ b/ci4/app/Models/Pedidos/AlbaranLineaModel.php @@ -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; + } + } \ No newline at end of file diff --git a/ci4/app/Models/Pedidos/AlbaranModel.php b/ci4/app/Models/Pedidos/AlbaranModel.php index 3834ca30..b79bb3c3 100644 --- a/ci4/app/Models/Pedidos/AlbaranModel.php +++ b/ci4/app/Models/Pedidos/AlbaranModel.php @@ -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; + } } \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/pdfs/albaran.php b/ci4/app/Views/themes/vuexy/pdfs/albaran.php index a5451d8e..2d49654b 100644 --- a/ci4/app/Views/themes/vuexy/pdfs/albaran.php +++ b/ci4/app/Views/themes/vuexy/pdfs/albaran.php @@ -28,38 +28,8 @@ - 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]; + mostrar_precios == 1; ?> @@ -70,19 +40,19 @@ Nº ALBARÁN: - numero ?> + id ?> Nº PEDIDO: - pedido_libro->id ?> + pedido_id ?> FECHA: - + created_at)) ?> @@ -90,13 +60,13 @@ Cliente: - customer_nombre ?> + cliente ?> - Att: customer_att ?> + Att: att_albaran ?> - customer_address ?> + direccion_albaran ?> @@ -110,7 +80,7 @@ Ref. Cliente Cajas Ejempl./Cajas - mostar_precios): ?> + €/ud. Subtotal @@ -120,7 +90,7 @@ lineas as $linea): + foreach ($albaranLineas as $linea): ?> cantidad ?> -
descripcion ?>
+
titulo ?>
isbn ?>
@@ -139,8 +109,8 @@
ref_cliente ?>
cajas ?> - ejemplares_por_caja ?> - mostar_precios): ?> + ejemplares_por_caja ?> +
precio_unidad ?>
@@ -172,7 +142,7 @@
- mostar_precios): ?> +
@@ -191,7 +161,7 @@ RECIBÍ - mostar_precios): ?> + TOTAL @@ -202,7 +172,6 @@ - diff --git a/ci4/app/Views/themes/vuexy/pdfs/albi.php b/ci4/app/Views/themes/vuexy/pdfs/albi.php deleted file mode 100644 index 17a54fdb..00000000 --- a/ci4/app/Views/themes/vuexy/pdfs/albi.php +++ /dev/null @@ -1,132 +0,0 @@ -@extends('layouts.pdf') - -@section('css') -{!! Html::style('css/pdf.albaran.css') !!} -@endsection - -@section('header') -@endsection - -@section('body') - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - -
- Nº ALBARÁN: - - {{ $obj->numero }} - - Nº PEDIDO: - - {{ $obj->pedido_libro->id }} - - FECHA: - - {{ $fecha_albaran_real_at ? $fecha_albaran_real_at->format('d/m/Y') : '-' }} -
Cliente:
{{ $obj->customer_nombre }}
Att: {{ $obj->customer_att }}
{{ $obj->customer_address }}
- - - - - - - - - - - @if($obj->mostar_precios) - - - @endif - - - - - @foreach($obj->lineas as $linea) - total; - ?> - - - - - - - - @if($obj->mostar_precios) - - - @endif - - @endforeach - - @if ($total < 5) - @for ($i = $total; $i < 7; $i++) - - - - - - - - @if($obj->mostar_precios) - - - @endif - - @endfor - @endif - -
Nº Unid.TítuloISBNRef. ClienteCajasEjempl./Cajas€/ud.Subtotal
{{ $linea->cantidad }}
{{ $linea->descripcion }}
{{ $linea->isbn }}
{{ $linea->ref_cliente }}
{{ $linea->cajas }}{{ $linea->ejemplares_por_caja }}
{{ float_to_str($linea->precio_unidad) }}
{{ float_to_str($linea->total) }}
- - - - - @if($obj->mostar_precios) - - - @endif - -
- RECIBÍ - - TOTAL - - {{ float_to_str($total_precio) }} -
-@endsection diff --git a/httpdocs/themes/vuexy/css/pdf.albaran.css b/httpdocs/themes/vuexy/css/pdf.albaran.css index 534e9581..fab87600 100644 --- a/httpdocs/themes/vuexy/css/pdf.albaran.css +++ b/httpdocs/themes/vuexy/css/pdf.albaran.css @@ -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; }