mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
192 lines
8.6 KiB
PHP
192 lines
8.6 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Facturacion;
|
|
|
|
use App\Models\Facturas\FacturaLineaModel;
|
|
use App\Models\Collection;
|
|
use DataTables\Editor;
|
|
use DataTables\Editor\Field;
|
|
use DataTables\Editor\Validate;
|
|
|
|
class FacturasLineas extends \App\Controllers\BaseResourceController
|
|
{
|
|
protected $modelName = FacturaLineaModel::class;
|
|
protected $format = 'json';
|
|
|
|
protected static $controllerSlug = 'factura-lineas';
|
|
|
|
|
|
public function datatable($factura_id = null){
|
|
|
|
if ($this->request->isAJAX() && $factura_id != null) {
|
|
|
|
$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;
|
|
$search = $reqData['search']['value'];
|
|
$requestedOrder = $reqData['order']['0']['column'] ?? 0;
|
|
//$order = FacturaModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0];
|
|
$dir = $reqData['order']['0']['dir'] ?? 'asc';
|
|
|
|
$resourceData = $this->model->getResource($factura_id)->orderBy(1, $dir)->limit($length, $start)->get()->getResultObject();
|
|
|
|
return $this->respond(Collection::datatable(
|
|
$resourceData,
|
|
$this->model->getResource($factura_id)->countAllResults(),
|
|
$this->model->getResource($factura_id)->countAllResults()
|
|
));
|
|
} else {
|
|
return $this->failUnauthorized('Invalid request', 403);
|
|
}
|
|
}
|
|
|
|
|
|
public function deleteLinea($factura_linea_id = 0){
|
|
|
|
if (!empty(static::$pluralObjectNameCc) && !empty(static::$singularObjectNameCc)) {
|
|
$objName = mb_strtolower(lang(ucfirst(static::$pluralObjectNameCc).'.'.static::$singularObjectNameCc));
|
|
} else {
|
|
$objName = lang('Basic.global.record');
|
|
}
|
|
|
|
if($factura_linea_id == 0){
|
|
return $this->failNotFound(lang('Basic.global.deleteError', [$objName]));
|
|
}
|
|
|
|
$facturaLinea = $this->model->find($factura_linea_id);
|
|
if($facturaLinea == null){
|
|
return $this->failNotFound(lang('Basic.global.deleteError', [$objName]));
|
|
}
|
|
|
|
if($facturaLinea->pedido_linea_impresion_id != null){
|
|
$this->model->deleteFacturasLineasPedido($facturaLinea->factura_id, $facturaLinea->pedido_linea_impresion_id, $facturaLinea->cantidad);
|
|
}
|
|
|
|
if($facturaLinea->pedido_maquetacion_id != null){
|
|
//$this->model->deleteFacturasLineasPedido($facturaLinea->factura_id, $facturaLinea->pedido_maquetacion_id, $facturaLinea->cantidad);
|
|
}
|
|
|
|
$facturaLinea = $this->model->delete($factura_linea_id);
|
|
$message = lang('Basic.global.deleteSuccess', [lang('Basic.global.record')]);
|
|
$response = $this->respondDeleted(['id' => $factura_linea_id, 'msg' => $message]);
|
|
return $response;
|
|
}
|
|
|
|
|
|
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, 'cliente_plantilla_precios_lineas' )
|
|
->fields(
|
|
Field::inst( 'plantilla_id' ),
|
|
Field::inst( 'tipo' ),
|
|
Field::inst( 'tipo_maquina' ),
|
|
Field::inst( 'tipo_impresion' ),
|
|
Field::inst( 'user_updated_id' ),
|
|
Field::inst( 'updated_at' ),
|
|
Field::inst( 'tiempo_min' )
|
|
->getFormatter( 'Format::toDecimalChar')->setFormatter( 'Format::fromDecimalChar')
|
|
->validator( 'Validate::notEmpty',array(
|
|
'message' => lang('ClientePrecios.validation.required'))
|
|
)
|
|
->validator('Validate::numeric', array(
|
|
"decimal" => ',',
|
|
'message' => lang('ClientePrecios.validation.decimal'))
|
|
),
|
|
|
|
Field::inst( 'tiempo_max' )
|
|
->getFormatter( 'Format::toDecimalChar')->setFormatter( 'Format::fromDecimalChar')
|
|
->validator( 'Validate::notEmpty',array(
|
|
'message' => lang('ClientePrecios.validation.required'))
|
|
)
|
|
->validator('Validate::numeric', array(
|
|
"decimal" => ',',
|
|
'message' => lang('ClientePrecios.validation.decimal'))
|
|
),
|
|
|
|
Field::inst( 'precio_hora' )
|
|
->getFormatter( 'Format::toDecimalChar')->setFormatter( 'Format::fromDecimalChar')
|
|
->validator( 'Validate::notEmpty',array(
|
|
'message' => lang('ClientePrecios.validation.required'))
|
|
)
|
|
->validator('Validate::numeric', array(
|
|
"decimal" => ',',
|
|
'message' => lang('ClientePrecios.validation.decimal'))
|
|
),
|
|
|
|
Field::inst( 'margen' )
|
|
->getFormatter( 'Format::toDecimalChar')->setFormatter( 'Format::fromDecimalChar')
|
|
->validator( 'Validate::notEmpty',array(
|
|
'message' => lang('ClientePrecios.validation.required'))
|
|
)
|
|
->validator('Validate::numeric', array(
|
|
"decimal" => ',',
|
|
'message' => lang('ClientePrecios.validation.decimal'))
|
|
),
|
|
|
|
)
|
|
->validator(function ($editor, $action, $data) {
|
|
if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT) {
|
|
foreach ($data['data'] as $pkey => $values) {
|
|
// Si no se quiere borrar...
|
|
if ($data['data'][$pkey]['is_deleted'] != 1) {
|
|
$process_data['tiempo_min'] = $data['data'][$pkey]['tiempo_min'];
|
|
$process_data['tiempo_max'] = $data['data'][$pkey]['tiempo_max'];
|
|
$process_data['tipo'] = $data['data'][$pkey]['tipo'];
|
|
$process_data['tipo_maquina'] = $data['data'][$pkey]['tipo_maquina'];
|
|
$process_data['tipo_impresion'] = $data['data'][$pkey]['tipo_impresion'];
|
|
|
|
$response = $this->model->checkIntervals($process_data, $pkey, $data['data'][$pkey]['plantilla_id']);
|
|
// No se pueden duplicar valores al crear o al editar
|
|
if (!empty($response)) {
|
|
return $response;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
->on('preCreate', function ($editor, &$values) {
|
|
$session = session();
|
|
$datetime = (new \CodeIgniter\I18n\Time("now"));
|
|
$editor
|
|
->field('user_updated_id')
|
|
->setValue($session->id_user);
|
|
$editor
|
|
->field('updated_at')
|
|
->setValue($datetime->format('Y-m-d H:i:s'));
|
|
})
|
|
->on('preEdit', function ($editor, &$values) {
|
|
$session = session();
|
|
$datetime = (new \CodeIgniter\I18n\Time("now"));
|
|
$editor
|
|
->field('user_updated_id')
|
|
->setValue($session->id_user);
|
|
$editor
|
|
->field('updated_at')
|
|
->setValue($datetime->format('Y-m-d H:i:s'));
|
|
})
|
|
->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);
|
|
}
|
|
}
|
|
} |