From b62a5d1b9a2e644bcb9d6d0ad6797392fc4748be Mon Sep 17 00:00:00 2001 From: imnavajas Date: Mon, 15 Jan 2024 22:09:18 +0100 Subject: [PATCH] Inciado link presupuesto PDF con backend --- ci4/app/Controllers/Pdf/PrintPresupuestos.php | 11 ++-- .../Models/Presupuestos/PresupuestoModel.php | 53 ++++++++++++++++--- .../themes/backend/vuexy/pdfs/presupuesto.php | 29 +++++----- 3 files changed, 67 insertions(+), 26 deletions(-) diff --git a/ci4/app/Controllers/Pdf/PrintPresupuestos.php b/ci4/app/Controllers/Pdf/PrintPresupuestos.php index 4469e9dd..46e48b08 100755 --- a/ci4/app/Controllers/Pdf/PrintPresupuestos.php +++ b/ci4/app/Controllers/Pdf/PrintPresupuestos.php @@ -13,13 +13,18 @@ class PrintPresupuestos extends BaseController public function index() { - //return view('pdf_view'); - return view(getenv('theme.path').'pdfs/presupuesto'); + $presupuestoModel = model('App\Models\Presupuestos\PresupuestoModel'); + + $data['presupuesto'] = $presupuestoModel->getResourceForPdf(8)->get()->getRow(); + + + return view(getenv('theme.path').'pdfs/presupuesto', $data); } public function generar(){ $dompdf = new \Dompdf\Dompdf(['isRemoteEnabled' => true]); //$dompdf->loadHtml(view('pdf_view')); - $dompdf->loadHtml(view(getenv('theme.path').'pdfs/presupuesto')); + //$dompdf->loadHtml(view(getenv('theme.path').'pdfs/presupuesto')); + $dompdf->loadHtml($this->index()); $dompdf->setPaper('A4', 'portrait'); $dompdf->render(); $dompdf->stream('presupuesto-demo.pdf'); diff --git a/ci4/app/Models/Presupuestos/PresupuestoModel.php b/ci4/app/Models/Presupuestos/PresupuestoModel.php index aa34dc7c..9c3ae2b4 100755 --- a/ci4/app/Models/Presupuestos/PresupuestoModel.php +++ b/ci4/app/Models/Presupuestos/PresupuestoModel.php @@ -1,4 +1,5 @@ [ "integer" => "Presupuestos.validation.integer", - + ], "coleccion" => [ "max_length" => "Presupuestos.validation.max_length", @@ -277,8 +278,9 @@ class PresupuestoModel extends \App\Models\GoBaseModel ], "referencia_cliente" => [ "max_length" => "Presupuestos.validation.max_length", - ], + ], ]; + public function findAllWithAllRelations(string $selcols = "*", int $limit = null, int $offset = 0) { $sql = @@ -324,14 +326,14 @@ class PresupuestoModel extends \App\Models\GoBaseModel $builder->where("t1.is_deleted", 0); - if(empty($search)) + if (empty($search)) return $builder; - else{ + else { $builder->groupStart(); - foreach($search as $col_search){ - if($col_search[0] != 1) + foreach ($search as $col_search) { + if ($col_search[0] != 1) $builder->like(self::SORTABLE[$col_search[0]], $col_search[2]); - else{ + else { $dates = explode(" ", $col_search[2]); $builder->where(self::SORTABLE[$col_search[0]] . ">=", $dates[0]); $builder->where(self::SORTABLE[$col_search[0]] . "<=", $dates[1]); @@ -340,6 +342,41 @@ class PresupuestoModel extends \App\Models\GoBaseModel $builder->groupEnd(); return $builder; } - + } + + + /** + * Get resource data. + * + * @param string $search + * + * @return \CodeIgniter\Database\BaseBuilder + */ + public function getResourceForPdf($presupuesto_id = -1) + { + $builder = $this->db + ->table($this->table . " t1") + ->select( + "t1.id AS id, t1.created_at AS fecha, t1.titulo AS titulo, t1.autor AS autor, t1.ferro AS ferro, + t1.ferro_digital AS ferro_digital, t1.prototipo AS prototipo, t1.solapas AS solapas, + t1.solapas_ancho AS solapas_ancho, t1.paginas AS paginas, t1.tirada AS tirada, t1.coleccion AS coleccion, + t1.total_presupuesto AS total_presupuesto, t1.total_precio_unidad AS total_precio_unidad, + t2.nombre AS cliente, + CONCAT(t3.first_name, ' ', t3.last_name) AS comercial, t3.email AS email_comercial, + t1.inc_rei AS inc_rei, + t6.estado AS estado" + ); + $builder->join("clientes t2", "t1.cliente_id = t2.id", "left"); + $builder->join("auth_user t3", "t1.user_update_id = t3.id_user", "left"); + $builder->join("presupuesto_estados t6", "t1.estado_id = t6.id", "left"); + + $builder->where("t1.is_deleted", 0); + $builder->where("t1.id", $presupuesto_id); + + return $builder; + + + } + } diff --git a/ci4/app/Views/themes/backend/vuexy/pdfs/presupuesto.php b/ci4/app/Views/themes/backend/vuexy/pdfs/presupuesto.php index 00241c88..2deccf92 100755 --- a/ci4/app/Views/themes/backend/vuexy/pdfs/presupuesto.php +++ b/ci4/app/Views/themes/backend/vuexy/pdfs/presupuesto.php @@ -37,34 +37,34 @@ PRESUPUESTO Nº: - id" ?> + id ?> CLIENTE: - customer->name" ?> + cliente ?> FECHA: - + fecha ?> - Título: titulo" ?> + Título: titulo ?> - Colección: coleccion" ?> + Colección: coleccion ?> - Autor: autor" ?> + Autor: autor ?> @@ -83,11 +83,11 @@ Ferro - TBD + ferro == 1) ? "SI" : "NO"); ?> Prototipo - SI + prototipo == 1) ? "SI" : "NO"); ?> Ferro Digital - SI + ferro_digital == 1) ? "SI" : "NO"); ?> Formato @@ -97,7 +97,7 @@ Nº de páginas totales - paginas" ?> + paginas ?> Nº de páginas ByN @@ -169,9 +169,9 @@ Tipo Solapas - + solapas == 1) ? "SI" : "NO"); ?> Ancho - TBD cm + solapas_ancho ?> cm @@ -252,7 +252,7 @@ - TBD uds. + tirada ?> uds. TBD € TBD € TBD € @@ -277,8 +277,7 @@ comercial el día que se oficialice el pedido, dado que pueda darse la situación de que no haya stock disponible o que su precio haya variado considerablemente, para así poder ofrecerle alternativas.

Esperando que los precios se ajusten a sus necesidades,
- customer->salesman->name" ?> customer->salesman->lastname" ?> • - email: customer->salesman->email" ?>

+ comercial ?> • email: email_comercial ?>

(*) En el formato de desarrollo de cubierta están contemplados los 3 mm. de vuelta de solapas en caso de llevarlas.
(**) Estos precios están sujetos a análisis de cobertura de tinta del archivo PDF de interior.