terminado a falta del resumen

This commit is contained in:
jaimejimenezortega
2024-05-21 20:43:47 +02:00
parent 77c284c9b4
commit 44c5595173
11 changed files with 38841 additions and 130 deletions

View File

@ -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;
}
}
}

View File

@ -141,6 +141,25 @@ class ClienteDireccionesModel extends \App\Models\BaseModel
return $builder->get()->getResultObject();
}
public function getIdForPresupuestoCliente($cliente_id = -1, $att = "", $email = "", $direccion = "", $cp = "", $pais_id = -1, $telefono = "")
{
$builder = $this->db
->table($this->table . " t1")
->select("t1.id AS id")
->where("t1.cliente_id", $cliente_id)
->where("t1.att", $att)
->where("t1.email", $email)
->where("t1.direccion", $direccion)
->where("t1.cp", $cp)
->where("t1.pais_id", $pais_id)
->where("t1.telefono", $telefono)
->limit(1);
return $builder->get()->getResultObject();
}
public function getMenuDirecciones($cliente_id=-1){

View File

@ -521,7 +521,7 @@ class PresupuestoLineaModel extends \App\Models\BaseModel
}
if($new_linea['tipo_linea'] =='lp_guardas')
array_push($data, ['paginas_impresion' => $new_linea['paginas_impresion']]);
$data = array_merge($data, ['paginas_impresion' => $new_linea['paginas_impresion']]);
return $this->db
->table($this->table . " t1")

View File

@ -372,11 +372,11 @@ class PresupuestoModel extends \App\Models\BaseModel
$this->db
->table($this->table . " t1")
->where('t1.id', $presupuesto_id)
->set('t1.estado', 2)
->set('t1.estado_id', 2)
->update();
}
function insertarPresupuestoCliente($tirada, $data, $data_cabecera, $extra_info, $resumen_totales, $iva_reducido, $excluir_rotativa, $tiradas_alternativas)
function insertarPresupuestoCliente($id, $tirada, $data, $data_cabecera, $extra_info, $resumen_totales, $iva_reducido, $excluir_rotativa, $tiradas_alternativas)
{
helper('date');
@ -462,9 +462,19 @@ class PresupuestoModel extends \App\Models\BaseModel
'excluir_rotativa' => $excluir_rotativa,
];
if($id != 0){
$fields['id'] = $id;
$fields['updated_at'] = date('Y-m-d H:i:s', now());
}
$this->db->table($this->table)->insert($fields);
return $this->db->insertID();
if($id != 0){
$this->db->table($this->table)->where('id', $id)->update($fields);
return $id;
}
else{
$this->db->table($this->table)->insert($fields);
return $this->db->insertID();
}
}
private function generateJson($data)

View File

@ -32,13 +32,14 @@
</div>
<div id="divDirecciones" class="col-12 pb-2">
</div>
</div>
<?= $this->section("additionalInlineJs") ?>
window.direcciones = <?= json_encode($presupuestoEntity->direcciones_envio) ?>;
window.direcciones_sel_tirada = <?= json_encode($presupuestoEntity->selected_tirada) ?>;
window.routes_direcciones = {
direcciones: "<?= route_to('getDirecciones') ?>",
getDatos: "<?= route_to('getDatosDireccion') ?>",

View File

@ -374,7 +374,7 @@
<div class="col-sm-3 mb-md-0 mb-2 d-flex align-items-end">
<div class="form-check form-switch mb-2">
<input class="form-check-input" type="checkbox" id="enableSobrecubierta" name="enableSobrecubierta" value="0"
<?php if (isset($datosPresupuesto->papel_sobrecubierta) && is_array($datosPresupuesto->papel_sobrecubierta) && !empty($datosPresupuesto->papel_sobrecubierta)) :
<?php if (isset($presupuestoEntity->papel_sobrecubierta) && $presupuestoEntity->papel_sobrecubierta>0) :
echo 'checked';
endif; ?>
>
@ -384,7 +384,7 @@
</div>
<h6 class="sobrecubierta enable-sobrecubierta"
<?php if (isset($datosPresupuesto->papel_sobrecubierta) && is_array($datosPresupuesto->papel_sobrecubierta) && !empty($datosPresupuesto->papel_sobrecubierta)) :
<?php if (isset($presupuestoEntity->papel_sobrecubierta) && $presupuestoEntity->papel_sobrecubierta>0) :
echo '';
else:
echo 'style="display: none;"';
@ -414,14 +414,20 @@
</div>
<h6 class="sobrecubierta enable-sobrecubierta"
<?php if (isset($datosPresupuesto->papel_sobrecubierta) && is_array($datosPresupuesto->papel_sobrecubierta) && !empty($datosPresupuesto->papel_sobrecubierta)) :
<?php if (isset($presupuestoEntity->papel_sobrecubierta) && $presupuestoEntity->papel_sobrecubierta>0) :
echo '';
else:
echo 'style="display: none;"';
endif; ?>
> Opciones extra </h6>
<div class="row sobrecubierta enable-sobrecubierta" style="display: none;">
<div class="row sobrecubierta enable-sobrecubierta"
<?php if (isset($presupuestoEntity->papel_sobrecubierta) && $presupuestoEntity->papel_sobrecubierta>0) :
echo '';
else:
echo 'style="display: none;"';
endif; ?>
>
<div id="tamanioSolapasSobrecubierta" class="col-sm-3 mb-md-0 mb-2"">
<label for="anchoSolapasSobrecubierta" class="form-label">Tamaño solapas</label>
@ -431,7 +437,7 @@
</div>
<div class="row sobrecubierta enable-sobrecubierta"
<?php if (isset($datosPresupuesto->papel_sobrecubierta) && is_array($datosPresupuesto->papel_sobrecubierta) && !empty($datosPresupuesto->papel_sobrecubierta)) :
<?php if (isset($presupuestoEntity->papel_sobrecubierta) && $presupuestoEntity->papel_sobrecubierta>0) :
echo '';
else:
echo 'style="display: none;"';
@ -469,13 +475,19 @@
<div class="col-sm-4 mb-md-0 mb-2">
<label for="impresionGuardas" class="form-label">Impresión de guardas</label>
<select id="impresionGuardas" name="impresionGuardas" class="form-control select2bs2 comp_guardas_items calcular-presupuesto" style="width: 100%;">
<option value="0">
<option value="0"
<?php echo ((!isset($presupuestoEntity->paginas_guardas) || $presupuestoEntity->paginas_guardas==0) ? 'selected' : ''); ?>
>
<p><?= lang('Presupuestos.sinImpresion') ?></p>
</option>
<option value="4">
<option value="4"
<?php echo ($presupuestoEntity->paginas_guardas==4 ? 'selected' : ''); ?>
>
<p><?= lang('Presupuestos.unaCara') ?></p>
</option>
<option value="8">
<option value="8"
<?php echo ($presupuestoEntity->paginas_guardas==8 ? 'selected' : ''); ?>
>
<p><?= lang('Presupuestos.dosCaras') ?></p>
</option>
</select>
@ -488,7 +500,7 @@
<select id="papelGuardas" name="papelGuardas" class="form-control select2bs2 calcular-presupuesto" style="width: 100%;">
<?php if (isset($datosPresupuesto->papelGuardas) && is_array($datosPresupuesto->papelGuardas) && !empty($datosPresupuesto->papelGuardas)) :
foreach ($datosPresupuesto->papelGuardas as $k => $v) : ?>
<option value="<?= $v->id ?>">
<option value="<?= $v->id ?>" <? echo ($v->id==$presupuestoEntity->papel_guardas?'selected':'');?> >
<?= $v->nombre ?>
</option>
<?php endforeach;

View File

@ -1,5 +1,9 @@
<div class="col-12 pb-2">
<div class="row mb-3">
<?php if($presupuestoEntity->estado_id==2): ?>
<h2>PRESUPUESTO ACEPTADO</h2>
<br>
<?php endif; ?>
<h3>Resumen</h3>
<div class="col-sm-6">
<h5 class="mb-1">Libro</h5>
@ -48,7 +52,11 @@
<?= $this->section("additionalInlineJs") ?>
window.estado = <?= $presupuestoEntity->estado_id ?>;
window.tirada = <?= $presupuestoEntity->selected_tirada ?>;
window.total = <?= $presupuestoEntity->total_aceptado ?>;
window.total_unidad = <?= $presupuestoEntity->total_precio_unidad ?>;
window.iva_reducido= <?= $presupuestoEntity->iva_reducido ?>;
window.routes_resumen = {
guardarPresupuesto: "<?= route_to('guardarPresupuesto') ?>",
}

View File

@ -24,6 +24,7 @@ function initDirecciones() {
function initTiradasDirecciones() {
const _this = this
let sel_index = 1;
$('#containerTiradasEnvios').empty();
@ -54,10 +55,16 @@ function initTiradasDirecciones() {
$('#containerTiradasEnvios').append(html);
if(parseInt($('#' + tirada_id).text().split(' ')[0]) == window.direcciones_sel_tirada){
sel_index = i;
}
$('#' + id).hide();
}
$('#env_tiradaPrecio1').trigger('click');
}
$(('#env_tiradaPrecio' + sel_index)).trigger('click');
cargarDirecciones();
const tiradasDireccionesList = [].slice.call(document.querySelectorAll('.custom-option-tiradasDirecciones .form-check-input'))
tiradasDireccionesList.map(function (customOptionEL) {
@ -71,6 +78,48 @@ function initTiradasDirecciones() {
})
}
function cargarDirecciones(){
$('#loader').show();
$('#divDirecciones').empty();
if(window.direcciones == null){
$('#loader').hide();
return;
}
for(let i=0; i<window.direcciones.length; i++){
const tipo = window.direcciones[i].entregaPieCalle == 1?'palets':'cajas';
let html = '';
html += '<div id="envioId' + window.direcciones[i].direccion_id + '" t="' + tipo + '" p= ' +window.direcciones[i].precio + ' class="row mb-3">';
html += '<div class="col-sm-5 form-check custom-option custom-option-basic checked">';
html += '<label class="form-check-label custom-option-content" for="customRadioAddress1">';
html += '<span class="custom-option-header mb-2">';
html += '<h6 class="fw-semibold mb-0">' + window.direcciones[i].att + '</h6>';
html += '<span class="badge bg-label-primary">' + window.direcciones[i].cantidad + ' unidades</span>';
html += '</span>';
html += '<span class="custom-option-body">';
html += '<small>' + window.direcciones[i].direccion + '</small><br>';
html += '<small>' + window.direcciones[i].cp + '</small><br>';
html += '<small>' + window.direcciones[i].municipio +', ' + window.direcciones[i].pais + '</small><br>';
html += '<small>' + window.direcciones[i].telefono + '</small><br>';
html += '<small>' + window.direcciones[i].email + '</small><br>';
if(tipo == 'palets'){
html += '<small><i>Envío en palets</i></small><br>';
}
html += '<hr class="my-2">';
html += '<span class="d-flex">';
html += '<a class="eliminar-direccion" href="javascript:void(0)">Eliminar</a>';
html += '</span>';
html += '</span>';
html += '</label>';
html += '</div>';
html += '</div>';
$('#divDirecciones').append(html);
$('#errorDirecciones').hide();
$('#loader').hide();
}
}
function updateTiradasDireccionesCheck(el) {
if (el.checked) {
// If custom option element is radio, remove checked from the siblings (closest `.row`)

View File

@ -77,32 +77,44 @@ function generarResumen(){
$('.resumen-extras').hide();
}
for (i = 1; i <= 4; i++) {
let id = "tiradaPrecio" + i;
if ($('#' + id).length > 0) {
if(window.estado==1){
for (i = 1; i <= 4; i++) {
let id = "tiradaPrecio" + i;
if ($('#' + id).length > 0) {
const envio = getTotalEnvio();
let tirada_id = "ud_tiradaPrecio" + i;
if(parseInt($('#' + tirada_id).text().replace(' ud.', '')) != tirada){
continue;
}
const envio = getTotalEnvio();
let tirada_id = "ud_tiradaPrecio" + i;
if(parseInt($('#' + tirada_id).text().replace(' ud.', '')) != tirada){
continue;
}
let total_id = "tot_tiradaPrecio" + i;
let total = parseFloat($('#' + total_id).text().replace('€', '').replace('Total: ', '')) + envio;
let total_iva = 0.0;
if($('#ivaReducido').val() == '1'){
total_iva = total * 1.04;
let total_id = "tot_tiradaPrecio" + i;
let total = parseFloat($('#' + total_id).text().replace('€', '').replace('Total: ', '')) + envio;
let total_iva = 0.0;
if($('#ivaReducido').val() == '1'){
total_iva = total * 1.04;
}
else{
total_iva = total * 1.21;
}
const precio_u = total_iva/tirada;
$('#resumenTotalIVA').text('Total (I.V.A. ' + (($('#ivaReducido').val() == '1')?'4':'21') + '%): ' + total_iva.toFixed(2) + '€');
$('#resumenPrecioU').text(precio_u.toFixed(4) + '€/ud');
}
else{
total_iva = total * 1.21;
}
const precio_u = total_iva/tirada;
$('#resumenTotalIVA').text('Total (I.V.A. ' + (($('#ivaReducido').val() == '1')?'4':'21') + '%): ' + total_iva.toFixed(2) + '€');
$('#resumenPrecioU').text(precio_u.toFixed(4) + '€/ud');
}
}
else{
let iva = 1.04;
if(window.iva_reducido == 0){
iva = 1.21;
}
let total = window.total*iva;
let p_unidad = total/window.tirada;
$('#resumenTotalIVA').text('Total (I.V.A. ' + (total.toFixed(2)) + '€');
$('#resumenPrecioU').text(p_unidad.toFixed(4) + '€/ud');
}
}
@ -139,6 +151,13 @@ $('#btnBack').on('click', function() {
});
function finalizarPresupuesto(confirmar){
const paths = window.location.pathname.split("/").filter(path => path !== "");
let id=0;
if(paths.length > 0 && paths[paths.length - 2] == 'edit'){
id=paths[paths.length - 1];
}
let servicios = [];
$('.servicio-extra:checked').each(function () {
servicios.push($(this).attr('serv_id'));
@ -185,7 +204,7 @@ function finalizarPresupuesto(confirmar){
}
}
if ($('#divGuardas').is(':visible')) {
if ($('#divGuardas').css('display') != 'none') {
datos_libro.guardas = {
papel: $('#papelGuardas option:selected').val(),
papel_nombre: $('#papelGuardas option:selected').text().trim(),
@ -215,6 +234,7 @@ function finalizarPresupuesto(confirmar){
let direcciones = getDireccionesEnvio();
datos = {
id: id,
datos_libro : datos_libro,
datos_cabecera: datos_cabecera,
direcciones: direcciones,

View File

@ -19,8 +19,12 @@
<!-- Create Deal Wizard -->
<div id="wizard-presupuesto-cliente" class="bs-stepper vertical mt-2 linear">
<div class="bs-stepper-header">
<?php if($presupuestoEntity->estado_id==1): ?>
<div class="step active" data-target="#tipo-libro">
<?php else: ?>
<div class="step" data-target="#tipo-libro">
<?php endif; ?>
<button type="button" class="step-trigger" aria-selected="false" disabled="disabled">
<span class="bs-stepper-circle"><i class="ti ti-book ti-sm"></i></span>
<span class="bs-stepper-label">
@ -53,7 +57,12 @@
</div>
<div class="line"></div>
<?php if($presupuestoEntity->estado_id==1): ?>
<div class="step" data-target="#resumen-libro">
<?php else: ?>
<div class="step active" data-target="#resumen-libro">
<?php endif; ?>
<button type="button" class="step-trigger" aria-selected="false" disabled="disabled">
<span class="bs-stepper-circle"><i class="ti ti-checkbox ti-sm"></i></span>
<span class="bs-stepper-label">
@ -80,7 +89,12 @@
<!-- Tipo Libro -->
<?php if($presupuestoEntity->estado_id==1): ?>
<div id="tipo-libro" class="content active dstepper-block fv-plugins-bootstrap5 fv-plugins-framework">
<?php else: ?>
<div id="tipo-libro" class="content dstepper-block fv-plugins-bootstrap5 fv-plugins-framework">
<?php endif; ?>
<div class="row g-3">
<?= view("themes/vuexy/form/presupuestos/cliente/_tipoLibroItems") ?>
@ -135,9 +149,14 @@
</div>
</div>
</div>
<!-- Review & Complete -->
<?php if($presupuestoEntity->estado_id==1): ?>
<div id="resumen-libro" class="content fv-plugins-bootstrap5 fv-plugins-framework">
<?php else: ?>
<div id="resumen-libro" class="content active fv-plugins-bootstrap5 fv-plugins-framework">
<?php endif; ?>
<div class="row g-3">
<?= view("themes/vuexy/form/presupuestos/cliente/_resumenItems") ?>
@ -145,10 +164,12 @@
</div>
<div class="col-12 d-flex justify-content-between mt-4">
<div class="col-6 d-flex flex-row">
<?php if ($presupuestoEntity->estado_id == 1) : ?>
<button class="btn btn-primary btn-prev waves-effect waves-light">
<i class="ti ti-arrow-left ti-xs me-sm-1 me-0"></i>
<span class="align-middle d-sm-inline-block d-none me-sm-1">Anterior</span>
</button>
<?php endif; ?>
</div>
<div class="col-6 d-flex flex-row-reverse">
<?php if ($presupuestoEntity->estado_id == 1) : ?>

38513
xdebug.log

File diff suppressed because one or more lines are too long