Añadida la logica de crear la columna y modelo

This commit is contained in:
Ignacio Martinez Navajas
2025-06-29 23:09:09 +02:00
parent 4e2003b8b8
commit 416b4db915
3 changed files with 89 additions and 26 deletions

View File

@ -0,0 +1,43 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class AddCatalogoIdToPresupuestos extends Migration
{
public function up()
{
// Añadir columna
$this->forge->addColumn('presupuestos', [
'catalogo_id' => [
'type' => 'INT',
'constraint' => 10,
'unsigned' => true,
'null' => true,
'after' => 'tipologia_id'
],
]);
// Agregar clave foránea
$this->db->query('
ALTER TABLE presupuestos
ADD CONSTRAINT FK_presupuestos_catalogo_libros
FOREIGN KEY (catalogo_id) REFERENCES catalogo_libros(id)
ON DELETE SET NULL
ON UPDATE CASCADE
');
}
public function down()
{
// Eliminar la clave foránea primero
$this->db->query('
ALTER TABLE presupuestos
DROP FOREIGN KEY FK_presupuestos_catalogo_libros
');
// Eliminar columna
$this->forge->dropColumn('presupuestos', 'catalogo_id');
}
}

View File

@ -27,6 +27,7 @@ class PresupuestoEntity extends \CodeIgniter\Entity\Entity
"user_update_id" => null, "user_update_id" => null,
"tipo_impresion_id" => null, "tipo_impresion_id" => null,
"tipologia_id" => null, "tipologia_id" => null,
"catalogo_id" => null,
"pais_id" => 1, "pais_id" => 1,
"estado_id" => 1, "estado_id" => 1,
"inc_rei" => null, "inc_rei" => null,
@ -123,6 +124,7 @@ class PresupuestoEntity extends \CodeIgniter\Entity\Entity
"user_update_id" => "?int", "user_update_id" => "?int",
"tipo_impresion_id" => "?int", "tipo_impresion_id" => "?int",
"tipologia_id" => "?int", "tipologia_id" => "?int",
"catalogo_id" => "?int",
"pais_id" => "int", "pais_id" => "int",
"estado_id" => "int", "estado_id" => "int",
"retractilado" => "boolean", "retractilado" => "boolean",

View File

@ -47,6 +47,7 @@ class PresupuestoModel extends \App\Models\BaseModel
"user_update_id", "user_update_id",
"tipo_impresion_id", "tipo_impresion_id",
"tipologia_id", "tipologia_id",
"catalogo_id",
"pais_id", "pais_id",
"estado_id", "estado_id",
"inc_rei", "inc_rei",
@ -500,7 +501,9 @@ class PresupuestoModel extends \App\Models\BaseModel
'total_antes_descuento' => round( 'total_antes_descuento' => round(
$totalCostes + $totalMargenes + $totalCostes + $totalMargenes +
$resumen_totales['coste_envio'] + $resumen_totales['margen_envio'] + $resumen_totales['coste_envio'] + $resumen_totales['margen_envio'] +
$data['envio_base'], 2), $data['envio_base'],
2
),
'total_descuento' => 0, 'total_descuento' => 0,
'total_descuentoPercent' => 0, 'total_descuentoPercent' => 0,
@ -508,19 +511,26 @@ class PresupuestoModel extends \App\Models\BaseModel
'total_presupuesto' => round( 'total_presupuesto' => round(
$totalCostes + $totalMargenes + $totalCostes + $totalMargenes +
$resumen_totales['coste_envio'] + $resumen_totales['margen_envio'] + $resumen_totales['coste_envio'] + $resumen_totales['margen_envio'] +
$data['envio_base'], 2), $data['envio_base'],
2
),
'total_aceptado' => round( 'total_aceptado' => round(
$totalCostes + $totalMargenes + $totalCostes + $totalMargenes +
$resumen_totales['coste_envio'] + $resumen_totales['margen_envio'] + $resumen_totales['coste_envio'] + $resumen_totales['margen_envio'] +
$data['envio_base'], 2 $data['envio_base'],
2
), ),
'total_factor' => round( 'total_factor' => round(
($totalCostes + $totalMargenes) / ($totalCostes + $totalMargenes) /
$resumen_totales['sumForFactor'], 2), $resumen_totales['sumForFactor'],
2
),
'total_factor_ponderado' => round( 'total_factor_ponderado' => round(
($totalCostes + $totalMargenes) / ($totalCostes + $totalMargenes) /
$resumen_totales['sumForFactorPonderado'], 2), $resumen_totales['sumForFactorPonderado'],
2
),
'iva_reducido' => $iva_reducido, 'iva_reducido' => $iva_reducido,
'excluir_rotativa' => $excluir_rotativa, 'excluir_rotativa' => $excluir_rotativa,
@ -534,8 +544,7 @@ class PresupuestoModel extends \App\Models\BaseModel
$this->db->table($this->table)->where('id', $id)->update($fields); $this->db->table($this->table)->where('id', $id)->update($fields);
return $id; return $id;
} }
/* Inserccion */ /* Inserccion */ else {
else {
$fields['user_created_id'] = auth()->id(); $fields['user_created_id'] = auth()->id();
$fields['user_update_id'] = auth()->id(); $fields['user_update_id'] = auth()->id();
$this->db->table($this->table)->insert($fields); $this->db->table($this->table)->insert($fields);
@ -746,7 +755,8 @@ class PresupuestoModel extends \App\Models\BaseModel
return $servicios; return $servicios;
} }
public function getPresupuestosClienteForm($cliente_id = -1){ public function getPresupuestosClienteForm($cliente_id = -1)
{
$builder = $this->db $builder = $this->db
->table($this->table . " pr") ->table($this->table . " pr")
->select('pr.id, pr.created_at as fecha, CONCAT(u.first_name, " ", u.last_name) AS comercial, pr.titulo, ->select('pr.id, pr.created_at as fecha, CONCAT(u.first_name, " ", u.last_name) AS comercial, pr.titulo,
@ -893,6 +903,14 @@ class PresupuestoModel extends \App\Models\BaseModel
return $description_interior . $description_cubierta . $description_sobrecubierta . $acabado; return $description_interior . $description_cubierta . $description_sobrecubierta . $acabado;
} }
public function vincularCatalogo(int $presupuesto_id, int $catalogo_id): bool
{
return $this->update($presupuesto_id, [
'catalogo_id' => $catalogo_id,
'updated_at' => date('Y-m-d H:i:s'),
'user_update_id' => auth()->id(),
]);
}
} }