private function nuevo_servicio_cliente() { $continuar = TRUE; $cliente = $this->cliente->get($_POST['cliente']); $almacen = $this->almacen->get($_POST['almacen']); $eje0 = new ejercicio(); $ejercicio = $eje0->get_by_fecha($_POST['fecha']); $serie = $this->serie->get($_POST['serie']); if (!$serie) { $this->new_error_msg('Serie no encontrada.'); $continuar = FALSE; } $forma_pago = $this->forma_pago->get($_POST['forma_pago']); if ($forma_pago) { $this->save_codpago($forma_pago->codpago); } else { $this->new_error_msg('Forma de pago no encontrada.'); $continuar = FALSE; } $divisa = $this->divisa->get($_POST['divisa']); $servicio = new servicio_cliente(); if ($this->duplicated_petition($_POST['petition_id'])) { $this->new_error_msg('Petición duplicada. Has hecho doble clic sobre el botón guardar y se han enviado dos peticiones. Mira en <a href="' . $servicio->url() . '">Servicios</a> para ver si el servicio se ha guardado correctamente.'); $continuar = FALSE; } if ($continuar) { $servicio->fecha = $_POST['fecha']; $servicio->codalmacen = $almacen->codalmacen; $servicio->codejercicio = $ejercicio->codejercicio; $servicio->codserie = $serie->codserie; $servicio->codpago = $forma_pago->codpago; $servicio->coddivisa = $divisa->coddivisa; $servicio->tasaconv = $divisa->tasaconv; if ($_POST['tasaconv'] != '') { $servicio->tasaconv = floatval($_POST['tasaconv']); } $servicio->codagente = $this->agente->codagente; $servicio->observaciones = $_POST['observaciones']; if (isset($_POST['numero2'])) { $servicio->numero2 = $_POST['numero2']; } $servicio->porcomision = $this->agente->porcomision; $servicio->codcliente = $cliente->codcliente; $servicio->cifnif = $cliente->cifnif; $servicio->nombrecliente = $cliente->razonsocial; $servicio->ciudad = $_POST['ciudad']; $servicio->codpais = $_POST['codpais']; $servicio->codpostal = $_POST['codpostal']; $servicio->direccion = $_POST['direccion']; $servicio->provincia = $_POST['provincia']; $servicio->prioridad = intval($_POST['prioridad']); $servicio->idestado = $_POST['estado']; if (isset($_POST['material'])) { $servicio->material = $_POST['material']; } if (isset($_POST['material_estado'])) { $servicio->material_estado = $_POST['material_estado']; } if (isset($_POST['accesorios'])) { $servicio->accesorios = $_POST['accesorios']; } if (isset($_POST['descripcion'])) { $servicio->descripcion = $_POST['descripcion']; } if (isset($_POST['solucion'])) { $servicio->solucion = $_POST['solucion']; } $servicio->fechainicio = Date('d-m-Y H:i'); if (isset($_POST['fechainicio'])) { $servicio->fechainicio = $_POST['fechainicio']; } if (isset($_POST['fechafin'])) { $servicio->fechafin = $_POST['fechafin']; } else { $servicio->fechafin = date('Y-m-d H:i', strtotime($servicio->fechainicio . '+ ' . $this->setup['cal_intervalo'] . 'minutes')); } if (isset($_POST['garantia'])) { $servicio->garantia = $_POST['garantia']; } if ($servicio->save()) { $art0 = new articulo(); $n = floatval($_POST['numlineas']); for ($i = 0; $i <= $n; $i++) { if (isset($_POST['referencia_' . $i])) { $linea = new linea_servicio_cliente(); $linea->idservicio = $servicio->idservicio; $linea->descripcion = $_POST['desc_' . $i]; if (!$serie->siniva and $cliente->regimeniva != 'Exento') { $imp0 = $this->impuesto->get_by_iva($_POST['iva_' . $i]); if ($imp0) { $linea->codimpuesto = $imp0->codimpuesto; $linea->iva = floatval($_POST['iva_' . $i]); $linea->recargo = floatval($_POST['recargo_' . $i]); } else { $linea->iva = floatval($_POST['iva_' . $i]); $linea->recargo = floatval($_POST['recargo_' . $i]); } } $linea->irpf = floatval($_POST['irpf_' . $i]); $linea->pvpunitario = floatval($_POST['pvp_' . $i]); $linea->cantidad = floatval($_POST['cantidad_' . $i]); $linea->dtopor = floatval($_POST['dto_' . $i]); $linea->pvpsindto = $linea->pvpunitario * $linea->cantidad; $linea->pvptotal = floatval($_POST['neto_' . $i]); $articulo = $art0->get($_POST['referencia_' . $i]); if ($articulo) { $linea->referencia = $articulo->referencia; } if ($linea->save()) { $servicio->neto += $linea->pvptotal; $servicio->totaliva += $linea->pvptotal * $linea->iva / 100; $servicio->totalirpf += $linea->pvptotal * $linea->irpf / 100; $servicio->totalrecargo += $linea->pvptotal * $linea->recargo / 100; if ($linea->irpf > $servicio->irpf) { $servicio->irpf = $linea->irpf; } } else { $this->new_error_msg("¡Imposible guardar la linea con referencia: " . $linea->referencia); $continuar = FALSE; } } } if ($continuar) { /// redondeamos $servicio->neto = round($servicio->neto, FS_NF0); $servicio->totaliva = round($servicio->totaliva, FS_NF0); $servicio->totalirpf = round($servicio->totalirpf, FS_NF0); $servicio->totalrecargo = round($servicio->totalrecargo, FS_NF0); $servicio->total = $servicio->neto + $servicio->totaliva - $servicio->totalirpf + $servicio->totalrecargo; if (abs(floatval($_POST['atotal']) - $servicio->total) >= 0.02) { $this->new_error_msg("El total difiere entre el controlador y la vista (" . $servicio->total . " frente a " . $_POST['atotal'] . "). Debes informar del error."); $servicio->delete(); } else { if ($servicio->save()) { $this->new_message("<a href='" . $servicio->url() . "'>" . ucfirst(FS_SERVICIO) . "</a> guardado correctamente."); $this->new_change(ucfirst(FS_SERVICIO) . " a Cliente " . $servicio->codigo, $servicio->url(), TRUE); header('Location: ' . $servicio->url()); } else { $this->new_error_msg("¡Imposible actualizar el <a href='" . $servicio->url() . "'>" . FS_SERVICIO . "</a>!"); } } } else { if ($servicio->delete()) { $this->new_message(ucfirst(FS_SERVICIO) . " eliminado correctamente."); } else { $this->new_error_msg("¡Imposible eliminar el <a href='" . $servicio->url() . "'>" . FS_SERVICIO . "</a>!"); } } } else { $this->new_error_msg("¡Imposible guardar el " . FS_SERVICIO . "!"); } } }
private function minicron() { $this->template = FALSE; $contrato = new contrato_servicio(); $eje0 = new ejercicio(); $estado = new estado_servicio(); $idestado = NULL; foreach ($estado->all() as $est) { $idestado = $est->id; break; } $offset = 0; $contratos = $contrato->all($offset, 'fsiguiente_servicio ASC'); while ($contratos) { foreach ($contratos as $con) { if ($con->fsiguiente_servicio) { if (strtotime($con->fsiguiente_servicio) > strtotime($con->fecha_renovacion)) { /// caducado } else { if (strtotime($con->fsiguiente_servicio) < strtotime('+1month')) { $cliente = $this->cliente->get($con->codcliente); if ($cliente) { $ejercicio = $eje0->get_by_fecha($con->fsiguiente_servicio); if ($ejercicio) { $servicio = new servicio_cliente(); $servicio->codcliente = $cliente->codcliente; $servicio->cifnif = $cliente->cifnif; $servicio->nombrecliente = $cliente->razonsocial; $servicio->codagente = $con->codagente; $servicio->coddivisa = $this->empresa->coddivisa; $servicio->codejercicio = $ejercicio->codejercicio; $servicio->codpago = $con->codpago; $servicio->codserie = $cliente->codserie; $servicio->fecha = $con->fsiguiente_servicio; $servicio->fechainicio = $con->fsiguiente_servicio . ' ' . $this->nuevocli_setup['cal_inicio']; $servicio->idestado = $idestado; foreach ($cliente->get_direcciones() as $dir) { if ($dir->domfacturacion) { $servicio->direccion = $dir->direccion; $servicio->codpostal = $dir->codpostal; $servicio->ciudad = $dir->ciudad; $servicio->provincia = $dir->provincia; $servicio->codpais = $dir->codpais; break; } } if ($servicio->save()) { $con->fsiguiente_servicio = NULL; if ($con->periodo) { $con->fsiguiente_servicio = date('d-m-Y', strtotime($servicio->fechainicio . ' ' . $con->periodo)); } $con->save(); } else { echo "Error al crear el servicio.\n"; foreach ($this->get_errors() as $err) { echo $err . "\n"; } } } } } else { echo "Cliente no encontrado.\n"; } } } $offset++; } $contratos = $contrato->all($offset, 'fsiguiente_servicio ASC'); } }
private function importar_sat() { $this->registro_sat = new registro_sat(); $this->detalle_sat = new detalle_sat(); $this->cliente = new cliente(); $importados = 0; $importados_det = 0; $data = $this->db->select("SELECT * FROM registros_sat;"); if ($data) { foreach ($data as $d) { $servicio = $this->registro_sat->get($d['nsat']); if ($servicio) { $servicio = new servicio_cliente(); $servicio->numero2 = "SAT_" . $d['nsat']; $servicio->fecha = $d['fentrada']; if (isset($d['fcomienzo'])) { $servicio->fechainicio = Date('d-m-Y H:i', strtotime($d['fcomienzo'])); } if (isset($d['ffin'])) { $servicio->fechafin = Date('d-m-Y H:i', strtotime($d['ffin'])); } //obtenemos ejercicio $eje0 = new ejercicio(); $ejercicio = $eje0->get_by_fecha($d['fentrada']); $servicio->codejercicio = $ejercicio->codejercicio; $servicio->material = $d['modelo']; $servicio->descripcion = $d['averia']; $servicio->accesorios = $d['accesorios']; $servicio->codcliente = $d['codcliente']; $servicio->observaciones = $d['observaciones']; $servicio->codagente = $d['codagente']; $servicio->idestado = '1'; $servicio->prioridad = $d['prioridad']; //obtenemos cliente $cliente0 = new cliente(); $cliente = $cliente0->get($d['codcliente']); $servicio->nombrecliente = $cliente->nombre; $servicio->codserie = $this->empresa->codserie; $servicio->codpago = $this->empresa->codpago; if ($servicio->save()) { $importados++; } //Importamos Detalles: $data2 = $this->db->select("SELECT * FROM detalles_sat WHERE nsat=" . $d['nsat'] . ";"); if ($data2) { foreach ($data2 as $d2) { $detalle = $this->detalle_sat->get($d2['id']); if ($detalle) { $detalle = new detalle_servicio(); $detalle->idservicio = $servicio->idservicio; $detalle->descripcion = $d2['descripcion']; $detalle->fecha = $d2['fecha']; if ($detalle->save()) { $importados_det++; } } } } } } } $this->new_message($importados . ' registros SAT importados.'); $this->new_message($importados_det . ' detalles SAT importados.'); $this->avisosat = '2'; }