trabajando en añadir lineas a envio

This commit is contained in:
2025-04-17 13:47:26 +02:00
parent 9e90ec798c
commit 3949607a3c
5 changed files with 223 additions and 82 deletions

View File

@ -70,7 +70,7 @@ class LogisticaController extends BaseController
return view(static::$viewPath . 'viewLogisticaSelectEnvios', $viewData);
}
public function searchPedidoOrISBN($search = "")
public function searchPedidoOrISBN($search = "", $envio_id = null)
{
if (empty($search)) {
@ -80,10 +80,27 @@ class LogisticaController extends BaseController
];
return $this->response->setJSON($result);
}
$result = LogisticaService::findPedidoOrISBN($search);
$result = LogisticaService::findPedidoOrISBN($search, $envio_id);
return $this->response->setJSON($result);
}
public function selectAddEnvioLinea(){
if ($this->request->isAJAX()) {
$query = LogisticaService::findLineaEnvio($this->request->getGet('direccion'))->orderBy("nombre", "asc");
if ($this->request->getGet("q")) {
$query->groupStart()
->orLike("pedidos.id", $this->request->getGet("q"))
->orLike("presupuestos.titulo", $this->request->getGet("q"))
->groupEnd();
}
return $this->response->setJSON($query->get()->getResultObject());
} else {
return $this->failUnauthorized('Invalid request', 403);
}
}
public function datatable_envios()
{
$model = model('App\Models\Logistica\EnvioModel');
@ -111,4 +128,53 @@ class LogisticaController extends BaseController
return $result->toJson(returnAsObject: true);
}
public function editEnvio($id = null){
if (empty($id)) {
return redirect()->to(base_url('logistica/selectEnvios/simple'))->with('error', lang('Logistica.errors.noEnvio'));
}
$model = model('App\Models\Logistica\EnvioModel');
$envioEntity = $model->select('envios.*, lg_paises.nombre as pais')
->join('lg_paises', 'lg_paises.id = envios.pais_id', 'left')
->where('envios.id', $id)
->first();
if (empty($envioEntity)) {
return redirect()->to(base_url('logistica/selectEnvios/simple'))->with('error', lang('Logistica.errors.noEnvio'));
}
$viewData = [
'currentModule' => static::$controllerSlug,
'boxTitle' => '<i class="ti ti-truck ti-xl"></i>' . ' '. lang('Logistica.envio') . ' [' . $envioEntity->id . ']: ' . $envioEntity->direccion,
'usingServerSideDataTable' => true,
'envioEntity' => $envioEntity,
];
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
return view(static::$viewPath . 'viewEnvioEditForm', $viewData);
}
public function datatable_enviosEdit($idEnvio)
{
$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("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>
';
});
return $result->toJson(returnAsObject: true);
}
}