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);