Merge branch 'refactor/messages-view' into feat/ordenes-trabajo

This commit is contained in:
amazuecos
2024-11-30 17:10:26 +01:00
156 changed files with 6538 additions and 2643 deletions

View File

@ -10,7 +10,7 @@ class ChatDeparmentModel extends Model
protected $table = 'chat_departments';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $returnType = 'array';
protected $returnType = 'object';
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $allowedFields = [
@ -53,9 +53,9 @@ class ChatDeparmentModel extends Model
public function getChatDepartments(string $type = "general"): array
{
$userModel = model(UserModel::class);
$chatMessageModel = model(ChatMessageModel::class);
$chatModel = model(ChatModel::class);
$query = $this->db->table('chat_departments')
$query = $this->builder()
->select(
[
@ -63,7 +63,6 @@ class ChatDeparmentModel extends Model
'chat_departments.name',
'chat_departments.display',
'chat_department_users.user_id',
'chats.id as chatId',
]
)
->join(
@ -71,30 +70,26 @@ class ChatDeparmentModel extends Model
"chat_department_users.chat_department_id = chat_departments.id",
'left'
)
->join("chats", "chats.chat_department_id = chat_departments.id", "left")
->join(
"users",
"chat_department_users.user_id = users.id",
'left'
)->join(
"chat_messages",
"chat_messages.chat_id = chats.id",
"left"
)
->where("chat_departments.type", $type);
if (auth()->user()->cliente_id == null) {
$query->where("chat_department_users.user_id", auth()->user()->id);
}
// if (auth()->user()->cliente_id == null) {
// $query->where("chat_department_users.user_id", auth()->user()->id);
// }
$results = $query->get()->getResultArray();
// Create the desired structure
$departments = [];
foreach ($results as $row) {
$departmentName = $row['name'];
// If the department is not yet added to the array, initialize it
if (!isset($departments[$departmentName])) {
$departments[$departmentName] = [
'id' => $row['id'],
'name' => $row['name'],
@ -131,4 +126,21 @@ class ChatDeparmentModel extends Model
->get()->getResultObject();
return $result;
}
public function getDisplay(int $chat_deparment_id) : string
{
return $this->find($chat_deparment_id)->display;
}
public function getChatDepartmentSelect(string $query = null)
{
$q = $this->builder()->select([
"id",
"display as name",
"description"
]);
if($query){
$q->orLike("display",$query)
->orLike("name",$query);
}
return $q;
}
}

View File

@ -2,16 +2,18 @@
namespace App\Models\Chat;
use App\Models\ChatNotification;
use App\Models\Usuarios\UserModel;
use CodeIgniter\Model;
use CodeIgniter\Database\BaseBuilder;
class ChatMessageModel extends Model
{
protected $table = 'chat_messages';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $returnType = 'object';
protected $useSoftDeletes = true;
protected $protectFields = true;
protected $allowedFields = [
"message",
@ -28,7 +30,7 @@ class ChatMessageModel extends Model
protected array $castHandlers = [];
// Dates
protected $useTimestamps = false;
protected $useTimestamps = true;
protected $dateFormat = 'datetime';
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
@ -71,11 +73,30 @@ class ChatMessageModel extends Model
}
return $messages;
}
public function get_chat_message(int $chat_message_id): object
{
$user = model(UserModel::class);
$auth_user = auth()->user();
$message = $this->find($chat_message_id);
$message->pos = $auth_user->id == $message->sender_id ? "right" : "left";
if ($auth_user->id == $message->sender_id) {
$message->sender_first_name = $auth_user->first_name;
$message->sender_last_name = $auth_user->last_name;
} else {
$sender_user = $user->find($message->sender_id);
$message->sender_first_name = $sender_user->first_name;
$message->sender_last_name = $sender_user->last_name;
}
return $message;
}
public function get_chat_contact_messages(int $receiver_id): array
{
$conversationArray = [];
$userModel = model(UserModel::class);
$chatNotificationModel = model(ChatNotification::class);
$receiverUser = $userModel->find($receiver_id);
$chat_id = null;
$messagesFromClient = $this->builder()
->where("sender_id", auth()->user()->id)
->where("receiver_id", $receiverUser->id)
@ -95,7 +116,9 @@ class ChatMessageModel extends Model
$conversationArray[] = $message;
}
$dates = array();
foreach ($conversationArray as $key => $row) {
$chatNotificationModel->builder()->set("viewed", true)->where("chat_message_id", $row->id)->where("user_id", auth()->user()->id)->update();
$dates[$key] = strtotime($row->created_at);
}
array_multisort($dates, SORT_ASC, $conversationArray);
@ -110,11 +133,32 @@ class ChatMessageModel extends Model
->where("receiver_id", auth()->user()->id)->countAllResults();
return $messagesFromReceiver;
}
public function get_chat_department_messages_count(int $chat_id) : int
{
$chatDepartmentMessagesCount = $this->builder()
->where("id",$chat_id)
->countAllResults();
return $chatDepartmentMessagesCount;
}
public function get_chat_messages_count(int $sender_id): int
{
$messagesFromReceiver = $this->builder()
->groupStart()
->where("sender_id", $sender_id)
->where("receiver_id", auth()->user()->id)
->orGroupStart()
->where("receiver_id", $sender_id)
->where("sender_id", auth()->user()->id)
->groupEnd()
->groupEnd()
->countAllResults();
return $messagesFromReceiver;
}
public function set_chat_messages_as_read(int $sender_id): int
{
$messagesFromReceiver = $this->builder()
->set("viewed", true)
->where("sender_id", $sender_id)
->where("user_id", $sender_id)
->where("receiver_id", auth()->user()->id)->update();
return $messagesFromReceiver;
}
@ -122,23 +166,32 @@ class ChatMessageModel extends Model
{
$chatDepartmentModel = model(ChatDeparmentModel::class);
$chatModel = model(ChatModel::class);
if(auth()->user()->cliente_id){
$messagesFromReceiver = 0;
$auth_user = auth()->user();
$chat_department_id = $chatModel->find($chat_id)->chat_department_id;
$users_in_chat = array_map(fn($x) => $x->id, $chatDepartmentModel->getChatDepartmentUsers($chat_department_id));
if (auth()->user()->cliente_id) {
// Si el usuario es cliente, marca como leídos todos los mensajes exceptos los suyos
$messagesFromReceiver = $this->builder()
->set("viewed", true)
->where("chat_id", $chat_id)
->whereNotIn("sender_id", [auth()->user()->id])->update();
}else{
$chat_department_id = $chatModel->find($chat_id)->chat_department_id;
$users_in_chat = array_map(fn($x) => $x->id, $chatDepartmentModel->getChatDepartmentUsers($chat_department_id));
$messagesFromReceiver = $this->builder()
->set("viewed", true)
->where("chat_id", $chat_id)
->whereNotIn("sender_id", $users_in_chat)
->update();
->set("viewed", true)
->where("chat_id", $chat_id)
->whereNotIn("sender_id", [$auth_user->id])->update();
} else {
// Si el usuario no es cliente y está dentro de los usuarios de departamento
// marca como leido todos los mensajes, excepto los mensajes de los usuarios
// de dentro del departamento
if (in_array($auth_user->id, $users_in_chat) == true) {
// if (($key = array_search($auth_user->id, $users_in_chat)) !== false) {
// unset($users_in_chat[$key]);
// }
$messagesFromReceiver = $this->builder()
->set("viewed", true)
->where("chat_id", $chat_id)
->whereNotIn("sender_id", $users_in_chat)
->update();
}
}
return $messagesFromReceiver;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -47,4 +47,16 @@ class ChatNotification extends Model
protected $afterFind = [];
protected $beforeDelete = [];
protected $afterDelete = [];
public function isChatMessageViewed(int $chat_message_id) : bool
{
$status = false;
$count = $this->where("chat_message_id",$chat_message_id)->where("viewed",false)->countAllResults();
if($count>0){
$status = false;
}else{
$status = true;
}
return $status;
}
}

View File

@ -10,7 +10,7 @@ class ChatUser extends Model
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $useSoftDeletes = true;
protected $protectFields = true;
protected $allowedFields = [
"user_id",
@ -24,7 +24,7 @@ class ChatUser extends Model
protected array $castHandlers = [];
// Dates
protected $useTimestamps = false;
protected $useTimestamps = true;
protected $dateFormat = 'datetime';
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
@ -46,4 +46,12 @@ class ChatUser extends Model
protected $afterFind = [];
protected $beforeDelete = [];
protected $afterDelete = [];
public function getChatUserArrayId(int $chat_id) : array
{
$queryResult = $this->builder()
->select(['chat_users.user_id'])
->where("chat_users.chat_id",$chat_id)
->get()->getResultObject();
return array_map(fn($q) => $q->user_id,$queryResult);
}
}

View File

@ -19,9 +19,10 @@ class PapelGenericoModel extends \App\Models\BaseModel
1 => "t1.code",
2 => "t1.code_ot",
3 => "t1.show_in_client",
4 => "t1.show_in_client_special",
];
protected $allowedFields = ["nombre", "code", "code_ot", "show_in_client", "deleted_at", "is_deleted"];
protected $allowedFields = ["nombre", "code", "code_ot", "show_in_client", "show_in_client_special", "deleted_at", "is_deleted"];
protected $returnType = "App\Entities\Configuracion\PapelGenerico";
protected $useTimestamps = true;
@ -62,7 +63,8 @@ class PapelGenericoModel extends \App\Models\BaseModel
];
public function getIdFromCode(string $code=""){
public function getIdFromCode(string $code = "")
{
$builder = $this->db
->table($this->table . " t1")
->select(
@ -77,7 +79,8 @@ class PapelGenericoModel extends \App\Models\BaseModel
}
public function getCodeFromId($id=0){
public function getCodeFromId($id = 0)
{
$builder = $this->db
->table($this->table . " t1")
->select(
@ -104,23 +107,24 @@ class PapelGenericoModel extends \App\Models\BaseModel
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id AS id, t1.nombre AS nombre, t1.code AS code, t1.code_ot AS code_ot, t1.show_in_client AS show_in_client"
"t1.id AS id, t1.nombre AS nombre, t1.code AS code, t1.code_ot AS code_ot,
t1.show_in_client AS show_in_client, t1.show_in_client_special AS show_in_client_special"
)
->where("is_deleted", 0);
return empty($search)
? $builder
: $builder
->groupStart()
->like("t1.id", $search)
->orLike("t1.nombre", $search)
->orLike("t1.code", $search)
->orLike("t1.code_ot", $search)
->orLike("t1.id", $search)
->orLike("t1.nombre", $search)
->orLike("t1.code", $search)
->orLike("t1.code_ot", $search)
->groupEnd();
->groupStart()
->like("t1.id", $search)
->orLike("t1.nombre", $search)
->orLike("t1.code", $search)
->orLike("t1.code_ot", $search)
->orLike("t1.id", $search)
->orLike("t1.nombre", $search)
->orLike("t1.code", $search)
->orLike("t1.code_ot", $search)
->groupEnd();
}
@ -128,9 +132,9 @@ class PapelGenericoModel extends \App\Models\BaseModel
{
/*
1.-> Tipo impresion
2.-> Maquina
3.-> Papeles impresion asociados a esa maquina
4.-> papeles genericos que aparecen en esos papeles impresion
2.-> Maquina
3.-> Papeles impresion asociados a esa maquina
4.-> papeles genericos que aparecen en esos papeles impresion
*/
$builder = $this->db
->table($this->table . " t1")
@ -153,48 +157,48 @@ class PapelGenericoModel extends \App\Models\BaseModel
->where("t5.is_deleted", 0)
->where("t5.tipo", $tipo);
if($is_cubierta==true){
$builder->where("t2.cubierta", 1);
$builder->where("t5.uso", 'cubierta');
}
if($is_sobrecubierta==true){
$builder->where("t2.sobrecubierta", 1);
$builder->where("t5.uso", 'sobrecubierta');
}
if ($is_cubierta == true) {
if($is_cubierta==false && $is_sobrecubierta==false){
$builder->where("t5.uso", 'interior');
}
$builder->where("t2.cubierta", 1);
$builder->where("t5.uso", 'cubierta');
}
if($is_guardas==true){
$builder->where("t2.guardas", 1);
}
if ($is_sobrecubierta == true) {
$builder->where("t2.sobrecubierta", 1);
$builder->where("t5.uso", 'sobrecubierta');
}
if($rotativa==true){
$builder->where("t2.rotativa", 1);
}
if ($is_cubierta == false && $is_sobrecubierta == false) {
$builder->where("t5.uso", 'interior');
}
if($mostrar_cliente!=null){
$builder->where("t1.show_in_client", $mostrar_cliente);
}
if ($is_guardas == true) {
$builder->where("t2.guardas", 1);
}
if ($rotativa == true) {
$builder->where("t2.rotativa", 1);
}
if ($mostrar_cliente != null) {
$builder->where("t1.show_in_client", $mostrar_cliente);
}
$data = $builder->orderBy("t1.nombre", "asc")->get()->getResultObject();
//var_dump($this->db->getLastQuery());
return $data;
}
public function getGramajeComparador(string $papel_generico_nombre="", $uso="", $ejemplares=0)
public function getGramajeComparador(string $papel_generico_nombre = "", $uso = "", $ejemplares = 0)
{
if($uso == 'cubierta' || $uso == 'sobrecubierta')
if ($uso == 'cubierta' || $uso == 'sobrecubierta')
$tipo = 'colorhq';
else
$tipo=$uso; // color y colorhq valen para los dos
if($uso == 'bn')
$tipo="negro";
if($uso == 'bnhq')
$tipo="negrohq";
$tipo = $uso; // color y colorhq valen para los dos
if ($uso == 'bn')
$tipo = "negro";
if ($uso == 'bnhq')
$tipo = "negrohq";
$builder = $this->db
->table($this->table . " t1")
@ -205,7 +209,7 @@ class PapelGenericoModel extends \App\Models\BaseModel
->join("lg_maquina_papel_impresion t3", "t3.papel_impresion_id = t2.id", "left")
->join("lg_maquinas t4", "t3.maquina_id = t4.id", "left")
->join("lg_maquinas_tarifas_impresion t5", "t5.maquina_id = t4.id", "left")
->where("t1.is_deleted", 0)
->where("t2.is_deleted", 0)
->where("t2.isActivo", 1)
@ -214,44 +218,43 @@ class PapelGenericoModel extends \App\Models\BaseModel
->where("t4.tipo", "impresion")
->where("t5.tipo", $tipo)
->where("t1.nombre", $papel_generico_nombre);
$uso_tarifa = 'interior';
if($uso == 'bn' || $uso == 'bnhq')
$builder->where("t2.bn", 1);
else if ($uso == 'color' || $uso == 'colorhq')
$builder->where("t2.color", 1);
else if ($uso == 'cubierta'){
$uso_tarifa = 'cubierta';
$builder->where("t2.cubierta", 1);
}
else if ($uso == 'sobrecubierta'){
$uso_tarifa = 'sobrecubierta';
$builder->where("t2.sobrecubierta", 1);
}
$uso_tarifa = 'interior';
$builder->where("t5.uso", $uso_tarifa);
if ($uso == 'bn' || $uso == 'bnhq')
$builder->where("t2.bn", 1);
else if ($uso == 'color' || $uso == 'colorhq')
$builder->where("t2.color", 1);
else if ($uso == 'cubierta') {
$uso_tarifa = 'cubierta';
$builder->where("t2.cubierta", 1);
} else if ($uso == 'sobrecubierta') {
$uso_tarifa = 'sobrecubierta';
$builder->where("t2.sobrecubierta", 1);
}
$builder->where("t4.min <=", $ejemplares);
$builder->where("t4.max >=", $ejemplares);
$values = $builder->orderBy("t2.gramaje", "asc")->get()->getResultObject();
$id = 1;
foreach ($values as $value){
$value->id = $id;
$id++;
}
$values_array = array_map( function( $value ) {
return $value->text;
}, $values );
$unique_values = array_unique($values_array);
return array_values(array_intersect_key($values, $unique_values));
$builder->where("t5.uso", $uso_tarifa);
$builder->where("t4.min <=", $ejemplares);
$builder->where("t4.max >=", $ejemplares);
$values = $builder->orderBy("t2.gramaje", "asc")->get()->getResultObject();
$id = 1;
foreach ($values as $value) {
$value->id = $id;
$id++;
}
$values_array = array_map(function ($value) {
return $value->text;
}, $values);
$unique_values = array_unique($values_array);
return array_values(array_intersect_key($values, $unique_values));
}
//tipo: negro, negrohq, color, colorhq
//uso: interior, rotativa, cubierta, sobrecubierta
public function getGramajeLineasPresupuesto($papel_generico_id=0, $tipo="", $uso="")
public function getGramajeLineasPresupuesto($papel_generico_id = 0, $tipo = "", $uso = "")
{
$builder = $this->db
->table($this->table . " t1")
@ -262,7 +265,7 @@ class PapelGenericoModel extends \App\Models\BaseModel
->join("lg_maquina_papel_impresion t3", "t3.papel_impresion_id = t2.id", "left")
->join("lg_maquinas t4", "t3.maquina_id = t4.id", "left")
->join("lg_maquinas_tarifas_impresion t5", "t5.maquina_id = t4.id", "left")
->where("t1.is_deleted", 0)
->where("t2.is_deleted", 0)
->where("t2.isActivo", 1)
@ -272,42 +275,142 @@ class PapelGenericoModel extends \App\Models\BaseModel
->where("t5.tipo", $tipo)
->where("t1.id", $papel_generico_id);
$uso_tarifa = 'interior';
$uso_tarifa = 'interior';
if ($uso == 'cubierta'){
$uso_tarifa = 'cubierta';
$builder->where("t2.cubierta", 1);
}
else if ($uso == 'sobrecubierta'){
$uso_tarifa = 'sobrecubierta';
$builder->where("t2.sobrecubierta", 1);
}
else{
if($tipo == 'negro' || $tipo == 'negrohq')
$builder->where("t2.bn", 1);
else if ($tipo == 'color' || $tipo == 'colorhq')
$builder->where("t2.color", 1);
}
if($uso=='rotativa')
$builder->where("t2.rotativa", 1);
else
$builder->where("t2.rotativa", 0);
if ($uso == 'cubierta') {
$uso_tarifa = 'cubierta';
$builder->where("t2.cubierta", 1);
} else if ($uso == 'sobrecubierta') {
$uso_tarifa = 'sobrecubierta';
$builder->where("t2.sobrecubierta", 1);
} else {
if ($tipo == 'negro' || $tipo == 'negrohq')
$builder->where("t2.bn", 1);
else if ($tipo == 'color' || $tipo == 'colorhq')
$builder->where("t2.color", 1);
}
$builder->where("t5.uso", $uso_tarifa);
$values = $builder->orderBy("t2.gramaje", "asc")->get()->getResultObject();
$id = 1;
foreach ($values as $value){
$value->id = $id;
$id++;
}
$values_array = array_map( function( $value ) {
return $value->text;
}, $values );
$unique_values = array_unique($values_array);
return array_values(array_intersect_key($values, $unique_values));
if ($uso == 'rotativa')
$builder->where("t2.rotativa", 1);
else
$builder->where("t2.rotativa", 0);
$builder->where("t5.uso", $uso_tarifa);
$values = $builder->orderBy("t2.gramaje", "asc")->get()->getResultObject();
$id = 1;
foreach ($values as $value) {
$value->id = $id;
$id++;
}
$values_array = array_map(function ($value) {
return $value->text;
}, $values);
$unique_values = array_unique($values_array);
return array_values(array_intersect_key($values, $unique_values));
}
public function getPapelCliente($tipo, $is_cubierta = false, $selected_papel_id = null, $tapa_dura = null, $papel_especial = false)
{
/*
1.-> Tipo impresion
2.-> Maquina
3.-> Papeles impresion asociados a esa maquina
4.-> papeles genericos que aparecen en esos papeles impresion
*/
if ($selected_papel_id != null) {
$builder = $this->db
->table($this->table . " t1")
->select(
"t2.gramaje as gramaje",
// for debug, t2.nombre AS nombre_papel_impresion, t4.nombre AS maquina_nombre, t5.uso AS tarifa_uso, t5.tipo AS tarifa_tipo"
)
->join("lg_papel_impresion t2", "t2.papel_generico_id = t1.id", "inner")
->join("lg_maquina_papel_impresion t3", "t3.papel_impresion_id = t2.id", "inner")
->join("lg_maquinas t4", "t3.maquina_id = t4.id", "inner")
->join("lg_maquinas_tarifas_impresion t5", "t5.maquina_id = t4.id", "inner")
->where("t1.id", $selected_papel_id)
->where("t1.is_deleted", 0)
->where("t1.show_in_client", 1)
->where("t2.is_deleted", 0)
->where("t2.isActivo", 1)
->where("t2.use_in_client", 1)
->where("t3.active", 1)
->where("t4.is_deleted", 0)
->where("t4.tipo", "impresion")
->where("t5.is_deleted", 0)
->where("t5.tipo", $tipo)
->distinct('t2.gramaje');
} else {
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id as id, t1.nombre AS nombre",
// for debug, t2.nombre AS nombre_papel_impresion, t4.nombre AS maquina_nombre, t5.uso AS tarifa_uso, t5.tipo AS tarifa_tipo"
)
->join("lg_papel_impresion t2", "t2.papel_generico_id = t1.id", "inner")
->join("lg_maquina_papel_impresion t3", "t3.papel_impresion_id = t2.id", "inner")
->join("lg_maquinas t4", "t3.maquina_id = t4.id", "inner")
->join("lg_maquinas_tarifas_impresion t5", "t5.maquina_id = t4.id", "inner")
->where("t1.is_deleted", 0)
->where("t1.show_in_client", 1)
->where("t2.is_deleted", 0)
->where("t2.isActivo", 1)
->where("t2.use_in_client", 1)
->where("t3.active", 1)
->where("t4.is_deleted", 0)
->where("t4.tipo", "impresion")
->where("t5.is_deleted", 0)
->where("t5.tipo", $tipo)
->distinct('t1.id');
}
// Validación adicional para asegurar que t1.id esté presente en las combinaciones con t3.active = 1
$builder->whereIn("t1.id", function ($subQuery) {
$subQuery->select("t1_inner.id")
->from("lg_papel_generico t1_inner")
->join("lg_papel_impresion t2_inner", "t2_inner.papel_generico_id = t1_inner.id", "inner")
->join("lg_maquina_papel_impresion t3_inner", "t3_inner.papel_impresion_id = t2_inner.id", "inner")
->where("t3_inner.active", 1);
});
if ($is_cubierta == true) {
$builder->where("t2.cubierta", 1);
$builder->where("t5.uso", 'cubierta');
if($tapa_dura == true){
$builder->where("t2.use_for_tapa_dura", 1);
}
} else {
$builder->where("t2.interior", 1);
$builder->where("t5.uso", 'interior');
if ($tipo == 'negro' || $tipo == 'negrohq')
$builder->where("t2.bn", 1);
else if ($tipo == 'color' || $tipo == 'colorhq')
$builder->where("t2.color", 1);
}
if ($papel_especial == true) {
$builder->where("t1.show_in_client_special", 1);
}
else{
$builder->where("t1.show_in_client_special", 0);
}
if ($tipo == 'colorhq' || $tipo == 'negrohq') {
$builder->where("t2.rotativa", 0);
}
if ($selected_papel_id != null)
$data = $builder->orderBy("t2.gramaje", "asc")->get()->getResultObject();
else
$data = $builder->orderBy("t1.nombre", "asc")->get()->getResultObject();
//$query = $this->db->getLastQuery();
return $data;
}
}

View File

@ -16,14 +16,17 @@ class PapelImpresionModel extends \App\Models\BaseModel
0 => "t1.nombre",
1 => "t2.nombre",
2 => "t1.gramaje",
3 => "t1.bn",
4 => "t1.color",
5 => "t1.cubierta",
6 => "t1.sobrecubierta",
7 => "t1.guardas",
8 => "t1.inkjet",
9 => "t1.rotativa",
10 => "t1.isActivo"
3 => "t1.interior",
4 => "t1.bn",
5 => "t1.color",
6 => "t1.cubierta",
7 => "t1.use_for_tapa_dura",
8 => "t1.sobrecubierta",
9 => "t1.guardas",
10 => "t1.inkjet",
11 => "t1.rotativa",
12 => "t1.isActivo",
13 => "t1.use_in_client",
];
@ -36,6 +39,7 @@ class PapelImpresionModel extends \App\Models\BaseModel
"espesor",
"gramaje",
"precio_tonelada",
"interior",
"bn",
"color",
"cubierta",
@ -44,6 +48,8 @@ class PapelImpresionModel extends \App\Models\BaseModel
"inkjet",
"rotativa",
"isActivo",
"use_in_client",
"use_for_tapa_dura",
"deleted_at",
"is_deleted",
"user_updated_id",
@ -141,23 +147,25 @@ class PapelImpresionModel extends \App\Models\BaseModel
*
* @return \CodeIgniter\Database\BaseBuilder
*/
public function getResource(string $search = "", $generico_id=-1)
public function getResource(string $search = "", $generico_id = -1)
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id AS id, t1.nombre AS nombre, t1.defecto AS defecto, t1.referencia AS referencia, t1.mano AS mano,
t1.espesor AS espesor, t1.gramaje AS gramaje, t1.precio_tonelada AS precio_tonelada,
t1.bn AS bn, t1.color AS color, t1.cubierta AS cubierta, t1.sobrecubierta AS sobrecubierta, t1.guardas AS guardas,
t1.espesor AS espesor, t1.gramaje AS gramaje, t1.interior AS interior, t1.precio_tonelada AS precio_tonelada,
t1.bn AS bn, t1.color AS color, t1.cubierta AS cubierta, t1.use_for_tapa_dura AS use_for_tapa_dura,
t1.sobrecubierta AS sobrecubierta, t1.guardas AS guardas,
t1.inkjet AS inkjet, t1.rotativa AS rotativa,
t1.isActivo AS isActivo, t2.nombre AS papel_generico_id"
t1.isActivo AS isActivo, t2.nombre AS papel_generico_id,
t1.use_in_client AS use_in_client"
);
$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);
if ($generico_id > 0) {
$builder->where("t1.papel_generico_id", $generico_id);
}
return empty($search)
@ -177,29 +185,29 @@ class PapelImpresionModel extends \App\Models\BaseModel
$builder = $this->db
->table($this->table . " t1")
->select(
"'".$maquina_id."'". " as maquina_id, t1.id AS papel_impresion_id, '0' as active"
"'" . $maquina_id . "'" . " as maquina_id, t1.id AS papel_impresion_id, '0' as active"
);
$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 (!empty($tarifas)) {
foreach ($tarifas as $tarifa) {
if (!$isFirst)
$where_str .= ' OR ';
else{
else {
$isFirst = false;
}
if ($tarifa->uso == 'cubierta')
$where_str .= "`t1`.`cubierta`=1";
else if ($tarifa->uso == 'sobrecubierta')
$where_str .= "`t1`.`sobrecubierta`=1";
else{
else {
if ($tarifa->tipo == 'negro' || $tarifa->tipo == 'negrohq')
$where_str .= "`t1`.`bn`=1 ";
$where_str .= "`t1`.`bn`=1 ";
else
$where_str .= "`t1`.`color`=1 ";
}
@ -207,11 +215,11 @@ class PapelImpresionModel extends \App\Models\BaseModel
$builder->where($where_str);
}
// si no hay tarifas no hay que devolver nada
else{
else {
// Se pone una condicion que no se puede dar
$builder->where("t1.bn", 2);
}
return $builder;
}
@ -224,43 +232,45 @@ class PapelImpresionModel extends \App\Models\BaseModel
*
* @return [type]
*/
public function getIdPapelesImpresionForPresupuesto($papel_generico_id = null, $gramaje = null, $options=[]){
public function getIdPapelesImpresionForPresupuesto($papel_generico_id = null, $gramaje = null, $options = [])
{
$bn = array_key_exists('bn', $options) ? $options['bn'] : null;
$color = array_key_exists('color', $options)? $options['color'] : null;
$cubierta = array_key_exists('cubierta', $options)? $options['cubierta'] : null;
$sobrecubierta = array_key_exists('sobrecubierta', $options)? $options['sobrecubierta'] : null;
$guardas = array_key_exists('guardas', $options)? $options['guardas'] : null;
$rotativa = array_key_exists('rotativa', $options)? $options['rotativa'] : null;
$color = array_key_exists('color', $options) ? $options['color'] : null;
$cubierta = array_key_exists('cubierta', $options) ? $options['cubierta'] : null;
$sobrecubierta = array_key_exists('sobrecubierta', $options) ? $options['sobrecubierta'] : null;
$guardas = array_key_exists('guardas', $options) ? $options['guardas'] : null;
$rotativa = array_key_exists('rotativa', $options) ? $options['rotativa'] : null;
$builder = $this->db
->table($this->table . " t1")
->distinct("t1.id")
->select(
"t1.id AS id, t1.nombre AS nombre, t1.papel_generico_id AS papel_generico_id,
t1.gramaje as gramaje, t1.espesor AS espesor, t1.precio_tonelada AS precio_tonelada, t1.rotativa AS rotativa");
t1.gramaje as gramaje, t1.espesor AS espesor, t1.precio_tonelada AS precio_tonelada, t1.rotativa AS rotativa"
);
$builder->where("t1.is_deleted", 0);
$builder->where("t1.isActivo", 1);
$builder->where("t1.papel_generico_id", $papel_generico_id);
$builder->where("t1.gramaje", $gramaje);
if(!is_null($bn)){
if (!is_null($bn)) {
$builder->where("t1.bn", $bn);
}
if(!is_null($color)){
if (!is_null($color)) {
$builder->where("t1.color", $color);
}
if(!is_null($cubierta)){
if (!is_null($cubierta)) {
$builder->where("t1.cubierta", $cubierta);
}
if(!is_null($sobrecubierta)){
if (!is_null($sobrecubierta)) {
$builder->where("t1.sobrecubierta", $sobrecubierta);
}
if(!is_null($guardas)){
if (!is_null($guardas)) {
$builder->where("t1.guardas", $guardas);
}
if(!is_null($rotativa)){
if (!is_null($rotativa)) {
$builder->where("t1.rotativa", $rotativa);
}
@ -269,7 +279,8 @@ class PapelImpresionModel extends \App\Models\BaseModel
//tipo: negro, negrohq, color, colorhq
//uso: interior, rotativa, cubierta, sobrecubierta
public function getPapelesImpresionForMenu($papel_generico = null, $gramaje = null, $tipo = null, $uso=""){
public function getPapelesImpresionForMenu($papel_generico = null, $gramaje = null, $tipo = null, $uso = "")
{
$builder = $this->db
->table($this->table . " t1")
->distinct("t1.id")
@ -278,8 +289,9 @@ class PapelImpresionModel extends \App\Models\BaseModel
->join("lg_maquinas t4", "t3.maquina_id = t4.id", "left")
->join("lg_maquinas_tarifas_impresion t5", "t4.id = t5.maquina_id", "left")
->select(
"t1.id AS id, t1.nombre AS text");
"t1.id AS id, t1.nombre AS text"
);
$builder->where("t1.is_deleted", 0);
$builder->where("t1.isActivo", 1);
$builder->where("t2.is_deleted", 0);
@ -288,7 +300,7 @@ class PapelImpresionModel extends \App\Models\BaseModel
$builder->where("t4.tipo", 'impresion');
$builder->where("t5.is_deleted", 0);
$builder->where("t5.tipo", $tipo);
$builder->where("t2.id", $papel_generico);
$builder->where("t1.gramaje", $gramaje);
@ -298,32 +310,35 @@ class PapelImpresionModel extends \App\Models\BaseModel
$builder->where("t1.sobrecubierta", 1);
else if ($uso == 'guardas')
$builder->where("t1.guardas", 1);
else{
if($tipo == 'negro' || $tipo == 'negrohq')
else {
if ($tipo == 'negro' || $tipo == 'negrohq')
$builder->where("t1.bn", 1);
else if ($tipo == 'color' || $tipo == 'colorhq')
$builder->where("t1.color", 1);
}
if($uso=='rotativa')
if ($uso == 'rotativa')
$builder->where("t1.rotativa", 1);
else
$builder->where("t1.rotativa", 0);
return $builder->orderBy("t1.id", "asc")->get()->getResultObject();
}
public function getNombre($id){
public function getNombre($id)
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.nombre AS text");
"t1.nombre AS text"
);
$builder->where("t1.id", $id);
return $builder->orderBy("t1.id", "asc")->get()->getResultObject();
}
public function getPapelGenericoCode($papel_id = 0){
public function getPapelGenericoCode($papel_id = 0)
{
$builder = $this->db
->table($this->table . " t1")
->select("t2.code AS code")
@ -332,12 +347,13 @@ class PapelImpresionModel extends \App\Models\BaseModel
->where("t1.is_deleted", 0)
->where("t1.isActivo", 1)
->where("t2.is_deleted", 0);
$result = $builder->get()->getResultObject();
if(count($result) > 0){
if (count($result) > 0) {
return $result[0]->code;
}
else
} else
return "";
}
}

View File

@ -73,7 +73,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
$result_array = [];
foreach($tarifa_value as $tarifa_proveedor){
$precio_total = floatval(1.0* $tarifa_proveedor->precio_hora* $tiempo) * (1+$tarifa_value[0]->margen/100.0);
if (!$POD){
if ($tirada>=$POD){
$precio_total += floatval($tarifa_proveedor->tarifa_importe_fijo);
}
@ -248,7 +248,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
return [];
}
public function getPrecioTarifaHoras($tarifa_encuadernacion_id, $paginas, $tirada, $proveedor_id, $POD, $paginas_cuadernillo = null){
public function getPrecioTarifaHoras($tarifa_encuadernacion_id, $paginas, $tirada, $proveedor_id, $POD, $paginas_cuadernillo = 32){
$modelTarifa = model('App\Models\Tarifas\TarifaEncuadernacionModel');
@ -265,7 +265,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
$ret_array = [];
foreach($tarifa_value as $tarifa_proveedor){
$precio_total = floatval(1.0* $tarifa_proveedor->precio_hora* $tiempo) * (1+$tarifa_value[0]->margen/100.0);
if (!$POD){
if ($tirada>=$POD){
$precio_total += floatval($tarifa_proveedor->tarifa_importe_fijo);
}

View File

@ -404,11 +404,13 @@ class PresupuestoModel extends \App\Models\BaseModel
'cliente_id' => $data['clienteId'],
'tipo_impresion_id' => $data['tipo_impresion_id'],
'pais_id' => 1,
'retractilado' => in_array("RETR", $data['cubierta']['acabadosCubierta']) ? 1 : 0,
'retractilado5' => in_array(5, $data['servicios']) ? 1 : 0,
'retractilado' => $data['retractilado'] ? 1 : 0,
'retractilado5' => $data['retractilado5'] ? 1 : 0,
'guardas' => in_array(62, $data['servicios']) ? 1 : 0,
'faja_color' => in_array(16, $data['servicios']) ? 1 : 0,
'ferro' => in_array(24, $data['servicios']) ? 1 : 0,
'ferro' => $data['ferro'] ? 1 : 0,
'ferro_digital' => $data['ferro_digital'] ? 1 : 0,
'marcapaginas' => $data['marcapaginas'] ? 1 : 0,
'prototipo' => $data['prototipo'] ? 1 : 0,
'papel_formato_id' => is_null($papel_formato_id) ? 0 : $papel_formato_id->id,
'papel_formato_personalizado' => !$papel_formato_id ? 1 : 0,
@ -424,7 +426,7 @@ class PresupuestoModel extends \App\Models\BaseModel
'solapas' => $data['cubierta']['solapasCubierta'] == 0 ? 0 : 1,
'lomo_redondo' => $data['cubierta']['lomoRedondo'] == 0 ? 0 : 1,
'cabezada' => $data['cubierta']['cabezada'] == 0 ? 0 : 1,
'solapas_ancho' => $data['cubierta']['solapasCubierta'] == 0 ? $data['cubierta']['solapasCubierta'] : 0,
'solapas_ancho' => $data['cubierta']['solapasCubierta'] > 0 ? $data['cubierta']['solapasCubierta'] : 0,
'solapas_sobrecubierta' => !$data['sobrecubierta'] ? 0 : 1,
'solapas_ancho_sobrecubierta' => !$data['sobrecubierta'] ? 0 : $data['sobrecubierta']['solapas'],
'cosido' => $is_cosido,

View File

@ -79,6 +79,7 @@ class TipoPresupuestoServiciosDefectoModel extends \App\Models\BaseModel
$where = "(t1.solapas IS NULL OR t1.solapas='" . $solapas . "')";
$builder->where($where);
$builder->where("t1.is_deleted", 0);
$builder->where("t2.is_deleted", 0);
$builder->select("t1.tarifa_id AS tarifa_id, t2.nombre AS tarifa_nombre");

View File

@ -30,7 +30,6 @@ class UserModel extends ShieldUserModel
protected $updatedField = 'updated_at';
protected $deletedField = 'deleted_at';
protected $validationRules = [
"first_name" => "required|trim|max_length[150]",
"last_name" => "required|trim|max_length[150]",
@ -66,7 +65,7 @@ class UserModel extends ShieldUserModel
$builder = $this->db
->table("users" . " t1")
->select(
"t1.id AS id, CONCAT(t1.first_name, ' ', t1.last_name) AS text"
"t1.id AS id, CONCAT(t1.first_name, ' ', t1.last_name) AS name"
);
$builder->where('t1.deleted_at', null);
@ -77,5 +76,19 @@ class UserModel extends ShieldUserModel
}
// Método para comprobar si el email ya está registrado
public function isEmailUnique($email)
{
$builder = $this->db
->table("auth_identities t1") // La tabla correcta
->select("t1.secret AS email")
->where('secret', $email);
// Obtener resultados
$result = $builder->get()->getRow();
// Devuelve true si no se encuentra el correo (es único), false en caso contrario
return $result === null;
}
}

View File

@ -20,6 +20,7 @@ class UserModel extends \App\Models\BaseModel
protected $allowedFields = [
"username",
"email",
"first_name",
"last_name",
"client_id",