diff --git a/ci4/app/Config/Email.php b/ci4/app/Config/Email.php index 43b3edb0..9447a491 100755 --- a/ci4/app/Config/Email.php +++ b/ci4/app/Config/Email.php @@ -6,7 +6,7 @@ use CodeIgniter\Config\BaseConfig; class Email extends BaseConfig { - public string $fromEmail = 'safekat@imnavajas.es'; + public string $fromEmail = 'soporte_erp@safekat.es'; public string $fromName = 'Safekat ERP'; public string $recipients = ''; @@ -28,27 +28,27 @@ class Email extends BaseConfig /** * SMTP Server Hostname */ - public string $SMTPHost = 'imnavajas.es'; + public string $SMTPHost = 'smtp.ionos.es'; /** * SMTP Username */ - public string $SMTPUser = 'safekat@imnavajas.es'; + public string $SMTPUser = 'soporte_erp@safekat.es'; /** * SMTP Password */ - public string $SMTPPass = 'Etkd9~448'; + public string $SMTPPass = 'H%5&qDkDkWnfLTGN'; /** * SMTP Port */ - public int $SMTPPort = 25; + public int $SMTPPort = 465; /** * SMTP Timeout (in seconds) */ - public int $SMTPTimeout = 5; + public int $SMTPTimeout = 15; /** * Enable persistent SMTP connections diff --git a/ci4/app/Config/RBAC/permissionMatrix.php b/ci4/app/Config/RBAC/permissionMatrix.php index c13aa388..c9f0a2ee 100644 --- a/ci4/app/Config/RBAC/permissionMatrix.php +++ b/ci4/app/Config/RBAC/permissionMatrix.php @@ -1,6 +1,182 @@ [ + "clientes.create", + "clientes.edit", + "clientes.delete", + "clientes.menu", + "plantilla-tarifa.create", + "plantilla-tarifa.edit", + "plantilla-tarifa.delete", + "plantilla-tarifa.menu", + "direcciones.create", + "direcciones.edit", + "direcciones.delete", + "direcciones.menu", + "presupuesto.create", + "presupuesto.edit", + "presupuesto.delete", + "presupuesto.menu", + "presupuesto-cliente.create", + "presupuesto-cliente.edit", + "presupuesto-cliente.delete", + "presupuesto-cliente.menu", + "pedidos-activos.view", + "pedidos-activos.menu", + "pedidos-finalizados.view", + "pedidos-finalizados.menu", + "pedidos-cancelados.view", + "pedidos-cancelados.menu", + "pedidos-todos.view", + "pedidos-todos.menu", + "tarifa-preimpresion.create", + "tarifa-preimpresion.edit", + "tarifa-preimpresion.delete", + "tarifa-preimpresion.menu", + "tarifa-manipulado.create", + "tarifa-manipulado.edit", + "tarifa-manipulado.delete", + "tarifa-manipulado.menu", + "tarifa-acabado.create", + "tarifa-acabado.edit", + "tarifa-acabado.delete", + "tarifa-acabado.menu", + "tarifa-encuadernacion.create", + "tarifa-encuadernacion.edit", + "tarifa-encuadernacion.delete", + "tarifa-encuadernacion.menu", + "tarifa-envio.create", + "tarifa-envio.edit", + "tarifa-envio.delete", + "tarifa-envio.menu", + "proveedores.create", + "proveedores.edit", + "proveedores.delete", + "proveedores.menu", + "ajustes.create", + "ajustes.edit", + "ajustes.delete", + "ajustes.menu", + "actividad.create", + "actividad.edit", + "actividad.delete", + "actividad.menu", + "paises.create", + "paises.edit", + "paises.delete", + "paises.menu", + "maquinas.create", + "maquinas.edit", + "maquinas.delete", + "maquinas.menu", + "maquinas-defecto.create", + "maquinas-defecto.edit", + "maquinas-defecto.delete", + "maquinas-defecto.menu", + "papel-generico.create", + "papel-generico.edit", + "papel-generico.delete", + "papel-generico.menu", + "papel-impresion.create", + "papel-impresion.edit", + "papel-impresion.delete", + "papel-impresion.menu", + "usuarios.create", + "usuarios.edit", + "usuarios.delete", + "usuarios.menu", + "roles-permisos.create", + "roles-permisos.edit", + "roles-permisos.delete", + "roles-permisos.menu", + "tickets.create", + "tickets.edit", + "tickets.menu", + ], + "cliente-admin" => [ + "presupuesto-cliente.create", + "presupuesto-cliente.edit", + "presupuesto-cliente.delete", + "presupuesto-cliente.menu", + "pedidos-activos.view", + "pedidos-activos.menu", + "pedidos-finalizados.view", + "pedidos-finalizados.menu", + "pedidos-cancelados.view", + "pedidos-cancelados.menu", + "pedidos-todos.view", + "pedidos-todos.menu", + ], + "cliente-editor" => [ + "presupuesto-cliente.create", + "presupuesto-cliente.edit", + "presupuesto-cliente.menu", + "pedidos-activos.view", + "pedidos-activos.menu", + "pedidos-finalizados.view", + "pedidos-finalizados.menu", + "pedidos-cancelados.view", + "pedidos-cancelados.menu", + "pedidos-todos.view", + "pedidos-todos.menu", + ], + "comercial" => [ + "clientes.create", + "clientes.edit", + "clientes.menu", + "direcciones.create", + "direcciones.edit", + "direcciones.menu", + "presupuesto.create", + "presupuesto.edit", + "presupuesto.delete", + "presupuesto.menu", + "presupuesto-cliente.create", + "presupuesto-cliente.edit", + "presupuesto-cliente.menu", + "pedidos-activos.view", + "pedidos-activos.menu", + "pedidos-finalizados.view", + "pedidos-finalizados.menu", + "pedidos-cancelados.view", + "pedidos-cancelados.menu", + "pedidos-todos.view", + "pedidos-todos.menu", + ], + "produccion" => [ + "clientes.create", + "clientes.edit", + "clientes.menu", + "direcciones.create", + "direcciones.edit", + "direcciones.menu", + "presupuesto.create", + "presupuesto.edit", + "presupuesto.menu", + ], + "maquina" => [ + "token.token", + "token.menu", + ], + "maquetador" => [ + "token.token", + "token.menu", + ], + "director" => [ + "token.token", + "token.menu", + ], + "contabilidad" => [ + "token.token", + "token.menu", + ], + "editor" => [ + "token.token", + "token.menu", + "Profile.index", + "Profile.menu", + ], + "beta" => [ "clientes.create", "clientes.edit", "clientes.delete", @@ -93,159 +269,8 @@ const SK_PERMISSION_MATRIX = [ "roles-permisos.edit", "roles-permisos.delete", "roles-permisos.menu", - ], - "cliente-admin" => [ - "presupuesto-cliente.create", - "presupuesto-cliente.edit", - "presupuesto-cliente.delete", - "presupuesto-cliente.menu", - "pedidos-activos.view", - "pedidos-activos.menu", - "pedidos-finalizados.view", - "pedidos-finalizados.menu", - "pedidos-cancelados.view", - "pedidos-cancelados.menu", - "pedidos-todos.view", - "pedidos-todos.menu", - ], - "cliente-editor" => [ - "presupuesto-cliente.create", - "presupuesto-cliente.edit", - "presupuesto-cliente.menu", - "pedidos-activos.view", - "pedidos-activos.menu", - "pedidos-finalizados.view", - "pedidos-finalizados.menu", - "pedidos-cancelados.view", - "pedidos-cancelados.menu", - "pedidos-todos.view", - "pedidos-todos.menu", - ], - "comercial" => [ - "token.token", - "token.menu", - ], - "produccion" => [ - "clientes.create", - "clientes.edit", - "clientes.menu", - "direcciones.create", - "direcciones.edit", - "direcciones.menu", - "presupuesto.create", - "presupuesto.edit", - "presupuesto.menu", - ], - "maquina" => [ - "token.token", - "token.menu", - ], - "maquetador" => [ - "token.token", - "token.menu", - ], - "director" => [ - "token.token", - "token.menu", - ], - "contabilidad" => [ - "token.token", - "token.menu", - ], - "editor" => [ - "token.token", - "token.menu", - "Profile.index", - "Profile.menu", - ], - "beta" => [ - "clientes.create", - "clientes.edit", - "clientes.delete", - "clientes.menu", - "plantilla-tarifa.create", - "plantilla-tarifa.edit", - "plantilla-tarifa.delete", - "plantilla-tarifa.menu", - "direcciones.create", - "direcciones.edit", - "direcciones.delete", - "direcciones.menu", - "presupuesto.create", - "presupuesto.edit", - "presupuesto.delete", - "presupuesto.menu", - "presupuesto-cliente.create", - "presupuesto-cliente.edit", - "presupuesto-cliente.delete", - "presupuesto-cliente.menu", - "pedidos-activos.view", - "pedidos-activos.menu", - "pedidos-finalizados.view", - "pedidos-finalizados.menu", - "pedidos-cancelados.view", - "pedidos-cancelados.menu", - "pedidos-todos.view", - "pedidos-todos.menu", - "tarifa-preimpresion.create", - "tarifa-preimpresion.edit", - "tarifa-preimpresion.delete", - "tarifa-preimpresion.menu", - "tarifa-manipulado.create", - "tarifa-manipulado.edit", - "tarifa-manipulado.delete", - "tarifa-manipulado.menu", - "tarifa-acabado.create", - "tarifa-acabado.edit", - "tarifa-acabado.delete", - "tarifa-acabado.menu", - "tarifa-encuadernacion.create", - "tarifa-encuadernacion.edit", - "tarifa-encuadernacion.delete", - "tarifa-encuadernacion.menu", - "tarifa-envio.create", - "tarifa-envio.edit", - "tarifa-envio.delete", - "tarifa-envio.menu", - "proveedores.create", - "proveedores.edit", - "proveedores.delete", - "proveedores.menu", - "ajustes.create", - "ajustes.edit", - "ajustes.delete", - "ajustes.menu", - "actividad.create", - "actividad.edit", - "actividad.delete", - "actividad.menu", - "paises.create", - "paises.edit", - "paises.delete", - "paises.menu", - "maquinas.create", - "maquinas.edit", - "maquinas.delete", - "maquinas.menu", - "maquinas-defecto.create", - "maquinas-defecto.edit", - "maquinas-defecto.delete", - "maquinas-defecto.menu", - "papel-generico.create", - "papel-generico.edit", - "papel-generico.delete", - "papel-generico.menu", - "papel-impresion.create", - "papel-impresion.edit", - "papel-impresion.delete", - "papel-impresion.menu", - "usuarios.create", - "usuarios.edit", - "usuarios.delete", - "usuarios.menu", - "roles-permisos.create", - "roles-permisos.edit", - "roles-permisos.delete", - "roles-permisos.menu", + "tickets.create", + "tickets.edit", + "tickets.menu", ], ]; diff --git a/ci4/app/Config/RBAC/permissions.php b/ci4/app/Config/RBAC/permissions.php index 4c640b77..35e8235f 100644 --- a/ci4/app/Config/RBAC/permissions.php +++ b/ci4/app/Config/RBAC/permissions.php @@ -93,4 +93,7 @@ const SK_PERMISSIONS = [ 'roles-permisos.edit' => 'Can edit', 'roles-permisos.delete' => 'Can delete', 'roles-permisos.menu' => 'Menu shall be visualize', + 'tickets.create' => 'Can create', + 'tickets.edit' => 'Can edit', + 'tickets.menu' => 'Menu shall be visualize', ]; diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 3b03dfa2..5a60b886 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -886,8 +886,8 @@ $routes->group('chat', ['namespace' => 'App\Controllers\Chat'], function ($route $routes->get('department/factura/(:num)/(:num)', 'ChatController::get_chat_factura/$1/$2', ['as' => 'getChatFactura']); $routes->get('department/(:num)/users', 'ChatController::get_chat_department_users/$1', ['as' => 'getChatDepartmentUsers']); - $routes->get('(:num)', 'ChatController::get_chat/$1', ['as' => 'getChat']); + $routes->post('message/error/presupuesto', 'ChatController::store_chat_error_message', ['as' => 'storeChatErrorMessage']); $routes->post('message/presupuesto', 'ChatController::store_chat_message_presupuesto', ['as' => 'storeChatMessagePresupuesto']); $routes->post('message/pedido', 'ChatController::store_chat_message_pedido', ['as' => 'storeChatMessagePedido']); $routes->post('message/factura', 'ChatController::store_chat_message_factura', ['as' => 'storeChatMessageFactura']); @@ -909,6 +909,27 @@ $routes->group('chat', ['namespace' => 'App\Controllers\Chat'], function ($route }); +$routes->group('messages', ['namespace' => 'App\Controllers\Chat'], function ($routes) { + $routes->get('datatable', 'ChatController::datatable_messages', ['as' => 'getDatatableMessages']); + $routes->get('datatable/presupuesto', 'ChatController::datatable_presupuesto_messages', ['as' => 'getDatatablePresupuestoMessages']); + $routes->get('datatable/pedido', 'ChatController::datatable_pedido_messages', ['as' => 'getDatatablePedidoMessages']); + $routes->get('datatable/factura', 'ChatController::datatable_factura_messages', ['as' => 'getDatatableFacturaMessages']); + + $routes->post('direct', 'ChatController::store_new_direct_message', ['as' => 'storeNewDirectMessage']); + $routes->post('direct/client', 'ChatController::store_new_direct_message_client', ['as' => 'storeNewDirectMessageClient']); +}); + + +$routes->group('soporte', ['namespace' => 'App\Controllers\Soporte'], function ($routes) { + $routes->get('', 'Ticketcontroller::index', ['as' => 'TicketIndex']); + $routes->get('add', 'Ticketcontroller::add', ['as' => 'NewTicket']); + $routes->post('add', 'Ticketcontroller::add', ['as' => 'createTicket']); + $routes->get('edit/(:num)', 'Ticketcontroller::edit/$1', ['as' => 'editTicket']); + $routes->post('edit/(:num)', 'Ticketcontroller::edit/$1', ['as' => 'updateTicket']); + $routes->post('ticketlist', 'Ticketcontroller::datatable'); + $routes->get('image/(:segment)', 'Ticketcontroller::image/$1'); +}); + $routes->group('produccion', ['namespace' => 'App\Controllers\Produccion'], function ($routes) { $routes->group('ordentrabajo', ['namespace' => 'App\Controllers\Produccion'], function ($routes) { @@ -949,7 +970,7 @@ $routes->group('produccion', ['namespace' => 'App\Controllers\Produccion'], func * -------------------------------------------------------------------- */ $routes->post('auth/jwt', '\App\Controllers\Sistema\AuthAPIController::jwtLogin'); - + $routes->group( 'api', [ @@ -963,13 +984,8 @@ $routes->group( 'filter' => 'cors' ]); - $routes->options('items', static function () { }); - $routes->options('items/(:any)', static function () { }); - $routes->post("calcular", 'ImprimelibrosApi::calcular'); - - - + $routes->post("guardar", 'ImprimelibrosApi::guardar'); // ... } ); diff --git a/ci4/app/Config/Services.php b/ci4/app/Config/Services.php index 8d209990..33330fa1 100755 --- a/ci4/app/Config/Services.php +++ b/ci4/app/Config/Services.php @@ -4,6 +4,7 @@ namespace Config; use App\Services\FTPService; use App\Services\MaquinaService; +use App\Services\MessageService; use App\Services\PapelImpresionService; use CodeIgniter\Config\BaseService; use App\Services\ProductionService; @@ -48,4 +49,8 @@ class Services extends BaseService { return new MaquinaService(); } + public static function messages() + { + return new MessageService(); + } } diff --git a/ci4/app/Controllers/API/ImprimelibrosApi.php b/ci4/app/Controllers/API/ImprimelibrosApi.php index d95bbdf0..aeff2713 100644 --- a/ci4/app/Controllers/API/ImprimelibrosApi.php +++ b/ci4/app/Controllers/API/ImprimelibrosApi.php @@ -25,111 +25,74 @@ class ImprimelibrosApi extends ResourceController { helper(['form']); + $jsonData = json_decode($this->request->getBody(), true); + + if (json_last_error() !== JSON_ERROR_NONE) { + return $this->respond( + [ + 'status' => 400, + 'error' => 'Invalid JSON format' + ], + 400 + ); + } + + + // Access the entire POST data + $post_data = $jsonData; + + //return $this->respond(var_dump($post_data)); + + // Instancia de presupuesto cliente + $presupuestocliente = new Presupuestocliente(); + $response = $presupuestocliente->calcular($post_data); + + if (isset($response['tiradas'])) { + + $response = [ + 'status' => 200, + 'error' => null, + 'data' => [ + 'tiradas' => $response['tiradas'], + 'precios' => $response['precio_u'] + ] + ]; + }else{ + $response = [ + 'status' => 400, + 'error' => $response + ]; + + } + return $this->respond($response); + } + + + public function guardar() + { + helper(['form']); + // Access the entire POST data $post_data = $this->request->getJSON(true); //return $this->respond(var_dump($post_data)); - $data_tmp = array - ( - 'clienteId' => 1870, - 'tamanio' => array - ( - 'ancho' => 170, - 'alto' => 240 - ), - 'tirada' => array - ( - '0' => 50, - '1' => 100, - - ), - 'paginas' => 320, - 'paginasColor' => 0, - 'pagColorConsecutivas' => 0, - 'papelInteriorDiferente' => 0, - 'paginasCuadernillo' => 32, - 'tipo' => 'cosido', - 'isColor' => 0, - 'isHq' => 0, - 'interior' => array - ( - 'papelInterior' => 3, - 'gramajeInterior' => 80 - ), - 'guardas' => array - ( - 'papel' => 'OFF1', - 'gramaje' => 170, - 'caras' => 8 - ), - 'posPaginasColor' => null, - 'prototipo' => 0, - 'ferro' => 0, - 'ferroDigital' => 0, - 'marcapaginas' => 0, - 'retractilado' => 0, - 'retractilado5' => 0, - 'eb' => 10.5, - 'cubierta' => array - ( - 'tipoCubierta' => 'tapaDura', - 'papelCubierta' => 2, - 'gramajeCubierta' => 170, - 'cabezada' => 'WHI', - 'acabado' => 1, - 'carasImpresion' => 2, - 'lomoRedondo' => 0, - 'solapas' => 0, - ), - 'sobrecubierta' => false, - 'faja' => false, - 'excluirRotativa' => 0, - 'ivaReducido' => 1, - 'servicios' => array - ( - 'prototipo' => 0, - 'ferro' => 0, - 'ferroDigital' => 0, - 'marcapaginas' => 0, - 'retractilado' => 0, - 'retractilado5' => 0 - ), - 'entrega_taller' => 1, - 'id' => 334 - ); - - // Crear el cliente HTTP - $client = \Config\Services::curlrequest(); - + // Instancia de presupuesto cliente $presupuestocliente = new Presupuestocliente(); - $response = $presupuestocliente->calcular($post_data); + $response = $presupuestocliente->guardar($post_data); + + return $this->respond($response); $response = [ 'status' => 200, 'error' => null, - 'messages' => [ - 'precio' => $response['precio_u'] + 'data' => [ + 'tiradas' => $response['tiradas'], + 'precios' => $response['precio_u'] ] ]; return $this->respond($response); } - public function delete($id = null) - { - $model = new ItemModel(); - $find = $model->find(['id' => $id]); - if (!$find) - return $this->failNotFound('No Data Found'); - $model->delete($id); - $response = [ - 'status' => 200, - 'error' => null, - 'messages' => [ - 'success' => 'Data deleted' - ] - ]; - return $this->respond($response); - } } diff --git a/ci4/app/Controllers/Chat/ChatController.php b/ci4/app/Controllers/Chat/ChatController.php index 854f562b..0be4e8ed 100644 --- a/ci4/app/Controllers/Chat/ChatController.php +++ b/ci4/app/Controllers/Chat/ChatController.php @@ -766,4 +766,11 @@ class ChatController extends BaseController $this->chatModel->setAsUnviewedChatUserNotifications($chat_id, auth()->user()->id); return $this->response->setJSON(["message" => "ok", "status" => true]); } + public function store_chat_error_message() + { + $bodyData = $this->request->getPost(); + $messageService = service('messages'); + $r = $messageService->createErrorMessagePresupuesto("Error",$bodyData['presupuesto_id']); + return $this->response->setJSON(["message" => "ok","data" => $r]); + } } diff --git a/ci4/app/Controllers/Configuracion/Papelesgenericos.php b/ci4/app/Controllers/Configuracion/Papelesgenericos.php index 82392fca..37e2ca7c 100755 --- a/ci4/app/Controllers/Configuracion/Papelesgenericos.php +++ b/ci4/app/Controllers/Configuracion/Papelesgenericos.php @@ -156,6 +156,9 @@ class Papelesgenericos extends \App\Controllers\BaseResourceController if ($this->request->getPost('show_in_client') == null) { $sanitizedData['show_in_client'] = false; } + if ($this->request->getPost('activo') == null) { + $sanitizedData['activo'] = false; + } if ($this->request->getPost('show_in_client_special') == null) { $sanitizedData['show_in_client_special'] = false; } @@ -163,6 +166,9 @@ class Papelesgenericos extends \App\Controllers\BaseResourceController if ($sanitizedData['show_in_client_special']) { $sanitizedData['show_in_client'] = true; } + if ($sanitizedData['activo']) { + $sanitizedData['activo'] = true; + } $noException = true; if ($successfulResult = $this->canValidate()): // if ($successfulResult = $this->validate($this->formValidationRules) ) : diff --git a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php index 9a9e3943..44432708 100644 --- a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php @@ -230,6 +230,9 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $sanitizedData['solapas_sobrecubierta'] = 0; } + $tipoImpresionModel = new TipoPresupuestoModel(); + $sanitizedData['cosido'] = $tipoImpresionModel->get_isCosido($sanitizedData['tipo_impresion_id']); + $noException = true; if ( $sanitizedData['papel_formato_id'] == null && $sanitizedData['papel_formato_ancho'] == null diff --git a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php index e6f14ce1..d1910537 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php @@ -18,6 +18,7 @@ use App\Models\Presupuestos\PresupuestoModel; use App\Models\Presupuestos\PresupuestoPreimpresionesModel; use App\Models\Presupuestos\PresupuestoServiciosExtraModel; use App\Models\Presupuestos\ErrorPresupuesto; +use App\Services\MessageService; use App\Services\PresupuestoClienteService; use App\Services\PresupuestoService; use Exception; @@ -42,7 +43,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController protected $indexRoute = 'listaPresupuestos'; - + protected MessageService $messageService; public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { @@ -61,6 +62,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController ['title' => lang("App.menu_presupuestos"), 'route' => "javascript:void(0);", 'active' => false], ['title' => "Listado", 'route' => site_url('presupuestocliente/list'), 'active' => true] ]; + $this->messageService = service('messages'); parent::initController($request, $response, $logger); $this->model = new PresupuestoModel(); @@ -441,7 +443,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController try { - $reqData = $this->request->getPost(); + //$reqData = $this->request->getPost(); $modelPapelGenerico = new PapelGenericoModel(); @@ -457,7 +459,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $tipo = $reqData['tipo']; $paginasCuadernillo = $reqData['paginasCuadernillo'] ?? null; - $papelInteriorDiferente = intval($reqData['papelInteriorDiferente']) ?? null; + $papelInteriorDiferente = intval($reqData['papelInteriorDiferente'] ?? null); $isColor = intval($reqData['isColor']) ?? 0; $isHq = intval($reqData['isHq']) ?? 0; @@ -927,483 +929,497 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController } } - public function guardar() + public function guardar($data = -1) { - if ($this->request->isAJAX()) { - $modelPapelGenerico = new PapelGenericoModel(); - - $reqData = $this->request->getPost(); - - $POD = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('POD')->value; - - $id = $reqData['id'] ?? 0; - $id = intval($id); - - $datosCabecera = $reqData['datosCabecera'] ?? []; - - - $confirmar = $reqData['confirmar'] ?? 0; - $confirmar = intval($confirmar); - - $cliente_id = $reqData['clienteId'] ?? -1; - - $tirada = $reqData['tirada'] ?? []; - $selected_tirada = $reqData['selectedTirada'] ?? 0; - $tamanio = $reqData['tamanio']; - $paginas = $reqData['paginas'] ?? 0; - $paginas_color = $reqData['paginasColor'] ?? 0; - - $envio_base = $reqData['eb'] ?? 0; - - $posPaginasColor = $reqData['posPaginasColor'] ?? ""; - $paginasColorConsecutivas = $reqData['pagColorConsecutivas'] ?? 0; - $papelInteriorDiferente = $reqData['papelInteriorDiferente'] ?? 0; - - $tipo = $reqData['tipo']; - - $paginasCuadernillo = $reqData['paginasCuadernillo'] ?? null; - $papelInteriorDiferente = intval($reqData['papelInteriorDiferente']) ?? null; - - $isColor = intval($reqData['isColor']) ?? 0; - $isHq = intval($reqData['isHq']) ?? 0; - - $prototipo = intval($reqData['prototipo']) ?? 0; - $ferro = intval($reqData['ferro']) ?? 0; - $ferroDigital = intval($reqData['ferroDigital']) ?? 0; - $marcapaginas = intval($reqData['marcapaginas']) ?? 0; - $retractilado = intval($reqData['retractilado']) ?? 0; - $retractilado5 = intval($reqData['retractilado5']) ?? 0; - - $interior = $reqData['interior'] ?? []; - $cubierta = $reqData['cubierta'] ?? []; - $sobrecubierta = $reqData['sobrecubierta'] ?? []; - $guardas = $reqData['guardas'] ?? []; - $faja = $reqData['faja'] ?? []; - $excluirRotativa = $reqData['excluirRotativa'] ?? 0; - $excluirRotativa = intval($excluirRotativa); - $ivaReducido = intval($reqData['ivaReducido']) ?? 0; - - $direcciones = $reqData['direcciones'] ?? []; - - $tipo_impresion_id = $this->getTipoImpresion($tipo, $cubierta['tipoCubierta']); - - if ($papelInteriorDiferente) { - $papel['negro'] = $modelPapelGenerico->where('id', $interior['papelInterior']['negro'])->first()->toArray(); - $papel['color'] = $modelPapelGenerico->where('id', $interior['papelInterior']['color'])->first()->toArray(); - $gramaje['negro'] = intval($interior['gramajeInterior']['negro']); - $gramaje['color'] = intval($interior['gramajeInterior']['color']); - } else { - $papel = $modelPapelGenerico->where('id', $interior['papelInterior'])->first()->toArray(); - $gramaje = intval($interior['gramajeInterior']); + if ($this->request) { + if ($this->request->isAJAX()) + $reqData = $this->request->getPost(); + } else { + if ($data == -1) { + return "Error: sin datos"; } - // Interior - $interior = [ - 'papel_generico' => $papel, - 'gramaje' => $gramaje, - 'excluirRotativa' => $excluirRotativa, - 'paginas' => $paginas, - 'paginas_color' => $paginas_color, - 'pos_paginas_color' => $posPaginasColor, - 'paginas_color_consecutivas' => $paginasColorConsecutivas, - 'papelInteriorDiferente' => $papelInteriorDiferente + $reqData = $data; + } + + $modelPapelGenerico = new PapelGenericoModel(); + + //$reqData = $this->request->getPost(); + + $POD = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('POD')->value; + + $id = $reqData['id'] ?? 0; + $id = intval($id); + + $datosCabecera = $reqData['datosCabecera'] ?? []; + + + $confirmar = $reqData['confirmar'] ?? 0; + $confirmar = intval($confirmar); + + $cliente_id = $reqData['clienteId'] ?? -1; + + $tirada = $reqData['tirada'] ?? []; + $selected_tirada = $reqData['selectedTirada'] ?? 0; + $tamanio = $reqData['tamanio']; + $paginas = $reqData['paginas'] ?? 0; + $paginas_color = $reqData['paginasColor'] ?? 0; + + $envio_base = $reqData['eb'] ?? 0; + + $posPaginasColor = $reqData['posPaginasColor'] ?? ""; + $paginasColorConsecutivas = $reqData['pagColorConsecutivas'] ?? 0; + $papelInteriorDiferente = $reqData['papelInteriorDiferente'] ?? 0; + + $tipo = $reqData['tipo']; + + $paginasCuadernillo = $reqData['paginasCuadernillo'] ?? 32; + $papelInteriorDiferente = intval($reqData['papelInteriorDiferente'] ?? null); + + $isColor = intval($reqData['isColor']) ?? 0; + $isHq = intval($reqData['isHq']) ?? 0; + + $prototipo = intval($reqData['prototipo'] ?? 0); + $ferro = intval($reqData['ferro'] ?? 0); + $ferroDigital = intval($reqData['ferroDigital'] ?? 0); + $marcapaginas = intval($reqData['marcapaginas'] ?? 0); + $retractilado = intval($reqData['retractilado'] ?? 0); + $retractilado5 = intval($reqData['retractilado5'] ?? 0); + + $interior = $reqData['interior'] ?? []; + $cubierta = $reqData['cubierta'] ?? []; + $sobrecubierta = $reqData['sobrecubierta'] ?? []; + $guardas = $reqData['guardas'] ?? []; + $faja = $reqData['faja'] ?? []; + $excluirRotativa = $reqData['excluirRotativa'] ?? 0; + $excluirRotativa = intval($excluirRotativa); + $ivaReducido = intval($reqData['ivaReducido'] ?? 0); + + $direcciones = $reqData['direcciones'] ?? []; + + $tipo_impresion_id = $this->getTipoImpresion($tipo, $cubierta['tipoCubierta']); + + if ($papelInteriorDiferente) { + $papel['negro'] = $modelPapelGenerico->where('id', $interior['papelInterior']['negro'])->first()->toArray(); + $papel['color'] = $modelPapelGenerico->where('id', $interior['papelInterior']['color'])->first()->toArray(); + $gramaje['negro'] = intval($interior['gramajeInterior']['negro']); + $gramaje['color'] = intval($interior['gramajeInterior']['color']); + } else { + $papel = $modelPapelGenerico->where('id', $interior['papelInterior'])->first()->toArray(); + $gramaje = intval($interior['gramajeInterior']); + } + // Interior + $interior = [ + 'papel_generico' => $papel, + 'gramaje' => $gramaje, + 'excluirRotativa' => $excluirRotativa, + 'paginas' => $paginas, + 'paginas_color' => $paginas_color, + 'pos_paginas_color' => $posPaginasColor, + 'paginas_color_consecutivas' => $paginasColorConsecutivas, + 'papelInteriorDiferente' => $papelInteriorDiferente + ]; + + + // Cubierta + $cubierta = [ + 'papel_generico_cubierta' => $modelPapelGenerico->where('id', $cubierta['papelCubierta'])->first()->toArray(), + 'gramajeCubierta' => intval($cubierta['gramajeCubierta']), + 'carasCubierta' => intval($cubierta['carasImpresion'] ?? 2), + 'solapasCubierta' => intval($cubierta['solapas'] ?? 0) == 1 ? intval($cubierta['tamanioSolapas']) : 0, + 'acabado' => $cubierta['acabado'] ?? 0, + 'lomoRedondo' => $cubierta['lomoRedondo'] ?? 0, + 'cabezada' => $cubierta['cabezada'] ?? 'WHI', + ]; + + // Sobrecubierta + if ($sobrecubierta != "false" && $sobrecubierta != null) { + $sobrecubierta = [ + 'papel' => $modelPapelGenerico->where('id', $sobrecubierta['papel'])->first()->toArray(), + 'gramaje' => intval($sobrecubierta['gramaje']), + 'solapas' => intval($sobrecubierta['solapas'] ?? 0), + 'acabado' => $sobrecubierta['acabado'] ?? 0, ]; + } else + $sobrecubierta = false; - - // Cubierta - $cubierta = [ - 'papel_generico_cubierta' => $modelPapelGenerico->where('id', $cubierta['papelCubierta'])->first()->toArray(), - 'gramajeCubierta' => intval($cubierta['gramajeCubierta']), - 'carasCubierta' => intval($cubierta['carasImpresion'] ?? 0), - 'solapasCubierta' => intval($cubierta['solapas'] ?? 0) == 1 ? intval($cubierta['tamanioSolapas']) : 0, - 'acabado' => $cubierta['acabado'] ?? 0, - 'lomoRedondo' => $cubierta['lomoRedondo'] ?? 0, - 'cabezada' => $cubierta['cabezada'] ?? 'WHI', + // Guardas + if ($guardas != "false" && $guardas != null) { + $datos_guardas = [ + 'papel' => $modelPapelGenerico->where('id', $guardas['papel'])->first()->toArray(), + 'gramaje' => intval($guardas['gramaje']), + 'caras' => intval($guardas['caras']), ]; + } else + $datos_guardas = false; - // Sobrecubierta - if ($sobrecubierta != "false" && $sobrecubierta != null) { - $sobrecubierta = [ - 'papel' => $modelPapelGenerico->where('id', $sobrecubierta['papel'])->first()->toArray(), - 'gramaje' => intval($sobrecubierta['gramaje']), - 'solapas' => intval($sobrecubierta['solapas'] ?? 0), - 'acabado' => $sobrecubierta['acabado'] ?? 0, - ]; - } else - $sobrecubierta = false; + $datos_presupuesto = array( + 'tirada' => $tirada, + 'tamanio' => $tamanio, + 'tipo_impresion_id' => $tipo_impresion_id, + 'clienteId' => $cliente_id, + 'isColor' => $isColor, + 'isHq' => $isHq, + 'paginasCuadernillo' => $paginasCuadernillo, - // Guardas - if ($guardas != "false" && $guardas != null) { - $datos_guardas = [ - 'papel' => $modelPapelGenerico->where('id', $guardas['papel'])->first()->toArray(), - 'gramaje' => intval($guardas['gramaje']), - 'caras' => intval($guardas['caras']), - ]; - } else - $datos_guardas = false; + 'interior' => $interior, + 'cubierta' => $cubierta, + 'sobrecubierta' => $sobrecubierta, + 'datos_guardas' => $datos_guardas, + 'faja' => $faja, - $datos_presupuesto = array( - 'tirada' => $tirada, - 'tamanio' => $tamanio, - 'tipo_impresion_id' => $tipo_impresion_id, - 'clienteId' => $cliente_id, - 'isColor' => $isColor, - 'isHq' => $isHq, - 'paginasCuadernillo' => $paginasCuadernillo, + 'servicios' => $reqData['servicios'] ?? [], + ); - 'interior' => $interior, - 'cubierta' => $cubierta, - 'sobrecubierta' => $sobrecubierta, - 'datos_guardas' => $datos_guardas, - 'faja' => $faja, + $datos_presupuesto['id'] = $id; - 'servicios' => $reqData['servicios'] ?? [], + $resultado_presupuesto = $this->calcular_presupuesto($datos_presupuesto, $selected_tirada, true); + + if (isset($resultado_presupuesto['errors'])) { + $errors = $resultado_presupuesto['errors']; + foreach ($errors as $error) { + if (!empty($error)) { + return $this->respond([ + 'error' => $error, + ]); + } + } + } else if (isset($resultado_presupuesto['exception'])) { + return $this->respond([ + 'error' => $resultado_presupuesto['exception'], + 'file' => $resultado_presupuesto['file'], + 'line' => $resultado_presupuesto['line'], + ]); + } + + // seleccionamos el peso de la tirada seleccionada + $peso_libro = $resultado_presupuesto['peso'][array_search($selected_tirada, $tirada)]; + + // calculo del envio base (tirada_maxima) + $resultado_presupuesto['eb'] = []; + $datos_presupuesto['envio_base'] = 0; + for ($i = 0; $i < count($tirada); $i++) { + $direccion = []; + $coste_direccion = $this->getCosteEnvio( + $direccion, + $resultado_presupuesto['peso'][$i], + $tirada[$i], + false, + true ); - $datos_presupuesto['id'] = $id; - - $resultado_presupuesto = $this->calcular_presupuesto($datos_presupuesto, $selected_tirada, true); - - if (isset($resultado_presupuesto['errors'])) { - $errors = $resultado_presupuesto['errors']; - foreach ($errors as $error) { - if (!empty($error)) { - return $this->respond([ - 'error' => $error, - ]); - } - } - } else if (isset($resultado_presupuesto['exception'])) { - return $this->respond([ - 'error' => $resultado_presupuesto['exception'], - 'file' => $resultado_presupuesto['file'], - 'line' => $resultado_presupuesto['line'], - ]); + if (intval($selected_tirada) == intval($tirada[$i])) { + $datos_presupuesto['envio_base'] = round($coste_direccion->coste * (1 + $coste_direccion->margen / 100.0), 2); } - // seleccionamos el peso de la tirada seleccionada - $peso_libro = $resultado_presupuesto['peso'][array_search($selected_tirada, $tirada)]; - - // calculo del envio base (tirada_maxima) - $resultado_presupuesto['eb'] = []; - $datos_presupuesto['envio_base'] = 0; - for ($i = 0; $i < count($tirada); $i++) { - $direccion = []; - $coste_direccion = $this->getCosteEnvio( - $direccion, - $resultado_presupuesto['peso'][$i], - $tirada[$i], - false, - true + if (!property_exists($coste_direccion, 'coste')) { + $errorModel = new ErrorPresupuesto(); + $data['direccion'] = 'Sin direccion'; + $data['peso'] = $resultado_presupuesto['peso'][$i]; + $data['palets'] = 'Sin direccion'; + $errorModel->insertError( + $id, + auth()->user()->id, + 'No se ha podido calcular el coste de envío', + $data ); - - if (intval($selected_tirada) == intval($tirada[$i])) { - $datos_presupuesto['envio_base'] = round($coste_direccion->coste * (1 + $coste_direccion->margen / 100.0), 2); - } - - if (!property_exists($coste_direccion, 'coste')) { - $errorModel = new ErrorPresupuesto(); - $data['direccion'] = 'Sin direccion'; - $data['peso'] = $resultado_presupuesto['peso'][$i]; - $data['palets'] = 'Sin direccion'; - $errorModel->insertError( - $id, - auth()->user()->id, - 'No se ha podido calcular el coste de envío', - $data - ); - $resultado_presupuesto = [ - 'errors' => (object) ([ - 'status' => 1 - ]), - ]; - return $resultado_presupuesto; - } else { - $resultado_presupuesto['eb'][$i] = round($coste_direccion->coste, 2); - $resultado_presupuesto['eb_margen'][$i] = round($coste_direccion->margen, 2); - } - } - - - for ($i = 0; $i < count($tirada); $i++) { - - $resultado_presupuesto['info']['totales'][$i]['coste_envio'] = 0.0; - $resultado_presupuesto['info']['totales'][$i]['margen_envio'] = 0.0; - } - if (count($direcciones) > 0) { - - for ($i = 0; $i < count($tirada); $i++) { - - $envio_base = true; - $coste_envio = 0.0; - $margen_envio = 0.0; - foreach ($direcciones as $direccion) { - // El primer envio no se calcula ya que se añade el base - if ($envio_base) { - //aporte del envio al precio unidad - $coste_envio += ($resultado_presupuesto['eb'][$i] / $tirada[$i]); - $margen_envio += ($resultado_presupuesto['eb_margen'][$i] / $tirada[$i]); - $resultado_presupuesto['info']['totales'][$i]['coste_envio'] += $resultado_presupuesto['eb'][$i] - $resultado_presupuesto['eb_margen'][$i]; - $resultado_presupuesto['info']['totales'][$i]['margen_envio'] += $resultado_presupuesto['eb_margen'][$i]; - $envio_base = false; - continue; - } - - $unidades = floor($direccion['unidades'] * $tirada[$i] / $selected_tirada); - $coste_direccion = $this->getCosteEnvio( - $direccion['direccion'], - $resultado_presupuesto['peso'][$i], - $unidades, - $direccion['entregaPalets'] == 'true' ? 1 : 0, - false, - ); - - if (!property_exists($coste_direccion, 'coste')) { - - $errorModel = new ErrorPresupuesto(); - $data['direccion'] = $direccion; - $data['peso'] = $resultado_presupuesto['peso'][$i]; - $data['palets'] = $direccion['entregaPalets'] == 'true' ? 1 : 0; - $errorModel->insertError( - $id, - auth()->user()->id, - 'No se ha podido calcular el coste de envío', - $data - ); - $resultado_presupuesto = [ - 'errors' => (object) ([ - 'status' => 1 - ]), - ]; - return $resultado_presupuesto; - } else { - //aporte del envio al precio unidad - $coste_envio += ($coste_direccion->coste / $tirada[$i]); - $resultado_presupuesto['info']['totales'][$i]['coste_envio'] += $coste_direccion->coste - $coste_direccion->margen; - $resultado_presupuesto['info']['totales'][$i]['margen_envio'] += $coste_direccion->margen; - - } - } - $resultado_presupuesto['precio_u'][$i] = round(floatval($resultado_presupuesto['precio_u'][$i]) + $coste_envio, 4); - } + $resultado_presupuesto = [ + 'errors' => (object) ([ + 'status' => 1 + ]), + ]; + return $resultado_presupuesto; } else { - for ($i = 0; $i < count($tirada); $i++) { - $coste_envio = 0.0; - $coste_envio += ($resultado_presupuesto['eb'][$i] / $tirada[$i]); - $resultado_presupuesto['info']['totales'][$i]['coste_envio'] = $resultado_presupuesto['eb'][$i] - $resultado_presupuesto['eb_margen'][$i]; - $resultado_presupuesto['info']['totales'][$i]['margen_envio'] = $resultado_presupuesto['eb_margen'][$i]; - $resultado_presupuesto['precio_u'][$i] = round(floatval($resultado_presupuesto['precio_u'][$i]) + $coste_envio, 4); - } + $resultado_presupuesto['eb'][$i] = round($coste_direccion->coste, 2); + $resultado_presupuesto['eb_margen'][$i] = round($coste_direccion->margen, 2); } + } - $model_presupuesto = new PresupuestoModel(); - $tiradas_alternativas = []; - $resumen_totales = []; + for ($i = 0; $i < count($tirada); $i++) { + + $resultado_presupuesto['info']['totales'][$i]['coste_envio'] = 0.0; + $resultado_presupuesto['info']['totales'][$i]['margen_envio'] = 0.0; + } + if (count($direcciones) > 0) { for ($i = 0; $i < count($tirada); $i++) { - if ($tirada[$i] != $selected_tirada) { + $envio_base = true; + $coste_envio = 0.0; + $margen_envio = 0.0; + foreach ($direcciones as $direccion) { + // El primer envio no se calcula ya que se añade el base + if ($envio_base) { + //aporte del envio al precio unidad + $coste_envio += ($resultado_presupuesto['eb'][$i] / $tirada[$i]); + $margen_envio += ($resultado_presupuesto['eb_margen'][$i] / $tirada[$i]); + $resultado_presupuesto['info']['totales'][$i]['coste_envio'] += $resultado_presupuesto['eb'][$i] - $resultado_presupuesto['eb_margen'][$i]; + $resultado_presupuesto['info']['totales'][$i]['margen_envio'] += $resultado_presupuesto['eb_margen'][$i]; + $envio_base = false; + continue; + } - $coste_total = $resultado_presupuesto['info']['totales'][$i]['totalImpresion'] + $resultado_presupuesto['info']['totales'][$i]['totalPapel'] + - $resultado_presupuesto['info']['totales'][$i]['margenImpresion'] + $resultado_presupuesto['info']['totales'][$i]['margenPapel']; - $coste_envio = $resultado_presupuesto['info']['totales'][$i]['coste_envio'] + $resultado_presupuesto['info']['totales'][$i]['margen_envio']; - $margen_total = round(($resultado_presupuesto['info']['totales'][$i]['margenImpresion'] + - $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(($coste_total + $resultado_presupuesto['info']['totales'][$i]['totalServicios'] + $resultado_presupuesto['info']['totales'][$i]['margenServicios'] + $coste_envio) / $tirada[$i], 4); + $unidades = floor($direccion['unidades'] * $tirada[$i] / $selected_tirada); + $coste_direccion = $this->getCosteEnvio( + $direccion['direccion'], + $resultado_presupuesto['peso'][$i], + $unidades, + $direccion['entregaPalets'] == 'true' ? 1 : 0, + false, + ); - array_push($tiradas_alternativas, (object) array( - 'tirada' => $tirada[$i], - 'coste_impresion' => round($coste_total, 2), - 'coste_envio' => $coste_envio, - 'margen' => $margen_total, - 'total_pedido' => $total_pedido, - 'precio_unidad' => $precio_u, - )); - } else { - $resumen_totales = $resultado_presupuesto['info']['totales'][$i]; - } - } + if (!property_exists($coste_direccion, 'coste')) { - $borrar_antes = false; - if ($id != 0) { - $borrar_antes = true; - } + $errorModel = new ErrorPresupuesto(); + $data['direccion'] = $direccion; + $data['peso'] = $resultado_presupuesto['peso'][$i]; + $data['palets'] = $direccion['entregaPalets'] == 'true' ? 1 : 0; + $errorModel->insertError( + $id, + auth()->user()->id, + 'No se ha podido calcular el coste de envío', + $data + ); + $resultado_presupuesto = [ + 'errors' => (object) ([ + 'status' => 1 + ]), + ]; + return $resultado_presupuesto; + } else { + //aporte del envio al precio unidad + $coste_envio += ($coste_direccion->coste / $tirada[$i]); + $resultado_presupuesto['info']['totales'][$i]['coste_envio'] += $coste_direccion->coste - $coste_direccion->margen; + $resultado_presupuesto['info']['totales'][$i]['margen_envio'] += $coste_direccion->margen; - $datos_presupuesto['prototipo'] = $prototipo; - $datos_presupuesto['ferro'] = $ferro; - $datos_presupuesto['ferro_digital'] = $ferroDigital; - $datos_presupuesto['marcapaginas'] = $marcapaginas; - $datos_presupuesto['retractilado'] = $retractilado; - $datos_presupuesto['retractilado5'] = $retractilado5; - $datos_presupuesto['entrega_taller'] = $reqData['entrega_taller'] ?? 0; - - - $resultado_presupuesto['info']['merma'] = $this->calcular_merma($selected_tirada, $POD); - - $datos_presupuesto['faja'] = $faja; - - $id = $model_presupuesto->insertarPresupuestoCliente( - $id, - $selected_tirada, - $datos_presupuesto, - $datosCabecera, - $resultado_presupuesto['info'], - $resumen_totales, - $ivaReducido, - $excluirRotativa, - $tiradas_alternativas - ); - - // Lineas Presupuesto - if ($borrar_antes && $id > 0) { - $this->borrarRelacionesPresupuesto($id); - } - - foreach ($resultado_presupuesto['values']['interior'] as $linea) { - - if (count($linea) > 0) - $this->guardarLineaPresupuesto($id, $linea); - } - if (count($resultado_presupuesto['values']['cubierta']) > 0) - $this->guardarLineaPresupuesto($id, $resultado_presupuesto['values']['cubierta']); - if (count($resultado_presupuesto['values']['sobrecubierta']) > 0) - $this->guardarLineaPresupuesto($id, $resultado_presupuesto['values']['sobrecubierta']); - if (count($resultado_presupuesto['values']['faja']) > 0) - $this->guardarLineaPresupuesto($id, $resultado_presupuesto['values']['faja']); - if (count($resultado_presupuesto['values']['guardas']) > 0) - $this->guardarLineaPresupuesto($id, $resultado_presupuesto['values']['guardas']); - - // Servicios - if ($sobrecubierta) { - if (intval($sobrecubierta['acabado']) > 0) { - $model = model('App\Models\Presupuestos\PresupuestoAcabadosModel'); - $servicio = $model->getPrecioTarifa(intval($sobrecubierta['acabado']), intval($selected_tirada), -1, $POD); - - if (count($servicio) > 0) { - if ($servicio[0]->total > 0) { - $this->guardarServicio($id, $servicio[0], 'acabado', false, true); - } } } + $resultado_presupuesto['precio_u'][$i] = round(floatval($resultado_presupuesto['precio_u'][$i]) + $coste_envio, 4); } - if (intval($cubierta['acabado']) > 0) { + } else { + for ($i = 0; $i < count($tirada); $i++) { + $coste_envio = 0.0; + $coste_envio += ($resultado_presupuesto['eb'][$i] / $tirada[$i]); + $resultado_presupuesto['info']['totales'][$i]['coste_envio'] = $resultado_presupuesto['eb'][$i] - $resultado_presupuesto['eb_margen'][$i]; + $resultado_presupuesto['info']['totales'][$i]['margen_envio'] = $resultado_presupuesto['eb_margen'][$i]; + $resultado_presupuesto['precio_u'][$i] = round(floatval($resultado_presupuesto['precio_u'][$i]) + $coste_envio, 4); + } + } + + + $model_presupuesto = new PresupuestoModel(); + $tiradas_alternativas = []; + $resumen_totales = []; + + for ($i = 0; $i < count($tirada); $i++) { + + if ($tirada[$i] != $selected_tirada) { + + $coste_total = $resultado_presupuesto['info']['totales'][$i]['totalImpresion'] + $resultado_presupuesto['info']['totales'][$i]['totalPapel'] + + $resultado_presupuesto['info']['totales'][$i]['margenImpresion'] + $resultado_presupuesto['info']['totales'][$i]['margenPapel']; + $coste_envio = $resultado_presupuesto['info']['totales'][$i]['coste_envio'] + $resultado_presupuesto['info']['totales'][$i]['margen_envio']; + $margen_total = round(($resultado_presupuesto['info']['totales'][$i]['margenImpresion'] + + $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(($coste_total + $resultado_presupuesto['info']['totales'][$i]['totalServicios'] + $resultado_presupuesto['info']['totales'][$i]['margenServicios'] + $coste_envio) / $tirada[$i], 4); + + array_push($tiradas_alternativas, (object) array( + 'tirada' => $tirada[$i], + 'coste_impresion' => round($coste_total, 2), + 'coste_envio' => $coste_envio, + 'margen' => $margen_total, + 'total_pedido' => $total_pedido, + 'precio_unidad' => $precio_u, + )); + } else { + $resumen_totales = $resultado_presupuesto['info']['totales'][$i]; + } + } + + $borrar_antes = false; + if ($id != 0) { + $borrar_antes = true; + } + + $datos_presupuesto['prototipo'] = $prototipo; + $datos_presupuesto['ferro'] = $ferro; + $datos_presupuesto['ferro_digital'] = $ferroDigital; + $datos_presupuesto['marcapaginas'] = $marcapaginas; + $datos_presupuesto['retractilado'] = $retractilado; + $datos_presupuesto['retractilado5'] = $retractilado5; + $datos_presupuesto['entrega_taller'] = $reqData['entrega_taller'] ?? 0; + + + $resultado_presupuesto['info']['merma'] = $this->calcular_merma($selected_tirada, $POD); + + $datos_presupuesto['faja'] = $faja; + + $id = $model_presupuesto->insertarPresupuestoCliente( + $id, + $selected_tirada, + $datos_presupuesto, + $datosCabecera, + $resultado_presupuesto['info'], + $resumen_totales, + $ivaReducido, + $excluirRotativa, + $tiradas_alternativas + ); + + // Lineas Presupuesto + if ($borrar_antes && $id > 0) { + $this->borrarRelacionesPresupuesto($id); + } + + foreach ($resultado_presupuesto['values']['interior'] as $linea) { + + if (count($linea) > 0) + $this->guardarLineaPresupuesto($id, $linea); + } + if (count($resultado_presupuesto['values']['cubierta']) > 0) + $this->guardarLineaPresupuesto($id, $resultado_presupuesto['values']['cubierta']); + if (count($resultado_presupuesto['values']['sobrecubierta']) > 0) + $this->guardarLineaPresupuesto($id, $resultado_presupuesto['values']['sobrecubierta']); + if (count($resultado_presupuesto['values']['faja']) > 0) + $this->guardarLineaPresupuesto($id, $resultado_presupuesto['values']['faja']); + if (count($resultado_presupuesto['values']['guardas']) > 0) + $this->guardarLineaPresupuesto($id, $resultado_presupuesto['values']['guardas']); + + // Servicios + if ($sobrecubierta) { + if (intval($sobrecubierta['acabado']) > 0) { $model = model('App\Models\Presupuestos\PresupuestoAcabadosModel'); - $servicio = $model->getPrecioTarifa(intval($cubierta['acabado']), intval($selected_tirada), -1, $POD); + $servicio = $model->getPrecioTarifa(intval($sobrecubierta['acabado']), intval($selected_tirada), -1, $POD); if (count($servicio) > 0) { if ($servicio[0]->total > 0) { - $this->guardarServicio($id, $servicio[0], 'acabado', true, false); + $this->guardarServicio($id, $servicio[0], 'acabado', false, true); } } - } - if (is_array($faja) && intval($faja['acabado']) > 0) { - $model = model('App\Models\Presupuestos\PresupuestoAcabadosModel'); - $servicio = $model->getPrecioTarifa(intval($faja['acabado']), intval($selected_tirada), -1, $POD); + } + if (intval($cubierta['acabado']) > 0) { + $model = model('App\Models\Presupuestos\PresupuestoAcabadosModel'); + $servicio = $model->getPrecioTarifa(intval($cubierta['acabado']), intval($selected_tirada), -1, $POD); - if (count($servicio) > 0) { - if ($servicio[0]->total > 0) { - $this->guardarServicio($id, $servicio[0], 'acabado', false, false, true); - } + if (count($servicio) > 0) { + if ($servicio[0]->total > 0) { + $this->guardarServicio($id, $servicio[0], 'acabado', true, false); } + } + } + if (is_array($faja) && $faja !== [] && intval($faja['acabado']) > 0) { + $model = model('App\Models\Presupuestos\PresupuestoAcabadosModel'); + $servicio = $model->getPrecioTarifa(intval($faja['acabado']), intval($selected_tirada), -1, $POD); + + if (count($servicio) > 0) { + if ($servicio[0]->total > 0) { + $this->guardarServicio($id, $servicio[0], 'acabado', false, false, true); + } } - foreach ($resultado_presupuesto['values']['serviciosDefecto']['encuadernacion'] as $servicio) { - $this->guardarServicio($id, $servicio, 'encuadernacion'); - } - foreach ($resultado_presupuesto['values']['serviciosDefecto']['manipulado'] as $servicio) { + + } + foreach ($resultado_presupuesto['values']['serviciosDefecto']['encuadernacion'] as $servicio) { + $this->guardarServicio($id, $servicio, 'encuadernacion'); + } + foreach ($resultado_presupuesto['values']['serviciosDefecto']['manipulado'] as $servicio) { + $this->guardarServicio($id, $servicio, 'manipulado'); + } + $servicio_ferro = (object) [ + 'nombre' => 'ferro', + 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_ferro')->value + ]; + $servicio_prototipo = (object) [ + 'nombre' => 'prototipo', + 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_prototipo')->value + ]; + $servicio_retractilado = (object) [ + 'nombre' => 'retractilado', + 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_retractilado')->value + ]; + $servicio_retractilado5 = (object) [ + 'nombre' => 'retractilado5', + 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_retractilado5')->value + ]; + $servicio_plegado_guardas = (object) [ + 'nombre' => 'plegado_guardas', + 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_plegado_guardas')->value + ]; + $servicio_solapas_cubierta = (object) [ + 'nombre' => 'solapas_cubierta', + 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('servicio_solapas_cubierta')->value + ]; + $servicio_solapas_sobrecubierta = (object) [ + 'nombre' => 'solapas_sobrecubierta', + 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('servicio_solapas_sobrecubierta')->value + ]; + $servicio_solapas_faja = (object) [ + 'nombre' => 'solapas_faja', + 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('servicio_solapas_faja')->value + ]; + $servicio_solapas_grandes_cubierta = (object) [ + 'nombre' => 'solapas_grandes_cubierta', + 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_plegado_exceso_solapas_cubierta')->value + ]; + $servicio_solapas_grandes_sobrecubierta = (object) [ + 'nombre' => 'solapas_grandes_sobrecubierta', + 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_plegado_exceso_solapas_sobrecubierta')->value + ]; + $servicio_solapas_grandes_faja = (object) [ + 'nombre' => 'solapas_grandes_faja', + 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_plegado_exceso_solapas_faja')->value + ]; + + foreach ($resultado_presupuesto['values']['servicios_automaticos'] as $servicio) { + if ($servicio->tarifa_id == $servicio_retractilado->id || $servicio->tarifa_id == $servicio_retractilado5->id) { + // Servicios acabado + $this->guardarServicio($id, $servicio, 'acabado'); + } else if ($servicio->tarifa_id == $servicio_ferro->id || $servicio->tarifa_id == $servicio_prototipo->id) { + // Servicios extra + $this->guardarServicio($id, $servicio, 'extra'); + } else if ($servicio->tarifa_id == $servicio_plegado_guardas->id) { + // Servicios manipulado + $this->guardarServicio($id, $servicio, 'manipulado'); + } else if ( + $servicio->tarifa_id == $servicio_solapas_cubierta->id || + $servicio->tarifa_id == $servicio_solapas_sobrecubierta->id || + $servicio->tarifa_id == $servicio_solapas_faja->id || + $servicio->tarifa_id == $servicio_solapas_grandes_cubierta->id || + $servicio->tarifa_id == $servicio_solapas_grandes_sobrecubierta->id || + $servicio->tarifa_id == $servicio_solapas_grandes_faja->id + ) { + // Servicios manipulado $this->guardarServicio($id, $servicio, 'manipulado'); } - $servicio_ferro = (object) [ - 'nombre' => 'ferro', - 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_ferro')->value - ]; - $servicio_prototipo = (object) [ - 'nombre' => 'prototipo', - 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_prototipo')->value - ]; - $servicio_retractilado = (object) [ - 'nombre' => 'retractilado', - 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_retractilado')->value - ]; - $servicio_retractilado5 = (object) [ - 'nombre' => 'retractilado5', - 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_retractilado5')->value - ]; - $servicio_plegado_guardas = (object) [ - 'nombre' => 'plegado_guardas', - 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_plegado_guardas')->value - ]; - $servicio_solapas_cubierta = (object) [ - 'nombre' => 'solapas_cubierta', - 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('servicio_solapas_cubierta')->value - ]; - $servicio_solapas_sobrecubierta = (object) [ - 'nombre' => 'solapas_sobrecubierta', - 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('servicio_solapas_sobrecubierta')->value - ]; - $servicio_solapas_faja = (object) [ - 'nombre' => 'solapas_faja', - 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('servicio_solapas_faja')->value - ]; - $servicio_solapas_grandes_cubierta = (object) [ - 'nombre' => 'solapas_grandes_cubierta', - 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_plegado_exceso_solapas_cubierta')->value - ]; - $servicio_solapas_grandes_sobrecubierta = (object) [ - 'nombre' => 'solapas_grandes_sobrecubierta', - 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_plegado_exceso_solapas_sobrecubierta')->value - ]; - $servicio_solapas_grandes_faja = (object) [ - 'nombre' => 'solapas_grandes_faja', - 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_plegado_exceso_solapas_faja')->value - ]; + } - foreach ($resultado_presupuesto['values']['servicios_automaticos'] as $servicio) { - if ($servicio->tarifa_id == $servicio_retractilado->id || $servicio->tarifa_id == $servicio_retractilado5->id) { - // Servicios acabado - $this->guardarServicio($id, $servicio, 'acabado'); - } else if ($servicio->tarifa_id == $servicio_ferro->id || $servicio->tarifa_id == $servicio_prototipo->id) { - // Servicios extra - $this->guardarServicio($id, $servicio, 'extra'); - } else if ($servicio->tarifa_id == $servicio_plegado_guardas->id) { - // Servicios manipulado - $this->guardarServicio($id, $servicio, 'manipulado'); - } else if ( - $servicio->tarifa_id == $servicio_solapas_cubierta->id || - $servicio->tarifa_id == $servicio_solapas_sobrecubierta->id || - $servicio->tarifa_id == $servicio_solapas_faja->id || - $servicio->tarifa_id == $servicio_solapas_grandes_cubierta->id || - $servicio->tarifa_id == $servicio_solapas_grandes_sobrecubierta->id || - $servicio->tarifa_id == $servicio_solapas_grandes_faja->id - ) { - // Servicios manipulado - $this->guardarServicio($id, $servicio, 'manipulado'); - } + if (array_key_exists('direcciones', $reqData)) { + + foreach ($reqData['direcciones'] as $direccion) { + $this->guardarLineaEnvio($id, $direccion, $peso_libro); } + } - if (array_key_exists('direcciones', $reqData)) { + if ($confirmar) { + $model_presupuesto->confirmarPresupuesto($id); + PresupuestoService::crearPedido($id); + } - foreach ($reqData['direcciones'] as $direccion) { - $this->guardarLineaEnvio($id, $direccion, $peso_libro); - } - } - - if ($confirmar) { - $model_presupuesto->confirmarPresupuesto($id); - PresupuestoService::crearPedido($id); - } + if ($this->request) { return $this->respond([ 'status' => $id, 'url' => site_url('presupuestos/presupuestocliente/edit'), 'message' => lang('Basic.global.saveSuccess', [lang('Basic.global.record')]), ]); - } else { - return $this->failUnauthorized('Invalid request', 403); + }else{ + return [ + 'sk_id' => $id, + 'sk_url' => site_url('presupuestos/presupuestocliente/edit/' . $id) + ]; } } @@ -2134,7 +2150,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 / $datosPedido->tirada), 2) * $datosPedido->tirada; $margenServicios += round(floatval($acabadoCubierta[0]->total - $base), 2); } } @@ -2225,7 +2241,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 / $datosPedido->tirada), 2) * $datosPedido->tirada; $margenServicios += round(floatval($acabadoSobrecubierta[0]->total - $base), 2); } } @@ -2378,7 +2394,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 / $datosPedido->tirada), 2) * $datosPedido->tirada; $margenServicios += round(floatval($acabadoFaja[0]->total - $base), 2); } } @@ -2432,8 +2448,8 @@ 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; - $margenServicios += round(floatval($servicio->total -$base), 2); + $base = round(floatval($base / $datosPedido->tirada), 2) * $datosPedido->tirada; + $margenServicios += round(floatval($servicio->total - $base), 2); } } @@ -2469,8 +2485,8 @@ 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; - $margenServicios += round(floatval($servicio->total -$base), 2); + $base = round(floatval($base / $datosPedido->tirada), 2) * $datosPedido->tirada; + $margenServicios += round(floatval($servicio->total - $base), 2); } } @@ -2527,7 +2543,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_plegado_exceso_solapas_faja')->value ]; - // se comprueba si $datos guardas es un array + // se comprueba si $datos guardas es un array if (is_array($datos_guardas)) { if (count($datos_guardas) > 0) { array_push($servicios, $servicio_plegado_guardas); // Plegado de guardas @@ -2538,20 +2554,23 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController } } - if ($datos_entrada['servicios']['retractilado']) // acabado - array_push($servicios, $servicio_retractilado); - if ($datos_entrada['servicios']['retractilado5']) // acabado - array_push($servicios, $servicio_retractilado5); - if ($datos_entrada['servicios']['prototipo']) // extra - array_push($servicios, $servicio_prototipo); - if ($datos_entrada['servicios']['ferro']) // extra - array_push($servicios, $servicio_ferro); - if ($solapasCubierta > 0) - array_push($servicios, $servicio_solapas_cubierta); - if (!is_null($sobreCubierta) && $sobreCubierta) // Si hay sobrecubierta, siempre con solapas - array_push($servicios, $servicio_solapas_sobrecubierta); - if (!is_null($faja) && $faja && $faja != false) // Si hay faja, siempre con solapas - array_push($servicios, $servicio_solapas_faja); + if ($datos_entrada['servicios'] !== []) { + + if ($datos_entrada['servicios']['retractilado']) // acabado + array_push($servicios, $servicio_retractilado); + if ($datos_entrada['servicios']['retractilado5']) // acabado + array_push($servicios, $servicio_retractilado5); + if ($datos_entrada['servicios']['prototipo']) // extra + array_push($servicios, $servicio_prototipo); + if ($datos_entrada['servicios']['ferro']) // extra + array_push($servicios, $servicio_ferro); + if ($solapasCubierta > 0) + array_push($servicios, $servicio_solapas_cubierta); + if (!is_null($sobreCubierta) && $sobreCubierta) // Si hay sobrecubierta, siempre con solapas + array_push($servicios, $servicio_solapas_sobrecubierta); + if (!is_null($faja) && $faja && $faja != false) // Si hay faja, siempre con solapas + array_push($servicios, $servicio_solapas_faja); + } foreach ($servicios as $servicio) { @@ -2586,7 +2605,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 / $datosPedido->tirada), 2) * $datosPedido->tirada; $margenServicios += round(floatval($resultado[0]->total - $base), 2); } } else if ($servicio->nombre == "ferro" || $servicio->nombre == "prototipo") { @@ -2618,7 +2637,7 @@ 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 / $datosPedido->tirada), 2) * $datosPedido->tirada; $margenServicios += round(floatval($resultado[0]->total - $base), 2); } } else if ($servicio->nombre == 'solapas_cubierta' || $servicio->nombre == 'solapas_sobrecubierta' || $servicio->nombre == 'solapas_faja') { @@ -2652,7 +2671,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 / $datosPedido->tirada), 2) * $datosPedido->tirada; $margenServicios += round(floatval($resultado[0]->total - $base), 2); } } @@ -2690,7 +2709,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 / $datosPedido->tirada), 2) * $datosPedido->tirada; $margenServicios += round(floatval($resultado[0]->total - $base), 2); } } @@ -2727,12 +2746,12 @@ 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 / $datosPedido->tirada), 2) * $datosPedido->tirada; $margenServicios += round(floatval($resultado[0]->total - $base), 2); } } - if (is_array($faja) && ($faja['solapas'] > 0 && intval($linea_faja['dimension_desarrollo']['ancho']) > 630)) { + if (is_array($faja) && $faja !== [] && ($faja['solapas'] > 0 && intval($linea_faja['dimension_desarrollo']['ancho']) > 630)) { // Servicios manipulado $resultado = PresupuestoCLienteService::getServiciosManipulado([ @@ -2764,7 +2783,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 / $datosPedido->tirada), 2) * $datosPedido->tirada; $margenServicios += round(floatval($resultado[0]->total - $base), 2); } } @@ -2865,7 +2884,6 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $sumForFactor += round($linea['precio_pedido'], 2); $sumForFactor -= round($linea['precio_pedido'], 2); - $totalImpresion += round($linea['precio_impresion_horas'], 2); $totalImpresion += round($linea['precio_click_pedido'], 2); $sumForFactor += round($linea['precio_click_pedido'], 2); @@ -2876,6 +2894,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $sumForFactor += round($linea['total_corte'], 2); } } + $margenImpresion += round($linea['precio_impresion_horas'], 2); // coste de maquina y magen son MARGEN, no COSTE $margenImpresion += round($linea['margen_impresion_horas'], 2); $margenImpresion += round($linea['margen_click_pedido'], 2); $sumForFactor -= round($linea['margen_click_pedido'], 2); diff --git a/ci4/app/Controllers/Sistema/Intranet.php b/ci4/app/Controllers/Sistema/Intranet.php index 99d3b206..73aa48f2 100644 --- a/ci4/app/Controllers/Sistema/Intranet.php +++ b/ci4/app/Controllers/Sistema/Intranet.php @@ -32,4 +32,29 @@ class Intranet extends Controller } + function tickets($resource_name) + { + helper('file'); + + $resource_path = WRITEPATH . 'uploads/tickets/' . $resource_name; + + if (file_exists($resource_path)) { + // Get the mime type of the file + $mime_type = mime_content_type($resource_path); + + // Get an instance of the Response class + $response = service('response'); + + // Set the content type + $response->setContentType($mime_type); + + // Set the output + $response->setBody(file_get_contents($resource_path)); + + // Send the response to the browser + $response->send(); + } + + } + } \ No newline at end of file diff --git a/ci4/app/Controllers/Soporte/Ticketcontroller.php b/ci4/app/Controllers/Soporte/Ticketcontroller.php new file mode 100644 index 00000000..a50c7889 --- /dev/null +++ b/ci4/app/Controllers/Soporte/Ticketcontroller.php @@ -0,0 +1,429 @@ +viewData['pageTitle'] = lang('Tickets.moduleTitle'); + + // Breadcrumbs + $this->viewData['breadcrumb'] = [ + ['title' => lang("App.menu_soporte"), 'route' => "javascript:void(0);", 'active' => false], + ['title' => lang("App.menu_soporte_ticket_list"), 'route' => route_to('TicketIndex'), 'active' => true] + ]; + + parent::initController($request, $response, $logger); + } + + public function index() + { + //checkPermission('tickets.menu'); + + $viewData = [ + 'currentModule' => static::$controllerSlug, + 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Tickets.tickets')]), + 'usingServerSideDataTable' => true, + 'userType' => auth()->user()->can('tickets.edit') ? 1 : 0, + ]; + + $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class + + return view(static::$viewPath . 'viewTicketList', $viewData); + } + + private function sendMail($subject, $body, $recipient) + { + $settings_model = new SettingsModel(); + $config = $settings_model->first()->toArray(); + $gateway = $config['email_gateway']; + $body = html_entity_decode($body); + + if ($gateway == 'smtp') { + try { + //https://codeigniter.com/user_guide/libraries/email.html + $email = \Config\Services::email(); + $config['protocol'] = $config['email_gateway']; + $config['SMTPHost'] = $config['email_smtp']; + $config['SMTPUser'] = $config['email_address']; + $config['SMTPPass'] = $config['email_pass']; + $config['SMTPPort'] = intval($config['email_port']); + $config['SMTPCrypto'] = $config['email_cert'] == 'none' ? '' : $config['email_cert']; + $config['SMTPTimeout'] = 15; + $config['mailType'] = 'html'; + $config['wordWrap'] = true; + + $email->initialize($config); + + $email->setFrom($config['email_address'], $config['email_name']); + $email->setTo($recipient); + + $email->setSubject($subject); + $email->setMessage($body); + + if (!$email->send()) { + return false; + } else { + return true; + } + } catch (\Exception $ex) { + return false; + } + } + return false; + } + + public function add() + { + + //checkPermission('tickets.create', $this->indexRoute); + + if ($this->request->getPost()): + + $nullIfEmpty = false; // !(phpversion() >= '8.1'); + + $postData = $this->request->getPost(); + + // get user id + $postData['usuario_id'] = auth()->user()->id; + $postData['user_soporte_id'] = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('default_soporte_user_id')->value; + + $sanitizedData = $this->sanitized($postData, $nullIfEmpty); + + $noException = true; + if ($successfulResult = $this->canValidate()): // if ($successfulResult = $this->validate($this->formValidationRules) ) : + + + if ($this->canValidate()): + try { + $successfulResult = $this->model->skipValidation(true)->save($sanitizedData); + } catch (\Exception $e) { + $noException = false; + $this->dealWithException($e); + } + else: + $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]); + $this->session->setFlashdata('formErrors', $this->model->errors()); + endif; + + $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission + endif; + if ($noException && $successfulResult): + + $id = $this->model->db->insertID(); + + $this->saveImages($id, $this->request->getFiles()); + + $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.'; + + $userModel = new \App\Models\UserModel(); + + $this->sendMail(lang('Tickets.newTicket'), lang('Tickets.newTicketBody') . base_url(route_to('editTicket', $id)), $userModel->find($sanitizedData['user_soporte_id'])->email); + + if ($thenRedirect): + if (!empty($this->indexRoute)): + return redirect()->to(route_to($this->indexRoute))->with('successMessage', $message); + else: + return $this->redirect2listView('successMessage', $message); + endif; + else: + $this->session->setFlashData('sweet-success', $message); + endif; + + endif; // $noException && $successfulResult + + endif; // ($requestMethod === 'post') + + $this->viewData['ticket'] = isset($sanitizedData) ? new TicketEntity($sanitizedData) : new TicketEntity(); + + $this->viewData['formAction'] = route_to('NewTicket'); + + $this->viewData['categorias'] = $this->model->getCategorias(); + $this->viewData['estados'] = $this->model->getEstados(); + $this->viewData['secciones'] = $this->model->getSecciones(); + + $this->viewData['supportUsers'] = $this->getSupportUsers(); + + $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('Tickets.ticket') . ' ' . lang('Basic.global.addNewSuffix'); + + + return $this->displayForm(__METHOD__); + } // end function add() + + public function edit($requestedId = null) + { + $modelRespuesta = new \App\Models\Soporte\TicketRespuestaModel(); + + if ($requestedId == null): + return $this->redirect2listView(); + endif; + $id = filter_var($requestedId, FILTER_SANITIZE_URL); + $ticket = $this->model->find($id); + + if ($ticket == false): + $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Tickets.ticket')), $id]); + return $this->redirect2listView('errorMessage', $message); + endif; + + if (!auth()->user()->can('Tickets.edit') && auth()->user()->id != $ticket->usuario_id) { + return redirect()->to(route_to('TicketIndex'))->with('errorMessage', lang('Basic.global.noPermission')); + } + + if ($this->request->getPost()): + + $oldUserSupport = $ticket->user_soporte_id; + $oldState = $ticket->estado_id; + + $postData = $this->request->getPost(); + $sanitizedData = $this->sanitized($postData, false); + + $noException = true; + if ($successfulResult = $this->canValidate()): // if ($successfulResult = $this->validate($this->formValidationRules) ) : + if ($this->canValidate()): + try { + $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); + + $this->saveImages($id, $this->request->getFiles()); + + if (auth()->user()->can('Tickets.edit')) { + + $respuesta = $modelRespuesta->where('ticket_id', $id)->first(); + if ($respuesta == null) { + $modelRespuesta->insert([ + 'ticket_id' => $id, + 'usuario_id' => auth()->user()->id, + 'mensaje' => $sanitizedData['respuesta_mensaje'] + ]); + } else { + $modelRespuesta->update($respuesta->id, [ + 'mensaje' => $sanitizedData['respuesta_mensaje'], + 'usuario_id' => auth()->user()->id, + ]); + } + + // envio de correos + $userModel = new \App\Models\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); + } + + if ($oldState != $sanitizedData['estado_id']) { + $this->sendMail(lang('Tickets.stateChange'), lang('Tickets.stateChangeBody') . base_url(route_to('editTicket', $id)), $userModel->find($ticket->usuario_id)->email); + } + + } + + } catch (\Exception $e) { + $noException = false; + $this->dealWithException($e); + } + else: + $this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Tickets.ticket'))]); + $this->session->setFlashdata('formErrors', $this->model->errors()); + + endif; + + $ticket->fill($sanitizedData); + + $thenRedirect = false; + endif; + if ($noException && $successfulResult): + $id = $ticket->id ?? $id; + $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.'; + + if ($thenRedirect): + if (!empty($this->indexRoute)): + return redirect()->to(route_to($this->indexRoute))->with('successMessage', $message); + else: + return $this->redirect2listView('successMessage', $message); + endif; + else: + return redirect()->to(route_to("editTicket", $id))->with('successMessage', $message); + //$this->session->setFlashData('sweet-success', $message); + endif; + + endif; // $noException && $successfulResult + endif; // ($requestMethod === 'post') + + $this->viewData['ticket'] = $ticket; + $this->viewData['respuesta'] = $modelRespuesta->where('ticket_id', $id)->first(); + + $this->viewData['formAction'] = route_to('updateTicket', $id); + + $this->viewData['categorias'] = $this->model->getCategorias(); + $this->viewData['estados'] = $this->model->getEstados(); + $this->viewData['secciones'] = $this->model->getSecciones(); + $this->viewData['supportUsers'] = $this->getSupportUsers(); + + $this->viewData['imagesTicket'] = $this->getImages('ticket', $id); + $this->viewData['imagesRespuesta'] = $this->getImages('respuesta', $id); + + $this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Tickets.ticket') . ' ' . lang('Basic.global.edit3'); + + + return $this->displayForm(__METHOD__, $id); + } // end function edit(...) + + public function datatable() + { + if ($this->request->isAJAX()) { + $reqData = $this->request->getPost(); + if (!isset($reqData['draw']) || !isset($reqData['columns'])) { + $errstr = 'No data available in response to this specific request.'; + $response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr); + return $response; + } + $start = $reqData['start'] ?? 0; + $length = $reqData['length'] ?? 5; + + $requestedOrder = $reqData['order'] ?? []; + + $searchValues = get_filter_datatables_columns($reqData); + + if (auth()->user()->can('tickets.edit')) { + $user_id = null; + } else { + $user_id = auth()->user()->id; + } + + $resourceData = $this->model->getResource($searchValues, $user_id); + foreach ($requestedOrder as $order) { + $column = $order['column'] ?? 0; + $dir = $order['dir'] ?? 'asc'; + $orderColumn = $this->model::SORTABLE[$column] ?? null; + if ($orderColumn) { + $resourceData->orderBy($orderColumn, $dir); + } + } + $resourceData = $resourceData->limit($length, $start)->get()->getResultObject(); + + return $this->respond(Collection::datatable( + $resourceData, + $this->model->getResource($searchValues)->countAllResults(), + $this->model->getResource($searchValues)->countAllResults() + )); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + public function image($imageName) + { + $filePath = WRITEPATH . "uploads/tickets/" . $imageName; + + if (!file_exists($filePath)) { + return $this->response->setStatusCode(404, 'Imagen no encontrada'); + } + + $mimeType = mime_content_type($filePath); + + return $this->response + ->setHeader('Content-Type', $mimeType) + ->setBody(file_get_contents($filePath)); + } + + private function saveImages($ticket_id, $files = []) + { + $uploadPath = WRITEPATH . 'uploads/tickets/'; + + $fileModel = new ticketFileModel(); + + if ($files && isset($files['files'])) { + foreach ($files['files'] as $file) { + if ($file->isValid() && !$file->hasMoved()) { + $originalName = $file->getClientName(); + $fileExt = $file->getExtension(); + + // Generar hash SHA-256 basado en el contenido del archivo + $fileHash = hash_file("sha256", $file->getTempName()); + $newFileName = $fileHash . '.' . $fileExt; + + // Mover el archivo con el nombre basado en el hash + $file->move($uploadPath, $newFileName); + + // Guardar en la base de datos + $fileModel->insert([ + 'nombre' => $originalName, + 'ticket_id' => $ticket_id, + 'hash' => $fileHash, + 'path' => 'uploads/tickets/' . $newFileName + ]); + } + } + } + } + + private function getImages($tipo = 'ticket', $id = null) + { + $images = []; + + $model = new ticketFileModel(); + if ($tipo == 'ticket') { + $files = $model->where('ticket_id', $id)->findAll(); + foreach ($files as $file) { + $ext = pathinfo($file['nombre'], PATHINFO_EXTENSION); + array_push($images, array( + "path" => '/soporte/image/' . $file['hash'] . "." . $ext, + "name" => $file['nombre'] + )); + } + } else { + $files = $model->where('respuesta_id', $id)->findAll(); + foreach ($files as $file) { + $ext = pathinfo($file['nombre'], PATHINFO_EXTENSION); + array_push($images, array( + "path" => '/soporte/image/' . $file['hash'] . "." . $ext, + "name" => $file['nombre'] + )); + } + } + return $images; + } + + private function getSupportUsers() + { + $defatulSoporteUserId = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('default_soporte_user_id')->value; + $supportUsers = array( + array( + 'id' => $defatulSoporteUserId, + 'name' => model('App\Models\UserModel')->getFullName($defatulSoporteUserId) + ), + array( + 'id' => 2, + 'name' => model('App\Models\UserModel')->getFullName(2) + ), + array( + 'id' => 1, + 'name' => model('App\Models\UserModel')->getFullName(1) + ), + ); + + return $supportUsers; + } +} diff --git a/ci4/app/Controllers/Tarifas/Acabados/TarifaAcabados.php b/ci4/app/Controllers/Tarifas/Acabados/TarifaAcabados.php index e2553235..a6e66616 100644 --- a/ci4/app/Controllers/Tarifas/Acabados/TarifaAcabados.php +++ b/ci4/app/Controllers/Tarifas/Acabados/TarifaAcabados.php @@ -348,7 +348,7 @@ class TarifaAcabados extends BaseResourceController )->where("deleted_at", null); if ($this->request->getGet("q")) { $query->groupStart() - ->orLike("lg_tarifas_acabado.nombre", $this->request->getGet("q")) + ->orLike("lg_tarifa_acabado.nombre", $this->request->getGet("q")) ->groupEnd(); } diff --git a/ci4/app/Controllers/Tarifas/Tarifaextra.php b/ci4/app/Controllers/Tarifas/Tarifaextra.php index 28ea2f1b..049c07d6 100755 --- a/ci4/app/Controllers/Tarifas/Tarifaextra.php +++ b/ci4/app/Controllers/Tarifas/Tarifaextra.php @@ -65,7 +65,9 @@ class Tarifaextra extends \App\Controllers\GoBaseController if ($this->request->getPost('mostrar_en_presupuesto') == null) { $sanitizedData['mostrar_en_presupuesto'] = false; } - + if ($this->request->getPost('mostrar_en_presupuesto_cliente') == null) { + $sanitizedData['mostrar_en_presupuesto_cliente'] = false; + } $noException = true; if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : @@ -142,7 +144,9 @@ class Tarifaextra extends \App\Controllers\GoBaseController if ($this->request->getPost('mostrar_en_presupuesto') == null) { $sanitizedData['mostrar_en_presupuesto'] = false; } - + if ($this->request->getPost('mostrar_en_presupuesto_cliente') == null) { + $sanitizedData['mostrar_en_presupuesto_cliente'] = false; + } $noException = true; if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($this->canValidate()) : diff --git a/ci4/app/Controllers/Tarifas/Tarifapreimpresion.php b/ci4/app/Controllers/Tarifas/Tarifapreimpresion.php index 6d26178e..474d60f1 100755 --- a/ci4/app/Controllers/Tarifas/Tarifapreimpresion.php +++ b/ci4/app/Controllers/Tarifas/Tarifapreimpresion.php @@ -63,7 +63,9 @@ class Tarifapreimpresion extends \App\Controllers\GoBaseController if ($this->request->getPost('mostrar_en_presupuesto') == null) { $sanitizedData['mostrar_en_presupuesto'] = false; } - + if ($this->request->getPost('mostrar_en_presupuesto_cliente') == null) { + $sanitizedData['mostrar_en_presupuesto_cliente'] = false; + } $noException = true; if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : @@ -144,7 +146,9 @@ class Tarifapreimpresion extends \App\Controllers\GoBaseController if ($this->request->getPost('mostrar_en_presupuesto') == null) { $sanitizedData['mostrar_en_presupuesto'] = false; } - + if ($this->request->getPost('mostrar_en_presupuesto_cliente') == null) { + $sanitizedData['mostrar_en_presupuesto_cliente'] = false; + } $noException = true; if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($this->canValidate()) : diff --git a/ci4/app/Database/Migrations/2025-02-14-114500_create_tickets_system.php b/ci4/app/Database/Migrations/2025-02-14-114500_create_tickets_system.php new file mode 100644 index 00000000..c0bbab1f --- /dev/null +++ b/ci4/app/Database/Migrations/2025-02-14-114500_create_tickets_system.php @@ -0,0 +1,99 @@ +forge->addField([ + 'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true], + 'keyword' => ['type' => 'VARCHAR', 'constraint' => 100, 'unique' => true], + ]); + $this->forge->addPrimaryKey('id'); + $this->forge->createTable('tickets_categorias'); + + // Tabla de secciones + $this->forge->addField([ + 'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true], + 'keyword' => ['type' => 'VARCHAR', 'constraint' => 100, 'unique' => true], + ]); + $this->forge->addPrimaryKey('id'); + $this->forge->createTable('tickets_secciones'); + + // Tabla de Estados + $this->forge->addField([ + 'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true], + 'keyword' => ['type' => 'VARCHAR', 'constraint' => 100, 'unique' => true], + ]); + $this->forge->addPrimaryKey('id'); + $this->forge->createTable('tickets_estados'); + + // Tabla de Tickets + $this->forge->addField([ + 'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true], + 'usuario_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true], + 'user_soporte_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true], + 'categoria_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true], + 'seccion_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true], + 'estado_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'default' => 1], + 'prioridad' => ['type' => 'ENUM', 'constraint' => ['alta', 'media', 'baja'], 'default' => 'media'], + 'titulo' => ['type' => 'VARCHAR', 'constraint' => 255], + 'descripcion' => ['type' => 'TEXT'], + 'created_at' => ['type' => 'DATETIME', 'null' => true], + 'updated_at' => ['type' => 'DATETIME', 'null' => true], + ]); + $this->forge->addPrimaryKey('id'); + $this->forge->addForeignKey('usuario_id', 'users', 'id', 'NO ACTION', 'NO ACTION'); + $this->forge->addForeignKey('user_soporte_id', 'users', 'id', 'NO ACTION', 'NO ACTION'); + $this->forge->addForeignKey('categoria_id', 'tickets_categorias', 'id', 'NO ACTION', 'NO ACTION'); + $this->forge->addForeignKey('seccion_id', 'tickets_secciones', 'id', 'NO ACTION', 'NO ACTION'); + $this->forge->addForeignKey('estado_id', 'tickets_estados', 'id', 'NO ACTION', 'NO ACTION'); + $this->forge->createTable('tickets'); + + // Tabla de Respuestas + $this->forge->addField([ + 'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true], + 'ticket_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true], + 'usuario_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true], + 'mensaje' => ['type' => 'TEXT'], + 'created_at' => ['type' => 'DATETIME', 'null' => true], + 'updated_at' => ['type' => 'DATETIME', 'null' => true], + ]); + $this->forge->addPrimaryKey('id'); + $this->forge->addForeignKey('ticket_id', 'tickets', 'id', '', 'NO ACTION'); + $this->forge->addForeignKey('usuario_id', 'users', 'id', 'NO ACTION', 'NO ACTION'); + $this->forge->createTable('tickets_respuestas'); + + // Tabla de Adjuntos + $this->forge->addField([ + 'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true], + 'ticket_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => true], + 'respuesta_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => true], + 'nombre' => ['type' => 'VARCHAR', 'constraint' => 255], + 'hash' => ['type' => 'VARCHAR', 'constraint' => 255], + 'path' => ['type' => 'VARCHAR', 'constraint' => 255], + 'created_at' => ['type' => 'DATETIME', 'null' => true], + 'updated_at' => ['type' => 'DATETIME', 'null' => true], + ]); + $this->forge->addPrimaryKey('id'); + $this->forge->addForeignKey('ticket_id', 'tickets', 'id', 'NO ACTION', 'NO ACTION'); + $this->forge->addForeignKey('respuesta_id', 'tickets_respuestas', 'id', 'NO ACTION', 'NO ACTION'); + $this->forge->createTable('tickets_adjuntos'); + } + + public function down() + { + $this->forge->dropTable('tickets_adjuntos'); + $this->forge->dropTable('tickets_respuestas'); + $this->forge->dropTable('tickets'); + $this->forge->dropTable('tickets_categorias'); + $this->forge->dropTable('tickets_estados'); + $this->forge->dropTable('tickets_secciones'); + + $this->db->table('config_variables_app')->where('name', 'default_soporte_user_id')->delete(); + } +} diff --git a/ci4/app/Database/Migrations/2025-02-16-194726_AlterTableTarifasCheckPresupuestoClienteMigration.php b/ci4/app/Database/Migrations/2025-02-16-194726_AlterTableTarifasCheckPresupuestoClienteMigration.php new file mode 100644 index 00000000..1d4f8510 --- /dev/null +++ b/ci4/app/Database/Migrations/2025-02-16-194726_AlterTableTarifasCheckPresupuestoClienteMigration.php @@ -0,0 +1,29 @@ + [ + 'type' => 'BOOLEAN', + 'default' => false, + ] + ]; + $this->forge->addColumn('lg_tarifa_acabado',$field); + $this->forge->addColumn('lg_tarifa_manipulado',$field); + $this->forge->addColumn('tarifa_encuadernacion',$field); + + } + + public function down() + { + $this->forge->dropColumn('lg_tarifa_acabado','mostrar_en_presupuesto_cliente'); + $this->forge->dropColumn('lg_tarifa_manipulado','mostrar_en_presupuesto_cliente'); + $this->forge->dropColumn('tarifa_encuadernacion','mostrar_en_presupuesto_cliente'); + } +} diff --git a/ci4/app/Database/Migrations/2025-02-16-224244_AlterAddColumnActivoPapelGenerico.php b/ci4/app/Database/Migrations/2025-02-16-224244_AlterAddColumnActivoPapelGenerico.php new file mode 100644 index 00000000..ae73c86b --- /dev/null +++ b/ci4/app/Database/Migrations/2025-02-16-224244_AlterAddColumnActivoPapelGenerico.php @@ -0,0 +1,26 @@ + [ + 'type' => 'BOOLEAN', + 'default' => true, + ] + ]; + $this->forge->addColumn('lg_papel_generico',$field); + + } + + public function down() + { + $this->forge->dropColumn('lg_papel_generico','activo'); + } +} + diff --git a/ci4/app/Database/Migrations/2025-02-20-080000_AlterTableTarifasExtraPreimpresionCheckPresupuestoClienteMigration.php b/ci4/app/Database/Migrations/2025-02-20-080000_AlterTableTarifasExtraPreimpresionCheckPresupuestoClienteMigration.php new file mode 100644 index 00000000..ee5e2428 --- /dev/null +++ b/ci4/app/Database/Migrations/2025-02-20-080000_AlterTableTarifasExtraPreimpresionCheckPresupuestoClienteMigration.php @@ -0,0 +1,30 @@ + [ + 'type' => 'BOOLEAN', + 'default' => false, + ] + ]; + $this->forge->addColumn('tarifa_extra',$field); + $this->forge->addColumn('lg_tarifa_preimpresion',$field); + + + } + + public function down() + { + $this->forge->dropColumn('tarifa_extra','mostrar_en_presupuesto_cliente'); + $this->forge->dropColumn('lg_tarifa_preimpresion','mostrar_en_presupuesto_cliente'); + + + } +} diff --git a/ci4/app/Database/Seeds/TicketsSeeder.php b/ci4/app/Database/Seeds/TicketsSeeder.php new file mode 100644 index 00000000..f7d0ea93 --- /dev/null +++ b/ci4/app/Database/Seeds/TicketsSeeder.php @@ -0,0 +1,76 @@ + 'errores', + ], + [ + 'keyword' => 'consultas', + ], + [ + 'keyword' => 'sugerencias', + ], + ]; + $this->db->table('tickets_categorias')->insertBatch($data); + + // secciones + $data = [ + [ + 'keyword' => 'presupuestos', + ], + [ + 'keyword' => 'pedidos', + ], + [ + 'keyword' => 'facturacion', + ], + [ + 'keyword' => 'logistica', + ], + [ + 'keyword' => 'configuracion', + ], + [ + 'keyword' => 'general', + ], + ]; + $this->db->table('tickets_secciones')->insertBatch($data); + + // estados + $data = [ + [ + 'keyword' => 'abierto', + ], + [ + 'keyword' => 'en_proceso', + ], + [ + 'keyword' => 'resuelto', + ], + [ + 'keyword' => 'archivado', + ], + ]; + $this->db->table('tickets_estados')->insertBatch($data); + + // config variables + $data = [ + [ + 'name' => 'default_soporte_user_id', + 'value' => '10', + 'description' => 'ID del usuario por defecto para asignar tickets', + ], + ]; + $this->db->table('config_variables_app')->insertBatch($data); + } +} \ No newline at end of file diff --git a/ci4/app/Entities/Configuracion/PapelGenerico.php b/ci4/app/Entities/Configuracion/PapelGenerico.php index a6bc5faa..344d1832 100755 --- a/ci4/app/Entities/Configuracion/PapelGenerico.php +++ b/ci4/app/Entities/Configuracion/PapelGenerico.php @@ -13,11 +13,13 @@ class PapelGenerico extends \CodeIgniter\Entity\Entity "show_in_client" => false, "show_in_client_special" => false, "is_deleted" => 0, + "activo" => false, "created_at" => null, "updated_at" => null, ]; protected $casts = [ "show_in_client" => "boolean", + "activo" => "boolean", "show_in_client_special" => "boolean", "is_deleted" => "int", ]; diff --git a/ci4/app/Entities/Soporte/TicketEntity.php b/ci4/app/Entities/Soporte/TicketEntity.php new file mode 100644 index 00000000..192e8d51 --- /dev/null +++ b/ci4/app/Entities/Soporte/TicketEntity.php @@ -0,0 +1,52 @@ + null, + 'usuario_id' => null, + 'tecnico_id' => null, + 'categoria_id'=> null, + 'estado_id' => null, + 'prioridad' => 'media', + 'titulo' => '', + 'descripcion' => '', + 'created_at' => null, + 'updated_at' => null, + ]; + + protected $dates = ['created_at', 'updated_at']; + + public function setTitulo(string $titulo) + { + $this->attributes['titulo'] = ucfirst($titulo); // Capitaliza el título + return $this; + } + + public function setDescripcion(string $descripcion) + { + $this->attributes['descripcion'] = ucfirst($descripcion); + return $this; + } + + public function getPrioridad(): string + { + return ucfirst($this->attributes['prioridad']); + } + + public function asignarTecnico(int $tecnicoId) + { + $this->attributes['tecnico_id'] = $tecnicoId; + return $this; + } + + public function cambiarEstado(int $estadoId) + { + $this->attributes['estado_id'] = $estadoId; + return $this; + } +} diff --git a/ci4/app/Entities/Soporte/TicketRespuestaEntity.php b/ci4/app/Entities/Soporte/TicketRespuestaEntity.php new file mode 100644 index 00000000..d7a082a3 --- /dev/null +++ b/ci4/app/Entities/Soporte/TicketRespuestaEntity.php @@ -0,0 +1,20 @@ + null, + 'ticket_id' => null, + 'usuario_id' => null, + 'mensaje' => null, + 'created_at' => null, + 'updated_at' => null, + ]; + + protected $dates = ['created_at', 'updated_at']; + +} diff --git a/ci4/app/Entities/Tarifas/Acabados/TarifaAcabadoEntity.php b/ci4/app/Entities/Tarifas/Acabados/TarifaAcabadoEntity.php index 37554c8d..0e384c7f 100644 --- a/ci4/app/Entities/Tarifas/Acabados/TarifaAcabadoEntity.php +++ b/ci4/app/Entities/Tarifas/Acabados/TarifaAcabadoEntity.php @@ -13,6 +13,7 @@ class TarifaAcabadoEntity extends \CodeIgniter\Entity\Entity "precio_min" => 0, "importe_fijo" => 0, "mostrar_en_presupuesto" => 1, + "mostrar_en_presupuesto_cliente" => 0, "acabado_cubierta" => 0, "acabado_sobrecubierta" => 0, "user_created_id" => 0, diff --git a/ci4/app/Entities/Tarifas/TarifaEncuadernacionEntity.php b/ci4/app/Entities/Tarifas/TarifaEncuadernacionEntity.php index 1aa85454..b8d01575 100755 --- a/ci4/app/Entities/Tarifas/TarifaEncuadernacionEntity.php +++ b/ci4/app/Entities/Tarifas/TarifaEncuadernacionEntity.php @@ -11,6 +11,7 @@ class TarifaEncuadernacionEntity extends \CodeIgniter\Entity\Entity "nombre" => null, "code" => null, "mostrar_en_presupuesto" => 1, + "mostrar_en_presupuesto_cliente" => 0, "tipo_encuadernacion" => 0, "servicio_encuadernacion" => 0, "por_horas" => 0, @@ -23,6 +24,7 @@ class TarifaEncuadernacionEntity extends \CodeIgniter\Entity\Entity ]; protected $casts = [ "mostrar_en_presupuesto" => "int", + "mostrar_en_presupuesto_cliente" => "bool", "code" => "string", "tipo_encuadernacion" => "int", "servicio_encuadernacion" => "int", diff --git a/ci4/app/Entities/Tarifas/TarifaManipuladoEntity.php b/ci4/app/Entities/Tarifas/TarifaManipuladoEntity.php index d9f3c2f7..d976de71 100755 --- a/ci4/app/Entities/Tarifas/TarifaManipuladoEntity.php +++ b/ci4/app/Entities/Tarifas/TarifaManipuladoEntity.php @@ -14,6 +14,7 @@ class TarifaManipuladoEntity extends \CodeIgniter\Entity\Entity "precio_min" => 0, "importe_fijo" => 0, "mostrar_en_presupuesto" => 1, + "mostrar_en_presupuesto_cliente" => 0, "user_created_id" => 0, "user_updated_id" => 0, "is_deleted" => 0, @@ -27,6 +28,7 @@ class TarifaManipuladoEntity extends \CodeIgniter\Entity\Entity "code" => "string", "comment" => "string", "mostrar_en_presupuesto" => "int", + "mostrar_en_presupuesto_cliente" => "bool", "user_created_id" => "int", "user_updated_id" => "int", "is_deleted" => "int", diff --git a/ci4/app/Entities/Tarifas/TarifaextraEntity.php b/ci4/app/Entities/Tarifas/TarifaextraEntity.php index db2b0594..7134684d 100755 --- a/ci4/app/Entities/Tarifas/TarifaextraEntity.php +++ b/ci4/app/Entities/Tarifas/TarifaextraEntity.php @@ -13,6 +13,7 @@ class TarifaextraEntity extends \CodeIgniter\Entity\Entity "precio" => null, "margen" => 0, "mostrar_en_presupuesto" => 1, + "mostrar_en_presupuesto_cliente" => false, "user_created_id" => 1, "user_update_id" => 1, "is_deleted" => 0, @@ -26,6 +27,7 @@ class TarifaextraEntity extends \CodeIgniter\Entity\Entity "comment" => "string", "margen" => "float", "mostrar_en_presupuesto" => "int", + "mostrar_en_presupuesto_cliente" => "bool", "user_created_id" => "int", "user_update_id" => "int", "is_deleted" => "int", diff --git a/ci4/app/Entities/Tarifas/TarifapreimpresionEntity.php b/ci4/app/Entities/Tarifas/TarifapreimpresionEntity.php index b1873597..86bd7f14 100755 --- a/ci4/app/Entities/Tarifas/TarifapreimpresionEntity.php +++ b/ci4/app/Entities/Tarifas/TarifapreimpresionEntity.php @@ -13,6 +13,7 @@ class TarifapreimpresionEntity extends \CodeIgniter\Entity\Entity "precio" => null, "margen" => 0, "mostrar_en_presupuesto" => 1, + "mostrar_en_presupuesto_cliente" => false, "user_created_id" => 1, "user_update_id" => 1, "is_deleted" => 0, @@ -26,6 +27,7 @@ class TarifapreimpresionEntity extends \CodeIgniter\Entity\Entity "code" => "string", "comment" => "string", "mostrar_en_presupuesto" => "int", + "mostrar_en_presupuesto_cliente" => "bool", "user_created_id" => "int", "user_update_id" => "int", "is_deleted" => "int", diff --git a/ci4/app/Language/es/App.php b/ci4/app/Language/es/App.php index 44552d73..a24597ea 100755 --- a/ci4/app/Language/es/App.php +++ b/ci4/app/Language/es/App.php @@ -818,5 +818,9 @@ return [ "menu_oauth" => "Autenticaciones", "menu_template" => "Plantillas", + "menu_soporte" => "Soporte", + "menu_soporte_new_ticket" => "Crear ticket", + "menu_soporte_ticket_list" => "Mis tickets", + ]; \ No newline at end of file diff --git a/ci4/app/Language/es/Basic.php b/ci4/app/Language/es/Basic.php index be74f2d1..3f1c5bf5 100755 --- a/ci4/app/Language/es/Basic.php +++ b/ci4/app/Language/es/Basic.php @@ -88,6 +88,7 @@ return [ 'line' => 'la línea', 'error_tittle' => 'Error', ], + 'noPermission' => 'No tiene permiso para acceder a esta página.', 'ok' => 'Ok', 'wait' => 'Espere', 'yes' => 'Si', diff --git a/ci4/app/Language/es/PapelGenerico.php b/ci4/app/Language/es/PapelGenerico.php index c38d8c1c..5df63224 100755 --- a/ci4/app/Language/es/PapelGenerico.php +++ b/ci4/app/Language/es/PapelGenerico.php @@ -8,6 +8,7 @@ return [ 'createdAt' => 'Creado el', 'deletedAt' => 'Deleted At', 'id' => 'ID', + 'activo' => 'Activo', 'isDeleted' => 'Is Deleted', 'moduleTitle' => 'Papel Genérico', 'nombre' => 'Nombre', diff --git a/ci4/app/Language/es/Presupuestos.php b/ci4/app/Language/es/Presupuestos.php index c1951b6e..b907e057 100755 --- a/ci4/app/Language/es/Presupuestos.php +++ b/ci4/app/Language/es/Presupuestos.php @@ -155,7 +155,7 @@ return [ 'totalClicks' => 'Total clicks', 'horas' => 'Horas máquina', 'precioHora' => 'Precio hora', - 'precioImpresion' => 'Precio impresión', + 'precioImpresion' => 'Total horas', 'precioPagNegro' => 'Precio pág. negro', 'precioPagColor' => 'Precio pág. color', 'totalTinta' => 'Total tinta', @@ -228,7 +228,7 @@ return [ 'totalClicks' => 'Total Clicks', 'totalTinta' => 'Total Tinta', 'totalCorte' => 'Total Corte', - 'totalImpresion' => 'TOTAL IMPRES.', + 'totalImpresion' => 'Total máquina', 'velocidadCorte' => 'Velocidad corte', 'precioHoraCorte' => 'Precio hora corte', 'tiempoCorte' => 'Tiempo corte', diff --git a/ci4/app/Language/es/RolesPermisos.php b/ci4/app/Language/es/RolesPermisos.php index 84e56b7f..ccc4176a 100644 --- a/ci4/app/Language/es/RolesPermisos.php +++ b/ci4/app/Language/es/RolesPermisos.php @@ -55,7 +55,7 @@ return [ 'ajustesSection' => 'Ajustes', 'actividadSection' => 'Accesos', - + "ticketsSection" => "Tickets", 'validation' => [ 'id' => [ diff --git a/ci4/app/Language/es/Tarifaacabado.php b/ci4/app/Language/es/Tarifaacabado.php index 5bdd61e9..1b5af0c8 100755 --- a/ci4/app/Language/es/Tarifaacabado.php +++ b/ci4/app/Language/es/Tarifaacabado.php @@ -13,6 +13,7 @@ return [ 'precioMin' => 'Precio Mínimo', 'importeFijo' => 'Importe Fijo', 'mostrar_en_presupuesto' => 'Mostrar en presupuesto', + 'mostrar_en_presupuesto_cliente' => 'Mostrar en presupuesto (cliente)', "acabado_cubierta" => "Acabado cubierta", "acabado_sobrecubierta" => "Acabado sobrecubierta", 'tarifaacabado' => 'Tarifa Acabado', diff --git a/ci4/app/Language/es/Tarifaencuadernacion.php b/ci4/app/Language/es/Tarifaencuadernacion.php index fbc59ef5..a4e15cde 100755 --- a/ci4/app/Language/es/Tarifaencuadernacion.php +++ b/ci4/app/Language/es/Tarifaencuadernacion.php @@ -23,6 +23,7 @@ return [ 'tiradaMax' => 'Tirada Max', 'tiradaMin' => 'Tirada Min', 'mostrar_en_presupuesto' => 'Mostrar en presupuesto', + 'mostrar_en_presupuesto_cliente' => 'Mostrar en presupuesto (cliente)', 'tipo_encuadernacion' => 'Tipo encuardernación', 'servicio_encuadernacion' => 'Servicio encuardernación', 'updatedAt' => 'Actualizado en', diff --git a/ci4/app/Language/es/Tarifaextra.php b/ci4/app/Language/es/Tarifaextra.php index ea711c63..f1263281 100755 --- a/ci4/app/Language/es/Tarifaextra.php +++ b/ci4/app/Language/es/Tarifaextra.php @@ -14,6 +14,7 @@ return [ 'precioMin' => 'Precio Mínimo', 'importeFijo' => 'Importe Fijo', 'mostrar_en_presupuesto' => 'Mostrar en presupuesto', + 'mostrar_en_presupuesto_cliente' => 'Mostrar en presupuesto (Cliente)', 'margen' => 'Margen', 'tarifaextra' => 'Tarifa Servicios Extra', 'tarifaextraList' => 'Lista Tarifas Servicios Extra', diff --git a/ci4/app/Language/es/Tarifamanipulado.php b/ci4/app/Language/es/Tarifamanipulado.php index 80afab6a..0bd0c413 100755 --- a/ci4/app/Language/es/Tarifamanipulado.php +++ b/ci4/app/Language/es/Tarifamanipulado.php @@ -18,6 +18,7 @@ return [ 'precioMin' => 'Precio T. Máx', 'importeFijo' => 'Importe Fijo', 'mostrar_en_presupuesto' => 'Mostrar en presupuesto', + 'mostrar_en_presupuesto_cliente' => 'Mostrar en presupuesto (cliente)', 'tarifamanipulado' => 'Tarifa Manipulado', 'tarifamanipuladoList' => 'Lista Tarifas Manipulado', 'tarifasmanipulado' => 'Tarifas Manipulado', diff --git a/ci4/app/Language/es/Tarifapreimpresion.php b/ci4/app/Language/es/Tarifapreimpresion.php index f98cd490..a1c885dd 100755 --- a/ci4/app/Language/es/Tarifapreimpresion.php +++ b/ci4/app/Language/es/Tarifapreimpresion.php @@ -14,6 +14,7 @@ return [ 'precioMin' => 'Precio Mínimo', 'importeFijo' => 'Importe Fijo', 'mostrar_en_presupuesto' => 'Mostrar en presupuesto', + 'mostrar_en_presupuesto_cliente' => 'Mostrar en presupuesto (Cliente)', 'margen' => 'Margen', 'tarifapreimpresion' => 'Tarifa Preimpresión', 'tarifapreimpresionList' => 'Lista Tarifas Preimpresión', diff --git a/ci4/app/Language/es/Tickets.php b/ci4/app/Language/es/Tickets.php new file mode 100644 index 00000000..020d304f --- /dev/null +++ b/ci4/app/Language/es/Tickets.php @@ -0,0 +1,70 @@ + 'Ticket', + 'tickets' => 'Tickets', + 'moduleTitle' => 'Tickets', + + "asunto" => "Asunto", + "tipo" => "Tipo", + "seccion" => "Sección", + "estado" => "Estado", + "prioridad" => "Prioridad", + "descripcion" => "Descripción", + "asignarTo" => "Asignado a", + "usuario" => "Creado por", + "createTicket" => "Crear Ticket", + "fechaCreacion" => "Fecha de creación", + "respuesta" => "Respuesta", + + // categorías + 'errores' => 'Errores', + 'consultas' => 'Consultas', + 'sugerencias' => 'Sugerencias', + + // secciones + 'presupuestos' => 'Presupuestos', + 'pedidos' => 'Pedidos', + 'facturacion' => 'Facturación', + 'logistica' => 'Logística', + 'configuracion' => 'Configuración', + 'general' => 'General', + + // estados + 'abierto' => 'Abierto', + 'en_proceso' => 'En proceso', + 'resuelto' => 'Resuelto', + 'archivado' => 'Archivado', + + //Prioridades + 'alta' => 'Alta', + 'media' => 'Media', + 'baja' => 'Baja', + + // FIcheros + 'adjuntos' => 'Adjuntar imágenes', + 'adjuntos_ticket' => 'Imágenes adjuntas', + + // Mail + 'newTicket' => 'Nuevo Ticket en ERP Safekat', + 'stateChange' => 'Cambio de estado en ticket en ERP Safekat', + 'asgignToChanged' => 'Asignado ticket en ERP Safekat', + 'newTicketBody' => '
Se ha creado un nuevo ticket en el sistema de soporte de Safekat ERP.
Puede verlo en el siguiente enlace:
El estado de un ticket en el sistema de soporte de Safekat ERP ha cambiado.
Puede verlo en el siguiente enlace:
Se le ha asignado un ticket en el sistema de soporte de Safekat ERP.
Puede verlo en el siguiente enlace:
| ID | += lang('Tickets.tipo') ?> | += lang('Tickets.seccion') ?> | += lang('Tickets.estado') ?> | + += lang('Tickets.prioridad') ?> | + += lang('Tickets.asunto') ?> | + += lang('Tickets.usuario') ?> | += lang('Tickets.asignarTo') ?> | + += lang('Tickets.fechaCreacion') ?> | += lang('Basic.global.Action') ?> | +
|---|
Directory access is forbidden.
- - - diff --git a/httpdocs/assets/js/safekat/common/common.js b/httpdocs/assets/js/safekat/common/common.js index d9400854..e9a877f2 100644 --- a/httpdocs/assets/js/safekat/common/common.js +++ b/httpdocs/assets/js/safekat/common/common.js @@ -26,6 +26,19 @@ export const initAutonumeric = () => { }); } }) + $("span.autonumeric-decimal").each(function () { + let autoNumericInstance = AutoNumeric.getAutoNumericElement(this) + if (!autoNumericInstance) { + new AutoNumeric(this, { + digitGroupSeparator: ".", + decimalCharacter: ",", + allowDecimalPadding : 'floats', + decimalPlaces: $(this).data('decimal-places'), + unformatOnSubmit: true, + + }); + } + }) // $(':input[type="number"]').each(function(){ // $(this).attr('type','text') // let autoNumericInstance = AutoNumeric.getAutoNumericElement(this) diff --git a/httpdocs/assets/js/safekat/components/alerts/sweetAlert.js b/httpdocs/assets/js/safekat/components/alerts/sweetAlert.js index 97f9bd66..75b668e2 100644 --- a/httpdocs/assets/js/safekat/components/alerts/sweetAlert.js +++ b/httpdocs/assets/js/safekat/components/alerts/sweetAlert.js @@ -1,37 +1,37 @@ -export const alertConfirmationDelete = (title,type="primary") => { - return Swal.fire({ - title: '¿Está seguro?', - text: "Esta acción es irreversible.", - icon: 'warning', - showCancelButton: true, - confirmButtonColor: '#3085d6', - cancelButtonColor: '#d33', - confirmButtonText: 'Sí', - cancelButtonText: 'Cancelar', - customClass: { - confirmButton: 'btn btn-danger me-1', - cancelButton: 'btn btn-label-secondary' - }, - buttonsStyling: false - }) -} - -export const alertSuccessMessage = (title,type="primary") => { - return Swal.fire({ - showCancelButton: false, - showConfirmButton : false, - title: title, - text: title, - icon: "success", - timer : 2000 +export const alertConfirmationDelete = (title, type = "primary") => { + return Swal.fire({ + title: '¿Está seguro?', + text: "Esta acción es irreversible.", + icon: 'warning', + showCancelButton: true, + confirmButtonColor: '#3085d6', + cancelButtonColor: '#d33', + confirmButtonText: 'Sí', + cancelButtonText: 'Cancelar', + customClass: { + confirmButton: 'btn btn-danger me-1', + cancelButton: 'btn btn-label-secondary' + }, + buttonsStyling: false }) } -export const alertWarningMessage = (title,message,type="primary") => { - return Swal.fire({ +export const alertSuccessMessage = (title, type = "primary") => { + return Swal.fire({ + showCancelButton: false, + showConfirmButton: false, + title: title, + text: title, + icon: "success", + timer: 2000 + }) +} + +export const alertWarningMessage = (title, message, type = "primary") => { + return Swal.fire({ title: title, text: message, icon: "warning", @@ -40,4 +40,27 @@ export const alertWarningMessage = (title,message,type="primary") => { }, buttonsStyling: false }) +} + +export const toastPresupuestoSummary = (value, target = 'body') => { + return Swal.mixin({ + toast: true, + position: 'bottom-end', + html: ` +Total presupuesto
+ ${value} +