Merge branch 'main' into feat/ordenes-trabajo

This commit is contained in:
amazuecos
2024-12-05 20:32:32 +01:00
38 changed files with 2256 additions and 1093 deletions

View File

@ -7,14 +7,16 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel
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",
0 => "t1.id",
1 => "t1.tipo",
2 => "t1.tipo_maquina",
3 => "t1.tipo_impresion",
4 => "t1.tiempo_min",
5 => "t1.tiempo_max",
6 => "t1.precio_hora",
7 => "t1.margen",
8 => "CONCAT(t2.first_name, ' ', t2.last_name)",
9 => "t1.updated_at",
];
/**
@ -113,10 +115,20 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel
function delete_values($plantilla_id = 0){
$datetime = (new \CodeIgniter\I18n\Time("now"));
$date_value = $datetime->format('Y-m-d H:i:s');
$this->db
->table($this->table . " t1")
->where('t1.plantilla_id', $plantilla_id)
->set('is_deleted', 1)
->set('deleted_at', $date_value)
->update();
$this->db
->table('cliente_precios' . " t1")
->where('t1.plantilla_id', $plantilla_id)
->set('plantilla_id', null)
->update();
}
@ -127,14 +139,15 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel
*
* @return \CodeIgniter\Database\BaseBuilder
*/
public function getResource($plantilla_id = -1)
public function getResource($search = [], $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"
t1.user_updated_id AS user_updated_id, t1.updated_at AS updated_at, CONCAT(t2.first_name, ' ', t2.last_name) AS user_updated,
t1.id AS DT_RowId"
);
$builder->join("users t2", "t1.user_updated_id = t2.id", "left");
@ -142,8 +155,19 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel
$builder->where('t1.is_deleted', 0);
$builder->where('t1.plantilla_id', $plantilla_id);
return $builder;
if (empty($search))
return $builder;
else {
$builder->groupStart();
foreach ($search as $col_search) {
if ($col_search[1] > 0 && $col_search[0] < 4)
$builder->where(self::SORTABLE[$col_search[0]], $col_search[2]);
else
$builder->like(self::SORTABLE[$col_search[0]], $col_search[2]);
}
$builder->groupEnd();
return $builder;
}
}
public function checkIntervals($data = [], $id_linea = null, $plantilla_id = null){
@ -183,14 +207,13 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel
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();
$values = $clientePreciosModel->getResource([], $cliente_id)->get()->getResultObject();
foreach ($values as $value) {
$this->db
->table($this->table . " t1")
@ -201,7 +224,7 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel
->set('tiempo_min', $value->tiempo_min)
->set('tiempo_max', $value->tiempo_max)
->set('margen', $value->margen)
->set('user_updated_id', $session->id_user)
->set('user_updated_id', auth()->user()->id)
->set('updated_at', $date_value)
->insert();
}

View File

@ -7,7 +7,8 @@ class ClientePlantillaPreciosModel extends \App\Models\BaseModel
protected $table = "cliente_plantilla_precios";
const SORTABLE = [
0 => "t1.nombre",
0 => "t1.id",
1 => "t1.nombre",
];
/**
@ -48,11 +49,11 @@ class ClientePlantillaPreciosModel extends \App\Models\BaseModel
/**
* Get resource data.
*
* @param string $search
* @param array $search
*
* @return \CodeIgniter\Database\BaseBuilder
*/
public function getResource(string $search = "", $cliente_id = -1)
public function getResource($search = [])
{
$builder = $this->db
->table($this->table . " t1")
@ -61,14 +62,17 @@ class ClientePlantillaPreciosModel extends \App\Models\BaseModel
);
$builder->where('t1.is_deleted', 0);
return empty($search)
? $builder
: $builder
->groupStart()
->like("t1.nombre", $search)
->groupEnd();
if (empty($search))
return $builder;
else {
$builder->groupStart();
foreach ($search as $col_search) {
$builder->like(self::SORTABLE[$col_search[0]], $col_search[2]);
}
$builder->groupEnd();
return $builder;
}
}
}

View File

@ -14,14 +14,14 @@ class ClientePreciosModel extends \App\Models\BaseModel
protected $useAutoIncrement = true;
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",
0 => "t1.id",
1 => "t1.tipo",
2 => "t1.tipo_maquina",
3 => "t1.tipo_impresion",
4 => "t1.tiempo_min",
5 => "t1.tiempo_max",
6 => "t1.precio_hora",
7 => "t1.margen",
];
protected $allowedFields = [
@ -153,7 +153,7 @@ class ClientePreciosModel extends \App\Models\BaseModel
// Se cargan los valores de la plantilla
$plantillaModel = model('App\Models\Clientes\ClientePlantillaPreciosLineasModel');
$values = $plantillaModel->getResource($plantilla_id)->get()->getResultObject();
$values = $plantillaModel->getResource([],$plantilla_id)->get()->getResultObject();
foreach ($values as $value) {
$this->db
->table($this->table . " t1")
@ -178,7 +178,6 @@ class ClientePreciosModel extends \App\Models\BaseModel
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');
@ -187,6 +186,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)
->distinct()
->get()->getResultObject();
@ -200,7 +200,7 @@ class ClientePreciosModel extends \App\Models\BaseModel
// Se cargan los valores de la plantilla
$plantillaModel = model('App\Models\Clientes\ClientePlantillaPreciosLineasModel');
$values = $plantillaModel->getResource($plantilla_id)->get()->getResultObject();
$values = $plantillaModel->getResource([], $plantilla_id)->get()->getResultObject();
foreach ($values as $value) {
$this->db
->table($this->table . " t1")
@ -215,7 +215,7 @@ class ClientePreciosModel extends \App\Models\BaseModel
->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('user_created_id', auth()->user()->id)
->set('created_at', $date_value)
->insert();
}
@ -256,7 +256,7 @@ class ClientePreciosModel extends \App\Models\BaseModel
*
* @return \CodeIgniter\Database\BaseBuilder
*/
public function getResource($cliente_id = -1)
public function getResource($search = [], $cliente_id = -1)
{
$builder = $this->db
->table($this->table . " t1")
@ -271,11 +271,43 @@ class ClientePreciosModel extends \App\Models\BaseModel
$builder->where('t1.is_deleted', 0);
$builder->where('t1.cliente_id', $cliente_id);
return $builder;
if (empty($search))
return $builder;
else {
$builder->groupStart();
foreach ($search as $col_search) {
if ($col_search[0] > 0 && $col_search[0] < 4)
$builder->where(self::SORTABLE[$col_search[0]], $col_search[2]);
else
$builder->like(self::SORTABLE[$col_search[0]], $col_search[2]);
}
$builder->groupEnd();
return $builder;
}
}
public function getPlantilla($cliente_id = -1){
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.plantilla_id AS id, t2.nombre AS nombre"
);
$builder->where('t1.is_deleted', 0);
$builder->where('t1.cliente_id', $cliente_id);
$builder->join("cliente_plantilla_precios t2", "t1.plantilla_id = t2.id", "left");
$builder->limit(1);
$values = $builder->get()->getResultArray();
if(count($values)>0){
return $values[0];
}
return [];
}
public function checkIntervals($data = [], $id_linea = null, $cliente_id = null){

View File

@ -313,7 +313,7 @@ class PapelGenericoModel extends \App\Models\BaseModel
}
public function getPapelCliente($tipo, $is_cubierta = false, $selected_papel_id = null, $tapa_dura = null, $papel_especial = false)
public function getPapelCliente($tipo, $is_cubierta = false, $selected_papel_id = null, $tapa_dura = null, $papel_especial = false, $POD = null)
{
/*
1.-> Tipo impresion
@ -322,6 +322,13 @@ class PapelGenericoModel extends \App\Models\BaseModel
4.-> papeles genericos que aparecen en esos papeles impresion
*/
if ($POD == true && ($tipo == 'color' || $tipo == 'negro')) {
if($tipo == 'color')
$tipo = 'colorhq';
else if($tipo == 'negro')
$tipo = 'negrohq';
}
if ($selected_papel_id != null) {
$builder = $this->db
->table($this->table . " t1")
@ -404,6 +411,14 @@ class PapelGenericoModel extends \App\Models\BaseModel
if ($tipo == 'colorhq' || $tipo == 'negrohq') {
$builder->where("t2.rotativa", 0);
}
else{
if($POD == false){
$builder->where("t2.rotativa", 1);
}
else if ($POD == true){
$builder->where("t2.rotativa", 0);
}
}
if ($selected_papel_id != null)