mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
trabajando en albaranes. Voy a quitar las cajas
This commit is contained in:
@ -505,15 +505,12 @@ $routes->group('pedidos', ['namespace' => 'App\Controllers\Pedidos'], function (
|
|||||||
$routes->resource('pedidos', ['namespace' => 'App\Controllers\Pedidos', 'controller' => 'Pedido', 'except' => 'show,new,create,update']);
|
$routes->resource('pedidos', ['namespace' => 'App\Controllers\Pedidos', 'controller' => 'Pedido', 'except' => 'show,new,create,update']);
|
||||||
|
|
||||||
|
|
||||||
$routes->group('albaranes', ['namespace' => 'App\Controllers\Pedidos'], function ($routes) {
|
$routes->group('albaranes', ['namespace' => 'App\Controllers\Albaranes'], function ($routes) {
|
||||||
$routes->post('add', 'Albaran::add', ['as' => 'crearAlbaranesPedido']);
|
$routes->post('generarAlbaran', 'Albaran::generateAlbaran', ['as' => 'generarAlbaran']);
|
||||||
$routes->post('update/(:any)', 'Albaran::update/$1', ['as' => 'actualizarAlbaran']);
|
$routes->get('albaranesEnvio', 'Albaran::getAlbaranes');
|
||||||
$routes->post('updateLinea/(:any)', 'Albaran::updateLinea/$1', ['as' => 'actualizarLineaAlbaran']);
|
$routes->get('datatablesAlbaranLinea', 'Albaran::datatablesLineasAlbaran');
|
||||||
$routes->post('deletelinea', 'Albaran::borrarlinea', ['as' => 'borrarAlbaranLinea']);
|
$routes->post('updateAlbaran', 'Albaran::updateAlbaran');
|
||||||
$routes->get('delete/(:any)', 'Albaran::delete/$1', ['as' => 'borrarAlbaran']);
|
$routes->post('borrarAlbaranLinea', 'Albaran::borrarLinea');
|
||||||
$routes->get('getalbaranes/(:any)', 'Albaran::getAlbaranes/$1', ['as' => 'getAlbaranes']);
|
|
||||||
$routes->get('nuevalinea/(:any)', 'Albaran::addLinea/$1', ['as' => 'addAlbaranLinea']);
|
|
||||||
$routes->post('nuevalinea/(:any)', 'Albaran::addLinea/$1', ['as' => 'addIVA']);
|
|
||||||
});
|
});
|
||||||
$routes->resource('albaranes', ['namespace' => 'App\Controllers\Pedidos', 'controller' => 'Albaran', 'except' => 'show,new,create,update']);
|
$routes->resource('albaranes', ['namespace' => 'App\Controllers\Pedidos', 'controller' => 'Albaran', 'except' => 'show,new,create,update']);
|
||||||
|
|
||||||
@ -788,7 +785,7 @@ $routes->group('logistica', ['namespace' => 'App\Controllers\Logistica'], functi
|
|||||||
$routes->get('addLineaEnvio', 'LogisticaController::addEnvioLinea');
|
$routes->get('addLineaEnvio', 'LogisticaController::addEnvioLinea');
|
||||||
$routes->post('updateCajaLinea', 'LogisticaController::setCajaLinea');
|
$routes->post('updateCajaLinea', 'LogisticaController::setCajaLinea');
|
||||||
$routes->post('deleteLineasEnvio', 'LogisticaController::deleteLineas');
|
$routes->post('deleteLineasEnvio', 'LogisticaController::deleteLineas');
|
||||||
$routes->post('updateUnidadesEnvio', 'LogisticaController::updateUnidadesEnvio');
|
$routes->post('updateLineaEnvio', 'LogisticaController::updateLineaEnvio');
|
||||||
$routes->post('updateComentariosEnvio', 'LogisticaController::saveComments');
|
$routes->post('updateComentariosEnvio', 'LogisticaController::saveComments');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -190,14 +190,6 @@ class LogisticaController extends BaseController
|
|||||||
return '<input type="checkbox" class="form-check-input checkbox-linea-envio" name="row_selected[]" value="' . $q->id . '">';
|
return '<input type="checkbox" class="form-check-input checkbox-linea-envio" name="row_selected[]" value="' . $q->id . '">';
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
->add("action", callback: function ($q) {
|
|
||||||
|
|
||||||
return '
|
|
||||||
<div class="btn-group btn-group-sm">
|
|
||||||
<a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="' . $q->id . '"></i></a>
|
|
||||||
</div>
|
|
||||||
';
|
|
||||||
})
|
|
||||||
->edit(
|
->edit(
|
||||||
"pedido",
|
"pedido",
|
||||||
function ($row, $meta) {
|
function ($row, $meta) {
|
||||||
@ -209,7 +201,23 @@ class LogisticaController extends BaseController
|
|||||||
function ($row, $meta) {
|
function ($row, $meta) {
|
||||||
return '<a href="' . base_url('presupuestoadmin/edit/' . $row->presupuesto) . '" target="_blank">' . $row->presupuesto . '</a>';
|
return '<a href="' . base_url('presupuestoadmin/edit/' . $row->presupuesto) . '" target="_blank">' . $row->presupuesto . '</a>';
|
||||||
}
|
}
|
||||||
);;
|
)
|
||||||
|
->edit(
|
||||||
|
"cajas",
|
||||||
|
function ($row, $meta) {
|
||||||
|
return '<input type="number" class="form-control input-lineas input-cajas text-center"
|
||||||
|
data-id="'. $row->id.'" data-name="cajas" value="' . $row->cajas . '">';
|
||||||
|
}
|
||||||
|
)->edit(
|
||||||
|
"unidadesEnvio",
|
||||||
|
function ($row, $meta) {
|
||||||
|
return '<input type="number" class="form-control input-lineas input-unidades text-center"
|
||||||
|
data-id="'. $row->id.'" data-name="unidades_envio" value="' . $row->unidadesEnvio . '">';
|
||||||
|
}
|
||||||
|
)
|
||||||
|
->edit('cajasRaw', function ($row) {
|
||||||
|
return is_null($row->cajas) ? '__SIN__ASIGNAR__' : $row->cajas;
|
||||||
|
});
|
||||||
|
|
||||||
return $result->toJson(returnAsObject: true);
|
return $result->toJson(returnAsObject: true);
|
||||||
}
|
}
|
||||||
@ -248,12 +256,13 @@ class LogisticaController extends BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateUnidadesEnvio()
|
public function updateLineaEnvio()
|
||||||
{
|
{
|
||||||
$id = $this->request->getPost('id');
|
$id = $this->request->getPost('id');
|
||||||
$unidades = $this->request->getPost('unidades_envio');
|
$fieldName = $this->request->getPost('name');
|
||||||
|
$fieldValue = $this->request->getPost('value');
|
||||||
|
|
||||||
if (!$id || !$unidades || intval($unidades) <= 0) {
|
if (!$id || !$fieldName || ($fieldName=='unidades_envio' && !$fieldValue)) {
|
||||||
return $this->response->setJSON([
|
return $this->response->setJSON([
|
||||||
'status' => false,
|
'status' => false,
|
||||||
'message' => 'Datos inválidos'
|
'message' => 'Datos inválidos'
|
||||||
@ -262,7 +271,7 @@ class LogisticaController extends BaseController
|
|||||||
|
|
||||||
$model = model('App\Models\Logistica\EnvioLineaModel');
|
$model = model('App\Models\Logistica\EnvioLineaModel');
|
||||||
$updated = $model->update($id, [
|
$updated = $model->update($id, [
|
||||||
'unidades_envio' => $unidades,
|
"" . $fieldName => $fieldValue==""? null: $fieldValue,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $this->response->setJSON([
|
return $this->response->setJSON([
|
||||||
|
|||||||
@ -11,8 +11,8 @@ class PrintAlbaranes extends BaseController
|
|||||||
public function index($albaran_id)
|
public function index($albaran_id)
|
||||||
{
|
{
|
||||||
|
|
||||||
$albaranModel = model('App\Models\Pedidos\AlbaranModel');
|
$albaranModel = model('App\Models\Albaranes\AlbaranModel');
|
||||||
$lineasAlbaranModel = model('App\Models\Pedidos\AlbaranLineaModel');
|
$lineasAlbaranModel = model('App\Models\Albaranes\AlbaranLineaModel');
|
||||||
|
|
||||||
$data['albaran'] = $albaranModel->getResourceForPdf($albaran_id)->get()->getRow();
|
$data['albaran'] = $albaranModel->getResourceForPdf($albaran_id)->get()->getRow();
|
||||||
$data['albaranLineas'] = $lineasAlbaranModel->getResourceForPdf($albaran_id)->get()->getResultObject();
|
$data['albaranLineas'] = $lineasAlbaranModel->getResourceForPdf($albaran_id)->get()->getResultObject();
|
||||||
@ -25,8 +25,8 @@ class PrintAlbaranes extends BaseController
|
|||||||
{
|
{
|
||||||
|
|
||||||
// Cargar modelos
|
// Cargar modelos
|
||||||
$albaranModel = model('App\Models\Pedidos\AlbaranModel');
|
$albaranModel = model('App\Models\Albaranes\AlbaranModel');
|
||||||
$lineasAlbaranModel = model('App\Models\Pedidos\AlbaranLineaModel');
|
$lineasAlbaranModel = model('App\Models\Albaranes\AlbaranLineaModel');
|
||||||
|
|
||||||
// Informacion del presupuesto
|
// Informacion del presupuesto
|
||||||
$data['albaran'] = $albaranModel->getResourceForPdf($albaran_id)->get()->getRow();
|
$data['albaran'] = $albaranModel->getResourceForPdf($albaran_id)->get()->getRow();
|
||||||
|
|||||||
@ -1,388 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controllers\Pedidos;
|
|
||||||
use App\Entities\Pedidos\AlbaranEntity;
|
|
||||||
use App\Models\Pedidos\AlbaranModel;
|
|
||||||
|
|
||||||
|
|
||||||
class Albaran extends \App\Controllers\BaseResourceController
|
|
||||||
{
|
|
||||||
protected $modelName = AlbaranModel::class;
|
|
||||||
protected $format = 'json';
|
|
||||||
|
|
||||||
protected static $singularObjectNameCc = 'albaran';
|
|
||||||
protected static $singularObjectName = 'Albaran';
|
|
||||||
protected static $pluralObjectName = 'Albaranes';
|
|
||||||
protected static $controllerSlug = 'albaran';
|
|
||||||
|
|
||||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
|
|
||||||
{
|
|
||||||
parent::initController($request, $response, $logger);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function index()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function delete($id = null)
|
|
||||||
{
|
|
||||||
if ($this->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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -17,6 +17,7 @@ class EnvioEntity extends Entity
|
|||||||
'finalizado' => 'boolean',
|
'finalizado' => 'boolean',
|
||||||
'codigo_seguimiento'=> 'string',
|
'codigo_seguimiento'=> 'string',
|
||||||
'proveedor_id' => 'int',
|
'proveedor_id' => 'int',
|
||||||
|
'cliente_id' => 'int',
|
||||||
'comentarios' => 'string',
|
'comentarios' => 'string',
|
||||||
'att' => 'string',
|
'att' => 'string',
|
||||||
'direccion' => 'string',
|
'direccion' => 'string',
|
||||||
|
|||||||
@ -1,46 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Entities\Pedidos;
|
|
||||||
|
|
||||||
use CodeIgniter\Entity;
|
|
||||||
|
|
||||||
class AlbaranEntity extends \CodeIgniter\Entity\Entity
|
|
||||||
{
|
|
||||||
protected $attributes = [
|
|
||||||
'id' => 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í
|
|
||||||
}
|
|
||||||
@ -1,40 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Entities\Pedidos;
|
|
||||||
|
|
||||||
use CodeIgniter\Entity;
|
|
||||||
|
|
||||||
class AlbaranLineaEntity extends \CodeIgniter\Entity\Entity
|
|
||||||
{
|
|
||||||
protected $attributes = [
|
|
||||||
'id' => 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',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
@ -51,6 +51,8 @@ return [
|
|||||||
'imprimirEtiquetas' => 'Imprimir etiquetas',
|
'imprimirEtiquetas' => 'Imprimir etiquetas',
|
||||||
'buttonsActions' => 'Acciones sobre las filas seleccionadas',
|
'buttonsActions' => 'Acciones sobre las filas seleccionadas',
|
||||||
'addCaja' => 'Añadir caja',
|
'addCaja' => 'Añadir caja',
|
||||||
|
'numCaja' => 'Número de caja',
|
||||||
|
'selectAll' => 'Seleccionar todo',
|
||||||
|
|
||||||
'errors' => [
|
'errors' => [
|
||||||
'noEnvio' => 'No se ha encontrado el envio',
|
'noEnvio' => 'No se ha encontrado el envio',
|
||||||
|
|||||||
@ -37,8 +37,9 @@ class EnvioLineaModel extends Model
|
|||||||
$builder = $this->db
|
$builder = $this->db
|
||||||
->table($this->table . " t1")
|
->table($this->table . " t1")
|
||||||
->select(
|
->select(
|
||||||
"t1.id, t1.pedido_id as pedido, t3.id as presupuesto,t1.cajas,
|
"t1.id, t1.pedido_id as pedido, t3.id as presupuesto,t1.cajas, t1.cajas as cajasRaw,
|
||||||
t3.titulo as titulo, t1.unidades_envio as unidadesEnvio, t1.unidades_total as unidadesTotal,
|
t3.titulo as titulo, t1.unidades_envio as unidadesEnvio, t1.unidades_envio as unidadesEnvioRaw,
|
||||||
|
t1.unidades_total as unidadesTotal,
|
||||||
IFNULL((
|
IFNULL((
|
||||||
SELECT SUM(t_sub.unidades_envio)
|
SELECT SUM(t_sub.unidades_envio)
|
||||||
FROM " . $this->table . " t_sub
|
FROM " . $this->table . " t_sub
|
||||||
|
|||||||
@ -19,6 +19,7 @@ class EnvioModel extends Model
|
|||||||
'codigo_seguimiento',
|
'codigo_seguimiento',
|
||||||
'proveedor_id',
|
'proveedor_id',
|
||||||
'comentarios',
|
'comentarios',
|
||||||
|
'cliente_id',
|
||||||
'att',
|
'att',
|
||||||
'direccion',
|
'direccion',
|
||||||
'ciudad',
|
'ciudad',
|
||||||
|
|||||||
@ -1,66 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models\Pedidos;
|
|
||||||
|
|
||||||
class AlbaranLineaModel extends \App\Models\BaseModel
|
|
||||||
{
|
|
||||||
protected $table = "albaranes_lineas";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether primary key uses auto increment.
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
protected $useAutoIncrement = true;
|
|
||||||
|
|
||||||
protected $primaryKey = 'id';
|
|
||||||
protected $returnType = 'App\Entities\Pedidos\AlbaranLineaEntity';
|
|
||||||
protected $allowedFields = [
|
|
||||||
'albaran_id',
|
|
||||||
'titulo',
|
|
||||||
'isbn',
|
|
||||||
'ref_cliente',
|
|
||||||
'cantidad',
|
|
||||||
'cajas',
|
|
||||||
'ejemplares_por_caja',
|
|
||||||
'precio_unidad',
|
|
||||||
'total',
|
|
||||||
'user_created_id',
|
|
||||||
'user_updated_id',
|
|
||||||
'created_at',
|
|
||||||
'updated_at',
|
|
||||||
'deleted_at',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected $useSoftDeletes = true;
|
|
||||||
protected $useTimestamps = true;
|
|
||||||
protected $createdField = 'created_at';
|
|
||||||
protected $updatedField = 'updated_at';
|
|
||||||
protected $deletedField = 'deleted_at';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get resource data for creating PDFs.
|
|
||||||
*
|
|
||||||
* @param string $search
|
|
||||||
*
|
|
||||||
* @return \CodeIgniter\Database\BaseBuilder
|
|
||||||
*/
|
|
||||||
public function getResourceForPdf($albaran_id = -1)
|
|
||||||
{
|
|
||||||
$builder = $this->db
|
|
||||||
|
|
||||||
->table($this->table . " t1")
|
|
||||||
->select(
|
|
||||||
"t1.id AS id, t1.albaran_id AS albaran_id, t1.titulo AS titulo, t1.isbn AS isbn,
|
|
||||||
t1.ref_cliente AS ref_cliente, t1.cantidad AS cantidad, t1.cajas AS cajas,
|
|
||||||
t1.ejemplares_por_caja AS ejemplares_por_caja, t1.precio_unidad AS precio_unidad,
|
|
||||||
t1.total AS total"
|
|
||||||
);
|
|
||||||
|
|
||||||
$builder->where("t1.deleted_at IS NULL");
|
|
||||||
$builder->where("t1.albaran_id", $albaran_id);
|
|
||||||
|
|
||||||
return $builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,161 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models\Pedidos;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AlbaranModel extends \App\Models\BaseModel
|
|
||||||
{
|
|
||||||
protected $table = "albaranes";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether primary key uses auto increment.
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
protected $useAutoIncrement = true;
|
|
||||||
|
|
||||||
protected $primaryKey = 'id';
|
|
||||||
protected $returnType = 'App\Entities\Pedidos\AlbaranEntity';
|
|
||||||
protected $allowedFields = [
|
|
||||||
'pedido_id',
|
|
||||||
'presupuesto_id',
|
|
||||||
'presupuesto_direccion_id',
|
|
||||||
'cliente_id',
|
|
||||||
'serie_id',
|
|
||||||
'numero_albaran',
|
|
||||||
'mostrar_precios',
|
|
||||||
'total',
|
|
||||||
'direccion_albaran',
|
|
||||||
'att_albaran',
|
|
||||||
'user_created_id',
|
|
||||||
'user_updated_id',
|
|
||||||
'created_at',
|
|
||||||
'updated_at',
|
|
||||||
'deleted_at',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected $useSoftDeletes = true;
|
|
||||||
protected $useTimestamps = true;
|
|
||||||
protected $createdField = 'created_at';
|
|
||||||
protected $updatedField = 'updated_at';
|
|
||||||
protected $deletedField = 'deleted_at';
|
|
||||||
|
|
||||||
public function generarAlbaranes($pedido_id, $presupuestos_id, $user_id){
|
|
||||||
|
|
||||||
$model_presupuesto = model('App\Models\Presupuestos\PresupuestoModel');
|
|
||||||
$model_presupuesto_direcciones = model('App\Models\Presupuestos\PresupuestoDireccionesModel');
|
|
||||||
$model_series = model('App\Models\Configuracion\SeriesFacturasModel');
|
|
||||||
|
|
||||||
$presupuestos = $model_presupuesto->find($presupuestos_id);
|
|
||||||
|
|
||||||
$return_data = [];
|
|
||||||
|
|
||||||
foreach ($presupuestos as $presupuesto) {
|
|
||||||
|
|
||||||
$envios = $model_presupuesto_direcciones->where('presupuesto_id', $presupuesto->id)->findAll();
|
|
||||||
|
|
||||||
foreach($envios as $envio){
|
|
||||||
|
|
||||||
// se buscan los albaranes en este presupuesto con la misma direccion y con el mismo presupuesto_id en albaran
|
|
||||||
// en albaran linea para obtener la cantidad total enviada
|
|
||||||
$model_albaran = model('App\Models\Pedidos\AlbaranModel');
|
|
||||||
$model_albaran_linea = model('App\Models\Pedidos\AlbaranLineaModel');
|
|
||||||
$albaranes = $model_albaran->where('presupuesto_id', $presupuesto->id)
|
|
||||||
->where('presupuesto_direccion_id', $envio->id)->findAll();
|
|
||||||
// se suman las cantidades de los albaranes
|
|
||||||
$cantidad_enviada = 0;
|
|
||||||
foreach($albaranes as $albaran){
|
|
||||||
$lineas = $model_albaran_linea->where('albaran_id', $albaran->id)->findAll();
|
|
||||||
foreach($lineas as $linea){
|
|
||||||
$cantidad_enviada += $linea->cantidad;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if($cantidad_enviada >= intval($envio->cantidad)){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// 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' => intval($envio->cantidad)-$cantidad_enviada,
|
|
||||||
'cajas' => 1,
|
|
||||||
'ejemplares_por_caja' => intval($envio->cantidad)-$cantidad_enviada,
|
|
||||||
'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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get resource data for creating PDFs.
|
|
||||||
*
|
|
||||||
* @param string $search
|
|
||||||
*
|
|
||||||
* @return \CodeIgniter\Database\BaseBuilder
|
|
||||||
*/
|
|
||||||
public function getResourceForPdf($albaran_id = -1)
|
|
||||||
{
|
|
||||||
$builder = $this->db
|
|
||||||
|
|
||||||
->table($this->table . " t1")
|
|
||||||
->select(
|
|
||||||
"t1.id AS id, t1.pedido_id AS pedido_id, t1.presupuesto_id AS presupuesto_id,
|
|
||||||
t1.presupuesto_direccion_id AS presupuesto_direccion_id, t1.cliente_id AS cliente_id,
|
|
||||||
t1.serie_id AS serie_id, t1.numero_albaran AS numero_albaran, t1.mostrar_precios AS mostrar_precios,
|
|
||||||
t1.total AS total, t1.direccion_albaran AS direccion_albaran, t1.att_albaran AS att_albaran,
|
|
||||||
t1.user_created_id AS user_created_id, t1.user_updated_id AS user_updated_id,
|
|
||||||
t1.created_at AS created_at, t1.updated_at AS updated_at,
|
|
||||||
t2.nombre AS cliente"
|
|
||||||
);
|
|
||||||
$builder->join("clientes t2", "t1.cliente_id = t2.id", "left");
|
|
||||||
|
|
||||||
$builder->where("t1.deleted_at IS NULL");
|
|
||||||
$builder->where("t1.id", $albaran_id);
|
|
||||||
|
|
||||||
return $builder;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -86,45 +86,51 @@ class LogisticaService
|
|||||||
public static function findLineaEnvioPorEnvio(int $envio_id)
|
public static function findLineaEnvioPorEnvio(int $envio_id)
|
||||||
{
|
{
|
||||||
$db = \Config\Database::connect();
|
$db = \Config\Database::connect();
|
||||||
|
$subCliente = $db->table('envios')
|
||||||
|
->select('cliente_id')
|
||||||
|
->where('id', $envio_id)
|
||||||
|
->getCompiledSelect();
|
||||||
|
|
||||||
$builder = $db->table('envios e_main');
|
$builder = $db->table('envios e_main');
|
||||||
|
|
||||||
$builder->select("
|
$builder->select("
|
||||||
CONCAT('[', p.id, '] - ', pr.titulo) AS name,
|
CONCAT('[', p.id, '] - ', pr.titulo) AS name,
|
||||||
p.id AS id,
|
pl.id AS id,
|
||||||
pl.id AS linea_id,
|
pl.cantidad,
|
||||||
pl.cantidad,
|
(
|
||||||
(
|
SELECT IFNULL(SUM(el.unidades_envio), 0)
|
||||||
SELECT IFNULL(SUM(el.unidades_envio), 0)
|
FROM envios_lineas el
|
||||||
FROM envios_lineas el
|
JOIN envios e ON e.id = el.envio_id
|
||||||
JOIN envios e ON e.id = el.envio_id
|
WHERE el.pedido_id = p.id
|
||||||
WHERE el.pedido_id = p.id
|
AND e.direccion = e_main.direccion
|
||||||
AND e.direccion = e_main.direccion
|
AND pr.cliente_id = ($subCliente)
|
||||||
) AS unidades_enviadas,
|
) AS unidades_enviadas,
|
||||||
(pl.cantidad - (
|
(
|
||||||
|
pl.cantidad - (
|
||||||
SELECT IFNULL(SUM(el2.unidades_envio), 0)
|
SELECT IFNULL(SUM(el2.unidades_envio), 0)
|
||||||
FROM envios_lineas el2
|
FROM envios_lineas el2
|
||||||
JOIN envios e2 ON e2.id = el2.envio_id
|
JOIN envios e2 ON e2.id = el2.envio_id
|
||||||
WHERE el2.pedido_id = p.id
|
WHERE el2.pedido_id = p.id
|
||||||
AND e2.direccion = e_main.direccion
|
AND e2.direccion = e_main.direccion
|
||||||
)) AS unidades_pendientes
|
AND pr.cliente_id = ($subCliente)
|
||||||
");
|
)
|
||||||
|
) AS unidades_pendientes
|
||||||
|
");
|
||||||
|
|
||||||
$builder->join('envios_lineas el_main', 'el_main.envio_id = e_main.id');
|
$builder->join('pedidos_linea pl', '1=1'); // para incluir líneas sin envío aún
|
||||||
$builder->join('pedidos p', 'p.id = el_main.pedido_id');
|
$builder->join('pedidos p', 'p.id = pl.pedido_id');
|
||||||
$builder->join('pedidos_linea pl', 'pl.pedido_id = p.id');
|
|
||||||
$builder->join('presupuestos pr', 'pr.id = pl.presupuesto_id');
|
$builder->join('presupuestos pr', 'pr.id = pl.presupuesto_id');
|
||||||
|
|
||||||
$builder->where('p.estado', 'finalizado');
|
|
||||||
$builder->where('e_main.id', $envio_id);
|
$builder->where('e_main.id', $envio_id);
|
||||||
|
$builder->where('p.estado', 'finalizado');
|
||||||
|
$builder->where("pr.cliente_id = ($subCliente)", null, false);
|
||||||
|
|
||||||
$builder->groupBy('pl.id');
|
$builder->having('unidades_pendientes >', 0);
|
||||||
$builder->having('unidades_enviadas < pl.cantidad', null, false);
|
|
||||||
$builder->orderBy('name', 'ASC');
|
$builder->orderBy('name', 'ASC');
|
||||||
|
|
||||||
return $builder;
|
return $builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function addLineaEnvio($envio_id = null, $pedido_id = null, $direccion = null)
|
public static function addLineaEnvio($envio_id = null, $pedido_id = null, $direccion = null)
|
||||||
{
|
{
|
||||||
$modelPedido = model('App\Models\Pedidos\PedidoModel');
|
$modelPedido = model('App\Models\Pedidos\PedidoModel');
|
||||||
@ -183,10 +189,10 @@ class LogisticaService
|
|||||||
return [
|
return [
|
||||||
'status' => true,
|
'status' => true,
|
||||||
'data' => [
|
'data' => [
|
||||||
'unidades_envio' => $result[0]->unidades_envio,
|
'unidades_envio' => $result[0]->unidades_envio,
|
||||||
'unidades_enviadas' => $result[0]->unidades_enviadas,
|
'unidades_enviadas' => $result[0]->unidades_enviadas,
|
||||||
'total_unidades' => $result[0]->total_unidades,
|
'total_unidades' => $result[0]->total_unidades,
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,7 +217,8 @@ class LogisticaService
|
|||||||
presupuesto_direcciones.email,
|
presupuesto_direcciones.email,
|
||||||
presupuesto_direcciones.pais_id,
|
presupuesto_direcciones.pais_id,
|
||||||
presupuesto_direcciones.cantidad - IFNULL(SUM(envios_lineas.unidades_envio), 0) as cantidad,
|
presupuesto_direcciones.cantidad - IFNULL(SUM(envios_lineas.unidades_envio), 0) as cantidad,
|
||||||
presupuesto_direcciones.cantidad as cantidad_total
|
presupuesto_direcciones.cantidad as cantidad_total,
|
||||||
|
presupuestos.cliente_id as cliente_id
|
||||||
')
|
')
|
||||||
->join('pedidos_linea', 'pedidos_linea.presupuesto_id = presupuesto_direcciones.presupuesto_id')
|
->join('pedidos_linea', 'pedidos_linea.presupuesto_id = presupuesto_direcciones.presupuesto_id')
|
||||||
->join('pedidos', 'pedidos.id = pedidos_linea.pedido_id')
|
->join('pedidos', 'pedidos.id = pedidos_linea.pedido_id')
|
||||||
@ -225,6 +232,7 @@ class LogisticaService
|
|||||||
|
|
||||||
// se genera un nuevo envio con estos datos
|
// se genera un nuevo envio con estos datos
|
||||||
$EnvioModel = model('App\Models\Logistica\EnvioModel');
|
$EnvioModel = model('App\Models\Logistica\EnvioModel');
|
||||||
|
$EnvioModel->set('cliente_id', $datosEnvio->cliente_id);
|
||||||
$EnvioModel->set('att', $datosEnvio->att);
|
$EnvioModel->set('att', $datosEnvio->att);
|
||||||
$EnvioModel->set('direccion', $datosEnvio->direccion);
|
$EnvioModel->set('direccion', $datosEnvio->direccion);
|
||||||
$EnvioModel->set('ciudad', $datosEnvio->ciudad);
|
$EnvioModel->set('ciudad', $datosEnvio->ciudad);
|
||||||
@ -261,9 +269,9 @@ class LogisticaService
|
|||||||
return [
|
return [
|
||||||
'status' => true,
|
'status' => true,
|
||||||
'data' => [
|
'data' => [
|
||||||
'id_envio' => $idEnvio,
|
'id_envio' => $idEnvio,
|
||||||
'multienvio' => false,
|
'multienvio' => false,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,7 +41,8 @@
|
|||||||
<?= lang("Logistica.direccion") ?>
|
<?= lang("Logistica.direccion") ?>
|
||||||
</label>
|
</label>
|
||||||
<input readonly id="direccion" name="direccion" tabindex="1" maxlength="50"
|
<input readonly id="direccion" name="direccion" tabindex="1" maxlength="50"
|
||||||
class="form-control" value="<?= old('direccion', $envioEntity->direccion) ?>">
|
class="form-control"
|
||||||
|
value="<?= old('direccion', $envioEntity->direccion) ?>">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-sm-2 px-3">
|
<div class="col-sm-2 px-3">
|
||||||
@ -95,7 +96,8 @@
|
|||||||
<?= lang("Logistica.comentariosEnvio") ?>
|
<?= lang("Logistica.comentariosEnvio") ?>
|
||||||
</label>
|
</label>
|
||||||
<input id="comentarios" name="comentarios" tabindex="1" maxlength="50"
|
<input id="comentarios" name="comentarios" tabindex="1" maxlength="50"
|
||||||
class="form-control" value="<?= old('comentarios', $envioEntity->comentarios) ?>">
|
class="form-control"
|
||||||
|
value="<?= old('comentarios', $envioEntity->comentarios) ?>">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-sm-3 px-3">
|
<div class="col-sm-3 px-3">
|
||||||
@ -159,6 +161,13 @@
|
|||||||
<p><?= lang('Logistica.buttonsActions') ?></p>
|
<p><?= lang('Logistica.buttonsActions') ?></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="d-flex flex-row mb-3">
|
<div class="d-flex flex-row mb-3">
|
||||||
|
<div class="col-sm-2 px-3">
|
||||||
|
<button id="btnSelectAll" name="btnSelectAll" tabindex="1"
|
||||||
|
class="btn btn-primary w-100">
|
||||||
|
<?= lang("Logistica.selectAll") ?>
|
||||||
|
<i class="ti ti-select"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
<div class="col-sm-2 px-3">
|
<div class="col-sm-2 px-3">
|
||||||
<button id="btnEliminarLineas" name="btnEliminarLineas" tabindex="1"
|
<button id="btnEliminarLineas" name="btnEliminarLineas" tabindex="1"
|
||||||
class="btn btn-danger w-100">
|
class="btn btn-danger w-100">
|
||||||
@ -175,7 +184,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-sm-2 px-3">
|
<div class="col-sm-2 px-3">
|
||||||
<button id="btnImprimirEtiquetas" name="btnImprimirEtiquetas" tabindex="1"
|
<button id="btnImprimirEtiquetas" name="btnImprimirEtiquetas" tabindex="1"
|
||||||
class="btn btn-primary w-100">
|
class="btn btn-info w-100">
|
||||||
<?= lang("Logistica.imprimirEtiquetas") ?>
|
<?= lang("Logistica.imprimirEtiquetas") ?>
|
||||||
<i class="ti ti-printer"></i>
|
<i class="ti ti-printer"></i>
|
||||||
</button>
|
</button>
|
||||||
@ -197,12 +206,21 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th></th>
|
<th></th>
|
||||||
<th></th>
|
<th></th>
|
||||||
|
<th class="text-center" style="width: 10%;">
|
||||||
|
<?= lang("Logistica.numCaja") ?>
|
||||||
|
</th>
|
||||||
<th><?= lang("Logistica.pedido") ?></th>
|
<th><?= lang("Logistica.pedido") ?></th>
|
||||||
<th><?= lang("Logistica.presupuesto") ?></th>
|
<th><?= lang("Logistica.presupuesto") ?></th>
|
||||||
<th><?= lang("Logistica.titulo") ?></th>
|
<th><?= lang("Logistica.titulo") ?></th>
|
||||||
<th><?= lang("Logistica.unidadesEnvio") ?></th>
|
<th class="text-center" style="width: 10%;">
|
||||||
<th><?= lang("Logistica.unidadesEnviadas") ?></th>
|
<?= lang("Logistica.unidadesEnvio") ?>
|
||||||
<th><?= lang("Logistica.unidadesTotales") ?></th>
|
</th>
|
||||||
|
<th class="text-center" style="width: 10%;">
|
||||||
|
<?= lang("Logistica.unidadesEnviadas") ?>
|
||||||
|
</th>
|
||||||
|
<th class="text-center" style="width: 10%;">
|
||||||
|
<?= lang("Logistica.unidadesTotales") ?>
|
||||||
|
</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
<th></th>
|
<th></th>
|
||||||
<th></th>
|
<th></th>
|
||||||
@ -219,25 +237,47 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
<div class="accordion accordion-bordered mt-3" id="accordioAlbaranes">
|
||||||
|
|
||||||
|
<div class="card accordion-item active">
|
||||||
|
<h2 class="accordion-header" id="headingAlbaranes">
|
||||||
|
<button type="button" class="accordion-button" data-bs-toggle="collapse"
|
||||||
|
data-bs-target="#accordionAlbaranesTip" aria-expanded="false"
|
||||||
|
aria-controls="accordionAlbaranesTip">
|
||||||
|
<h3><?= lang("Pedidos.albaranes") ?></h3>
|
||||||
|
</button>
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<div id="accordionAlbaranesTip" class="accordion-collapse collapse show"
|
||||||
|
data-bs-parent="#accordioAlbaranes">
|
||||||
|
<div id="contenedorAlbaranes" class="accordion-body">
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?= $this->endSection() ?>
|
<?= $this->endSection() ?>
|
||||||
|
|
||||||
<?= $this->section('css') ?>
|
<?= $this->section('css') ?>
|
||||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.css') ?>" />
|
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.css') ?>" />
|
||||||
<link rel="stylesheet" href="https://cdn.datatables.net/rowreorder/1.4.1/css/rowReorder.dataTables.min.css">
|
<link rel="stylesheet" href="https://cdn.datatables.net/rowreorder/1.4.1/css/rowReorder.dataTables.min.css">
|
||||||
<link rel="stylesheet" href="https://code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css">
|
<link rel="stylesheet" href="https://code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css">
|
||||||
|
|
||||||
<?= $this->endSection() ?>
|
<?= $this->endSection() ?>
|
||||||
|
|
||||||
<?= $this->section('additionalExternalJs') ?>
|
<?= $this->section('additionalExternalJs') ?>
|
||||||
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.min.js"></script>
|
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.min.js"></script>
|
||||||
<script src="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.js') ?>"></script>
|
<script src="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.js') ?>"></script>
|
||||||
<script src="https://cdn.datatables.net/rowgroup/1.3.1/js/dataTables.rowGroup.min.js"></script>
|
<script src="https://cdn.datatables.net/rowgroup/1.3.1/js/dataTables.rowGroup.min.js"></script>
|
||||||
|
|
||||||
<script src="https://cdn.datatables.net/rowreorder/1.4.1/js/dataTables.rowReorder.min.js"></script>
|
<script src="https://cdn.datatables.net/rowreorder/1.4.1/js/dataTables.rowReorder.min.js"></script>
|
||||||
<script type="module" src="<?= site_url("assets/js/safekat/pages/logistica/envioEdit.js") ?>"></script>
|
<script type="module" src="<?= site_url("assets/js/safekat/pages/logistica/envioEdit.js") ?>"></script>
|
||||||
<?= $this->endSection() ?>
|
<?= $this->endSection() ?>
|
||||||
@ -1,787 +0,0 @@
|
|||||||
<div class="accordion accordion-bordered mt-3" id="accordioAlbaranes">
|
|
||||||
|
|
||||||
<div class="card accordion-item active">
|
|
||||||
<h2 class="accordion-header" id="headingAlbaranes">
|
|
||||||
<button type="button" class="accordion-button" data-bs-toggle="collapse" data-bs-target="#accordionAlbaranesTip" aria-expanded="false" aria-controls="accordionAlbaranesTip">
|
|
||||||
<h3><?= lang("Pedidos.albaranes") ?></h3>
|
|
||||||
</button>
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
<div id="accordionAlbaranesTip" class="accordion-collapse collapse show" data-bs-parent="#accordioAlbaranes">
|
|
||||||
<div class="accordion-body">
|
|
||||||
|
|
||||||
<div id='alert-albaranes' class="alert alert-warning d-flex align-items-baseline d-none" role="alert">
|
|
||||||
<div class="d-flex flex-column ps-1">
|
|
||||||
<h5 id='error-albaranes' class="alert-heading mb-2"></h5>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div id="bonotes_albaranes" class="col-12 d-flex flex-row-reverse mt-4 gap-2">
|
|
||||||
<div id="generar_albaranes" class="btn mt-3 btn-success waves-effect waves-light ml-2">
|
|
||||||
<span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('Pedidos.generarAlbaranes') ?></span>
|
|
||||||
<i class="ti ti-player-play ti-xs"></i>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="borrar_albaranes" class="btn mt-3 btn-danger waves-effect waves-light ml-2">
|
|
||||||
<span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('Pedidos.borrarAlbaranes') ?></span>
|
|
||||||
<i class="ti ti-trash ti-xs"></i>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div> <!-- /.accordion-body -->
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<?=$this->section('additionalInlineJs') ?>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$('#generar_albaranes').on('click', function(){
|
|
||||||
|
|
||||||
var lineasPedido = $('#tableOfLineasPedido').DataTable();
|
|
||||||
var presupuestos = lineasPedido.column(0).data().unique().toArray();
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: '<?= route_to('crearAlbaranesPedido') ?>',
|
|
||||||
type: 'POST',
|
|
||||||
data: {
|
|
||||||
pedido_id: <?= $pedidoEntity->id ?>,
|
|
||||||
presupuestos_id: presupuestos,
|
|
||||||
<?= csrf_token() ?? "token" ?>: <?= csrf_token() ?>v,
|
|
||||||
},
|
|
||||||
success: function(response){
|
|
||||||
|
|
||||||
if(response.data.length > 0){
|
|
||||||
Object.values(response.data).forEach(function(item){
|
|
||||||
generarAlbaran(item);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
cambios_cantidad_albaranes();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
|
|
||||||
const deleteLineaBtns = function(data) {
|
|
||||||
return `
|
|
||||||
<td class="text-right py-0 align-middle">
|
|
||||||
<div class="btn-group btn-group-sm">
|
|
||||||
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete-linea mx-2" data-id="${data.id}"></i></a>
|
|
||||||
</div>
|
|
||||||
</td>`;
|
|
||||||
};
|
|
||||||
|
|
||||||
function generarAlbaran(item){
|
|
||||||
|
|
||||||
// Crear los elementos necesarios
|
|
||||||
const accordion = $('<div>', {
|
|
||||||
class: 'accordion accordion-bordered mt-3 accordion-albaran',
|
|
||||||
id: 'accordioAlbaran' + item.albaran.id,
|
|
||||||
albaran: item.albaran.id
|
|
||||||
});
|
|
||||||
|
|
||||||
const card = $('<div>', {
|
|
||||||
class: 'card accordion-item active'
|
|
||||||
});
|
|
||||||
|
|
||||||
const header = $('<h2>', {
|
|
||||||
class: 'accordion-header',
|
|
||||||
id: 'headingAlbaran' + item.albaran.id
|
|
||||||
});
|
|
||||||
|
|
||||||
const button = $('<button>', {
|
|
||||||
type: 'button',
|
|
||||||
class: 'accordion-button collapsed',
|
|
||||||
'data-bs-toggle': 'collapse',
|
|
||||||
'data-bs-target': '#accordionAlbaranTip' + item.albaran.id,
|
|
||||||
'aria-expanded': 'false',
|
|
||||||
'aria-controls': 'accordionAlbaranTip' + item.albaran.id,
|
|
||||||
'albaran': item.albaran.id,
|
|
||||||
}).css({
|
|
||||||
'background-color': '#F0F8FF'
|
|
||||||
});
|
|
||||||
|
|
||||||
const h3 = $('<h5>').html(item.albaran.numero_albaran);
|
|
||||||
|
|
||||||
const collapseDiv = $('<div>', {
|
|
||||||
id: 'accordionAlbaranTip' + item.albaran.id,
|
|
||||||
class: 'accordion-collapse collapse',
|
|
||||||
'data-bs-parent': '#accordioAlbaran' + item.albaran.id
|
|
||||||
});
|
|
||||||
|
|
||||||
const body = $('<div>', {
|
|
||||||
class: 'accordion-body'
|
|
||||||
});
|
|
||||||
|
|
||||||
const cabecera =
|
|
||||||
`
|
|
||||||
<div class="col-12 d-flex justify-content-between mb-3">
|
|
||||||
<div class="col-6 d-flex flex-row">
|
|
||||||
<div class="col-2">
|
|
||||||
<label><?= lang('Pedidos.fecha') ?>:</label>
|
|
||||||
</div>
|
|
||||||
<div class="col-2">
|
|
||||||
<label>${item.albaran.fecha_albaran}</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-6 d-flex flex-row-reverse">
|
|
||||||
<div class="col-2">
|
|
||||||
<label style="text-align: right; display:block">${item.albaran.pedido_id}</label>
|
|
||||||
</div>
|
|
||||||
<div class="col-2">
|
|
||||||
<label style="text-align: right"><?= lang('Pedidos.pedido') ?>:</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-12 d-flex justify-content-between mb-3">
|
|
||||||
<div class="col-6 d-flex flex-row">
|
|
||||||
<div class="col-2">
|
|
||||||
<label><?= lang('Pedidos.cliente') ?>:</label>
|
|
||||||
</div>
|
|
||||||
<div class="col-4">
|
|
||||||
<label>${$('#cliente').val()}</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-6 d-flex flex-row-reverse">
|
|
||||||
<div class="col-2">
|
|
||||||
<label style="text-align: right; display:block">${item.albaran.numero_albaran}</label>
|
|
||||||
</div>
|
|
||||||
<div class="col-2">
|
|
||||||
<label style="text-align: right"><?= lang('Pedidos.albaran') ?>:</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-12 d-flex justify-content-between mb-3">
|
|
||||||
<div class="col-1">
|
|
||||||
<label><?= lang('Pedidos.att') ?>:</label>
|
|
||||||
</div>
|
|
||||||
<div class="col-11">
|
|
||||||
<input id="att_${item.albaran.id}" class="cambios-albaran form-control" albaran_id=${item.albaran.id} value="${item.albaran.att_albaran}" class="form-control"></input>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-12 d-flex justify-content-between mb-3">
|
|
||||||
<div class="col-1">
|
|
||||||
<label><?= lang('Pedidos.direccion') ?>:</label>
|
|
||||||
</div>
|
|
||||||
<div class="col-11">
|
|
||||||
<input id="direccion_${item.albaran.id}" albaran_id=${item.albaran.id} value="${item.albaran.direccion_albaran}" class="cambios-albaran form-control"></input>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
|
|
||||||
const table = $('<table>',
|
|
||||||
{ id: 'tablaAlbaran' + item.albaran.id, width:'100%', class: 'table table-responsive table-striped table-hover table-albaran' })
|
|
||||||
.css({
|
|
||||||
'width': '100%',
|
|
||||||
}).append(
|
|
||||||
$('<thead>').append(
|
|
||||||
$('<tr>').append(
|
|
||||||
$('<th>').css({'max-width':'20px'}),
|
|
||||||
$('<th>'),
|
|
||||||
$('<th>', { class:'lp-header', scope: 'col' }).css({'font-size':'smaller'}).text('Unidades'),
|
|
||||||
$('<th>', { class:'lp-header',scope: 'col' }).css({'font-size':'smaller'}).text('Título'),
|
|
||||||
$('<th>', { class:'lp-header',scope: 'col' }).css({'font-size':'smaller'}).text('ISBN'),
|
|
||||||
$('<th>', { class:'lp-header',scope: 'col' }).css({'font-size':'smaller'}).text('Ref. Cliente'),
|
|
||||||
$('<th>', { class:'lp-header',scope: 'col' }).css({'font-size':'smaller'}).text('Cajas'),
|
|
||||||
$('<th>', { class:'lp-header',scope: 'col' }).css({'font-size':'smaller'}).text('Ej./Cajas'),
|
|
||||||
$('<th>', { class:'lp-header',scope: 'col' }).css({'font-size':'smaller'}).text('€/u'),
|
|
||||||
$('<th>', { class:'lp-header',scope: 'col' }).css({'font-size':'smaller'}).text('Subtotal')
|
|
||||||
)
|
|
||||||
),
|
|
||||||
$('<tbody>'),
|
|
||||||
$('<tfoot>').append(
|
|
||||||
$('<tr>').append(
|
|
||||||
$('<th>', { colspan: '9', style: 'text-align:right' }).text('')
|
|
||||||
)
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
let isChecked = item.albaran.mostrar_precios == 1 ? 'checked' : '';
|
|
||||||
const botones_albaran =
|
|
||||||
`
|
|
||||||
<div class="row mt-1">
|
|
||||||
<div id="div_mostrar_precios_${item.albaran.id}" class="col-2 d-flex flex-row gap-2">
|
|
||||||
<div class="d-flex align-items-center">
|
|
||||||
<label><?= lang('Pedidos.mostrarPrecios') ?>:</label>
|
|
||||||
</div>
|
|
||||||
<div class="d-flex align-items-center">
|
|
||||||
<input type="checkbox" id="mostrar_precios" name="mostrar_precios" albaran_id=${item.albaran.id} class="mostrar-precios custom-control-input" ${isChecked} >
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div id="bonotes_albaran_${item.albaran.id}" class="col-10 d-flex flex-row-reverse gap-2">
|
|
||||||
<div id="borrar_albaran_${item.albaran.id}" class="borrar-albaran btn mt-3 button-albaran btn-label-danger waves-effect waves-light ml-2">
|
|
||||||
<span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('Pedidos.borrarAlbaran') ?></span>
|
|
||||||
<i class="ti ti-trash ti-xs"></i>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="imprimir_albaran_${item.albaran.id}" class="imprimir-albaran btn mt-3 btn-label-secondary button-albaran waves-effect waves-light ml-2">
|
|
||||||
<span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('Pedidos.imprimirAlbaran') ?></span>
|
|
||||||
<i class="ti ti-printer ti-xs"></i>
|
|
||||||
</div>
|
|
||||||
<div id="nueva_linea_albaran_${item.albaran.id}" class="nueva-linea-albaran btn mt-3 btn-label-secondary button-albaran waves-effect waves-light ml-2">
|
|
||||||
<span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('Pedidos.nuevaLinea') ?></span>
|
|
||||||
<i class="ti ti-plus ti-xs"></i>
|
|
||||||
</div>
|
|
||||||
<div id="add_iva_albaran_${item.albaran.id}" class="add-iva-albaran btn mt-3 btn-label-secondary button-albaran waves-effect waves-light ml-2">
|
|
||||||
<span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('Pedidos.addIva') ?></span>
|
|
||||||
<i class="ti ti-plus ti-xs"></i>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
|
|
||||||
// Armar la estructura
|
|
||||||
button.append(h3);
|
|
||||||
header.append(button);
|
|
||||||
card.append(header);
|
|
||||||
collapseDiv.append(body);
|
|
||||||
body.append(cabecera);
|
|
||||||
body.append(table);
|
|
||||||
body.append(botones_albaran);
|
|
||||||
card.append(collapseDiv);
|
|
||||||
accordion.append(card);
|
|
||||||
|
|
||||||
// Agregar el elemento al accordioAlbaranes
|
|
||||||
$('#bonotes_albaranes').before(accordion);
|
|
||||||
|
|
||||||
|
|
||||||
const datatableAlbaran = new DataTable('#tablaAlbaran' + item.albaran.id,{
|
|
||||||
scrollX: true,
|
|
||||||
searching: false,
|
|
||||||
paging: false,
|
|
||||||
info: false,
|
|
||||||
ordering: false,
|
|
||||||
responsive: true,
|
|
||||||
select: false,
|
|
||||||
dom: 't',
|
|
||||||
language: {
|
|
||||||
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
|
|
||||||
},
|
|
||||||
columns: [
|
|
||||||
{ data: 'id'},
|
|
||||||
{
|
|
||||||
data: deleteLineaBtns,
|
|
||||||
className: 'dt-center'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: 'cantidad',
|
|
||||||
render: function ( data, type, row, meta ) {
|
|
||||||
|
|
||||||
var input = $('<input>', {
|
|
||||||
id: 'cantidad_' + row.id,
|
|
||||||
name: 'cantidad_' + row.id,
|
|
||||||
class: 'lp-cell lp-input albaran_linea cantidad-albaran',
|
|
||||||
albaran: item.albaran.numero_albaran,
|
|
||||||
type: 'text',
|
|
||||||
value: data,
|
|
||||||
linea: row.id
|
|
||||||
}).css({
|
|
||||||
'text-align': 'center',
|
|
||||||
'font-size': 'smaller',
|
|
||||||
'max-width': '50px'
|
|
||||||
});
|
|
||||||
return input.prop('outerHTML');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: 'titulo',
|
|
||||||
render: function ( data, type, row, meta ) {
|
|
||||||
|
|
||||||
var input = $('<input>', {
|
|
||||||
id: 'titulo_' + row.id,
|
|
||||||
name: 'titulo_' + row.id,
|
|
||||||
class: 'lp-cell lp-input albaran_linea',
|
|
||||||
albaran: item.albaran.numero_albaran,
|
|
||||||
type: 'text',
|
|
||||||
value: data,
|
|
||||||
linea: row.id
|
|
||||||
}).css({
|
|
||||||
'text-align': 'center',
|
|
||||||
'font-size': 'smaller',
|
|
||||||
'min-width': '300px'
|
|
||||||
});
|
|
||||||
return input.prop('outerHTML');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: 'isbn',
|
|
||||||
render: function ( data, type, row, meta ) {
|
|
||||||
|
|
||||||
var input = $('<input>', {
|
|
||||||
id: 'isbn_' + row.id,
|
|
||||||
name: 'isbn_' + row.id,
|
|
||||||
class: 'lp-cell lp-input albaran_linea',
|
|
||||||
albaran: item.albaran.numero_albaran,
|
|
||||||
type: 'text',
|
|
||||||
value: data,
|
|
||||||
linea: row.id
|
|
||||||
}).css({
|
|
||||||
'text-align': 'center',
|
|
||||||
'font-size': 'smaller'
|
|
||||||
});
|
|
||||||
return input.prop('outerHTML');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: 'ref_cliente',
|
|
||||||
render: function ( data, type, row, meta ) {
|
|
||||||
|
|
||||||
var input = $('<input>', {
|
|
||||||
id: 'ref_cliente_' + row.id,
|
|
||||||
name: 'ref_cliente_' + row.id,
|
|
||||||
class: 'lp-cell lp-input albaran_linea',
|
|
||||||
albaran: item.albaran.numero_albaran,
|
|
||||||
type: 'text',
|
|
||||||
value: data,
|
|
||||||
linea: row.id
|
|
||||||
}).css({
|
|
||||||
'text-align': 'center',
|
|
||||||
'font-size': 'smaller'
|
|
||||||
});
|
|
||||||
return input.prop('outerHTML');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: 'cajas',
|
|
||||||
render: function ( data, type, row, meta ) {
|
|
||||||
|
|
||||||
var input = $('<input>', {
|
|
||||||
id: 'cajas_' + row.id,
|
|
||||||
name: 'cajas_' + row.id,
|
|
||||||
class: 'lp-cell lp-input albaran_linea',
|
|
||||||
albaran: item.albaran.numero_albaran,
|
|
||||||
type: 'text',
|
|
||||||
value: data,
|
|
||||||
linea: row.id
|
|
||||||
}).css({
|
|
||||||
'text-align': 'center',
|
|
||||||
'font-size': 'smaller',
|
|
||||||
'max-width': '50px'
|
|
||||||
});
|
|
||||||
return input.prop('outerHTML');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: 'ejemplares_por_caja',
|
|
||||||
render: function ( data, type, row, meta ) {
|
|
||||||
|
|
||||||
var input = $('<input>', {
|
|
||||||
id: 'ejemplares_por_caja_' + row.id,
|
|
||||||
name: 'ejemplares_por_caja_' + row.id,
|
|
||||||
class: 'lp-cell lp-input albaran_linea',
|
|
||||||
albaran: item.albaran.numero_albaran,
|
|
||||||
type: 'text',
|
|
||||||
value: data,
|
|
||||||
linea: row.id
|
|
||||||
}).css({
|
|
||||||
'text-align': 'center',
|
|
||||||
'font-size': 'smaller',
|
|
||||||
'max-width': '50px'
|
|
||||||
});
|
|
||||||
return input.prop('outerHTML');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: 'precio_unidad',
|
|
||||||
render: function ( data, type, row, meta ) {
|
|
||||||
|
|
||||||
value = parseFloat(data).toFixed(4);
|
|
||||||
var input = $('<input>', {
|
|
||||||
id: 'precio_unidad_' + row.id,
|
|
||||||
name: 'precio_unidad_' + row.id,
|
|
||||||
class: 'lp-cell lp-input albaran_linea',
|
|
||||||
albaran: item.albaran.numero_albaran,
|
|
||||||
type: 'text',
|
|
||||||
value: value,
|
|
||||||
linea: row.id
|
|
||||||
}).css({
|
|
||||||
'text-align': 'center',
|
|
||||||
'font-size': 'smaller',
|
|
||||||
'max-width': '50px'
|
|
||||||
});
|
|
||||||
return input.prop('outerHTML');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: 'total',
|
|
||||||
render: function ( data, type, row, meta ) {
|
|
||||||
|
|
||||||
var input = $('<input>', {
|
|
||||||
id: 'total_' + row.id,
|
|
||||||
name: 'total_' + row.id,
|
|
||||||
class: 'lp-cell lp-input albaran_linea',
|
|
||||||
albaran: item.albaran.numero_albaran,
|
|
||||||
type: 'text',
|
|
||||||
value: data,
|
|
||||||
linea: row.id
|
|
||||||
}).css({
|
|
||||||
'text-align': 'center',
|
|
||||||
'font-size': 'smaller',
|
|
||||||
'max-width': '50px'
|
|
||||||
});
|
|
||||||
return input.prop('outerHTML');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
],
|
|
||||||
columnDefs: [
|
|
||||||
{ targets: [0], visible: false, searchable: false },
|
|
||||||
{ targets: [1], orderable: false },
|
|
||||||
{ targets: [2, 3, 4, 5, 6, 7, 8, 9], className: 'dt-center' }
|
|
||||||
],
|
|
||||||
initComplete: function(settings){
|
|
||||||
var numColumns = this.api().columns().count();
|
|
||||||
if(item.albaran.mostrar_precios == 0){
|
|
||||||
this.api().column(numColumns - 1).visible(false);
|
|
||||||
this.api().column(numColumns - 2).visible(false);
|
|
||||||
} else {
|
|
||||||
this.api().column(numColumns - 1).visible(true);
|
|
||||||
this.api().column(numColumns - 2).visible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// Añadir la nueva fila a la tabla
|
|
||||||
if(Array.isArray(item.lineas)) {
|
|
||||||
item.lineas.forEach(function(linea) {
|
|
||||||
datatableAlbaran.row.add(linea).draw();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$(document).on('click', '.accordion-button', function(){
|
|
||||||
|
|
||||||
var albaran_id = $(this).attr('albaran');
|
|
||||||
var table = $('#tablaAlbaran' + albaran_id).DataTable();
|
|
||||||
table.columns.adjust();
|
|
||||||
});
|
|
||||||
|
|
||||||
$(document).on('change', '.cambios-albaran', function(){
|
|
||||||
|
|
||||||
var elementId = $(this).attr('id');
|
|
||||||
|
|
||||||
data = {
|
|
||||||
<?= csrf_token() ?? "token" ?>: <?= csrf_token() ?>v,
|
|
||||||
};
|
|
||||||
data[elementId.split('_')[0] + '_albaran'] = $(this).val();
|
|
||||||
|
|
||||||
var albaran_id = $(this).attr('albaran_id');
|
|
||||||
var url = '<?= route_to('actualizarAlbaran', ':id') ?>';
|
|
||||||
url = url.replace(':id', albaran_id );
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: url,
|
|
||||||
type: 'POST',
|
|
||||||
data: data,
|
|
||||||
success: function(response){
|
|
||||||
|
|
||||||
if('error' in response){
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
$(document).on('change', '.mostrar-precios', function(){
|
|
||||||
|
|
||||||
var checked = $(this).prop('checked');
|
|
||||||
|
|
||||||
var albaran_id = $(this).attr('albaran_id');
|
|
||||||
var table = $('#tablaAlbaran' + albaran_id).DataTable();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var url = '<?= route_to('actualizarAlbaran', ':id') ?>';
|
|
||||||
url = url.replace(':id', albaran_id );
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: url,
|
|
||||||
type: 'POST',
|
|
||||||
data: {
|
|
||||||
mostrar_precios: checked?1:0,
|
|
||||||
<?= csrf_token() ?? "token" ?>: <?= csrf_token() ?>v,
|
|
||||||
},
|
|
||||||
success: function(response){
|
|
||||||
|
|
||||||
if('error' in response){
|
|
||||||
if(response.error == 0){
|
|
||||||
if(checked){
|
|
||||||
table.column(9).visible(true);
|
|
||||||
table.column(8).visible(true);
|
|
||||||
} else {
|
|
||||||
table.column(9).visible(false);
|
|
||||||
table.column(8).visible(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
$(document).on('click', '.btn-delete-linea', function(){
|
|
||||||
var elementId = $(this).attr('id');
|
|
||||||
var domTable = $(this).closest('table');
|
|
||||||
var table = domTable.DataTable();
|
|
||||||
const row = $(this).closest('tr');
|
|
||||||
var url = '<?= route_to('borrarAlbaranLinea') ?>';
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: url,
|
|
||||||
type: 'POST',
|
|
||||||
data: {
|
|
||||||
id: $(this).attr('data-id'),
|
|
||||||
<?= csrf_token() ?? "token" ?>: <?= csrf_token() ?>v,
|
|
||||||
},
|
|
||||||
success: function(response){
|
|
||||||
|
|
||||||
if('error' in response){
|
|
||||||
if(response.error == 0){
|
|
||||||
table.row($(row)).remove().draw();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
$(document).on('change', '.albaran_linea', function(){
|
|
||||||
|
|
||||||
var elementId = $(this).attr('id');
|
|
||||||
|
|
||||||
if(elementId.includes('cantidad')){
|
|
||||||
const item_id = elementId.split('_').slice(-1)[0];
|
|
||||||
let table = $(this).closest('table').DataTable(); // Obtiene la tabla DataTable
|
|
||||||
let row = $(this).closest('tr'); // Encuentra la fila actual
|
|
||||||
let rowIndex = table.row(row).index(); // Obtiene el índice de la fila
|
|
||||||
|
|
||||||
const previousValue = table.cell(rowIndex, 2).data();
|
|
||||||
const newValue = parseInt($(this).val()); // Obtiene el nuevo valor del input
|
|
||||||
|
|
||||||
let cantidad = calcular_cantidad_albaranes();
|
|
||||||
|
|
||||||
if(cantidad-previousValue+newValue <= parseInt($('#total_tirada').val()) ){
|
|
||||||
// Actualiza el DataTable
|
|
||||||
table.cell(rowIndex, 2).data(newValue);
|
|
||||||
const cajas = parseInt(table.cell(rowIndex, 6).data());
|
|
||||||
table.cell(rowIndex, 7).data(parseInt(newValue/cajas));
|
|
||||||
table.cell(rowIndex, 9).data(parseFloat(parseFloat(table.cell(rowIndex, 8).data()) * newValue).toFixed(2));
|
|
||||||
$('#ejemplares_por_caja_' + item_id).val(parseInt(newValue/cajas)).trigger('change');
|
|
||||||
$('#total_' + item_id).val(parseFloat((table.cell(rowIndex, 8).data()) * newValue).toFixed(2)).trigger('change');
|
|
||||||
cambios_cantidad_albaranes();
|
|
||||||
table.draw();
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
$(this).val(previousValue);
|
|
||||||
table.cell(rowIndex, 7).data(previousValue);
|
|
||||||
table.draw();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data = {
|
|
||||||
<?= csrf_token() ?? "token" ?>: <?= csrf_token() ?>v,
|
|
||||||
};
|
|
||||||
data[elementId.split('_').slice(0, -1).join('_')] = $(this).val();
|
|
||||||
|
|
||||||
var linea_id = $(this).attr('linea');
|
|
||||||
var url = '<?= route_to('actualizarLineaAlbaran', ':id') ?>';
|
|
||||||
url = url.replace(':id', linea_id );
|
|
||||||
|
|
||||||
if(elementId.includes('cajas')){
|
|
||||||
var cajas = $(this).val();
|
|
||||||
var linea_id = elementId.split('_').slice(-1)[0];
|
|
||||||
$('#ejemplares_por_caja_' + linea_id).val(parseInt($('#cantidad_' + linea_id).val()/cajas)).trigger('change');
|
|
||||||
}
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: url,
|
|
||||||
type: 'POST',
|
|
||||||
data: data,
|
|
||||||
success: function(response){
|
|
||||||
|
|
||||||
if('error' in response){
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
$(document).on('click', '#borrar_albaranes', function(){
|
|
||||||
|
|
||||||
asyncConfirmDialogWithParams(
|
|
||||||
"Borrar albaranes",
|
|
||||||
"¿Está seguro de borrar los albaranes? Esta acción no se puede deshacer.",
|
|
||||||
borrar_albaranes, function(){}, [])
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
function borrar_albaranes(){
|
|
||||||
|
|
||||||
// seleccionan todos los accordion dentro del body del accordion accordioAlbaranes
|
|
||||||
$('.accordion-albaran').each(function() {
|
|
||||||
// Aquí puedes trabajar con cada acordeón interno encontrado
|
|
||||||
var albaran_id = $(this).attr('albaran');
|
|
||||||
var url = '<?= route_to('borrarAlbaran', ':id') ?>';
|
|
||||||
url = url.replace(':id', albaran_id );
|
|
||||||
$.ajax({
|
|
||||||
url: url,
|
|
||||||
type: 'GET',
|
|
||||||
success: function(response){
|
|
||||||
if(response){
|
|
||||||
if('error' in response){
|
|
||||||
if(response.error == 0){
|
|
||||||
$('#accordioAlbaran' + albaran_id).remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cambios_cantidad_albaranes();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function borrar_albaran(albaran_id){
|
|
||||||
|
|
||||||
var url = '<?= route_to('borrarAlbaran', ':id') ?>';
|
|
||||||
url = url.replace(':id', albaran_id );
|
|
||||||
$.ajax({
|
|
||||||
url: url,
|
|
||||||
type: 'GET',
|
|
||||||
success: function(response){
|
|
||||||
if(response){
|
|
||||||
if('error' in response){
|
|
||||||
if(response.error == 0){
|
|
||||||
$('#accordioAlbaran' + albaran_id).remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cambios_cantidad_albaranes();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$(document).on('click', '.borrar-albaran', function(){
|
|
||||||
|
|
||||||
var albaran_id = $(this).attr('id').split('_').slice(-1)[0];
|
|
||||||
|
|
||||||
asyncConfirmDialogWithParams(
|
|
||||||
"Borrar albarán",
|
|
||||||
"¿Está seguro de borrar el albarán? Esta acción no se puede deshacer.",
|
|
||||||
borrar_albaran, function(){}, [albaran_id])
|
|
||||||
});
|
|
||||||
|
|
||||||
$(document).on('click', '.nueva-linea-albaran', function(){
|
|
||||||
|
|
||||||
var albaran_id = $(this).attr('id').split('_').slice(-1)[0];
|
|
||||||
var url = '<?= route_to('addAlbaranLinea', ':id') ?>';
|
|
||||||
url = url.replace(':id', albaran_id );
|
|
||||||
$.ajax({
|
|
||||||
url: url,
|
|
||||||
type: 'GET',
|
|
||||||
success: function(response){
|
|
||||||
if(response){
|
|
||||||
if('error' in response){
|
|
||||||
if(response.error == 0){
|
|
||||||
var table = $('#tablaAlbaran' + albaran_id).DataTable();
|
|
||||||
table.row.add(response.data).draw();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
$(document).on('click', '.add-iva-albaran', function(){
|
|
||||||
|
|
||||||
var albaran_id = $(this).attr('id').split('_').slice(-1)[0];
|
|
||||||
var url = '<?= route_to('addIVA', ':id') ?>';
|
|
||||||
url = url.replace(':id', albaran_id );
|
|
||||||
data = {
|
|
||||||
albaran_id: albaran_id,
|
|
||||||
<?= csrf_token() ?? "token" ?>: <?= csrf_token() ?>v,
|
|
||||||
};
|
|
||||||
$.ajax({
|
|
||||||
url: url,
|
|
||||||
type: 'POST',
|
|
||||||
data: data,
|
|
||||||
success: function(response){
|
|
||||||
if(response){
|
|
||||||
if('error' in response){
|
|
||||||
if(response.error == 0){
|
|
||||||
var table = $('#tablaAlbaran' + albaran_id).DataTable();
|
|
||||||
table.row.add(response.data).draw();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
$(document).on('click', '.imprimir-albaran', function(){
|
|
||||||
|
|
||||||
var albaran_id = $(this).attr('id').split('_').slice(-1)[0];
|
|
||||||
|
|
||||||
window.open('<?= site_url('print-albaran/generar/') ?>' + albaran_id, '_blank');
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: '<?= route_to('getAlbaranes', $pedidoEntity->id) ?>',
|
|
||||||
type: 'GET',
|
|
||||||
success: function(response){
|
|
||||||
|
|
||||||
if(response.data.length > 0){
|
|
||||||
Object.values(response.data).forEach(function(item){
|
|
||||||
generarAlbaran(item);
|
|
||||||
});
|
|
||||||
|
|
||||||
cambios_cantidad_albaranes();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
function calcular_cantidad_albaranes(){
|
|
||||||
let cantidad_albaranes = 0;
|
|
||||||
const tablas = $('.table.table-albaran');
|
|
||||||
const tabla_pedido = $('#tableOfLineasPedido').DataTable();
|
|
||||||
const titulo = tabla_pedido.column(3).data().toArray()[0];
|
|
||||||
for(var i = 0; i < tablas.length; i++){
|
|
||||||
var table = $(tablas[i]).DataTable();
|
|
||||||
table.rows().every(function(){
|
|
||||||
if(titulo && titulo.length >0 && this.data() && titulo.includes(this.data().titulo)){
|
|
||||||
cantidad_albaranes += parseInt(this.data().cantidad) || 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return cantidad_albaranes;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function cambios_cantidad_albaranes(){
|
|
||||||
const cantidad_albaranes = calcular_cantidad_albaranes();
|
|
||||||
check_cantidad_albaranes(cantidad_albaranes);
|
|
||||||
}
|
|
||||||
|
|
||||||
function check_cantidad_albaranes(unidades_albaranes){
|
|
||||||
if(unidades_albaranes != parseInt($('#total_tirada').val()) ){
|
|
||||||
$('#alert-albaranes').removeClass('d-none');
|
|
||||||
$('#error-albaranes').
|
|
||||||
html('<?= lang('Pedidos.validation.errorCantidadAlbaranes') ?>'
|
|
||||||
.replace('{0}', unidades_albaranes)
|
|
||||||
.replace('{1}', $('#total_tirada').val()));
|
|
||||||
$('#generar_albaranes').removeClass('d-none');
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
$('#alert-albaranes').addClass('d-none');
|
|
||||||
$('#error-albaranes').html('');
|
|
||||||
$('#generar_albaranes').addClass('d-none');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
<?=$this->endSection() ?>
|
|
||||||
@ -99,7 +99,7 @@ var tableOfLineasPedido = new DataTable('#tableOfLineasPedido',{
|
|||||||
drawCallback: function(){
|
drawCallback: function(){
|
||||||
$(this.api().table().container()).find('table').css('width', '100%');
|
$(this.api().table().container()).find('table').css('width', '100%');
|
||||||
this.api().columns.adjust();
|
this.api().columns.adjust();
|
||||||
cambios_cantidad_albaranes();
|
//cambios_cantidad_albaranes();
|
||||||
},
|
},
|
||||||
footerCallback: function (row, data, start, end, display) {
|
footerCallback: function (row, data, start, end, display) {
|
||||||
let api = this.api();
|
let api = this.api();
|
||||||
|
|||||||
@ -29,9 +29,6 @@
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?= view("themes/vuexy/form/pedidos/_cabeceraItems") ?>
|
<?= view("themes/vuexy/form/pedidos/_cabeceraItems") ?>
|
||||||
<?= view("themes/vuexy/form/pedidos/_lineasItems") ?>
|
<?= view("themes/vuexy/form/pedidos/_lineasItems") ?>
|
||||||
<?php if (!(auth()->user()->inGroup('cliente-admin') || auth()->user()->inGroup('cliente-editor'))) : ?>
|
|
||||||
<?= view("themes/vuexy/form/pedidos/_albaranesItems") ?>
|
|
||||||
<?php endif; ?>
|
|
||||||
<?= view("themes/vuexy/form/pedidos/_facturasItems") ?>
|
<?= view("themes/vuexy/form/pedidos/_facturasItems") ?>
|
||||||
<?= view("themes/vuexy/components/chat_internal_pedido", data: ["modelId" => $pedidoEntity->id, "type" => "pedido"]) ?>
|
<?= view("themes/vuexy/components/chat_internal_pedido", data: ["modelId" => $pedidoEntity->id, "type" => "pedido"]) ?>
|
||||||
</div><!-- /.card-body -->
|
</div><!-- /.card-body -->
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import ClassSelect from '../../components/select2.js';
|
import ClassSelect from '../../components/select2.js';
|
||||||
import Ajax from '../../components/ajax.js';
|
import Ajax from '../../components/ajax.js';
|
||||||
|
import AlbaranComponent from '../../components/albaranComponent.js';
|
||||||
|
|
||||||
class EnvioEdit {
|
class EnvioEdit {
|
||||||
|
|
||||||
@ -8,6 +9,7 @@ class EnvioEdit {
|
|||||||
|
|
||||||
this.tableCols = [
|
this.tableCols = [
|
||||||
{ data: "rowSelected" },
|
{ data: "rowSelected" },
|
||||||
|
{ data: "cajasRaw", defaultContent: "" },
|
||||||
{ data: "cajas", defaultContent: "" },
|
{ data: "cajas", defaultContent: "" },
|
||||||
{ data: "pedido" },
|
{ data: "pedido" },
|
||||||
{ data: "presupuesto" },
|
{ data: "presupuesto" },
|
||||||
@ -15,9 +17,9 @@ class EnvioEdit {
|
|||||||
{ data: "unidadesEnvio" },
|
{ data: "unidadesEnvio" },
|
||||||
{ data: "unidadesEnviadas" },
|
{ data: "unidadesEnviadas" },
|
||||||
{ data: "unidadesTotal" },
|
{ data: "unidadesTotal" },
|
||||||
{ data: "action" },
|
|
||||||
{ data: "id" },
|
{ data: "id" },
|
||||||
{ data: "pesoUnidad" }
|
{ data: "pesoUnidad" },
|
||||||
|
{ data: "unidadesEnvioRaw" }
|
||||||
];
|
];
|
||||||
|
|
||||||
this.table = null;
|
this.table = null;
|
||||||
@ -29,6 +31,8 @@ class EnvioEdit {
|
|||||||
this.btnAddCaja = $("#btnAddCaja");
|
this.btnAddCaja = $("#btnAddCaja");
|
||||||
this.btnDeleteLinea = $("#btnEliminarLineas");
|
this.btnDeleteLinea = $("#btnEliminarLineas");
|
||||||
this.btnGuardarComentarios = $("#guardarComentarios");
|
this.btnGuardarComentarios = $("#guardarComentarios");
|
||||||
|
this.btnSelectAll = $("#btnSelectAll");
|
||||||
|
this.btnGenerarAlbaran = $("#btnGenerarAlbaran");
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
@ -51,43 +55,45 @@ class EnvioEdit {
|
|||||||
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
|
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
|
||||||
},
|
},
|
||||||
rowGroup: {
|
rowGroup: {
|
||||||
dataSrc: 'cajas',
|
dataSrc: 'cajasRaw',
|
||||||
startRender: function (rows, group) {
|
startRender: function (rows, group) {
|
||||||
const nombreGrupo = group === null || group === '' || group === 'null' || group.toUpperCase() === 'NO GROUP'
|
// Forzar el grupo a string (DataTables puede pasarlo como undefined o null de forma interna)
|
||||||
? 'SIN ASIGNAR'
|
const groupStr = group == null || group === 0 || group === '0' ? '__SIN__ASIGNAR__' : group.toString();
|
||||||
: group;
|
const nombreGrupo = groupStr === '__SIN__ASIGNAR__' ? 'SIN ASIGNAR' : groupStr;
|
||||||
|
|
||||||
let totalUnidades = 0;
|
let totalUnidades = 0;
|
||||||
let totalPeso = 0;
|
let totalPeso = 0;
|
||||||
rows.data().each(function (row) {
|
rows.data().each(function (row) {
|
||||||
const unidades = parseInt(row.unidadesEnvio) || 0;
|
const unidades = parseInt(row.unidadesEnvioRaw) || 0;
|
||||||
totalUnidades += unidades;
|
totalUnidades += unidades;
|
||||||
totalPeso += parseFloat(row.pesoUnidad) * unidades || 0;
|
totalPeso += (parseFloat(row.pesoUnidad) || 0) * unidades;
|
||||||
});
|
});
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<label class="switch switch-square">
|
<label class="switch switch-square">
|
||||||
<input type="checkbox" class="switch-input switch-grupo" data-grupo="${nombreGrupo}" id="switch-grupo-${nombreGrupo}">
|
<input type="checkbox" class="switch-input switch-grupo" data-grupo="${groupStr}" id="switch-grupo-${groupStr}">
|
||||||
<span class="switch-toggle-slider"></span>
|
<span class="switch-toggle-slider"></span>
|
||||||
<span class="switch-label">
|
<span class="switch-label">
|
||||||
CAJA: ${nombreGrupo} [unidades: ${totalUnidades}, peso: <span class="peso-grupo" data-valor="${totalPeso}">${totalPeso.toFixed(1)}</span> kg]
|
CAJA: ${nombreGrupo} [unidades: ${totalUnidades}, peso: <span class="peso-grupo" data-valor="${totalPeso}">${totalPeso.toFixed(1)}</span> kg]
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
"columnDefs": [
|
"columnDefs": [
|
||||||
{
|
{
|
||||||
"targets": [0, 8],
|
"targets": [0],
|
||||||
"className": "text-center",
|
"className": "text-center",
|
||||||
"orderable": false,
|
"orderable": false,
|
||||||
"searchable": false,
|
"searchable": false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"targets": [2, 3, 5, 6, 7],
|
"targets": [3, 4, 6, 7, 8],
|
||||||
"className": "text-center",
|
"className": "text-center",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
targets: [1, 9, 10],
|
targets: [1, 9, 10, 11],
|
||||||
visible: false
|
visible: false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@ -105,9 +111,10 @@ class EnvioEdit {
|
|||||||
const rowData = this.data();
|
const rowData = this.data();
|
||||||
const node = $(this.node());
|
const node = $(this.node());
|
||||||
|
|
||||||
const valorCaja = (rowData.cajas === null || rowData.cajas === '' || rowData.cajas === 0 || rowData.cajas === '0')
|
const valorCaja = (rowData.cajasRaw === null || rowData.cajasRaw === '' ||
|
||||||
? 'SIN ASIGNAR'
|
rowData.cajasRaw === 0 || rowData.cajasRaw === '0' || rowData.cajasRaw === undefined)
|
||||||
: rowData.cajas;
|
? '__SIN__ASIGNAR__'
|
||||||
|
: rowData.cajasRaw.toString();
|
||||||
|
|
||||||
if (valorCaja == grupo) {
|
if (valorCaja == grupo) {
|
||||||
node.find('.checkbox-linea-envio').prop('checked', checked);
|
node.find('.checkbox-linea-envio').prop('checked', checked);
|
||||||
@ -152,9 +159,9 @@ class EnvioEdit {
|
|||||||
const table = $('#tableLineasEnvio').DataTable();
|
const table = $('#tableLineasEnvio').DataTable();
|
||||||
const rowData = table.row($row).data();
|
const rowData = table.row($row).data();
|
||||||
|
|
||||||
const valorCaja = (rowData.cajas === null || rowData.cajas === '' || rowData.cajas === 0 || rowData.cajas === '0')
|
const valorCaja = (rowData.cajasRaw === null || rowData.cajasRaw === '' || rowData.cajasRaw === 0 || rowData.cajasRaw === '0')
|
||||||
? 'SIN ASIGNAR'
|
? '__SIN__ASIGNAR__'
|
||||||
: rowData.cajas;
|
: rowData.cajasRaw;
|
||||||
|
|
||||||
// 1. Filtrar todas las filas del mismo grupo
|
// 1. Filtrar todas las filas del mismo grupo
|
||||||
let total = 0;
|
let total = 0;
|
||||||
@ -162,9 +169,9 @@ class EnvioEdit {
|
|||||||
|
|
||||||
table.rows().every(function () {
|
table.rows().every(function () {
|
||||||
const data = this.data();
|
const data = this.data();
|
||||||
const grupo = (data.cajas === null || data.cajas === '' || data.cajas === 0 || data.cajas === '0')
|
const grupo = (data.cajasRaw === null || data.cajasRaw === '' || data.cajasRaw === 0 || data.cajasRaw === '0')
|
||||||
? 'SIN ASIGNAR'
|
? 'SIN ASIGNAR'
|
||||||
: data.cajas;
|
: data.cajasRaw;
|
||||||
|
|
||||||
if (grupo == valorCaja) {
|
if (grupo == valorCaja) {
|
||||||
total++;
|
total++;
|
||||||
@ -184,72 +191,49 @@ class EnvioEdit {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on('click', '.btn-edit', (e) => {
|
$(document).on('change', '.input-lineas', (e) => {
|
||||||
const table = this.table;
|
const table = this.table;
|
||||||
const id = $(e.currentTarget).data('id');
|
|
||||||
const row = table.row($(e.currentTarget).closest('tr'));
|
const row = table.row($(e.currentTarget).closest('tr'));
|
||||||
const rowData = row.data();
|
const rowData = row.data();
|
||||||
|
const fieldName = $(e.currentTarget).data('name');
|
||||||
|
const fieldValue = $(e.currentTarget).val();
|
||||||
|
|
||||||
Swal.fire({
|
$.post('/logistica/updateLineaEnvio', {
|
||||||
title: 'Editar unidades a enviar',
|
id: rowData.id,
|
||||||
input: 'number',
|
"name": fieldName,
|
||||||
inputLabel: `Unidades actuales: ${rowData.unidadesEnvio}`,
|
'value': fieldValue
|
||||||
inputValue: rowData.unidadesEnvio,
|
}, function (response) {
|
||||||
inputAttributes: {
|
if (response.status) {
|
||||||
min: 1
|
table.draw(false);
|
||||||
},
|
} else {
|
||||||
showCancelButton: true,
|
Swal.fire({
|
||||||
confirmButtonText: 'Guardar',
|
title: 'Error',
|
||||||
cancelButtonText: 'Cancelar',
|
text: response.message,
|
||||||
inputValidator: (value) => {
|
icon: 'error',
|
||||||
if (!value || parseInt(value) <= 0) {
|
showCancelButton: false,
|
||||||
return 'Debes ingresar un valor mayor a 0';
|
confirmButtonColor: '#3085d6',
|
||||||
}
|
confirmButtonText: 'Ok',
|
||||||
},
|
customClass: {
|
||||||
customClass: {
|
confirmButton: 'btn btn-primary me-1',
|
||||||
confirmButton: 'btn btn-primary me-1',
|
},
|
||||||
cancelButton: 'btn btn-secondary'
|
buttonsStyling: false
|
||||||
},
|
|
||||||
buttonsStyling: false
|
|
||||||
}).then((result) => {
|
|
||||||
if (result.isConfirmed) {
|
|
||||||
const nuevasUnidades = parseInt(result.value);
|
|
||||||
|
|
||||||
$.post('/logistica/updateUnidadesEnvio', {
|
|
||||||
id: rowData.id,
|
|
||||||
unidades_envio: nuevasUnidades
|
|
||||||
}, function (response) {
|
|
||||||
if (response.status) {
|
|
||||||
table.draw(false);
|
|
||||||
} else {
|
|
||||||
Swal.fire({
|
|
||||||
title: 'Error',
|
|
||||||
text: response.message,
|
|
||||||
icon: 'error',
|
|
||||||
showCancelButton: false,
|
|
||||||
confirmButtonColor: '#3085d6',
|
|
||||||
confirmButtonText: 'Ok',
|
|
||||||
customClass: {
|
|
||||||
confirmButton: 'btn btn-primary me-1',
|
|
||||||
},
|
|
||||||
buttonsStyling: false
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}).fail(() => {
|
|
||||||
Swal.fire({
|
|
||||||
title: 'Error',
|
|
||||||
text: 'No se pudo actualizar el dato.',
|
|
||||||
icon: 'error',
|
|
||||||
showCancelButton: false,
|
|
||||||
confirmButtonColor: '#3085d6',
|
|
||||||
confirmButtonText: 'Ok',
|
|
||||||
customClass: {
|
|
||||||
confirmButton: 'btn btn-primary me-1',
|
|
||||||
},
|
|
||||||
buttonsStyling: false
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
table.draw(false);
|
||||||
}
|
}
|
||||||
|
}).fail(() => {
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Error',
|
||||||
|
text: 'No se pudo actualizar el dato.',
|
||||||
|
icon: 'error',
|
||||||
|
showCancelButton: false,
|
||||||
|
confirmButtonColor: '#3085d6',
|
||||||
|
confirmButtonText: 'Ok',
|
||||||
|
customClass: {
|
||||||
|
confirmButton: 'btn btn-primary me-1',
|
||||||
|
},
|
||||||
|
buttonsStyling: false
|
||||||
|
});
|
||||||
|
table.draw(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -258,6 +242,8 @@ class EnvioEdit {
|
|||||||
this.btnAddLinea.on('click', this._addEnvioLinea.bind(this));
|
this.btnAddLinea.on('click', this._addEnvioLinea.bind(this));
|
||||||
this.btnAddCaja.on('click', this._addCaja.bind(this));
|
this.btnAddCaja.on('click', this._addCaja.bind(this));
|
||||||
this.btnDeleteLinea.on('click', this._deleteLineas.bind(this));
|
this.btnDeleteLinea.on('click', this._deleteLineas.bind(this));
|
||||||
|
this.btnGenerarAlbaran.on('click', this._generarAlbaran.bind(this));
|
||||||
|
|
||||||
this.btnGuardarComentarios.on('click', () => {
|
this.btnGuardarComentarios.on('click', () => {
|
||||||
|
|
||||||
$.post('/logistica/updateComentariosEnvio', {
|
$.post('/logistica/updateComentariosEnvio', {
|
||||||
@ -274,6 +260,127 @@ class EnvioEdit {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
this.btnSelectAll.on('click', () => {
|
||||||
|
$('.switch-grupo').each(function () {
|
||||||
|
const $switch = $(this);
|
||||||
|
if (!$switch.is(':checked')) {
|
||||||
|
$switch.prop('checked', true).trigger('change');
|
||||||
|
} else {
|
||||||
|
// incluso si ya está marcado, forzamos el evento por seguridad
|
||||||
|
$switch.trigger('change');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
this._getAlbaranes();
|
||||||
|
}
|
||||||
|
|
||||||
|
_getAlbaranes() {
|
||||||
|
$.get('/albaranes/albaranesEnvio', {
|
||||||
|
envio_id: $('#id').val(),
|
||||||
|
}, function (response) {
|
||||||
|
if (response.status && response.data) {
|
||||||
|
|
||||||
|
for (let i = 0; i < response.data.length; i++) {
|
||||||
|
const albaran = response.data[i];
|
||||||
|
new AlbaranComponent(albaran).mount('#contenedorAlbaranes');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Error',
|
||||||
|
text: response.message,
|
||||||
|
icon: 'error',
|
||||||
|
showCancelButton: false,
|
||||||
|
confirmButtonColor: '#3085d6',
|
||||||
|
confirmButtonText: 'Ok',
|
||||||
|
customClass: {
|
||||||
|
confirmButton: 'btn btn-primary me-1',
|
||||||
|
},
|
||||||
|
buttonsStyling: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).fail(() => {
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Error',
|
||||||
|
text: 'No se han podido obtener los albaranes.',
|
||||||
|
icon: 'error',
|
||||||
|
showCancelButton: false,
|
||||||
|
confirmButtonColor: '#3085d6',
|
||||||
|
confirmButtonText: 'Ok',
|
||||||
|
customClass: {
|
||||||
|
confirmButton: 'btn btn-primary me-1',
|
||||||
|
},
|
||||||
|
buttonsStyling: false
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_generarAlbaran() {
|
||||||
|
|
||||||
|
// se seleccionan los id de las lineas de envio con checkbox marcado
|
||||||
|
const table = this.table;
|
||||||
|
const selectedRows = table.rows({ page: 'current' }).nodes().filter((node) => {
|
||||||
|
const checkbox = $(node).find('.checkbox-linea-envio');
|
||||||
|
return checkbox.is(':checked');
|
||||||
|
});
|
||||||
|
const ids = selectedRows.map((node) => {
|
||||||
|
const rowData = table.row(node).data();
|
||||||
|
return rowData.id;
|
||||||
|
}
|
||||||
|
).toArray();
|
||||||
|
if (ids.length <= 0) {
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Atención!',
|
||||||
|
text: 'Debe seleccionar al menos una línea de envío para generar el albarán.',
|
||||||
|
icon: 'info',
|
||||||
|
showCancelButton: false,
|
||||||
|
confirmButtonColor: '#3085d6',
|
||||||
|
confirmButtonText: 'Ok',
|
||||||
|
customClass: {
|
||||||
|
confirmButton: 'btn btn-primary me-1',
|
||||||
|
},
|
||||||
|
buttonsStyling: false
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const idEnvio = $('#id').val();
|
||||||
|
$.post('/albaranes/generarAlbaran', {
|
||||||
|
envio_id: idEnvio,
|
||||||
|
envio_lineas: ids
|
||||||
|
}, function (response) {
|
||||||
|
if (response.status && response.albaran) {
|
||||||
|
|
||||||
|
new AlbaranComponent(response.albaran).mount('#contenedorAlbaranes');
|
||||||
|
} else {
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Error',
|
||||||
|
text: response.message,
|
||||||
|
icon: 'error',
|
||||||
|
showCancelButton: false,
|
||||||
|
confirmButtonColor: '#3085d6',
|
||||||
|
confirmButtonText: 'Ok',
|
||||||
|
customClass: {
|
||||||
|
confirmButton: 'btn btn-primary me-1',
|
||||||
|
},
|
||||||
|
buttonsStyling: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).fail(() => {
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Error',
|
||||||
|
text: 'No se pudo generar el albarán.',
|
||||||
|
icon: 'error',
|
||||||
|
showCancelButton: false,
|
||||||
|
confirmButtonColor: '#3085d6',
|
||||||
|
confirmButtonText: 'Ok',
|
||||||
|
customClass: {
|
||||||
|
confirmButton: 'btn btn-primary me-1',
|
||||||
|
},
|
||||||
|
buttonsStyling: false
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_deleteLineas() {
|
_deleteLineas() {
|
||||||
@ -441,8 +548,8 @@ class EnvioEdit {
|
|||||||
$('.dtrg-group').each(function () {
|
$('.dtrg-group').each(function () {
|
||||||
const $grupo = $(this);
|
const $grupo = $(this);
|
||||||
let nombreGrupo = $grupo.text().toUpperCase().replace('CAJA:', '').trim();
|
let nombreGrupo = $grupo.text().toUpperCase().replace('CAJA:', '').trim();
|
||||||
if (nombreGrupo === 'SIN ASIGNAR') {
|
if (nombreGrupo.includes('SIN ASIGNAR')) {
|
||||||
nombreGrupo = null;
|
nombreGrupo = '__SIN__ASIGNAR__';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Evitar aplicar múltiples veces
|
// Evitar aplicar múltiples veces
|
||||||
@ -655,7 +762,23 @@ class EnvioEdit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function () {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
new EnvioEdit().init();
|
const dropdown = document.querySelector(".dropdown-language");
|
||||||
|
const activeItem = dropdown.querySelector(".dropdown-menu .dropdown-item");
|
||||||
|
let locale = 'es';
|
||||||
|
if (activeItem) {
|
||||||
|
locale = activeItem.getAttribute("data-language");
|
||||||
|
}
|
||||||
|
|
||||||
|
new Ajax('/translate/getTranslation', { locale: locale, translationFile: ['Albaran'] }, {},
|
||||||
|
function (translations) {
|
||||||
|
window.language = JSON.parse(translations);
|
||||||
|
new EnvioEdit().init();
|
||||||
|
},
|
||||||
|
function (error) {
|
||||||
|
console.log("Error getting translations:", error);
|
||||||
|
}
|
||||||
|
).post();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default EnvioEdit;
|
export default EnvioEdit;
|
||||||
Reference in New Issue
Block a user