From 94222790df2bb4463294f4f3c5c63e8a8136a5ed Mon Sep 17 00:00:00 2001 From: imnavajas Date: Fri, 25 Jul 2025 11:39:20 +0200 Subject: [PATCH 1/2] =?UTF-8?q?A=C3=B1adimos=20ISKN?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...-090000_CreateTiposPapelGenerico copy.php} | 0 ...025-07-25-100000_AddIsknToPresupuestos.php | 27 +++++++++++++++++++ 2 files changed, 27 insertions(+) rename ci4/app/Database/Migrations/{2025-07-15-090000_CreateTiposPapelGenerico.php => 2025-07-15-090000_CreateTiposPapelGenerico copy.php} (100%) create mode 100644 ci4/app/Database/Migrations/2025-07-25-100000_AddIsknToPresupuestos.php diff --git a/ci4/app/Database/Migrations/2025-07-15-090000_CreateTiposPapelGenerico.php b/ci4/app/Database/Migrations/2025-07-15-090000_CreateTiposPapelGenerico copy.php similarity index 100% rename from ci4/app/Database/Migrations/2025-07-15-090000_CreateTiposPapelGenerico.php rename to ci4/app/Database/Migrations/2025-07-15-090000_CreateTiposPapelGenerico copy.php diff --git a/ci4/app/Database/Migrations/2025-07-25-100000_AddIsknToPresupuestos.php b/ci4/app/Database/Migrations/2025-07-25-100000_AddIsknToPresupuestos.php new file mode 100644 index 00000000..3759ff6f --- /dev/null +++ b/ci4/app/Database/Migrations/2025-07-25-100000_AddIsknToPresupuestos.php @@ -0,0 +1,27 @@ +forge->addColumn('presupuestos', [ + 'iskn' => [ + 'type' => 'VARCHAR', + 'constraint' => 64, + 'null' => true, + 'default' => null, + 'after' => 'coleccion', // o cualquier campo existente tras el cual quieras insertarlo + 'collation' => 'utf8_unicode_ci', + ], + ]); + } + + public function down() + { + $this->forge->dropColumn('presupuestos', 'iskn'); + } +} From 266241b26041eeee0b86a82a536b6d546c341d6a Mon Sep 17 00:00:00 2001 From: imnavajas Date: Fri, 25 Jul 2025 12:33:30 +0200 Subject: [PATCH 2/2] =?UTF-8?q?A=C3=B1adida=20a=20vista=20de=20presupuesto?= =?UTF-8?q?=20admin=20iskn.=20Asignacion=20automatica=20al=20confirmar=20p?= =?UTF-8?q?resupuesto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Presupuestos/Presupuestoadmin.php | 1 + .../Presupuestos/PresupuestoEntity.php | 1 + ci4/app/Language/en/Presupuestos.php | 1 + .../Models/Presupuestos/PresupuestoModel.php | 48 ++++++++++--- .../admin/_datosPresupuestoItems.php | 72 +++++++++++-------- .../presupuestoAdmin/presupuestoAdminEdit.js | 1 + .../sections/datosGenerales.js | 2 + 7 files changed, 85 insertions(+), 41 deletions(-) diff --git a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php index 22b29d04..d6a81aaa 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php @@ -587,6 +587,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $data['datosGenerales']['coleccion'] = $presupuesto->coleccion; $data['datosGenerales']['numero_edicion'] = $presupuesto->numero_edicion; $data['datosGenerales']['isbn'] = $presupuesto->isbn; + $data['datosGenerales']['iskn'] = $presupuesto->iskn; $data['datosGenerales']['pais'] = $presupuesto->pais_id; $data['datosGenerales']['pais_nombre'] = model('App\Models\Configuracion\PaisModel')->find($presupuesto->pais_id)->nombre; $data['datosGenerales']['cliente']['id'] = $presupuesto->cliente_id; diff --git a/ci4/app/Entities/Presupuestos/PresupuestoEntity.php b/ci4/app/Entities/Presupuestos/PresupuestoEntity.php index 00fd262e..27f315e1 100755 --- a/ci4/app/Entities/Presupuestos/PresupuestoEntity.php +++ b/ci4/app/Entities/Presupuestos/PresupuestoEntity.php @@ -47,6 +47,7 @@ class PresupuestoEntity extends \CodeIgniter\Entity\Entity "titulo" => "", "autor" => null, "coleccion" => null, + "iskn" => null, "numero_edicion" => null, "isbn" => null, "referencia_cliente" => null, diff --git a/ci4/app/Language/en/Presupuestos.php b/ci4/app/Language/en/Presupuestos.php index f465f2ef..1ddd76a3 100755 --- a/ci4/app/Language/en/Presupuestos.php +++ b/ci4/app/Language/en/Presupuestos.php @@ -35,6 +35,7 @@ return [ 'coleccion' => 'Collection', 'numeroEdicion' => 'Edition number', 'isbn' => 'ISBN', + 'iskn' => 'Identificador ISKN', 'referenciaCliente' => 'Customer reference', 'formatoLibro' => "Book format", 'papelFormatoId' => "Size", diff --git a/ci4/app/Models/Presupuestos/PresupuestoModel.php b/ci4/app/Models/Presupuestos/PresupuestoModel.php index 5a90c01b..b0cdfe07 100755 --- a/ci4/app/Models/Presupuestos/PresupuestoModel.php +++ b/ci4/app/Models/Presupuestos/PresupuestoModel.php @@ -67,6 +67,7 @@ class PresupuestoModel extends \App\Models\BaseModel "titulo", "autor", "coleccion", + "iskn", "numero_edicion", "isbn", "referencia_cliente", @@ -139,7 +140,7 @@ class PresupuestoModel extends \App\Models\BaseModel 'lomo_redondo', 'cabezada', 'envio_base', - 'direcciones_fp_checks', + 'direcciones_fp_checks', ]; protected $returnType = "App\Entities\Presupuestos\PresupuestoEntity"; @@ -401,15 +402,27 @@ class PresupuestoModel extends \App\Models\BaseModel } } - function confirmarPresupuesto($presupuesto_id) + /** + * Confirma un presupuesto (cambia su estado a 'confirmado') y, + * si no tiene asignado un ISKN, lo genera y lo asigna automáticamente. + * + * @param int $presupuesto_id ID del presupuesto a confirmar. + * @return void + */ + public function confirmarPresupuesto($presupuesto_id) { + // Cambiar el estado del presupuesto a '2' (confirmado) $this->db ->table($this->table . " t1") ->where('t1.id', $presupuesto_id) ->set('t1.estado_id', 2) ->update(); + + // Si existe y aún no tiene ISKN asignado, lo generamos y asignamos + $this->asignarIskn($presupuesto_id); } + function insertarPresupuestoCliente($id, $tirada, $data, $data_cabecera, $extra_info, $resumen_totales, $iva_reducido, $excluir_rotativa, $tiradas_alternativas) { @@ -501,8 +514,8 @@ class PresupuestoModel extends \App\Models\BaseModel 'total_antes_descuento' => round( $totalCostes + $totalMargenes + - $resumen_totales['coste_envio'] + $resumen_totales['margen_envio'] + - $data['envio_base'], + $resumen_totales['coste_envio'] + $resumen_totales['margen_envio'] + + $data['envio_base'], 2 ), 'total_descuento' => 0, @@ -511,25 +524,25 @@ class PresupuestoModel extends \App\Models\BaseModel 'total_precio_unidad' => $resumen_totales['precio_unidad'], 'total_presupuesto' => round( $totalCostes + $totalMargenes + - $resumen_totales['coste_envio'] + $resumen_totales['margen_envio'] + - $data['envio_base'], + $resumen_totales['coste_envio'] + $resumen_totales['margen_envio'] + + $data['envio_base'], 2 ), 'total_aceptado' => round( $totalCostes + $totalMargenes + - $resumen_totales['coste_envio'] + $resumen_totales['margen_envio'] + - $data['envio_base'], + $resumen_totales['coste_envio'] + $resumen_totales['margen_envio'] + + $data['envio_base'], 2 ), 'total_factor' => round( ($totalCostes + $totalMargenes) / - $resumen_totales['sumForFactor'], + $resumen_totales['sumForFactor'], 2 ), 'total_factor_ponderado' => round( ($totalCostes + $totalMargenes) / - $resumen_totales['sumForFactorPonderado'], + $resumen_totales['sumForFactorPonderado'], 2 ), @@ -635,7 +648,6 @@ class PresupuestoModel extends \App\Models\BaseModel 'gramaje' => intval($data['faja']['gramaje']), ); } - } $json = json_encode($values); return $json; @@ -915,5 +927,19 @@ class PresupuestoModel extends \App\Models\BaseModel ]); } + public function asignarIskn(int $presupuesto_id): bool + { + $presupuesto = $this->find($presupuesto_id); + // Si no existe o ya tiene ISKN, no lo modificamos + if (!$presupuesto || !empty($presupuesto->iskn)) { + return false; + } + + return $this->update($presupuesto_id, [ + 'iskn' => model('App\Models\Catalogo\IdentificadorIsknModel')->newIskn(), + 'updated_at' => date('Y-m-d H:i:s'), + 'user_update_id' => auth()->id(), + ]); + } } diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosPresupuestoItems.php b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosPresupuestoItems.php index 085fc242..2222005d 100755 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosPresupuestoItems.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosPresupuestoItems.php @@ -25,7 +25,7 @@ - + @@ -39,12 +39,12 @@ @@ -71,7 +71,7 @@
@@ -81,7 +81,7 @@
@@ -95,37 +95,37 @@
-
+
-
+
- +
-
+
- + @@ -133,31 +133,43 @@
- +
- -
+ +
- +
-
+
- + +
+
+ + +
+
+ +
@@ -167,4 +179,4 @@
-
+
\ No newline at end of file diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js index 76f632ce..e1429784 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js @@ -234,6 +234,7 @@ class PresupuestoAdminEdit { titulo: this.datosGenerales.titulo.val(), autor: this.datosGenerales.autor.val(), isbn: this.datosGenerales.isbn.val(), + iskn: this.datosGenerales.iskn.val(), pais_id: this.datosGenerales.pais.getVal(), coleccion: this.datosGenerales.coleccion.val(), numero_edicion: this.datosGenerales.numeroEdicion.val(), diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosGenerales.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosGenerales.js index 1f5063e6..3295ac63 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosGenerales.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosGenerales.js @@ -15,6 +15,7 @@ class DatosGenerales{ this.coleccion = this.domItem.find('#coleccion'); this.numeroEdicion = this.domItem.find('#numeroEdicion'); this.isbn = this.domItem.find('#isbn'); + this.iskn = this.domItem.find('#iskn'); this.cliente = new ClassSelect($('#clienteId'), '/clientes/cliente/getSelect2', 'Seleccione cliente'); @@ -46,6 +47,7 @@ class DatosGenerales{ this.coleccion.val(datos.coleccion); this.numeroEdicion.val(datos.numero_edicion); this.isbn.val(datos.isbn); + this.iskn.val(datos.iskn); this.cliente.setOption(datos.cliente.id, datos.cliente.nombre);