mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
arreglado todo
This commit is contained in:
115
ci4/app/Models/Presupuestos/ErrorPresupuesto.php
Normal file
115
ci4/app/Models/Presupuestos/ErrorPresupuesto.php
Normal file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Presupuestos;
|
||||
|
||||
use CodeIgniter\Database\BaseBuilder;
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class ErrorPresupuesto extends Model
|
||||
{
|
||||
protected $table = 'presupuesto_errores';
|
||||
protected $primaryKey = 'id';
|
||||
protected $useAutoIncrement = true;
|
||||
protected $returnType = 'object';
|
||||
protected $useSoftDeletes = false;
|
||||
protected $protectFields = true;
|
||||
protected $allowedFields = [
|
||||
"presupuesto_id",
|
||||
"presupuesto_user_id",
|
||||
"error",
|
||||
"datos_presupuesto",
|
||||
"visto",
|
||||
"last_user_id",
|
||||
"comment",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"deleted_at",
|
||||
];
|
||||
|
||||
protected bool $allowEmptyInserts = false;
|
||||
protected bool $updateOnlyChanged = true;
|
||||
|
||||
protected array $casts = [];
|
||||
protected array $castHandlers = [];
|
||||
|
||||
// Dates
|
||||
protected $useTimestamps = true;
|
||||
//protected $dateFormat = 'datetime';
|
||||
protected $createdField = 'created_at';
|
||||
protected $updatedField = 'updated_at';
|
||||
protected $deletedField = 'deleted_at';
|
||||
|
||||
// Validation
|
||||
protected $validationRules = [];
|
||||
protected $validationMessages = [];
|
||||
protected $skipValidation = false;
|
||||
protected $cleanValidationRules = true;
|
||||
|
||||
// Callbacks
|
||||
protected $allowCallbacks = true;
|
||||
protected $beforeInsert = [];
|
||||
protected $afterInsert = [];
|
||||
protected $beforeUpdate = [];
|
||||
protected $afterUpdate = [];
|
||||
protected $beforeFind = [];
|
||||
protected $afterFind = [];
|
||||
protected $beforeDelete = [];
|
||||
protected $afterDelete = [];
|
||||
|
||||
public function insertError(int $presupuesto_id, int $presupuesto_user_id, string $error, mixed $datos)
|
||||
{
|
||||
$this->insert([
|
||||
"presupuesto_id" => $presupuesto_id,
|
||||
"presupuesto_user_id" => $presupuesto_user_id,
|
||||
"error" => $error,
|
||||
"datos_presupuesto" => json_encode($datos)
|
||||
]);
|
||||
}
|
||||
public function updateComment(int $error_presupuesto_id, string $comment): bool
|
||||
{
|
||||
$updated = $this->update($error_presupuesto_id, [
|
||||
"comment" => $comment
|
||||
]);
|
||||
return $updated;
|
||||
}
|
||||
public function getErrorPresupuestoForm(int $error_presupuesto_id) : array
|
||||
{
|
||||
$query = $this->builder()
|
||||
->select([
|
||||
"presupuesto_errores.id",
|
||||
"CONCAT(t1.first_name,' ',t1.last_name) as presupuestoUser",
|
||||
"CONCAT(t2.first_name,' ',t2.last_name) as lastUser",
|
||||
"presupuesto_errores.created_at",
|
||||
"presupuesto_errores.datos_presupuesto",
|
||||
"presupuesto_errores.error",
|
||||
"presupuesto_errores.visto",
|
||||
"presupuesto_errores.comment"
|
||||
])
|
||||
->join("users t1", "t1.id = presupuesto_errores.presupuesto_user_id", "left")
|
||||
->join("users t2", "t2.id = presupuesto_errores.last_user_id", "left")
|
||||
->where("presupuesto_errores.deleted_at", null)
|
||||
->where("presupuesto_errores.id",$error_presupuesto_id);
|
||||
return $query->get()->getResultObject();
|
||||
}
|
||||
public function getQueryDatatable(): BaseBuilder
|
||||
{
|
||||
$query = $this->builder()
|
||||
->select([
|
||||
"presupuesto_errores.id",
|
||||
"presupuestos.id as presupuestoId",
|
||||
"CONCAT(t1.first_name,' ',t1.last_name) as presupuestoUser",
|
||||
"CONCAT(t2.first_name,' ',t2.last_name) as lastUser",
|
||||
"presupuesto_errores.created_at",
|
||||
"presupuesto_errores.datos_presupuesto",
|
||||
"presupuesto_errores.error",
|
||||
"presupuesto_errores.visto",
|
||||
"presupuesto_errores.comment",
|
||||
|
||||
])
|
||||
->join("users t1", "t1.id = presupuesto_errores.presupuesto_user_id", "left")
|
||||
->join("users t2", "t2.id = presupuesto_errores.last_user_id", "left")
|
||||
->join("presupuestos", "presupuestos.id = presupuesto_errores.presupuesto_id", "left")
|
||||
->where("presupuesto_errores.deleted_at", null);
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Tarifas;
|
||||
|
||||
class TarifaEncuadernacionDimensionesModel extends \App\Models\BaseModel
|
||||
@ -12,20 +13,14 @@ class TarifaEncuadernacionDimensionesModel extends \App\Models\BaseModel
|
||||
*/
|
||||
protected $useAutoIncrement = true;
|
||||
|
||||
protected $allowedFields = [
|
||||
|
||||
];
|
||||
protected $allowedFields = [];
|
||||
protected $returnType = "App\Entities\Tarifas\TarifaEncuadernacionDimensionesEntity";
|
||||
|
||||
public static $labelField = "descripcion";
|
||||
|
||||
protected $validationRules = [
|
||||
|
||||
];
|
||||
protected $validationRules = [];
|
||||
|
||||
protected $validationMessages = [
|
||||
|
||||
];
|
||||
protected $validationMessages = [];
|
||||
|
||||
/**
|
||||
* Get resource data.
|
||||
@ -34,13 +29,32 @@ class TarifaEncuadernacionDimensionesModel extends \App\Models\BaseModel
|
||||
*
|
||||
* @return \CodeIgniter\Database\BaseBuilder
|
||||
*/
|
||||
public function getDimensiones(){
|
||||
public function getDimensiones()
|
||||
{
|
||||
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select("t1.id AS value, t1.keyword AS label")
|
||||
->orderBy('t1.id', 'asc');
|
||||
->table($this->table . " t1")
|
||||
->select("t1.id AS value, t1.keyword AS label")
|
||||
->orderBy('t1.id', 'asc');
|
||||
|
||||
return $builder->get()->getResultObject();
|
||||
$result = $builder->get()->getResultObject();
|
||||
|
||||
// Convertir el resultado en un array
|
||||
$resultArray = json_decode(json_encode($result), true);
|
||||
|
||||
// Buscar y mover el objeto con value == 3 al principio
|
||||
foreach ($resultArray as $key => $item) {
|
||||
if ($item['value'] == 4) {
|
||||
$generico = $item;
|
||||
unset($resultArray[$key]);
|
||||
array_unshift($resultArray, $generico);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Convertir de nuevo a objetos
|
||||
$result = json_decode(json_encode($resultArray));
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user