terminada envio lineas

This commit is contained in:
2025-04-18 13:38:06 +02:00
parent 15f6d0d675
commit 0b04e6dabd
14 changed files with 1313 additions and 19 deletions

View File

@ -84,26 +84,29 @@ class LogisticaController extends BaseController
return $this->response->setJSON($result);
}
public function selectAddEnvioLinea(){
public function selectAddEnvioLinea()
{
if ($this->request->isAJAX()) {
$query = LogisticaService::findLineaEnvioPorEnvio($this->request->getGet('envio'))->orderBy("name", "asc");
$query = LogisticaService::findLineaEnvioPorEnvio($this->request->getGet('envio'));
if ($this->request->getGet("q")) {
$query->groupStart()
->orLike("pedidos.id", $this->request->getGet("q"))
->orLike("presupuestos.titulo", $this->request->getGet("q"))
->orLike("p.id", $this->request->getGet("q"))
->orLike("pr.titulo", $this->request->getGet("q"))
->groupEnd();
}
$result = $query->get()->getResultObject();
$result = $query->orderBy("name", "asc")->get()->getResultObject();
return $this->response->setJSON($result);
} else {
return $this->failUnauthorized('Invalid request', 403);
}
}
public function addEnvioLinea(){
public function addEnvioLinea()
{
if ($this->request->isAJAX()) {
$pedido_id = $this->request->getGet('pedido_id');
@ -123,20 +126,20 @@ class LogisticaController extends BaseController
$model = model('App\Models\Logistica\EnvioModel');
$q = $model->getDatatableQuery();
$result = DataTable::of($q)
->edit(
"finalizado",
function ($row, $meta) {
if ($row->finalizado == 1)
if ($row->finalizado == 1)
return '<i class="ti ti-check"></i>';
else
return '<i class="ti ti-x"></i>';
}
)
->add("action", callback: function ($q) {
return '
return '
<div class="btn-group btn-group-sm">
<a href="javascript:void(0);"><i class="ti ti-eye ti-sm btn-edit mx-2" data-id="' . $q->id . '"></i></a>
</div>
@ -146,7 +149,8 @@ class LogisticaController extends BaseController
return $result->toJson(returnAsObject: true);
}
public function editEnvio($id = null){
public function editEnvio($id = null)
{
if (empty($id)) {
return redirect()->to(base_url('logistica/selectEnvios/simple'))->with('error', lang('Logistica.errors.noEnvio'));
@ -159,10 +163,11 @@ class LogisticaController extends BaseController
if (empty($envioEntity)) {
return redirect()->to(base_url('logistica/selectEnvios/simple'))->with('error', lang('Logistica.errors.noEnvio'));
}
$envioEntity->nextCaja = model('App\Models\Logistica\EnvioLineaModel')->getMaxCaja();
$viewData = [
'currentModule' => static::$controllerSlug,
'boxTitle' => '<i class="ti ti-truck ti-xl"></i>' . ' '. lang('Logistica.envio') . ' [' . $envioEntity->id . ']: ' . $envioEntity->direccion,
'boxTitle' => '<i class="ti ti-truck ti-xl"></i>' . ' ' . lang('Logistica.envio') . ' [' . $envioEntity->id . ']: ' . $envioEntity->direccion,
'usingServerSideDataTable' => true,
'envioEntity' => $envioEntity,
];
@ -177,15 +182,17 @@ class LogisticaController extends BaseController
$model = model('App\Models\Logistica\EnvioLineaModel');
$q = $model->getDatatableQuery($idEnvio);
$result = DataTable::of($q)
->add("rowSelected",callback: function ($q) {
return '<input type="checkbox" class="form-check-input" name="row_selected[]" value="' . $q->id . '">';
->add(
"rowSelected",
callback: function ($q) {
return '<input type="checkbox" class="form-check-input checkbox-linea-envio" name="row_selected[]" value="' . $q->id . '">';
}
)
->add("action", callback: function ($q) {
return '
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>
@ -194,4 +201,85 @@ class LogisticaController extends BaseController
return $result->toJson(returnAsObject: true);
}
public function setCajaLinea()
{
if ($this->request->isAJAX()) {
$id = $this->request->getPost('id');
$caja = $this->request->getPost('caja');
$model = model('App\Models\Logistica\EnvioLineaModel');
$result = $model->update($id, [
'cajas' => $caja,
]);
return $this->response->setJSON([
"status" => $result,
]);
} else {
return $this->failUnauthorized('Invalid request', 403);
}
}
public function deleteLineas()
{
if ($this->request->isAJAX()) {
$ids = $this->request->getPost('ids');
$model = model('App\Models\Logistica\EnvioLineaModel');
$result = $model->delete($ids);
return $this->response->setJSON([
"status" => $result,
]);
} else {
return $this->failUnauthorized('Invalid request', 403);
}
}
public function updateUnidadesEnvio()
{
$id = $this->request->getPost('id');
$unidades = $this->request->getPost('unidades_envio');
if (!$id || !$unidades || intval($unidades) <= 0) {
return $this->response->setJSON([
'status' => false,
'message' => 'Datos inválidos'
]);
}
$model = model('App\Models\Logistica\EnvioLineaModel');
$updated = $model->update($id, [
'unidades_envio' => $unidades,
]);
return $this->response->setJSON([
'status' => $updated,
'message' => $updated ? 'Actualizado' : 'Error al actualizar'
]);
}
public function saveComments()
{
$id = $this->request->getPost('id');
$comments = $this->request->getPost('comentarios');
if (!$id || !$comments) {
return $this->response->setJSON([
'status' => false,
'message' => 'Datos inválidos'
]);
}
$model = model('App\Models\Logistica\EnvioModel');
$updated = $model->update($id, [
'comentarios' => $comments,
]);
return $this->response->setJSON([
'status' => $updated,
'message' => $updated ? 'Actualizado' : 'Error al actualizar'
]);
}
}