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: