From ab63043f36f01d8078ee18e88f58c91ce1afc326 Mon Sep 17 00:00:00 2001 From: imnavajas Date: Thu, 3 Apr 2025 13:26:44 +0200 Subject: [PATCH 01/14] Unificada entidad de usuarios a UserEntity --- ci4/app/Entities/Usuarios/UserEntity.php | 9 +++---- ci4/app/Entities/Usuarios/UsersEntity.php | 30 ----------------------- 2 files changed, 4 insertions(+), 35 deletions(-) delete mode 100644 ci4/app/Entities/Usuarios/UsersEntity.php diff --git a/ci4/app/Entities/Usuarios/UserEntity.php b/ci4/app/Entities/Usuarios/UserEntity.php index a6410e2f..ecfca4f4 100755 --- a/ci4/app/Entities/Usuarios/UserEntity.php +++ b/ci4/app/Entities/Usuarios/UserEntity.php @@ -1,11 +1,9 @@ null, @@ -20,7 +18,6 @@ class UserEntity extends \CodeIgniter\Entity\Entity "created_at" => null, "updated_at" => null, "deleted_at" => null, - ]; protected $casts = [ "id" => "int", @@ -73,4 +70,6 @@ class UserEntity extends \CodeIgniter\Entity\Entity $m = model(ChatNotification::class); return $m->where('user_id',$this->attributes['id'])->findAll() ?? []; } + + } diff --git a/ci4/app/Entities/Usuarios/UsersEntity.php b/ci4/app/Entities/Usuarios/UsersEntity.php deleted file mode 100644 index 51da0555..00000000 --- a/ci4/app/Entities/Usuarios/UsersEntity.php +++ /dev/null @@ -1,30 +0,0 @@ - null, - 'last_name'=> null, - 'cliente_id' => null, - 'comments' => null, - ]; - protected $casts = [ - "cliente_id" => "int", - ]; - - public function getFullName() - { - $firstName = trim($this->attributes["first_name"] ?? ""); - $lastName = trim($this->attributes["last_name"] ?? ""); - $fullName = $firstName . ' ' . $lastName; - $fullName = trim($fullName); // In case first name is empty, this will remove the leading space - - // Use the username attribute if the full name is still empty after trimming - return $fullName ?: $this->attributes["username"]; - } - - -} From ac804e972027b56e59c50c61dd40ab4738300cdd Mon Sep 17 00:00:00 2001 From: imnavajas Date: Thu, 3 Apr 2025 13:29:32 +0200 Subject: [PATCH 02/14] Eliminadas referencias a UsersEntity --- ci4/app/Config/Auth.php | 1 - ci4/app/Models/Clientes/ClienteUsuariosModel.php | 2 +- ci4/app/Models/UserModel.php | 3 +-- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/ci4/app/Config/Auth.php b/ci4/app/Config/Auth.php index decc5ba3..ef4171f9 100644 --- a/ci4/app/Config/Auth.php +++ b/ci4/app/Config/Auth.php @@ -13,7 +13,6 @@ declare(strict_types=1); namespace Config; -use App\Entities\Usuarios\UsersEntity; use App\Models\UserModel; use CodeIgniter\Shield\Authentication\Authenticators\JWT; use CodeIgniter\Shield\Authentication\Passwords\ValidationRules; diff --git a/ci4/app/Models/Clientes/ClienteUsuariosModel.php b/ci4/app/Models/Clientes/ClienteUsuariosModel.php index 4eedadf5..e735d7d2 100644 --- a/ci4/app/Models/Clientes/ClienteUsuariosModel.php +++ b/ci4/app/Models/Clientes/ClienteUsuariosModel.php @@ -23,7 +23,7 @@ class ClienteUsuariosModel extends ShieldUserModel ]; protected $allowedFields = ["id", "first_name", "last_name", "email"]; - protected $returnType = "App\Entities\Usuarios\UsersEntity"; + protected $returnType = "App\Entities\Usuarios\UserEntity"; protected $useTimestamps = true; protected $useSoftDeletes = false; diff --git a/ci4/app/Models/UserModel.php b/ci4/app/Models/UserModel.php index 34f1767a..919f23df 100644 --- a/ci4/app/Models/UserModel.php +++ b/ci4/app/Models/UserModel.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Models; -use App\Entities\Usuarios\UsersEntity; use CodeIgniter\Shield\Authentication\Traits\HasAccessTokens; use CodeIgniter\Shield\Models\UserModel as ShieldUserModel; @@ -34,7 +33,7 @@ class UserModel extends ShieldUserModel 5 => "t1.last_active", ]; - protected $returnType = UsersEntity::class; + protected $returnType = UserEntity::class; protected $useSoftDeletes = true; protected $useTimestamps = true; From a123c2dfa763413a4b136d6afeaa4d56fa6d8580 Mon Sep 17 00:00:00 2001 From: imnavajas Date: Thu, 3 Apr 2025 13:54:19 +0200 Subject: [PATCH 03/14] Mergeados UserModel's y eliminadas referencias a App\Models\UserModel a favor de App\Models\Usuarios\UserModel --- ci4/app/Config/Auth.php | 2 +- ci4/app/Controllers/Clientes/Cliente.php | 4 +- ci4/app/Controllers/Configuracion/Users.php | 2 +- ci4/app/Controllers/Facturacion/Facturas.php | 2 +- ci4/app/Controllers/Pedidos/Pedido.php | 2 +- .../Presupuestos/Presupuestoadmin.php | 4 +- ci4/app/Controllers/Profile.php | 2 +- .../Controllers/Soporte/Ticketcontroller.php | 10 +- ci4/app/Models/UserModel.php | 152 --------------- ci4/app/Models/Usuarios/UserModel.php | 183 ++++++++++++++---- 10 files changed, 154 insertions(+), 209 deletions(-) delete mode 100644 ci4/app/Models/UserModel.php diff --git a/ci4/app/Config/Auth.php b/ci4/app/Config/Auth.php index ef4171f9..f111d63a 100644 --- a/ci4/app/Config/Auth.php +++ b/ci4/app/Config/Auth.php @@ -13,7 +13,7 @@ declare(strict_types=1); namespace Config; -use App\Models\UserModel; +use App\Models\Usuarios\UserModel; use CodeIgniter\Shield\Authentication\Authenticators\JWT; use CodeIgniter\Shield\Authentication\Passwords\ValidationRules; use CodeIgniter\Shield\Config\Auth as ShieldAuth; diff --git a/ci4/app/Controllers/Clientes/Cliente.php b/ci4/app/Controllers/Clientes/Cliente.php index 970118d9..23a7d20f 100755 --- a/ci4/app/Controllers/Clientes/Cliente.php +++ b/ci4/app/Controllers/Clientes/Cliente.php @@ -384,7 +384,7 @@ class Cliente extends \App\Controllers\BaseResourceController { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Users.user'))])]; if (!is_null($selId)) : - $userModel = model('App\Models\UserModel'); + $userModel = model('App\Models\Usuarios\UserModel'); $selOption = $userModel->where('id', $selId)->findColumn('first_name'); if (!empty($selOption)) : @@ -414,7 +414,7 @@ class Cliente extends \App\Controllers\BaseResourceController { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Users.user'))])]; if (!is_null($selId)) : - $userModel = model('App\Models\UserModel'); + $userModel = model('App\Models\Usuarios\UserModel'); $selOption = $userModel->where('id', $selId)->findColumn('last_name'); if (!empty($selOption)) : diff --git a/ci4/app/Controllers/Configuracion/Users.php b/ci4/app/Controllers/Configuracion/Users.php index 24e57306..b34c3b89 100755 --- a/ci4/app/Controllers/Configuracion/Users.php +++ b/ci4/app/Controllers/Configuracion/Users.php @@ -5,7 +5,7 @@ use App\Models\Chat\ChatDeparmentModel; use App\Models\Chat\ChatDeparmentUserModel; use App\Models\Usuarios\GroupModel; -use App\Models\UserModel; +use App\Models\Usuarios\UserModel; use App\Models\Usuarios\GroupsUsersModel; use App\Models\Collection; diff --git a/ci4/app/Controllers/Facturacion/Facturas.php b/ci4/app/Controllers/Facturacion/Facturas.php index 3d914183..22c4985c 100755 --- a/ci4/app/Controllers/Facturacion/Facturas.php +++ b/ci4/app/Controllers/Facturacion/Facturas.php @@ -220,7 +220,7 @@ class Facturas extends \App\Controllers\BaseResourceController ['title' => lang("Facturas.facturaList"), 'route' => route_to('facturasList'), 'active' => true] ]; - $userModel = model('App\Models\UserModel'); + $userModel = model('App\Models\Usuarios\UserModel'); $factura->created_by = $userModel->getFullName($factura->user_created_id); $factura->updated_by = $userModel->getFullName($factura->user_updated_id); $factura->created_at_footer = $factura->created_at ? date(' H:i d/m/Y', strtotime($factura->created_at)) : ''; diff --git a/ci4/app/Controllers/Pedidos/Pedido.php b/ci4/app/Controllers/Pedidos/Pedido.php index bf4ddc9d..6e28240e 100755 --- a/ci4/app/Controllers/Pedidos/Pedido.php +++ b/ci4/app/Controllers/Pedidos/Pedido.php @@ -583,7 +583,7 @@ class Pedido extends \App\Controllers\BaseResourceController $pedidoEntity->fecha_encuadernado_text = $pedidoEntity->fecha_encuadernado ? date('d/m/Y', strtotime($pedidoEntity->fecha_encuadernado)) : ''; $pedidoEntity->fecha_entrega_externo_text = $pedidoEntity->fecha_entrega_externo ? date('d/m/Y', strtotime($pedidoEntity->fecha_entrega_externo)) : ''; - $userModel = model('App\Models\UserModel'); + $userModel = model('App\Models\Usuarios\UserModel'); $pedidoEntity->created_by = $userModel->getFullName($pedidoEntity->user_created_id); $pedidoEntity->updated_by = $userModel->getFullName($pedidoEntity->user_updated_id); $pedidoEntity->created_at_footer = $pedidoEntity->created_at ? date(' H:i d/m/Y', strtotime($pedidoEntity->created_at)) : ''; diff --git a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php index 47883116..d6973597 100644 --- a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php @@ -635,8 +635,8 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $data['resumen']['iva_reducido'] = $presupuesto->iva_reducido; - $data['created_by'] = model('App\Models\UserModel')->getFullName($presupuesto->user_created_id); - $data['updated_by'] = model('App\Models\UserModel')->getFullName($presupuesto->user_update_id); + $data['created_by'] = model('App\Models\Usuarios\UserModel')->getFullName($presupuesto->user_created_id); + $data['updated_by'] = model('App\Models\Usuarios\UserModel')->getFullName($presupuesto->user_update_id); $data['created_at'] = date(' H:i d/m/Y', strtotime($presupuesto->created_at)); $data['updated_at'] = date(' H:i d/m/Y', strtotime($presupuesto->updated_at)); diff --git a/ci4/app/Controllers/Profile.php b/ci4/app/Controllers/Profile.php index 67449c84..82fbb5e6 100755 --- a/ci4/app/Controllers/Profile.php +++ b/ci4/app/Controllers/Profile.php @@ -3,7 +3,7 @@ namespace App\Controllers; -use App\Models\UserModel; +use App\Models\Usuarios\UserModel; class Profile extends BaseController { diff --git a/ci4/app/Controllers/Soporte/Ticketcontroller.php b/ci4/app/Controllers/Soporte/Ticketcontroller.php index 51ed1a70..d760d8c7 100644 --- a/ci4/app/Controllers/Soporte/Ticketcontroller.php +++ b/ci4/app/Controllers/Soporte/Ticketcontroller.php @@ -109,7 +109,7 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.'; - $userModel = new \App\Models\UserModel(); + $userModel = new \App\Models\Usuarios\UserModel(); $this->sendMail(lang('Tickets.newTicket'), lang('Tickets.newTicketBody') . base_url(route_to('editTicket', $id)), $userModel->find($sanitizedData['user_soporte_id'])->email); @@ -195,7 +195,7 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController } // envio de correos - $userModel = new \App\Models\UserModel(); + $userModel = new \App\Models\Usuarios\UserModel(); if ($oldUserSupport != $sanitizedData['user_soporte_id']) { $this->sendMail(lang('Tickets.asgignToChanged'), lang('Tickets.asgignToChangedBody') . base_url(route_to('editTicket', $id)), $userModel->find($sanitizedData['user_soporte_id'])->email); } @@ -379,15 +379,15 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController $supportUsers = array( array( 'id' => $defatulSoporteUserId, - 'name' => model('App\Models\UserModel')->getFullName($defatulSoporteUserId) + 'name' => model('App\Models\Usuarios\UserModel')->getFullName($defatulSoporteUserId) ), array( 'id' => 2, - 'name' => model('App\Models\UserModel')->getFullName(2) + 'name' => model('App\Models\Usuarios\UserModel')->getFullName(2) ), array( 'id' => 1, - 'name' => model('App\Models\UserModel')->getFullName(1) + 'name' => model('App\Models\Usuarios\UserModel')->getFullName(1) ), ); diff --git a/ci4/app/Models/UserModel.php b/ci4/app/Models/UserModel.php deleted file mode 100644 index 919f23df..00000000 --- a/ci4/app/Models/UserModel.php +++ /dev/null @@ -1,152 +0,0 @@ -allowedFields = [ - ...$this->allowedFields, - 'first_name', // Añadido - 'last_name', // Añadido - 'cliente_id', // Añadido - 'comments', // Añadido - ]; - } - - const SORTABLE = [ - 0 => "t1.id", - 1 => "t1.first_name", - 2 => "t1.last_name", - 3 => "t2.secret", - 4 => "t3.nombre", - 5 => "t1.last_active", - ]; - - protected $returnType = UserEntity::class; - - protected $useSoftDeletes = true; - protected $useTimestamps = true; - protected $createdField = 'created_at'; - protected $updatedField = 'updated_at'; - protected $deletedField = 'deleted_at'; - - protected $validationRules = [ - "first_name" => "required|trim|max_length[150]", - "last_name" => "required|trim|max_length[150]", - "email" => "required|valid_email|max_length[150]", - 'new_pwd' => 'permit_empty|min_length[8]', - 'new_pwd_confirm' => 'permit_empty|required_with[new_pwd]|matches[new_pwd]', - "comments" => "permit_empty|trim|max_length[512]" - ]; - - protected $validationMessages = [ - 'first_name' => [ - "max_length" => "Users.validation.first_name.max_length", - "required" => "Users.validation.first_name.required" - ], - 'last_name' => [ - "max_length" => "Users.validation.last_name.max_length", - "required" => "Users.validation.last_name.required" - ], - 'new_pwd' => [ - 'min_length' => "App.profile_rules_password_m" - ], - 'new_pwd_confirm' => [ - 'matches' => "App.profile_rules_password_confirm_m" - ], - 'comments' => [ - "max_length" => "Users.validation.last_name.max_length", - ], - 'email' => [ - "required" => "Users.validation.email.required", - "valid_email" => "Users.validation.email.valid_email", - "max_length" => "Users.validation.email.max_length" - ] - - ]; - - public function getResource($search = []) - { - $builder = $this->db - ->table($this->table . " t1") - ->select( - "t1.id as id, t1.first_name AS first_name, t1.last_name AS last_name, - t2.secret AS email, t1.last_active AS last_active, t3.nombre AS cliente" - ); - - $builder->join("auth_identities t2", "t1.id = t2.user_id", "left"); - $builder->join("clientes t3", "t1.cliente_id = t3.id", "left"); - - $builder->where('t1.deleted_at', null)->groupBy("t1.id"); - - if (empty($search)) - return $builder; - else { - $builder->groupStart(); - foreach ($search as $col_search) { - $column = self::SORTABLE[$col_search[0]]; - $value = $col_search[2]; - $builder->where("LOWER(CONVERT($column USING utf8)) COLLATE utf8_general_ci LIKE", "%" . strtolower($value) . "%"); - } - $builder->groupEnd(); - return $builder; - } - } - - public function getComerciales() - { - - $builder = $this->db - ->table("users" . " t1") - ->select( - "t1.id AS id, CONCAT(t1.first_name, ' ', t1.last_name) AS name" - ); - - $builder->where('t1.deleted_at', null); - $builder->where("t2.group", "comercial"); - $builder->join("auth_groups_users t2", "t1.id = t2.user_id", "left"); - - return $builder->get()->getResult(); - - } - - public function getFullName($id=0){ - $builder = $this->db - ->table("users" . " t1") - ->select( - "CONCAT(t1.first_name, ' ', t1.last_name) AS name" - ); - - $builder->where('t1.deleted_at', null); - $builder->where('t1.id', $id); - - return $builder->get()->getRow()->name; - } - - // 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; - } - -} diff --git a/ci4/app/Models/Usuarios/UserModel.php b/ci4/app/Models/Usuarios/UserModel.php index d4e2d993..1906b9ca 100755 --- a/ci4/app/Models/Usuarios/UserModel.php +++ b/ci4/app/Models/Usuarios/UserModel.php @@ -1,64 +1,160 @@ allowedFields = [ + ...$this->allowedFields, + 'first_name', // Añadido + 'last_name', // Añadido + 'cliente_id', // Añadido + 'comments', // Añadido + ]; + } + + const SORTABLE = [ + 0 => "t1.id", + 1 => "t1.first_name", + 2 => "t1.last_name", + 3 => "t2.secret", + 4 => "t3.nombre", + 5 => "t1.last_active", + ]; + + protected $returnType = UserEntity::class; + + protected $useSoftDeletes = true; + protected $useTimestamps = true; + protected $createdField = 'created_at'; + protected $updatedField = 'updated_at'; + protected $deletedField = 'deleted_at'; + protected $validationRules = [ "first_name" => [ "label" => "Users.firstName", - "rules" => "trim|max_length[150]", - ], + "rules" => "required|trim|max_length[150]", + ], "last_name" => [ "label" => "Users.lastName", - "rules" => "trim|max_length[150]", - ], + "rules" => "required|trim|max_length[150]", + ], + 'new_pwd' => 'permit_empty|min_length[8]', + 'new_pwd_confirm' => 'permit_empty|required_with[new_pwd]|matches[new_pwd]', + "comments" => "permit_empty|trim|max_length[512]" ]; protected $validationMessages = [ - "first_name" => [ + 'first_name' => [ "max_length" => "Users.validation.first_name.max_length", - "required" => "Users.validation.first_name.required", + "required" => "Users.validation.first_name.required" ], - "last_name" => [ + 'last_name' => [ "max_length" => "Users.validation.last_name.max_length", - "required" => "Users.validation.last_name.required", - ], + "required" => "Users.validation.last_name.required" + ], + 'new_pwd' => [ + 'min_length' => "App.profile_rules_password_m" + ], + 'new_pwd_confirm' => [ + 'matches' => "App.profile_rules_password_confirm_m" + ], + 'comments' => [ + "max_length" => "Users.validation.last_name.max_length", + ], + 'email' => [ + "required" => "Users.validation.email.required", + "valid_email" => "Users.validation.email.valid_email", + "max_length" => "Users.validation.email.max_length" + ] + ]; + public function getResource($search = []) + { + $builder = $this->db + ->table($this->table . " t1") + ->select( + "t1.id as id, t1.first_name AS first_name, t1.last_name AS last_name, + t2.secret AS email, t1.last_active AS last_active, t3.nombre AS cliente" + ); + + $builder->join("auth_identities t2", "t1.id = t2.user_id", "left"); + $builder->join("clientes t3", "t1.cliente_id = t3.id", "left"); + + $builder->where('t1.deleted_at', null)->groupBy("t1.id"); + + if (empty($search)) + return $builder; + else { + $builder->groupStart(); + foreach ($search as $col_search) { + $column = self::SORTABLE[$col_search[0]]; + $value = $col_search[2]; + $builder->where("LOWER(CONVERT($column USING utf8)) COLLATE utf8_general_ci LIKE", "%" . strtolower($value) . "%"); + } + $builder->groupEnd(); + return $builder; + } + } + + public function getComerciales() + { + + $builder = $this->db + ->table("users" . " t1") + ->select( + "t1.id AS id, CONCAT(t1.first_name, ' ', t1.last_name) AS name" + ); + + $builder->where('t1.deleted_at', null); + $builder->where("t2.group", "comercial"); + $builder->join("auth_groups_users t2", "t1.id = t2.user_id", "left"); + + return $builder->get()->getResult(); + + } + + public function getFullName($id=0){ + $builder = $this->db + ->table("users" . " t1") + ->select( + "CONCAT(t1.first_name, ' ', t1.last_name) AS name" + ); + + $builder->where('t1.deleted_at', null); + $builder->where('t1.id', $id); + + return $builder->get()->getRow()->name; + } + + // 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; + } + public function getGroupsTitles($user_token){ $sql = 'SELECT `auth_groups`.`title` FROM `auth_groups` @@ -78,4 +174,5 @@ class UserModel extends \App\Models\BaseModel } + } From 398afbaedac5164c9c2eb80dc3165ee30eded7e3 Mon Sep 17 00:00:00 2001 From: imnavajas Date: Thu, 3 Apr 2025 14:16:43 +0200 Subject: [PATCH 04/14] =?UTF-8?q?Arreglado=20bug=20a=C3=B1adir=20usuarios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ci4/app/Controllers/Configuracion/Users.php | 10 ++++---- ci4/app/Models/Usuarios/UserModel.php | 26 +-------------------- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/ci4/app/Controllers/Configuracion/Users.php b/ci4/app/Controllers/Configuracion/Users.php index b34c3b89..c207006e 100755 --- a/ci4/app/Controllers/Configuracion/Users.php +++ b/ci4/app/Controllers/Configuracion/Users.php @@ -9,8 +9,6 @@ use App\Models\Usuarios\UserModel; use App\Models\Usuarios\GroupsUsersModel; use App\Models\Collection; -use CodeIgniter\Shield\Entities\User; -use function PHPUnit\Framework\isNull; class Users extends \App\Controllers\GoBaseController { @@ -89,9 +87,7 @@ class Users extends \App\Controllers\GoBaseController // Marcar el username como NULL $sanitizedData = $this->sanitized($postData, true); - $email = $sanitizedData['email']; - unset($sanitizedData['email']); - + $noException = true; // Obtener proveedor de usuarios @@ -102,7 +98,7 @@ class Users extends \App\Controllers\GoBaseController try { // The Email is unique - if ($this->user_model->isEmailUnique($email)) { + if ($this->user_model->isEmailUnique($sanitizedData['email'])) { // Crear el usuario si pasa la validación $user = new \CodeIgniter\Shield\Entities\User([ @@ -111,6 +107,8 @@ class Users extends \App\Controllers\GoBaseController 'last_name' => $sanitizedData['last_name'], 'cliente_id' => $sanitizedData['cliente_id'], 'comments' => $sanitizedData['comments'], + 'email' => $sanitizedData['email'], + 'password' => $sanitizedData['password'], 'status' => $sanitizedData['status'] ?? 0, 'active' => $sanitizedData['active'] ?? 0, ]); diff --git a/ci4/app/Models/Usuarios/UserModel.php b/ci4/app/Models/Usuarios/UserModel.php index 1906b9ca..623caac1 100755 --- a/ci4/app/Models/Usuarios/UserModel.php +++ b/ci4/app/Models/Usuarios/UserModel.php @@ -73,11 +73,6 @@ class UserModel extends ShieldUserModel ], 'comments' => [ "max_length" => "Users.validation.last_name.max_length", - ], - 'email' => [ - "required" => "Users.validation.email.required", - "valid_email" => "Users.validation.email.valid_email", - "max_length" => "Users.validation.email.max_length" ] ]; @@ -154,25 +149,6 @@ class UserModel extends ShieldUserModel // Devuelve true si no se encuentra el correo (es único), false en caso contrario return $result === null; } - - public function getGroupsTitles($user_token){ - - $sql = 'SELECT `auth_groups`.`title` FROM `auth_groups` - JOIN `group_user` ON `auth_groups`.`token` = `group_user`.`token_group` - JOIN `auth_user` ON `auth_user`.`token` = `group_user`.`token_user` - WHERE `auth_user`.`token` = \''. $user_token . '\''; - - - $query = $this->db->query($sql); - $result = $query->getResultObject(); - $data = []; - foreach($result as $r){ - array_push($data, $r->title); - } - return implode(',', $data); - - - - } + } From 6208839a1236dd15db17608e32ddc56fc2f63b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Thu, 3 Apr 2025 23:36:12 +0200 Subject: [PATCH 05/14] empezando modificaciones --- .../Presupuestos/Presupuestoadmin.php | 5 + .../admin/_resumenPresupuestoItems.php | 133 ++++++++++++------ .../presupuestoAdmin/presupuestoAdminEdit.js | 7 + 3 files changed, 103 insertions(+), 42 deletions(-) diff --git a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php index 47883116..d55231e8 100644 --- a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php @@ -633,6 +633,11 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $data['resumen']['total_factor'] = is_numeric($presupuesto->total_factor) ? $presupuesto->total_factor : 0; $data['resumen']['total_factor_ponderado'] = is_numeric($presupuesto->total_factor_ponderado) ? $presupuesto->total_factor_ponderado : 0; + $data['total_aceptado_revisado'] = $presupuesto->total_aceptado_revisado; + $data['aprobado_by_at'] = ($presupuesto->aprobado_user_id != null)?model('App\Models\UserModel')->getFullName($presupuesto->aprobado_user_id) . ', ' + . date('d/m/Y', strtotime($presupuesto->aprobado_at)):''; + + $data['resumen']['iva_reducido'] = $presupuesto->iva_reducido; $data['created_by'] = model('App\Models\UserModel')->getFullName($presupuesto->user_created_id); diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_resumenPresupuestoItems.php b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_resumenPresupuestoItems.php index 5f4c691b..24eb02b6 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_resumenPresupuestoItems.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_resumenPresupuestoItems.php @@ -2,14 +2,12 @@

-
+
@@ -18,63 +16,88 @@
Coste papel
-
+
Margen papel
-
-
+
+
Coste impresión
-
+
Margen impresión
-
-
+
+
Coste servicios
-
+
Margen servicios
-
-
+
+
Coste de envío
-
+
Precio de envío
-
+
Margen envío
-
+

Total Costes
-
+
Total Margen
-
-
+
+

Total
-
+
Descuento (%)
-
-
+
+
Total presupuesto
-
+
Precio unidad
-
+
Factor
-
-
Factor Ponderado
-
+
+
Factor Ponderado +
+
- estado_id == 2 ? 'onclick="return false;"' : ''; ?> type="checkbox" id="confirmar_presupuesto" name="confirmar_presupuesto" value="1" estado_id == 2 ? 'checked' : ''; ?>> - + estado_id == 2 ? 'onclick="return false;"' : ''; ?> type="checkbox" id="confirmar_presupuesto" + name="confirmar_presupuesto" value="1" estado_id == 2 ? 'checked' : ''; ?>> +
@@ -92,18 +115,44 @@
- estado_id == 2): ?> -
-
- - > -
-
- +
+
+
+
+
+ + estado_id == 2)? "disabled":"" ?> type="text" class="autonumeric-currency form-control text-center fs-5" + id="total_aceptado_revisado"> +
+
+ +
+
+ estado_id == 2): ?> +
+
+ + > +
+
+ +
+

+ +

+
+
+
+
+
-
- - + + + + + \ No newline at end of file diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js index 7894e139..7299bcf5 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js @@ -82,6 +82,10 @@ class PresupuestoAdminEdit { // Autonumeric AutoNumeric.multiple('.autonumeric-currency', { decimalPlaces: 2, currencySymbol: '€', currencySymbolPlacement: 's', digitGroupSeparator: '.', decimalCharacter: ',' }); + + $('#total_aceptado_revisado').on('change', function () { + AutoNumeric.getAutoNumericElement(this).set(this.value); + }); const impresion_id = $('#tipo_impresion_id').val(); let tipoLibro = ''; @@ -375,6 +379,9 @@ class PresupuestoAdminEdit { self.tipo_impresion.val(response.data.tipo_impresion); self.POD.val(response.data.POD); + $('#total_aceptado_revisado').val(response.data.total_aceptado_revisado); + $('#aprobado_by_at').html(response.data.aprobado_by_at); + $('#created_by').html(response.data.created_by); $('#updated_by').html(response.data.updated_by); $('#created_at').html(response.data.created_at); From cdf70c19ff2faa57060eeb1819fde516616f6527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Thu, 3 Apr 2025 23:37:14 +0200 Subject: [PATCH 06/14] =?UTF-8?q?a=C3=B1adidos=20ficheros=20nuevos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...AddTotalAceptadoRevisadoToPresupuestos.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 ci4/app/Database/Migrations/2025-04-03-200406_AddTotalAceptadoRevisadoToPresupuestos.php diff --git a/ci4/app/Database/Migrations/2025-04-03-200406_AddTotalAceptadoRevisadoToPresupuestos.php b/ci4/app/Database/Migrations/2025-04-03-200406_AddTotalAceptadoRevisadoToPresupuestos.php new file mode 100755 index 00000000..5bf43d37 --- /dev/null +++ b/ci4/app/Database/Migrations/2025-04-03-200406_AddTotalAceptadoRevisadoToPresupuestos.php @@ -0,0 +1,25 @@ +forge->addColumn('presupuestos', [ + 'total_aceptado_revisado' => [ + 'type' => 'FLOAT', + 'null' => true, + 'default' => null, + 'after' => 'total_aceptado' // Opcional: reemplazar con la última columna actual + ], + ]); + } + + public function down() + { + $this->forge->dropColumn('presupuestos', 'total_aceptado_revisado'); + } +} From c832af90d00cf30416aa0fb616ed54e733d17512 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Fri, 4 Apr 2025 01:32:50 +0200 Subject: [PATCH 07/14] add import ChatNotificationModel --- ci4/app/Entities/Usuarios/UserEntity.php | 1 + 1 file changed, 1 insertion(+) diff --git a/ci4/app/Entities/Usuarios/UserEntity.php b/ci4/app/Entities/Usuarios/UserEntity.php index ecfca4f4..39261124 100755 --- a/ci4/app/Entities/Usuarios/UserEntity.php +++ b/ci4/app/Entities/Usuarios/UserEntity.php @@ -1,6 +1,7 @@ Date: Fri, 4 Apr 2025 09:21:36 +0200 Subject: [PATCH 08/14] trabajando --- .../Presupuestos/Presupuestoadmin.php | 10 +++++--- .../presupuestoAdmin/presupuestoAdminEdit.js | 9 ++++--- .../presupuestoAdmin/sections/resumen.js | 25 +++++++++++++++---- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php index d55231e8..31ef4ed1 100644 --- a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php @@ -232,12 +232,16 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $postData = $this->request->getPost(); $postData['updated_at'] = gmdate('Y-m-d H:m:s', time()); - + $sanitizedData = $this->sanitized($postData, $nullIfEmpty); - - // JJO $sanitizedData['user_updated_id'] = auth()->user()->id; + if(isset($sanitizedData['total_aceptado_revisado']) && $sanitizedData['total_aceptado_revisado'] != 0 + && $sanitizedData['total_aceptado_revisado'] != null && $sanitizedData['total_aceptado_revisado'] != ""){ + $sanitizedData['aprobado_at'] = $sanitizedData['updated_at']; + $sanitizedData['aprobado_by'] = $sanitizedData['user_updated_id']; + } + if ($this->request->getPost('is_duplicado') == null) { $sanitizedData['is_duplicado'] = 0; } diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js index 7299bcf5..1606cd6e 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js @@ -83,10 +83,6 @@ class PresupuestoAdminEdit { // Autonumeric AutoNumeric.multiple('.autonumeric-currency', { decimalPlaces: 2, currencySymbol: '€', currencySymbolPlacement: 's', digitGroupSeparator: '.', decimalCharacter: ',' }); - $('#total_aceptado_revisado').on('change', function () { - AutoNumeric.getAutoNumericElement(this).set(this.value); - }); - const impresion_id = $('#tipo_impresion_id').val(); let tipoLibro = ''; if (impresion_id == 1 || impresion_id == 2) { @@ -124,6 +120,11 @@ class PresupuestoAdminEdit { this.tiradasAlternativas.init(); this.resumen.init(); + $('#btn_aceptar_revisado').on('click', function () { + + this.resumen.updateTotales({ updateLP: true, updateServicios: true, updateEnvio: true }); + }.bind(this)); + if (window.location.href.includes("edit")) { setTimeout(() => { diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/resumen.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/resumen.js index cc09be38..bcedce0c 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/resumen.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/resumen.js @@ -11,7 +11,7 @@ class Resumen { const self = this; this.toastPresupuestoTotal = null $(".update-totales").on("change", function () { - self.updateTotales(true, true, true) + self.updateTotales(null, { updateLP: true, updateServicios: true, updateEnvio: true }); }); $(document).on('update-totales', async function () { @@ -52,7 +52,7 @@ class Resumen { $("#margenEnvios").html(resumen.total_margen_envios || 0); $("#margenEnvios").val(resumen.total_margen_envios || 0); - $("#totalCostes").html(resumen.total_costes || 0); + $("#totalCostes").html(resumen.total_costes || 0).val(); $("#porcentajeMargen").html(resumen.porcentajeMargen ? resumen.porcentajeMargen: 0); $("#totalMargenes").html(resumen.total_margenes || 0); $("#totalCostes").val(resumen.total_costes || 0); @@ -94,7 +94,7 @@ class Resumen { - async updateTotales(event, data = {}) { + async updateTotales(data = {}) { const self = this; @@ -297,8 +297,20 @@ class Resumen { margenEnvios = parseFloat($('#margenEnvios').attr('val')) } - let totalCostes = parseFloat(totalPapel.toFixed(2)) + parseFloat(totalImpresion.toFixed(2)) + parseFloat(totalServicios.toFixed(2)) + parseFloat(totalEnvios.toFixed(2)) + let totalCostes = parseFloat(totalPapel.toFixed(2)) + parseFloat(totalImpresion.toFixed(2)) + + parseFloat(totalServicios.toFixed(2)) + parseFloat(totalEnvios.toFixed(2)) + let totalMargenes = parseFloat(margenPapel.toFixed(2)) + parseFloat(margenImpresion.toFixed(2)) + parseFloat(margenServicios.toFixed(2)) + parseFloat(margenEnvios.toFixed(2)) + + let total_aceptado_revisado = AutoNumeric.getAutoNumericElement($('#total_aceptado_revisado')[0]).getNumber() + if(total_aceptado_revisado != '' && total_aceptado_revisado != undefined && + total_aceptado_revisado != null && total_aceptado_revisado != 0){ + if(total_aceptado_revisado < totalCostes){ + total_aceptado_revisado = totalCoste ; + } + totalMargenes = parseFloat(total_aceptado_revisado)- totalCostes; + } + let porcentajeMargen = totalCostes + totalMargenes > 0 ? (100 * totalMargenes / (totalCostes + totalMargenes)).toFixed(0) : 0 $('#totalCostes').html(totalCostes).val(totalCostes.toFixed(2)) $('#totalMargenes').html(totalMargenes).val(totalMargenes.toFixed(2)) @@ -307,7 +319,7 @@ class Resumen { if ($('#total_descuentoPercent').val() < 0) { $('#total_descuentoPercent').val(0) } - let totalAntesDescuento = totalCostes + totalMargenes - parseFloat(totalEnvios.toFixed(2)) + totalEnvios_base; + let totalAntesDescuento = totalCostes + totalMargenes + parseFloat(totalEnvios.toFixed(2)) + totalEnvios_base; let totalDescuento = totalAntesDescuento * parseInt($('#total_descuentoPercent').val() || 0) / 100 let totalPresupuesto = totalAntesDescuento - totalDescuento; // para el calculo del precio_u solo se tiene en cuenta el base let precioUnidad = totalPresupuesto / parseInt($('#tirada').val()) @@ -372,6 +384,9 @@ class Resumen { return data; } + updateFromTotalAceptadoRevisado() { + } + roundToTwoDecimals(num) { return parseFloat(num.toFixed(2)); } From cddf64b0256aa989e72a933bf34faf53c9ff2038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Fri, 4 Apr 2025 17:03:08 +0200 Subject: [PATCH 09/14] terminada modificacion --- .../Presupuestos/Presupuestoadmin.php | 13 +++- .../Presupuestos/PresupuestoEntity.php | 2 + .../PresupuestoDireccionesModel.php | 1 + .../Models/Presupuestos/PresupuestoModel.php | 1 + .../admin/_resumenPresupuestoItems.php | 45 ++++++----- httpdocs/assets/js/safekat/components/chat.js | 2 +- .../presupuestoAdmin/presupuestoAdminEdit.js | 36 +++++++-- .../pages/presupuestoAdmin/sections/envios.js | 9 +-- .../presupuestoAdmin/sections/resumen.js | 78 +++++++++++++------ 9 files changed, 129 insertions(+), 58 deletions(-) diff --git a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php index 31ef4ed1..7c3e941d 100644 --- a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php @@ -239,7 +239,13 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController if(isset($sanitizedData['total_aceptado_revisado']) && $sanitizedData['total_aceptado_revisado'] != 0 && $sanitizedData['total_aceptado_revisado'] != null && $sanitizedData['total_aceptado_revisado'] != ""){ $sanitizedData['aprobado_at'] = $sanitizedData['updated_at']; - $sanitizedData['aprobado_by'] = $sanitizedData['user_updated_id']; + $sanitizedData['aprobado_user_id'] = $sanitizedData['user_updated_id']; + } + + if ($presupuestoEntity->estado_id == 1 && isset($postData['confirmar']) && $postData['confirmar'] == 1) { + $sanitizedData['aprobado_at'] = $sanitizedData['updated_at']; + $sanitizedData['aprobado_user_id'] = $sanitizedData['user_updated_id']; + $sanitizedData['total_aceptado_revisado'] = $sanitizedData['total_presupuesto']; } if ($this->request->getPost('is_duplicado') == null) { @@ -638,8 +644,9 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $data['resumen']['total_factor_ponderado'] = is_numeric($presupuesto->total_factor_ponderado) ? $presupuesto->total_factor_ponderado : 0; $data['total_aceptado_revisado'] = $presupuesto->total_aceptado_revisado; - $data['aprobado_by_at'] = ($presupuesto->aprobado_user_id != null)?model('App\Models\UserModel')->getFullName($presupuesto->aprobado_user_id) . ', ' - . date('d/m/Y', strtotime($presupuesto->aprobado_at)):''; + $data['aprobado_by_at'] = ($presupuesto->aprobado_user_id != null)? + model('App\Models\UserModel')->getFullName($presupuesto->aprobado_user_id) . ', ' + . date('d/m/Y H:i:s', strtotime($presupuesto->aprobado_at)):''; $data['resumen']['iva_reducido'] = $presupuesto->iva_reducido; diff --git a/ci4/app/Entities/Presupuestos/PresupuestoEntity.php b/ci4/app/Entities/Presupuestos/PresupuestoEntity.php index c4993d9c..2b28d821 100755 --- a/ci4/app/Entities/Presupuestos/PresupuestoEntity.php +++ b/ci4/app/Entities/Presupuestos/PresupuestoEntity.php @@ -100,6 +100,7 @@ class PresupuestoEntity extends \CodeIgniter\Entity\Entity "total_factor" => null, "total_factor_ponderado" => null, 'total_aceptado' => null, + 'total_aceptado_revisado' => null, 'iva_reducido' => null, 'excluir_rotativa' => null, "acabado_cubierta_id" => null, @@ -173,6 +174,7 @@ class PresupuestoEntity extends \CodeIgniter\Entity\Entity "total_factor" => "?float", "total_factor_ponderado" => "?float", 'total_aceptado' => "?float", + 'total_aceptado_revisado' => "?float", 'iva_reducido' => "?boolean", 'excluir_rotativa' => "?boolean", "acabado_cubierta_id" => "int", diff --git a/ci4/app/Models/Presupuestos/PresupuestoDireccionesModel.php b/ci4/app/Models/Presupuestos/PresupuestoDireccionesModel.php index 90da4d00..cc24fb30 100755 --- a/ci4/app/Models/Presupuestos/PresupuestoDireccionesModel.php +++ b/ci4/app/Models/Presupuestos/PresupuestoDireccionesModel.php @@ -74,6 +74,7 @@ class PresupuestoDireccionesModel extends \App\Models\BaseModel $builder->where('t1.presupuesto_id', $presupuesto_id); $builder->join("lg_paises t2", "t1.pais_id = t2.id", "left"); + $builder->orderBy('t1.id', 'DESC'); return empty($search) ? $builder diff --git a/ci4/app/Models/Presupuestos/PresupuestoModel.php b/ci4/app/Models/Presupuestos/PresupuestoModel.php index 38f9aada..676e78b8 100755 --- a/ci4/app/Models/Presupuestos/PresupuestoModel.php +++ b/ci4/app/Models/Presupuestos/PresupuestoModel.php @@ -119,6 +119,7 @@ class PresupuestoModel extends \App\Models\BaseModel "total_descuento", "total_descuentoPercent", "total_presupuesto", + "total_aceptado_revisado", "total_precio_unidad", "total_factor", "total_factor_ponderado", diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_resumenPresupuestoItems.php b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_resumenPresupuestoItems.php index 24eb02b6..31a2a04b 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_resumenPresupuestoItems.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_resumenPresupuestoItems.php @@ -44,13 +44,13 @@
Coste de envío
-
Precio de envío
-
+ class="autonumeric-resumen-currency">
Margen envío
+ class="autonumeric-resumen-currency">
+
Total envío base
+

@@ -69,7 +69,7 @@
-
Total
+
Total antes de descuento
Descuento (%)
@@ -118,28 +118,41 @@
+ +
+

El total aceptado y revisado tiene que ser mayor que total costes + precio de envío +

+
- estado_id == 2)? "disabled":"" ?> type="text" class="autonumeric-currency form-control text-center fs-5" - id="total_aceptado_revisado"> + estado_id == 2) ? "disabled" : "" ?> type="text" + class="autonumeric-currency form-control text-center fs-5" + id="total_aceptado_revisado">
-
- estado_id == 2): ?> + estado_id == 2): ?>
-
+
> + class="form-control text-center fs-5 autonumeric-resumen-currency" value="" >
- +

@@ -149,10 +162,6 @@

- - -
- - \ No newline at end of file + \ No newline at end of file diff --git a/httpdocs/assets/js/safekat/components/chat.js b/httpdocs/assets/js/safekat/components/chat.js index e0de09bf..043a6fef 100644 --- a/httpdocs/assets/js/safekat/components/chat.js +++ b/httpdocs/assets/js/safekat/components/chat.js @@ -68,7 +68,7 @@ class Chat { } if (this.chatHistoryBody[0]) { - console.log("History body"); + //console.log("History body"); this.scrollbarChatHistory = new PerfectScrollbar(this.chatHistoryBody[0], { wheelPropagation: false, suppressScrollX: true, diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js index 1606cd6e..c597c3ce 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js @@ -120,9 +120,28 @@ class PresupuestoAdminEdit { this.tiradasAlternativas.init(); this.resumen.init(); - $('#btn_aceptar_revisado').on('click', function () { - - this.resumen.updateTotales({ updateLP: true, updateServicios: true, updateEnvio: true }); + $('#btn_ajustar_revisado').on('click', function () { + + this.resumen.updateTotales({ updateLP: true, updateServicios: true, updateEnvio: true }, true); + }.bind(this)); + + $('#total_aceptado_revisado').on('change', function () { + let totalCostes = AutoNumeric.getAutoNumericElement($('#totalCostes')[0]); + let envio_base = AutoNumeric.getAutoNumericElement($('#precioEnvios')[0]); + let autoTotalAceptado = AutoNumeric.getAutoNumericElement($('#total_aceptado_revisado')[0]); + let total_aceptado_revisado = autoTotalAceptado.getNumber(); + + if (total_aceptado_revisado && total_aceptado_revisado != 0) { + const nuevoTotal = totalCostes.getNumber() + envio_base.getNumber(); + + if (total_aceptado_revisado < nuevoTotal) { + // Solo usá .set(), no .val() ni .html() + autoTotalAceptado.set(nuevoTotal); + total_aceptado_revisado = nuevoTotal; + } + + totalMargenes = total_aceptado_revisado - nuevoTotal; + } }.bind(this)); if (window.location.href.includes("edit")) { @@ -147,7 +166,7 @@ class PresupuestoAdminEdit { target.removeClass('d-none'); } }); - + $(document).on('update-presupuesto', this.updatePresupuesto.bind(this)); @@ -380,9 +399,10 @@ class PresupuestoAdminEdit { self.tipo_impresion.val(response.data.tipo_impresion); self.POD.val(response.data.POD); - $('#total_aceptado_revisado').val(response.data.total_aceptado_revisado); + AutoNumeric.getAutoNumericElement($('#total_aceptado_revisado')[0]).set(response.data.total_aceptado_revisado); + $('#aprobado_by_at').html(response.data.aprobado_by_at); - + $('#created_by').html(response.data.created_by); $('#updated_by').html(response.data.updated_by); $('#created_at').html(response.data.created_at); @@ -628,7 +648,7 @@ class PresupuestoAdminEdit { const svgData = serializer.serializeToString(shapeSvgEl); const svgBlob = new Blob([svgData], { type: 'image/svg+xml;charset=utf-8' }); const svgUrl = URL.createObjectURL(svgBlob); - const img = new Image(shapeSvgEl.getBoundingClientRect().width,shapeSvgEl.getBoundingClientRect().height); + const img = new Image(shapeSvgEl.getBoundingClientRect().width, shapeSvgEl.getBoundingClientRect().height); img.onload = () => { const scaleFactor = 3; // Increase resolution (e.g., 2x, 3x) const canvas = document.createElement('canvas'); @@ -639,7 +659,7 @@ class PresupuestoAdminEdit { canvas.height = height * scaleFactor; const ctx = canvas.getContext('2d'); ctx.scale(scaleFactor, scaleFactor); - ctx.drawImage(img, 0,0,width,height); + ctx.drawImage(img, 0, 0, width, height); const pngUrl = canvas.toDataURL('image/png'); const downloadLink = document.createElement('a'); downloadLink.href = pngUrl; diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/envios.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/envios.js index a67afda7..00170f69 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/envios.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/envios.js @@ -41,14 +41,13 @@ class Envios { processing: true, autoWidth: true, responsive: true, - order: [[0, "asc"]], pageLength: 20, lengthChange: false, searching: false, paging: false, info: false, scrollX: true, - + ordering: false, columns: [ { 'data': 'tarifa_id' }, { 'data': 'cantidad' }, @@ -87,10 +86,10 @@ class Envios { { orderable: false, searchable: false, - targets: [$('#tableOfDireccionesEnvio').find("tr:first th").length - 1] + // all columns + targets: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] + //targets: [$('#tableOfDireccionesEnvio').find("tr:first th").length - 1] }, - { "orderData": [0], "targets": 0 }, - ], language: { url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/resumen.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/resumen.js index bcedce0c..ca466e56 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/resumen.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/resumen.js @@ -26,22 +26,22 @@ class Resumen { // Mapear los valores a los elementos HTML por ID $("#totalCostePapel").val(resumen.total_coste_papel || 0); $("#totalCostePapel").html(resumen.total_coste_papel || 0); - $("#porcentajeMargenPapel").val(resumen.total_margenPercent_papel ? resumen.total_margenPercent_papel: 0); - $("#porcentajeMargenPapel").html(resumen.total_margenPercent_papel ? resumen.total_margenPercent_papel: 0); + $("#porcentajeMargenPapel").val(resumen.total_margenPercent_papel ? resumen.total_margenPercent_papel : 0); + $("#porcentajeMargenPapel").html(resumen.total_margenPercent_papel ? resumen.total_margenPercent_papel : 0); $("#margenPapel").val(resumen.total_margen_papel || 0); $("#margenPapel").html(resumen.total_margen_papel || 0); $("#totalCosteImpresion").val(resumen.total_coste_impresion || 0); $("#totalCosteImpresion").html(resumen.total_coste_impresion || 0); - $("#porcentajeMargenImpresion").val(resumen.total_margenPercent_impresion ? resumen.total_margenPercent_impresion: 0); - $("#porcentajeMargenImpresion").html(resumen.total_margenPercent_impresion ? resumen.total_margenPercent_impresion: 0); + $("#porcentajeMargenImpresion").val(resumen.total_margenPercent_impresion ? resumen.total_margenPercent_impresion : 0); + $("#porcentajeMargenImpresion").html(resumen.total_margenPercent_impresion ? resumen.total_margenPercent_impresion : 0); $("#margenImpresion").val(resumen.total_margen_impresion || 0); $("#margenImpresion").html(resumen.total_margen_impresion || 0); $("#totalServicios").html(resumen.total_coste_servicios || 0); $("#totalServicios").val(resumen.total_coste_servicios || 0); - $("#porcentajeMargenServicios").val(resumen.total_margenPercent_servicios ? resumen.total_margenPercent_servicios: 0); - $("#porcentajeMargenServicios").html(resumen.total_margenPercent_servicios ? resumen.total_margenPercent_servicios: 0); + $("#porcentajeMargenServicios").val(resumen.total_margenPercent_servicios ? resumen.total_margenPercent_servicios : 0); + $("#porcentajeMargenServicios").html(resumen.total_margenPercent_servicios ? resumen.total_margenPercent_servicios : 0); $("#margenServicios").val(resumen.total_margen_servicios || 0); $("#margenServicios").html(resumen.total_margen_servicios || 0); @@ -53,10 +53,10 @@ class Resumen { $("#margenEnvios").val(resumen.total_margen_envios || 0); $("#totalCostes").html(resumen.total_costes || 0).val(); - $("#porcentajeMargen").html(resumen.porcentajeMargen ? resumen.porcentajeMargen: 0); + $("#porcentajeMargen").html(resumen.porcentajeMargen ? resumen.porcentajeMargen : 0); $("#totalMargenes").html(resumen.total_margenes || 0); $("#totalCostes").val(resumen.total_costes || 0); - $("#porcentajeMargen").val(resumen.porcentajeMargen ? resumen.porcentajeMargen: 0); + $("#porcentajeMargen").val(resumen.porcentajeMargen ? resumen.porcentajeMargen : 0); $("#totalMargenes").val(resumen.total_margenes || 0); $("#totalAntesDescuento").html(resumen.total_antes_descuento || 0); @@ -64,14 +64,14 @@ class Resumen { $("#descuentoTotal").html(resumen.total_descuento || 0); $("#totalDespuesDecuento").html(resumen.total_presupuesto || 0).trigger("change") $("#precioUnidadPresupuesto").html(resumen.total_precio_unidad || 0); - $("#factor").html(resumen.total_factor|| 0); - $("#factor_ponderado").html(resumen.total_factor_ponderado|| 0); + $("#factor").html(resumen.total_factor || 0); + $("#factor_ponderado").html(resumen.total_factor_ponderado || 0); $("#totalAntesDescuento").val(resumen.total_antes_descuento || 0); $("#descuentoTotal").val(resumen.total_descuento || 0); $("#totalDespuesDecuento").val(resumen.total_presupuesto || 0).trigger("change") $("#precioUnidadPresupuesto").val(resumen.total_precio_unidad || 0); - $("#factor").val(resumen.total_factor|| 0); - $("#factor_ponderado").val(resumen.total_factor_ponderado|| 0); + $("#factor").val(resumen.total_factor || 0); + $("#factor_ponderado").val(resumen.total_factor_ponderado || 0); if (resumen.total_aceptado !== undefined) { $("#totalAceptado").html(resumen.total_aceptado || 0); @@ -94,7 +94,7 @@ class Resumen { - async updateTotales(data = {}) { + async updateTotales(data = {}, ajustar = false) { const self = this; @@ -181,7 +181,7 @@ class Resumen { $('#porcentajeMargenImpresion').html(porcentajeMargenImpresion).val(porcentajeMargenImpresion.toFixed(2)) $('#totalCosteImpresion').html(totalImpresion).val(totalImpresion.toFixed(2)) $('#margenImpresion').html(margenImpresion).val(margenImpresion.toFixed(2)) - + } else { @@ -297,18 +297,45 @@ class Resumen { margenEnvios = parseFloat($('#margenEnvios').attr('val')) } - let totalCostes = parseFloat(totalPapel.toFixed(2)) + parseFloat(totalImpresion.toFixed(2)) + let totalCostes = parseFloat(totalPapel.toFixed(2)) + parseFloat(totalImpresion.toFixed(2)) + parseFloat(totalServicios.toFixed(2)) + parseFloat(totalEnvios.toFixed(2)) let totalMargenes = parseFloat(margenPapel.toFixed(2)) + parseFloat(margenImpresion.toFixed(2)) + parseFloat(margenServicios.toFixed(2)) + parseFloat(margenEnvios.toFixed(2)) - let total_aceptado_revisado = AutoNumeric.getAutoNumericElement($('#total_aceptado_revisado')[0]).getNumber() - if(total_aceptado_revisado != '' && total_aceptado_revisado != undefined && - total_aceptado_revisado != null && total_aceptado_revisado != 0){ - if(total_aceptado_revisado < totalCostes){ - total_aceptado_revisado = totalCoste ; + let autoTotalAceptado = AutoNumeric.getAutoNumericElement($('#total_aceptado_revisado')[0]); + let total_aceptado_revisado = autoTotalAceptado.getNumber(); + + if (ajustar) { + if (total_aceptado_revisado && total_aceptado_revisado != 0) { + const nuevoTotal = totalCostes + totalEnvios_base; + + + if (total_aceptado_revisado < nuevoTotal) { + + if($('#total_aceptado')){ + $('#div_ajustar_error').removeClass('d-none'); + $('#error_recalcular_margen').hide().empty(). + html('El presupuesto está confirmado y el total coste + precio de envio es menor que el total aceptado y revisado'). + fadeIn("slow", function(){ + setTimeout(function(){ + $('#div_ajustar_error').addClass('d-none'); + }, 5000); + }); + + } + else{ + autoTotalAceptado.set(nuevoTotal); + total_aceptado_revisado = nuevoTotal; + } + + + } - totalMargenes = parseFloat(total_aceptado_revisado)- totalCostes; + + if(!($('#total_aceptado') && total_aceptado_revisado < nuevoTotal)){ + totalMargenes = total_aceptado_revisado - nuevoTotal; + } + } } let porcentajeMargen = totalCostes + totalMargenes > 0 ? (100 * totalMargenes / (totalCostes + totalMargenes)).toFixed(0) : 0 @@ -319,11 +346,10 @@ class Resumen { if ($('#total_descuentoPercent').val() < 0) { $('#total_descuentoPercent').val(0) } - let totalAntesDescuento = totalCostes + totalMargenes + parseFloat(totalEnvios.toFixed(2)) + totalEnvios_base; + let totalAntesDescuento = totalCostes + totalMargenes + totalEnvios_base; let totalDescuento = totalAntesDescuento * parseInt($('#total_descuentoPercent').val() || 0) / 100 let totalPresupuesto = totalAntesDescuento - totalDescuento; // para el calculo del precio_u solo se tiene en cuenta el base let precioUnidad = totalPresupuesto / parseInt($('#tirada').val()) - totalPresupuesto += totalEnvios; $('#totalAntesDescuento').html(totalAntesDescuento).val(totalAntesDescuento.toFixed(2)) $('#descuentoTotal').html(totalDescuento).val(totalDescuento.toFixed(2)) @@ -381,6 +407,12 @@ class Resumen { data.total_aceptado = $('#totalDespuesDecuento').val(); } + let autoTotalAceptado = AutoNumeric.getAutoNumericElement($('#total_aceptado_revisado')[0]); + let total_aceptado_revisado = autoTotalAceptado.getNumber(); + if (total_aceptado_revisado && total_aceptado_revisado != 0) { + data.total_aceptado_revisado = total_aceptado_revisado; + } + return data; } From 6b1dc578211162be4f40aa969ce85045faaf1ccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Fri, 4 Apr 2025 18:14:31 +0200 Subject: [PATCH 10/14] corregido --- .../form/presupuestos/admin/_resumenPresupuestoItems.php | 4 ++-- .../js/safekat/pages/presupuestoAdmin/sections/resumen.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_resumenPresupuestoItems.php b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_resumenPresupuestoItems.php index 31a2a04b..9d4c9fbe 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_resumenPresupuestoItems.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_resumenPresupuestoItems.php @@ -143,7 +143,7 @@ class="btn btn-primary w-100">Ajustar - estado_id == 2): ?> + estado_id == 2): ?>
- +

diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/resumen.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/resumen.js index ca466e56..98920850 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/resumen.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/resumen.js @@ -338,7 +338,7 @@ class Resumen { } } - let porcentajeMargen = totalCostes + totalMargenes > 0 ? (100 * totalMargenes / (totalCostes + totalMargenes)).toFixed(0) : 0 + let porcentajeMargen = totalCostes + totalMargenes > 0 ? (100 * totalMargenes / (totalCostes)).toFixed(0) : 0 $('#totalCostes').html(totalCostes).val(totalCostes.toFixed(2)) $('#totalMargenes').html(totalMargenes).val(totalMargenes.toFixed(2)) $('#porcentajeMargen').html(porcentajeMargen).val(porcentajeMargen) From e70e3b9683ecbb2bd3b257148a351ed6eecce61b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Fri, 4 Apr 2025 18:21:25 +0200 Subject: [PATCH 11/14] corregido --- ci4/app/Controllers/Presupuestos/Presupuestoadmin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php index e13c2a5c..d554c1f0 100644 --- a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php @@ -645,7 +645,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $data['total_aceptado_revisado'] = $presupuesto->total_aceptado_revisado; $data['aprobado_by_at'] = ($presupuesto->aprobado_user_id != null)? - model('App\Models\UserModel')->getFullName($presupuesto->aprobado_user_id) . ', ' + model('App\Models\Usuarios\UserModel')->getFullName($presupuesto->aprobado_user_id) . ', ' . date('d/m/Y H:i:s', strtotime($presupuesto->aprobado_at)):''; From c493f7c8acc0f5315e3cdab81a6226931a35ba6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Fri, 4 Apr 2025 18:30:24 +0200 Subject: [PATCH 12/14] corregido --- .../form/presupuestos/admin/_resumenPresupuestoItems.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_resumenPresupuestoItems.php b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_resumenPresupuestoItems.php index 9d4c9fbe..31a2a04b 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_resumenPresupuestoItems.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_resumenPresupuestoItems.php @@ -143,7 +143,7 @@ class="btn btn-primary w-100">Ajustar

- estado_id == 2): ?> + estado_id == 2): ?>
- +

From 21dceb2c23ceab45a71d17abe619a1481ccec3e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Sat, 5 Apr 2025 08:49:24 +0200 Subject: [PATCH 13/14] arraglado --- .../pages/presupuestoAdmin/sections/lineasPresupuesto.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/lineasPresupuesto.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/lineasPresupuesto.js index d7ecc331..6f991a0e 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/lineasPresupuesto.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/lineasPresupuesto.js @@ -235,7 +235,7 @@ class LineasPresupuesto { let tipo = 'negro'; switch (row.row_id) { - case 'lp_negrohq': + case 'lp_bnhq': tipo = 'negrohq'; break; case 'lp_rot_color': @@ -1727,7 +1727,7 @@ class LineasPresupuesto { let tipo = 'negro'; let uso = 'interior'; switch (tipoLinea) { - case 'lp_negrohq': + case 'lp_bnhq': tipo = 'negrohq'; break; case 'lp_rot_color': From 73e6106e4f9ae8b9c567374dcce4d70d3e04118a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Sat, 5 Apr 2025 10:25:08 +0200 Subject: [PATCH 14/14] =?UTF-8?q?solucionado.=20Tambi=C3=A9n=20corregidos?= =?UTF-8?q?=20a=C3=B1adir=20margen=20en=20envios=20de=20cliente=20y=20prob?= =?UTF-8?q?lema=20al=20cargar=20cubierta=20con=20solapas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Presupuestos/Presupuestocliente.php | 80 ++++++++++--------- .../presupuestoAdmin/sections/datosLibro.js | 6 +- .../presupuestoAdmin/sections/servicios.js | 64 ++++++++++++--- .../presupuestoCliente/disenioCubierta.js | 31 +++---- 4 files changed, 116 insertions(+), 65 deletions(-) diff --git a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php index b25d3db9..56c32604 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php @@ -601,7 +601,9 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController ]; return $return_data; } else { - $return_data['eb'][$i] = round($coste_direccion->coste, 2); + $coste = floatval($coste_direccion->coste); + $margen = $coste * (intval($coste_direccion->margen) / 100.0); + $return_data['eb'][$i] = round($coste + $margen, 2); } } @@ -657,16 +659,17 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController ]; return $return_data; } else { - // Se añade a los costes de envío - $coste_envio += $coste_direccion->coste; + $coste = floatval($coste_direccion->coste); + $margen = $coste * (intval($coste_direccion->margen) / 100.0); + $coste_envio += $coste + $margen; } } $return_data['coste_envio'][$i] = round($coste_envio, 2); } - } + } + - if ($this->request) { if ($this->request->isAJAX()) @@ -1101,7 +1104,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController } } } else if (isset($resultado_presupuesto['exception'])) { - if($this->request) { + if ($this->request) { return $this->respond([ 'error' => $resultado_presupuesto['exception'], 'file' => $resultado_presupuesto['file'], @@ -1111,7 +1114,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController return $resultado_presupuesto['exception']; } } - + // seleccionamos el peso de la tirada seleccionada $peso_libro = $resultado_presupuesto['peso'][array_search($selected_tirada, $tirada)]; @@ -1225,7 +1228,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController } $resultado_presupuesto['coste_envio'][$i] = round($coste_envio, 2); } - } + } $model_presupuesto = new PresupuestoModel(); $tiradas_alternativas = []; @@ -1242,7 +1245,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $resultado_presupuesto['info']['totales'][$i]['margenPapel'] + $resultado_presupuesto['info']['totales'][$i]['margen_envio']) / ($coste_total + $coste_envio) * 100.0, 2); $total_pedido = round(($coste_total + $resultado_presupuesto['info']['totales'][$i]['totalServicios'] + $resultado_presupuesto['info']['totales'][$i]['margenServicios'] + $coste_envio), 2); - $precio_u = round( $resultado_presupuesto['precio_u'][$i], 4); + $precio_u = round($resultado_presupuesto['precio_u'][$i], 4); array_push($tiradas_alternativas, (object) array( 'tirada' => $tirada[$i], @@ -1255,7 +1258,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController } else { $resumen_totales = $resultado_presupuesto['info']['totales'][$i]; $resumen_totales['precio_unidad'] = round($resultado_presupuesto['precio_u'][$i], 4); - + } } @@ -1613,8 +1616,10 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController if (intval($presupuesto->estado_id) == 2) { $data['resumen']['base'] = $presupuesto->total_antes_descuento; $data['resumen']['total_envio'] = round( - floatval($presupuesto->total_coste_envios) + - floatval($presupuesto->total_margen_envios), 2); + floatval($presupuesto->total_coste_envios) + + floatval($presupuesto->total_margen_envios), + 2 + ); $data['resumen']['precio_unidad'] = $presupuesto->total_precio_unidad; } @@ -2207,6 +2212,8 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController return $return_data; } + $cantidad_total = intval($datosPedido->tirada) + intval($datosPedido->merma); + // Acabado Cubierta if (intval($datos_entrada['cubierta']['acabado']) != 0) { @@ -2215,7 +2222,8 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController foreach ($serviciosAcabado as $servicio) { $model = model('App\Models\Presupuestos\PresupuestoAcabadosModel'); - $acabadoCubierta = $model->getPrecioTarifa(intval($servicio), $datosPedido->tirada, -1, $POD); + + $acabadoCubierta = $model->getPrecioTarifa(intval($servicio), $cantidad_total, -1, $POD); if (count($acabadoCubierta) > 0) { if ($acabadoCubierta[0]->total <= 0) { @@ -2239,7 +2247,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController if ($extra_info) { $totalServicios += round(floatval($acabadoCubierta[0]->total), 2); $base = round(floatval($acabadoCubierta[0]->total / (1 + $acabadoCubierta[0]->margen / 100.0)), 2); - $base = round(floatval($base / $datosPedido->tirada), 2) * $datosPedido->tirada; + $base = round(floatval($base / $cantidad_total), 2) * $cantidad_total; $margenServicios += round(floatval($acabadoCubierta[0]->total - $base), 2); } } @@ -2252,7 +2260,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $tarifa = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_lomo_redondo')->value; $resultado = PresupuestoCLienteService::getServiciosManipulado([ 'tarifa_id' => intval($tarifa), - 'tirada' => $datosPedido->tirada, + 'tirada' => $cantidad_total, 'POD' => $POD, ]); @@ -2278,7 +2286,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController if ($extra_info) { $totalServicios += round(floatval($resultado[0]->total), 2); $base = round(floatval($resultado[0]->total / (1 + $resultado[0]->margen / 100.0)), 2); - $base = round(floatval($base / $datosPedido->tirada), 2) * $datosPedido->tirada; + $base = round(floatval($base / $cantidad_total), 2) * $cantidad_total; $margenServicios += round(floatval($resultado[0]->total - $base), 2); } @@ -2348,7 +2356,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController foreach ($serviciosAcabado as $servicio) { $model = model('App\Models\Presupuestos\PresupuestoAcabadosModel'); - $acabadoSobrecubierta = $model->getPrecioTarifa(intval($servicio), $datosPedido->tirada, -1, $POD); + $acabadoSobrecubierta = $model->getPrecioTarifa(intval($servicio), $cantidad_total, -1, $POD); if (count($acabadoSobrecubierta) > 0) { @@ -2374,7 +2382,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController if ($extra_info) { $totalServicios += round(floatval($acabadoSobrecubierta[0]->total), 2); $base = round(floatval($acabadoSobrecubierta[0]->total / (1 + $acabadoSobrecubierta[0]->margen / 100.0)), 2); - $base = round(floatval($base / $datosPedido->tirada), 2) * $datosPedido->tirada; + $base = round(floatval($base / $cantidad_total), 2) * $cantidad_total; $margenServicios += round(floatval($acabadoSobrecubierta[0]->total - $base), 2); } } @@ -2506,7 +2514,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController foreach ($serviciosAcabado as $servicio) $model = model('App\Models\Presupuestos\PresupuestoAcabadosModel'); - $acabadoFaja = $model->getPrecioTarifa(intval($servicio), $datosPedido->tirada, -1, $POD); + $acabadoFaja = $model->getPrecioTarifa(intval($servicio), $cantidad_total, -1, $POD); if (count($acabadoFaja) > 0) { @@ -2532,7 +2540,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController if ($extra_info) { $totalServicios += round(floatval($acabadoFaja[0]->total), 2); $base = round(floatval($acabadoFaja[0]->total / (1 + $acabadoFaja[0]->margen / 100.0)), 2); - $base = round(floatval($base / $datosPedido->tirada), 2) * $datosPedido->tirada; + $base = round(floatval($base / $cantidad_total), 2) * $cantidad_total; $margenServicios += round(floatval($acabadoFaja[0]->total - $base), 2); } } @@ -2552,7 +2560,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $costeServiciosDefecto = 0.0; $servDefectoEnc = PresupuestoCLienteService::getServiciosEncuadernacionDefault([ 'tipo_impresion_id' => $tipo_impresion_id, - 'tirada' => $datosPedido->tirada, + 'tirada' => $cantidad_total, 'paginas' => intval($paginas) ?? 0, 'ancho' => $datosPedido->ancho, 'alto' => $datosPedido->alto, @@ -2586,14 +2594,14 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController if ($extra_info) { $totalServicios += round(floatval($servicio->total), 2); $base = round(floatval($servicio->total / (1 + $servicio->margen / 100.0)), 2); - $base = round(floatval($base / $datosPedido->tirada), 2) * $datosPedido->tirada; + $base = round(floatval($base / $cantidad_total), 2) * $cantidad_total; $margenServicios += round(floatval($servicio->total - $base), 2); } } $servDefectoMan = PresupuestoCLienteService::getServiciosManipuladoDefault([ 'tipo_impresion_id' => $tipo_impresion_id, - 'tirada' => $datosPedido->tirada, + 'tirada' => $cantidad_total, 'POD' => $POD, 'solapas' => intval($solapasCubierta) > 0 ? 1 : 0, ]); @@ -2623,7 +2631,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController if ($extra_info) { $totalServicios += round(floatval($servicio->total), 2); $base = round(floatval($servicio->total / (1 + $servicio->margen / 100.0)), 2); - $base = round(floatval($base / $datosPedido->tirada), 2) * $datosPedido->tirada; + $base = round(floatval($base / $cantidad_total), 2) * $cantidad_total; $margenServicios += round(floatval($servicio->total - $base), 2); } } @@ -2702,7 +2710,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController // Servicios acabado $resultado = PresupuestoCLienteService::getServiciosAcabados([ 'tarifa_id' => intval($servicio->id), - 'tirada' => $datosPedido->tirada, + 'tirada' => $cantidad_total, 'POD' => $POD, ]); array_push($serviciosAutomaticos, $resultado[0]); @@ -2728,7 +2736,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController if ($extra_info) { $totalServicios += round(floatval($resultado[0]->total), 2); $base = round(floatval($resultado[0]->total / (1 + $resultado[0]->margen / 100.0)), 2); - $base = round(floatval($base / $datosPedido->tirada), 2) * $datosPedido->tirada; + $base = round(floatval($base / $cantidad_total), 2) * $cantidad_total; $margenServicios += round(floatval($resultado[0]->total - $base), 2); } } else if ($servicio->nombre == "ferro" || $servicio->nombre == "prototipo") { @@ -2760,14 +2768,14 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController if ($extra_info) { $totalServicios += round(floatval($resultado[0]->precio), 2); $base = round(floatval($resultado[0]->total / (1 + $resultado[0]->margen / 100.0)), 2); - $base = round(floatval($base / $datosPedido->tirada), 2) * $datosPedido->tirada; + $base = round(floatval($base / $cantidad_total), 2) * $cantidad_total; $margenServicios += round(floatval($resultado[0]->total - $base), 2); } } else if ($servicio->nombre == 'solapas_cubierta' || $servicio->nombre == 'solapas_sobrecubierta' || $servicio->nombre == 'solapas_faja') { // Servicios manipulado $resultado = PresupuestoCLienteService::getServiciosManipulado([ 'tarifa_id' => intval($servicio->id), - 'tirada' => $datosPedido->tirada, + 'tirada' => $cantidad_total, 'POD' => $POD, ]); @@ -2794,7 +2802,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController if ($extra_info) { $totalServicios += round(floatval($resultado[0]->total), 2); $base = round(floatval($resultado[0]->total / (1 + $resultado[0]->margen / 100.0)), 2); - $base = round(floatval($base / $datosPedido->tirada), 2) * $datosPedido->tirada; + $base = round(floatval($base / $cantidad_total), 2) * $cantidad_total; $margenServicios += round(floatval($resultado[0]->total - $base), 2); } } @@ -2835,7 +2843,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController if ($extra_info) { $totalServicios += round(floatval($resultado[0]->precio), 2); $base = round(floatval($resultado[0]->precio / (1 + $resultado[0]->margen / 100.0)), 2); - $base = round(floatval($base / $datosPedido->tirada), 2) * $datosPedido->tirada; + $base = round(floatval($base / $cantidad_total), 2) * $cantidad_total; $margenServicios += round(floatval($resultado[0]->precio - $base), 2); } } @@ -2847,7 +2855,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController // Servicios manipulado $resultado = PresupuestoCLienteService::getServiciosManipulado([ 'tarifa_id' => intval($servicio_solapas_grandes_cubierta->id), - 'tirada' => $datosPedido->tirada, + 'tirada' => $cantidad_total, 'POD' => $POD, ]); @@ -2874,7 +2882,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController if ($extra_info) { $totalServicios += round(floatval($resultado[0]->total), 2); $base = round(floatval($resultado[0]->total / (1 + $resultado[0]->margen / 100.0)), 2); - $base = round(floatval($base / $datosPedido->tirada), 2) * $datosPedido->tirada; + $base = round(floatval($base / $cantidad_total), 2) * $cantidad_total; $margenServicios += round(floatval($resultado[0]->total - $base), 2); } } @@ -2884,7 +2892,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController // Servicios manipulado $resultado = PresupuestoCLienteService::getServiciosManipulado([ 'tarifa_id' => intval($servicio_solapas_grandes_sobrecubierta->id), - 'tirada' => $datosPedido->tirada, + 'tirada' => $cantidad_total, 'POD' => $POD, ]); @@ -2911,7 +2919,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController if ($extra_info) { $totalServicios += round(floatval($resultado[0]->total), 2); $base = round(floatval($resultado[0]->total / (1 + $resultado[0]->margen / 100.0)), 2); - $base = round(floatval($base / $datosPedido->tirada), 2) * $datosPedido->tirada; + $base = round(floatval($base / $cantidad_total), 2) * $cantidad_total; $margenServicios += round(floatval($resultado[0]->total - $base), 2); } } @@ -2921,7 +2929,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController // Servicios manipulado $resultado = PresupuestoCLienteService::getServiciosManipulado([ 'tarifa_id' => intval($servicio_solapas_grandes_faja->id), - 'tirada' => $datosPedido->tirada, + 'tirada' => $cantidad_total, 'POD' => $POD, ]); @@ -2948,7 +2956,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController if ($extra_info) { $totalServicios += round(floatval($resultado[0]->total), 2); $base = round(floatval($resultado[0]->total / (1 + $resultado[0]->margen / 100.0)), 2); - $base = round(floatval($base / $datosPedido->tirada), 2) * $datosPedido->tirada; + $base = round(floatval($base / $cantidad_total), 2) * $cantidad_total; $margenServicios += round(floatval($resultado[0]->total - $base), 2); } } diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js index ae7e402d..61f8bf67 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js @@ -548,10 +548,10 @@ class DatosLibro { this.updateComparador(); - const url2 = window.location.href; - const url_parts2 = url2.split('/'); + const url = window.location.href; + - if (url_parts2[url_parts2.length - 2] == 'edit') { + if (url.includes('edit')) { $(document).trigger('update-presupuesto', { update_lineas: true, update_servicios: true, diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/servicios.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/servicios.js index a9e474b6..2fc81df3 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/servicios.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/servicios.js @@ -116,13 +116,13 @@ class Servicios { } else if (servicio == 'ferro') { const id = $('#ferro').attr('service-id'); - if(!this.checkServiceInTable(this.serviciosExtra.table, id)) - this.serviciosExtra.getPresupuestoExtra(id); + if (!this.checkServiceInTable(this.serviciosExtra.table, id)) + this.serviciosExtra.getPresupuestoExtra(id); } else if (servicio == 'ferroDigital') { const id = $('#ferroDigital').attr('service-id'); - if(!this.checkServiceInTable(this.serviciosExtra.table, id)) - this.serviciosExtra.getPresupuestoExtra(id); + if (!this.checkServiceInTable(this.serviciosExtra.table, id)) + this.serviciosExtra.getPresupuestoExtra(id); } else if (servicio == 'prototipo') { const id = $('#prototipo').attr('service-id'); @@ -137,7 +137,7 @@ class Servicios { else if (servicio == 'retractilado5') { const id = $('#retractilado5').attr('service-id'); if (!this.checkServiceInTable(this.serviciosAcabado.table, id)) - this.serviciosAcabado.getPresupuestoAcabado(id, null, null,true); + this.serviciosAcabado.getPresupuestoAcabado(id, null, null, true); } else if (servicio == 'solapas_cubierta') { const id = $('#serv_solapas_cubierta').attr('service-id'); @@ -227,7 +227,7 @@ class Servicios { } else if (servicio == 'retractilado') { const id = $('#retractilado').attr('service-id'); - for(let i = this.serviciosAcabado.table.rows().count(); i >= 0; i--) { + for (let i = this.serviciosAcabado.table.rows().count(); i >= 0; i--) { let data = this.serviciosAcabado.table.row(i).data(); if (data && data.tarifa_id == id) { this.serviciosAcabado.table.row(i).remove(); @@ -238,7 +238,7 @@ class Servicios { } else if (servicio == 'retractilado5') { const id = $('#retractilado5').attr('service-id'); - for(let i = this.serviciosAcabado.table.rows().count(); i >= 0; i--) { + for (let i = this.serviciosAcabado.table.rows().count(); i >= 0; i--) { let data = this.serviciosAcabado.table.row(i).data(); if (data && data.tarifa_id == id) { this.serviciosAcabado.table.row(i).remove(); @@ -461,6 +461,10 @@ class ServiciosAcabado { if (parseInt($('#tirada').val()) > 0) { var tirada = parseInt($('#tirada').val()) + var merma = parseInt($('#merma').val()) + if (merma && merma > 0) { + tirada = tirada + merma; + } } else { var tirada = 0 @@ -532,6 +536,10 @@ class ServiciosAcabado { let tirada = 0; if (parseInt($('#tirada').val()) > 0) { tirada = parseInt($('#tirada').val()) + var merma = parseInt($('#merma').val()) + if (merma && merma > 0) { + tirada = tirada + merma; + } } if (tarifa_ids.length > 0 && tirada > 0) { const data = { @@ -578,6 +586,10 @@ class ServiciosAcabado { let tirada = 0 if (parseInt($('#tirada').val()) > 0) { tirada = parseInt($('#tirada').val()) + var merma = parseInt($('#merma').val()) + if (merma && merma > 0) { + tirada = tirada + merma; + } } let datos = { tirada: tirada, @@ -596,7 +608,7 @@ class ServiciosAcabado { new Ajax('/serviciosacabados/getvalues', datos, {}, function (response) { if (response.values) { - if(uso=='cubierta'){ + if (uso == 'cubierta') { for (let i = self.table.rows().count() - 1; i >= 0; i--) { let data = self.table.row(i).data(); if (data && (data.cubierta == 1)) { @@ -604,7 +616,7 @@ class ServiciosAcabado { } } } - else if(uso=='sobrecubierta'){ + else if (uso == 'sobrecubierta') { for (let i = self.table.rows().count() - 1; i >= 0; i--) { let data = self.table.row(i).data(); if (data && (data.sobrecubierta == 1)) { @@ -612,7 +624,7 @@ class ServiciosAcabado { } } } - else if(uso=='faja'){ + else if (uso == 'faja') { for (let i = self.table.rows().count() - 1; i >= 0; i--) { let data = self.table.row(i).data(); if (data && (data.faja == 1)) { @@ -645,7 +657,7 @@ class ServiciosAcabado { else { self.table.rows.add(response.values).draw(false); } - + } }, function (error) { @@ -1059,7 +1071,11 @@ class ServiciosEncuadernacion { let tirada = 0; if (parseInt($('#tirada').val()) > 0) { - tirada = parseInt($('#tirada').val()) + tirada = parseInt($('#tirada').val()); + var merma = parseInt($('#merma').val()) + if (merma && merma > 0) { + tirada = tirada + merma; + } } let paginas = 0; @@ -1160,6 +1176,10 @@ class ServiciosEncuadernacion { let tirada = 0; if (parseInt($('#tirada').val()) > 0) { tirada = parseInt($('#tirada').val()) + var merma = parseInt($('#merma').val()) + if (merma && merma > 0) { + tirada = tirada + merma; + } } let paginas = 0; if (parseInt($('#paginas').val()) > 0) { @@ -1201,6 +1221,10 @@ class ServiciosEncuadernacion { let tirada = 0; if (parseInt($('#tirada').val()) > 0) { tirada = parseInt($('#tirada').val()) + var merma = parseInt($('#merma').val()) + if (merma && merma > 0) { + tirada = tirada + merma; + } } let paginas = 0; if (parseInt($('#paginas').val()) > 0) { @@ -1243,6 +1267,10 @@ class ServiciosEncuadernacion { let tirada = 0; if (parseInt($('#tirada').val()) > 0) { tirada = parseInt($('#tirada').val()) + var merma = parseInt($('#merma').val()) + if (merma && merma > 0) { + tirada = tirada + merma; + } } let paginas = 0; if (parseInt($('#paginas').val()) > 0) { @@ -1531,6 +1559,10 @@ class ServiciosManipulado { let tirada = 0; if (parseInt($('#tirada').val()) > 0) { tirada = parseInt($('#tirada').val()) + var merma = parseInt($('#merma').val()) + if (merma && merma > 0) { + tirada = tirada + merma; + } } let datos = { @@ -1568,6 +1600,10 @@ class ServiciosManipulado { let tirada = 0; if (parseInt($('#tirada').val()) > 0) { tirada = parseInt($('#tirada').val()) + var merma = parseInt($('#merma').val()) + if (merma && merma > 0) { + tirada = tirada + merma; + } } if (tarifa_ids.length > 0) { @@ -1597,6 +1633,10 @@ class ServiciosManipulado { let tirada = 0; if (parseInt($('#tirada').val()) > 0) { tirada = parseInt($('#tirada').val()) + var merma = parseInt($('#merma').val()) + if (merma && merma > 0) { + tirada = tirada + merma; + } } let datos = { diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js index dddb012b..a8647048 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js @@ -324,6 +324,7 @@ class DisenioCubierta { this.papelCubierta = datosCubierta.papel.id; this.gramaje = datosCubierta.gramaje; + if (datosCubierta.lomoRedondo) { this.tapaDuraLomoRedondo.trigger('click'); } @@ -336,23 +337,25 @@ class DisenioCubierta { } } - if (datosCubierta.tapa == "dura") { - this.papelGuardas.setOption(datosGuardas.papel_id, datosGuardas.papel); - this.gramajeGuardas.setOption(datosGuardas.gramaje, datosGuardas.gramaje); - this.guardasImpresas.val(datosGuardas.paginas).trigger('change'); - this.cabezada.val(datosCubierta.cabezada).trigger('change'); - } - else { - this.carasCubierta.val(datosCubierta.paginas).trigger('change'); - if (datosCubierta.solapas) { - this.conSolapas.trigger('click'); - this.tamanioSolapasCubierta.val(datosCubierta.solapas_ancho); - + setTimeout(() => { + if (datosCubierta.tapa == "dura") { + this.papelGuardas.setOption(datosGuardas.papel_id, datosGuardas.papel); + this.gramajeGuardas.setOption(datosGuardas.gramaje, datosGuardas.gramaje); + this.guardasImpresas.val(datosGuardas.paginas).trigger('change'); + this.cabezada.val(datosCubierta.cabezada).trigger('change'); } else { - this.sinSolapas.trigger('click'); + this.carasCubierta.val(datosCubierta.paginas).trigger('change'); + if (datosCubierta.solapas) { + this.conSolapas.trigger('click'); + this.tamanioSolapasCubierta.val(datosCubierta.solapas_ancho); + + } + else { + this.sinSolapas.trigger('click'); + } } - } + }, 0); this.divPapelCubierta.find(`[cod="${datosCubierta.papel.code}"]`).addClass('selected');