mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
terminado a falta del resumen
This commit is contained in:
@ -158,7 +158,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
$datosPresupuesto->acabadosSobrecubierta = $this->getAcabadosSobrecubierta();
|
||||
|
||||
$datosPresupuesto->tipo_libro = $this->getTipoLibro($presupuestoEntity->tipo_impresion_id ?? null);
|
||||
[$datosPresupuesto->color_impresion, $datosPresupuesto->calidad_impresion] =
|
||||
[$datosPresupuesto->color_impresion, $datosPresupuesto->calidad_impresion] =
|
||||
$this->getTipoInterior($presupuestoEntity->id ?? null);
|
||||
$datosPresupuesto->tapa = $this->getTapa($presupuestoEntity->tipo_impresion_id ?? null);
|
||||
|
||||
@ -167,6 +167,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
$this->obtenerTiradas($presupuestoEntity);
|
||||
$this->obtenerDatosPapel($presupuestoEntity);
|
||||
$this->obtenerPaginasColor($presupuestoEntity);
|
||||
$this->obtenerDireccionesEnvio($presupuestoEntity);
|
||||
|
||||
$this->viewData['formAction'] = route_to('updateCosidotapablanda', $id);
|
||||
|
||||
@ -174,10 +175,10 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
|
||||
$this->viewData['presupuestoEntity'] = $presupuestoEntity;
|
||||
$this->viewData['datosPresupuesto'] = $datosPresupuesto;
|
||||
|
||||
|
||||
// Si se ha llamado a esta funcion porque se ha duplicado el presupuesto
|
||||
// se actualiza la bbdd para que sólo ejecute algunas funciones una vez
|
||||
if($presupuestoEntity->is_duplicado){
|
||||
if ($presupuestoEntity->is_duplicado) {
|
||||
$this->model->removeIsDuplicado($presupuestoEntity->id);
|
||||
}
|
||||
|
||||
@ -221,33 +222,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
}
|
||||
}
|
||||
|
||||
// Se borran las lineas de presupuesto
|
||||
$model = new PresupuestoLineaModel();
|
||||
$model->where("presupuesto_id", $id)->delete();
|
||||
|
||||
// Se borran las direcciones de presupuesto
|
||||
$model = new PresupuestoDireccionesModel();
|
||||
$model->where("presupuesto_id", $id)->delete();
|
||||
|
||||
// Se borran los servicios de acabado
|
||||
$model = new PresupuestoAcabadosModel();
|
||||
$model->where("presupuesto_id", $id)->delete();
|
||||
|
||||
// Se borran los servicios de preimpresion
|
||||
$model = new PresupuestoPreimpresionesModel();
|
||||
$model->where("presupuesto_id", $id)->delete();
|
||||
|
||||
// Se borran los servicios de encuadernacion
|
||||
$model = new PresupuestoEncuadernacionesModel();
|
||||
$model->where("presupuesto_id", $id)->delete();
|
||||
|
||||
// Se borran los servicios de manipulado
|
||||
$model = new PresupuestoManipuladosModel();
|
||||
$model->where("presupuesto_id", $id)->delete();
|
||||
|
||||
// Se borran los servicios extra
|
||||
$model = new PresupuestoServiciosExtraModel();
|
||||
$model->where("presupuesto_id", $id)->delete();
|
||||
$this->borrarRelacionesPresupuesto($id);
|
||||
|
||||
// $message = lang('Basic.global.deleteSuccess', [$objName]); IMN commented
|
||||
$message = lang('Basic.global.deleteSuccess', [lang('Basic.global.record')]);
|
||||
@ -255,6 +230,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
public function getGramaje()
|
||||
{
|
||||
if ($this->request->isAJAX()) {
|
||||
@ -373,7 +349,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
$sobreCubierta = $reqData["sobrecubierta"] ?? null;
|
||||
|
||||
// Guardas
|
||||
$datos_guardas = $reqData['guardas'] ?? 0;
|
||||
$datos_guardas = $reqData['guardas'] ?? [];
|
||||
|
||||
$servicios = $reqData['servicios'] ?? [];
|
||||
|
||||
@ -508,6 +484,9 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
|
||||
$confirmar = $reqData['confirmar'] ?? 0;
|
||||
|
||||
$id = $reqData['id'] ?? 0;
|
||||
$id = intval($id);
|
||||
|
||||
$datosCabecera = $reqData['datos_cabecera'] ?? [];
|
||||
|
||||
$tirada = $reqData['datos_libro']['tirada'] ?? 0;
|
||||
@ -604,12 +583,22 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
|
||||
$proporcion = intval($direccion['unidades']) / $selected_tirada * 100.0;
|
||||
$unidades_calculo = floor($tirada[$i] * $proporcion / 100.0);
|
||||
$coste_envio = $this->calcular_coste_envio(
|
||||
$direccion['id'],
|
||||
$peso_libro,
|
||||
$unidades_calculo,
|
||||
$direccion['tipo'] == 'cajas' ? 0 : 1
|
||||
);
|
||||
try{
|
||||
$coste_envio = $this->calcular_coste_envio(
|
||||
$direccion['id'],
|
||||
$peso_libro,
|
||||
$unidades_calculo,
|
||||
$direccion['tipo'] == 'cajas' ? 0 : 1
|
||||
);
|
||||
}
|
||||
catch(Exception $e){
|
||||
return $this->respond([
|
||||
'status' => -1,
|
||||
'message' => "Error al calcular el coste de envío (¿las direcciones están guardadas?)",
|
||||
$csrfTokenName => $newTokenHash
|
||||
]);
|
||||
}
|
||||
|
||||
if (count($coste_envio) > 0) {
|
||||
$coste = floatval($coste_envio[0]->coste);
|
||||
$margen = ($coste * floatval($coste_envio[0]->margen)) / 100.0;
|
||||
@ -648,7 +637,13 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
}
|
||||
}
|
||||
|
||||
$borrar_antes = false;
|
||||
if ($id != 0) {
|
||||
$borrar_antes = true;
|
||||
}
|
||||
|
||||
$id = $model_presupuesto->insertarPresupuestoCliente(
|
||||
$id,
|
||||
$selected_tirada,
|
||||
$datos_presupuesto,
|
||||
$datosCabecera,
|
||||
@ -660,6 +655,10 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
);
|
||||
|
||||
// Lineas Presupuesto
|
||||
if ($borrar_antes && $id > 0) {
|
||||
$this->borrarRelacionesPresupuesto($id);
|
||||
}
|
||||
|
||||
foreach ($resultado_presupuesto['info']['interior'] as $linea) {
|
||||
|
||||
if (count($linea) > 0)
|
||||
@ -693,7 +692,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
$this->guardarLineaEnvio($id, $direccion, $peso_libro);
|
||||
}
|
||||
|
||||
if($confirmar == 1){
|
||||
if ($confirmar) {
|
||||
$model_presupuesto->confirmarPresupuesto($id);
|
||||
}
|
||||
|
||||
@ -714,6 +713,37 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
* Funciones auxiliares
|
||||
*
|
||||
**********************/
|
||||
protected function borrarRelacionesPresupuesto($id)
|
||||
{
|
||||
// Se borran las lineas de presupuesto
|
||||
$model = new PresupuestoLineaModel();
|
||||
$model->where("presupuesto_id", $id)->delete();
|
||||
|
||||
// Se borran las direcciones de presupuesto
|
||||
$model = new PresupuestoDireccionesModel();
|
||||
$model->where("presupuesto_id", $id)->delete();
|
||||
|
||||
// Se borran los servicios de acabado
|
||||
$model = new PresupuestoAcabadosModel();
|
||||
$model->where("presupuesto_id", $id)->delete();
|
||||
|
||||
// Se borran los servicios de preimpresion
|
||||
$model = new PresupuestoPreimpresionesModel();
|
||||
$model->where("presupuesto_id", $id)->delete();
|
||||
|
||||
// Se borran los servicios de encuadernacion
|
||||
$model = new PresupuestoEncuadernacionesModel();
|
||||
$model->where("presupuesto_id", $id)->delete();
|
||||
|
||||
// Se borran los servicios de manipulado
|
||||
$model = new PresupuestoManipuladosModel();
|
||||
$model->where("presupuesto_id", $id)->delete();
|
||||
|
||||
// Se borran los servicios extra
|
||||
$model = new PresupuestoServiciosExtraModel();
|
||||
$model->where("presupuesto_id", $id)->delete();
|
||||
}
|
||||
|
||||
protected function guardarLineaPresupuesto($presupuestoId, $linea)
|
||||
{
|
||||
|
||||
@ -885,7 +915,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
$sobreCubierta = $datos_entrada["sobrecubierta"] ?? null;
|
||||
|
||||
// Guardas
|
||||
$datos_guardas = $datos_entrada['guardas'] ?? [];
|
||||
$datos_guardas = $datos_entrada['datos_guardas'] ?? [];
|
||||
|
||||
// Servicios
|
||||
$servicios = $datos_entrada['servicios'] ?? [];
|
||||
@ -1086,11 +1116,11 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
$lomo_sobrecubierta = 0.0;
|
||||
if (!is_null($sobreCubierta)) {
|
||||
|
||||
$papel_generico = [
|
||||
$papel_generico_sobrecubierta = [
|
||||
'id' => $sobreCubierta['papel'] ?? 0,
|
||||
'nombre' => $sobreCubierta['papel_nombre'] ?? "",
|
||||
];
|
||||
$input_data['papel_generico'] = $papel_generico;
|
||||
$input_data['papel_generico'] = $papel_generico_sobrecubierta;
|
||||
$input_data['gramaje'] = $sobreCubierta['gramaje'] ?? 0;
|
||||
$input_data['datosPedido']->paginas = 4;
|
||||
$input_data['paginas_color'] = 4;
|
||||
@ -1146,11 +1176,11 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
if (count($datos_guardas) != 0) {
|
||||
|
||||
$guardas = $datos_guardas;
|
||||
$papel_generico = [
|
||||
$papel_generico_guardas = [
|
||||
'id' => $datos_guardas['papel'] ?? 0,
|
||||
'nombre' => $datos_guardas['nombre'] ?? "",
|
||||
];
|
||||
$input_data['papel_generico'] = $papel_generico;
|
||||
$input_data['papel_generico'] = $papel_generico_guardas;
|
||||
$input_data['gramaje'] = $datos_guardas['gramaje'] ?? 0;
|
||||
$input_data['datosPedido']->paginas = 8;
|
||||
$input_data['paginas_color'] = 8;
|
||||
@ -1323,7 +1353,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
));
|
||||
}
|
||||
|
||||
if ($extra_info){// && $tirada[$t] == $selected_tirada) {
|
||||
if ($extra_info) { // && $tirada[$t] == $selected_tirada) {
|
||||
|
||||
$info['lomo_cubierta'] = $lomo;
|
||||
$info['lomo_sobrecubierta'] = $lomo_sobrecubierta;
|
||||
@ -1375,7 +1405,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
|
||||
if ($linea['tipo_maquina'] == 'inkjet') {
|
||||
$totalImpresion += $linea['precio_tinta'];
|
||||
if(array_key_exists('total_corte', $linea)){
|
||||
if (array_key_exists('total_corte', $linea)) {
|
||||
$totalImpresion += $linea['total_corte'];
|
||||
$sumForFactor += $linea['total_corte'];
|
||||
}
|
||||
@ -1503,120 +1533,148 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getTipoLibro($tipo_impresion_id){
|
||||
if($tipo_impresion_id == 1 || $tipo_impresion_id == 2){
|
||||
|
||||
protected function getTipoLibro($tipo_impresion_id)
|
||||
{
|
||||
if ($tipo_impresion_id == 1 || $tipo_impresion_id == 2) {
|
||||
return 'fresado';
|
||||
}
|
||||
else if ($tipo_impresion_id == 3 || $tipo_impresion_id == 4){
|
||||
} else if ($tipo_impresion_id == 3 || $tipo_impresion_id == 4) {
|
||||
return 'cosido';
|
||||
}
|
||||
else if ($tipo_impresion_id == 5 || $tipo_impresion_id == 6){
|
||||
} else if ($tipo_impresion_id == 5 || $tipo_impresion_id == 6) {
|
||||
return 'espiral';
|
||||
}
|
||||
else if ($tipo_impresion_id == 7 || $tipo_impresion_id == 8){
|
||||
} else if ($tipo_impresion_id == 7 || $tipo_impresion_id == 8) {
|
||||
return 'wireo';
|
||||
}
|
||||
else if ($tipo_impresion_id == 21){
|
||||
} else if ($tipo_impresion_id == 21) {
|
||||
return 'grapado';
|
||||
}
|
||||
else
|
||||
} else
|
||||
return '';
|
||||
}
|
||||
protected function getTipoInterior($presupuestoId){
|
||||
protected function getTipoInterior($presupuestoId)
|
||||
{
|
||||
|
||||
$calidad = 'estandar';
|
||||
$color = 'negro';
|
||||
|
||||
$model = model('App\Models\Presupuestos\PresupuestoLineaModel');
|
||||
$data = $model->where('presupuesto_id', $presupuestoId)->findAll();;
|
||||
foreach($data as $linea){
|
||||
foreach ($data as $linea) {
|
||||
|
||||
if (strpos($linea->tipo, "hq") !== false) { // $linea->tipo contains the substring "hq"
|
||||
$calidad='premium';
|
||||
$calidad = 'premium';
|
||||
}
|
||||
if (strpos($linea->tipo, "color") !== false) { // $linea->tipo contains the substring "color"
|
||||
$color='color';
|
||||
$color = 'color';
|
||||
}
|
||||
}
|
||||
return [$color, $calidad];
|
||||
|
||||
}
|
||||
|
||||
protected function getTapa($tipo_impresion_id ){
|
||||
|
||||
|
||||
protected function getTapa($tipo_impresion_id)
|
||||
{
|
||||
|
||||
$tapa = 'blanda';
|
||||
|
||||
if($tipo_impresion_id == 1 || $tipo_impresion_id == 3 ||
|
||||
$tipo_impresion_id == 5 || $tipo_impresion_id == 7)
|
||||
if (
|
||||
$tipo_impresion_id == 1 || $tipo_impresion_id == 3 ||
|
||||
$tipo_impresion_id == 5 || $tipo_impresion_id == 7
|
||||
)
|
||||
$tapa = 'dura';
|
||||
|
||||
return $tapa;
|
||||
|
||||
return $tapa;
|
||||
}
|
||||
|
||||
protected function obtenerPaginasColor($presupuestoEntity){
|
||||
protected function obtenerPaginasColor($presupuestoEntity)
|
||||
{
|
||||
$comparador_data = json_decode($presupuestoEntity->comparador_json_data);
|
||||
if(property_exists($comparador_data, 'color')){
|
||||
if (property_exists($comparador_data, 'color')) {
|
||||
$presupuestoEntity->paginasColor = $comparador_data->color->paginas;
|
||||
}
|
||||
if(property_exists($comparador_data, 'colorhq')){
|
||||
if (property_exists($comparador_data, 'colorhq')) {
|
||||
$presupuestoEntity->paginasColor = $comparador_data->colorhq->paginas;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$presupuestoEntity->paginasColor = 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected function obtenerTiradas($presupuestoEntity){
|
||||
protected function obtenerTiradas($presupuestoEntity)
|
||||
{
|
||||
|
||||
$tiradas_alternativas = json_decode($presupuestoEntity->tirada_alternativa_json_data, true);
|
||||
$tiradas = array();
|
||||
array_push($tiradas, $presupuestoEntity->tirada);
|
||||
if(!is_null($tiradas_alternativas)){
|
||||
if(count($tiradas_alternativas) > 0){
|
||||
foreach($tiradas_alternativas as $tirada){
|
||||
if (!is_null($tiradas_alternativas)) {
|
||||
if (count($tiradas_alternativas) > 0) {
|
||||
foreach ($tiradas_alternativas as $tirada) {
|
||||
array_push($tiradas, intval($tirada['tirada']));
|
||||
}
|
||||
}
|
||||
}
|
||||
sort($tiradas);
|
||||
$presupuestoEntity->selected_tirada = $presupuestoEntity->tirada;
|
||||
for($i=0; $i<count($tiradas); $i++){
|
||||
$key = 'tirada' . ($i==0?'':strval($i+1));
|
||||
for ($i = 0; $i < count($tiradas); $i++) {
|
||||
$key = 'tirada' . ($i == 0 ? '' : strval($i + 1));
|
||||
$presupuestoEntity->$key = $tiradas[$i];
|
||||
}
|
||||
}
|
||||
|
||||
protected function obtenerDatosPapel($presupuestoEntity){
|
||||
protected function obtenerDireccionesEnvio($presupuestoEntity)
|
||||
{
|
||||
$model = model('App\Models\Presupuestos\PresupuestoDireccionesModel');
|
||||
$model_direcciones = model('App\Models\Clientes\ClienteDireccionesModel');
|
||||
$direcciones = $model->where('presupuesto_id', $presupuestoEntity->id)->findAll();
|
||||
|
||||
$result = [];
|
||||
$temp = [];
|
||||
for ($i=0; $i<count($direcciones); $i++) {
|
||||
$direccion_id = $model_direcciones->getIdForPresupuestoCliente(
|
||||
$presupuestoEntity->cliente_id,
|
||||
$direcciones[$i]->att,
|
||||
$direcciones[$i]->email,
|
||||
$direcciones[$i]->direccion,
|
||||
$direcciones[$i]->cp,
|
||||
$direcciones[$i]->pais_id,
|
||||
$direcciones[$i]->telefono);
|
||||
if(count($direccion_id) > 0) {
|
||||
$temp = $direcciones[$i]->toArray();
|
||||
$temp['direccion_id'] = $direccion_id[0]->id;
|
||||
array_push($result, $temp);
|
||||
}
|
||||
}
|
||||
if(count($result) > 0)
|
||||
$presupuestoEntity->direcciones_envio = $result;
|
||||
}
|
||||
|
||||
protected function obtenerDatosPapel($presupuestoEntity)
|
||||
{
|
||||
|
||||
$id = $presupuestoEntity->id;
|
||||
|
||||
$model = model('App\Models\Presupuestos\PresupuestoLineaModel');
|
||||
$data = $model->where('presupuesto_id', $id)->findAll();
|
||||
if(count($data)>0){
|
||||
foreach($data as $linea){
|
||||
if (count($data) > 0) {
|
||||
foreach ($data as $linea) {
|
||||
// Se coje el primer papel que se encuentre para el interior
|
||||
// para presupuestos del cliente sólo se escoje un papel para el interior
|
||||
if (strpos($linea->tipo, "bn") !== false || strpos($linea->tipo, "color") !== false) {
|
||||
if (strpos($linea->tipo, "bn") !== false || strpos($linea->tipo, "color") !== false) {
|
||||
$presupuestoEntity->papel_interior = $linea->papel_id;
|
||||
$presupuestoEntity->gramaje_interior = $linea->gramaje;
|
||||
}
|
||||
// Si es cubierta
|
||||
else if (strpos($linea->tipo, "cubierta") !== false && strpos($linea->tipo, "sobrecubierta") === false) {
|
||||
else if (strpos($linea->tipo, "cubierta") !== false && strpos($linea->tipo, "sobrecubierta") === false) {
|
||||
$presupuestoEntity->papel_cubierta = $linea->papel_id;
|
||||
$presupuestoEntity->gramaje_cubierta = $linea->gramaje;
|
||||
$presupuestoEntity->paginas_cubierta = $linea->paginas;
|
||||
}
|
||||
// Si es sobrecubierta
|
||||
else if (strpos($linea->tipo, "sobrecubierta") !== false) {
|
||||
else if (strpos($linea->tipo, "sobrecubierta") !== false) {
|
||||
$presupuestoEntity->papel_sobrecubierta = $linea->papel_id;
|
||||
$presupuestoEntity->gramaje_sobrecubierta = $linea->gramaje;
|
||||
$presupuestoEntity->paginas_sobrecubierta = $linea->paginas;
|
||||
}
|
||||
// Si es guardas
|
||||
else if (strpos($linea->tipo, "guardas") !== false) {
|
||||
$presupuestoEntity->papel_guardas = $linea->papel_id;;
|
||||
else if (strpos($linea->tipo, "guardas") !== false) {
|
||||
$presupuestoEntity->papel_guardas = $linea->papel_id;
|
||||
$presupuestoEntity->paginas_guardas = $linea->paginas;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user