Files
safekat/ci4/app/Controllers/Presupuestos/PresupuestoManipulados.php
2023-10-31 22:32:21 +01:00

124 lines
4.4 KiB
PHP

<?php namespace App\Controllers\Presupuestos;
use App\Controllers\GoBaseResourceController;
use App\Models\Collection;
use App\Entities\Clientes\ClienteContactoEntity;
use App\Models\Clientes\ClienteModel;
use App\Models\Presupuestos\PresupuestoManipuladosModel;
use DataTables\Editor;
use DataTables\Editor\Field;
use DataTables\Editor\Validate;
class PresupuestoManipulados extends \App\Controllers\GoBaseResourceController
{
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/backend/vuexy/form/presupuestos/';
protected $indexRoute = 'contactoDeClienteList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
}
public function datatable()
{
if ($this->request->isAJAX()) {
$reqData = $this->request->getPost();
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 = $reqData['length'] ?? 5;
$requestedOrder = $reqData['order']['0']['column'] ?? 1;
$order = PresupuestoManipuladosModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 1];
$dir = $reqData['order']['0']['dir'] ?? 'asc';
$id_P = $reqData['id_presupuesto'] ?? -1;
$resourceData = $this->model->getResource($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 {
return $this->failUnauthorized('Invalid request', 403);
}
}
public function datatable_editor() {
if ($this->request->isAJAX()) {
include(APPPATH . "ThirdParty/DatatablesEditor/DataTables.php");
// Build our Editor instance and process the data coming from _POST
$response = Editor::inst( $db, 'presupuesto_manipulados' )
->fields(
Field::inst( 'tarifa_manipulado_id' )
->validator( 'Validate::notEmpty',array(
'message' => 'Selecciones servicios de acabado' )
),
Field::inst( 'precio_unidad' )
->validator( 'Validate::notEmpty',array(
'message' => 'Falta precio unitario' )
),
Field::inst( 'precio_total' )
->validator( 'Validate::notEmpty',array(
'message' => 'Falta precio total' )
),
Field::inst( 'presupuesto_id' ),
)
->validator( function($editor, $action, $data){
if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT){
//return $response;
/*foreach ($data['data'] as $pkey => $values ){
// No se pueden duplicar valores al crear o al editar
if (!empty($response)){
return $response;
}
}*/
}
})
->debug(true)
->process( $_POST )
->data();
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
$response[$csrfTokenName] = $newTokenHash;
echo json_encode($response);
} else {
return $this->failUnauthorized('Invalid request', 403);
}
}
}