mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
añadiendo tarifas envio
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
<?php namespace App\Controllers\Compras;
|
||||
|
||||
use stdClass;
|
||||
use App\Controllers\GoBaseResourceController;
|
||||
|
||||
use App\Models\Collection;
|
||||
@ -75,6 +76,9 @@ class Proveedores extends \App\Controllers\GoBaseResourceController {
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
// Rellenar el campo "propiedades" si es necesario
|
||||
$postData = $this->getPropiedadesFromPost($postData);
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
@ -107,7 +111,8 @@ class Proveedores extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
if ($thenRedirect) :
|
||||
if (!empty($this->indexRoute)) :
|
||||
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
|
||||
return redirect()->to(site_url('/compras/proveedores/edit/' . $id))->with('message', $message);
|
||||
//return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
|
||||
else:
|
||||
return $this->redirect2listView('sweet-success', $message);
|
||||
endif;
|
||||
@ -139,6 +144,13 @@ class Proveedores extends \App\Controllers\GoBaseResourceController {
|
||||
endif;
|
||||
$id = filter_var($requestedId, FILTER_SANITIZE_URL);
|
||||
$proveedorEntity = $this->model->find($id);
|
||||
|
||||
// Propiedades para proveedores tipo transporte
|
||||
if(!is_null($proveedorEntity->propiedades))
|
||||
{
|
||||
$proveedorEntity = $this->getPropiedadesFromEntity($proveedorEntity);
|
||||
}
|
||||
|
||||
|
||||
if ($proveedorEntity == false) :
|
||||
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Proveedores.proveedor')), $id]);
|
||||
@ -153,10 +165,11 @@ class Proveedores extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
|
||||
// Rellenar el campo "propiedades" si es necesario
|
||||
$postData = $this->getPropiedadesFromPost($postData);
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
|
||||
@ -177,7 +190,7 @@ class Proveedores extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
$proveedorEntity->fill($sanitizedData);
|
||||
|
||||
$thenRedirect = false;
|
||||
$thenRedirect = true;
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
$id = $proveedorEntity->id ?? $id;
|
||||
@ -188,7 +201,9 @@ class Proveedores extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
if ($thenRedirect) :
|
||||
if (!empty($this->indexRoute)) :
|
||||
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
|
||||
//return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
|
||||
$this->session->setFlashData('sweet-success', $message);
|
||||
return redirect()->to(site_url('/compras/proveedores/edit/' . $id))->with('message', $message);
|
||||
else:
|
||||
return $this->redirect2listView('sweet-success', $message);
|
||||
endif;
|
||||
@ -199,6 +214,7 @@ class Proveedores extends \App\Controllers\GoBaseResourceController {
|
||||
endif; // $noException && $successfulResult
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
|
||||
$this->viewData['proveedorEntity'] = $proveedorEntity;
|
||||
$this->viewData['proveedorTipoList'] = $this->getProveedorTipoListItems($proveedorEntity->tipo_id ?? null);
|
||||
$this->viewData['provinciaList'] = $this->getProvinciaListItems($proveedorEntity->provincia_id ?? null);
|
||||
@ -326,4 +342,43 @@ class Proveedores extends \App\Controllers\GoBaseResourceController {
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
private function getPropiedadesFromEntity($entity){
|
||||
|
||||
$temp_data = $entity;
|
||||
$config = json_decode($temp_data->propiedades);
|
||||
if (in_array("palets",$config->config)){
|
||||
$temp_data->palets=1;
|
||||
}
|
||||
if (in_array("cajas",$config->config)){
|
||||
$temp_data->cajas=1;
|
||||
}
|
||||
return $temp_data;
|
||||
}
|
||||
|
||||
private function getPropiedadesFromPost($postData){
|
||||
|
||||
if (array_key_exists("cajas",$postData) || array_key_exists("palets",$postData)){
|
||||
|
||||
$temp_data = $postData;
|
||||
$prop = new stdClass();
|
||||
$prop->config = [];
|
||||
if (array_key_exists("cajas",$temp_data)){
|
||||
array_push($prop->config, "cajas");
|
||||
unset($temp_data["cajas"]);
|
||||
}
|
||||
if (array_key_exists("palets",$temp_data)){
|
||||
array_push($prop->config, "palets");
|
||||
unset($temp_data["palets"]);
|
||||
}
|
||||
$temp_data["propiedades"] = json_encode($prop);
|
||||
return $temp_data;
|
||||
}
|
||||
else{
|
||||
$temp_data = $postData;
|
||||
$temp_data["propiedades"] = null;
|
||||
return $temp_data;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user