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()) { + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + $model_linea = model('App\Models\Pedidos\AlbaranLineaModel'); + $model_linea->where('albaran_id', $id)->delete(); + + $this->model->where('id', $id)->delete(); + + $data = [ + 'error' => 0, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + } + else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + public function addLinea($albaran_id){ + + if ($this->request->isAJAX()) { + + $model_linea = model('App\Models\Pedidos\AlbaranLineaModel'); + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + // si es un post, es el iva + if($this->request->getPost()){ + $reqData = $this->request->getPost(); + $albaran_id = $reqData['albaran_id'] ?? 0; + + $albaran = $this->model->find($albaran_id); + if($albaran == false){ + $data = [ + 'error' => 'Albaran no encontrado', + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + } + $presupuesto_model = model('App\Models\Presupuestos\PresupuestoModel'); + $presupuesto = $presupuesto_model->find($albaran->presupuesto_id); + if($presupuesto == false){ + $data = [ + 'error' => 'Presupuesto no encontrado', + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + } + $iva_reducido = $presupuesto->iva_reducido; + $lineas = $model_linea->where('albaran_id', $albaran_id)->findAll(); + $total = 0; + foreach($lineas as $linea){ + $total += $linea->total; + } + $iva = $iva_reducido? $total * 4.0 / 100: $total * 21.0 / 100; + $data_linea= [ + 'albaran_id' => $albaran_id, + 'titulo' => $iva_reducido?lang('Pedidos.iva4'):lang('Pedidos.iva21'), + 'cantidad' => 1, + 'precio_unidad' => round($iva,2), + 'total' => round($iva,2), + 'user_created_id' => auth()->user()->id, + 'user_updated_id' => auth()->user()->id + ]; + $id_linea = $model_linea->insert($data_linea); + $linea = $model_linea->find($id_linea); + $data = [ + 'error' => 0, + 'data' => $linea, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + } + else{ + $linea = [ + 'albaran_id' => $albaran_id, + 'user_created_id' => auth()->user()->id, + 'user_updated_id' => auth()->user()->id + ]; + $id_linea = $model_linea->insert($linea); + $data = $model_linea->find($id_linea); + + $data = [ + 'error' => 0, + 'data' => $data, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + } + } + else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + public function add() + { + if ($this->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); + } + } + + public function update($id = null){ + + if ($this->request->isAJAX()) { + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + if ($id == null) : + $data = [ + 'error' => 2, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + endif; + $id = filter_var($id, FILTER_SANITIZE_URL); + $albaranEntity = $this->model->find($id); + + if ($albaranEntity == false) : + $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.albaran')), $id]); + $data = [ + 'error' => $message, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + endif; + + if ($this->request->getPost()) : + + $nullIfEmpty = true; // !(phpversion() >= '8.1'); + + $postData = $this->request->getPost(); + + $sanitizedData = $this->sanitized($postData, $nullIfEmpty); + + // JJO + $sanitizedData['user_updated_id'] = auth()->user()->id; + + $noException = true; + if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : + + if ($this->canValidate()) : + try { + $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); + } catch (\Exception $e) { + $noException = false; + $this->dealWithException($e); + } + else: + $this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Pedidos.albaran'))]); + $this->session->setFlashdata('formErrors', $this->model->errors()); + + endif; + + $albaranEntity->fill($sanitizedData); + + endif; + if ($noException && $successfulResult) : + $id = $albaranEntity->id ?? $id; + $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.'; + + $data = [ + 'error' => 0, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + + endif; // $noException && $successfulResult + endif; // ($requestMethod === 'post') + + $data = [ + 'error' => 1, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + } + else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + + public function updateLinea($id = null){ + + if ($this->request->isAJAX()) { + + $model_linea = model('App\Models\Pedidos\AlbaranLineaModel'); + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + if ($id == null) : + $data = [ + 'error' => 2, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + endif; + $id = filter_var($id, FILTER_SANITIZE_URL); + $albaranEntity = $model_linea->find($id); + + if ($albaranEntity == false) : + $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.albaran')), $id]); + $data = [ + 'error' => $message, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + endif; + + if ($this->request->getPost()) : + + $nullIfEmpty = true; // !(phpversion() >= '8.1'); + + $postData = $this->request->getPost(); + + $sanitizedData = $this->sanitized($postData, $nullIfEmpty); + + // JJO + $sanitizedData['user_updated_id'] = auth()->user()->id; + + $noException = true; + if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : + + if ($this->canValidate()) : + try { + $successfulResult = $model_linea->skipValidation(true)->update($id, $sanitizedData); + } catch (\Exception $e) { + $noException = false; + $this->dealWithException($e); + } + else: + $this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Pedidos.albaran'))]); + $this->session->setFlashdata('formErrors', $model_linea->errors()); + + endif; + + $albaranEntity->fill($sanitizedData); + + endif; + if ($noException && $successfulResult) : + $id = $albaranEntity->id ?? $id; + $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.'; + + $data = [ + 'error' => 0, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + + endif; // $noException && $successfulResult + endif; // ($requestMethod === 'post') + + $data = [ + 'error' => 1, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + } + else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + public function borrarLinea(){ + if ($this->request->isAJAX()) { + + $model_linea = model('App\Models\Pedidos\AlbaranLineaModel'); + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + $reqData = $this->request->getPost(); + $id = $reqData['id'] ?? 0; + $id = filter_var($id, FILTER_SANITIZE_URL); + $albaranLineaEntity = $model_linea->find($id); + + if ($albaranLineaEntity == false) : + $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.albaran')), $id]); + $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.albaran')), $id]); + $data = [ + 'error' => $message, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + endif; + + $successfulResult = $model_linea->skipValidation(true)->update($id, ['deleted_at' => date('Y-m-d H:i:s')]); + + if ($successfulResult) : + $data = [ + 'error' => 0, + $csrfTokenName => $newTokenHash + ]; + else: + $data = [ + 'error' => 1, + $csrfTokenName => $newTokenHash + ]; + endif; + return $this->respond($data); + } + else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + public function getAlbaranes($pedido_id = null){ + if ($this->request->isAJAX()) { + + $model_linea = model('App\Models\Pedidos\AlbaranLineaModel'); + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + $returnData = []; + $albaranes = $this->model->asArray()->where('pedido_id', $pedido_id)->findAll(); + + foreach($albaranes as $albaran){ + $albaran['fecha_albaran'] = $albaran['updated_at']; + array_push($returnData, + [ + 'albaran' => $albaran, + 'lineas' => $model_linea->asArray()->where('albaran_id', $albaran['id'])->findAll()] + ); + } + + $data = [ + 'data' => $returnData, + $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 af9c7953..93e41170 100755 --- a/ci4/app/Controllers/Pedidos/Pedido.php +++ b/ci4/app/Controllers/Pedidos/Pedido.php @@ -2,54 +2,301 @@ 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('Pedidos.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], + ]; + + 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() { - echo 'Pedidos Activos'; + $viewData = [ + 'currentModule' => static::$controllerSlug, + 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Pedidos.pedido')]), + 'presupuestoEntity' => new PedidoEntity(), + 'usingServerSideDataTable' => true, + 'pageTitle' => lang('Pedidos.Pedidos'), + 'estadoPedidos' => 'activo', + ['title' => lang("App.menu_pedidos"), 'route' => site_url('pedidos/todos'), 'active' => true] + ]; + + return view(static::$viewPath . 'viewPedidosList', $viewData); } public function finalizados() { - echo 'Pedidos Finalizados'; + $viewData = [ + 'currentModule' => static::$controllerSlug, + 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Pedidos.pedido')]), + 'presupuestoEntity' => new PedidoEntity(), + 'usingServerSideDataTable' => true, + 'pageTitle' => lang('Pedidos.Pedidos'), + 'estadoPedidos' => 'finalizado', + ['title' => lang("App.menu_pedidos"), 'route' => site_url('pedidos/todos'), 'active' => true] + ]; + + return view(static::$viewPath . 'viewPedidosList', $viewData); } public function cancelados() { - echo 'Pedidos Cancelados'; + $viewData = [ + 'currentModule' => static::$controllerSlug, + 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Pedidos.pedido')]), + 'presupuestoEntity' => new PedidoEntity(), + 'usingServerSideDataTable' => true, + 'pageTitle' => lang('Pedidos.Pedidos'), + 'estadoPedidos' => 'cancelado', + ['title' => lang("App.menu_pedidos"), 'route' => site_url('pedidos/todos'), 'active' => true] + ]; + + return view(static::$viewPath . 'viewPedidosList', $viewData); } - 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 cambiarEstado(){ + if($this->request->isAJAX()){ + $id = $this->request->getPost('id'); + $estado = $this->request->getPost('estado'); + + $this->model->where('id', $id)->set(['estado' => $estado])->update(); + return $this->respond(['status' => 'success', 'message' => lang('Basic.global.success')]); + }else{ + return $this->failUnauthorized('Invalid request', 403); + } + } + + + public function update($id = null){ + + if ($this->request->isAJAX()) { + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + if ($id == null) : + $data = [ + 'error' => 2, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + 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]); + $data = [ + 'error' => $message, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + endif; + + if ($this->request->getPost()) : + + $nullIfEmpty = true; // !(phpversion() >= '8.1'); + + $postData = $this->request->getPost(); + + $sanitizedData = $this->sanitized($postData, $nullIfEmpty); + + // JJO + $sanitizedData['user_updated_id'] = auth()->user()->id; + + $noException = true; + if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : + + if ($this->canValidate()) : + try { + $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); + } catch (\Exception $e) { + $noException = false; + $this->dealWithException($e); + } + else: + $this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Pedidos.albaran'))]); + $this->session->setFlashdata('formErrors', $this->model->errors()); + + endif; + + $pedidoEntity->fill($sanitizedData); + + endif; + if ($noException && $successfulResult) : + $id = $pedidoEntity->id ?? $id; + $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.'; + + $data = [ + 'error' => 0, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + + endif; // $noException && $successfulResult + endif; // ($requestMethod === 'post') + + $data = [ + 'error' => 1, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + } + else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + public function edit($id=null){ + + 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(){ + + 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_TODOS[$requestedOrder >= 0 ? $requestedOrder : 0]; + $dir = $reqData['order']['0']['dir'] ?? 'asc'; + $estado = $reqData['estado'] ?? 'todos'; + if($estado == 'todos') $estado = ''; + + $model_linea = model('\App\Models\Pedidos\PedidoLineaModel'); + $resourceData = $model_linea->getResource($search, $estado)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); + + return $this->respond(Collection::datatable( + $resourceData, + $model_linea->getResource("", $estado)->countAllResults(), + $model_linea->getResource($search, $estado)->countAllResults() + )); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + 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); + + $pedidoEntity->estadoText = lang('Pedidos.' . $pedidoEntity->estado); + + if(count($datos) > 0){ + $pedidoEntity->cliente = $datos[0]->cliente; + $pedidoEntity->cliente_id = $datos[0]->cliente_id; + $pedidoEntity->comercial = $datos[0]->comercial; + } + + $pedidoEntity->fecha_entrega_real_text = $pedidoEntity->fecha_entrega_real ? date('d/m/Y', strtotime($pedidoEntity->fecha_entrega_real)) : ''; + $pedidoEntity->fecha_impresion_text = $pedidoEntity->fecha_impresion ? date('d/m/Y', strtotime($pedidoEntity->fecha_impresion)) : ''; + $pedidoEntity->fecha_encuadernado_text = $pedidoEntity->fecha_encuadernado ? date('d/m/Y', strtotime($pedidoEntity->fecha_encuadernado)) : ''; + $pedidoEntity->fecha_entrega_externo_text = $pedidoEntity->fecha_entrega_externo ? date('d/m/Y', strtotime($pedidoEntity->fecha_entrega_externo)) : ''; + } } \ 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/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/Entities/Pedidos/AlbaranEntity.php b/ci4/app/Entities/Pedidos/AlbaranEntity.php new file mode 100644 index 00000000..bdff8334 --- /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, + 'mostrar_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', + 'mostrar_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..c2137df8 --- /dev/null +++ b/ci4/app/Entities/Pedidos/AlbaranLineaEntity.php @@ -0,0 +1,40 @@ + null, + 'albaran_id' => null, + 'titulo' => null, + 'isbn' => null, + 'ref_cliente' => null, + 'cantidad' => null, + 'cajas' => null, + 'ejemplares_por_caja' => null, + 'precio_unidad' => null, + 'total' => null, + 'user_created_id' => null, + 'user_updated_id' => null, + 'created_at' => null, + 'updated_at' => null, + 'deleted_at' => 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', + 'user_created_id' => 'integer', + 'user_updated_id' => 'integer', + ]; +} \ 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..0e58640a --- /dev/null +++ b/ci4/app/Language/en/Pedidos.php @@ -0,0 +1,82 @@ + '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', + + 'validacion' => 'Validation', + 'produccion' => 'Production', + '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', + 'unidades' => "Units", + 'concepto' => "Concept", + 'total' => "Total", + 'presupuesto' => 'Budget', + + 'moduleTitle' => 'Orders', + 'pedido' => 'Order', + 'pedidos' => 'Orders', + 'pedidosList' => 'Orders List', + + 'cancelar' => 'Cancel', + 'finalizar' => 'Finish', + + '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', + '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", + 'mostrarPrecios' => 'Show prices', + 'iva4' => "4,00 % VAT", + 'iva21' => "21,00 % VAT", + + 'facturas' => 'Invoices', + + 'validation' => [ + + ], +]; \ No newline at end of file diff --git a/ci4/app/Language/es/App.php b/ci4/app/Language/es/App.php index 3806b8cb..15882bbe 100755 --- a/ci4/app/Language/es/App.php +++ b/ci4/app/Language/es/App.php @@ -739,7 +739,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..5e790760 --- /dev/null +++ b/ci4/app/Language/es/Pedidos.php @@ -0,0 +1,84 @@ + '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', + + 'validacion' => 'Validación', + 'produccion' => 'Producción', + 'finalizado' => 'Finalizado', + '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', + 'unidades' => "Unidades", + 'concepto' => "Concepto", + 'total' => "Total", + 'presupuesto' => 'Presupuesto', + + 'moduleTitle' => 'Pedidos', + 'pedido' => 'Pedido', + 'pedidos' => 'Pedidos', + 'pedidosList' => 'Lista de Pedidos', + + 'cancelar' => 'Cancelar', + 'finalizar' => 'Finalizar', + + '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', + '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", + 'mostrarPrecios' => 'Mostrar precios', + 'iva4' => "4,00 % IVA", + 'iva21' => "21,00 % IVA", + + + 'facturas' => 'Facturas', + + 'validation' => [ + + ], + + +]; \ No newline at end of file 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/AlbaranLineaModel.php b/ci4/app/Models/Pedidos/AlbaranLineaModel.php new file mode 100644 index 00000000..62f6ccd4 --- /dev/null +++ b/ci4/app/Models/Pedidos/AlbaranLineaModel.php @@ -0,0 +1,41 @@ +find($presupuestos_id); + + $return_data = []; + + 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 = [ + '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, + 'user_created_id' => $user_id, + 'user_updated_id' => $user_id, + ]; + + + $serie = $model_series->find(11); + $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 = [ + '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, + 'mostrar_precios' => 0, + 'total' => $albaran_linea['total'], + 'direccion_albaran' => $envio->direccion, + 'att_albaran' => $envio->att, + 'user_created_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'); + $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; + + array_push($return_data, ["albaran"=>$albaran, "lineas" =>[$albaran_linea]]); + } + } + + return $return_data; + } +} \ 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..13308f06 --- /dev/null +++ b/ci4/app/Models/Pedidos/PedidoLineaModel.php @@ -0,0 +1,79 @@ + "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"; + + + 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 != "") { + if($estado == "activo") { + $sql = "t2.estado = 'validacion' OR t2.estado = 'produccion'"; + $builder->where($sql); + } else { + $builder->where("t2.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 new file mode 100644 index 00000000..04755c6e --- /dev/null +++ b/ci4/app/Models/Pedidos/PedidoModel.php @@ -0,0 +1,88 @@ + "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 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(); + } + + 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 414b39f0..7d690433 100755 --- a/ci4/app/Models/Presupuestos/PresupuestoModel.php +++ b/ci4/app/Models/Presupuestos/PresupuestoModel.php @@ -539,5 +539,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..55eacaac --- /dev/null +++ b/ci4/app/Views/themes/vuexy/form/pedidos/_albaranesItems.php @@ -0,0 +1,709 @@ +
+ +
+

+ +

+ +
+
+ + +
+
+ + +
+ +
+ + +
+
+ +
+
+
+
+ + +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){ + + 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 accordion-albaran', + id: 'accordioAlbaran' + item.albaran.id, + albaran: item.albaran.id + }); + + const card = $('
', { + class: 'card accordion-item active' + }); + + const header = $('

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

+
+ +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': 'paginas' }, + { 'data': 'tirada' }, + { 'data': 'total_presupuesto' }, + { '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 } + ] + }); + + 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) { + var url = ''; + url = url.replace(':id', `${$(this).attr('data-id')}` ); + window.location.href = url; + }); + + +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')) {