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 @@
| = lang('Pedidos.presupuesto') ?> | -=lang('Pedidos.unidades')?> | += lang('Pedidos.unidades')?> | = lang('Pedidos.concepto') ?> | = lang('Pedidos.total') ?> | ||||
|---|---|---|---|---|---|---|---|---|
| Total: | +Total: | |||||||