terminando el editor2 de los papeles

This commit is contained in:
Jaime Jimenez
2023-07-05 11:46:00 +02:00
parent 14b69b52ae
commit 370b0deb62
5 changed files with 279 additions and 57 deletions

View File

@ -1,6 +1,8 @@
<?php
namespace App\Models\Configuracion;
use CodeIgniter\Database\RawSql;
class MaquinasPapelesImpresionModel extends \App\Models\GoBaseModel
{
protected $table = "lg_maquina_papel_impresion";
@ -35,7 +37,7 @@ class MaquinasPapelesImpresionModel extends \App\Models\GoBaseModel
*
* @return \CodeIgniter\Database\BaseBuilder
*/
public function getResource(string $search = "", $isRotativa = 0)
public function getResource(string $search = "", $isRotativa = 0, $tarifas = [], $maquina_id = -1)
{
$builder = $this->db
->table($this->table . " t1")
@ -43,44 +45,52 @@ class MaquinasPapelesImpresionModel extends \App\Models\GoBaseModel
"t1.maquina_id AS maquina_id, t1.papel_impresion_id AS papel_impresion_id, t1.active AS active, t2.nombre AS maquina,
t3.nombre AS papel_impresion, t3.gramaje AS gramaje, , t3.bn AS bn, t3.color AS color, t3.cubierta AS cubierta, , t3.sobrecubierta AS sobrecubierta,
t3.rotativa AS rotativa, t4.nombre as papel_generico"
);
$builder->join("lg_maquinas t2", "t1.maquina_id = t2.id", "left");
$builder->join("lg_papel_impresion t3", "t1.papel_impresion_id = t3.id", "left");
$builder->join("lg_papel_generico t4", "t3.papel_generico_id = t4.id", "left");
)
->join("lg_papel_impresion t3", "t1.papel_impresion_id = t3.id", "left")
->join("lg_maquinas t2", "t1.maquina_id = t2.id", "left")
->join("lg_papel_generico t4", "t3.papel_generico_id = t4.id", "left");
$builder->where("t1.maquina_id", $maquina_id);
$builder->where("t2.is_deleted", 0);
$builder->where("t3.is_deleted", 0);
$builder->where("t4.is_deleted", 0);
$builder->where("t3.isActivo", 1);
$builder->where("t3.rotativa", $isRotativa);
$isFirst = false;
$where_str = "";
// Si hay tarifas...
/*if (!empty($tarifas)){
$isFirst = true;
$where_str = "(";
//Si hay tarifas...
if (!empty($tarifas)){
foreach ($tarifas as $tarifa){
if (!$isFirst)
$where_str += ' OR ';
if ($tarifa->uso == 'portada')
$where_str += "t3.portada=1 AND ";
if ($tarifa->tipo == 'negro' || $tarifa->tipo == 'negrohq')
$where_str += "t3.bn=1";
else
$where_str += "t3.bn=1";
$where_str .= ' OR ';
else{
$isFirst = false;
}
if ($tarifa->uso == 'cubierta')
$where_str .= "t3.cubierta=1";
else if ($tarifa->uso == 'sobrecubierta')
$where_str .= "t3.sobrecubierta=1";
else{
if ($tarifa->tipo == 'negro' || $tarifa->tipo == 'negrohq')
$where_str .= "t3.bn=1";
else
$where_str .= "t3.color=1";
}
}
$builder->where($where_str);
}*/
$where_str .= ")";
$builder->where(new RawSql($where_str));
}
// si no hay tarifas no hay que devolver nada
/*else{
return "";
}*/
else{
// Se pone una condicion que no se puede dar
$builder->where("t3.bn", 2);
}
return empty($search)
@ -91,4 +101,80 @@ class MaquinasPapelesImpresionModel extends \App\Models\GoBaseModel
->orLike("t3.nombre", $search)
->groupEnd();
}
public function getInitData($isRotativa = 0, $tarifas = [], $maquina_id = -1)
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.*"
);
$builder->join("lg_papel_impresion t2", "t1.papel_impresion_id = t2.id", "left");
$builder->where("t1.maquina_id", $maquina_id);
$builder->where("t2.is_deleted", 0);
$builder->where("t2.isActivo", 1);
$builder->where("t2.rotativa", $isRotativa);
$builder->where("t1.active", 1);
$isFirst = true;
$where_str = "";
//Si hay tarifas...
if (!empty($tarifas)){
foreach ($tarifas as $tarifa){
if (!$isFirst)
$where_str .= ' OR ';
else{
$isFirst = false;
}
if ($tarifa->uso == 'cubierta')
$where_str .= "`t2`.`cubierta`=1";
else if ($tarifa->uso == 'sobrecubierta')
$where_str .= "`t2`.`sobrecubierta`=1";
else{
if ($tarifa->tipo == 'negro' || $tarifa->tipo == 'negrohq')
$where_str .= "`t2`.`bn`=1 ";
else
$where_str .= "`t2`.`color`=1 ";
}
}
$builder->where($where_str);
}
// si no hay tarifas no hay que devolver nada
else{
// Se pone una condicion que no se puede dar
$builder->where("t3.bn", 2);
}
return $builder;
}
public function deleteRows($maquina_id = -1){
$this->db
->table($this->table . " t1")
->where("maquina_id", $maquina_id)
->delete();
}
public function insertRows($values = []){
if (!empty($values)){
$this->db->table($this->table)->insertBatch($values);
}
}
public function updateRows($values = []){
if (!empty($values)){
foreach($values as $value){
$builder = $this->db->table($this->table)->where('maquina_id', $value['maquina_id']);
$builder->where('papel_impresion_id', $value['papel_impresion_id']);
$builder->update($value);
}
}
}
}

View File

@ -214,6 +214,7 @@ class PapelImpresionModel extends \App\Models\GoBaseModel
$builder->join("lg_papel_generico t2", "t1.papel_generico_id = t2.id", "left");
$builder->where("t1.is_deleted", 0);
$builder->where("t1.isActivo", 1);
if($generico_id>0){
$builder->where("t1.papel_generico_id", $generico_id);
}
@ -229,4 +230,47 @@ class PapelImpresionModel extends \App\Models\GoBaseModel
->orLike("t2.nombre", $search)
->groupEnd();
}
public function getIdPapelesActivos($tarifas = [])
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id AS id"
);
$builder->where("t1.is_deleted", 0);
$builder->where("t1.isActivo", 1);
$isFirst = true;
$where_str = "";
//Si hay tarifas...
if (!empty($tarifas)){
foreach ($tarifas as $tarifa){
if (!$isFirst)
$where_str .= ' OR ';
else{
$isFirst = false;
}
if ($tarifa->uso == 'cubierta')
$where_str .= "`t1`.`cubierta`=1";
else if ($tarifa->uso == 'sobrecubierta')
$where_str .= "`t1`.`sobrecubierta`=1";
else{
if ($tarifa->tipo == 'negro' || $tarifa->tipo == 'negrohq')
$where_str .= "`t1`.`bn`=1 ";
else
$where_str .= "`t1`.`color`=1 ";
}
}
$builder->where($where_str);
}
// si no hay tarifas no hay que devolver nada
else{
// Se pone una condicion que no se puede dar
$builder->where("t1.bn", 2);
}
return $builder;
}
}