Exemple #1
0
 protected function private_core()
 {
     /// ¿El usuario tiene permiso para eliminar en esta página?
     $this->allow_delete = $this->user->allow_delete_on(__CLASS__);
     $this->share_extensions();
     $this->estado = new estado_sat();
     /// leemos la API key de google maps de la base de datos o del formulario
     $fsvar = new fs_var();
     if (isset($_POST['maps_api_key'])) {
         $this->maps_api_key = $_POST['maps_api_key'];
         $fsvar->simple_save('maps_api_key', $this->maps_api_key);
     } else {
         $this->maps_api_key = $fsvar->simple_get('maps_api_key');
     }
     /// cargamos la configuración
     $this->sat_setup = $fsvar->array_get(array('sat_col_modelo' => 0, 'sat_col_posicion' => 0, 'sat_col_accesorios' => 0, 'sat_col_prioridad' => 0, 'sat_col_fecha' => 1, 'sat_col_fechaini' => 0, 'sat_col_fechafin' => 0), FALSE);
     if (isset($_POST['sat_setup'])) {
         $this->sat_setup['sat_col_modelo'] = isset($_POST['col_modelo']) ? 1 : 0;
         $this->sat_setup['sat_col_posicion'] = isset($_POST['col_posicion']) ? 1 : 0;
         $this->sat_setup['sat_col_accesorios'] = isset($_POST['col_accesorios']) ? 1 : 0;
         $this->sat_setup['sat_col_prioridad'] = isset($_POST['col_prioridad']) ? 1 : 0;
         $this->sat_setup['sat_col_fecha'] = isset($_POST['col_fecha']) ? 1 : 0;
         $this->sat_setup['sat_col_fechaini'] = isset($_POST['col_fechaini']) ? 1 : 0;
         $this->sat_setup['sat_col_fechafin'] = isset($_POST['col_fechafin']) ? 1 : 0;
         if ($fsvar->array_save($this->sat_setup)) {
             $this->new_message('Datos guardados correctamente.');
         } else {
             $this->new_error_msg('Error al guardar los datos.');
         }
     } else {
         if (isset($_GET['delete_estado'])) {
             $estado = $this->estado->get($_GET['delete_estado']);
             if ($estado) {
                 if ($estado->delete()) {
                     $this->new_message('Estado eliminado correctamente.');
                 } else {
                     $this->new_error_msg('Error al eliminar el estado.');
                 }
             } else {
                 $this->new_error_msg('Estado no encontrado.');
             }
         } else {
             if (isset($_POST['id_estado'])) {
                 $estado = $this->estado->get($_POST['id_estado']);
                 if (!$estado) {
                     $estado = new estado_sat();
                     $estado->id = intval($_POST['id_estado']);
                 }
                 $estado->descripcion = $_POST['descripcion'];
                 $estado->color = $_POST['color'];
                 $estado->activo = isset($_POST['activo']);
                 if ($estado->save()) {
                     $this->new_message('Estado guardado correctamente.');
                 } else {
                     $this->new_error_msg('Error al guardar el estado.');
                 }
             }
         }
     }
 }
 protected function process()
 {
     $this->show_fs_toolbar = FALSE;
     $this->demo_warnign_showed = FALSE;
     $fsvar = new fs_var();
     $this->first_time = !$fsvar->simple_get('first_time');
     if (isset($_POST['modpages'])) {
         $this->first_time = FALSE;
         $fsvar->simple_save('first_time', '1');
         foreach ($this->all_pages() as $p) {
             if (!$p->exists) {
                 if ($p->delete()) {
                     $this->new_message('Se ha eliminado automáticamente la página ' . $p->name . ' ya que no tiene un controlador asociado en la carpeta controller.');
                 }
             } else {
                 if (!isset($_POST['enabled'])) {
                     $this->disable_page($p);
                 } else {
                     if (!$p->enabled and in_array($p->name, $_POST['enabled'])) {
                         $this->enable_page($p);
                     } else {
                         if ($p->enabled and !in_array($p->name, $_POST['enabled'])) {
                             $this->disable_page($p);
                         }
                     }
                 }
             }
         }
         $this->new_message('Datos guardados correctamente.');
         $this->new_message('Ahora es el momento de <a href="index.php?page=admin_empresa">
         introducir los datos de tu empresa</a>, si todavía no lo has hecho.');
     }
     $this->paginas = $this->all_pages();
     $this->load_menu(TRUE);
 }
 protected function private_core()
 {
     /// ¿El usuario tiene permiso para eliminar en esta página?
     $this->allow_delete = $this->user->allow_delete_on(__CLASS__);
     $eje = new ejercicio();
     $this->ejercicios = $eje->all();
     $this->serie = new serie();
     $fsvar = new fs_var();
     if (isset($_GET['num_personalizada'])) {
         $this->num_personalizada = TRUE;
         $fsvar->simple_save('numeracion_personalizada', $this->num_personalizada);
     } else {
         $this->num_personalizada = $fsvar->simple_get('numeracion_personalizada');
     }
     if (isset($_POST['codserie'])) {
         $serie = $this->serie->get($_POST['codserie']);
         if (!$serie) {
             $serie = new serie();
             $serie->codserie = $_POST['codserie'];
         }
         $serie->descripcion = $_POST['descripcion'];
         $serie->siniva = isset($_POST['siniva']);
         $serie->irpf = floatval($_POST['irpf']);
         if ($this->num_personalizada) {
             $serie->codejercicio = NULL;
             $serie->numfactura = 1;
             if ($_POST['codejercicio'] != '') {
                 $serie->codejercicio = $_POST['codejercicio'];
                 $serie->numfactura = intval($_POST['numfactura']);
             }
         }
         if ($serie->save()) {
             $this->new_message("Serie " . $serie->codserie . " guardada correctamente");
         } else {
             $this->new_error_msg("¡Imposible guardar la serie!");
         }
     } else {
         if (isset($_GET['delete'])) {
             if (!$this->user->admin) {
                 $this->new_error_msg('Sólo un administrador puede eliminar series.');
             } else {
                 $serie = $this->serie->get($_GET['delete']);
                 if ($serie) {
                     if ($serie->delete()) {
                         $this->new_message('Serie eliminada correctamente.');
                     } else {
                         $this->new_error_msg("¡Imposible eliminar la serie!");
                     }
                 } else {
                     $this->new_error_msg("Serie no encontrada.");
                 }
             }
         }
     }
 }
 protected function private_core()
 {
     /// ¿El usuario tiene permiso para eliminar en esta página?
     $this->allow_delete = $this->user->allow_delete_on(__CLASS__);
     $eje = new ejercicio();
     $this->ejercicios = $eje->all();
     $this->serie = new serie();
     $fsvar = new fs_var();
     if (isset($_GET['num_personalizada'])) {
         if ($_GET['num_personalizada'] == 'TRUE') {
             $this->num_personalizada = TRUE;
             $fsvar->simple_save('numeracion_personalizada', $this->num_personalizada);
         } else {
             $this->num_personalizada = FALSE;
             $fsvar->simple_delete('numeracion_personalizada');
         }
     } else {
         $this->num_personalizada = $fsvar->simple_get('numeracion_personalizada');
     }
     if (isset($_POST['codserie'])) {
         $this->modificar_serie();
     } else {
         if (isset($_GET['delete'])) {
             if (!$this->user->admin) {
                 $this->new_error_msg('Sólo un administrador puede eliminar ' . FS_SERIES . '.');
             } else {
                 $serie = $this->serie->get($_GET['delete']);
                 if ($serie) {
                     if ($serie->delete()) {
                         $this->new_message('Datos eliminados correctamente: ' . FS_SERIE . ' ' . $_GET['delete'], TRUE);
                     } else {
                         $this->new_error_msg("¡Imposible eliminar " . FS_SERIE . ' ' . $_GET['delete'] . "!");
                     }
                 } else {
                     $this->new_error_msg('Datos no encontrados: ' . FS_SERIE . ' ' . $_GET['delete']);
                 }
             }
         }
     }
 }
 private function configurar_validez()
 {
     $fsvar = new fs_var();
     if (isset($_POST['setup_validez'])) {
         $this->setup_validez = intval($_POST['setup_validez']);
         $fsvar->simple_save('presu_validez', $this->setup_validez);
         $this->new_message('Configuración modificada correctamente.');
     } else {
         $dias = $fsvar->simple_get('presu_validez');
         if ($dias) {
             $this->setup_validez = intval($dias);
         }
     }
 }
 protected function private_core()
 {
     $almacen = new almacen();
     $this->pais = new pais();
     /// ¿El usuario tiene permiso para eliminar en esta página?
     $this->allow_delete = $this->user->allow_delete_on(__CLASS__);
     if (isset($_POST['scodalmacen'])) {
         $al0 = $almacen->get($_POST['scodalmacen']);
         if (!$al0) {
             $al0 = new almacen();
             $al0->codalmacen = $_POST['scodalmacen'];
         }
         $al0->nombre = $_POST['snombre'];
         $al0->codpais = $_POST['scodpais'];
         $al0->provincia = $_POST['sprovincia'];
         $al0->poblacion = $_POST['spoblacion'];
         $al0->direccion = $_POST['sdireccion'];
         $al0->codpostal = $_POST['scodpostal'];
         $al0->telefono = $_POST['stelefono'];
         $al0->fax = $_POST['sfax'];
         $al0->contacto = $_POST['scontacto'];
         if ($al0->save()) {
             $this->new_message("Almacén " . $al0->codalmacen . " guardado correctamente.");
         } else {
             $this->new_error_msg("¡Imposible guardar el almacén!");
         }
     } else {
         if (isset($_GET['delete'])) {
             $al0 = $almacen->get($_GET['delete']);
             if ($al0) {
                 if (!$this->user->admin) {
                     $this->new_error_msg("Solo un administrador puede eliminar un almacén.");
                 } else {
                     if ($al0->delete()) {
                         $this->new_message("Almacén " . $al0->codalmacen . " eliminado correctamente");
                     } else {
                         $this->new_error_msg("¡Imposible eliminar el almacén!");
                     }
                 }
             } else {
                 $this->new_error_msg("¡Almacén no encontrado!");
             }
         } else {
             /// ¿Guardamos las opciones avanzadas?
             $guardar = FALSE;
             foreach ($GLOBALS['config2'] as $i => $value) {
                 if (isset($_POST[$i])) {
                     $GLOBALS['config2'][$i] = $_POST[$i];
                     $guardar = TRUE;
                 }
             }
             if ($guardar) {
                 $file = fopen('tmp/' . FS_TMP_NAME . 'config2.ini', 'w');
                 if ($file) {
                     foreach ($GLOBALS['config2'] as $i => $value) {
                         if (is_numeric($value)) {
                             fwrite($file, $i . " = " . $value . ";\n");
                         } else {
                             fwrite($file, $i . " = '" . $value . "';\n");
                         }
                     }
                     fclose($file);
                 }
                 $this->new_message('Datos guardados correctamente.');
             }
         }
     }
     $this->almacenes = $almacen->all();
     /// si hay más de un almacén activamos el soporte multi-almacén en los listados
     $fsvar = new fs_var();
     if (count($this->almacenes) > 1) {
         $fsvar->simple_save('multi_almacen', TRUE);
     } else {
         $fsvar->simple_delete('multi_almacen');
     }
 }
 private function get_download_list()
 {
     /**
      * Esta es la lista de plugins fijos, los imprescindibles.
      */
     $this->download_list = array('facturacion_base' => array('url' => 'https://github.com/NeoRazorX/facturacion_base/archive/master.zip', 'url_repo' => 'https://github.com/NeoRazorX/facturacion_base', 'description' => 'Permite la gestión básica de una empresa: gestión de ventas, de compras y contabilidad básica.'), 'argentina' => array('url' => 'https://github.com/FacturaScripts/argentina/archive/master.zip', 'url_repo' => 'https://github.com/FacturaScripts/argentina', 'description' => 'Plugin de adaptación de FacturaScripts a <b>Argentina</b>.'), 'colombia' => array('url' => 'https://github.com/salvaWEBco/colombia/archive/master.zip', 'url_repo' => 'https://github.com/salvaWEBco/colombia', 'description' => 'Plugin de adaptación de FacturaScripts a <b>Colombia</b>.'), 'ecuador' => array('url' => 'https://github.com/FacturaScripts/ecuador/archive/master.zip', 'url_repo' => 'https://github.com/FacturaScripts/ecuador', 'description' => 'Plugin de adaptación de FacturaScripts a <b>Ecuador</b>.'), 'panama' => array('url' => 'https://github.com/NeoRazorX/panama/archive/master.zip', 'url_repo' => 'https://github.com/NeoRazorX/panama', 'description' => 'Plugin de adaptación de FacturaScripts a <b>Panamá</b>.'), 'peru' => array('url' => 'https://github.com/NeoRazorX/peru/archive/master.zip', 'url_repo' => 'https://github.com/NeoRazorX/peru', 'description' => 'Plugin de adaptación de FacturaScripts a <b>Perú</b>.'), 'republica_dominicana' => array('url' => 'https://github.com/joenilson/republica_dominicana/archive/master.zip', 'url_repo' => 'https://github.com/joenilson/republica_dominicana', 'description' => 'Plugin de adaptación de FacturaScripts a <b>República Dominicana</b>.'));
     $fsvar = new fs_var();
     $this->step = $fsvar->simple_get('install_step');
     /**
      * Usamos last_download_check para almacenar la última vez que vimos las descargas.
      * Así podemos saber qué descargas son nuevas.
      */
     $this->last_download_check = $fsvar->simple_get('last_download_check');
     if (!$this->last_download_check) {
         $this->last_download_check = Date('d-m-Y', strtotime('-1week'));
     }
     $this->new_downloads = 0;
     /**
      * Download_list2 es la lista de plugins de la comunidad, se descarga de Internet.
      */
     $this->download_list2 = $this->cache->get('download_list');
     if (!$this->download_list2) {
         $json = @$this->curl_get_contents('https://www.facturascripts.com/comm3/index.php?page=community_plugins&json=TRUE', 5);
         if ($json) {
             $this->download_list2 = json_decode($json);
             $this->cache->set('download_list', $this->download_list2);
         } else {
             $this->new_error_msg('Error al descargar la lista de plugins.');
             $this->download_list2 = array();
         }
     }
     foreach ($this->download_list2 as $i => $di) {
         $this->download_list2[$i]->nuevo = FALSE;
         if (strtotime($di->creado) > strtotime($this->last_download_check)) {
             $this->new_downloads++;
             $this->download_list2[$i]->nuevo = TRUE;
         }
     }
     /// ahora nos guardamos last_download_check
     $this->last_download_check = Date('d-m-Y', strtotime('-1week'));
     $fsvar->simple_save('last_download_check', $this->last_download_check);
 }
 /**
  * Descarga un plugin de la lista de plugins fijos.
  */
 private function download1()
 {
     if (isset($this->download_list[$_GET['download']])) {
         $this->new_message('Descargando el plugin ' . $_GET['download']);
         if (@file_put_contents('download.zip', $this->curl_get_contents($this->download_list[$_GET['download']]['url']))) {
             $zip = new ZipArchive();
             $res = $zip->open('download.zip', ZipArchive::CHECKCONS);
             if ($res === TRUE) {
                 $plugins_list = scandir(getcwd() . '/plugins');
                 $zip->extractTo('plugins/');
                 $zip->close();
                 unlink('download.zip');
                 /// renombramos si es necesario
                 foreach (scandir(getcwd() . '/plugins') as $f) {
                     if (is_dir('plugins/' . $f) and $f != '.' and $f != '..') {
                         $encontrado2 = FALSE;
                         foreach ($plugins_list as $f2) {
                             if ($f == $f2) {
                                 $encontrado2 = TRUE;
                                 break;
                             }
                         }
                         if (!$encontrado2) {
                             rename('plugins/' . $f, 'plugins/' . $_GET['download']);
                             break;
                         }
                     }
                 }
                 $this->new_message('Plugin añadido correctamente.');
                 $this->enable_plugin($_GET['download']);
                 if ($this->step == '1') {
                     $this->step = '2';
                     $fsvar = new fs_var();
                     $fsvar->simple_save('install_step', $this->step);
                 }
             } else {
                 $this->new_error_msg('Error al abrir el ZIP. Código: ' . $res);
             }
         } else {
             $this->new_error_msg('Error al descargar. Tendrás que descargarlo manualmente desde ' . '<a href="' . $this->download_list[$_GET['download']]['url'] . '" target="_blank">aquí</a> ' . 'y añadirlo desde la pestaña <b>plugins</b>.');
         }
     } else {
         $this->new_error_msg('Descarga no encontrada.');
     }
 }
 private function download1()
 {
     if (isset($this->download_list[$_GET['download']])) {
         $this->new_message('Descargando el plugin ' . $_GET['download']);
         if (@file_put_contents('download.zip', $this->curl_get_contents($this->download_list[$_GET['download']]['url']))) {
             $zip = new ZipArchive();
             $res = $zip->open('download.zip');
             if ($res === TRUE) {
                 $zip->extractTo('plugins/');
                 $zip->close();
                 unlink('download.zip');
                 /// renombramos el directorio
                 if (file_exists('plugins/' . $_GET['download'] . '-master')) {
                     rename('plugins/' . $_GET['download'] . '-master', 'plugins/' . $_GET['download']);
                 }
                 $this->new_message('Plugin añadido correctamente.');
                 $this->enable_plugin($_GET['download']);
                 if ($this->step == '1') {
                     $this->step = '2';
                     $fsvar = new fs_var();
                     $fsvar->simple_save('install_step', $this->step);
                 }
             } else {
                 $this->new_error_msg('Error al abrir el ZIP. Código: ' . $res);
             }
         } else {
             $this->new_error_msg('Error al descargar. Tendrás que descargarlo manualmente desde ' . '<a href="' . $this->download_list[$_GET['download']]['url'] . '" target="_blank">aquí</a> ' . 'y añadirlo desde la pestaña <b>plugins</b>.');
         }
     } else {
         $this->new_error_msg('Descarga no encontrada.');
     }
 }
 protected function private_core()
 {
     $this->almacen = new almacen();
     $this->cuenta_banco = new cuenta_banco();
     $this->divisa = new divisa();
     $this->ejercicio = new ejercicio();
     $this->forma_pago = new forma_pago();
     $this->serie = new serie();
     $this->pais = new pais();
     $fsvar = new fs_var();
     /// obtenemos los datos de configuración del email
     $this->mail = array('mail_host' => 'smtp.gmail.com', 'mail_port' => '465', 'mail_enc' => 'ssl', 'mail_user' => '', 'mail_low_security' => FALSE);
     $this->mail = $fsvar->array_get($this->mail, FALSE);
     /// obtenemos los datos de configuración de impresión
     $this->impresion = array('print_ref' => '1', 'print_dto' => '1', 'print_alb' => '0', 'print_formapago' => '1');
     $this->impresion = $fsvar->array_get($this->impresion, FALSE);
     if (isset($_POST['cifnif'])) {
         /// guardamos los datos de la empresa
         $this->empresa->nombre = $_POST['nombre'];
         $this->empresa->nombrecorto = $_POST['nombrecorto'];
         $this->empresa->cifnif = $_POST['cifnif'];
         $this->empresa->administrador = $_POST['administrador'];
         $this->empresa->codpais = $_POST['codpais'];
         $this->empresa->provincia = $_POST['provincia'];
         $this->empresa->ciudad = $_POST['ciudad'];
         $this->empresa->direccion = $_POST['direccion'];
         $this->empresa->codpostal = $_POST['codpostal'];
         $this->empresa->telefono = $_POST['telefono'];
         $this->empresa->fax = $_POST['fax'];
         $this->empresa->web = $_POST['web'];
         $this->empresa->email = $_POST['email'];
         $this->empresa->email_firma = $_POST['email_firma'];
         $this->empresa->email_password = $_POST['email_password'];
         $this->empresa->lema = $_POST['lema'];
         $this->empresa->horario = $_POST['horario'];
         $this->empresa->contintegrada = isset($_POST['contintegrada']);
         $this->empresa->codejercicio = $_POST['codejercicio'];
         $this->empresa->codserie = $_POST['codserie'];
         $this->empresa->coddivisa = $_POST['coddivisa'];
         $this->empresa->codpago = $_POST['codpago'];
         $this->empresa->codalmacen = $_POST['codalmacen'];
         $this->empresa->pie_factura = $_POST['pie_factura'];
         $this->empresa->recequivalencia = isset($_POST['recequivalencia']);
         if ($this->empresa->save()) {
             /// guardamos las opciones por defecto de almacén y forma de pago
             $this->save_codalmacen($_POST['codalmacen']);
             $this->save_codpago($_POST['codpago']);
             $this->new_message('Datos guardados correctamente.');
             if (!$this->empresa->contintegrada) {
                 $this->new_message('¿Quieres activar la <b>contabilidad integrada</b>?' . ' Haz clic en la sección <a href="#facturacion">facturación</a>.');
             }
             $step = $fsvar->simple_get('install_step');
             if ($step == 2) {
                 $step = 3;
                 $fsvar->simple_save('install_step', $step);
             }
             if ($step == 3 and $this->empresa->contintegrada) {
                 $this->new_message('Recuerda que tienes que <a href="index.php?page=contabilidad_ejercicio&cod=' . $this->empresa->codejercicio . '">importar los datos del ejercicio</a>.');
             }
         } else {
             $this->new_error_msg('Error al guardar los datos.');
         }
         /// guardamos los datos del email
         if (isset($_POST['mail_host'])) {
             $this->mail['mail_host'] = 'smtp.gmail.com';
             if ($_POST['mail_host'] != '') {
                 $this->mail['mail_host'] = $_POST['mail_host'];
             }
             $this->mail['mail_port'] = '465';
             if ($_POST['mail_port'] != '') {
                 $this->mail['mail_port'] = $_POST['mail_port'];
             }
             $this->mail['mail_enc'] = strtolower($_POST['mail_enc']);
             $this->mail['mail_user'] = $_POST['mail_user'];
             $this->mail['mail_low_security'] = isset($_POST['mail_low_security']);
             $fsvar->array_save($this->mail);
             $this->mail_test();
         }
         /// guardamos los datos de impresión
         $this->impresion['print_ref'] = isset($_POST['print_ref']) ? 1 : 0;
         $this->impresion['print_dto'] = isset($_POST['print_dto']) ? 1 : 0;
         $this->impresion['print_alb'] = isset($_POST['print_alb']) ? 1 : 0;
         $this->impresion['print_formapago'] = isset($_POST['print_formapago']) ? 1 : 0;
         $fsvar->array_save($this->impresion);
     } else {
         if (isset($_POST['nombre'])) {
             /// guardamos solamente lo básico, ya que facturacion_base no está activado
             $this->empresa->nombre = $_POST['nombre'];
             $this->empresa->nombrecorto = $_POST['nombrecorto'];
             $this->empresa->web = $_POST['web'];
             $this->empresa->email = $_POST['email'];
             $this->empresa->email_firma = $_POST['email_firma'];
             $this->empresa->email_password = $_POST['email_password'];
             if ($this->empresa->save()) {
                 $this->new_message('Datos guardados correctamente.');
             } else {
                 $this->new_error_msg('Error al guardar los datos.');
             }
             /// guardamos los datos del email
             if (isset($_POST['mail_host'])) {
                 $this->mail['mail_host'] = 'smtp.gmail.com';
                 if ($_POST['mail_host'] != '') {
                     $this->mail['mail_host'] = $_POST['mail_host'];
                 }
                 $this->mail['mail_port'] = '465';
                 if ($_POST['mail_port'] != '') {
                     $this->mail['mail_port'] = $_POST['mail_port'];
                 }
                 $this->mail['mail_enc'] = strtolower($_POST['mail_enc']);
                 $this->mail['mail_user'] = $_POST['mail_user'];
                 $this->mail['mail_low_security'] = isset($_POST['mail_low_security']);
                 $fsvar->array_save($this->mail);
                 $this->mail_test();
             }
         } else {
             if (isset($_POST['logo'])) {
                 if (is_uploaded_file($_FILES['fimagen']['tmp_name'])) {
                     $this->delete_logo();
                     if (substr(strtolower($_FILES['fimagen']['name']), -3) == 'png') {
                         copy($_FILES['fimagen']['tmp_name'], "tmp/" . FS_TMP_NAME . "logo.png");
                     } else {
                         copy($_FILES['fimagen']['tmp_name'], "tmp/" . FS_TMP_NAME . "logo.jpg");
                     }
                     $this->new_message('Logotipo guardado correctamente.');
                 }
             } else {
                 if (isset($_GET['delete_logo'])) {
                     $this->delete_logo();
                 } else {
                     if (isset($_GET['delete_cuenta'])) {
                         $cuenta = $this->cuenta_banco->get($_GET['delete_cuenta']);
                         if ($cuenta) {
                             if ($cuenta->delete()) {
                                 $this->new_message('Cuenta bancaria eliminada correctamente.');
                             } else {
                                 $this->new_error_msg('Imposible eliminar la cuenta bancaria.');
                             }
                         } else {
                             $this->new_error_msg('Cuenta bancaria no encontrada.');
                         }
                     } else {
                         if (isset($_POST['iban'])) {
                             if (isset($_POST['codcuenta'])) {
                                 $cuentab = $this->cuenta_banco->get($_POST['codcuenta']);
                             } else {
                                 $cuentab = new cuenta_banco();
                             }
                             $cuentab->descripcion = $_POST['descripcion'];
                             $cuentab->iban = $_POST['iban'];
                             $cuentab->swift = $_POST['swift'];
                             if (isset($_POST['codsubcuenta'])) {
                                 $cuentab->codsubcuenta = $_POST['codsubcuenta'];
                             }
                             if ($cuentab->save()) {
                                 $this->new_message('Cuenta bancaria guardada correctamente.');
                             } else {
                                 $this->new_error_msg('Imposible guardar la cuenta bancaria.');
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->facturacion_base = in_array('facturacion_base', $GLOBALS['plugins']);
     $this->logo = FALSE;
     if (file_exists('tmp/' . FS_TMP_NAME . 'logo.png')) {
         $this->logo = 'tmp/' . FS_TMP_NAME . 'logo.png';
     } else {
         if (file_exists('tmp/' . FS_TMP_NAME . 'logo.jpg')) {
             $this->logo = 'tmp/' . FS_TMP_NAME . 'logo.jpg';
         }
     }
 }
Exemple #11
0
 protected function private_core()
 {
     $this->check_menu();
     $this->almacen = new almacen();
     $this->divisa = new divisa();
     $this->ejercicio = new ejercicio();
     $this->forma_pago = new forma_pago();
     $this->pais = new pais();
     $this->serie = new serie();
     $fsvar = new fs_var();
     $this->step = $fsvar->simple_get('install_step');
     if ($this->step < 2 or isset($_GET['restart'])) {
         $this->step = 2;
     }
     if (FS_DEMO) {
         $this->new_advice('En el modo demo no se pueden hacer cambios en esta página.');
         $this->new_advice('Si te gusta FacturaScripts y quieres saber más, consulta la ' . '<a href="https://www.facturascripts.com/comm3/index.php?page=community_questions">sección preguntas</a>.');
     } else {
         if (isset($_POST['nombrecorto'])) {
             /// guardamos los datos de la empresa
             $this->empresa->nombre = $_POST['nombre'];
             $this->empresa->nombrecorto = $_POST['nombrecorto'];
             $this->empresa->cifnif = $_POST['cifnif'];
             $this->empresa->administrador = $_POST['administrador'];
             $this->empresa->codpais = $_POST['codpais'];
             $this->empresa->provincia = $_POST['provincia'];
             $this->empresa->ciudad = $_POST['ciudad'];
             $this->empresa->direccion = $_POST['direccion'];
             $this->empresa->codpostal = $_POST['codpostal'];
             $this->empresa->telefono = $_POST['telefono'];
             $this->empresa->fax = $_POST['fax'];
             $this->empresa->web = $_POST['web'];
             if ($this->empresa->save()) {
                 $this->new_message('Datos guardados correctamente.');
                 /// avanzamos el asistente
                 $this->step = 3;
                 if ($this->empresa->codpais == 'ESP' or $this->empresa->codpais == 'ES') {
                     /// si es España nos podemos ahorrar un paso
                     $this->empresa->coddivisa = 'EUR';
                     $this->empresa->save();
                     $this->step = 4;
                 }
                 $fsvar->simple_save('install_step', $this->step);
             } else {
                 $this->new_error_msg('Error al guardar los datos.');
             }
         } else {
             if (isset($_POST['coddivisa'])) {
                 $this->empresa->coddivisa = $_POST['coddivisa'];
                 if ($this->empresa->save()) {
                     foreach ($GLOBALS['config2'] as $i => $value) {
                         if (isset($_POST[$i])) {
                             $GLOBALS['config2'][$i] = $_POST[$i];
                         }
                     }
                     $file = fopen('tmp/' . FS_TMP_NAME . 'config2.ini', 'w');
                     if ($file) {
                         foreach ($GLOBALS['config2'] as $i => $value) {
                             if (is_numeric($value)) {
                                 fwrite($file, $i . " = " . $value . ";\n");
                             } else {
                                 fwrite($file, $i . " = '" . $value . "';\n");
                             }
                         }
                         fclose($file);
                     }
                     $this->new_message('Datos guardados correctamente.');
                     /// avanzamos el asistente
                     $this->step = 4;
                     $fsvar->simple_save('install_step', $this->step);
                 } else {
                     $this->new_error_msg('Error al guardar los datos.');
                 }
             } else {
                 if (isset($_POST['codejercicio'])) {
                     $this->empresa->contintegrada = isset($_POST['contintegrada']);
                     $this->empresa->codejercicio = $_POST['codejercicio'];
                     $this->empresa->codserie = $_POST['codserie'];
                     $this->empresa->codpago = $_POST['codpago'];
                     $this->empresa->codalmacen = $_POST['codalmacen'];
                     $this->empresa->recequivalencia = isset($_POST['recequivalencia']);
                     if ($this->empresa->save()) {
                         foreach ($GLOBALS['config2'] as $i => $value) {
                             if (isset($_POST[$i])) {
                                 $GLOBALS['config2'][$i] = $_POST[$i];
                             }
                         }
                         $file = fopen('tmp/' . FS_TMP_NAME . 'config2.ini', 'w');
                         if ($file) {
                             foreach ($GLOBALS['config2'] as $i => $value) {
                                 if (is_numeric($value)) {
                                     fwrite($file, $i . " = " . $value . ";\n");
                                 } else {
                                     fwrite($file, $i . " = '" . $value . "';\n");
                                 }
                             }
                             fclose($file);
                         }
                         $this->new_message('Datos guardados correctamente.');
                         /// avanzamos el asistente
                         $this->step = 5;
                         $fsvar->simple_save('install_step', $this->step);
                     } else {
                         $this->new_error_msg('Error al guardar los datos.');
                     }
                 }
             }
         }
     }
 }
 /**
  * Devuelve el total de pedidos de Woocommerce.
  * Como las consultas a la API son lentas, se almacena el resultado en la
  * base de datos y se consulta a la API de vez en cuando.
  * @return type
  */
 private function get_total_pedidos()
 {
     $fsvar = new fs_var();
     $aux = $fsvar->simple_get('wooc_total_pedidos');
     if ($aux and mt_rand(0, 9) != 0) {
         return intval($aux);
     } else {
         $total = 0;
         $data = $this->wcapi->get_orders_count();
         if (isset($data->count)) {
             $this->conectado = TRUE;
             $total = intval($data->count);
             $fsvar->simple_save('wooc_total_pedidos', $total);
         }
         return $total;
     }
 }
 protected function process()
 {
     $this->almacen = new almacen();
     $this->cuenta_banco = new cuenta_banco();
     $this->divisa = new divisa();
     $this->ejercicio = new ejercicio();
     $this->forma_pago = new forma_pago();
     $this->serie = new serie();
     $this->pais = new pais();
     /// obtenemos los datos de configuración del email
     $this->mail = array('mail_host' => 'smtp.gmail.com', 'mail_port' => '465', 'mail_enc' => 'ssl', 'mail_user' => '');
     $fsvar = new fs_var();
     $this->mail = $fsvar->array_get($this->mail, FALSE);
     if (isset($_POST['nombre'])) {
         /*
          * Guardamos los elementos por defecto
          */
         $this->save_codalmacen($_POST['codalmacen']);
         $this->save_coddivisa($_POST['coddivisa']);
         $this->save_codejercicio($_POST['codejercicio']);
         $this->save_codpago($_POST['codpago']);
         $this->save_codserie($_POST['codserie']);
         $this->save_codpais($_POST['codpais']);
         /// guardamos los datos de la empresa
         $this->empresa->nombre = $_POST['nombre'];
         $this->empresa->nombrecorto = $_POST['nombrecorto'];
         $this->empresa->cifnif = $_POST['cifnif'];
         $this->empresa->administrador = $_POST['administrador'];
         $this->empresa->codpais = $_POST['codpais'];
         $this->empresa->provincia = $_POST['provincia'];
         $this->empresa->ciudad = $_POST['ciudad'];
         $this->empresa->direccion = $_POST['direccion'];
         $this->empresa->codpostal = $_POST['codpostal'];
         $this->empresa->telefono = $_POST['telefono'];
         $this->empresa->fax = $_POST['fax'];
         $this->empresa->web = $_POST['web'];
         $this->empresa->email = $_POST['email'];
         $this->empresa->email_firma = $_POST['email_firma'];
         $this->empresa->email_password = $_POST['email_password'];
         $this->empresa->lema = $_POST['lema'];
         $this->empresa->horario = $_POST['horario'];
         $this->empresa->contintegrada = isset($_POST['contintegrada']);
         $this->empresa->codejercicio = $_POST['codejercicio'];
         $this->empresa->codserie = $_POST['codserie'];
         $this->empresa->coddivisa = $_POST['coddivisa'];
         $this->empresa->codpago = $_POST['codpago'];
         $this->empresa->codalmacen = $_POST['codalmacen'];
         $this->empresa->pie_factura = $_POST['pie_factura'];
         $this->empresa->recequivalencia = isset($_POST['recequivalencia']);
         if ($this->empresa->save()) {
             $this->new_message('Datos guardados correctamente.');
             $step = $fsvar->simple_get('install_step');
             if ($step == 2) {
                 if (in_array('facturacion_base', $GLOBALS['plugins'])) {
                     $this->new_message('Y por último tienes que <a href="index.php?page=contabilidad_ejercicio&cod=' . $this->empresa->codejercicio . '">importar los datos del ejercicio</a>.');
                 }
                 $fsvar->simple_save('install_step', 3);
             }
         } else {
             $this->new_error_msg('Error al guardar los datos.');
         }
         /// guardamos los datos del email
         if (isset($_POST['mail_host'])) {
             if ($_POST['mail_host'] == '') {
                 $this->mail['mail_host'] = 'smtp.gmail.com';
             } else {
                 $this->mail['mail_host'] = $_POST['mail_host'];
             }
             if ($_POST['mail_port'] == '') {
                 $this->mail['mail_port'] = '465';
             } else {
                 $this->mail['mail_port'] = $_POST['mail_port'];
             }
             $this->mail['mail_enc'] = strtolower($_POST['mail_enc']);
             $this->mail['mail_user'] = $_POST['mail_user'];
             $fsvar->array_save($this->mail);
             $this->mail_test();
         }
     } else {
         if (isset($_POST['logo'])) {
             if (is_uploaded_file($_FILES['fimagen']['tmp_name'])) {
                 copy($_FILES['fimagen']['tmp_name'], "tmp/" . FS_TMP_NAME . "logo.png");
                 $this->new_message('Logotipo guardado correctamente.');
             }
         } else {
             if (isset($_GET['delete_logo'])) {
                 if (file_exists('tmp/' . FS_TMP_NAME . 'logo.png')) {
                     unlink('tmp/' . FS_TMP_NAME . 'logo.png');
                     $this->new_message('Logotipo borrado correctamente.');
                 }
             } else {
                 if (isset($_GET['delete_cuenta'])) {
                     $cuenta = $this->cuenta_banco->get($_GET['delete_cuenta']);
                     if ($cuenta) {
                         if ($cuenta->delete()) {
                             $this->new_message('Cuenta bancaria eliminada correctamente.');
                         } else {
                             $this->new_error_msg('Imposible eliminar la cuenta bancaria.');
                         }
                     } else {
                         $this->new_error_msg('Cuenta bancaria no encontrada.');
                     }
                 } else {
                     if (isset($_POST['iban'])) {
                         if (isset($_POST['codcuenta'])) {
                             $cuentab = $this->cuenta_banco->get($_POST['codcuenta']);
                         } else {
                             $cuentab = new cuenta_banco();
                         }
                         $cuentab->descripcion = $_POST['descripcion'];
                         if ($_POST['ciban'] != '') {
                             $cuentab->iban = $cuentab->calcular_iban($_POST['ciban']);
                         } else {
                             $cuentab->iban = $_POST['iban'];
                         }
                         $cuentab->swift = $_POST['swift'];
                         if ($cuentab->save()) {
                             $this->new_message('Cuenta bancaria guardada correctamente.');
                         } else {
                             $this->new_error_msg('Imposible guardar la cuenta bancaria.');
                         }
                     }
                 }
             }
         }
     }
     $this->logo = file_exists('tmp/' . FS_TMP_NAME . 'logo.png');
 }
 protected function private_core()
 {
     $this->check_menu();
     $this->almacen = new almacen();
     $this->bad_password = FALSE;
     $this->divisa = new divisa();
     $this->ejercicio = new ejercicio();
     $this->forma_pago = new forma_pago();
     $this->pais = new pais();
     $this->serie = new serie();
     /// ¿Hay errores? Usa informes > Errores
     if ($this->get_errors()) {
         $this->new_message('Puedes solucionar la mayoría de errores en la base de datos ejecutando el ' . '<a href="index.php?page=informe_errores" target="_blank">informe de errores</a> ' . 'sobre las tablas.');
     }
     if ($this->user->password == sha1('admin')) {
         $this->bad_password = TRUE;
     }
     $fsvar = new fs_var();
     $this->step = $fsvar->simple_get('install_step');
     if ($this->step < 2 or isset($_GET['restart'])) {
         $this->step = 2;
     }
     if (FS_DEMO) {
         $this->new_advice('En el modo demo no se pueden hacer cambios en esta página.');
         $this->new_advice('Si te gusta FacturaScripts y quieres saber más, consulta la ' . '<a href="https://www.facturascripts.com/comm3/index.php?page=community_questions">sección preguntas</a>.');
     } else {
         if (isset($_POST['nombrecorto'])) {
             /// guardamos los datos de la empresa
             $this->empresa->nombre = $_POST['nombre'];
             $this->empresa->nombrecorto = $_POST['nombrecorto'];
             $this->empresa->cifnif = $_POST['cifnif'];
             $this->empresa->administrador = $_POST['administrador'];
             $this->empresa->codpais = $_POST['codpais'];
             $this->empresa->provincia = $_POST['provincia'];
             $this->empresa->ciudad = $_POST['ciudad'];
             $this->empresa->direccion = $_POST['direccion'];
             $this->empresa->codpostal = $_POST['codpostal'];
             $this->empresa->telefono = $_POST['telefono'];
             $this->empresa->fax = $_POST['fax'];
             $this->empresa->web = $_POST['web'];
             $continuar = TRUE;
             if (isset($_POST['npassword'])) {
                 if ($_POST['npassword'] != '') {
                     if ($_POST['npassword'] == $_POST['npassword2']) {
                         $this->user->set_password($_POST['npassword']);
                         $this->user->save();
                     } else {
                         $this->new_error_msg('Las contraseñas no coinciden.');
                         $continuar = FALSE;
                     }
                 }
             }
             if (!$continuar) {
                 /// no hacemos nada
             } else {
                 if ($this->empresa->save()) {
                     $this->new_message('Datos guardados correctamente.');
                     /// avanzamos el asistente
                     $this->step = 3;
                     if ($this->empresa->codpais == 'ESP' or $this->empresa->codpais == 'ES') {
                         /// si es España nos podemos ahorrar un paso
                         $this->empresa->coddivisa = 'EUR';
                         $this->empresa->save();
                         $this->step = 4;
                     }
                     $fsvar->simple_save('install_step', $this->step);
                 } else {
                     $this->new_error_msg('Error al guardar los datos.');
                 }
             }
         } else {
             if (isset($_POST['coddivisa'])) {
                 $this->empresa->coddivisa = $_POST['coddivisa'];
                 if ($this->empresa->save()) {
                     foreach ($GLOBALS['config2'] as $i => $value) {
                         if (isset($_POST[$i])) {
                             $GLOBALS['config2'][$i] = $_POST[$i];
                         }
                     }
                     $file = fopen('tmp/' . FS_TMP_NAME . 'config2.ini', 'w');
                     if ($file) {
                         foreach ($GLOBALS['config2'] as $i => $value) {
                             if (is_numeric($value)) {
                                 fwrite($file, $i . " = " . $value . ";\n");
                             } else {
                                 fwrite($file, $i . " = '" . $value . "';\n");
                             }
                         }
                         fclose($file);
                     }
                     $this->new_message('Datos guardados correctamente.');
                     /// avanzamos el asistente
                     $this->step = 4;
                     $fsvar->simple_save('install_step', $this->step);
                 } else {
                     $this->new_error_msg('Error al guardar los datos.');
                 }
             } else {
                 if (isset($_POST['codejercicio'])) {
                     $this->empresa->contintegrada = isset($_POST['contintegrada']);
                     $this->empresa->codejercicio = $_POST['codejercicio'];
                     $this->empresa->codserie = $_POST['codserie'];
                     $this->empresa->codpago = $_POST['codpago'];
                     $this->empresa->codalmacen = $_POST['codalmacen'];
                     $this->empresa->recequivalencia = isset($_POST['recequivalencia']);
                     if ($this->empresa->save()) {
                         /// guardamos las opciones por defecto de almacén y forma de pago
                         $this->save_codalmacen($_POST['codalmacen']);
                         $this->save_codpago($_POST['codpago']);
                         foreach ($GLOBALS['config2'] as $i => $value) {
                             if (isset($_POST[$i])) {
                                 $GLOBALS['config2'][$i] = $_POST[$i];
                             }
                         }
                         $file = fopen('tmp/' . FS_TMP_NAME . 'config2.ini', 'w');
                         if ($file) {
                             foreach ($GLOBALS['config2'] as $i => $value) {
                                 if (is_numeric($value)) {
                                     fwrite($file, $i . " = " . $value . ";\n");
                                 } else {
                                     fwrite($file, $i . " = '" . $value . "';\n");
                                 }
                             }
                             fclose($file);
                         }
                         $this->new_message('Datos guardados correctamente.');
                         /// avanzamos el asistente
                         $this->step = 5;
                         $fsvar->simple_save('install_step', $this->step);
                     } else {
                         $this->new_error_msg('Error al guardar los datos.');
                     }
                 }
             }
         }
     }
 }
Exemple #15
0
 protected function private_core()
 {
     /// ¿El usuario tiene permiso para eliminar en esta página?
     $this->allow_delete = $this->user->allow_delete_on(__CLASS__);
     $this->share_extensions();
     $this->estado = new estado_sat();
     /// leemos la API key de google maps de la base de datos o del formulario
     $fsvar = new fs_var();
     if (isset($_POST['maps_api_key'])) {
         $this->maps_api_key = $_POST['maps_api_key'];
         $fsvar->simple_save('maps_api_key', $this->maps_api_key);
     } else {
         $this->maps_api_key = $fsvar->simple_get('maps_api_key');
     }
     /// cargamos la configuración
     $this->sat_setup = $fsvar->array_get(array('sat_col_modelo' => 0, 'sat_col_posicion' => 0, 'sat_col_accesorios' => 0, 'sat_col_prioridad' => 0, 'sat_col_fecha' => 1, 'sat_col_fechaini' => 0, 'sat_col_fechafin' => 0, 'sat_condiciones' => "Condiciones del deposito:\nLos presupuestos realizados tienen una" . " validez de 15 días.\nUna vez avisado al cliente para que recoja el producto este dispondrá" . " de un plazo máximo de 2 meses para recogerlo, de no ser así y no haber aviso por parte del" . " cliente se empezará a cobrar 1 euro al día por gastos de almacenaje.\nLos accesorios y" . " productos externos al equipo no especificados en este documento no podrán ser reclamados en" . " caso de disconformidad con el técnico."), FALSE);
     if (isset($_POST['sat_setup'])) {
         $this->sat_setup['sat_col_modelo'] = isset($_POST['col_modelo']) ? 1 : 0;
         $this->sat_setup['sat_col_posicion'] = isset($_POST['col_posicion']) ? 1 : 0;
         $this->sat_setup['sat_col_accesorios'] = isset($_POST['col_accesorios']) ? 1 : 0;
         $this->sat_setup['sat_col_prioridad'] = isset($_POST['col_prioridad']) ? 1 : 0;
         $this->sat_setup['sat_col_fecha'] = isset($_POST['col_fecha']) ? 1 : 0;
         $this->sat_setup['sat_col_fechaini'] = isset($_POST['col_fechaini']) ? 1 : 0;
         $this->sat_setup['sat_col_fechafin'] = isset($_POST['col_fechafin']) ? 1 : 0;
         $this->sat_setup['sat_condiciones'] = $fsvar->no_html($_POST['condiciones']);
         if ($fsvar->array_save($this->sat_setup)) {
             $this->new_message('Datos guardados correctamente.');
         } else {
             $this->new_error_msg('Error al guardar los datos.');
         }
     } else {
         if (isset($_GET['delete_estado'])) {
             $estado = $this->estado->get($_GET['delete_estado']);
             if ($estado) {
                 if ($estado->delete()) {
                     $this->new_message('Estado eliminado correctamente.');
                 } else {
                     $this->new_error_msg('Error al eliminar el estado.');
                 }
             } else {
                 $this->new_error_msg('Estado no encontrado.');
             }
         } else {
             if (isset($_POST['id_estado'])) {
                 $estado = $this->estado->get($_POST['id_estado']);
                 if (!$estado) {
                     $estado = new estado_sat();
                     $estado->id = intval($_POST['id_estado']);
                 }
                 $estado->descripcion = $_POST['descripcion'];
                 $estado->color = $_POST['color'];
                 $estado->activo = isset($_POST['activo']);
                 if ($estado->save()) {
                     $this->new_message('Estado guardado correctamente.');
                 } else {
                     $this->new_error_msg('Error al guardar el estado.');
                 }
             }
         }
     }
 }