mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
terminada funcionalidad reimpresion presupuestos
This commit is contained in:
@ -31,6 +31,9 @@ $routes->group('presupuestoadmin', ['namespace' => 'App\Controllers\Presupuestos
|
|||||||
$routes->get('presupuestosCliente', 'Presupuestoadmin::tablaClienteForm');
|
$routes->get('presupuestosCliente', 'Presupuestoadmin::tablaClienteForm');
|
||||||
$routes->get('getSumCliente/(:num)', 'Presupuestoadmin::obtenerTotalPresupuestosCliente/$1');
|
$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']);
|
$routes->post('download_zip', 'Presupuestocliente::download_zip', ['as' => 'descargarAdminArchivos']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -133,8 +133,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
|||||||
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'];
|
$ancho = $sanitizedData['papel_formato_ancho'];
|
||||||
$alto = $sanitizedData['papel_formato_alto'];
|
$alto = $sanitizedData['papel_formato_alto'];
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
$papelFormatoModel = new PapelFormatoModel();
|
$papelFormatoModel = new PapelFormatoModel();
|
||||||
$papelFormato = $papelFormatoModel->find($sanitizedData['papel_formato_id']);
|
$papelFormato = $papelFormatoModel->find($sanitizedData['papel_formato_id']);
|
||||||
$ancho = $papelFormato->ancho;
|
$ancho = $papelFormato->ancho;
|
||||||
@ -242,8 +241,10 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
|||||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||||
$sanitizedData['user_updated_id'] = auth()->user()->id;
|
$sanitizedData['user_updated_id'] = auth()->user()->id;
|
||||||
|
|
||||||
if(isset($sanitizedData['total_aceptado_revisado']) && $sanitizedData['total_aceptado_revisado'] != 0
|
if (
|
||||||
&& $sanitizedData['total_aceptado_revisado'] != null && $sanitizedData['total_aceptado_revisado'] != ""){
|
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_at'] = $sanitizedData['updated_at'];
|
||||||
$sanitizedData['aprobado_user_id'] = $sanitizedData['user_updated_id'];
|
$sanitizedData['aprobado_user_id'] = $sanitizedData['user_updated_id'];
|
||||||
}
|
}
|
||||||
@ -1082,8 +1083,10 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
|||||||
|
|
||||||
$resourceData = PresupuestoService::obtenerComparadorPlana($input_data);
|
$resourceData = PresupuestoService::obtenerComparadorPlana($input_data);
|
||||||
|
|
||||||
if($calcular_merma == 1 && count($resourceData) > 0 &&
|
if (
|
||||||
count($resourceData[0]['fields']) >0 && $resourceData[0]['fields']['num_formas'] > 0) {
|
$calcular_merma == 1 && count($resourceData) > 0 &&
|
||||||
|
count($resourceData[0]['fields']) > 0 && $resourceData[0]['fields']['num_formas'] > 0
|
||||||
|
) {
|
||||||
|
|
||||||
usort($resourceData, function ($a, $b) {
|
usort($resourceData, function ($a, $b) {
|
||||||
return $b['fields']['total_impresion'] <=> $a['fields']['total_impresion'];
|
return $b['fields']['total_impresion'] <=> $a['fields']['total_impresion'];
|
||||||
@ -1132,8 +1135,10 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
|||||||
|
|
||||||
$resourceData = PresupuestoService::obtenerComparadorRotativa($input_data);
|
$resourceData = PresupuestoService::obtenerComparadorRotativa($input_data);
|
||||||
|
|
||||||
if($calcular_merma == 1 && count($resourceData) > 0 &&
|
if (
|
||||||
count($resourceData[0]['fields']) >0 && $resourceData[0]['fields']['num_formas'] > 0) {
|
$calcular_merma == 1 && count($resourceData) > 0 &&
|
||||||
|
count($resourceData[0]['fields']) > 0 && $resourceData[0]['fields']['num_formas'] > 0
|
||||||
|
) {
|
||||||
|
|
||||||
usort($resourceData, function ($a, $b) {
|
usort($resourceData, function ($a, $b) {
|
||||||
return $b['fields']['total_impresion'] <=> $a['fields']['total_impresion'];
|
return $b['fields']['total_impresion'] <=> $a['fields']['total_impresion'];
|
||||||
@ -1215,7 +1220,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
|||||||
return $this->respond($data);
|
return $this->respond($data);
|
||||||
} else if ($tipo == 'duplicar') {
|
} else if ($tipo == 'duplicar') {
|
||||||
$presupuesto_id = $reqData['presupuesto_id'] ?? -1;
|
$presupuesto_id = $reqData['presupuesto_id'] ?? -1;
|
||||||
$result = $this->duplicarPresupuesto($presupuesto_id);
|
$result = PresupuestoService::duplicarPresupuesto($presupuesto_id);
|
||||||
$newTokenHash = csrf_hash();
|
$newTokenHash = csrf_hash();
|
||||||
$csrfTokenName = csrf_token();
|
$csrfTokenName = csrf_token();
|
||||||
if ($result['success']) {
|
if ($result['success']) {
|
||||||
@ -1300,7 +1305,8 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
|||||||
$isPOD,
|
$isPOD,
|
||||||
$anchoLibro,
|
$anchoLibro,
|
||||||
$alto,
|
$alto,
|
||||||
$tirada);
|
$tirada
|
||||||
|
);
|
||||||
if ($this->request->getGet("q")) {
|
if ($this->request->getGet("q")) {
|
||||||
$query->groupStart()
|
$query->groupStart()
|
||||||
->orLike("t1.nombre", $this->request->getGet("q"))
|
->orLike("t1.nombre", $this->request->getGet("q"))
|
||||||
@ -1356,7 +1362,8 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$model = model('App\Models\Configuracion\PapelGenericoModel');
|
$model = model('App\Models\Configuracion\PapelGenericoModel');
|
||||||
$query = $model->getGramajeForComparador($tipo,
|
$query = $model->getGramajeForComparador(
|
||||||
|
$tipo,
|
||||||
$papel_generico_id,
|
$papel_generico_id,
|
||||||
$cubierta,
|
$cubierta,
|
||||||
$sobrecubierta,
|
$sobrecubierta,
|
||||||
@ -1366,7 +1373,8 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
|||||||
$isPOD,
|
$isPOD,
|
||||||
$anchoLibro,
|
$anchoLibro,
|
||||||
$alto,
|
$alto,
|
||||||
$tirada);
|
$tirada
|
||||||
|
);
|
||||||
if ($this->request->getGet("q")) {
|
if ($this->request->getGet("q")) {
|
||||||
$query->groupStart()
|
$query->groupStart()
|
||||||
->orLike("t2.gramaje", $this->request->getGet("q"))
|
->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()
|
public function allItemsSelect()
|
||||||
{
|
{
|
||||||
@ -1815,7 +1748,8 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
|||||||
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(
|
->edit(
|
||||||
'estado', fn($q) => match ($q->estado) {
|
'estado',
|
||||||
|
fn($q) => match ($q->estado) {
|
||||||
"1" => lang('Presupuestos.borrador'),
|
"1" => lang('Presupuestos.borrador'),
|
||||||
"2" => lang('Presupuestos.confirmado'),
|
"2" => lang('Presupuestos.confirmado'),
|
||||||
default => '--'
|
default => '--'
|
||||||
@ -1832,7 +1766,8 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
|||||||
return $result->toJson(returnAsObject: true);
|
return $result->toJson(returnAsObject: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function obtenerTotalPresupuestosCliente($cliente_id){
|
public function obtenerTotalPresupuestosCliente($cliente_id)
|
||||||
|
{
|
||||||
|
|
||||||
$error = false;
|
$error = false;
|
||||||
$result = [
|
$result = [
|
||||||
@ -1845,15 +1780,15 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
|||||||
->groupBy('presupuestos.cliente_id')->get()->getResultObject();
|
->groupBy('presupuestos.cliente_id')->get()->getResultObject();
|
||||||
if (count($data) > 0) {
|
if (count($data) > 0) {
|
||||||
$result['total_impresion'] = round(floatval($data[0]->total), 2);
|
$result['total_impresion'] = round(floatval($data[0]->total), 2);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
$error = true;
|
$error = true;
|
||||||
}
|
}
|
||||||
$result['total'] = $result['total_impresion'] + $result['total_maquetacion'];
|
$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;
|
$error = false;
|
||||||
$result = [
|
$result = [
|
||||||
@ -1868,8 +1803,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
|||||||
->groupBy('presupuestos.cliente_id')->get()->getResultObject();
|
->groupBy('presupuestos.cliente_id')->get()->getResultObject();
|
||||||
if (count($data) > 0) {
|
if (count($data) > 0) {
|
||||||
$result['total_impresion'] = round(floatval($data[0]->total), 2);
|
$result['total_impresion'] = round(floatval($data[0]->total), 2);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
$error = true;
|
$error = true;
|
||||||
}
|
}
|
||||||
$result['total'] = $result['total_impresion'] + $result['total_maquetacion'];
|
$result['total'] = $result['total_impresion'] + $result['total_maquetacion'];
|
||||||
@ -1877,6 +1811,51 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected function getClienteListItems($selId = null)
|
protected function getClienteListItems($selId = null)
|
||||||
{
|
{
|
||||||
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Clientes.cliente'))])];
|
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Clientes.cliente'))])];
|
||||||
@ -1972,4 +1951,6 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
|||||||
|
|
||||||
return $direcciones;
|
return $direcciones;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -363,6 +363,9 @@ return [
|
|||||||
'borrador' => 'Borrador',
|
'borrador' => 'Borrador',
|
||||||
'confirmado' => 'Confirmado',
|
'confirmado' => 'Confirmado',
|
||||||
|
|
||||||
|
'reprint' => 'Reimpresión',
|
||||||
|
'presupuestoGenerado' => 'Presupuesto generado con éxito',
|
||||||
|
|
||||||
'files' => 'Ficheros',
|
'files' => 'Ficheros',
|
||||||
'titulos' => [
|
'titulos' => [
|
||||||
'libroFresadoTapaDura' => 'Rústica Fresado tapa dura',
|
'libroFresadoTapaDura' => 'Rústica Fresado tapa dura',
|
||||||
@ -402,6 +405,7 @@ return [
|
|||||||
],
|
],
|
||||||
|
|
||||||
'errores' => [
|
'errores' => [
|
||||||
|
'presupuestoNotFound' => 'Presupuesto no encontrado',
|
||||||
'paginas' => 'El campo páginas tiene que ser mayor que cero',
|
'paginas' => 'El campo páginas tiene que ser mayor que cero',
|
||||||
'paginasLP' => 'El número de páginas no coincide con el total',
|
'paginasLP' => 'El número de páginas no coincide con el total',
|
||||||
'tiradas' => 'El campo tiradas tiene que ser mayor que cero',
|
'tiradas' => 'El campo tiradas tiene que ser mayor que cero',
|
||||||
|
|||||||
@ -24,7 +24,8 @@ class PresupuestoFicheroModel extends \App\Models\BaseModel
|
|||||||
public static $labelField = "nombre";
|
public static $labelField = "nombre";
|
||||||
|
|
||||||
|
|
||||||
public function saveFileInBBDD($presupuesto_id, $filename, $extension ,$user_id) {
|
public function saveFileInBBDD($presupuesto_id, $filename, $extension, $user_id)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
$new_filename = $this->generateFileHash($filename) . '.' . $extension;
|
$new_filename = $this->generateFileHash($filename) . '.' . $extension;
|
||||||
|
|
||||||
@ -42,7 +43,8 @@ class PresupuestoFicheroModel extends \App\Models\BaseModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteFiles($presupuesto_id, $old_files = []){
|
public function deleteFiles($presupuesto_id, $old_files = [])
|
||||||
|
{
|
||||||
|
|
||||||
$files = $this->db
|
$files = $this->db
|
||||||
->table($this->table . " t1")
|
->table($this->table . " t1")
|
||||||
@ -67,7 +69,37 @@ 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
|
return $this->db
|
||||||
->table($this->table . " t1")
|
->table($this->table . " t1")
|
||||||
->where('presupuesto_id', $presupuesto_id)->get()->getResult();
|
->where('presupuesto_id', $presupuesto_id)->get()->getResult();
|
||||||
@ -81,7 +113,8 @@ class PresupuestoFicheroModel extends \App\Models\BaseModel
|
|||||||
* @param string $filename Nombre del fichero con extensión
|
* @param string $filename Nombre del fichero con extensión
|
||||||
* @return string Hash encriptado del fichero
|
* @return string Hash encriptado del fichero
|
||||||
*/
|
*/
|
||||||
private function generateFileHash($filename) {
|
private function generateFileHash($filename)
|
||||||
|
{
|
||||||
return hash('sha256', $filename);
|
return hash('sha256', $filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2108,4 +2108,90 @@ class PresupuestoService extends BaseService
|
|||||||
}
|
}
|
||||||
return null;
|
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')): ?>
|
<?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']) ?>
|
<?= 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"
|
<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"
|
name="clone"
|
||||||
id="cloneForm"
|
id="cloneForm"
|
||||||
value="<?= lang("Basic.global.Clone") ?>"
|
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; ?>
|
<?php endif; ?>
|
||||||
<?= anchor(route_to("presupuestoAdminList", $tipo_impresion_id), lang("Basic.global.Cancel"), ["class" => "btn btn-secondary float-start",]) ?>
|
<?= anchor(route_to("presupuestoAdminList", $tipo_impresion_id), lang("Basic.global.Cancel"), ["class" => "btn btn-secondary float-start",]) ?>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -180,6 +180,7 @@ class PresupuestoAdminEdit {
|
|||||||
this.fileUploadDropzone.init()
|
this.fileUploadDropzone.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$('#reprint').on('click', this.reprintPresupuesto.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -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 () {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
@ -704,4 +765,5 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
console.log("Error getting translations:", error);
|
console.log("Error getting translations:", error);
|
||||||
}
|
}
|
||||||
).post();
|
).post();
|
||||||
|
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user