mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
287 lines
12 KiB
PHP
287 lines
12 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Presupuestos;
|
|
|
|
|
|
use App\Controllers\BaseResourceController;
|
|
|
|
use App\Models\Collection;
|
|
|
|
use App\Services\PresupuestoService;
|
|
|
|
class Presupuestotiradasalternativas extends \App\Controllers\BaseResourceController
|
|
{
|
|
|
|
protected $modelName = PresupuestoManipuladosModel::class;
|
|
protected $format = 'json';
|
|
|
|
protected static $singularObjectName = 'Presupuestos tirada alternativa';
|
|
protected static $singularObjectNameCc = 'PresupuestoTiradaAlternativa';
|
|
protected static $pluralObjectName = 'Presupuesto tiradas alternativas';
|
|
protected static $pluralObjectNameCc = 'PresupuestoTiradasAlternativas';
|
|
|
|
protected static $controllerSlug = 'presupuesto-tiradas';
|
|
|
|
protected static $viewPath = 'themes/backend/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)
|
|
{
|
|
}
|
|
|
|
public function update($requestedId = null)
|
|
{
|
|
}
|
|
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
// Esta funcion se usa para obtener los datos de la tabla de la vista de presupuestos
|
|
public function datatable_2()
|
|
{
|
|
|
|
$reqData = $this->request->getPost();
|
|
|
|
$newTokenHash = csrf_hash();
|
|
$csrfTokenName = csrf_token();
|
|
|
|
$json_data = $reqData['json_tiradas'] ?? null;
|
|
$cliente_id = $reqData['cliente_id'] ?? 0;
|
|
|
|
$tipo_impresion_id = $reqData['tipo_impresion_id'] ?? 4;
|
|
|
|
$values = [];
|
|
|
|
if ($json_data) {
|
|
|
|
$data = json_decode($json_data, true);
|
|
|
|
foreach ($data as $linea) {
|
|
// Se obtienen los valores de cada linea para el calculo del precio
|
|
$datosPedido = (object)array(
|
|
'paginas' => intval($linea['paginas']) ?? 0,
|
|
'tirada' => intval($reqData['tirada']) ?? 0,
|
|
'merma' => intval($reqData['merma']) ?? 0,
|
|
'ancho' => intval($reqData['ancho']) ?? 100000,
|
|
'alto' => intval($reqData['alto']) ?? 100000,
|
|
'a_favor_fibra' => $linea['aFavorFibra'] ?? 1,
|
|
'isCosido' => (new \App\Models\Configuracion\TipoPresupuestoModel())->get_isCosido($tipo_impresion_id), // JJO esto es custom por cada tipo de presupuesto
|
|
);
|
|
|
|
if ($linea['row_id'] == 'lp_guardas') {
|
|
$datosPedido->paginas_impresion = intval($linea['paginas_impresion']) ?? 0;
|
|
// Para el caso de Fresado y Cosido tapa dura, las guardas son un diptico
|
|
// y hay que imprimirlas como "cosido" (dos hojas pegadas). En el caso de espiral
|
|
// o wire-o tapa dura, las guardas se imprimen como hojas sueltas
|
|
if ($tipo_impresion_id == 1 || $tipo_impresion_id == 3) {
|
|
$datosPedido->isCosido = true;
|
|
} else if ($tipo_impresion_id == 5 || $tipo_impresion_id == 7) {
|
|
$datosPedido->isCosido = false;
|
|
}
|
|
} else if ($linea['row_id'] == 'lp_sobrecubierta' || $linea['row_id'] == 'lp_cubierta') {
|
|
$datosPedido->solapas =
|
|
$linea['row_id'] == 'lp_cubierta' ? $reqData['solapas_cubierta'] : $reqData['solapas_sobrecubierta'];
|
|
$datosPedido->solapas_ancho =
|
|
$linea['row_id'] == 'lp_cubierta' ? $reqData['solapas_cubierta_ancho'] : $reqData['solapas_sobrecubierta_ancho'];
|
|
$datosPedido->lomo = $reqData['lomo'];
|
|
|
|
$type = $linea['row_id'] == 'lp_cubierta' ? 'cubierta' : 'sobrecubierta';
|
|
|
|
$datosPedido->anchoExteriores = PresupuestoService::getAnchoTotalExteriores($type, $tipo_impresion_id, $datosPedido);
|
|
$datosPedido->altoExteriores = PresupuestoService::getAltoTotalExteriores($type, $tipo_impresion_id, $datosPedido);
|
|
}
|
|
|
|
|
|
$maquina = (new \App\Models\Configuracion\MaquinaModel())->find($linea['maquina_id']);
|
|
$papel = (new \App\Models\Configuracion\PapelImpresionModel())->find($linea['papel_impresion_id']);
|
|
$pg = (new \App\Models\Configuracion\PapelGenericoModel())->find($linea['papel']);
|
|
|
|
$papel_generico['id'] = $pg->id;
|
|
$papel_generico['nombre'] = $pg->nombre;
|
|
|
|
$maquina->maquina_id = $maquina->id;
|
|
|
|
switch ($linea['row_id']) {
|
|
case 'lp_rot_bn':
|
|
case 'lp_rot_color':
|
|
$uso = 'interior';
|
|
$tipo = strpos($linea['row_id'], "_bn") !== false ? 'negro' : 'color';
|
|
$paginas_negro = isset($linea['numPagColor']) ? intval($datosPedido->paginas) - intval($linea['numPagColor']) : 0;
|
|
$paginas_color = $linea['numPagColor'] ?? 0;
|
|
$paginas = (object)array(
|
|
'negro' => $paginas_negro,
|
|
'color' => $paginas_color,
|
|
);
|
|
$parametrosRotativa = (object)array(
|
|
'a_favor_fibra' => $datosPedido->a_favor_fibra,
|
|
'bnPages' => $paginas->negro,
|
|
'colorPages' => $paginas->color,
|
|
'rotativa_gota_negro' => 0,
|
|
'rotativa_gota_color' => 0,
|
|
);
|
|
$parametrosRotativa->rotativa_gota_negro = floatval($linea['gotaNegro']?? 0);
|
|
$parametrosRotativa->rotativa_gota_color = floatval($linea['gotaColor']?? 0);
|
|
$parametrosRotativa->rotativa_negro = floatval($linea['cobNegro'] ?? 0);
|
|
$parametrosRotativa->rotativa_cyan = floatval($linea['cobCyan'] ?? 0);
|
|
$parametrosRotativa->rotativa_magenta = floatval($linea['cobMagenta']?? 0);
|
|
$parametrosRotativa->rotativa_amarillo = floatval($linea['cobAmarillo']?? 0);
|
|
break;
|
|
case 'lp_cubierta':
|
|
$uso = 'cubierta';
|
|
break;
|
|
case 'lp_sobrecubierta':
|
|
$uso = 'sobrecubierta';
|
|
break;
|
|
case 'lp_guardas':
|
|
$uso = 'guardas';
|
|
break;
|
|
default:
|
|
$uso = 'interior';
|
|
$isHq = strpos($linea['row_id'], "hq") !== false ? true : false;
|
|
$isColor = strpos($linea['row_id'], "_color") !== false ? true : false;
|
|
$tipo = $isColor ? ($isHq ? 'colorhq' : 'color') : ($isHq ? 'negrohq' : 'negro');
|
|
break;
|
|
}
|
|
|
|
if ($uso == 'cubierta' || $uso == 'sobrecubierta' || $uso == 'guardas') {
|
|
$isColor = true;
|
|
$isHq = true;
|
|
$tipo = 'colorhq';
|
|
}
|
|
|
|
if (strpos($linea['row_id'], 'lp_rot') !== 0) {
|
|
// The string does not start with the prefix
|
|
$opciones_papel = PresupuestoService::get_opciones_papel($uso, $isColor);
|
|
}
|
|
|
|
$datosTipolog = $linea['gotaNegro'] ?? null;
|
|
if (!is_null($datosTipolog)) {
|
|
$datosTipolog = [];
|
|
$data_temp = (object)array(
|
|
'negro' => floatval($linea['cobNegro'] ?? 0),
|
|
'cyan' => floatval($linea['cobCyan'] ?? 0),
|
|
'magenta' => floatval($linea['cobMagenta']?? 0),
|
|
'amarillo' => floatval($linea['cobAmarillo']?? 0),
|
|
'cg' => floatval($linea['cobCG'] ?? 0),
|
|
'gota_negro' => floatval($linea['gotaNegro']?? 0),
|
|
'gota_color' => floatval($linea['gotaColor']?? 0),
|
|
);
|
|
array_push($datosTipolog, $data_temp);
|
|
}
|
|
|
|
$datosLinea = array();
|
|
|
|
$datosLinea['uso'] = $uso;
|
|
$datosLinea['tipo'] = $tipo;
|
|
$datosLinea['datosPedido'] = $datosPedido;
|
|
$datosLinea['cliente_id'] = $cliente_id;
|
|
$datosLinea['papel'] = $papel;
|
|
if(isset($isColor))
|
|
$datosLinea['isColor'] = $isColor;
|
|
if(isset($opciones_papel))
|
|
$datosLinea['opciones_papel'] = $opciones_papel;
|
|
if(isset($parametrosRotativa))
|
|
$datosLinea['parametrosRotativa'] = $parametrosRotativa;
|
|
if(isset($paginas))
|
|
$datosLinea['paginas'] = $paginas;
|
|
$datosLinea['maquina'] = $maquina;
|
|
$datosLinea['papel_generico'] = $papel_generico;
|
|
$datosLinea['a_favor_fibra'] = $linea['aFavorFibra'] ?? null;
|
|
$datosLinea['datosTipolog'] = $datosTipolog;
|
|
$datosLinea['gramaje'] = $linea['gramaje'] ?? 0;
|
|
|
|
if ($linea['row_id'] != 'lp_rot_bn' && $linea['row_id'] != 'lp_rot_color') {
|
|
$linea_coste = PresupuestoService::getLineaPresupuestoPlana($datosLinea);
|
|
} else {
|
|
$linea_coste = PresupuestoService::getLineaPresupuestoRotativa($datosLinea);
|
|
}
|
|
|
|
if (empty($linea))
|
|
continue;
|
|
|
|
if ($linea['check_papel_total'] == 0) {
|
|
$linea_coste['fields']['precio_pedido'] = 0;
|
|
}
|
|
if ($linea['check_impresion_total'] == 0) {
|
|
$linea_coste['fields']['precio_impresion_horas'] = 0;
|
|
$linea_coste['fields']['precio_click_pedido'] = 0;
|
|
if ($linea_coste['fields']['tipo_maquina'] == 'inkjet') {
|
|
$linea_coste['fields']['precio_tinta'] = 0;
|
|
if (strpos($linea['row_id'], 'lp_rot') === 0) {
|
|
$linea_coste['fields']['total_corte'] = 0;
|
|
}
|
|
}
|
|
}
|
|
$linea_coste['total_coste'] = $linea_coste['fields']['precio_pedido'] +
|
|
$linea_coste['fields']['precio_impresion_horas'] +
|
|
$linea_coste['fields']['precio_click_pedido'];
|
|
if ($linea_coste['fields']['tipo_maquina'] == 'inkjet') {
|
|
|
|
$linea_coste['total_coste'] +=
|
|
$linea_coste['fields']['precio_tinta'];
|
|
if (strpos($linea['row_id'], 'lp_rot') === 0) {
|
|
$linea_coste['total_coste'] +=
|
|
$linea_coste['fields']['total_corte'];
|
|
}
|
|
}
|
|
|
|
|
|
$linea_coste['total_margen'] = $linea_coste['fields']['margen_papel_pedido'] +
|
|
$linea_coste['fields']['margen_impresion_horas'] +
|
|
$linea_coste['fields']['margen_click_pedido'];
|
|
|
|
unset($linea_coste['fields']);
|
|
array_push($values, $linea_coste);
|
|
}
|
|
} else {
|
|
$values = [];
|
|
}
|
|
|
|
$newTokenHash = csrf_hash();
|
|
$csrfTokenName = csrf_token();
|
|
|
|
$response[$csrfTokenName] = $newTokenHash;
|
|
$response['lineas'] = $values;
|
|
|
|
return $this->respond($response);
|
|
|
|
}
|
|
}
|