mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
177 lines
6.5 KiB
PHP
Executable File
177 lines
6.5 KiB
PHP
Executable File
<?php namespace App\Controllers\Presupuestos;
|
|
|
|
|
|
use App\Controllers\BaseResourceController;
|
|
|
|
use App\Models\Collection;
|
|
|
|
|
|
use App\Models\Presupuestos\PresupuestoDireccionesModel;
|
|
|
|
|
|
|
|
class Presupuestodirecciones extends \App\Controllers\BaseResourceController
|
|
{
|
|
|
|
protected $modelName = PresupuestoDireccionesModel::class;
|
|
protected $format = 'json';
|
|
|
|
protected static $singularObjectName = 'Presupuesto direcciones';
|
|
protected static $singularObjectNameCc = 'presupuestoDirecciones';
|
|
protected static $pluralObjectName = 'Presupuestos direcciones';
|
|
protected static $pluralObjectNameCc = 'presupuestosDirecciones';
|
|
|
|
protected static $controllerSlug = 'presupuesto-direcciones';
|
|
|
|
protected static $viewPath = 'themes/vuexy/form/presupuestos/';
|
|
|
|
|
|
|
|
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
|
|
{
|
|
parent::initController($request, $response, $logger);
|
|
}
|
|
|
|
|
|
public function add(){
|
|
if ($this->request->isAJAX()) {
|
|
|
|
$reqData = $this->request->getPost();
|
|
$presupuesto_id = $reqData['presupuesto_id'] ?? -1;
|
|
$tarifa_id = $reqData['tarifa_id'] ?? -1;
|
|
$cantidad = $reqData['cantidad'] ?? -1;
|
|
$peso = $reqData['peso'] ?? -1;
|
|
$att = $reqData['att'] ?? "";
|
|
$email = $reqData['email'] ?? "";
|
|
$direccion = $reqData['direccion'] ?? "";
|
|
$pais_id = $reqData['pais_id'] ?? -1;
|
|
$provincia = $reqData['provincia'] ?? "";
|
|
$municipio = $reqData['municipio'] ?? "";
|
|
$cp = $reqData['cp'] ?? "";
|
|
$telefono = $reqData['telefono'] ?? "";
|
|
$precio = $reqData['precio'] ?? "";
|
|
$margen = $reqData['margen'] ?? "";
|
|
$proveedor = $reqData['proveedor'] ?? "";
|
|
$proveedor_id = $reqData['proveedor_id'] ?? "";
|
|
$entregaPieCalle = $reqData['entregaPieCalle'] ?? 0;
|
|
$is_ferro_prototipo = $reqData['is_ferro_prototipo'] ?? 0;
|
|
$num_ferro_prototipo = $reqData['num_ferro_prototipo'] ?? 0;
|
|
|
|
$data = [
|
|
"presupuesto_id" => $presupuesto_id,
|
|
"tarifa_id" => $tarifa_id,
|
|
"cantidad" => $cantidad,
|
|
"peso" => $peso,
|
|
"att" => $att,
|
|
"email" => $email,
|
|
"direccion" => $direccion,
|
|
"pais_id" => $pais_id,
|
|
"provincia" => $provincia,
|
|
"municipio" => $municipio,
|
|
"cp" => $cp,
|
|
"telefono" => $telefono,
|
|
"precio" => $precio,
|
|
"margen" => $margen,
|
|
"proveedor" => $proveedor,
|
|
"proveedor_id" => $proveedor_id,
|
|
"entregaPieCalle" => $entregaPieCalle,
|
|
"is_ferro_prototipo" => $is_ferro_prototipo,
|
|
"num_ferro_prototipo" => $num_ferro_prototipo
|
|
];
|
|
$response = $this->model->insert($data);
|
|
|
|
$newTokenHash = csrf_hash();
|
|
$csrfTokenName = csrf_token();
|
|
$data_ret = [
|
|
'data' => $response,
|
|
$csrfTokenName => $newTokenHash
|
|
];
|
|
return $this->respond($data_ret);
|
|
|
|
} else {
|
|
return $this->failUnauthorized('Invalid request', 403);
|
|
}
|
|
}
|
|
|
|
public function datatable()
|
|
{
|
|
if ($this->request->isAJAX()) {
|
|
$reqData = $this->request->getPost();
|
|
|
|
if( is_null($reqData['tipo']?? null)){
|
|
if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
|
|
$errstr = 'No data available in response to this specific request.';
|
|
$response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
|
|
return $response;
|
|
}
|
|
$start = $reqData['start'] ?? 0;
|
|
$length = 30;
|
|
$search = $reqData['search']['value'];
|
|
$requestedOrder = $reqData['order']['0']['column'] ?? 1;
|
|
$order = PresupuestoDireccionesModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 1];
|
|
$dir = $reqData['order']['0']['dir'] ?? 'asc';
|
|
|
|
$id_P = $reqData['presupuesto_id'] ?? -1;
|
|
|
|
|
|
$resourceData = $this->model->getResource($search, $id_P)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
|
|
|
|
|
|
return $this->respond(Collection::datatable(
|
|
$resourceData,
|
|
$this->model->getResource()->countAllResults(),
|
|
$this->model->getResource("", $id_P)->countAllResults()
|
|
));
|
|
}
|
|
else if($reqData['tipo']=='get_tarifa'){
|
|
$peso = $reqData['peso'] ?? 0;
|
|
$paisId = $reqData['paisId'] ?? 0;
|
|
$cp = $reqData['cp'] ?? 0;
|
|
$tipo_envio = $reqData['tipo_envio'] ?? null;
|
|
|
|
$model = model('App\Models\Tarifas\TarifaEnvioModel');
|
|
return $this->respond($model->getTarifaEnvio($paisId, $cp, $peso, $tipo_envio));
|
|
}
|
|
else if($reqData['tipo']=='clear_lineas'){
|
|
|
|
$presupuesto_id = $reqData['presupuesto_id'] ?? 0;
|
|
return $this->respond($this->model->where('presupuesto_id', $presupuesto_id)->delete());
|
|
}
|
|
|
|
|
|
} else {
|
|
return $this->failUnauthorized('Invalid request', 403);
|
|
}
|
|
}
|
|
|
|
public function datatable_2(){
|
|
|
|
$reqData = $this->request->getJSON();
|
|
|
|
if($reqData->tipo=='get_tarifa'){
|
|
|
|
$peso = $reqData->peso ?? 0;
|
|
$paisId = $reqData->paisId ?? 0;
|
|
$cp = $reqData->cp ?? 0;
|
|
$tipo_envio = $reqData->tipo_envio ?? 'cajas';
|
|
|
|
$model = model('App\Models\Tarifas\TarifaEnvioModel');
|
|
$newTokenHash = csrf_hash();
|
|
$csrfTokenName = csrf_token();
|
|
$values = $model->getTarifaEnvio($paisId, $cp, $peso, $tipo_envio);
|
|
$data = [
|
|
'data' => count($values)>0?$values[0]:[],
|
|
$csrfTokenName => $newTokenHash
|
|
];
|
|
|
|
return $this->respond($data);
|
|
}
|
|
else if($reqData->tipo=='clear_lineas'){
|
|
|
|
$presupuesto_id = $reqData->presupuesto_id ?? 0;
|
|
return $this->respond($this->model->where('presupuesto_id', $presupuesto_id)->delete());
|
|
}
|
|
}
|
|
|
|
}
|