From 2143660cf6d6d518e7e1ade90d54e4711da8c0c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Tue, 11 Jun 2024 08:53:20 +0200 Subject: [PATCH 01/10] =?UTF-8?q?a=C3=B1adidos=20entidades=20y=20modelos.?= =?UTF-8?q?=20Hecha=20lista=20de=20todos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ci4/app/Config/Routes.php | 12 ++ ci4/app/Controllers/Pedidos/Pedido.php | 102 +++++++++--- ci4/app/Entities/Pedidos/PedidoEntity.php | 30 ++++ .../Entities/Pedidos/PedidoLineaEntity.php | 25 +++ ci4/app/Language/en/App.php | 2 +- ci4/app/Language/en/Pedidos.php | 27 ++++ ci4/app/Language/es/App.php | 2 +- ci4/app/Language/es/Pedidos.php | 28 ++++ ci4/app/Models/Pedidos/PedidoLineaModel.php | 42 +++++ ci4/app/Models/Pedidos/PedidoModel.php | 82 ++++++++++ .../vuexy/form/pedidos/viewPedidosList.php | 147 ++++++++++++++++++ .../themes/vuexy/main/menu_digitalizacion.php | 6 +- .../themes/vuexy/main/menu_maquetacion.php | 6 +- .../themes/vuexy/main/menus/pedidos_menu.php | 4 +- 14 files changed, 484 insertions(+), 31 deletions(-) create mode 100644 ci4/app/Entities/Pedidos/PedidoEntity.php create mode 100644 ci4/app/Entities/Pedidos/PedidoLineaEntity.php create mode 100644 ci4/app/Language/en/Pedidos.php create mode 100644 ci4/app/Language/es/Pedidos.php create mode 100644 ci4/app/Models/Pedidos/PedidoLineaModel.php create mode 100644 ci4/app/Models/Pedidos/PedidoModel.php create mode 100644 ci4/app/Views/themes/vuexy/form/pedidos/viewPedidosList.php diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 34182efa..060fe82e 100755 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -588,6 +588,18 @@ $routes->group('presupuestotiradasalternativas', ['namespace' => 'App\Controller $routes->post('datatable_2', 'Presupuestotiradasalternativas::datatable_2', ['as' => 'getTiradaData']); }); +$routes->group('pedidos', ['namespace' => 'App\Controllers\Pedidos'], function ($routes) { + $routes->get('list', 'Pedido::todos', ['as' => 'listaPresupuestos']); + $routes->get('listActivos', 'Pedido::activos', ['as' => 'listaPresupuestosActivos']); + $routes->get('listFinalizados', 'Pedido::finalizados', ['as' => 'listaFinalizados']); + $routes->get('listCancelados', 'Pedido::cancelados', ['as' => 'listaCancelados']); + $routes->post('datatable', 'Pedido::datatable', ['as' => 'dataTableOfPedidos']); + $routes->get('add', 'Pedido::add', ['as' => 'nuevoPedido']); + $routes->post('add', 'Pedido::add', ['as' => 'crearPedido']); + $routes->post('edit/(:num)', 'Pedido::edit/$1', ['as' => 'editarPedido']); +}); +$routes->resource('pedidos', ['namespace' => 'App\Controllers\Pedidos', 'controller' => 'Pedido', 'except' => 'show,new,create,update']); + $routes->group( diff --git a/ci4/app/Controllers/Pedidos/Pedido.php b/ci4/app/Controllers/Pedidos/Pedido.php index af9c7953..7a32875e 100755 --- a/ci4/app/Controllers/Pedidos/Pedido.php +++ b/ci4/app/Controllers/Pedidos/Pedido.php @@ -2,18 +2,48 @@ namespace App\Controllers\Pedidos; use App\Controllers\BaseController; +use App\Entities\Pedidos\PedidoEntity; +use App\Models\Collection; +use App\Models\Pedidos\PedidoModel; -class Pedido extends BaseController +class Pedido extends \App\Controllers\BaseResourceController { - function __construct() - { - + protected $modelName = PedidoModel::class; + protected $format = 'json'; + + protected static $singularObjectNameCc = 'pedido'; + protected static $singularObjectName = 'Pedido'; + protected static $pluralObjectName = 'Pedidos'; + protected static $controllerSlug = 'pedido'; + + protected static $viewPath = 'themes/vuexy/form/pedidos/'; + + protected $indexRoute = 'pedidoList'; + + + public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) + { + $this->viewData['pageTitle'] = lang('Tarifaextra.moduleTitle'); + // Se indica que este controlador trabaja con soft_delete + + // Breadcrumbs + $this->viewData['breadcrumb'] = [ + ['title' => lang("App.menu_pedidos"), 'route' => "javascript:void(0);", 'active' => false], + ]; + + parent::initController($request, $response, $logger); + } public function index() { - echo 'Pedidos'; + + $this->viewData['usingClientSideDataTable'] = true; + + $this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Tarifaextra.tarifaextra')]); + parent::index(); + } public function activos() @@ -31,25 +61,55 @@ class Pedido extends BaseController echo 'Pedidos Cancelados'; } - public function manuales() + public function todos() { - echo 'Pedidos Manuales'; + + $viewData = [ + 'currentModule' => static::$controllerSlug, + 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Pedidos.pedido')]), + 'presupuestoEntity' => new PedidoEntity(), + 'usingServerSideDataTable' => true, + 'pageTitle' => lang('Pedidos.Pedidos'), + 'estadoPedidos' => 'todos', + ['title' => lang("App.menu_pedidos"), 'route' => site_url('pedidos/todos'), 'active' => true] + ]; + + return view(static::$viewPath . 'viewPedidosList', $viewData); + } -// public function delete_files() -// { -// -// } -// -// public function pedidos_maquetacion() -// { -// -// } -// -// public function pedidos_prestashop() -// { -// -// } + public function edit($id=null){ + echo "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; + $search = $reqData['search']['value']; + $requestedOrder = $reqData['order']['0']['column'] ?? 0; + $order = PedidoModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0]; + $dir = $reqData['order']['0']['dir'] ?? 'asc'; + + $resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); + + return $this->respond(Collection::datatable( + $resourceData, + $this->model->getResource()->countAllResults(), + $this->model->getResource($search)->countAllResults() + )); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } } \ No newline at end of file diff --git a/ci4/app/Entities/Pedidos/PedidoEntity.php b/ci4/app/Entities/Pedidos/PedidoEntity.php new file mode 100644 index 00000000..a847c03b --- /dev/null +++ b/ci4/app/Entities/Pedidos/PedidoEntity.php @@ -0,0 +1,30 @@ + null, + "total_precio" => null, + "total_tirada" => null, + "estado" => null, + "user_created_id" => null, + "user_updated_id" => null, + "user_validated_id" => null, + "fecha_entrega_real" => null, + "fecha_impresion" => null, + "fecha_encuadernado" => null, + "fecha_entrega_externo" => null, + "created_at" => null, + "updated_at" => null, + "validated_at" => null, + ]; + + + protected $casts = [ + "total_precio" => "float", + "total_tirada" => "float", + ]; +} diff --git a/ci4/app/Entities/Pedidos/PedidoLineaEntity.php b/ci4/app/Entities/Pedidos/PedidoLineaEntity.php new file mode 100644 index 00000000..38efab3f --- /dev/null +++ b/ci4/app/Entities/Pedidos/PedidoLineaEntity.php @@ -0,0 +1,25 @@ + null, + "pedido_id" => null, + "presupuesto_id" => null, + "ubicacion_id" => null, + "user_created_id" => null, + "user_updated_id" => null, + "created_at" => null, + "updated_at" => null, + ]; + + + protected $casts = [ + "pedido_id" => "int", + "presupuesto_id" => "int", + "ubicacion_id" => "int", + ]; +} diff --git a/ci4/app/Language/en/App.php b/ci4/app/Language/en/App.php index f3648c44..8a54743e 100755 --- a/ci4/app/Language/en/App.php +++ b/ci4/app/Language/en/App.php @@ -731,7 +731,7 @@ return [ "menu_pedidos_activos" => "Actives", "menu_pedidos_finalizados" => "Finished", "menu_pedidos_cancelados" => "Cancelled", - "menu_pedidos_manuales" => "Manual", + "menu_pedidos_todos" => "All", "menu_presupuestos" => "Budgets", "menu_presupuesto" => "Books", diff --git a/ci4/app/Language/en/Pedidos.php b/ci4/app/Language/en/Pedidos.php new file mode 100644 index 00000000..c5f68504 --- /dev/null +++ b/ci4/app/Language/en/Pedidos.php @@ -0,0 +1,27 @@ + 'Number', + 'fecha' => 'Date', + 'fecha_entrega' => 'Delivery Date', + 'cliente' => 'Client', + 'comercial' => 'Commercial', + 'titulo' => 'Title', + 'ubicacion' => 'Location', + 'inc_rei' => 'Inc/Rei', // This seems to be a specific term, left as is + 'num_paginas' => 'Number of Pages', + 'tiradas' => 'Print Runs', + 'total_presupuesto' => 'Total Budget', + 'estado' => 'Status', + + 'moduleTitle' => 'Orders', + 'pedido' => 'Order', + 'pedidos' => 'Orders', + 'pedidosList' => 'Orders List', + + 'validation' => [ + + ], +]; \ No newline at end of file diff --git a/ci4/app/Language/es/App.php b/ci4/app/Language/es/App.php index 653da4cf..f41817f4 100755 --- a/ci4/app/Language/es/App.php +++ b/ci4/app/Language/es/App.php @@ -737,7 +737,7 @@ return [ "menu_pedidos_activos" => "Activos", "menu_pedidos_finalizados" => "Finalizados", "menu_pedidos_cancelados" => "Cancelados", - "menu_pedidos_manuales" => "Manuales", + "menu_pedidos_todos" => "Todos", "menu_presupuestos" => "Presupuestos", "menu_presupuesto" => "Libros", diff --git a/ci4/app/Language/es/Pedidos.php b/ci4/app/Language/es/Pedidos.php new file mode 100644 index 00000000..386fd67c --- /dev/null +++ b/ci4/app/Language/es/Pedidos.php @@ -0,0 +1,28 @@ + 'Número', + 'fecha' => 'Fecha', + 'fecha_entrega' => 'Fecha
Entrega', + 'cliente' => 'Cliente', + 'comercial' => 'Comercial', + 'titulo' => 'Título', + 'ubicacion' => 'Ubicación', + 'inc_rei' => 'Inc/Rei', + 'num_paginas' => 'Nº Páginas', + 'tiradas' => 'Tiradas', + 'total_presupuesto' => 'Total', + 'estado' => 'Estado', + + 'moduleTitle' => 'Pedidos', + 'pedido' => 'Pedido', + 'pedidos' => 'Pedidos', + 'pedidosList' => 'Lista de Pedidos', + + 'validation' => [ + + ], + + +]; \ No newline at end of file diff --git a/ci4/app/Models/Pedidos/PedidoLineaModel.php b/ci4/app/Models/Pedidos/PedidoLineaModel.php new file mode 100644 index 00000000..f61c2fc0 --- /dev/null +++ b/ci4/app/Models/Pedidos/PedidoLineaModel.php @@ -0,0 +1,42 @@ + "t1.id", + 1 => "t1.estado", + 2 => "t1.total_precio", + 3 => "t1.total_tirada", + ]; + + protected $allowedFields = [ + "pedido_id", + "presupuesto_id", + "ubicacion_id", + "user_created_id", + "user_updated_id", + "created_at", + "updated_at", + ]; + protected $returnType = "App\Entities\Pedidos\PedidoLineaEntity"; + + protected $useTimestamps = true; + protected $useSoftDeletes = false; + + protected $createdField = "created_at"; + protected $updatedField = "updated_at"; + + public static $labelField = "id"; + +} \ No newline at end of file diff --git a/ci4/app/Models/Pedidos/PedidoModel.php b/ci4/app/Models/Pedidos/PedidoModel.php new file mode 100644 index 00000000..fc43d402 --- /dev/null +++ b/ci4/app/Models/Pedidos/PedidoModel.php @@ -0,0 +1,82 @@ + "t1.id", + 1 => "t1.updated_at", + 2 => "t1.fecha_entrega_real", + 3 => "t4.nombre", + 4 => "t5.first_name", + 5 => "t3.titulo", + 6 => "t6.ubicacion", + 7 => "t3.inc_rei", + 8 => "t3.paginas", + 9 => "t3.tirada", + 10 => "t3.total_aceptado", + 11 => "t1.estado" + ]; + + protected $allowedFields = [ + "total_precio", + "total_tirada", + "estado", + "user_created_id", + "user_updated_id", + "user_validated_id", + "fecha_entrega_real", + "fecha_impresion", + "fecha_encuadernado", + "fecha_entrega_externo", + "created_at", + "updated_at", + "validated_at", + ]; + protected $returnType = "App\Entities\Pedidos\PedidoEntity"; + + protected $useTimestamps = true; + protected $useSoftDeletes = false; + + protected $createdField = "created_at"; + protected $updatedField = "updated_at"; + + public static $labelField = "id"; + + public function getResource(string $search = "", $tarifa_envio_id = -1) + { + $builder = $this->db + ->table($this->table . " t1") + ->select( + "t1.id AS id, t1.updated_at AS fecha, t1.fecha_entrega_real AS fecha_entrega, + t4.nombre AS cliente, CONCAT(t5.first_name, ' ', t5.last_name) AS comercial, + t3.titulo AS titulo, t6.nombre AS ubicacion, t3.inc_rei AS inc_rei, + t3.paginas AS paginas, t3.tirada AS tirada, t3.total_aceptado AS total_presupuesto, + t1.estado AS estado" + ); + + $builder->join("pedidos_linea t2", "t1.id = t2.pedido_id", "left"); + $builder->join("presupuestos t3", "t2.presupuesto_id = t3.id", "left"); + $builder->join("clientes t4", "t4.id = t3.cliente_id", "left"); + $builder->join("users t5", "t5.id = t4.comercial_id", "left"); + $builder->join("ubicaciones t6", "t6.id = t2.ubicacion_id", "left"); + + return empty($search) + ? $builder + : $builder + ->groupStart() + ->like("t1.id", $search) + ->orLike("t1.id", $search) + ->groupEnd(); + } +} \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidosList.php b/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidosList.php new file mode 100644 index 00000000..6a45dc7e --- /dev/null +++ b/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidosList.php @@ -0,0 +1,147 @@ +include('themes/_commonPartialsBs/datatables') ?> +include('themes/_commonPartialsBs/_confirm2delete') ?> +extend('themes/vuexy/main/defaultlayout') ?> +section('content'); ?> +
+
+ +
+
+

+
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+
+ +endSection() ?> + + +section('additionalInlineJs') ?> + + const lastColNr = $('#tableOfPedidos').find("tr:first th").length - 1; + const actionBtns = function(data) { + return ` + +
+ +
+ `; + }; + + theTable = $('#tableOfPedidos').DataTable({ + processing: true, + serverSide: true, + autoWidth: true, + responsive: true, + scrollX: true, + lengthMenu: [ 5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500 ], + pageLength: 50, + lengthChange: true, + "dom": 'lfBrtip', + "buttons": [ + 'copy', 'csv', 'excel', 'print', { + extend: 'pdfHtml5', + orientation: 'landscape', + pageSize: 'A4' + } + ], + stateSave: true, + order: [[0, 'asc']], + language: { + url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" + }, + ajax : $.fn.dataTable.pipeline( { + url: '', + method: 'POST', + data: { + estado: "", + }, + headers: {'X-Requested-With': 'XMLHttpRequest'}, + async: true, + }), + columnDefs: [ + { + orderable: false, + searchable: false, + targets: [lastColNr] + } + ], + columns : [ + { 'data': 'id' }, + { 'data': 'fecha' }, + { 'data': 'fecha_entrega' }, + { 'data': 'cliente' }, + { 'data': 'comercial' }, + { 'data': 'titulo' }, + { 'data': 'ubicacion' }, + { 'data': 'inc_rei' }, + { 'data': 'num_paginas' }, + { 'data': 'tiradas' }, + { 'data': 'total_presupuesto' }, + { 'data': 'estado' }, + { 'data': actionBtns } + ] + }); + + theTable.on( 'draw.dt', function () { + const boolCols = []; + for (let coln of boolCols) { + theTable.column(coln, { page: 'current' }).nodes().each( function (cell, i) { + cell.innerHTML = cell.innerHTML == '1' ? '' : ''; + }); + } + }); + + + $(document).on('click', '.btn-edit', function(e) { + window.location.href = `/pedidos/edit/${$(this).attr('data-id')}`; + }); + + +endSection() ?> + + +section('css') ?> + "> +endSection() ?> + + +section('additionalExternalJs') ?> + + + + + + + +endSection() ?> + diff --git a/ci4/app/Views/themes/vuexy/main/menu_digitalizacion.php b/ci4/app/Views/themes/vuexy/main/menu_digitalizacion.php index c451b754..af211791 100644 --- a/ci4/app/Views/themes/vuexy/main/menu_digitalizacion.php +++ b/ci4/app/Views/themes/vuexy/main/menu_digitalizacion.php @@ -117,10 +117,10 @@ - 0): ?> + 0): ?> diff --git a/ci4/app/Views/themes/vuexy/main/menu_maquetacion.php b/ci4/app/Views/themes/vuexy/main/menu_maquetacion.php index 958974ec..359caef1 100644 --- a/ci4/app/Views/themes/vuexy/main/menu_maquetacion.php +++ b/ci4/app/Views/themes/vuexy/main/menu_maquetacion.php @@ -138,10 +138,10 @@ - 0): ?> + 0): ?> diff --git a/ci4/app/Views/themes/vuexy/main/menus/pedidos_menu.php b/ci4/app/Views/themes/vuexy/main/menus/pedidos_menu.php index 85093ca9..30c38ad4 100644 --- a/ci4/app/Views/themes/vuexy/main/menus/pedidos_menu.php +++ b/ci4/app/Views/themes/vuexy/main/menus/pedidos_menu.php @@ -27,8 +27,8 @@ if (auth()->user()->inGroup('beta')) { From 8aa77510609047243ec4ca5d03e17e41ef75743b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Tue, 11 Jun 2024 11:02:36 +0200 Subject: [PATCH 02/10] trabajando en el form de cliente --- ci4/app/Config/Routes.php | 3 +- ci4/app/Controllers/Pedidos/Pedido.php | 36 ++++++++++++++- .../Presupuestos/Presupuestocliente.php | 40 +++++++++++++++++ ci4/app/Language/en/Pedidos.php | 6 +++ ci4/app/Language/es/Pedidos.php | 6 +++ ci4/app/Models/Clientes/ClienteModel.php | 7 +++ ci4/app/Models/Pedidos/PedidoModel.php | 9 +++- .../vuexy/form/pedidos/_cabeceraItems.php | 44 +++++++++++++++++++ .../vuexy/form/pedidos/viewPedidoForm.php | 27 ++++++++++++ .../vuexy/form/pedidos/viewPedidosList.php | 41 ++++++++++++++--- 10 files changed, 209 insertions(+), 10 deletions(-) create mode 100644 ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php create mode 100644 ci4/app/Views/themes/vuexy/form/pedidos/viewPedidoForm.php diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 060fe82e..0fa46c4e 100755 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -323,6 +323,7 @@ $routes->group('clientes', ['namespace' => 'App\Controllers\Clientes'], function /* Cliente */ $routes->group('cliente', ['namespace' => 'App\Controllers\Clientes'], function ($routes) { $routes->get('', 'Cliente::index', ['as' => 'clienteList']); + $routes->get('edit/(:num)', 'Cliente::edit/$1', ['as' => 'editarCliente']); $routes->match(['get', 'post'], 'add', 'Cliente::add', ['as' => 'clienteAdd']); $routes->match(['get', 'post'], 'edit/(:num)', 'Cliente::edit/$1', ['as' => 'clienteEdit']); $routes->get('delete/(:num)', 'Cliente::delete/$1', ['as' => 'clienteDelete']); @@ -596,7 +597,7 @@ $routes->group('pedidos', ['namespace' => 'App\Controllers\Pedidos'], function ( $routes->post('datatable', 'Pedido::datatable', ['as' => 'dataTableOfPedidos']); $routes->get('add', 'Pedido::add', ['as' => 'nuevoPedido']); $routes->post('add', 'Pedido::add', ['as' => 'crearPedido']); - $routes->post('edit/(:num)', 'Pedido::edit/$1', ['as' => 'editarPedido']); + $routes->get('edit/(:any)', 'Pedido::edit/$1', ['as' => 'editarPedido']); }); $routes->resource('pedidos', ['namespace' => 'App\Controllers\Pedidos', 'controller' => 'Pedido', 'except' => 'show,new,create,update']); diff --git a/ci4/app/Controllers/Pedidos/Pedido.php b/ci4/app/Controllers/Pedidos/Pedido.php index 7a32875e..bd84bc68 100755 --- a/ci4/app/Controllers/Pedidos/Pedido.php +++ b/ci4/app/Controllers/Pedidos/Pedido.php @@ -79,7 +79,25 @@ class Pedido extends \App\Controllers\BaseResourceController } public function edit($id=null){ - echo "Edit"; + + if ($id == null) : + return $this->redirect2listView(); + endif; + $id = filter_var($id, FILTER_SANITIZE_URL); + $pedidoEntity = $this->model->find($id); + + if ($pedidoEntity == false) : + $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.pedido')), $id]); + return $this->redirect2listView('sweet-error', $message); + endif; + + $this->obtenerDatosFormulario($pedidoEntity); + + $this->viewData['pedidoEntity'] = $pedidoEntity; + + $this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Pedidos.moduleTitle') . ' ' . lang('Basic.global.edit3'); + + return $this->displayForm(__METHOD__, $id); } public function datatable(){ @@ -96,7 +114,7 @@ class Pedido extends \App\Controllers\BaseResourceController $length = $reqData['length'] ?? 5; $search = $reqData['search']['value']; $requestedOrder = $reqData['order']['0']['column'] ?? 0; - $order = PedidoModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0]; + $order = PedidoModel::SORTABLE_TODOS[$requestedOrder >= 0 ? $requestedOrder : 0]; $dir = $reqData['order']['0']['dir'] ?? 'asc'; $resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); @@ -111,5 +129,19 @@ class Pedido extends \App\Controllers\BaseResourceController } } + private function obtenerDatosFormulario(&$pedidoEntity){ + + $pedidoLineaModel = model('\App\Models\Pedidos\PedidoLineaModel'); + $clienteModel = model('\App\Models\Clientes\ClienteModel'); + $presupuestoModel = model('\App\Models\Presupuestos\PresupuestoModel'); + + $linea = $pedidoLineaModel->where('pedido_id', $pedidoEntity->id)->first(); + // los clientes son los mismos para todas las lineas de un mismo presupuesto + $presupuesto = $presupuestoModel->find($linea->presupuesto_id); + $cliente = $clienteModel->find($presupuesto->cliente_id); + + $pedidoEntity->cliente = $cliente->nombre; + $pedidoEntity->cliente_id = $cliente->id; + } } \ No newline at end of file diff --git a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php index 3bf94ddf..67784cd8 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php @@ -20,6 +20,7 @@ use Exception; use function PHPUnit\Framework\containsOnly; + class Presupuestocliente extends \App\Controllers\BaseResourceController { protected $modelName = "PresupuestoModel"; @@ -787,6 +788,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController if ($confirmar) { $model_presupuesto->confirmarPresupuesto($id); + $this->crearPedido($id); } return $this->respond([ @@ -889,6 +891,44 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController * Funciones auxiliares * **********************/ + public function crearPedido($presupuesto_id) + { + $model_pedido = model('App\Models\Pedidos\PedidoModel'); + $model_pedido_linea = model('App\Models\Pedidos\PedidoLineaModel'); + $model_cliente = model('App\Models\Clientes\ClienteModel'); + + $model_presupuesto = new PresupuestoModel(); + $datos_presupuesto = $model_presupuesto->find($presupuesto_id); + + $id_linea = 0; + + $data_pedido = [ + 'total_precio' => $datos_presupuesto->total_aceptado, + 'total_tirada' => $datos_presupuesto->tirada, + 'estado' => $model_cliente->creditoDisponible($datos_presupuesto->cliente_id) ? "produccion" : "validacion", + 'user_created_id' => auth()->user()->id, + 'user_updated_id' => auth()->user()->id, + ]; + + $pedido_id = $model_pedido->insert($data_pedido); + if($pedido_id){ + $data_pedido_linea = [ + "pedido_id" => $pedido_id, + "presupuesto_id" => $presupuesto_id, + "ubicacion_id" => 1, // safetak por defecto + "user_created_id" => auth()->user()->id, + "user_updated_id" => auth()->user()->id, + ]; + $id_linea = $model_pedido_linea->insert($data_pedido_linea); + } + + if($id_linea != 0 && $pedido_id != 0){ + return true; + } + return false; + } + + protected function borrarRelacionesPresupuesto($id) { // Se borran las lineas de presupuesto diff --git a/ci4/app/Language/en/Pedidos.php b/ci4/app/Language/en/Pedidos.php index c5f68504..4551b2da 100644 --- a/ci4/app/Language/en/Pedidos.php +++ b/ci4/app/Language/en/Pedidos.php @@ -15,6 +15,12 @@ return [ 'tiradas' => 'Print Runs', 'total_presupuesto' => 'Total Budget', 'estado' => 'Status', + + 'validacion' => 'Validation', + 'produccion' => 'Production', + 'finalizado' => 'Finished', + 'enviado' => 'Sent', + 'cancelado' => 'Cancelled', 'moduleTitle' => 'Orders', 'pedido' => 'Order', diff --git a/ci4/app/Language/es/Pedidos.php b/ci4/app/Language/es/Pedidos.php index 386fd67c..021cb159 100644 --- a/ci4/app/Language/es/Pedidos.php +++ b/ci4/app/Language/es/Pedidos.php @@ -15,6 +15,12 @@ return [ 'total_presupuesto' => 'Total', 'estado' => 'Estado', + 'validacion' => 'Validación', + 'produccion' => 'Producción', + 'finalizado' => 'Finalizado', + 'enviado' => 'Enviado', + 'cancelado' => 'Cancelado', + 'moduleTitle' => 'Pedidos', 'pedido' => 'Pedido', 'pedidos' => 'Pedidos', diff --git a/ci4/app/Models/Clientes/ClienteModel.php b/ci4/app/Models/Clientes/ClienteModel.php index 0a211f29..f6e09af2 100755 --- a/ci4/app/Models/Clientes/ClienteModel.php +++ b/ci4/app/Models/Clientes/ClienteModel.php @@ -308,4 +308,11 @@ class ClienteModel extends \App\Models\BaseModel ->orLike("t7.nombre", $search) ->groupEnd(); } + + /* + TO-DO: Implementar la lógica de negocio para el crédito disponible + */ + public function creditoDisponible($cliente_id){ + return true; + } } diff --git a/ci4/app/Models/Pedidos/PedidoModel.php b/ci4/app/Models/Pedidos/PedidoModel.php index fc43d402..623062cd 100644 --- a/ci4/app/Models/Pedidos/PedidoModel.php +++ b/ci4/app/Models/Pedidos/PedidoModel.php @@ -12,7 +12,7 @@ class PedidoModel extends \App\Models\BaseModel * @var bool */ protected $useAutoIncrement = true; - + const SORTABLE_TODOS = [ 0 => "t1.id", 1 => "t1.updated_at", @@ -53,7 +53,7 @@ class PedidoModel extends \App\Models\BaseModel public static $labelField = "id"; - public function getResource(string $search = "", $tarifa_envio_id = -1) + public function getResource(string $search = "", $estado="") { $builder = $this->db ->table($this->table . " t1") @@ -71,6 +71,11 @@ class PedidoModel extends \App\Models\BaseModel $builder->join("users t5", "t5.id = t4.comercial_id", "left"); $builder->join("ubicaciones t6", "t6.id = t2.ubicacion_id", "left"); + if($estado != "") { + $builder->where("t1.estado", $estado); + } + + // Falta implementar la busqueda por grupos return empty($search) ? $builder : $builder diff --git a/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php b/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php new file mode 100644 index 00000000..7beeb0e0 --- /dev/null +++ b/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php @@ -0,0 +1,44 @@ +
+
+

+ +

+ +
+
+ +
+ +
+ +
+ + +
+
+ +
+
+ + + + +
+
+ + +
+ +
+
+
+
\ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidoForm.php b/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidoForm.php new file mode 100644 index 00000000..e9384afe --- /dev/null +++ b/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidoForm.php @@ -0,0 +1,27 @@ +include("themes/_commonPartialsBs/datatables") ?> +include("themes/_commonPartialsBs/select2bs5") ?> +include("themes/_commonPartialsBs/sweetalert") ?> +extend('themes/vuexy/main/defaultlayout') ?> + +section("content") ?> +
+
+
+
+

+
+
+ +
+ + getErrors()) ? $validation->listErrors("bootstrap_style") : "" ?> + +
+
+ "btn btn-secondary float-start"]) ?> +
+
+
+
+
+endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidosList.php b/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidosList.php index 6a45dc7e..1a169428 100644 --- a/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidosList.php +++ b/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidosList.php @@ -52,7 +52,7 @@ return `
- +
`; }; @@ -104,10 +104,39 @@ { 'data': 'titulo' }, { 'data': 'ubicacion' }, { 'data': 'inc_rei' }, - { 'data': 'num_paginas' }, - { 'data': 'tiradas' }, + { 'data': 'paginas' }, + { 'data': 'tirada' }, { 'data': 'total_presupuesto' }, - { 'data': 'estado' }, + { 'data': 'estado', + render: function(data, type, row, meta) { + switch(data){ + case "validacion": + return ''; + break; + + case "produccion": + return ''; + break; + + case "finalizado": + return ''; + break; + + case "enviado": + return ''; + break; + + case "cancelado": + return ''; + break; + + default: + return data; // Debug + break; + + } + } + }, { 'data': actionBtns } ] }); @@ -123,7 +152,9 @@ $(document).on('click', '.btn-edit', function(e) { - window.location.href = `/pedidos/edit/${$(this).attr('data-id')}`; + var url = ''; + url = url.replace(':id', `${$(this).attr('data-id')}` ); + window.location.href = url; }); From e491172b2839f918cf9ec23ba7060257817df4cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Tue, 11 Jun 2024 11:11:02 +0200 Subject: [PATCH 03/10] cambiado el obtener la lista a pedidos_linea --- ci4/app/Controllers/Pedidos/Pedido.php | 9 +++--- ci4/app/Models/Pedidos/PedidoLineaModel.php | 32 +++++++++++++++++++++ ci4/app/Models/Pedidos/PedidoModel.php | 31 -------------------- 3 files changed, 37 insertions(+), 35 deletions(-) diff --git a/ci4/app/Controllers/Pedidos/Pedido.php b/ci4/app/Controllers/Pedidos/Pedido.php index bd84bc68..25bc2f5a 100755 --- a/ci4/app/Controllers/Pedidos/Pedido.php +++ b/ci4/app/Controllers/Pedidos/Pedido.php @@ -92,7 +92,7 @@ class Pedido extends \App\Controllers\BaseResourceController endif; $this->obtenerDatosFormulario($pedidoEntity); - + $this->viewData['pedidoEntity'] = $pedidoEntity; $this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Pedidos.moduleTitle') . ' ' . lang('Basic.global.edit3'); @@ -117,12 +117,13 @@ class Pedido extends \App\Controllers\BaseResourceController $order = PedidoModel::SORTABLE_TODOS[$requestedOrder >= 0 ? $requestedOrder : 0]; $dir = $reqData['order']['0']['dir'] ?? 'asc'; - $resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); + $model_linea = model('\App\Models\Pedidos\PedidoLineaModel'); + $resourceData = $model_linea->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); return $this->respond(Collection::datatable( $resourceData, - $this->model->getResource()->countAllResults(), - $this->model->getResource($search)->countAllResults() + $model_linea->getResource()->countAllResults(), + $model_linea->getResource($search)->countAllResults() )); } else { return $this->failUnauthorized('Invalid request', 403); diff --git a/ci4/app/Models/Pedidos/PedidoLineaModel.php b/ci4/app/Models/Pedidos/PedidoLineaModel.php index f61c2fc0..de4bb1e9 100644 --- a/ci4/app/Models/Pedidos/PedidoLineaModel.php +++ b/ci4/app/Models/Pedidos/PedidoLineaModel.php @@ -39,4 +39,36 @@ class PedidoLineaModel extends \App\Models\BaseModel public static $labelField = "id"; + + public function getResource(string $search = "", $estado="") + { + $builder = $this->db + ->table($this->table . " t1") + ->select( + "t2.id AS id, t2.updated_at AS fecha, t2.fecha_entrega_real AS fecha_entrega, + t4.nombre AS cliente, CONCAT(t5.first_name, ' ', t5.last_name) AS comercial, + t3.titulo AS titulo, t6.nombre AS ubicacion, t3.inc_rei AS inc_rei, + t3.paginas AS paginas, t3.tirada AS tirada, t3.total_aceptado AS total_presupuesto, + t2.estado AS estado" + ); + + $builder->join("pedidos t2", "t2.id = t1.pedido_id", "left"); + $builder->join("presupuestos t3", "t1.presupuesto_id = t3.id", "left"); + $builder->join("clientes t4", "t4.id = t3.cliente_id", "left"); + $builder->join("users t5", "t5.id = t4.comercial_id", "left"); + $builder->join("ubicaciones t6", "t6.id = t1.ubicacion_id", "left"); + + if($estado != "") { + $builder->where("t1.estado", $estado); + } + + // Falta implementar la busqueda por grupos + return empty($search) + ? $builder + : $builder + ->groupStart() + ->like("t1.id", $search) + ->orLike("t1.id", $search) + ->groupEnd(); + } } \ No newline at end of file diff --git a/ci4/app/Models/Pedidos/PedidoModel.php b/ci4/app/Models/Pedidos/PedidoModel.php index 623062cd..6b0336eb 100644 --- a/ci4/app/Models/Pedidos/PedidoModel.php +++ b/ci4/app/Models/Pedidos/PedidoModel.php @@ -53,35 +53,4 @@ class PedidoModel extends \App\Models\BaseModel public static $labelField = "id"; - public function getResource(string $search = "", $estado="") - { - $builder = $this->db - ->table($this->table . " t1") - ->select( - "t1.id AS id, t1.updated_at AS fecha, t1.fecha_entrega_real AS fecha_entrega, - t4.nombre AS cliente, CONCAT(t5.first_name, ' ', t5.last_name) AS comercial, - t3.titulo AS titulo, t6.nombre AS ubicacion, t3.inc_rei AS inc_rei, - t3.paginas AS paginas, t3.tirada AS tirada, t3.total_aceptado AS total_presupuesto, - t1.estado AS estado" - ); - - $builder->join("pedidos_linea t2", "t1.id = t2.pedido_id", "left"); - $builder->join("presupuestos t3", "t2.presupuesto_id = t3.id", "left"); - $builder->join("clientes t4", "t4.id = t3.cliente_id", "left"); - $builder->join("users t5", "t5.id = t4.comercial_id", "left"); - $builder->join("ubicaciones t6", "t6.id = t2.ubicacion_id", "left"); - - if($estado != "") { - $builder->where("t1.estado", $estado); - } - - // Falta implementar la busqueda por grupos - return empty($search) - ? $builder - : $builder - ->groupStart() - ->like("t1.id", $search) - ->orLike("t1.id", $search) - ->groupEnd(); - } } \ No newline at end of file From b1734e169b4fdc03f10fd010601b45530fee4f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Thu, 13 Jun 2024 19:23:50 +0200 Subject: [PATCH 04/10] trabajando en el form --- ci4/app/Controllers/Pedidos/Pedido.php | 16 +- ci4/app/Language/en/Pedidos.php | 14 ++ ci4/app/Language/es/Pedidos.php | 14 ++ ci4/app/Models/Pedidos/PedidoModel.php | 14 ++ .../vuexy/form/pedidos/_cabeceraItems.php | 184 +++++++++++++++++- .../vuexy/form/pedidos/_lineasItems.php | 103 ++++++++++ .../vuexy/form/pedidos/viewPedidoForm.php | 13 +- 7 files changed, 339 insertions(+), 19 deletions(-) create mode 100644 ci4/app/Views/themes/vuexy/form/pedidos/_lineasItems.php diff --git a/ci4/app/Controllers/Pedidos/Pedido.php b/ci4/app/Controllers/Pedidos/Pedido.php index 25bc2f5a..f8d45fc3 100755 --- a/ci4/app/Controllers/Pedidos/Pedido.php +++ b/ci4/app/Controllers/Pedidos/Pedido.php @@ -132,17 +132,15 @@ class Pedido extends \App\Controllers\BaseResourceController private function obtenerDatosFormulario(&$pedidoEntity){ - $pedidoLineaModel = model('\App\Models\Pedidos\PedidoLineaModel'); - $clienteModel = model('\App\Models\Clientes\ClienteModel'); - $presupuestoModel = model('\App\Models\Presupuestos\PresupuestoModel'); + $datos = $this->model->obtenerDatosForm($pedidoEntity->id); - $linea = $pedidoLineaModel->where('pedido_id', $pedidoEntity->id)->first(); - // los clientes son los mismos para todas las lineas de un mismo presupuesto - $presupuesto = $presupuestoModel->find($linea->presupuesto_id); - $cliente = $clienteModel->find($presupuesto->cliente_id); + $pedidoEntity->estadoText = lang('Pedidos.' . $pedidoEntity->estado); - $pedidoEntity->cliente = $cliente->nombre; - $pedidoEntity->cliente_id = $cliente->id; + if(count($datos) > 0){ + $pedidoEntity->cliente = $datos[0]->cliente; + $pedidoEntity->cliente_id = $datos[0]->cliente_id; + $pedidoEntity->comercial = $datos[0]->comercial; + } } } \ No newline at end of file diff --git a/ci4/app/Language/en/Pedidos.php b/ci4/app/Language/en/Pedidos.php index 4551b2da..99ae4950 100644 --- a/ci4/app/Language/en/Pedidos.php +++ b/ci4/app/Language/en/Pedidos.php @@ -21,7 +21,21 @@ return [ 'finalizado' => 'Finished', 'enviado' => 'Sent', 'cancelado' => 'Cancelled', + + 'datosPedido' => 'Order Details', + 'totales' => 'Totales', + 'total_precio' => 'Total price', + "total_tirada" => 'Total print', + + 'fechas' => "Dates", + 'fecha_entrega_real' => 'Actual Delivery Date', + 'fecha_impresion' => 'Printing Date', + 'fecha_encuadernado' => 'Binding Date', + 'fecha_entrega_externo' => 'External Delivery Date', + + 'lineas' => 'Lines', + 'moduleTitle' => 'Orders', 'pedido' => 'Order', 'pedidos' => 'Orders', diff --git a/ci4/app/Language/es/Pedidos.php b/ci4/app/Language/es/Pedidos.php index 021cb159..08c27abe 100644 --- a/ci4/app/Language/es/Pedidos.php +++ b/ci4/app/Language/es/Pedidos.php @@ -21,6 +21,20 @@ return [ 'enviado' => 'Enviado', 'cancelado' => 'Cancelado', + 'datosPedido' => 'Datos del pedido', + + 'totales' => 'Totales', + 'total_precio' => 'Total precio', + "total_tirada" => 'Total tirada', + + 'fechas' => "Fechas", + 'fecha_entrega_real' => "Fecha entrega real", + 'fecha_impresion' => "Fecha impresion", + 'fecha_encuadernado' => "Fecha encuadernado", + 'fecha_entrega_externo' => "Fecha entrega externo", + + 'lineas' => 'Líneas pedido', + 'moduleTitle' => 'Pedidos', 'pedido' => 'Pedido', 'pedidos' => 'Pedidos', diff --git a/ci4/app/Models/Pedidos/PedidoModel.php b/ci4/app/Models/Pedidos/PedidoModel.php index 6b0336eb..4018529c 100644 --- a/ci4/app/Models/Pedidos/PedidoModel.php +++ b/ci4/app/Models/Pedidos/PedidoModel.php @@ -53,4 +53,18 @@ class PedidoModel extends \App\Models\BaseModel public static $labelField = "id"; + public function obtenerDatosForm($pedido_id){ + $builder = $this->db + ->table($this->table . " t1") + ->select( + "t4.id AS cliente_id, t4.nombre AS cliente, CONCAT(t5.first_name, ' ', t5.last_name) AS comercial"); + + $builder->join("pedidos_linea t2", "t2.pedido_id = t1.id", "left"); + $builder->join("presupuestos t3", "t2.presupuesto_id = t3.id", "left"); + $builder->join("clientes t4", "t4.id = t3.cliente_id", "left"); + $builder->join("users t5", "t5.id = t4.comercial_id", "left"); + + + return $builder->get()->getResultObject(); + } } \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php b/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php index 7beeb0e0..19dac6f8 100644 --- a/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php +++ b/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php @@ -1,8 +1,9 @@
+
-

+

@@ -14,31 +15,196 @@
-
-
+
-
+
+ +
+ + +
+
+
+ +
+ + +
+
+ + + +
+
+

+ +

+ +
+
+
+
+
+ + +
+
+ +
+
+ + +
+
+ +
+
+
+
+ +
+
+

+ +

+
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+
+
+
- \ No newline at end of file + + + +section('additionalInlineJs') ?> + +$("#fecha_entrega_real").flatpickr({ + dateFormat: "d/m/Y", + locale: { + firstDayOfWeek: 1, + weekdays: { + shorthand: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'], + longhand: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'], + }, + months: { + shorthand: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Оct', 'Nov', 'Dic'], + longhand: ['Enero', 'Febreo', 'Мarzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], + }, + }, +}); + +$("#fecha_impresion").flatpickr({ + dateFormat: "d/m/Y", + locale: { + firstDayOfWeek: 1, + weekdays: { + shorthand: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'], + longhand: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'], + }, + months: { + shorthand: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Оct', 'Nov', 'Dic'], + longhand: ['Enero', 'Febreo', 'Мarzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], + }, + }, +}); + +$("#fecha_encuadernado").flatpickr({ + dateFormat: "d/m/Y", + locale: { + firstDayOfWeek: 1, + weekdays: { + shorthand: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'], + longhand: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'], + }, + months: { + shorthand: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Оct', 'Nov', 'Dic'], + longhand: ['Enero', 'Febreo', 'Мarzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], + }, + }, +}); + +$("#fecha_entrega_externo").flatpickr({ + dateFormat: "d/m/Y", + locale: { + firstDayOfWeek: 1, + weekdays: { + shorthand: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'], + longhand: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'], + }, + months: { + shorthand: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Оct', 'Nov', 'Dic'], + longhand: ['Enero', 'Febreo', 'Мarzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], + }, + }, +}); + +endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/pedidos/_lineasItems.php b/ci4/app/Views/themes/vuexy/form/pedidos/_lineasItems.php new file mode 100644 index 00000000..132fdfb5 --- /dev/null +++ b/ci4/app/Views/themes/vuexy/form/pedidos/_lineasItems.php @@ -0,0 +1,103 @@ +
+ +
+

+ +

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+ + +section('additionalInlineJs') ?> + +$("#fecha_entrega_real").flatpickr({ + dateFormat: "d/m/Y", + locale: { + firstDayOfWeek: 1, + weekdays: { + shorthand: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'], + longhand: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'], + }, + months: { + shorthand: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Оct', 'Nov', 'Dic'], + longhand: ['Enero', 'Febreo', 'Мarzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], + }, + }, +}); + +$("#fecha_impresion").flatpickr({ + dateFormat: "d/m/Y", + locale: { + firstDayOfWeek: 1, + weekdays: { + shorthand: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'], + longhand: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'], + }, + months: { + shorthand: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Оct', 'Nov', 'Dic'], + longhand: ['Enero', 'Febreo', 'Мarzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], + }, + }, +}); + +$("#fecha_encuadernado").flatpickr({ + dateFormat: "d/m/Y", + locale: { + firstDayOfWeek: 1, + weekdays: { + shorthand: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'], + longhand: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'], + }, + months: { + shorthand: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Оct', 'Nov', 'Dic'], + longhand: ['Enero', 'Febreo', 'Мarzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], + }, + }, +}); + +$("#fecha_entrega_externo").flatpickr({ + dateFormat: "d/m/Y", + locale: { + firstDayOfWeek: 1, + weekdays: { + shorthand: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'], + longhand: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'], + }, + months: { + shorthand: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Оct', 'Nov', 'Dic'], + longhand: ['Enero', 'Febreo', 'Мarzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], + }, + }, +}); + +endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidoForm.php b/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidoForm.php index e9384afe..b65da3c8 100644 --- a/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidoForm.php +++ b/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidoForm.php @@ -16,6 +16,7 @@ getErrors()) ? $validation->listErrors("bootstrap_style") : "" ?> +
"btn btn-secondary float-start"]) ?> @@ -24,4 +25,14 @@
-endSection() ?> \ No newline at end of file +endSection() ?> + + +section('css') ?> + "> +endSection() ?> + +section('additionalExternalJs') ?> + +endSection() ?> + From c9d88753928a6f9a7c28a19113876964c7d08b08 Mon Sep 17 00:00:00 2001 From: jaimejimenezortega Date: Thu, 13 Jun 2024 23:53:20 +0200 Subject: [PATCH 05/10] trabajando en pedidos 3 --- ci4/app/Config/Routes.php | 3 + ci4/app/Controllers/Pedidos/Pedido.php | 25 +++ ci4/app/Controllers/Test.php | 17 +- ci4/app/Language/en/Pedidos.php | 22 ++- ci4/app/Language/es/Pedidos.php | 22 ++- ci4/app/Models/Pedidos/PedidoModel.php | 18 ++ .../Models/Presupuestos/PresupuestoModel.php | 167 ++++++++++++++++++ .../vuexy/form/pedidos/_albaranesItems.php | 24 +++ .../vuexy/form/pedidos/_cabeceraItems.php | 6 +- .../vuexy/form/pedidos/_facturasItems.php | 24 +++ .../vuexy/form/pedidos/_lineasItems.php | 162 ++++++++++------- .../vuexy/form/pedidos/viewPedidoForm.php | 11 ++ 12 files changed, 418 insertions(+), 83 deletions(-) create mode 100644 ci4/app/Views/themes/vuexy/form/pedidos/_albaranesItems.php create mode 100644 ci4/app/Views/themes/vuexy/form/pedidos/_facturasItems.php diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 0fa46c4e..cd29dcfc 100755 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -524,6 +524,7 @@ $routes->resource('clientedirecciones', ['namespace' => 'App\Controllers\Cliente $routes->group('cosidotapablanda', ['namespace' => 'App\Controllers\Presupuestos'], function ($routes) { $routes->get('list/(:num)', 'Cosidotapablanda::list/$1', ['as' => 'cosidotapablandaList']); // HOMOGENIZAR CON ARGS DINAMICOS!!! $routes->get('add/(:num)', 'Cosidotapablanda::add/$1', ['as' => 'newCosidotapablanda']); + $routes->get('edit/(:any)', 'Cosidotapablanda::edit/$1', ['as' => 'editarPresupuesto']); $routes->post('add/(:num)', 'Cosidotapablanda::add/$1', ['as' => 'createCosidotapablanda']); $routes->post('create', 'Cosidotapablanda::create', ['as' => 'ajaxCreateCosidotapablanda']); $routes->put('(:num)/update', 'Cosidotapablanda::update/$1', ['as' => 'ajaxUpdateCosidotapablanda']); @@ -541,6 +542,7 @@ $routes->group('presupuestocliente', ['namespace' => 'App\Controllers\Presupuest $routes->get('add', 'Presupuestocliente::add', ['as' => 'nuevoPresupuestoCliente']); $routes->post('add', 'Presupuestocliente::add', ['as' => 'crearPresupuestoCliente']); $routes->post('edit/(:num)', 'Presupuestocliente::edit/$1', ['as' => 'editarPresupuestoCliente']); + $routes->get('edit/(:any)', 'Presupuestocliente::edit/$1', ['as' => 'editarPresupuestoCliente2']); $routes->post('getgramaje', 'Presupuestocliente::getGramaje', ['as' => 'obtenerGramaje']); $routes->post('presupuesto', 'Presupuestocliente::presupuesto', ['as' => 'presupuestoCliente']); $routes->post('getDireccionesCliente', 'Presupuestocliente::getDireccionesCliente', ['as' => 'getDirecciones']); @@ -598,6 +600,7 @@ $routes->group('pedidos', ['namespace' => 'App\Controllers\Pedidos'], function ( $routes->get('add', 'Pedido::add', ['as' => 'nuevoPedido']); $routes->post('add', 'Pedido::add', ['as' => 'crearPedido']); $routes->get('edit/(:any)', 'Pedido::edit/$1', ['as' => 'editarPedido']); + $routes->post('getlineas', 'Pedido::getLineas', ['as' => 'tablaLineasPedido']); }); $routes->resource('pedidos', ['namespace' => 'App\Controllers\Pedidos', 'controller' => 'Pedido', 'except' => 'show,new,create,update']); diff --git a/ci4/app/Controllers/Pedidos/Pedido.php b/ci4/app/Controllers/Pedidos/Pedido.php index f8d45fc3..c08bc6b7 100755 --- a/ci4/app/Controllers/Pedidos/Pedido.php +++ b/ci4/app/Controllers/Pedidos/Pedido.php @@ -27,6 +27,8 @@ class Pedido extends \App\Controllers\BaseResourceController $this->viewData['pageTitle'] = lang('Tarifaextra.moduleTitle'); // Se indica que este controlador trabaja con soft_delete + $this->viewData = ['usingServerSideDataTable' => true]; + // Breadcrumbs $this->viewData['breadcrumb'] = [ ['title' => lang("App.menu_pedidos"), 'route' => "javascript:void(0);", 'active' => false], @@ -130,6 +132,29 @@ class Pedido extends \App\Controllers\BaseResourceController } } + public function getlineas(){ + 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; + } + + $id = $reqData['pedido_id'] ?? 0; + $resourceData = $this->model->obtenerLineasPedido($id); + + return $this->respond(Collection::datatable( + $resourceData, + count($resourceData), + count($resourceData) + )); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + private function obtenerDatosFormulario(&$pedidoEntity){ $datos = $this->model->obtenerDatosForm($pedidoEntity->id); diff --git a/ci4/app/Controllers/Test.php b/ci4/app/Controllers/Test.php index cccbe256..3b6973fc 100755 --- a/ci4/app/Controllers/Test.php +++ b/ci4/app/Controllers/Test.php @@ -20,18 +20,11 @@ class Test extends BaseController public function index() { - helper('rbac'); - - //$user = auth()->user(); - - //generate_php_permissions_constant(); - - echo generate_php_permissions_matrix_constant(); - - //$user->syncGroups('admin'); - - //var_dump($user->can('token.menu')); - + $model = new PresupuestoModel(); + $data = $model->generarLineaPedido(123); + echo '
';
+        var_dump($data);
+        echo '
'; } diff --git a/ci4/app/Language/en/Pedidos.php b/ci4/app/Language/en/Pedidos.php index 99ae4950..83a6714b 100644 --- a/ci4/app/Language/en/Pedidos.php +++ b/ci4/app/Language/en/Pedidos.php @@ -35,11 +35,31 @@ return [ 'fecha_entrega_externo' => 'External Delivery Date', 'lineas' => 'Lines', - + 'unidades' => "Units", + 'concepto' => "Concept", + 'total' => "Total", + 'presupuesto' => 'Budget', + 'moduleTitle' => 'Orders', 'pedido' => 'Order', 'pedidos' => 'Orders', 'pedidosList' => 'Orders List', + + 'unaCara' => '1 side', + 'dosCaras' => '2 sides', + + 'lineasTemplates' =>[ + 'libro' => "[BUDGET %s] Printing of %s copies of %s pages.\nTitle: %s. Author: %s. ISBN: %s.Size: %smm.\n", + 'libro_linea_interior' => "%s black pages on %s paper of %s grams", + 'libro_linea_cubierta' => "\nCover printed on %s on %s paper of %s grams", + 'libro_linea_sobrecubierta' => "\nDust jacket on %s paper of %s grams", + 'libro_solapas' => " with flaps of %smm.", + 'libro_encuadernacion' => "\nType of binding: %s" + ], + + 'albaranes' => 'Delivery Notes', + + 'facturas' => 'Invoices', 'validation' => [ diff --git a/ci4/app/Language/es/Pedidos.php b/ci4/app/Language/es/Pedidos.php index 08c27abe..5237a09d 100644 --- a/ci4/app/Language/es/Pedidos.php +++ b/ci4/app/Language/es/Pedidos.php @@ -34,12 +34,32 @@ return [ 'fecha_entrega_externo' => "Fecha entrega externo", 'lineas' => 'Líneas pedido', - + 'unidades' => "Unidades", + 'concepto' => "Concepto", + 'total' => "Total", + 'presupuesto' => 'Presupuesto', + 'moduleTitle' => 'Pedidos', 'pedido' => 'Pedido', 'pedidos' => 'Pedidos', 'pedidosList' => 'Lista de Pedidos', + + 'unaCara' => '1 cara', + 'dosCaras' => '2 caras', + + 'lineasTemplates' =>[ + 'libro' => "[PRESUPUESTO %s] Impresión de %s ejemplares de %s páginas.\nTítulo: %s. Autor: %s. ISBN: %s.Tamaño: %smm.\n", + 'libro_linea_interior' => "%s páginas en negro sobre papel %s de %s gramos", + 'libro_linea_cubierta' => "\nCubierta impresa a %s sobre papel %s de %s gramos", + 'libro_linea_sobrecubierta' => "\nSobrecubierta sobre papel %s de %s gramos", + 'libro_solapas' => " con solapas de %smm." , + 'libro_encuadernacion' => "\nTipo de encuadernación: %s" + ], + 'albaranes' => 'Albaranes', + + 'facturas' => 'Facturas', + 'validation' => [ ], diff --git a/ci4/app/Models/Pedidos/PedidoModel.php b/ci4/app/Models/Pedidos/PedidoModel.php index 4018529c..04755c6e 100644 --- a/ci4/app/Models/Pedidos/PedidoModel.php +++ b/ci4/app/Models/Pedidos/PedidoModel.php @@ -67,4 +67,22 @@ class PedidoModel extends \App\Models\BaseModel return $builder->get()->getResultObject(); } + + public function obtenerLineasPedido($pedido_id){ + $builder = $this->db + ->table($this->table . " t1") + ->select( + "t2.presupuesto_id" + ); + $builder->where("t1.id", $pedido_id); + $builder->join("pedidos_linea t2", "t2.pedido_id = t1.id", "left"); + $model_presupuesto = model("App\Models\Presupuestos\PresupuestoModel"); + $lineasPresupuesto = []; + + foreach($builder->get()->getResultObject() as $row){ + array_push($lineasPresupuesto, $model_presupuesto->generarLineaPedido($row->presupuesto_id)[0]); + } + + return $lineasPresupuesto; + } } \ No newline at end of file diff --git a/ci4/app/Models/Presupuestos/PresupuestoModel.php b/ci4/app/Models/Presupuestos/PresupuestoModel.php index e4cb1a6f..5d25dabe 100755 --- a/ci4/app/Models/Presupuestos/PresupuestoModel.php +++ b/ci4/app/Models/Presupuestos/PresupuestoModel.php @@ -538,5 +538,172 @@ class PresupuestoModel extends \App\Models\BaseModel return $json; } + public function generarLineaPedido($presupuesto_id) + { + $builder = $this->db + ->table($this->table . " t1") + ->select( + "t1.id AS numero, t1.tipo_impresion_id as tipo, t1.tirada AS unidades, t1.total_aceptado as total, t1.paginas AS paginas, + t1.titulo AS titulo, t1.autor AS autor, t1.isbn AS isbn, + t1.papel_formato_id AS papel_formato_id, t1.papel_formato_personalizado AS papel_formato_personalizado, + t1.papel_formato_ancho AS papel_formato_ancho, t1.papel_formato_alto AS papel_formato_alto, + CONCAT(CAST(t2.ancho AS INT), 'x', CAST(t2.alto AS INT)) AS tamanio, + t3.codigo AS codigo_encuadernacion, + t1.solapas AS solapas_cubierta, CAST(t1.solapas_ancho AS INT) AS solapas_ancho_cubierta, + t1.solapas_sobrecubierta AS solapas_sobrecubierta, CAST(t1.solapas_ancho_sobrecubierta AS INT) AS solapas_ancho_sobrecubierta," + ); + $builder->join("lg_papel_formato t2", "t1.papel_formato_id = t2.id", "left"); + $builder->join("tipos_presupuestos t3", "t1.tipo_impresion_id = t3.id", "left"); + $builder->where("t1.is_deleted", 0); + $builder->where("t1.id", $presupuesto_id); + $presupuesto = $builder->get()->getResultObject(); + if(count($presupuesto) > 0){ + + $modelLinea = model('App\Models\Presupuestos\PresupuestoLineaModel'); + $lineas = $modelLinea->where('presupuesto_id', $presupuesto_id)->findAll(); + + $presupuesto = $presupuesto[0]; + + // Libro + if($presupuesto->tipo < 10){ + if($presupuesto->papel_formato_personalizado == 1){ + $presupuesto->tamanio= $presupuesto->papel_formato_ancho . "x" . $presupuesto->papel_formato_alto; + } + + $presupuesto->concepto = sprintf(lang('Pedidos.lineasTemplates.libro'), + $presupuesto->numero, + $presupuesto->unidades, + $presupuesto->paginas, + $presupuesto->titulo, + $presupuesto->autor, + $presupuesto->isbn, + $presupuesto->tamanio); + $presupuesto->concepto .= $this->generarConceptoLineasPresupuestoLibro($lineas, $presupuesto); + + $presupuesto = (object)[ + 'numero' => $presupuesto->numero, + 'unidades' => $presupuesto->unidades, + 'total' => $presupuesto->total, + 'concepto' => $presupuesto->concepto, + ]; + } + return [$presupuesto]; + } + + } + + private function generarConceptoLineasPresupuestoLibro($lineas, $presupuesto){ + + $model_papel = model('App\Models\Configuracion\PapelImpresionModel'); + $description_interior = ""; + $description_cubierta = ""; + $description_sobrecubierta = ""; + $paginas_negro = 0; + $paginas_color = 0; + $papel_negro = ""; + $papel_color = ""; + $gramaje_negro = 0; + $gramaje_color = 0; + + $lp_bn_lines = array_filter($lineas, function($linea) { + return strpos($linea->tipo, 'lp_bn') === 0; + }); + $lp_color_lines = array_filter($lineas, function($linea) { + return strpos($linea->tipo, 'lp_color') === 0; + }); + + $lp_rot_bn = array_filter($lineas, function($linea) { + return strpos($linea->tipo, 'lp_rot_bn') === 0; + }); + + $lp_rot_color = array_filter($lineas, function($linea) { + return strpos($linea->tipo, 'lp_rot_color') === 0; + }); + + if(count($lp_bn_lines) > 0){ + $lp_bn_lines = array_values($lp_bn_lines)[0]; + $paginas_negro = $lp_bn_lines->paginas; + $gramaje_negro = $lp_bn_lines->gramaje; + $papel_negro = $model_papel->where('id', $lp_bn_lines->papel_impresion_id)->first()->nombre; + $description_interior .= sprintf(lang('Pedidos.lineasTemplates.libro_linea_interior'), + strval($paginas_negro), + $papel_negro, + strval($gramaje_negro)) . ". "; + } + if(count($lp_color_lines) > 0){ + $lp_color_lines = array_values($lp_color_lines)[0]; + $paginas_color = $lp_color_lines->paginas; + $gramaje_color = $lp_color_lines->gramaje; + $papel_color = $model_papel->where('id', $lp_color_lines->papel_impresion_id)->first()->nombre; + $description_interior .= sprintf(lang('Pedidos.lineasTemplates.libro_linea_interior'), + strval($paginas_color), + $papel_color, + strval($gramaje_color)) . ". "; + } + + if(count($lp_rot_bn) > 0){ + $lp_rot_bn = array_values($lp_rot_bn)[0]; + $paginas_negro = $lp_rot_bn->paginas; + $gramaje_negro = $lp_rot_bn->gramaje; + $papel_negro = $model_papel->where('id', $lp_rot_bn->papel_impresion_id)->first()->nombre; + $description_interior .= sprintf(lang('Pedidos.lineasTemplates.libro_linea_interior'), + strval($paginas_negro), + $papel_negro, + strval($gramaje_negro)) . ". "; + } + + if(count($lp_rot_color) > 0){ + $lp_rot_color = array_values($lp_rot_color)[0]; + $paginas_negro = intval($lp_rot_color->paginas)-intval($lp_rot_color->rotativa_pag_color); + $gramaje = $lp_rot_color->gramaje; + $papel = $model_papel->where('id', $lp_rot_color->papel_impresion_id)->first()->nombre; + if($paginas_negro > 0){ + $description_interior .= sprintf(lang('Pedidos.lineasTemplates.libro_linea_interior'), + strval($paginas_negro), + $papel, + strval($gramaje)) . ". "; + } + + $description_interior .= sprintf(lang('Pedidos.lineasTemplates.libro_linea_interior'), + strval($lp_rot_color->rotativa_pag_color), + $papel, + strval($gramaje)) . ". "; + } + + $lp_cubierta = array_filter($lineas, function($linea) { + return strpos($linea->tipo, 'lp_cubierta') === 0; + }); + $lp_sobrecubierta = array_filter($lineas, function($linea) { + return strpos($linea->tipo, 'lp_sobrecubierta') === 0; + }); + + if(count($lp_cubierta) > 0){ + $lp_cubierta = array_values($lp_cubierta)[0]; + if($lp_cubierta->paginas == 2){ + $lp_cubierta->caras = lang('Pedidos.unaCara'); + } + else{ + $lp_cubierta->caras = lang('Pedidos.dosCaras'); + } + $description_cubierta = sprintf(lang('Pedidos.lineasTemplates.libro_linea_cubierta'), + $lp_cubierta->caras, + $model_papel->where('id', $lp_cubierta->papel_impresion_id)->first()->nombre, + strval($lp_cubierta->gramaje)); + $description_cubierta .= ($presupuesto->solapas_cubierta==1? sprintf(lang('Pedidos.lineasTemplates.libro_solapas'), $presupuesto->solapas_ancho_cubierta):". "); + } + if(count($lp_sobrecubierta) > 0){ + $lp_sobrecubierta = array_values($lp_sobrecubierta)[0]; + $description_sobrecubierta = sprintf(lang('Pedidos.lineasTemplates.libro_linea_sobrecubierta'), + $model_papel->where('id', $lp_sobrecubierta->papel_impresion_id)->first()->nombre, + strval($lp_sobrecubierta->gramaje)); + $description_sobrecubierta .= ($presupuesto->solapas_sobrecubierta==1? sprintf(lang('Pedidos.lineasTemplates.libro_solapas'), $presupuesto->solapas_ancho_sobrecubierta):". "); + } + + $acabado = sprintf(lang('Pedidos.lineasTemplates.libro_encuadernacion'), + lang('Presupuestos.' . $presupuesto->codigo_encuadernacion)); + + return $description_interior. $description_cubierta . $description_sobrecubierta . $acabado; + + } } diff --git a/ci4/app/Views/themes/vuexy/form/pedidos/_albaranesItems.php b/ci4/app/Views/themes/vuexy/form/pedidos/_albaranesItems.php new file mode 100644 index 00000000..d9024819 --- /dev/null +++ b/ci4/app/Views/themes/vuexy/form/pedidos/_albaranesItems.php @@ -0,0 +1,24 @@ +
+ +
+

+ +

+ +
+
+ + +
+
+
+
+ + +section('additionalInlineJs') ?> + + + +endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php b/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php index 19dac6f8..d1a0f0f9 100644 --- a/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php +++ b/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php @@ -27,7 +27,7 @@ @@ -60,7 +60,7 @@

@@ -95,7 +95,7 @@

diff --git a/ci4/app/Views/themes/vuexy/form/pedidos/_facturasItems.php b/ci4/app/Views/themes/vuexy/form/pedidos/_facturasItems.php new file mode 100644 index 00000000..c3871138 --- /dev/null +++ b/ci4/app/Views/themes/vuexy/form/pedidos/_facturasItems.php @@ -0,0 +1,24 @@ +
+ +
+

+ +

+ +
+
+ + +
+
+
+
+ + +section('additionalInlineJs') ?> + + + +endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/pedidos/_lineasItems.php b/ci4/app/Views/themes/vuexy/form/pedidos/_lineasItems.php index 132fdfb5..a28164e5 100644 --- a/ci4/app/Views/themes/vuexy/form/pedidos/_lineasItems.php +++ b/ci4/app/Views/themes/vuexy/form/pedidos/_lineasItems.php @@ -13,24 +13,21 @@ - - - - - - - - - - - - - + + + + + - + + + + + +
Total:
@@ -40,64 +37,97 @@ section('additionalInlineJs') ?> -$("#fecha_entrega_real").flatpickr({ - dateFormat: "d/m/Y", - locale: { - firstDayOfWeek: 1, - weekdays: { - shorthand: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'], - longhand: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'], - }, - months: { - shorthand: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Оct', 'Nov', 'Dic'], - longhand: ['Enero', 'Febreo', 'Мarzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], +const lastColNr = $('#tableOfLineasPedido').find("tr:first th").length - 1; +const viewPresupuestoBtns = function(data) { + return ` + +
+ +
+ `; +}; + +var tableOfLineasPedido = new DataTable('#tableOfLineasPedido',{ + processing: true, + serverSide: true, + autoWidth: true, + responsive: true, + scrollX: true, + searchable: false, + info: false, + dom: '', + language: { + url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" + }, + ajax : $.fn.dataTable.pipeline( { + url: '', + data: function ( d ) { + d.pedido_id = id ?>; }, + method: 'POST', + headers: {'X-Requested-With': 'XMLHttpRequest'}, + async: true, + }), + columnDefs: [ + { + targets: 0, + orderable: false, + data: null, + defaultContent: '' }, + { + targets: [1,2,3], + orderable: false, + }, + ], + columns: [ + { + data: viewPresupuestoBtns, + className: 'dt-center' + }, + {data: 'unidades'}, + {data: 'concepto'}, + {data: 'total'}, + ], + footerCallback: function (row, data, start, end, display) { + let api = this.api(); + + // Remove the formatting to get integer data for summation + let intVal = function (i) { + return typeof i === 'string' + ? i.replace(/[\$,]/g, '') * 1 + : typeof i === 'number' + ? i + : 0; + }; + + // Total over all pages + total = api + .column(3) + .data() + .reduce((a, b) => intVal(a) + intVal(b), 0); + + // Update footer + api.column(3).footer().innerHTML = + 'Total: ' + total; + } }); -$("#fecha_impresion").flatpickr({ - dateFormat: "d/m/Y", - locale: { - firstDayOfWeek: 1, - weekdays: { - shorthand: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'], - longhand: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'], - }, - months: { - shorthand: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Оct', 'Nov', 'Dic'], - longhand: ['Enero', 'Febreo', 'Мarzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], - }, - }, -}); -$("#fecha_encuadernado").flatpickr({ - dateFormat: "d/m/Y", - locale: { - firstDayOfWeek: 1, - weekdays: { - shorthand: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'], - longhand: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'], - }, - months: { - shorthand: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Оct', 'Nov', 'Dic'], - longhand: ['Enero', 'Febreo', 'Мarzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], - }, - }, -}); -$("#fecha_entrega_externo").flatpickr({ - dateFormat: "d/m/Y", - locale: { - firstDayOfWeek: 1, - weekdays: { - shorthand: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'], - longhand: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'], - }, - months: { - shorthand: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Оct', 'Nov', 'Dic'], - longhand: ['Enero', 'Febreo', 'Мarzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], - }, - }, + +$(document).on('click', '.btn-view', function(e) { + user()->inGroup('admin') || auth()->user()->inGroup('beta')): ?> + var url = ''; + + var url = ''; + + url = url.replace(':id', `${$(this).attr('data-id')}` ); + console.log(url); + window.open( + url, + '_blank' // <- This is what makes it open in a new window. + ); }); endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidoForm.php b/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidoForm.php index b65da3c8..4b8e3f10 100644 --- a/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidoForm.php +++ b/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidoForm.php @@ -17,6 +17,8 @@ getErrors()) ? $validation->listErrors("bootstrap_style") : "" ?> + +
"btn btn-secondary float-start"]) ?> @@ -30,9 +32,18 @@ section('css') ?> "> + "> endSection() ?> section('additionalExternalJs') ?> + + + + + + + + endSection() ?> From 3e0443927c62d9d145c624e3897dcf3419afdc54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Fri, 14 Jun 2024 15:04:41 +0200 Subject: [PATCH 06/10] trabajando --- ci4/app/Config/Routes.php | 6 + ci4/app/Controllers/Facturacion/Albaran.php | 30 ----- ci4/app/Controllers/Pedidos/Albaran.php | 63 +++++++++++ ci4/app/Controllers/Pedidos/Pedido.php | 2 +- ci4/app/Entities/Pedidos/AlbaranEntity.php | 46 ++++++++ .../Entities/Pedidos/AlbaranLineaEntity.php | 33 ++++++ ci4/app/Language/en/Pedidos.php | 2 + ci4/app/Language/es/Pedidos.php | 2 + ci4/app/Models/Pedidos/AlbaranLineaModel.php | 34 ++++++ ci4/app/Models/Pedidos/AlbaranModel.php | 103 ++++++++++++++++++ .../vuexy/form/pedidos/_albaranesItems.php | 30 +++++ .../vuexy/form/pedidos/_lineasItems.php | 45 ++++---- 12 files changed, 346 insertions(+), 50 deletions(-) delete mode 100755 ci4/app/Controllers/Facturacion/Albaran.php create mode 100644 ci4/app/Controllers/Pedidos/Albaran.php create mode 100644 ci4/app/Entities/Pedidos/AlbaranEntity.php create mode 100644 ci4/app/Entities/Pedidos/AlbaranLineaEntity.php create mode 100644 ci4/app/Models/Pedidos/AlbaranLineaModel.php create mode 100644 ci4/app/Models/Pedidos/AlbaranModel.php diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index e3b35125..34e261bc 100755 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -632,6 +632,12 @@ $routes->group('pedidos', ['namespace' => 'App\Controllers\Pedidos'], function ( $routes->resource('pedidos', ['namespace' => 'App\Controllers\Pedidos', 'controller' => 'Pedido', 'except' => 'show,new,create,update']); +$routes->group('albaranes', ['namespace' => 'App\Controllers\Pedidos'], function ($routes) { + $routes->post('add', 'Albaran::add', ['as' => 'crearAlbaranesPedido']); +}); +$routes->resource('albaranes', ['namespace' => 'App\Controllers\Pedidos', 'controller' => 'Albaran', 'except' => 'show,new,create,update']); + + $routes->group( 'printpresupuestos', diff --git a/ci4/app/Controllers/Facturacion/Albaran.php b/ci4/app/Controllers/Facturacion/Albaran.php deleted file mode 100755 index cc91f085..00000000 --- a/ci4/app/Controllers/Facturacion/Albaran.php +++ /dev/null @@ -1,30 +0,0 @@ -request->isAJAX()) { + + $user = auth()->user()->id; + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + $reqData = $this->request->getPost(); + $pedido_id = $reqData['pedido_id'] ?? 0; + $presupuestos_id = $reqData['presupuestos_id'] ?? 0; + + $return_data = $this->model->generarAlbaranes($pedido_id, $presupuestos_id, $user); + $data = [ + 'data' => $return_data, + $csrfTokenName => $newTokenHash + ]; + + return $this->respond($data); + + } + else { + return $this->failUnauthorized('Invalid request', 403); + } + + + } + +} + \ No newline at end of file diff --git a/ci4/app/Controllers/Pedidos/Pedido.php b/ci4/app/Controllers/Pedidos/Pedido.php index c08bc6b7..1fa366fd 100755 --- a/ci4/app/Controllers/Pedidos/Pedido.php +++ b/ci4/app/Controllers/Pedidos/Pedido.php @@ -24,7 +24,7 @@ class Pedido extends \App\Controllers\BaseResourceController public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { - $this->viewData['pageTitle'] = lang('Tarifaextra.moduleTitle'); + $this->viewData['pageTitle'] = lang('Pedidos.moduleTitle'); // Se indica que este controlador trabaja con soft_delete $this->viewData = ['usingServerSideDataTable' => true]; diff --git a/ci4/app/Entities/Pedidos/AlbaranEntity.php b/ci4/app/Entities/Pedidos/AlbaranEntity.php new file mode 100644 index 00000000..c07449f7 --- /dev/null +++ b/ci4/app/Entities/Pedidos/AlbaranEntity.php @@ -0,0 +1,46 @@ + null, + 'pedido_id' => null, + 'presupuesto_id' => null, + 'presupuesto_direccion_id' => null, + 'cliente_id' => null, + 'serie_id' => null, + 'numero_albaran' => null, + 'mostar_precios' => null, + 'total' => null, + 'direccion_albaran' => null, + 'att_albaran' => null, + 'user_created_id' => null, + 'user_updated_id' => null, + 'created_at' => null, + 'updated_at' => null, + 'deleted_at' => null, + ]; + + protected $dates = ['created_at', 'updated_at', 'deleted_at']; + + protected $casts = [ + 'id' => 'integer', + 'pedido_id' => '?integer', + 'presupuesto_id' => '?integer', + 'presupuesto_direccion_id' => '?integer', + 'cliente_id' => '?integer', + 'serie_id' => '?integer', + 'numero_albaran' => '?string', + 'mostar_precios' => '?boolean', + 'total' => 'float', + 'direccion_albaran' => '?string', + 'att_albaran' => '?string', + 'user_created_id' => 'integer', + 'user_updated_id' => 'integer', + ]; + + // Agrega tus métodos personalizados aquí +} diff --git a/ci4/app/Entities/Pedidos/AlbaranLineaEntity.php b/ci4/app/Entities/Pedidos/AlbaranLineaEntity.php new file mode 100644 index 00000000..de5bda52 --- /dev/null +++ b/ci4/app/Entities/Pedidos/AlbaranLineaEntity.php @@ -0,0 +1,33 @@ + null, + 'albaran_id' => null, + 'titulo' => null, + 'isbn' => null, + 'ref_cliente' => null, + 'cantidad' => null, + 'cajas' => null, + 'ejemplares_por_caja' => null, + 'precio_unidad' => null, + 'total' => null, + ]; + + protected $casts = [ + 'id' => 'integer', + 'albaran_id' => '?integer', + 'titulo' => 'string', + 'isbn' => '?string', + 'ref_cliente' => '?string', + 'cantidad' => '?integer', + 'cajas' => '?integer', + 'ejemplares_por_caja' => '?integer', + 'precio_unidad' => 'float', + 'total' => 'float', + ]; +} \ No newline at end of file diff --git a/ci4/app/Language/en/Pedidos.php b/ci4/app/Language/en/Pedidos.php index 83a6714b..d0d4f8bd 100644 --- a/ci4/app/Language/en/Pedidos.php +++ b/ci4/app/Language/en/Pedidos.php @@ -58,6 +58,8 @@ return [ ], 'albaranes' => 'Delivery Notes', + 'generarAlbaranes' => 'Generate delivery notes', + 'borrarAlbaranes' => 'Delete delivery notes', 'facturas' => 'Invoices', diff --git a/ci4/app/Language/es/Pedidos.php b/ci4/app/Language/es/Pedidos.php index 5237a09d..f8f9d409 100644 --- a/ci4/app/Language/es/Pedidos.php +++ b/ci4/app/Language/es/Pedidos.php @@ -57,6 +57,8 @@ return [ ], 'albaranes' => 'Albaranes', + 'generarAlbaranes' => 'Generar albaranes', + 'borrarAlbaranes' => 'Borrar albaranes', 'facturas' => 'Facturas', diff --git a/ci4/app/Models/Pedidos/AlbaranLineaModel.php b/ci4/app/Models/Pedidos/AlbaranLineaModel.php new file mode 100644 index 00000000..e7d7a757 --- /dev/null +++ b/ci4/app/Models/Pedidos/AlbaranLineaModel.php @@ -0,0 +1,34 @@ +find($presupuestos_id); + + foreach ($presupuestos as $presupuesto) { + + $envios = $model_presupuesto_direcciones->where('presupuesto_id', $presupuesto->id)->findAll(); + foreach($envios as $envio){ + + // calculo precio_unidad + $precio_unidad = $presupuesto->total_aceptado/$presupuesto->tirada; + + $albaran_linea = []; + $albaran_linea = array( + 'titulo' => $presupuesto->titulo, + 'isbn' => $presupuesto->isbn, + 'ref_cliente' => $presupuesto->ref_cliente, + 'cantidad' => $envio->cantidad, + 'cajas' => 1, + 'ejemplares_por_caja' => $envio->cantidad, + 'precio_unidad' => $precio_unidad, + 'total' => $precio_unidad * $envio->cantidad + ); + + + $serie = $model_series->find(11); + $numero_albaran = str_replace($serie->next, 'number', $serie->formato); + $numero_albaran = str_replace(date("Y"), 'year', $numero_albaran); + + $serie->next = $serie->next + 1; + $model_series->save($serie); + + $albaran = array( + 'pedido_id' => $pedido_id, + 'presupuesto_id' => $presupuesto->id, + 'presupuesto_direccion_id' => $envio->id, + 'cliente_id' => $presupuesto->cliente_id, + 'serie_id' => 11, // Serie de albaranes + 'numero_albaran' => $numero_albaran, + 'mostar_precios' => 0, + 'total' => $albaran_linea['total'], + 'direccion_albaran' => $envio->direccion, + 'att_albaran' => $envio->att, + 'created_at' => date("Y-m-d H:i:s"), + 'updated_at' => date("Y-m-d H:i:s"), + 'user_created_id' => $user_id, + 'user_updated_id' => $user_id + ); + + $id_albaran = $this->insert($albaran); + $model_albaran_linea = model('App\Models\Pedidos\AlbaranLineaModel'); + $model_albaran_linea->insert($albaran_linea); + + return $id_albaran; + } + } + + return 0; + } +} \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/pedidos/_albaranesItems.php b/ci4/app/Views/themes/vuexy/form/pedidos/_albaranesItems.php index d9024819..01fcd952 100644 --- a/ci4/app/Views/themes/vuexy/form/pedidos/_albaranesItems.php +++ b/ci4/app/Views/themes/vuexy/form/pedidos/_albaranesItems.php @@ -10,6 +10,18 @@
+ +
+
+ + +
+ +
+ + +
+
@@ -19,6 +31,24 @@ section('additionalInlineJs') ?> +$('#generar_albaranes').on('click', function(){ + + var lineasPedido = $('#tableOfLineasPedido').DataTable(); + var presupuestos = lineasPedido.column(0).data().unique().toArray(); + + $.ajax({ + url: '', + type: 'POST', + data: { + pedido_id: id ?>, + presupuestos_id: presupuestos, + : v, + }, + success: function(response){ + console.log(response); + } + }); +}) endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/pedidos/_lineasItems.php b/ci4/app/Views/themes/vuexy/form/pedidos/_lineasItems.php index a28164e5..9665e763 100644 --- a/ci4/app/Views/themes/vuexy/form/pedidos/_lineasItems.php +++ b/ci4/app/Views/themes/vuexy/form/pedidos/_lineasItems.php @@ -13,8 +13,9 @@ + - + @@ -25,7 +26,7 @@ - +
Total:Total:
@@ -37,7 +38,6 @@ section('additionalInlineJs') ?> -const lastColNr = $('#tableOfLineasPedido').find("tr:first th").length - 1; const viewPresupuestoBtns = function(data) { return ` @@ -55,7 +55,7 @@ var tableOfLineasPedido = new DataTable('#tableOfLineasPedido',{ scrollX: true, searchable: false, info: false, - dom: '', + dom: 't', language: { url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" }, @@ -68,19 +68,8 @@ var tableOfLineasPedido = new DataTable('#tableOfLineasPedido',{ headers: {'X-Requested-With': 'XMLHttpRequest'}, async: true, }), - columnDefs: [ - { - targets: 0, - orderable: false, - data: null, - defaultContent: '' - }, - { - targets: [1,2,3], - orderable: false, - }, - ], columns: [ + {data: 'numero'}, { data: viewPresupuestoBtns, className: 'dt-center' @@ -89,6 +78,24 @@ var tableOfLineasPedido = new DataTable('#tableOfLineasPedido',{ {data: 'concepto'}, {data: 'total'}, ], + columnDefs: [ + { + targets: 0, + visible: false, + orderable: false, + searchable: false + }, + { + targets: 1, + orderable: false, + data: null, + defaultContent: '' + }, + { + targets: [2,3,4], + orderable: false, + }, + ], footerCallback: function (row, data, start, end, display) { let api = this.api(); @@ -103,14 +110,14 @@ var tableOfLineasPedido = new DataTable('#tableOfLineasPedido',{ // Total over all pages total = api - .column(3) + .column(4) .data() .reduce((a, b) => intVal(a) + intVal(b), 0); // Update footer - api.column(3).footer().innerHTML = + api.column(4).footer().innerHTML = 'Total: ' + total; - } + }, }); From 87e6b029e279b87a022a72b71525a053711a8eb9 Mon Sep 17 00:00:00 2001 From: jaimejimenezortega Date: Sat, 15 Jun 2024 11:14:02 +0200 Subject: [PATCH 07/10] falta mostrar precios albaran --- ci4/app/Language/en/Pedidos.php | 7 + ci4/app/Language/es/Pedidos.php | 7 + ci4/app/Models/Pedidos/AlbaranLineaModel.php | 4 - ci4/app/Models/Pedidos/AlbaranModel.php | 28 +- .../vuexy/form/pedidos/_albaranesItems.php | 372 +++++++++++++++++- .../vuexy/form/pedidos/viewPedidoForm.php | 1 + 6 files changed, 400 insertions(+), 19 deletions(-) diff --git a/ci4/app/Language/en/Pedidos.php b/ci4/app/Language/en/Pedidos.php index d0d4f8bd..3a7518f3 100644 --- a/ci4/app/Language/en/Pedidos.php +++ b/ci4/app/Language/en/Pedidos.php @@ -58,8 +58,15 @@ return [ ], 'albaranes' => 'Delivery Notes', + 'albaran' => 'Delivery Note', 'generarAlbaranes' => 'Generate delivery notes', 'borrarAlbaranes' => 'Delete delivery notes', + 'att' => "Att", + 'direccion' => 'Address', + 'borrarAlbaran' => 'Delete delivery note', + 'imprimirAlbaran' => 'Print', + 'nuevaLinea' => 'New line', + 'addIva' => "Add VAT", 'facturas' => 'Invoices', diff --git a/ci4/app/Language/es/Pedidos.php b/ci4/app/Language/es/Pedidos.php index f8f9d409..c37f9dc4 100644 --- a/ci4/app/Language/es/Pedidos.php +++ b/ci4/app/Language/es/Pedidos.php @@ -57,8 +57,15 @@ return [ ], 'albaranes' => 'Albaranes', + 'albaran' => 'Albarán', 'generarAlbaranes' => 'Generar albaranes', 'borrarAlbaranes' => 'Borrar albaranes', + 'att' => "Att", + 'direccion' => 'Direccion', + 'borrarAlbaran' => 'Borrar albarán', + 'imprimirAlbaran' => 'Imprimir', + 'nuevaLinea' => 'Nueva línea', + 'addIva' => "Añadir IVA", 'facturas' => 'Facturas', diff --git a/ci4/app/Models/Pedidos/AlbaranLineaModel.php b/ci4/app/Models/Pedidos/AlbaranLineaModel.php index e7d7a757..a384fb22 100644 --- a/ci4/app/Models/Pedidos/AlbaranLineaModel.php +++ b/ci4/app/Models/Pedidos/AlbaranLineaModel.php @@ -26,9 +26,5 @@ class AlbaranLineaModel extends \App\Models\BaseModel 'precio_unidad', 'total', ]; - - protected $useTimestamps = true; - protected $createdField = 'created_at'; - protected $updatedField = 'updated_at'; } \ No newline at end of file diff --git a/ci4/app/Models/Pedidos/AlbaranModel.php b/ci4/app/Models/Pedidos/AlbaranModel.php index 7fd30c73..87923a9b 100644 --- a/ci4/app/Models/Pedidos/AlbaranModel.php +++ b/ci4/app/Models/Pedidos/AlbaranModel.php @@ -45,6 +45,8 @@ class AlbaranModel extends \App\Models\BaseModel $presupuestos = $model_presupuesto->find($presupuestos_id); + $return_data = []; + foreach ($presupuestos as $presupuesto) { $envios = $model_presupuesto_direcciones->where('presupuesto_id', $presupuesto->id)->findAll(); @@ -54,7 +56,7 @@ class AlbaranModel extends \App\Models\BaseModel $precio_unidad = $presupuesto->total_aceptado/$presupuesto->tirada; $albaran_linea = []; - $albaran_linea = array( + $albaran_linea = [ 'titulo' => $presupuesto->titulo, 'isbn' => $presupuesto->isbn, 'ref_cliente' => $presupuesto->ref_cliente, @@ -63,17 +65,17 @@ class AlbaranModel extends \App\Models\BaseModel 'ejemplares_por_caja' => $envio->cantidad, 'precio_unidad' => $precio_unidad, 'total' => $precio_unidad * $envio->cantidad - ); + ]; $serie = $model_series->find(11); - $numero_albaran = str_replace($serie->next, 'number', $serie->formato); - $numero_albaran = str_replace(date("Y"), 'year', $numero_albaran); + $numero_albaran = str_replace('{number}', $serie->next, $serie->formato); + $numero_albaran = str_replace( '{year}', date("Y"), $numero_albaran); $serie->next = $serie->next + 1; $model_series->save($serie); - $albaran = array( + $albaran = [ 'pedido_id' => $pedido_id, 'presupuesto_id' => $presupuesto->id, 'presupuesto_direccion_id' => $envio->id, @@ -84,20 +86,22 @@ class AlbaranModel extends \App\Models\BaseModel 'total' => $albaran_linea['total'], 'direccion_albaran' => $envio->direccion, 'att_albaran' => $envio->att, - 'created_at' => date("Y-m-d H:i:s"), - 'updated_at' => date("Y-m-d H:i:s"), 'user_created_id' => $user_id, - 'user_updated_id' => $user_id - ); + 'user_updated_id' => $user_id, + 'fecha_albaran' => date('d/m/Y'), + ]; $id_albaran = $this->insert($albaran); $model_albaran_linea = model('App\Models\Pedidos\AlbaranLineaModel'); - $model_albaran_linea->insert($albaran_linea); + $albaran['id'] = $id_albaran; + $albaran_linea['albaran_id'] = $id_albaran; + $id_albaran_linea =$model_albaran_linea->insert($albaran_linea); + $albaran_linea['id'] = $id_albaran_linea; - return $id_albaran; + array_push($return_data, ["albaran"=>$albaran, "albaran_linea" =>$albaran_linea]); } } - return 0; + return $return_data; } } \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/pedidos/_albaranesItems.php b/ci4/app/Views/themes/vuexy/form/pedidos/_albaranesItems.php index 01fcd952..a8fba5ed 100644 --- a/ci4/app/Views/themes/vuexy/form/pedidos/_albaranesItems.php +++ b/ci4/app/Views/themes/vuexy/form/pedidos/_albaranesItems.php @@ -8,10 +8,10 @@
-
+
-
+
@@ -45,10 +45,376 @@ $('#generar_albaranes').on('click', function(){ : v, }, success: function(response){ - console.log(response); + + if(response.data.length > 0){ + Object.values(response.data).forEach(function(item){ + generarAlbaran(item); + }); + } } }); }) +const deleteLineaBtns = function(data) { + return ` + +
+ +
+ `; +}; + +function generarAlbaran(item){ + + // Crear los elementos necesarios + const accordion = $('
', { + class: 'accordion accordion-bordered mt-3', + id: 'albaran' + item.albaran_linea.id + }); + + const card = $('
', { + class: 'card accordion-item active' + }); + + const header = $('

', { + class: 'accordion-header', + id: 'headingAlbaran' + item.albaran_linea.id + }); + + const button = $('