mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Merge branch 'feat/boton_reimprimir' into 'main'
terminada funcionalidad reimpresion presupuestos See merge request jjimenez/safekat!830
This commit is contained in:
@ -31,6 +31,9 @@ $routes->group('presupuestoadmin', ['namespace' => 'App\Controllers\Presupuestos
|
||||
$routes->get('presupuestosCliente', 'Presupuestoadmin::tablaClienteForm');
|
||||
$routes->get('getSumCliente/(:num)', 'Presupuestoadmin::obtenerTotalPresupuestosCliente/$1');
|
||||
|
||||
$routes->get('hasFiles', 'Presupuestoadmin::hasFiles');
|
||||
$routes->post('reprint', 'Presupuestoadmin::reprintPresupuesto');
|
||||
|
||||
$routes->post('download_zip', 'Presupuestocliente::download_zip', ['as' => 'descargarAdminArchivos']);
|
||||
});
|
||||
|
||||
|
||||
@ -130,11 +130,10 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
$POD = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('POD')->value;
|
||||
$ancho = 0;
|
||||
$alto = 0;
|
||||
if(isset($sanitizedData['papel_formato_personalizado']) && $sanitizedData['papel_formato_personalizado'] == '1'){
|
||||
if (isset($sanitizedData['papel_formato_personalizado']) && $sanitizedData['papel_formato_personalizado'] == '1') {
|
||||
$ancho = $sanitizedData['papel_formato_ancho'];
|
||||
$alto = $sanitizedData['papel_formato_alto'];
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$papelFormatoModel = new PapelFormatoModel();
|
||||
$papelFormato = $papelFormatoModel->find($sanitizedData['papel_formato_id']);
|
||||
$ancho = $papelFormato->ancho;
|
||||
@ -152,7 +151,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
]);
|
||||
|
||||
$model = new PresupuestoEncuadernacionesModel();
|
||||
foreach($servDefectoEnc as $servicio){
|
||||
foreach ($servDefectoEnc as $servicio) {
|
||||
|
||||
$data = [
|
||||
'presupuesto_id' => $id,
|
||||
@ -238,12 +237,14 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
$postData['updated_at'] = gmdate('Y-m-d H:m:s', time());
|
||||
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
$sanitizedData['user_updated_id'] = auth()->user()->id;
|
||||
|
||||
if(isset($sanitizedData['total_aceptado_revisado']) && $sanitizedData['total_aceptado_revisado'] != 0
|
||||
&& $sanitizedData['total_aceptado_revisado'] != null && $sanitizedData['total_aceptado_revisado'] != ""){
|
||||
if (
|
||||
isset($sanitizedData['total_aceptado_revisado']) && $sanitizedData['total_aceptado_revisado'] != 0
|
||||
&& $sanitizedData['total_aceptado_revisado'] != null && $sanitizedData['total_aceptado_revisado'] != ""
|
||||
) {
|
||||
$sanitizedData['aprobado_at'] = $sanitizedData['updated_at'];
|
||||
$sanitizedData['aprobado_user_id'] = $sanitizedData['user_updated_id'];
|
||||
}
|
||||
@ -369,9 +370,9 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
}
|
||||
|
||||
// modificar los datos del pedido y de la factura si no está la factura validada
|
||||
if ($presupuestoEntity->estado_id == 2){
|
||||
if ($presupuestoEntity->estado_id == 2) {
|
||||
$facturaModel = model('App\Models\Facturas\FacturaModel');
|
||||
if(!$facturaModel->presupuestoHasFacturaValidada($id)){
|
||||
if (!$facturaModel->presupuestoHasFacturaValidada($id)) {
|
||||
// se actualiza primero el pedido
|
||||
$pedidoModel = model('App\Models\Pedidos\PedidoLineaModel');
|
||||
$pedidoLineaId = $pedidoModel->where('presupuesto_id', $id)->first()->id;
|
||||
@ -437,7 +438,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
$this->viewData['POD'] = $this->getPOD();
|
||||
|
||||
$this->viewData['no_envio_base'] = model('App\Models\Clientes\ClienteModel')->where('id', $presupuestoEntity->cliente_id)->first();
|
||||
if($this->viewData['no_envio_base'])
|
||||
if ($this->viewData['no_envio_base'])
|
||||
$this->viewData['no_envio_base'] = $this->viewData['no_envio_base']->no_envio_base;
|
||||
|
||||
$this->viewData['serviciosAutomaticos'] = [
|
||||
@ -465,11 +466,11 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
|
||||
$modelPedidoLinea = new \App\Models\Pedidos\PedidoLineaModel();
|
||||
$linea = $modelPedidoLinea->where('presupuesto_id', $id)->first();
|
||||
if($linea){
|
||||
if ($linea) {
|
||||
$this->viewData['pedido_id'] = $linea->pedido_id;
|
||||
$modelOrden = new \App\Models\OrdenTrabajo\OrdenTrabajoModel();
|
||||
$orden = $modelOrden->where('pedido_id', $linea->pedido_id)->first();
|
||||
if($orden){
|
||||
if ($orden) {
|
||||
$this->viewData['orden_id'] = $orden->id;
|
||||
}
|
||||
}
|
||||
@ -639,7 +640,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
$data['comparador']['json_data'] = json_decode($presupuesto->comparador_json_data, true);
|
||||
if ($data['comparador']['json_data'] != null) {
|
||||
foreach ($data['comparador']['json_data'] as &$item) {
|
||||
if(intval($item['papel_id'])>0)
|
||||
if (intval($item['papel_id']) > 0)
|
||||
$item['papel_nombre'] = $modelPapelGenerico->getNombre($item['papel_id'])['nombre'];
|
||||
}
|
||||
}
|
||||
@ -663,7 +664,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
$data['comentarios_pdf'] = $presupuesto->comentarios_pdf;
|
||||
$data['comentarios_presupuesto'] = $presupuesto->comentarios_presupuesto;
|
||||
$data['comentarios_produccion'] = $presupuesto->comentarios_produccion;
|
||||
|
||||
|
||||
|
||||
$data['tiradasAlternativas'] = json_decode($presupuesto->tirada_alternativa_json_data);
|
||||
|
||||
@ -694,9 +695,9 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
$data['resumen']['total_factor_ponderado'] = is_numeric($presupuesto->total_factor_ponderado) ? $presupuesto->total_factor_ponderado : 0;
|
||||
|
||||
$data['total_aceptado_revisado'] = $presupuesto->total_aceptado_revisado;
|
||||
$data['aprobado_by_at'] = ($presupuesto->aprobado_user_id != null)?
|
||||
model('App\Models\Usuarios\UserModel')->getFullName($presupuesto->aprobado_user_id) . ', '
|
||||
. date('d/m/Y H:i:s', strtotime($presupuesto->aprobado_at)):'';
|
||||
$data['aprobado_by_at'] = ($presupuesto->aprobado_user_id != null) ?
|
||||
model('App\Models\Usuarios\UserModel')->getFullName($presupuesto->aprobado_user_id) . ', '
|
||||
. date('d/m/Y H:i:s', strtotime($presupuesto->aprobado_at)) : '';
|
||||
|
||||
|
||||
$data['resumen']['iva_reducido'] = $presupuesto->iva_reducido;
|
||||
@ -817,7 +818,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
$paginas_color = $sobrecubierta['datosPedido']['paginas'] ?? 0;
|
||||
$tipo_impresion_id = $sobrecubierta['tipo_impresion_id'];
|
||||
$faja = intval($sobrecubierta['faja'] ?? 0);
|
||||
$uso = $faja==1? 'faja' : $sobrecubierta['uso'];
|
||||
$uso = $faja == 1 ? 'faja' : $sobrecubierta['uso'];
|
||||
|
||||
|
||||
$data = array(
|
||||
@ -1082,20 +1083,22 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
|
||||
$resourceData = PresupuestoService::obtenerComparadorPlana($input_data);
|
||||
|
||||
if($calcular_merma == 1 && count($resourceData) > 0 &&
|
||||
count($resourceData[0]['fields']) >0 && $resourceData[0]['fields']['num_formas'] > 0) {
|
||||
if (
|
||||
$calcular_merma == 1 && count($resourceData) > 0 &&
|
||||
count($resourceData[0]['fields']) > 0 && $resourceData[0]['fields']['num_formas'] > 0
|
||||
) {
|
||||
|
||||
usort($resourceData, function ($a, $b) {
|
||||
return $b['fields']['total_impresion'] <=> $a['fields']['total_impresion'];
|
||||
});
|
||||
|
||||
$num_formas = [];
|
||||
$formas_linea = $datosPedido->isCosido ? intval($resourceData[0]['fields']['num_formas']['value']) / 2 :
|
||||
intval($resourceData[0]['fields']['num_formas']['value']);
|
||||
$formas_linea = $datosPedido->isCosido ? intval($resourceData[0]['fields']['num_formas']['value']) / 2 :
|
||||
intval($resourceData[0]['fields']['num_formas']['value']);
|
||||
array_push($num_formas, $formas_linea);
|
||||
|
||||
$POD = $this->getPOD();
|
||||
$datosPedido->merma = PresupuestoService::calcular_merma($datosPedido->tirada,$POD, $num_formas);
|
||||
$datosPedido->merma = PresupuestoService::calcular_merma($datosPedido->tirada, $POD, $num_formas);
|
||||
|
||||
$resourceData = PresupuestoService::obtenerComparadorPlana($input_data);
|
||||
}
|
||||
@ -1132,20 +1135,22 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
|
||||
$resourceData = PresupuestoService::obtenerComparadorRotativa($input_data);
|
||||
|
||||
if($calcular_merma == 1 && count($resourceData) > 0 &&
|
||||
count($resourceData[0]['fields']) >0 && $resourceData[0]['fields']['num_formas'] > 0) {
|
||||
if (
|
||||
$calcular_merma == 1 && count($resourceData) > 0 &&
|
||||
count($resourceData[0]['fields']) > 0 && $resourceData[0]['fields']['num_formas'] > 0
|
||||
) {
|
||||
|
||||
usort($resourceData, function ($a, $b) {
|
||||
return $b['fields']['total_impresion'] <=> $a['fields']['total_impresion'];
|
||||
});
|
||||
|
||||
$num_formas = [];
|
||||
$formas_linea = $datosPedido->isCosido ? intval($resourceData[0]['fields']['num_formas']['value']) / 2 :
|
||||
intval($resourceData[0]['fields']['num_formas']['value']);
|
||||
$formas_linea = $datosPedido->isCosido ? intval($resourceData[0]['fields']['num_formas']['value']) / 2 :
|
||||
intval($resourceData[0]['fields']['num_formas']['value']);
|
||||
array_push($num_formas, $formas_linea);
|
||||
|
||||
$POD = $this->getPOD();
|
||||
$datosPedido->merma = PresupuestoService::calcular_merma($datosPedido->tirada,$POD, $num_formas);
|
||||
$datosPedido->merma = PresupuestoService::calcular_merma($datosPedido->tirada, $POD, $num_formas);
|
||||
|
||||
$resourceData = PresupuestoService::obtenerComparadorRotativa($input_data);
|
||||
}
|
||||
@ -1215,7 +1220,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
return $this->respond($data);
|
||||
} else if ($tipo == 'duplicar') {
|
||||
$presupuesto_id = $reqData['presupuesto_id'] ?? -1;
|
||||
$result = $this->duplicarPresupuesto($presupuesto_id);
|
||||
$result = PresupuestoService::duplicarPresupuesto($presupuesto_id);
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
if ($result['success']) {
|
||||
@ -1271,12 +1276,12 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
$cubierta = false;
|
||||
if ($uso == 'cubierta') {
|
||||
$cubierta = true;
|
||||
$anchoLibro = 2* $ancho + 2 * $solapas + $lomo;
|
||||
$anchoLibro = 2 * $ancho + 2 * $solapas + $lomo;
|
||||
}
|
||||
$sobrecubierta = false;
|
||||
if ($uso == 'sobrecubierta') {
|
||||
$sobrecubierta = true;
|
||||
$anchoLibro = 2* $ancho + 2 * $solapas + $lomo;
|
||||
$anchoLibro = 2 * $ancho + 2 * $solapas + $lomo;
|
||||
}
|
||||
$guardas = false;
|
||||
if ($uso == 'guardas') {
|
||||
@ -1300,7 +1305,8 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
$isPOD,
|
||||
$anchoLibro,
|
||||
$alto,
|
||||
$tirada);
|
||||
$tirada
|
||||
);
|
||||
if ($this->request->getGet("q")) {
|
||||
$query->groupStart()
|
||||
->orLike("t1.nombre", $this->request->getGet("q"))
|
||||
@ -1339,12 +1345,12 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
$cubierta = false;
|
||||
if ($uso == 'cubierta') {
|
||||
$cubierta = true;
|
||||
$anchoLibro = 2* $ancho + 2 * $solapas + $lomo;
|
||||
$anchoLibro = 2 * $ancho + 2 * $solapas + $lomo;
|
||||
}
|
||||
$sobrecubierta = false;
|
||||
if ($uso == 'sobrecubierta') {
|
||||
$sobrecubierta = true;
|
||||
$anchoLibro = 2* $ancho + 2 * $solapas + $lomo;
|
||||
$anchoLibro = 2 * $ancho + 2 * $solapas + $lomo;
|
||||
}
|
||||
$guardas = false;
|
||||
if ($uso == 'guardas') {
|
||||
@ -1356,7 +1362,8 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
}
|
||||
|
||||
$model = model('App\Models\Configuracion\PapelGenericoModel');
|
||||
$query = $model->getGramajeForComparador($tipo,
|
||||
$query = $model->getGramajeForComparador(
|
||||
$tipo,
|
||||
$papel_generico_id,
|
||||
$cubierta,
|
||||
$sobrecubierta,
|
||||
@ -1366,7 +1373,8 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
$isPOD,
|
||||
$anchoLibro,
|
||||
$alto,
|
||||
$tirada);
|
||||
$tirada
|
||||
);
|
||||
if ($this->request->getGet("q")) {
|
||||
$query->groupStart()
|
||||
->orLike("t2.gramaje", $this->request->getGet("q"))
|
||||
@ -1599,81 +1607,6 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Duplica un presupuesto dado por su ID.
|
||||
*
|
||||
* Esta función duplica un presupuesto y todas sus entidades relacionadas como acabados, encuadernaciones, manipulados,
|
||||
* preimpresiones, direcciones y lineas. El presupuesto duplicado se marca como tal y a su título se le añade
|
||||
* una cadena 'duplicado'. La función devuelve un array con un estado de éxito y el ID del nuevo presupuesto.
|
||||
*
|
||||
* @param int $id El ID del presupuesto a duplicar.
|
||||
* @return array Un array asociativo que contiene una clave 'success' que indica el estado de éxito de la operación,
|
||||
* y una clave 'id' que contiene el ID del nuevo presupuesto si la operación fue exitosa.
|
||||
* Si ocurre una excepción, la clave 'success' será false y una clave 'message' contendrá el mensaje de la excepción.
|
||||
* @throws \Exception Si ocurre un error durante la operación.
|
||||
*/
|
||||
private function duplicarPresupuesto($id)
|
||||
{
|
||||
|
||||
try {
|
||||
|
||||
$presupuesto = $this->model->find($id);
|
||||
$presupuesto->titulo = $presupuesto->titulo . ' - ' . lang('Presupuestos.duplicado');
|
||||
$presupuesto->is_duplicado = 1;
|
||||
$presupuesto->estado_id = 1;
|
||||
$new_id = $this->model->insert($presupuesto);
|
||||
|
||||
$presupuestoAcabadosModel = model('App\Models\Presupuestos\PresupuestoAcabadosModel');
|
||||
foreach ($presupuestoAcabadosModel->where('presupuesto_id', $presupuesto->id)->findAll() as $acabado) {
|
||||
$acabado->presupuesto_id = $new_id;
|
||||
$presupuestoAcabadosModel->insert($acabado);
|
||||
}
|
||||
|
||||
$presupuestoEncuadernacionesModel = model('App\Models\Presupuestos\PresupuestoEncuadernacionesModel');
|
||||
foreach ($presupuestoEncuadernacionesModel->where('presupuesto_id', $presupuesto->id)->findAll() as $encuadernacion) {
|
||||
$encuadernacion->presupuesto_id = $new_id;
|
||||
$presupuestoEncuadernacionesModel->insert($encuadernacion);
|
||||
}
|
||||
|
||||
$presupuestoManipuladosModel = model('App\Models\Presupuestos\PresupuestoManipuladosModel');
|
||||
foreach ($presupuestoManipuladosModel->where('presupuesto_id', $presupuesto->id)->findAll() as $manipulado) {
|
||||
$manipulado->presupuesto_id = $new_id;
|
||||
$presupuestoManipuladosModel->insert($manipulado);
|
||||
}
|
||||
|
||||
$presupuestoPreimpresionesModel = model('App\Models\Presupuestos\PresupuestoPreimpresionesModel');
|
||||
foreach ($presupuestoPreimpresionesModel->where('presupuesto_id', $presupuesto->id)->findAll() as $preimpresion) {
|
||||
$preimpresion->presupuesto_id = $new_id;
|
||||
$presupuestoPreimpresionesModel->insert($preimpresion);
|
||||
}
|
||||
|
||||
$presupuestoServiciosExtraModel = model('App\Models\Presupuestos\PresupuestoServiciosExtraModel');
|
||||
foreach ($presupuestoServiciosExtraModel->where('presupuesto_id', $presupuesto->id)->findAll() as $servicioExtra) {
|
||||
$servicioExtra->presupuesto_id = $new_id;
|
||||
$presupuestoServiciosExtraModel->insert($servicioExtra);
|
||||
}
|
||||
|
||||
$presupuestoDireccionesModel = model('App\Models\Presupuestos\PresupuestoDireccionesModel');
|
||||
foreach ($presupuestoDireccionesModel->where('presupuesto_id', $presupuesto->id)->findAll() as $direccion) {
|
||||
$direccion->presupuesto_id = $new_id;
|
||||
$presupuestoDireccionesModel->insert($direccion);
|
||||
}
|
||||
|
||||
$presupuestoLineaModel = model('App\Models\Presupuestos\PresupuestoLineaModel');
|
||||
$presupuestoLineaModel->duplicateLineasPresupuesto($presupuesto->id, $new_id);
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'id' => $new_id
|
||||
];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => $e->getMessage()
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function allItemsSelect()
|
||||
{
|
||||
@ -1812,10 +1745,11 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
$result = DataTable::of($q)
|
||||
->edit(
|
||||
'fecha',
|
||||
fn($q) => $q->fecha?Time::createFromFormat("Y-m-d H:i:s", $q->fecha)->format("d/m/Y"):""
|
||||
fn($q) => $q->fecha ? Time::createFromFormat("Y-m-d H:i:s", $q->fecha)->format("d/m/Y") : ""
|
||||
)
|
||||
->edit(
|
||||
'estado', fn($q) => match ($q->estado) {
|
||||
'estado',
|
||||
fn($q) => match ($q->estado) {
|
||||
"1" => lang('Presupuestos.borrador'),
|
||||
"2" => lang('Presupuestos.confirmado'),
|
||||
default => '--'
|
||||
@ -1826,13 +1760,14 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
<a href="javascript:void(0);"><i class="ti ti-eye ti-sm btn-edit mx-2" data-id="' . $q->id . '"></i></a>
|
||||
</div>
|
||||
';
|
||||
|
||||
|
||||
});
|
||||
|
||||
return $result->toJson(returnAsObject: true) ;
|
||||
|
||||
return $result->toJson(returnAsObject: true);
|
||||
}
|
||||
|
||||
public function obtenerTotalPresupuestosCliente($cliente_id){
|
||||
public function obtenerTotalPresupuestosCliente($cliente_id)
|
||||
{
|
||||
|
||||
$error = false;
|
||||
$result = [
|
||||
@ -1843,17 +1778,17 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
->where('presupuestos.cliente_id', $cliente_id)
|
||||
->select('SUM(presupuestos.total_aceptado) as total')
|
||||
->groupBy('presupuestos.cliente_id')->get()->getResultObject();
|
||||
if(count($data) > 0){
|
||||
if (count($data) > 0) {
|
||||
$result['total_impresion'] = round(floatval($data[0]->total), 2);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$error = true;
|
||||
}
|
||||
$result['total'] = $result['total_impresion'] + $result['total_maquetacion'];
|
||||
return $this->respond(['status' => $error?'error':'success', 'totales' => $result]);
|
||||
return $this->respond(['status' => $error ? 'error' : 'success', 'totales' => $result]);
|
||||
}
|
||||
|
||||
public function obtenerTotalPedidosCliente($cliente_id){
|
||||
public function obtenerTotalPedidosCliente($cliente_id)
|
||||
{
|
||||
|
||||
$error = false;
|
||||
$result = [
|
||||
@ -1866,14 +1801,58 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
->join('pedidos_linea', 'pedidos_linea.pedido_id = pedidos.id')
|
||||
->join('presupuestos', 'presupuestos.id = pedidos_linea.presupuesto_id')
|
||||
->groupBy('presupuestos.cliente_id')->get()->getResultObject();
|
||||
if(count($data) > 0){
|
||||
if (count($data) > 0) {
|
||||
$result['total_impresion'] = round(floatval($data[0]->total), 2);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$error = true;
|
||||
}
|
||||
$result['total'] = $result['total_impresion'] + $result['total_maquetacion'];
|
||||
return $this->respond(['status' => $error?'error':'success', 'totales' => $result]);
|
||||
return $this->respond(['status' => $error ? 'error' : 'success', 'totales' => $result]);
|
||||
}
|
||||
|
||||
|
||||
public function hasFiles()
|
||||
{
|
||||
|
||||
if ($this->request->isAJAX()) {
|
||||
$id = $this->request->getGet('id');
|
||||
$presupuesto = $this->model->find($id);
|
||||
if (!$presupuesto) {
|
||||
return $this->respond([
|
||||
'status' => 'error',
|
||||
'message' => lang('Presupuestos.presupuestoNotFound'),
|
||||
]);
|
||||
}
|
||||
|
||||
$files = $presupuesto->files() ?? [];
|
||||
if (count($files) == 0) {
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'hasFiles' => false,
|
||||
]);
|
||||
} else {
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'hasFiles' => true,
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function reprintPresupuesto()
|
||||
{
|
||||
|
||||
if ($this->request->isAJAX()) {
|
||||
$id = $this->request->getPost('id');
|
||||
$duplicateFiles = $this->request->getPost('duplicateFiles') ?? false;
|
||||
$response = PresupuestoService::duplicarPresupuesto($id, true, $duplicateFiles);
|
||||
return $this->respond($response);
|
||||
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1903,7 +1882,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
$modelPapel = new PapelGenericoModel();
|
||||
foreach ($lineas as $linea) {
|
||||
$linea->papel_generico = (new PapelGenericoModel())->find($linea->papel_id)->nombre;
|
||||
if($linea->tipo == 'lp_faja'){
|
||||
if ($linea->tipo == 'lp_faja') {
|
||||
$linea->alto_faja = $presupuestoEntity->alto_faja_color;
|
||||
}
|
||||
}
|
||||
@ -1972,4 +1951,6 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
|
||||
return $direcciones;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -363,6 +363,9 @@ return [
|
||||
'borrador' => 'Borrador',
|
||||
'confirmado' => 'Confirmado',
|
||||
|
||||
'reprint' => 'Reimpresión',
|
||||
'presupuestoGenerado' => 'Presupuesto generado con éxito',
|
||||
|
||||
'files' => 'Ficheros',
|
||||
'titulos' => [
|
||||
'libroFresadoTapaDura' => 'Rústica Fresado tapa dura',
|
||||
@ -402,6 +405,7 @@ return [
|
||||
],
|
||||
|
||||
'errores' => [
|
||||
'presupuestoNotFound' => 'Presupuesto no encontrado',
|
||||
'paginas' => 'El campo páginas tiene que ser mayor que cero',
|
||||
'paginasLP' => 'El número de páginas no coincide con el total',
|
||||
'tiradas' => 'El campo tiradas tiene que ser mayor que cero',
|
||||
|
||||
@ -24,10 +24,11 @@ class PresupuestoFicheroModel extends \App\Models\BaseModel
|
||||
public static $labelField = "nombre";
|
||||
|
||||
|
||||
public function saveFileInBBDD($presupuesto_id, $filename, $extension ,$user_id) {
|
||||
try{
|
||||
public function saveFileInBBDD($presupuesto_id, $filename, $extension, $user_id)
|
||||
{
|
||||
try {
|
||||
$new_filename = $this->generateFileHash($filename) . '.' . $extension;
|
||||
|
||||
|
||||
$this->db->table($this->table . " t1")
|
||||
->set('presupuesto_id', $presupuesto_id)
|
||||
->set('nombre', $filename)
|
||||
@ -42,13 +43,14 @@ class PresupuestoFicheroModel extends \App\Models\BaseModel
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteFiles($presupuesto_id, $old_files = []){
|
||||
public function deleteFiles($presupuesto_id, $old_files = [])
|
||||
{
|
||||
|
||||
$files = $this->db
|
||||
->table($this->table . " t1")
|
||||
->where('presupuesto_id', $presupuesto_id)->get()->getResult();
|
||||
if($files){
|
||||
foreach($files as $file){
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
|
||||
// se comprueba que el $file->nombre no sea igual a ninguno de los elementos del array $old_files
|
||||
if (!in_array($file->nombre, $old_files)) {
|
||||
@ -67,21 +69,52 @@ class PresupuestoFicheroModel extends \App\Models\BaseModel
|
||||
}
|
||||
|
||||
|
||||
public function getFiles($presupuesto_id){
|
||||
public function copyFiles($presupuesto_id_origen, $presupuesto_id_destino)
|
||||
{
|
||||
|
||||
$files = $this->db
|
||||
->table($this->table . " t1")
|
||||
->where('presupuesto_id', $presupuesto_id_origen)->get()->getResult();
|
||||
if ($files) {
|
||||
|
||||
foreach ($files as $file) {
|
||||
|
||||
$hash = $this->generateFileHash($file->nombre);
|
||||
|
||||
// se copia el fichero a la nueva ubicación
|
||||
if (!file_exists(WRITEPATH . $file->file_path)) {
|
||||
copy($file->file_path, WRITEPATH . 'uploads/presupuestos/' . $hash);
|
||||
}
|
||||
|
||||
$this->db->table($this->table . " t1")
|
||||
->set('presupuesto_id', $presupuesto_id_destino)
|
||||
->set('nombre', $file->nombre)
|
||||
->set('file_path', WRITEPATH . 'uploads/presupuestos/' . $hash)
|
||||
->set('upload_by', auth()->user()->id)
|
||||
->set('upload_at', date('Y-m-d H:i:s'))
|
||||
->insert();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getFiles($presupuesto_id)
|
||||
{
|
||||
return $this->db
|
||||
->table($this->table . " t1")
|
||||
->where('presupuesto_id', $presupuesto_id)->get()->getResult();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Función para convertir el nombre y extensión de un fichero en un hash único
|
||||
* usando cifrado simétrico.
|
||||
*
|
||||
* @param string $filename Nombre del fichero con extensión
|
||||
* @return string Hash encriptado del fichero
|
||||
*/
|
||||
private function generateFileHash($filename) {
|
||||
* Función para convertir el nombre y extensión de un fichero en un hash único
|
||||
* usando cifrado simétrico.
|
||||
*
|
||||
* @param string $filename Nombre del fichero con extensión
|
||||
* @return string Hash encriptado del fichero
|
||||
*/
|
||||
private function generateFileHash($filename)
|
||||
{
|
||||
return hash('sha256', $filename);
|
||||
}
|
||||
|
||||
|
||||
@ -2108,4 +2108,90 @@ class PresupuestoService extends BaseService
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function duplicarPresupuesto($id = null, $is_reimpresion = false, $copy_files = false)
|
||||
{
|
||||
try {
|
||||
|
||||
$modelPresupuesto = model('App\Models\Presupuestos\PresupuestoModel');
|
||||
$presupuesto = $modelPresupuesto->find($id);
|
||||
if (!$presupuesto || $id == null) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => lang('Presupuestos.presupuestoNotFound'),
|
||||
];
|
||||
}
|
||||
$presupuesto->titulo = $presupuesto->titulo . ' - ' . lang('Presupuestos.duplicado');
|
||||
$presupuesto->is_duplicado = 1;
|
||||
$presupuesto->estado_id = 1;
|
||||
if($is_reimpresion){
|
||||
$presupuesto->inc_rei = "reimpresion";
|
||||
$modelPedidoLinea = model('App\Models\Pedidos\PedidoLineaModel');
|
||||
$pedido_linea = $modelPedidoLinea->where('presupuesto_id', $id)->first();
|
||||
if($pedido_linea){
|
||||
$text = "REIMPRESION [" . date('Y-m-d H:i:s') . "] - PEDIDO: " . $pedido_linea->pedido_id .
|
||||
"\n================================================\n";
|
||||
$presupuesto->comentarios_safekat = $presupuesto->comentarios_safekat . $text;
|
||||
}
|
||||
}
|
||||
$new_id = $modelPresupuesto->insert($presupuesto);
|
||||
|
||||
$presupuestoAcabadosModel = model('App\Models\Presupuestos\PresupuestoAcabadosModel');
|
||||
foreach ($presupuestoAcabadosModel->where('presupuesto_id', $presupuesto->id)->findAll() as $acabado) {
|
||||
$acabado->presupuesto_id = $new_id;
|
||||
$presupuestoAcabadosModel->insert($acabado);
|
||||
}
|
||||
|
||||
$presupuestoEncuadernacionesModel = model('App\Models\Presupuestos\PresupuestoEncuadernacionesModel');
|
||||
foreach ($presupuestoEncuadernacionesModel->where('presupuesto_id', $presupuesto->id)->findAll() as $encuadernacion) {
|
||||
$encuadernacion->presupuesto_id = $new_id;
|
||||
$presupuestoEncuadernacionesModel->insert($encuadernacion);
|
||||
}
|
||||
|
||||
$presupuestoManipuladosModel = model('App\Models\Presupuestos\PresupuestoManipuladosModel');
|
||||
foreach ($presupuestoManipuladosModel->where('presupuesto_id', $presupuesto->id)->findAll() as $manipulado) {
|
||||
$manipulado->presupuesto_id = $new_id;
|
||||
$presupuestoManipuladosModel->insert($manipulado);
|
||||
}
|
||||
|
||||
$presupuestoPreimpresionesModel = model('App\Models\Presupuestos\PresupuestoPreimpresionesModel');
|
||||
foreach ($presupuestoPreimpresionesModel->where('presupuesto_id', $presupuesto->id)->findAll() as $preimpresion) {
|
||||
$preimpresion->presupuesto_id = $new_id;
|
||||
$presupuestoPreimpresionesModel->insert($preimpresion);
|
||||
}
|
||||
|
||||
$presupuestoServiciosExtraModel = model('App\Models\Presupuestos\PresupuestoServiciosExtraModel');
|
||||
foreach ($presupuestoServiciosExtraModel->where('presupuesto_id', $presupuesto->id)->findAll() as $servicioExtra) {
|
||||
$servicioExtra->presupuesto_id = $new_id;
|
||||
$presupuestoServiciosExtraModel->insert($servicioExtra);
|
||||
}
|
||||
|
||||
$presupuestoDireccionesModel = model('App\Models\Presupuestos\PresupuestoDireccionesModel');
|
||||
foreach ($presupuestoDireccionesModel->where('presupuesto_id', $presupuesto->id)->findAll() as $direccion) {
|
||||
$direccion->presupuesto_id = $new_id;
|
||||
$presupuestoDireccionesModel->insert($direccion);
|
||||
}
|
||||
|
||||
$presupuestoLineaModel = model('App\Models\Presupuestos\PresupuestoLineaModel');
|
||||
$presupuestoLineaModel->duplicateLineasPresupuesto($presupuesto->id, $new_id);
|
||||
|
||||
|
||||
if (boolval($copy_files)== true) {
|
||||
$presupuestoFilesModel = model('App\Models\Presupuestos\PresupuestoFicheroModel');
|
||||
$presupuestoFilesModel->copyFiles($presupuesto->id, $new_id);
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'id' => $new_id,
|
||||
'message' => lang('Presupuestos.presupuestoGenerado'),
|
||||
];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => $e->getMessage()
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,11 +93,19 @@
|
||||
<?php if (str_contains($formAction, 'edit')): ?>
|
||||
<?= anchor(route_to("presupuestoToPdf", $presupuestoId), lang("Basic.global.Print"), ["class" => "btn btn-dark float-start me-sm-3 me-1",'target' => '_blank']) ?>
|
||||
<input type="button"
|
||||
class="btn btn-info float-start me-sm-3 me-1"
|
||||
class="btn btn-primary float-start me-sm-3 me-1"
|
||||
name="clone"
|
||||
id="cloneForm"
|
||||
value="<?= lang("Basic.global.Clone") ?>"
|
||||
/>
|
||||
<?php if($presupuestoEntity->estado_id == 2): ?>
|
||||
<input type="button"
|
||||
class="btn btn-primary float-start me-sm-3 me-1"
|
||||
name="reprint"
|
||||
id="reprint"
|
||||
value="<?= lang("Presupuestos.reprint") ?>"
|
||||
/>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<?= anchor(route_to("presupuestoAdminList", $tipo_impresion_id), lang("Basic.global.Cancel"), ["class" => "btn btn-secondary float-start",]) ?>
|
||||
</div>
|
||||
|
||||
@ -180,6 +180,7 @@ class PresupuestoAdminEdit {
|
||||
this.fileUploadDropzone.init()
|
||||
}
|
||||
|
||||
$('#reprint').on('click', this.reprintPresupuesto.bind(this));
|
||||
}
|
||||
|
||||
|
||||
@ -401,12 +402,12 @@ class PresupuestoAdminEdit {
|
||||
self.tipo_impresion.val(response.data.tipo_impresion);
|
||||
self.POD.val(response.data.POD);
|
||||
|
||||
const totalAceptadoRevisado = response.data.total_aceptado_revisado != null ?
|
||||
const totalAceptadoRevisado = response.data.total_aceptado_revisado != null ?
|
||||
response.data.total_aceptado_revisado : response.data.resumen.total_aceptado;
|
||||
AutoNumeric.getAutoNumericElement($('#total_aceptado_revisado')[0]).set(totalAceptadoRevisado);
|
||||
|
||||
|
||||
$('#aprobado_by_at').html(response.data.aprobado_by_at);
|
||||
|
||||
|
||||
$('#created_by').html(response.data.created_by);
|
||||
$('#updated_by').html(response.data.updated_by);
|
||||
$('#created_at').html(response.data.created_at);
|
||||
@ -677,6 +678,66 @@ class PresupuestoAdminEdit {
|
||||
})
|
||||
}
|
||||
|
||||
reprintPresupuesto() {
|
||||
|
||||
const id = window.location.href.split("/").pop();
|
||||
new Ajax('/presupuestoadmin/hasFiles',
|
||||
{ id: id }, {},
|
||||
function (response) {
|
||||
if (response.status === 'success') {
|
||||
if (response.hasFiles) {
|
||||
|
||||
Swal.fire({
|
||||
title: 'El presupuesto tiene archivos adjuntos',
|
||||
text: '¿Desea incluir los mismos ficheros en el nuevo presupuesto?',
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Sí',
|
||||
cancelButtonText: 'No',
|
||||
customClass: {
|
||||
confirmButton: 'btn btn-danger me-1',
|
||||
cancelButton: 'btn btn-secondary'
|
||||
},
|
||||
buttonsStyling: false
|
||||
}).then((result) => {
|
||||
new Ajax('/presupuestoadmin/reprint',
|
||||
{ id: id, duplicateFiles: result.isConfirmed?1:0 }, {},
|
||||
function (response) {
|
||||
if (response.success === true) {
|
||||
Swal.fire({
|
||||
text: response.message,
|
||||
icon: 'success',
|
||||
confirmButtonColor: '#3085d6',
|
||||
confirmButtonText: 'Ok',
|
||||
customClass: {
|
||||
confirmButton: 'btn btn-primary me-1',
|
||||
},
|
||||
buttonsStyling: false
|
||||
})
|
||||
window.open('/presupuestoadmin/edit/' + response.id, '_blank');
|
||||
} else {
|
||||
popErrorAlert(response.mensaje);
|
||||
}
|
||||
},
|
||||
function (error) {
|
||||
popErrorAlert(error);
|
||||
}
|
||||
).post();
|
||||
});
|
||||
}
|
||||
|
||||
} else {
|
||||
popErrorAlert(response.mensaje);
|
||||
}
|
||||
$('#loader').modal('hide');
|
||||
},
|
||||
function (error) {
|
||||
console.error(error);
|
||||
$('#loader').modal('hide');
|
||||
}
|
||||
).get();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
@ -704,4 +765,5 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
console.log("Error getting translations:", error);
|
||||
}
|
||||
).post();
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user