mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
terminado editar cliente
This commit is contained in:
@ -861,6 +861,7 @@ class Cosidotapablanda extends \App\Controllers\BaseResourceController
|
||||
$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');
|
||||
|
||||
@ -169,6 +169,11 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
$this->obtenerPaginasColor($presupuestoEntity);
|
||||
$this->obtenerDireccionesEnvio($presupuestoEntity);
|
||||
|
||||
// Si el presupuesto está confirmado, se generan los datos del resumen
|
||||
if($presupuestoEntity->estado_id == 2){
|
||||
$this->generarResumen($presupuestoEntity);
|
||||
}
|
||||
|
||||
$this->viewData['formAction'] = route_to('updateCosidotapablanda', $id);
|
||||
|
||||
$this->viewData['paisList'] = $this->getPaisListItems();
|
||||
@ -473,6 +478,91 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
}
|
||||
}
|
||||
|
||||
public function duplicarPresupuesto(){
|
||||
if ($this->request->isAJAX()) {
|
||||
|
||||
$reqData = $this->request->getPost();
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
|
||||
$id = $reqData['id'] ?? 0;
|
||||
|
||||
if($id > 0){
|
||||
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($preimpresion);
|
||||
}
|
||||
|
||||
$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 $this->respond([
|
||||
'success' => true,
|
||||
'id' => $new_id,
|
||||
$csrfTokenName => $newTokenHash
|
||||
]);
|
||||
|
||||
}catch(\Exception $e){
|
||||
return $this->respond([
|
||||
'success' => false,
|
||||
'message' => $e->getMessage(),
|
||||
$csrfTokenName => $newTokenHash
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'success' => false,
|
||||
'message' => "No existe el presupuesto",
|
||||
$csrfTokenName => $newTokenHash
|
||||
|
||||
]);
|
||||
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function guardarPresupuesto()
|
||||
{
|
||||
if ($this->request->isAJAX()) {
|
||||
@ -1621,6 +1711,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
{
|
||||
$model = model('App\Models\Presupuestos\PresupuestoDireccionesModel');
|
||||
$model_direcciones = model('App\Models\Clientes\ClienteDireccionesModel');
|
||||
$model_pais = model('App\Models\Configuracion\PaisModel');
|
||||
$direcciones = $model->where('presupuesto_id', $presupuestoEntity->id)->findAll();
|
||||
|
||||
$result = [];
|
||||
@ -1636,6 +1727,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
$direcciones[$i]->telefono);
|
||||
if(count($direccion_id) > 0) {
|
||||
$temp = $direcciones[$i]->toArray();
|
||||
$temp['pais'] = $model_pais->where('id', $direcciones[$i]->pais_id)->first()->nombre;
|
||||
$temp['direccion_id'] = $direccion_id[0]->id;
|
||||
array_push($result, $temp);
|
||||
}
|
||||
@ -1679,4 +1771,91 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function generarResumen($presupuestoEntity){
|
||||
|
||||
$presupuestoEntity->resumen = (object)[
|
||||
'titulo' => $this->generarTitulo($presupuestoEntity),
|
||||
'tamanio' => $this->obtenerTamanio($presupuestoEntity),
|
||||
'tipo_impresion' => $this->obtenerTipoImpresion($presupuestoEntity)
|
||||
];
|
||||
|
||||
$model_papelGenerico = model('App\Models\Configuracion\PapelGenericoModel');
|
||||
if(!is_null($presupuestoEntity->papel_interior)){
|
||||
$nombre = $model_papelGenerico->where('id', $presupuestoEntity->papel_interior)->first()->nombre;
|
||||
if($nombre != null)
|
||||
$presupuestoEntity->papel_interior_nombre = $nombre;
|
||||
}
|
||||
if(!is_null($presupuestoEntity->papel_cubierta)){
|
||||
$nombre = $model_papelGenerico->where('id', $presupuestoEntity->papel_interior)->first()->nombre;
|
||||
if($nombre != null)
|
||||
$presupuestoEntity->papel_cubierta_nombre = $nombre;
|
||||
}
|
||||
if(!is_null($presupuestoEntity->papel_sobrecubierta)){
|
||||
$nombre = $model_papelGenerico->where('id', $presupuestoEntity->papel_sobrecubierta)->first()->nombre;
|
||||
if($nombre != null)
|
||||
$presupuestoEntity->papel_sobrecubierta_nombre = $nombre;
|
||||
}
|
||||
if(!is_null($presupuestoEntity->papel_guardas)){
|
||||
$nombre = $model_papelGenerico->where('id', $presupuestoEntity->papel_guardas)->first()->nombre;
|
||||
if($nombre != null)
|
||||
$presupuestoEntity->papel_guardas_nombre = $nombre;
|
||||
}
|
||||
}
|
||||
|
||||
protected function generarTitulo($presupuestoEntity){
|
||||
|
||||
$model = model('App\Models\Configuracion\TipoPresupuestoModel');
|
||||
$codigo = $model->where('id', $presupuestoEntity->tipo_impresion_id)->first()->codigo;
|
||||
$titulo = lang('Presupuestos.titulos.'.$codigo);
|
||||
return $titulo;
|
||||
}
|
||||
|
||||
protected function obtenerTamanio($presupuestoEntity){
|
||||
|
||||
$ancho = 0;
|
||||
$alto = 0;
|
||||
|
||||
$model = model('App\Models\Presupuestos\PresupuestoModel');
|
||||
$data = $model->where('id', $presupuestoEntity->id)->first();
|
||||
|
||||
if($data != null){
|
||||
if($data->papel_formato_personalizado == 0){
|
||||
|
||||
$model_papel_formato = model('App\Models\Configuracion\PapelFormatoModel');
|
||||
$data_papel_formato = $model_papel_formato->where('id', $data->papel_formato_id)->first();
|
||||
$ancho = $data_papel_formato->ancho;
|
||||
$alto = $data_papel_formato->alto;
|
||||
}
|
||||
else{
|
||||
$ancho = $data->papel_formato_ancho;
|
||||
$alto = $data->papel_formato_alto;
|
||||
}
|
||||
}
|
||||
|
||||
return $ancho . "x" . $alto;
|
||||
}
|
||||
|
||||
protected function obtenerTipoImpresion($presupuestoEntity){
|
||||
|
||||
$id = $presupuestoEntity->id;
|
||||
|
||||
$isColor = false;
|
||||
$isHq = false;
|
||||
|
||||
$model = model('App\Models\Presupuestos\PresupuestoLineaModel');
|
||||
$data = $model->where('presupuesto_id', $id)->findAll();
|
||||
if (count($data) > 0) {
|
||||
foreach ($data as $linea) {
|
||||
if (strpos($linea->tipo, "hq") !== false) {
|
||||
$isHq = true;
|
||||
}
|
||||
if (strpos($linea->tipo, "color") !== false) {
|
||||
$isColor = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
$tipo = "" . ($isColor ? "Color" : "Negro") . " " . ($isHq ? "premium" : "estándar");
|
||||
return $tipo;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user