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; });