mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
212 lines
6.3 KiB
PHP
Executable File
212 lines
6.3 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models\Clientes;
|
|
|
|
class ClientePlantillaPreciosLineasModel extends \App\Models\GoBaseModel
|
|
{
|
|
protected $table = "cliente_plantilla_precios_lineas";
|
|
|
|
const SORTABLE = [
|
|
0 => "t1.tipo",
|
|
1 => "t1.tipo_maquina",
|
|
2 => "t1.tipo_impresion",
|
|
3 => "t1.tiempo_min",
|
|
4 => "t1.tiempo_max",
|
|
5 => "t1.precio_hora",
|
|
6 => "t1.margen",
|
|
|
|
];
|
|
|
|
/**
|
|
* Whether primary key uses auto increment.
|
|
*
|
|
* @var bool
|
|
*/
|
|
protected $useAutoIncrement = true;
|
|
|
|
|
|
protected $allowedFields = [
|
|
"plantilla_id",
|
|
"tipo",
|
|
"tipo_maquina",
|
|
"tipo_impresion",
|
|
"tiempo_min",
|
|
"tiempo_max",
|
|
"precio_hora",
|
|
"margen",
|
|
"is_deleted",
|
|
"deleted_at",
|
|
"created_at",
|
|
"updated_at",
|
|
"user_updated_id"];
|
|
|
|
protected $returnType = "App\Entities\Clientes\ClientePlantillaPreciosLineasEntity";
|
|
|
|
protected $useTimestamps = true;
|
|
protected $useSoftDeletes = false;
|
|
|
|
protected $createdField = "created_at";
|
|
|
|
protected $updatedField = "updated_at";
|
|
|
|
public static $labelField = "plantilla_id";
|
|
|
|
protected $validationRules = [
|
|
"plantilla_id" => [
|
|
"label" => "ClientePrecios.plantilla_id",
|
|
"rules" => "required",
|
|
],
|
|
"tipo" => [
|
|
"label" => "ClientePrecios.tipo",
|
|
"rules" => "required|in_list[interior,cubierta,sobrecubierta]",
|
|
],
|
|
"tipo_maquina" => [
|
|
"label" => "ClientePrecios.tipo_maquina",
|
|
"rules" => "required|in_list[toner,inkjet]",
|
|
],
|
|
"tipo_impresion" => [
|
|
"label" => "ClientePrecios.tipo_impresion",
|
|
"rules" => "required|in_list[negro,color,negrohq,colorhq]",
|
|
],
|
|
"tiempo_min" => [
|
|
"label" => "ClientePrecios.tiempo_min",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"tiempo_max" => [
|
|
"label" => "ClientePrecios.tiempo_max",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"margen" => [
|
|
"label" => "ClientePrecios.margen",
|
|
"rules" => "required|decimal",
|
|
],
|
|
|
|
|
|
|
|
];
|
|
|
|
protected $validationMessages = [
|
|
"plantilla_id" => [
|
|
"required" => "ClientePrecios.validation.required",
|
|
|
|
],
|
|
"tipo" => [
|
|
"required" => "ClientePrecios.validation.required",
|
|
],
|
|
"tipo_maquina" => [
|
|
"required" => "ClientePrecios.validation.required",
|
|
],
|
|
"tipo_impresion" => [
|
|
"required" => "ClientePrecios.validation.required",
|
|
],
|
|
"tiempo_min" => [
|
|
"required" => "ClientePrecios.validation.required",
|
|
],
|
|
"tiempo_max" => [
|
|
"required" => "ClientePrecios.validation.required",
|
|
],
|
|
"margen" => [
|
|
"required" => "ClientePrecios.validation.required",
|
|
],
|
|
];
|
|
|
|
|
|
|
|
function delete_values($plantilla_id = 0){
|
|
$this->db
|
|
->table($this->table . " t1")
|
|
->where('t1.plantilla_id', $plantilla_id)
|
|
->set('is_deleted', 1)
|
|
->update();
|
|
}
|
|
|
|
/**
|
|
* Get resource data.
|
|
*
|
|
* @param string $search
|
|
*
|
|
* @return \CodeIgniter\Database\BaseBuilder
|
|
*/
|
|
public function getResource($plantilla_id = -1)
|
|
{
|
|
$builder = $this->db
|
|
->table($this->table . " t1")
|
|
->select(
|
|
"t1.id as id, t1.tipo AS tipo, t1.tipo_maquina AS tipo_maquina, t1.tipo_impresion AS tipo_impresion,
|
|
t1.tiempo_min AS tiempo_min, t1.tiempo_max AS tiempo_max, t1.precio_hora AS precio_hora, t1.margen AS margen,
|
|
t1.user_updated_id AS user_updated_id, t1.updated_at AS updated_at, CONCAT(t2.first_name, ' ', t2.last_name) AS user_updated"
|
|
);
|
|
|
|
$builder->join("auth_user t2", "t1.user_updated_id = t2.id_user", "left");
|
|
|
|
$builder->where('t1.is_deleted', 0);
|
|
$builder->where('t1.plantilla_id', $plantilla_id);
|
|
|
|
|
|
return $builder;
|
|
}
|
|
|
|
public function checkIntervals($data = [], $id_linea = null, $plantilla_id = null){
|
|
|
|
helper('general');
|
|
|
|
if(floatval($data["tiempo_min"])>= floatval($data["tiempo_max"])){
|
|
return lang('ClientePrecios.errors.error_tiempo_range');
|
|
}
|
|
|
|
$rows = $this->db
|
|
->table($this->table)
|
|
->select("id, tiempo_min, tiempo_max")
|
|
->where("is_deleted", 0)
|
|
->where("tipo", $data["tipo"])
|
|
->where("tipo_maquina", $data["tipo_maquina"])
|
|
->where("tipo_impresion", $data["tipo_impresion"])
|
|
->where("plantilla_id", $plantilla_id)
|
|
->get()->getResultObject();
|
|
|
|
|
|
foreach ($rows as $row) {
|
|
if (!is_null($id_linea)){
|
|
if($row->id == $id_linea){
|
|
continue;
|
|
}
|
|
}
|
|
if(check_overlap(floatval($data["tiempo_min"]), floatval($data["tiempo_max"]),
|
|
$row->tiempo_min, $row->tiempo_max)){
|
|
return lang('ClientePrecios.errors.error_tiempo_overlap');
|
|
}
|
|
}
|
|
|
|
return "";
|
|
}
|
|
|
|
|
|
function copy_from_cliente($cliente_id = 0, $plantilla_id = 0){
|
|
|
|
$session = session();
|
|
$datetime = (new \CodeIgniter\I18n\Time("now"));
|
|
$date_value = $datetime->format('Y-m-d H:i:s');
|
|
|
|
|
|
// Se cargan los valores en la plantilla
|
|
$clientePreciosModel = model('App\Models\Clientes\ClientePreciosModel');
|
|
$values = $clientePreciosModel->getResource($cliente_id)->get()->getResultObject();
|
|
foreach ($values as $value) {
|
|
$this->db
|
|
->table($this->table . " t1")
|
|
->set('plantilla_id', $plantilla_id)
|
|
->set('tipo', $value->tipo)
|
|
->set('tipo_maquina', $value->tipo_maquina)
|
|
->set('tipo_impresion', $value->tipo_impresion)
|
|
->set('tiempo_min', $value->tiempo_min)
|
|
->set('tiempo_max', $value->tiempo_max)
|
|
->set('margen', $value->margen)
|
|
->set('user_updated_id', $session->id_user)
|
|
->set('updated_at', $date_value)
|
|
->insert();
|
|
}
|
|
|
|
}
|
|
|
|
}
|