mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Añadida la logica de crear la columna y modelo
This commit is contained in:
@ -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');
|
||||
}
|
||||
}
|
||||
@ -27,6 +27,7 @@ class PresupuestoEntity extends \CodeIgniter\Entity\Entity
|
||||
"user_update_id" => null,
|
||||
"tipo_impresion_id" => null,
|
||||
"tipologia_id" => null,
|
||||
"catalogo_id" => null,
|
||||
"pais_id" => 1,
|
||||
"estado_id" => 1,
|
||||
"inc_rei" => null,
|
||||
@ -123,6 +124,7 @@ class PresupuestoEntity extends \CodeIgniter\Entity\Entity
|
||||
"user_update_id" => "?int",
|
||||
"tipo_impresion_id" => "?int",
|
||||
"tipologia_id" => "?int",
|
||||
"catalogo_id" => "?int",
|
||||
"pais_id" => "int",
|
||||
"estado_id" => "int",
|
||||
"retractilado" => "boolean",
|
||||
|
||||
@ -47,6 +47,7 @@ class PresupuestoModel extends \App\Models\BaseModel
|
||||
"user_update_id",
|
||||
"tipo_impresion_id",
|
||||
"tipologia_id",
|
||||
"catalogo_id",
|
||||
"pais_id",
|
||||
"estado_id",
|
||||
"inc_rei",
|
||||
@ -500,7 +501,9 @@ class PresupuestoModel extends \App\Models\BaseModel
|
||||
'total_antes_descuento' => round(
|
||||
$totalCostes + $totalMargenes +
|
||||
$resumen_totales['coste_envio'] + $resumen_totales['margen_envio'] +
|
||||
$data['envio_base'], 2),
|
||||
$data['envio_base'],
|
||||
2
|
||||
),
|
||||
'total_descuento' => 0,
|
||||
'total_descuentoPercent' => 0,
|
||||
|
||||
@ -508,19 +511,26 @@ class PresupuestoModel extends \App\Models\BaseModel
|
||||
'total_presupuesto' => round(
|
||||
$totalCostes + $totalMargenes +
|
||||
$resumen_totales['coste_envio'] + $resumen_totales['margen_envio'] +
|
||||
$data['envio_base'], 2),
|
||||
$data['envio_base'],
|
||||
2
|
||||
),
|
||||
'total_aceptado' => round(
|
||||
$totalCostes + $totalMargenes +
|
||||
$resumen_totales['coste_envio'] + $resumen_totales['margen_envio'] +
|
||||
$data['envio_base'], 2
|
||||
$data['envio_base'],
|
||||
2
|
||||
),
|
||||
|
||||
'total_factor' => round(
|
||||
($totalCostes + $totalMargenes) /
|
||||
$resumen_totales['sumForFactor'], 2),
|
||||
$resumen_totales['sumForFactor'],
|
||||
2
|
||||
),
|
||||
'total_factor_ponderado' => round(
|
||||
($totalCostes + $totalMargenes) /
|
||||
$resumen_totales['sumForFactorPonderado'], 2),
|
||||
$resumen_totales['sumForFactorPonderado'],
|
||||
2
|
||||
),
|
||||
|
||||
'iva_reducido' => $iva_reducido,
|
||||
'excluir_rotativa' => $excluir_rotativa,
|
||||
@ -534,8 +544,7 @@ class PresupuestoModel extends \App\Models\BaseModel
|
||||
$this->db->table($this->table)->where('id', $id)->update($fields);
|
||||
return $id;
|
||||
}
|
||||
/* Inserccion */
|
||||
else {
|
||||
/* Inserccion */ else {
|
||||
$fields['user_created_id'] = auth()->id();
|
||||
$fields['user_update_id'] = auth()->id();
|
||||
$this->db->table($this->table)->insert($fields);
|
||||
@ -746,7 +755,8 @@ class PresupuestoModel extends \App\Models\BaseModel
|
||||
return $servicios;
|
||||
}
|
||||
|
||||
public function getPresupuestosClienteForm($cliente_id = -1){
|
||||
public function getPresupuestosClienteForm($cliente_id = -1)
|
||||
{
|
||||
$builder = $this->db
|
||||
->table($this->table . " pr")
|
||||
->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;
|
||||
}
|
||||
|
||||
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(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user