mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
77 lines
3.0 KiB
PHP
77 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Facturacion;
|
|
|
|
use App\Models\Facturas\FacturaLineaModel;
|
|
use App\Models\Collection;
|
|
|
|
|
|
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;
|
|
}
|
|
} |