realizado el calculo por horas e introducido en el comparador

This commit is contained in:
Jaime Jiménez
2024-01-03 16:57:55 +01:00
parent fbea595a6b
commit 04f5748cb3
16 changed files with 240 additions and 49 deletions

View File

@ -129,10 +129,16 @@ class ClientePreciosModel extends \App\Models\GoBaseModel
function delete_values($cliente_id = 0){
$session = session();
$datetime = (new \CodeIgniter\I18n\Time("now"));
$date_value = $datetime->format('Y-m-d H:i:s');
$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();
}
@ -158,14 +164,90 @@ class ClientePreciosModel extends \App\Models\GoBaseModel
->set('tipo_impresion', $value->tipo_impresion)
->set('tiempo_min', $value->tiempo_min)
->set('tiempo_max', $value->tiempo_max)
->set('precio_hora', $value->precio_hora)
->set('margen', $value->margen)
->set('user_updated_id', $session->id_user)
->set('updated_at', $date_value)
->set('user_created_id', $session->id_user)
->set('created_at', $date_value)
->insert();
}
}
function update_from_plantilla($plantilla_id = 0){
$session = session();
$datetime = (new \CodeIgniter\I18n\Time("now"));
$date_value = $datetime->format('Y-m-d H:i:s');
// Se obtienen todos los id de clientes que usen esa tarifa
$clientes = $this->db
->table($this->table . " t1")
->select("t1.cliente_id AS id")
->where('t1.plantilla_id', $plantilla_id)
->distinct()
->get()->getResultObject();
if(count($clientes)<=0){
return;
}
foreach ($clientes as $cliente){
// Se borran los valores existentes
$this->delete_values($cliente->id);
// Se cargan los valores de la plantilla
$plantillaModel = model('App\Models\Clientes\ClientePlantillaPreciosLineasModel');
$values = $plantillaModel->getResource($plantilla_id)->get()->getResultObject();
foreach ($values as $value) {
$this->db
->table($this->table . " t1")
->set('cliente_id', $cliente->id)
->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('precio_hora', $value->precio_hora)
->set('margen', $value->margen)
->set('user_updated_id', $value->user_updated_id)
->set('updated_at', $value->updated_at)
->set('user_created_id', $session->id_user)
->set('created_at', $date_value)
->insert();
}
}
}
// config es un objeto que incluye
// - tipo: 'interior', 'cubierta', 'sobrecubierta'
// - tipo_maquina: 'toner', 'inkjet'
// - tipo_impresion: 'negro', 'color', 'negrohq', 'colorhq'
function get_precio_hora($cliente_id, $config, $tiempo){
// Se cargan los valores de la plantilla
$values = $this->db
->table($this->table . " t1")
->select("t1.precio_hora AS precio_hora, t1.margen AS margen")
->where('cliente_id', $cliente_id)
->where('tipo', $config->tipo)
->where('tipo_maquina', $config->tipo_maquina)
->where('tipo_impresion', $config->tipo_impresion)
->where('tiempo_min <=', $tiempo)
->where('tiempo_max >=', $tiempo)
->where('is_deleted', 0)
->get()->getResultObject();
if(count($values)>0){
return [floatval(($values[0])->precio_hora), floatval(($values[0])->margen)];
}
return [null, null];
}
/**
* Get resource data.