delete is_deleted field

This commit is contained in:
amazuecos
2025-04-11 06:56:55 +02:00
parent 9e591a099d
commit 1e339b5503
11 changed files with 84 additions and 45 deletions

View File

@ -464,7 +464,7 @@ class Cliente extends \App\Controllers\BaseResourceController
return null;
}
$modelPlantillaPreciosCliente = model('App\Models\Clientes\ClientePlantillaPreciosModel');
$plantilla = $modelPlantillaPreciosCliente->where("id", $plantilla_id)->where("is_deleted", 0)->first();
$plantilla = $modelPlantillaPreciosCliente->where("id", $plantilla_id)->where("deleted_at", null)->first();
if ($plantilla == false) {
return null;
} else {

View File

@ -135,7 +135,6 @@ class ClientePrecios extends \App\Controllers\BaseResourceController
Field::inst('tipo_impresion'),
Field::inst('user_updated_id'),
Field::inst('updated_at'),
Field::inst('is_deleted'),
Field::inst('tiempo_min')
->getFormatter('Format::toDecimalChar')->setFormatter('Format::fromDecimalChar')
->validator(
@ -205,7 +204,6 @@ class ClientePrecios extends \App\Controllers\BaseResourceController
if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT) {
foreach ($data['data'] as $pkey => $values) {
// Si no se quiere borrar...
if ($data['data'][$pkey]['is_deleted'] != 1) {
$process_data['tiempo_min'] = $data['data'][$pkey]['tiempo_min'];
$process_data['tiempo_max'] = $data['data'][$pkey]['tiempo_max'];
$process_data['tipo'] = $data['data'][$pkey]['tipo'];
@ -217,7 +215,6 @@ class ClientePrecios extends \App\Controllers\BaseResourceController
if (!empty($response)) {
return $response;
}
}
}
}
})

View File

@ -155,7 +155,6 @@ class Clienteplantillaprecioslineas extends \App\Controllers\BaseResourceControl
Field::inst( 'tipo_impresion' ),
Field::inst( 'user_updated_id' ),
Field::inst( 'deleted_at' ),
Field::inst( 'is_deleted' ),
Field::inst( 'updated_at' ),
Field::inst( 'tiempo_min' )
->getFormatter( 'Format::toDecimalChar')->setFormatter( 'Format::fromDecimalChar')

View File

@ -0,0 +1,49 @@
<?php
namespace App\Database\Migrations;
use App\Models\Clientes\ClienteContactoModel;
use App\Models\Clientes\ClienteModel;
use App\Models\Clientes\ClientePlantillaPreciosModel;
use App\Models\Clientes\ClientePreciosModel;
use CodeIgniter\Database\Migration;
use CodeIgniter\I18n\Time;
class DropIsDeletedField extends Migration
{
public function up()
{
$m = $this->db->table('clientes');
$m->where('is_deleted',1)->update(['deleted_at' => Time::now()]);
$m->where('is_deleted',0)->update(['deleted_at' => null]);
$this->forge->dropColumn('clientes',"is_deleted");
$m = $this->db->table('cliente_contactos');
$m->where('is_deleted',1)->update(['deleted_at' => Time::now()]);
$m->where('is_deleted',0)->update(['deleted_at' => null]);
$this->forge->dropColumn('cliente_contactos',"is_deleted");
$m = $this->db->table('cliente_precios');
$m->where('is_deleted',1)->update(['deleted_at' => Time::now()]);
$m->where('is_deleted',0)->update(['deleted_at' => null]);
$this->forge->dropColumn('cliente_precios',"is_deleted");
$m = $this->db->table('cliente_plantilla_precios_lineas');
$m->where('is_deleted',1)->update(['deleted_at' => Time::now()]);
$m->where('is_deleted',0)->update(['deleted_at' => null]);
$this->forge->dropColumn('cliente_plantilla_precios_lineas',"is_deleted");
$m = $this->db->table('cliente_plantilla_precios');
$m->where('is_deleted',1)->update(['deleted_at' => Time::now()]);
$m->where('is_deleted',0)->update(['deleted_at' => null]);
$this->forge->dropColumn('cliente_plantilla_precios',"is_deleted");
}
public function down()
{
}
}

View File

@ -25,12 +25,12 @@ class ClienteContactoModel extends \App\Models\BaseModel
protected $returnType = "App\Entities\Clientes\ClienteContactoEntity";
protected $useTimestamps = true;
protected $useSoftDeletes = false;
protected $useSoftDeletes = true;
protected $deletedField = 'deleted_at';
protected $createdField = "created_at";
protected $updatedField = "updated_at";
protected $deletedField = 'deleted_at';
public static $labelField = "nombre";
@ -113,7 +113,7 @@ class ClienteContactoModel extends \App\Models\BaseModel
);
$builder->where('t1.cliente_id', $cliente_id);
$builder->where("t1.is_deleted", 0);
$builder->where("t1.deleted_at", null);
$builder->join("clientes t2", "t1.cliente_id = t2.id", "left");
return empty($search)

View File

@ -2,6 +2,8 @@
namespace App\Models\Clientes;
use App\Entities\Clientes\ClienteEntity;
class ClienteModel extends \App\Models\BaseModel
{
protected $table = "clientes";
@ -57,13 +59,11 @@ class ClienteModel extends \App\Models\BaseModel
"comentarios_tirada_flexible",
"margen_plantilla_id",
"comentarios",
"is_deleted",
"deleted_at",
"user_created_id",
"user_update_id",
];
protected $returnType = "App\Entities\Clientes\ClienteEntity";
protected $returnType = ClienteEntity::class;
protected $useSoftDeletes = true;
protected $deletedField = 'deleted_at';
public static $labelField = "nombre";
@ -197,10 +197,7 @@ class ClienteModel extends \App\Models\BaseModel
"fecha_vencimiento" => [
"max_length" => "Clientes.validation.fecha_vencimiento.max_length",
],
"is_deleted" => [
"integer" => "Clientes.validation.is_deleted.integer",
"required" => "Clientes.validation.is_deleted.required",
],
"limite_credito" => [
"decimal" => "Clientes.validation.limite_credito.decimal",
"required" => "Clientes.validation.limite_credito.required",
@ -287,7 +284,7 @@ class ClienteModel extends \App\Models\BaseModel
->select(
"t1.id AS id, t1.nombre AS nombre, t1.alias AS alias, t1.cif AS cif, t1.email AS email, t1.vencimiento AS vencimiento, t5.first_name AS comercial, t7.nombre AS forma_pago_id"
)
->where("is_deleted", 0);;
->where("t1.deleted_at", null);;
$builder->join("users t5", "t1.comercial_id = t5.id", "left");
$builder->join("formas_pago t7", "t1.forma_pago_id = t7.id", "left");
@ -315,7 +312,7 @@ class ClienteModel extends \App\Models\BaseModel
->select(
"t1.limite_credito AS limite_credito"
)
->where("t1.is_deleted", 0)
->where("t1.deleted_at", null)
->where("t1.id", $cliente_id);
$limite = $builder->get()->getResultObject();
@ -340,7 +337,7 @@ class ClienteModel extends \App\Models\BaseModel
t2.nombre AS cliente_pais, t1.cp AS cliente_cp, t1.ciudad AS cliente_ciudad,
t3.nombre AS cliente_provincia, t1.credito_asegurado AS creditoAsegurado"
)
->where("t1.is_deleted", 0)
->where("t1.deleted_at", null)
->where("t1.id", $cliente_id);
$builder->join("lg_paises t2", "t1.pais_id = t2.id", "left");
$builder->join("lg_provincias t3", "t1.provincia_id = t3.id", "left");
@ -394,7 +391,7 @@ class ClienteModel extends \App\Models\BaseModel
"t1.nombre AS nombre"
)
->where("id", $id)
->where("is_deleted", 0);
->where("t1.deleted_at", null);
return $builder->get()->getResultObject()[0]->nombre;
} catch (\Exception $e) {
@ -409,7 +406,7 @@ class ClienteModel extends \App\Models\BaseModel
->select(
"t1.id AS id, t1.nombre AS name"
)
->where("is_deleted", 0);
->where("t1.deleted_at", null);
return empty($search)
? $builder->get()->getResultObject()
: $builder
@ -586,7 +583,7 @@ class ClienteModel extends \App\Models\BaseModel
$result['limite_credito'] = $this->db->table('clientes')
->select('limite_credito')
->where('id', $cliente_id)
->where('is_deleted', 0)
->where("deleted_at", null)
->get()
->getResultObject()[0]->limite_credito;
$result['limite_credito'] = round(floatval($result['limite_credito']), 2);

View File

@ -36,7 +36,6 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel
"tiempo_max",
"precio_hora",
"margen",
"is_deleted",
"deleted_at",
"created_at",
"updated_at",
@ -45,11 +44,12 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel
protected $returnType = "App\Entities\Clientes\ClientePlantillaPreciosLineasEntity";
protected $useTimestamps = true;
protected $useSoftDeletes = false;
protected $useSoftDeletes = true;
protected $createdField = "created_at";
protected $updatedField = "updated_at";
protected $deletedField = 'deleted_at';
public static $labelField = "plantilla_id";
@ -121,7 +121,6 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel
$this->db
->table($this->table . " t1")
->where('t1.plantilla_id', $plantilla_id)
->set('is_deleted', 1)
->set('deleted_at', $date_value)
->update();
@ -152,7 +151,7 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel
$builder->join("users t2", "t1.user_updated_id = t2.id", "left");
$builder->where('t1.is_deleted', 0);
$builder->where('t1.deleted_at', 0);
$builder->where('t1.plantilla_id', $plantilla_id);
if (empty($search))
@ -181,7 +180,7 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel
$rows = $this->db
->table($this->table)
->select("id, tiempo_min, tiempo_max")
->where("is_deleted", 0)
->where("deleted_at", null)
->where("tipo", $data["tipo"])
->where("tipo_maquina", $data["tipo_maquina"])
->where("tipo_impresion", $data["tipo_impresion"])

View File

@ -19,11 +19,12 @@ class ClientePlantillaPreciosModel extends \App\Models\BaseModel
protected $useAutoIncrement = true;
protected $allowedFields = ["nombre", "is_deleted", "deleted_at", "created_at", "updated_at"];
protected $allowedFields = ["nombre", "deleted_at", "created_at", "updated_at"];
protected $returnType = "App\Entities\Clientes\ClientePlantillaPreciosEntity";
protected $useTimestamps = true;
protected $useSoftDeletes = false;
protected $useSoftDeletes = true;
protected $deletedField = 'deleted_at';
protected $createdField = "created_at";
@ -61,7 +62,7 @@ class ClientePlantillaPreciosModel extends \App\Models\BaseModel
"t1.id as id, t1.nombre AS nombre"
);
$builder->where('t1.is_deleted', 0);
$builder->where('t1.deleted_at', null);
if (empty($search))
return $builder;

View File

@ -34,7 +34,6 @@ class ClientePreciosModel extends \App\Models\BaseModel
"tiempo_max",
"precio_hora",
"margen",
"is_deleted",
"deleted_at",
"created_at",
"updated_at",
@ -45,7 +44,8 @@ class ClientePreciosModel extends \App\Models\BaseModel
protected $returnType = "App\Entities\Clientes\ClientePreciosEntity";
protected $useTimestamps = true;
protected $useSoftDeletes = false;
protected $useSoftDeletes = true;
protected $deletedField = 'deleted_at';
protected $createdField = "created_at";
@ -140,7 +140,6 @@ class ClientePreciosModel extends \App\Models\BaseModel
$this->db
->table($this->table . " t1")
->where('cliente_id', $cliente_id)
->set('is_deleted', 1)
->set('deleted_at', $date_value)
->set('user_updated_id', $session->id_user)
->update();
@ -153,7 +152,7 @@ class ClientePreciosModel extends \App\Models\BaseModel
// Se borran los valores existentes para todos los clientes en una sola consulta
$modelCliente = model('App\Models\Clientes\ClienteModel');
$clientes = $modelCliente->select('id')->where('is_deleted', 0)->findAll();
$clientes = $modelCliente->select('id')->where('deleted_at', null)->findAll();
// Se borra la tabla
$this->db->table($this->table)->truncate();
@ -288,7 +287,7 @@ class ClientePreciosModel extends \App\Models\BaseModel
->table($this->table . " t1")
->select("t1.cliente_id AS id")
->where('t1.plantilla_id', $plantilla_id)
->where('t1.is_deleted', 0)
->where('t1.deleted_at', null)
->distinct()
->get()->getResultArray();
// Extraer solo los IDs de los clientes
@ -359,7 +358,7 @@ class ClientePreciosModel extends \App\Models\BaseModel
->where('tipo_impresion', $config->tipo_impresion)
->where('tiempo_min <=', $tiempo)
->where('tiempo_max >=', $tiempo)
->where('is_deleted', 0)
->where('deleted_at', null)
->get()->getResultObject();
if (count($values) > 0) {
@ -389,7 +388,7 @@ class ClientePreciosModel extends \App\Models\BaseModel
$builder->join("users t2", "t1.user_updated_id = t2.id", "left");
$builder->where('t1.is_deleted', 0);
$builder->where('t1.deleted_at', 0);
$builder->where('t1.cliente_id', $cliente_id);
if (empty($search))
@ -415,7 +414,7 @@ class ClientePreciosModel extends \App\Models\BaseModel
"t1.plantilla_id AS id, t2.nombre AS nombre"
);
$builder->where('t1.is_deleted', 0);
$builder->where('t1.deleted_at', null);
$builder->where('t1.cliente_id', $cliente_id);
$builder->join("cliente_plantilla_precios t2", "t1.plantilla_id = t2.id", "left");
$builder->limit(1);
@ -442,7 +441,7 @@ class ClientePreciosModel extends \App\Models\BaseModel
$rows = $this->db
->table($this->table)
->select("id, tiempo_min, tiempo_max")
->where("is_deleted", 0)
->where("deleted_at", null)
->where("tipo", $data["tipo"])
->where("tipo_maquina", $data["tipo_maquina"])
->where("tipo_impresion", $data["tipo_impresion"])
@ -476,7 +475,7 @@ class ClientePreciosModel extends \App\Models\BaseModel
$value = $this->db
->table($this->table)
->select("plantilla_id")
->where("is_deleted", 0)
->where("deleted_at", null)
->where("cliente_id", $cliente_id)
->limit(1)->get()->getResultObject();

View File

@ -26,7 +26,8 @@ class ClienteUsuariosModel extends ShieldUserModel
protected $returnType = "App\Entities\Usuarios\UserEntity";
protected $useTimestamps = true;
protected $useSoftDeletes = false;
protected $useSoftDeletes = true;
protected $deletedField = 'deleted_at';
protected $createdField = "created_at";

View File

@ -787,10 +787,7 @@ $(document).on('click', '.btn-remove', function(e) {
},{
"name": "deleted_at",
"type": "hidden"
},{
"name": "is_deleted",
"type": "hidden"
},
}
]
} );