mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
133 lines
3.7 KiB
PHP
Executable File
133 lines
3.7 KiB
PHP
Executable File
<?php namespace App\Controllers\Presupuestos;
|
|
|
|
|
|
use App\Controllers\BaseResourceController;
|
|
|
|
use App\Models\Collection;
|
|
|
|
use App\Entities\Clientes\ClienteContactoEntity;
|
|
|
|
use App\Models\Clientes\ClienteModel;
|
|
|
|
use App\Models\Presupuestos\PresupuestoManipuladosModel;
|
|
|
|
class Presupuestomanipulados extends \App\Controllers\BaseResourceController
|
|
{
|
|
|
|
protected $modelName = PresupuestoManipuladosModel::class;
|
|
protected $format = 'json';
|
|
|
|
protected static $singularObjectName = 'Presupuesto manipulado';
|
|
protected static $singularObjectNameCc = 'presupuestoManipulado';
|
|
protected static $pluralObjectName = 'Presupuestos manipulado';
|
|
protected static $pluralObjectNameCc = 'presupuestosManipulado';
|
|
|
|
protected static $controllerSlug = 'presupuesto-manipulado';
|
|
|
|
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 edit($requestedId = null)
|
|
{
|
|
|
|
if ($requestedId == null) :
|
|
return;
|
|
endif;
|
|
|
|
$postData = $this->request->getJSON();
|
|
$tarifas = array_column($postData->datos, 'tarifa_id');
|
|
|
|
if(count($tarifas)>0){
|
|
$this->model->deleteServiciosNotInArray($requestedId, $tarifas);
|
|
}
|
|
else{
|
|
$this->model->deleteAllServicios($requestedId);
|
|
}
|
|
|
|
if(count($tarifas)>0){
|
|
$this->model->updateTarifas($requestedId, $postData->datos);
|
|
}
|
|
|
|
$newTokenHash = csrf_hash();
|
|
$csrfTokenName = csrf_token();
|
|
$data = [
|
|
$csrfTokenName => $newTokenHash
|
|
];
|
|
|
|
return $this->respond($data);
|
|
}
|
|
|
|
public function update($requestedId = null)
|
|
{
|
|
|
|
if ($requestedId == null) :
|
|
return;
|
|
endif;
|
|
|
|
$postData = $this->request->getJSON();
|
|
$tarifas = array_column($postData->datos, 'tarifa_id');
|
|
$tirada = $postData->tirada ?? 0;
|
|
$POD = $postData->POD ?? 0;
|
|
$result = [];
|
|
|
|
if(count($tarifas)>0){
|
|
foreach ($tarifas as $tarifa){
|
|
$values = $this->model->getPrecioTarifa($tarifa, $tirada, $POD);
|
|
array_push($result, $values);
|
|
}
|
|
}
|
|
|
|
$newTokenHash = csrf_hash();
|
|
$csrfTokenName = csrf_token();
|
|
$data = [
|
|
'lines' => $result,
|
|
$csrfTokenName => $newTokenHash
|
|
];
|
|
|
|
return $this->respond($data);
|
|
}
|
|
|
|
|
|
public function datatable()
|
|
{
|
|
if ($this->request->isAJAX()) {
|
|
$reqData = $this->request->getPost();
|
|
|
|
$tarifa_manipulado_id = $reqData['tarifa_manipulado_id'] ?? 0;
|
|
$tirada = $reqData['tirada'] ?? 0;
|
|
$POD = $reqData['POD'] ?? 0;
|
|
$tipo = $reqData['tipo'] ?? null;
|
|
|
|
|
|
$newTokenHash = csrf_hash();
|
|
$csrfTokenName = csrf_token();
|
|
|
|
if(is_null($tipo)){
|
|
$values = $this->model->getPrecioTarifa($tarifa_manipulado_id, $tirada, $POD);
|
|
}
|
|
else{
|
|
$solapas = $reqData['solapas'] ?? -1;
|
|
$tipo_impresion_id = $reqData['tipo_impresion_id'] ?? 4;
|
|
$values = $this->model->initPresupuesto($tipo_impresion_id, $solapas, $tirada, $POD);
|
|
}
|
|
|
|
$data = [
|
|
'values' => $values,
|
|
$csrfTokenName => $newTokenHash
|
|
];
|
|
|
|
return $this->respond($data);
|
|
|
|
} else {
|
|
return $this->failUnauthorized('Invalid request', 403);
|
|
}
|
|
}
|
|
|
|
}
|