protected function private_core()
 {
     $this->share_extensions();
     $this->servicio = new servicio_cliente();
     $this->agente = new agente();
     $this->serie = new serie();
     $this->estados = new estado_servicio();
     // cargamos las opciones del calendario
     $fsvar = new fs_var();
     $this->servicios_setup = $fsvar->array_get(array('servicios_mostrar_fechainicio' => 0, 'cal_inicio' => "09:00", 'cal_fin' => "20:00", 'cal_intervalo' => "30"), FALSE);
     if (isset($_REQUEST['buscar_cliente'])) {
         $this->buscar_cliente();
     }
     if (isset($_REQUEST['codagente']) or isset($_REQUEST['codcliente']) or isset($_REQUEST['estado'])) {
         if (isset($_REQUEST['codcliente'])) {
             if ($_REQUEST['codcliente'] != '') {
                 $cli0 = new cliente();
                 $this->cliente = $cli0->get($_REQUEST['codcliente']);
                 $this->codcliente = $_REQUEST['codcliente'];
             }
             if (isset($_REQUEST['codagente'])) {
                 $this->codagente = $_REQUEST['codagente'];
             }
             if (isset($_REQUEST['estado'])) {
                 $this->estado = $_REQUEST['estado'];
             }
         }
     }
 }
 protected function process()
 {
     $this->offset = 0;
     $this->agente = new agente();
     $this->tarifas = new tarifas_clientes();
     $this->share_extension();
     /// ¿El usuario tiene permiso para eliminar en esta página?
     $this->allow_delete = $this->user->allow_delete_on(__CLASS__);
     if (isset($_GET['codcliente'])) {
         //Primero seleccionamos cliente
         $cliente = new cliente();
         $this->cliente = $cliente->get($_GET['codcliente']);
         //Ahora buscamos un articulo
         if (isset($_REQUEST['buscar_articulo'])) {
             /// desactivamos la plantilla HTML
             $this->template = FALSE;
             $json = array();
             $articulo = new articulo();
             $this->articulos = $articulo->search($_REQUEST['buscar_articulo']);
             foreach ($this->articulos as $art) {
                 $json[] = array('value' => $art->descripcion, 'data' => $art->referencia);
             }
             header('Content-Type: application/json');
             echo json_encode(array('query' => $_REQUEST['buscar_articulo'], 'suggestions' => $json));
         } else {
             if (isset($_POST['tarifa_pvp'])) {
                 $this->nueva_tarifa();
                 //Luego Seleccionamos las tarifas mas recientes de los articulos para este cliente
                 $this->tarifas_select = $this->tarifas->get_tarifas_cliente_select($_GET['codcliente']);
                 //Por ultimo seleccinamos todas las tarias de precios para este cliente
                 $this->tarifas_all = $this->tarifas->get_tarifas_cliente($_GET['codcliente']);
                 //Para eliminar
             } else {
                 if (isset($_GET['delete_tarifa'])) {
                     $tarifa = $this->tarifas->get($_GET['delete_tarifa']);
                     if ($tarifa) {
                         if ($tarifa->delete()) {
                             $this->new_message('Tarifa eliminada correctamente.');
                         } else {
                             $this->new_error_msg('Imposible eliminar la tarifa.');
                         }
                     } else {
                         $this->new_error_msg('Tarifa no encontrada.');
                     }
                     //Luego Seleccionamos las tarifas mas recientes de los articulos para este cliente
                     $this->tarifas_select = $this->tarifas->get_tarifas_cliente_select($_GET['codcliente']);
                     //Por ultimo seleccinamos todas las tarias de precios para este cliente
                     $this->tarifas_all = $this->tarifas->get_tarifas_cliente($_GET['codcliente']);
                 } else {
                     //Luego Seleccionamos las tarifas mas recientes de los articulos para este cliente
                     $this->tarifas_select = $this->tarifas->get_tarifas_cliente_select($_GET['codcliente']);
                     //Por ultimo seleccinamos todas las tarias de precios para este cliente
                     $this->tarifas_all = $this->tarifas->get_tarifas_cliente($_GET['codcliente']);
                 }
             }
         }
     } else {
         $this->new_error_msg('Imposible enseñar tarifas, cliente no seleccionado.');
     }
 }
 protected function private_core()
 {
     $this->cliente = FALSE;
     $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';
         }
     }
     $this->template = FALSE;
     if (isset($_REQUEST['id'])) {
         $recibo0 = new recibo_cliente();
         $this->recibo = $recibo0->get($_REQUEST['id']);
         if ($this->recibo) {
             $cliente = new cliente();
             $this->cliente = $cliente->get($this->recibo->codcliente);
             $fact0 = new factura_cliente();
             $this->factura = $fact0->get($this->recibo->idfactura);
             $this->generar_pdf_recibo();
         } else {
             echo 'ERROR - Recibo no encontrado.';
         }
     } else {
         $this->share_extensions();
     }
 }
 protected function private_core()
 {
     $this->share_extensions();
     /// obtenemos los datos de configuración de impresión
     $this->impresion = array('print_ref' => '1', 'print_dto' => '1', 'print_alb' => '0', 'print_formapago' => '1');
     $fsvar = new fs_var();
     $this->impresion = $fsvar->array_get($this->impresion, FALSE);
     $this->factura = FALSE;
     if (isset($_GET['id'])) {
         $factura = new factura_cliente();
         $this->factura = $factura->get($_GET['id']);
     }
     if (isset($_GET['abreviatura'])) {
         $traduccion = new traduccion_fac_det();
         $this->traduccion = $traduccion->get($_GET['abreviatura']);
     } else {
         $traduccion = new traduccion_fac_det();
         $this->traduccion = $traduccion->get('es_ES');
     }
     if ($this->factura) {
         $cliente = new cliente();
         $this->cliente = $cliente->get($this->factura->codcliente);
         if (isset($_POST['email'])) {
             $this->enviar_email('factura', $_REQUEST['tipo']);
         } else {
             $filename = 'factura_' . $this->factura->codigo . '.pdf';
             $this->generar_pdf(FALSE, $filename);
         }
     } else {
         $this->new_error_msg("¡Factura de cliente no encontrada!");
     }
 }
 protected function private_core()
 {
     //cargamos configuración de servicios
     $fsvar = new fs_var();
     $this->servicios_setup = $fsvar->array_get(array('servicios_diasfin' => 10, 'servicios_material' => 0, 'servicios_mostrar_material' => 0, 'servicios_material_estado' => 0, 'servicios_mostrar_material_estado' => 0, 'servicios_accesorios' => 0, 'servicios_mostrar_accesorios' => 0, 'servicios_descripcion' => 0, 'servicios_mostrar_descripcion' => 0, 'servicios_solucion' => 0, 'servicios_mostrar_solucion' => 0, 'servicios_fechafin' => 0, 'servicios_mostrar_fechafin' => 0, 'servicios_fechainicio' => 0, 'servicios_mostrar_fechainicio' => 0, 'servicios_mostrar_garantia' => 0, 'servicios_garantia' => 0, 'servicios_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);
     /*Cargamos traduccion*/
     $this->st = $fsvar->array_get(array('st_servicio' => "Servicio", 'st_servicios' => "Servicios", 'st_material' => "Material", 'st_material_estado' => "Estado del material entregado", 'st_accesorios' => "Accesorios que entrega", 'st_descripcion' => "Descripción de la averia", 'st_solucion' => "Solución"), FALSE);
     $this->cliente = FALSE;
     $this->impuesto = new impuesto();
     $this->servicio = FALSE;
     /// obtenemos los datos de configuración de impresión
     $this->impresion = array('print_ref' => '1', 'print_dto' => '1', 'print_alb' => '0');
     $fsvar = new fs_var();
     $this->impresion = $fsvar->array_get($this->impresion, FALSE);
     if (isset($_REQUEST['id'])) {
         $serv = new servicio_cliente();
         $this->servicio = $serv->get($_REQUEST['id']);
         if ($this->servicio) {
             $cliente = new cliente();
             $this->cliente = $cliente->get($this->servicio->codcliente);
         }
         if (isset($_POST['email'])) {
             $this->enviar_email('servicio');
         } else {
             $this->generar_pdf_servicio();
         }
     }
     $this->share_extensions();
 }
 protected function private_core()
 {
     $this->share_extension();
     $this->cliente = FALSE;
     $this->desde = Date('01-01-Y');
     $this->hasta = Date('t-m-Y');
     $this->resultados = FALSE;
     $this->serie = new serie();
     if (isset($_REQUEST['buscar_cliente'])) {
         $this->buscar_cliente();
     } else {
         if (isset($_REQUEST['codcliente'])) {
             $cli0 = new cliente();
             $this->cliente = $cli0->get($_REQUEST['codcliente']);
             if (isset($_REQUEST['codserie'])) {
                 $this->codserie = $_REQUEST['codserie'];
             }
             if (isset($_REQUEST['desde'])) {
                 $this->desde = $_REQUEST['desde'];
             }
             if (isset($_REQUEST['hasta'])) {
                 $this->hasta = $_REQUEST['hasta'];
             }
             if ($this->cliente) {
                 $this->resultados = $this->buscar_pedidos();
                 if (isset($_POST['cantidad_0'])) {
                     $this->agrupar_pedidos();
                     $this->resultados = FALSE;
                 }
             }
         }
     }
 }
 protected function process()
 {
     $this->show_fs_toolbar = FALSE;
     $this->cliente = FALSE;
     $this->pedido = FALSE;
     $this->presupuesto = FALSE;
     if (isset($_REQUEST['pedido']) and isset($_REQUEST['id'])) {
         $ped = new pedido_cliente();
         $this->pedido = $ped->get($_REQUEST['id']);
         if ($this->pedido) {
             $cliente = new cliente();
             $this->cliente = $cliente->get($this->pedido->codcliente);
         }
         if (isset($_POST['email'])) {
             $this->enviar_email('pedio');
         } else {
             $this->generar_pdf_pedido();
         }
     } else {
         if (isset($_REQUEST['presupuesto']) and isset($_REQUEST['id'])) {
             $pres = new presupuesto_cliente();
             $this->presupuesto = $pres->get($_REQUEST['id']);
             if ($this->presupuesto) {
                 $cliente = new cliente();
                 $this->cliente = $cliente->get($this->presupuesto->codcliente);
             }
             if (isset($_POST['email'])) {
                 $this->enviar_email('presupuesto');
             } else {
                 $this->generar_pdf_presupuesto();
             }
         }
     }
     $this->share_extensions();
 }
 protected function private_core()
 {
     $this->share_extension();
     /// cargamos la configuración de servicios
     $fsvar = new fs_var();
     $this->setup = $fsvar->array_get(array('servicios_diasfin' => 10, 'servicios_material' => 0, 'servicios_mostrar_material' => 0, 'servicios_material_estado' => 0, 'servicios_mostrar_material_estado' => 0, 'servicios_accesorios' => 0, 'servicios_mostrar_accesorios' => 0, 'servicios_descripcion' => 0, 'servicios_mostrar_descripcion' => 0, 'servicios_solucion' => 0, 'servicios_mostrar_solucion' => 0, 'servicios_fechafin' => 0, 'servicios_mostrar_fechafin' => 0, 'servicios_fechainicio' => 0, 'servicios_mostrar_fechainicio' => 0, 'servicios_mostrar_garantia' => 0, 'servicios_garantia' => 0, 'servicios_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.", 'st_servicio' => "Servicio", 'st_servicios' => "Servicios", 'st_material' => "Material", 'st_material_estado' => "Estado del material entregado", 'st_accesorios' => "Accesorios que entrega", 'st_descripcion' => "Descripción de la averia", 'st_solucion' => "Solución", 'st_fechainicio' => "Fecha de Inicio", 'st_fechafin' => "Fecha de finalización", 'st_garantía' => "Garantía"), FALSE);
     /// cargamos el servicios
     $this->servicio = FALSE;
     if (isset($_GET['id'])) {
         $serv0 = new servicio_cliente();
         $this->servicio = $serv0->get($_GET['id']);
     }
     $term0 = new terminal_caja();
     $this->terminales = $term0->all();
     $this->terminal = FALSE;
     if (isset($_GET['terminal'])) {
         $this->terminal = $term0->get($_GET['terminal']);
     }
     if ($this->servicio and $this->terminal) {
         $cli0 = new cliente();
         $this->cliente = $cli0->get($this->servicio->codcliente);
         $numt = $this->terminal->num_tickets;
         while ($numt > 0) {
             $this->imprimir();
             $this->terminal->save();
             $numt--;
         }
     }
 }
 protected function process()
 {
     $albaran = new albaran_cliente();
     /// desactivamos la barra de botones
     $this->show_fs_toolbar = FALSE;
     $this->offset = 0;
     if (isset($_GET['offset'])) {
         $this->offset = intval($_GET['offset']);
     }
     /// Usamos una cookie para recordar si el usuario quiere ver los pendientes
     $this->pendientes = isset($_COOKIE['ventas_alb_ptes']);
     if (isset($_GET['ptefactura'])) {
         $this->pendientes = $_GET['ptefactura'] == 'TRUE';
         if ($this->pendientes) {
             setcookie('ventas_alb_ptes', 'TRUE', time() + FS_COOKIES_EXPIRE);
         } else {
             setcookie('ventas_alb_ptes', FALSE, time() - FS_COOKIES_EXPIRE);
         }
     }
     if (isset($_POST['buscar_lineas'])) {
         $this->buscar_lineas();
     } else {
         if (isset($_GET['codagente'])) {
             $this->template = 'extension/ventas_albaranes_agente';
             $agente = new agente();
             $this->agente = $agente->get($_GET['codagente']);
             $this->resultados = $albaran->all_from_agente($_GET['codagente'], $this->offset);
         } else {
             if (isset($_GET['codcliente'])) {
                 $this->template = 'extension/ventas_albaranes_cliente';
                 $cliente = new cliente();
                 $this->cliente = $cliente->get($_GET['codcliente']);
                 $this->resultados = $albaran->all_from_cliente($_GET['codcliente'], $this->offset);
             } else {
                 if (isset($_GET['ref'])) {
                     $this->template = 'extension/ventas_albaranes_articulo';
                     $articulo = new articulo();
                     $this->articulo = $articulo->get($_GET['ref']);
                     $linea = new linea_albaran_cliente();
                     $this->resultados = $linea->all_from_articulo($_GET['ref'], $this->offset);
                 } else {
                     $this->share_extension();
                     if (isset($_POST['delete'])) {
                         $this->delete_albaran();
                     }
                     if ($this->query) {
                         $this->resultados = $albaran->search($this->query, $this->offset);
                     } else {
                         if ($this->pendientes) {
                             $this->resultados = $albaran->all_ptefactura($this->offset);
                         } else {
                             $this->resultados = $albaran->all($this->offset);
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #10
0
 protected function process()
 {
     $this->factura = new factura_cliente();
     $this->huecos = array();
     $this->offset = 0;
     if (isset($_GET['offset'])) {
         $this->offset = intval($_GET['offset']);
     }
     if (isset($_POST['buscar_lineas'])) {
         $this->buscar_lineas();
     } else {
         if (isset($_GET['codagente'])) {
             $this->template = 'extension/ventas_facturas_agente';
             $agente = new agente();
             $this->agente = $agente->get($_GET['codagente']);
             $this->resultados = $this->factura->all_from_agente($_GET['codagente'], $this->offset);
         } else {
             if (isset($_GET['codcliente'])) {
                 $this->template = 'extension/ventas_facturas_cliente';
                 $cliente = new cliente();
                 $this->cliente = $cliente->get($_GET['codcliente']);
                 $this->resultados = $this->factura->all_from_cliente($_GET['codcliente'], $this->offset);
             } else {
                 if (isset($_GET['ref'])) {
                     $this->template = 'extension/ventas_facturas_articulo';
                     $articulo = new articulo();
                     $this->articulo = $articulo->get($_GET['ref']);
                     $linea = new linea_factura_cliente();
                     $this->resultados = $linea->all_from_articulo($_GET['ref'], $this->offset);
                 } else {
                     $this->share_extension();
                     $this->huecos = $this->factura->huecos();
                     if (isset($_GET['delete'])) {
                         $fact = $this->factura->get($_GET['delete']);
                         if ($fact) {
                             if ($fact->delete()) {
                                 $this->new_message("Factura eliminada correctamente.");
                             } else {
                                 $this->new_error_msg("¡Imposible eliminar la factura!");
                             }
                         } else {
                             $this->new_error_msg("¡Factura no encontrada!");
                         }
                     }
                     if ($this->query != '') {
                         $this->resultados = $this->factura->search($this->query, $this->offset);
                     } else {
                         if (isset($_GET['sinpagar'])) {
                             $this->resultados = $this->factura->all_sin_pagar($this->offset);
                         } else {
                             $this->resultados = $this->factura->all($this->offset);
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #11
0
 protected function process()
 {
     $pedido = new pedido_cliente();
     $this->offset = 0;
     if (isset($_GET['offset'])) {
         $this->offset = intval($_GET['offset']);
     }
     $this->mostrar = 'todos';
     if (isset($_GET['mostrar'])) {
         $this->mostrar = $_GET['mostrar'];
     }
     if (isset($_POST['buscar_lineas'])) {
         $this->buscar_lineas();
     } else {
         if (isset($_GET['codagente'])) {
             $this->template = 'extension/ventas_pedidos_agente';
             $agente = new agente();
             $this->agente = $agente->get($_GET['codagente']);
             $this->resultados = $pedido->all_from_agente($_GET['codagente'], $this->offset);
         } else {
             if (isset($_GET['codcliente'])) {
                 $this->template = 'extension/ventas_pedidos_cliente';
                 $cliente = new cliente();
                 $this->cliente = $cliente->get($_GET['codcliente']);
                 $this->resultados = $pedido->all_from_cliente($_GET['codcliente'], $this->offset);
             } else {
                 if (isset($_GET['ref'])) {
                     $this->template = 'extension/ventas_pedidos_articulo';
                     $articulo = new articulo();
                     $this->articulo = $articulo->get($_GET['ref']);
                     $linea = new linea_pedido_cliente();
                     $this->resultados = $linea->all_from_articulo($_GET['ref'], $this->offset);
                 } else {
                     $this->share_extension();
                     if (isset($_POST['delete'])) {
                         $this->delete_pedido();
                     }
                     if ($this->query) {
                         $this->resultados = $pedido->search($this->query, $this->offset);
                     } else {
                         if ($this->mostrar == 'pendientes') {
                             $this->resultados = $pedido->all_ptealbaran($this->offset);
                         } else {
                             if ($this->mostrar == 'rechazados') {
                                 $this->resultados = $pedido->all_rechazados($this->offset);
                             } else {
                                 /// ejecutamos el proceso del cron para pedidos.
                                 $pedido->cron_job();
                                 $this->resultados = $pedido->all($this->offset);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 protected function process()
 {
     $pedido = new pedido_cliente();
     /// desactivamos la barra de botones
     $this->show_fs_toolbar = FALSE;
     $this->offset = 0;
     if (isset($_GET['offset'])) {
         $this->offset = intval($_GET['offset']);
     }
     if (isset($_POST['buscar_lineas'])) {
         $this->buscar_lineas();
     } else {
         if (isset($_GET['codagente'])) {
             $this->template = 'extension/ventas_pedidos_agente';
             $agente = new agente();
             $this->agente = $agente->get($_GET['codagente']);
             $this->resultados = $pedido->all_from_agente($_GET['codagente'], $this->offset);
         } else {
             if (isset($_GET['codcliente'])) {
                 $this->template = 'extension/ventas_pedidos_cliente';
                 $cliente = new cliente();
                 $this->cliente = $cliente->get($_GET['codcliente']);
                 $this->resultados = $pedido->all_from_cliente($_GET['codcliente'], $this->offset);
             } else {
                 if (isset($_GET['ref'])) {
                     $this->template = 'extension/ventas_pedidos_articulo';
                     $articulo = new articulo();
                     $this->articulo = $articulo->get($_GET['ref']);
                     $linea = new linea_pedido_cliente();
                     $this->resultados = $linea->all_from_articulo($_GET['ref'], $this->offset);
                 } else {
                     $this->share_extension();
                     if (isset($_POST['delete'])) {
                         $this->delete_pedido();
                     }
                     if ($this->query) {
                         $this->resultados = $pedido->search($this->query, $this->offset);
                     } else {
                         if (isset($_GET['pendientes'])) {
                             $this->resultados = $pedido->all_ptealbaran($this->offset);
                         } else {
                             if (isset($_GET['rechazados'])) {
                                 $this->resultados = $pedido->all_rechazados($this->offset);
                             } else {
                                 $this->resultados = $pedido->all($this->offset);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 protected function private_core()
 {
     $this->albaran = new albaran_cliente();
     $this->cliente = FALSE;
     $this->codserie = NULL;
     $this->ejercicio = new ejercicio();
     $this->forma_pago = new forma_pago();
     $this->serie = new serie();
     $this->neto = 0;
     $this->total = 0;
     $this->desde = Date('01-01-Y');
     $this->hasta = Date('t-m-Y');
     $this->observaciones = '';
     if (isset($_REQUEST['buscar_cliente'])) {
         $this->buscar_cliente();
     } else {
         if (isset($_POST['idalbaran'])) {
             $this->cliente = new cliente();
             $this->agrupar();
         } else {
             if (isset($_REQUEST['codcliente'])) {
                 $cli0 = new cliente();
                 $this->cliente = $cli0->get($_REQUEST['codcliente']);
                 if (isset($_REQUEST['codserie'])) {
                     $this->codserie = $_REQUEST['codserie'];
                 }
                 if (isset($_REQUEST['desde'])) {
                     $this->desde = $_REQUEST['desde'];
                 }
                 if (isset($_REQUEST['hasta'])) {
                     $this->hasta = $_REQUEST['hasta'];
                 }
                 if (isset($_REQUEST['observaciones'])) {
                     $this->observaciones = $_REQUEST['observaciones'];
                 }
                 if ($this->cliente) {
                     $this->resultados = $this->albaran->search_from_cliente($this->cliente->codcliente, $this->desde, $this->hasta, $this->codserie, $this->observaciones);
                     if ($this->resultados) {
                         foreach ($this->resultados as $alb) {
                             $this->neto += $alb->neto;
                             $this->total += $alb->total;
                         }
                     } else {
                         $this->new_message("Sin resultados.");
                     }
                 }
             } else {
                 $this->share_extensions();
             }
         }
     }
 }
 protected function private_core()
 {
     $this->share_extension();
     $this->documentos = array();
     if (isset($_GET['folder']) and isset($_GET['cod'])) {
         //Primero cargamos el proveedor o cliente segun sea
         if ($_GET['folder'] == 'proveedor') {
             $proveedor = new proveedor();
             $this->proveedor = $proveedor->get($_GET['cod']);
             $this->cod = $_GET['cod'];
         } else {
             $cliente = new cliente();
             $this->cliente = $cliente->get($_GET['cod']);
             $this->cod = $_GET['cod'];
         }
         //Luego si no existen documentos crea directorios
         if (!file_exists('tmp/' . FS_TMP_NAME . 'documentos_procli')) {
             mkdir('tmp/' . FS_TMP_NAME . 'documentos_procli');
         }
         if (!file_exists('tmp/' . FS_TMP_NAME . 'documentos_procli/' . $_GET['folder'])) {
             mkdir('tmp/' . FS_TMP_NAME . 'documentos_procli/' . $_GET['folder']);
         }
         //PAra subir archivos
         if (isset($_POST['upload'])) {
             if (is_uploaded_file($_FILES['fdocumento']['tmp_name'])) {
                 if (!file_exists('tmp/' . FS_TMP_NAME . 'documentos_procli/' . $_GET['folder'] . '/' . $this->cod)) {
                     mkdir('tmp/' . FS_TMP_NAME . 'documentos_procli/' . $_GET['folder'] . '/' . $this->cod);
                 }
                 copy($_FILES['fdocumento']['tmp_name'], "tmp/" . FS_TMP_NAME . "documentos_procli/" . $_GET['folder'] . '/' . $this->cod . '/' . $_FILES['fdocumento']['name']);
                 $this->new_message('Documentos añadido correctamente.');
             }
         } else {
             if (isset($_GET['delete'])) {
                 if (file_exists('tmp/' . FS_TMP_NAME . 'documentos_procli/' . $_GET['folder'] . '/' . $this->cod . '/' . $_GET['delete'])) {
                     if (unlink('tmp/' . FS_TMP_NAME . 'documentos_procli/' . $_GET['folder'] . '/' . $this->cod . '/' . $_GET['delete'])) {
                         $this->new_message('Archivo ' . $_GET['delete'] . ' eliminado correctamente.');
                     } else {
                         $this->new_error_msg('Error al eliminar el archivo ' . $_GET['delete'] . '.');
                     }
                 } else {
                     $this->new_error_msg('Archivo no encontrado.');
                 }
             }
         }
         //Si no finalmente enseñamos todos los documentos para este cliente o proveedor
         $this->documentos = $this->get_documentos();
     }
 }
Beispiel #15
0
 protected function process()
 {
     $this->share_extensions();
     $this->factura = FALSE;
     if (isset($_GET['id'])) {
         $factura = new factura_cliente();
         $this->factura = $factura->get($_GET['id']);
     }
     if ($this->factura) {
         $cliente = new cliente();
         $this->cliente = $cliente->get($this->factura->codcliente);
         $this->generar_pdf();
     } else {
         $this->new_error_msg("¡Factura de cliente no encontrada!");
     }
 }
 protected function private_core()
 {
     $this->albaran = FALSE;
     $this->cliente = FALSE;
     $this->factura = FALSE;
     $this->impuesto = new impuesto();
     /// obtenemos los datos de configuración de impresión
     $this->impresion = array('print_ref' => '1', 'print_dto' => '1', 'print_alb' => '0');
     $fsvar = new fs_var();
     $this->impresion = $fsvar->array_get($this->impresion, FALSE);
     $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';
         }
     }
     if (isset($_REQUEST['albaran']) and isset($_REQUEST['id'])) {
         $alb = new albaran_cliente();
         $this->albaran = $alb->get($_REQUEST['id']);
         if ($this->albaran) {
             $cliente = new cliente();
             $this->cliente = $cliente->get($this->albaran->codcliente);
         }
         if (isset($_POST['email'])) {
             $this->enviar_email('albaran');
         } else {
             $this->generar_pdf_albaran();
         }
     } else {
         if (isset($_REQUEST['factura']) and isset($_REQUEST['id'])) {
             $fac = new factura_cliente();
             $this->factura = $fac->get($_REQUEST['id']);
             if ($this->factura) {
                 $cliente = new cliente();
                 $this->cliente = $cliente->get($this->factura->codcliente);
             }
             if (isset($_POST['email'])) {
                 $this->enviar_email('factura', $_REQUEST['tipo']);
             } else {
                 $this->generar_pdf_factura($_REQUEST['tipo']);
             }
         }
     }
     $this->share_extensions();
 }
Beispiel #17
0
function CrearCliente($comercial, $legal, $direccion, $poblacion, $cp, $email, $telefono1, $telefono2, $contacto, $cargo, $cuentabancaria, $numero, $comentario, $tipocliente, $idpais, $paginaweb, $IdLocal = false, $FechaNacimiento)
{
    $comercial = str_replace('&', '&', $comercial);
    $legal = str_replace('&', '&', $legal);
    if (!$IdLocal) {
        $IdLocal = getSesionDato("IdTienda");
    }
    $oCliente = new cliente();
    $oCliente->Crea();
    $oCliente->set("NombreComercial", $comercial, FORCE);
    $oCliente->set("NombreLegal", $legal, FORCE);
    $oCliente->set("Direccion", $direccion, FORCE);
    $oCliente->set("Localidad", $poblacion, FORCE);
    $oCliente->set("CP", $cp, FORCE);
    $oCliente->set("Email", $email, FORCE);
    $oCliente->set("Telefono1", $telefono1, FORCE);
    $oCliente->set("Telefono2", $telefono2, FORCE);
    $oCliente->set("Contacto", $contacto, FORCE);
    $oCliente->set("Cargo", $cargo, FORCE);
    $oCliente->set("CuentaBancaria", $cuentabancaria, FORCE);
    $oCliente->set("NumeroFiscal", $numero, FORCE);
    $oCliente->set("Comentarios", $comentario, FORCE);
    $oCliente->set("TipoCliente", $tipocliente, FORCE);
    $oCliente->set("IdPais", $idpais, FORCE);
    $oCliente->set("PaginaWeb", $paginaweb, FORCE);
    $oCliente->set("FechaRegistro", "NOW()", FORCE);
    $oCliente->set("FechaChange", "NOW()", FORCE);
    $oCliente->set("IdLocal", $IdLocal, FORCE);
    $oCliente->set("FechaNacimiento", $FechaNacimiento, FORCE);
    if ($oCliente->Alta()) {
        //if(isVerbose())
        //	echo gas("aviso", _("Nuevo cliente registrado"));
        return $oCliente->get("IdCliente");
    } else {
        //echo gas("aviso", _("No se ha podido registrar el nuevo producto"));
        return false;
    }
}
 protected function private_core()
 {
     $this->share_extensions();
     $this->cliente = FALSE;
     $this->resultados = array();
     /// recibimos el código del cliente
     if (isset($_REQUEST['cod']) and !empty($_REQUEST['cod'])) {
         $cli0 = new cliente();
         $this->cliente = $cli0->get($_REQUEST['cod']);
     }
     $this->observaciones = '';
     if (isset($_REQUEST['observaciones'])) {
         $this->observaciones = $_REQUEST['observaciones'];
     }
     $this->offset = 0;
     if (isset($_REQUEST['offset'])) {
         $this->offset = $_REQUEST['offset'];
     }
     if ($this->cliente) {
         $lineafacturacli = new linea_factura_cliente();
         $this->resultados = $lineafacturacli->search_from_cliente2($this->cliente->codcliente, $this->query, $this->observaciones, $this->offset);
     }
 }
 protected function private_core()
 {
     $this->desde = Date('01-m-Y');
     if (isset($_POST['desde'])) {
         $this->desde = $_POST['desde'];
     }
     $this->hasta = Date('d-m-Y');
     if (isset($_POST['hasta'])) {
         $this->hasta = $_POST['hasta'];
     }
     $this->cliente = FALSE;
     $this->codcliente = FALSE;
     if (isset($_POST['codcliente'])) {
         $this->codcliente = $_POST['codcliente'];
         $cli0 = new cliente();
         $this->cliente = $cli0->get($this->codcliente);
     }
     $this->serie = new serie();
     $this->codserie = FALSE;
     if (isset($_POST['codserie'])) {
         $this->codserie = $_POST['codserie'];
     }
     if (isset($_REQUEST['buscar_cliente'])) {
         $this->buscar_cliente();
     } else {
         if (isset($_POST['idfactura'])) {
             $this->pagar_facturas();
         } else {
             $this->share_extensions();
         }
     }
     $this->resultados = FALSE;
     if (isset($_POST['codcliente'])) {
         $this->resultados = $this->buscar_facturas();
     }
 }
 protected function process()
 {
     $this->show_fs_toolbar = FALSE;
     $this->albaran = FALSE;
     $this->cliente = FALSE;
     $this->factura = FALSE;
     $this->impuesto = new impuesto();
     if (isset($_REQUEST['albaran']) and isset($_REQUEST['id'])) {
         $alb = new albaran_cliente();
         $this->albaran = $alb->get($_REQUEST['id']);
         if ($this->albaran) {
             $cliente = new cliente();
             $this->cliente = $cliente->get($this->albaran->codcliente);
         }
         if (isset($_POST['email'])) {
             $this->enviar_email('albaran');
         } else {
             $this->generar_pdf_albaran();
         }
     } else {
         if (isset($_REQUEST['factura']) and isset($_REQUEST['id'])) {
             $fac = new factura_cliente();
             $this->factura = $fac->get($_REQUEST['id']);
             if ($this->factura) {
                 $cliente = new cliente();
                 $this->cliente = $cliente->get($this->factura->codcliente);
             }
             if (isset($_POST['email'])) {
                 $this->enviar_email('factura', $_REQUEST['tipo']);
             } else {
                 $this->generar_pdf_factura($_REQUEST['tipo']);
             }
         }
     }
     $this->share_extensions();
 }
Beispiel #21
0
 protected function private_core()
 {
     $this->provsms = new proveedor_sms();
     $this->documento = FALSE;
     $this->telefono = '';
     $this->mensaje = '';
     $this->documento_url = $this->url();
     $cliente = new cliente();
     $servicio = FALSE;
     if (isset($_REQUEST['servicio'])) {
         $serv = new servicio_cliente();
         $servicio = $serv->get($_REQUEST['id']);
         if ($servicio) {
             $this->cliente = $cliente->get($servicio->codcliente);
             $this->id = $servicio->idservicio;
             $this->documento = 'servicio';
             $this->documento_url = $servicio->url();
         }
     } else {
         if (isset($_REQUEST['pedido'])) {
             $ped = new pedido_cliente();
             $pedido = $ped->get($_REQUEST['id']);
             if ($pedido) {
                 $this->cliente = $cliente->get($pedido->codcliente);
                 $this->id = $pedido->idpedido;
                 $this->documento = 'pedido';
                 $this->documento_url = $pedido->url();
             }
         }
     }
     if (isset($_POST['enviar'])) {
         $this->provsms = FALSE;
         $provsms = new proveedor_sms();
         $this->provsms = $provsms->get($_POST['proveedor']);
         if ($this->provsms) {
             if (!($this->telefono = $_POST['telefono'] == '+34')) {
                 $this->telefono = $_POST['telefono'];
                 $this->mensaje = $_POST['mensaje'];
                 if (strpos($this->provsms->url, 'freevoipdeal')) {
                     if ($this->sms_freevoipdeal()) {
                         $this->new_message('Mensaje desde Freevoipdeal enviado');
                         if ($servicio) {
                             $this->agrega_detalle($servicio);
                         } else {
                             if ($pedido) {
                                 $this->pedido_observaciones();
                             }
                         }
                     } else {
                         $this->new_error_msg('Error al enviar el mensaje');
                     }
                 } else {
                     if (strpos($this->provsms->url, 'clickatell')) {
                         if ($this->sms_clickatell()) {
                             $this->new_message('Mensaje desde Clickatell enviado');
                             if ($servicio) {
                                 $this->agrega_detalle($servicio);
                             }
                         } else {
                             $this->new_error_msg('Error al enviar el mensaje');
                         }
                     }
                 }
             } else {
                 $this->new_error_msg('No has introducido ningún número.');
             }
         } else {
             $this->new_error_msg('Proveedor de SMS no encontrado.');
         }
     }
 }
 protected function private_core()
 {
     $this->desde = Date('01-m-Y');
     if (isset($_POST['desde'])) {
         $this->desde = $_POST['desde'];
     }
     $this->hasta = Date('d-m-Y');
     if (isset($_POST['hasta'])) {
         $this->hasta = $_POST['hasta'];
     }
     $this->cliente = FALSE;
     $this->codcliente = FALSE;
     if (!isset($_POST['todos']) and isset($_POST['codcliente'])) {
         $this->codcliente = $_POST['codcliente'];
         $cli0 = new cliente();
         $this->cliente = $cli0->get($this->codcliente);
     }
     $this->serie = new serie();
     $this->codserie = FALSE;
     if (isset($_POST['codserie'])) {
         $this->codserie = $_POST['codserie'];
     }
     if (isset($_REQUEST['buscar_cliente'])) {
         $this->buscar_cliente();
     } else {
         if (in_array('tesoreria', $GLOBALS['plugins'])) {
             $this->new_error_msg('Si usas el <b>plugin Tesorería</b> no puedes usar este' . ' asistente para pagar todas las facturas.');
         } else {
             if (isset($_POST['idfactura'])) {
                 /// ¿Marcamos ya las facturas?
                 $num = 0;
                 $asi0 = new asiento();
                 $asifac = new asiento_factura();
                 $fact0 = new factura_cliente();
                 foreach ($_POST['idfactura'] as $id) {
                     $factura = $fact0->get($id);
                     if ($factura) {
                         $asiento = $asi0->get($factura->idasiento);
                         if ($asiento) {
                             $factura->idasientop = $asifac->generar_asiento_pago($asiento, $factura->codpago);
                             if ($factura->idasientop) {
                                 $factura->pagada = TRUE;
                                 if ($factura->save()) {
                                     $num++;
                                 }
                             }
                         } else {
                             $factura->pagada = TRUE;
                             if ($factura->save()) {
                                 $num++;
                             }
                         }
                     }
                 }
                 foreach ($asifac->errors as $err) {
                     $this->new_error_msg($err);
                 }
                 $this->new_message($num . ' facturas marcadas como pagadas, estas son las siguientes.');
             } else {
                 $this->share_extensions();
             }
         }
     }
     $this->resultados = FALSE;
     if (isset($_POST['desde'])) {
         $this->resultados = $this->buscar_facturas();
     }
 }
 protected function private_core()
 {
     $this->ppage = $this->page->get('ventas_clientes');
     $this->agente = new agente();
     $this->cuenta_banco = new cuenta_banco_cliente();
     $this->divisa = new divisa();
     $this->forma_pago = new forma_pago();
     $this->grupo = new grupo_clientes();
     $this->pais = new pais();
     $this->serie = new serie();
     /// ¿El usuario tiene permiso para eliminar en esta página?
     $this->allow_delete = $this->user->allow_delete_on(__CLASS__);
     /// cargamos el cliente
     $cliente = new cliente();
     $this->cliente = FALSE;
     if (isset($_POST['codcliente'])) {
         $this->cliente = $cliente->get($_POST['codcliente']);
     } else {
         if (isset($_GET['cod'])) {
             $this->cliente = $cliente->get($_GET['cod']);
         }
     }
     /// ¿Hay que hacer algo más?
     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($_GET['delete_dir'])) {
             $dir = new direccion_cliente();
             $dir0 = $dir->get($_GET['delete_dir']);
             if ($dir0) {
                 if ($dir0->delete()) {
                     $this->new_message('Dirección eliminada correctamente.');
                 } else {
                     $this->new_error_msg('Imposible eliminar la dirección.');
                 }
             } else {
                 $this->new_error_msg('Dirección no encontrada.');
             }
         } else {
             if (isset($_POST['coddir'])) {
                 $dir = new direccion_cliente();
                 if ($_POST['coddir'] != '') {
                     $dir = $dir->get($_POST['coddir']);
                 }
                 $dir->apartado = $_POST['apartado'];
                 $dir->ciudad = $_POST['ciudad'];
                 $dir->codcliente = $this->cliente->codcliente;
                 $dir->codpais = $_POST['pais'];
                 $dir->codpostal = $_POST['codpostal'];
                 $dir->descripcion = $_POST['descripcion'];
                 $dir->direccion = $_POST['direccion'];
                 $dir->domenvio = isset($_POST['direnvio']);
                 $dir->domfacturacion = isset($_POST['dirfact']);
                 $dir->provincia = $_POST['provincia'];
                 if ($dir->save()) {
                     $this->new_message("Dirección guardada correctamente.");
                 } else {
                     $this->new_message("¡Imposible guardar la dirección!");
                 }
             } else {
                 if (isset($_POST['iban'])) {
                     if (isset($_POST['codcuenta'])) {
                         $cuentab = $this->cuenta_banco->get($_POST['codcuenta']);
                     } else {
                         $cuentab = new cuenta_banco_cliente();
                         $cuentab->codcliente = $_POST['codcliente'];
                     }
                     $cuentab->descripcion = $_POST['descripcion'];
                     if ($_POST['ciban'] != '') {
                         $cuentab->iban = $this->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.');
                     }
                 } else {
                     if (isset($_POST['codcliente'])) {
                         $this->cliente->nombre = $_POST['nombre'];
                         $this->cliente->razonsocial = $_POST['razonsocial'];
                         $this->cliente->cifnif = $_POST['cifnif'];
                         $this->cliente->telefono1 = $_POST['telefono1'];
                         $this->cliente->telefono2 = $_POST['telefono2'];
                         $this->cliente->fax = $_POST['fax'];
                         $this->cliente->web = $_POST['web'];
                         $this->cliente->email = $_POST['email'];
                         $this->cliente->observaciones = $_POST['observaciones'];
                         $this->cliente->codserie = $_POST['codserie'];
                         $this->cliente->codpago = $_POST['codpago'];
                         $this->cliente->coddivisa = $_POST['coddivisa'];
                         $this->cliente->regimeniva = $_POST['regimeniva'];
                         $this->cliente->recargo = isset($_POST['recargo']);
                         $this->cliente->debaja = isset($_POST['debaja']);
                         $this->cliente->codagente = NULL;
                         if ($_POST['codagente'] != '---') {
                             $this->cliente->codagente = $_POST['codagente'];
                         }
                         $this->cliente->codgrupo = NULL;
                         if ($_POST['codgrupo'] != '---') {
                             $this->cliente->codgrupo = $_POST['codgrupo'];
                         }
                         if ($this->cliente->save()) {
                             $this->new_message("Datos del cliente modificados correctamente.");
                         } else {
                             $this->new_error_msg("¡Imposible modificar los datos del cliente!");
                         }
                     }
                 }
             }
         }
     }
     if ($this->cliente) {
         $this->page->title = $this->cliente->codcliente;
     } else {
         $this->new_error_msg("¡Cliente no encontrado!");
     }
 }
Beispiel #24
0
function FormularioAltaParticular()
{
    global $action;
    $oCliente = new cliente();
    $oCliente->Crea();
    $ot = getTemplate("FormAltaClienteParticular");
    if (!$ot) {
        error(__FILE__ . __LINE__, "Info: template no encontrado");
        return false;
    }
    $ot->fijar("tTitulo", _("Alta cliente"));
    $ot->fijar("action", $action);
    $ot->fijar("tModPagoHabitual", _("Modo pago hab."));
    $ot->fijar("vIdModPagoHabitual", $oCliente->get("IdModPagoHabitual"));
    $ot->fijar("comboModPagoHabitual", genComboModPagoHabitual($oCliente->get("IdModPagoHabitual")));
    $ot->fijar("tIdPais", _("País"));
    $ot->fijar("vIdPais", $oCliente->get("IdPais"));
    $ot->fijar("comboIdPais", genComboPaises($oCliente->get("IdPais")));
    $ot->campo(_("Nombre"), "NombreComercial", $oCliente);
    $ot->campo(_("Nombre legal"), "NombreLegal", $oCliente);
    $ot->campo(_("Dirección"), "Direccion", $oCliente);
    $ot->campo(_("Localidad"), "Localidad", $oCliente);
    $ot->campo(_("Código postal"), "CP", $oCliente);
    $ot->campo(_("Telf.(1)"), "Telefono1", $oCliente);
    $ot->campo(_("Telf.(2)"), "Telefono2", $oCliente);
    $ot->campo(_("Contacto"), "Contacto", $oCliente);
    $ot->campo(_("Cargo"), "Cargo", $oCliente);
    $ot->campo(_("Email"), "Email", $oCliente);
    $ot->campo(_("Cuenta bancaria"), "CuentaBancaria", $oCliente);
    $ot->campo(_("Número fiscal"), "NumeroFiscal", $oCliente);
    $ot->campo(_("Comentarios"), "Comentarios", $oCliente);
    //modalidad de pago habitual?
    echo $ot->Output();
}
 protected function private_core()
 {
     $this->tipo = FALSE;
     $this->subcuenta = FALSE;
     $this->cuenta = new cuenta();
     /// seleccionamos el ejercicio
     $ejercicio = new ejercicio();
     $eje0 = $ejercicio->get_by_fecha(date('d-m-Y'));
     if (isset($_POST['codejercicio'])) {
         $this->codejercicio = $_POST['codejercicio'];
     } else {
         if ($eje0) {
             $this->codejercicio = $eje0->codejercicio;
         } else {
             $this->codejercicio = $this->default_items->codejercicio();
         }
     }
     if (isset($_POST['ejercicio']) and isset($_POST['query'])) {
         $this->new_search();
     } else {
         if (isset($_REQUEST['cli'])) {
             $this->tipo = 'cli';
             $cliente = new cliente();
             $this->cliente = $cliente->get($_REQUEST['cli']);
             if ($this->cliente) {
                 $subcuenta_cliente = new subcuenta_cliente();
                 if (isset($_GET['delete_sca'])) {
                     $aux_sca = $subcuenta_cliente->get2($_GET['delete_sca']);
                     if ($aux_sca) {
                         if ($aux_sca->delete()) {
                             $this->new_message('El cliente ya no está asocuado a esa subcuenta.');
                         } else {
                             $this->new_error_msg('Imposible quitar la subcuenta.');
                         }
                     } else {
                         $this->new_error_msg('Relación con la subcuenta no encontrada.');
                     }
                 } else {
                     if (isset($_GET['idsc'])) {
                         $this->subcuenta_a = $subcuenta_cliente->get($_GET['cli'], $_GET['idsc']);
                         if ($this->subcuenta_a) {
                             $this->subcuenta = $this->subcuenta_a->get_subcuenta();
                             $this->codejercicio = $this->subcuenta_a->codejercicio;
                         }
                     } else {
                         if (isset($_POST['idsc'])) {
                             $this->subcuenta_a = $subcuenta_cliente->get($_POST['cli'], $_POST['idsc']);
                             if ($this->subcuenta_a) {
                                 $subc = new subcuenta();
                                 $subc0 = $subc->get($_POST['idsc2']);
                                 if ($subc0) {
                                     $this->subcuenta_a->idsubcuenta = $subc0->idsubcuenta;
                                     $this->subcuenta_a->codsubcuenta = $subc0->codsubcuenta;
                                     $this->subcuenta_a->codejercicio = $subc0->codejercicio;
                                     if ($this->subcuenta_a->save()) {
                                         $this->new_message('Datos guardados correctamente.');
                                     } else {
                                         $this->new_error_msg('Imposible asignar la subcuenta al cliente.');
                                     }
                                     $this->subcuenta = $subc0;
                                 } else {
                                     $this->new_error_msg('Subcuenta no encontrada.');
                                     $this->subcuenta = $this->subcuenta_a->get_subcuenta();
                                 }
                             }
                         } else {
                             if (isset($_POST['idsc2'])) {
                                 $subc = new subcuenta();
                                 $subc0 = $subc->get($_POST['idsc2']);
                                 if ($subc0) {
                                     $subcuenta_cliente->codcliente = $this->cliente->codcliente;
                                     $subcuenta_cliente->idsubcuenta = $subc0->idsubcuenta;
                                     $subcuenta_cliente->codsubcuenta = $subc0->codsubcuenta;
                                     $subcuenta_cliente->codejercicio = $subc0->codejercicio;
                                     if ($subcuenta_cliente->save()) {
                                         $this->new_message('Datos guardados correctamente.');
                                     } else {
                                         $this->new_error_msg('Imposible asignar la subcuenta al cliente.');
                                     }
                                     $this->subcuenta = $subc0;
                                 } else {
                                     $this->new_error_msg('Subcuenta no encontrada.');
                                 }
                             } else {
                                 if (isset($_POST['cuenta'])) {
                                     $cuenta0 = $this->cuenta->get($_POST['cuenta']);
                                     if ($cuenta0) {
                                         $subc0 = new subcuenta();
                                         $subc0->codcuenta = $cuenta0->codcuenta;
                                         $subc0->coddivisa = $this->default_items->coddivisa();
                                         $subc0->codejercicio = $cuenta0->codejercicio;
                                         $subc0->codsubcuenta = $_POST['codsubcuenta'];
                                         $subc0->descripcion = $this->cliente->nombre;
                                         $subc0->idcuenta = $cuenta0->idcuenta;
                                         if ($subc0->save()) {
                                             $subcuenta_cliente->codcliente = $this->cliente->codcliente;
                                             $subcuenta_cliente->idsubcuenta = $subc0->idsubcuenta;
                                             $subcuenta_cliente->codsubcuenta = $subc0->codsubcuenta;
                                             $subcuenta_cliente->codejercicio = $subc0->codejercicio;
                                             if ($subcuenta_cliente->save()) {
                                                 $this->new_message('Datos guardados correctamente.');
                                             } else {
                                                 $this->new_error_msg('Imposible asignar la subcuenta al cliente.');
                                             }
                                             $this->subcuenta = $subc0;
                                         } else {
                                             $this->new_error_msg('Imposible crear la sucuenta.');
                                         }
                                     } else {
                                         $this->new_error_msg('Cuenta no encontrada.');
                                     }
                                 } else {
                                     foreach ($subcuenta_cliente->all_from_cliente($_REQUEST['cli']) as $sca) {
                                         if ($sca->codejercicio == $this->codejercicio) {
                                             $this->subcuenta_a = $sca;
                                             $this->subcuenta = $sca->get_subcuenta();
                                             break;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             if (isset($_REQUEST['pro'])) {
                 $this->tipo = 'pro';
                 $proveedor = new proveedor();
                 $this->proveedor = $proveedor->get($_REQUEST['pro']);
                 if ($this->proveedor) {
                     $subcuenta_proveedor = new subcuenta_proveedor();
                     if (isset($_GET['delete_sca'])) {
                         $aux_sca = $subcuenta_proveedor->get2($_GET['delete_sca']);
                         if ($aux_sca) {
                             if ($aux_sca->delete()) {
                                 $this->new_message('El proveedor ya no está asocuado a esa subcuenta.');
                             } else {
                                 $this->new_error_msg('Imposible quitar la subcuenta.');
                             }
                         } else {
                             $this->new_error_msg('Relación con la subcuenta no encontrada.');
                         }
                     } else {
                         if (isset($_GET['idsc'])) {
                             $this->subcuenta_a = $subcuenta_proveedor->get($_GET['pro'], $_GET['idsc']);
                             if ($this->subcuenta_a) {
                                 $this->subcuenta = $this->subcuenta_a->get_subcuenta();
                                 $this->codejercicio = $this->subcuenta_a->codejercicio;
                             }
                         } else {
                             if (isset($_POST['idsc'])) {
                                 $this->subcuenta_a = $subcuenta_proveedor->get($_POST['pro'], $_POST['idsc']);
                                 if ($this->subcuenta_a) {
                                     $subc = new subcuenta();
                                     $subc0 = $subc->get($_POST['idsc2']);
                                     if ($subc0) {
                                         $this->subcuenta_a->idsubcuenta = $subc0->idsubcuenta;
                                         $this->subcuenta_a->codsubcuenta = $subc0->codsubcuenta;
                                         $this->subcuenta_a->codejercicio = $subc0->codejercicio;
                                         if ($this->subcuenta_a->save()) {
                                             $this->new_message('Datos guardados correctamente.');
                                         } else {
                                             $this->new_error_msg('Imposible asignar la subcuenta al proveedor.');
                                         }
                                         $this->subcuenta = $subc0;
                                     } else {
                                         $this->new_error_msg('Subcuenta no encontrada.');
                                         $this->subcuenta = $this->subcuenta_a->get_subcuenta();
                                     }
                                 }
                             } else {
                                 if (isset($_POST['idsc2'])) {
                                     $subc = new subcuenta();
                                     $subc0 = $subc->get($_POST['idsc2']);
                                     if ($subc0) {
                                         $subcuenta_proveedor->codproveedor = $this->proveedor->codproveedor;
                                         $subcuenta_proveedor->idsubcuenta = $subc0->idsubcuenta;
                                         $subcuenta_proveedor->codsubcuenta = $subc0->codsubcuenta;
                                         $subcuenta_proveedor->codejercicio = $subc0->codejercicio;
                                         if ($subcuenta_proveedor->save()) {
                                             $this->new_message('Datos guardados correctamente.');
                                         } else {
                                             $this->new_error_msg('Imposible asignar la subcuenta al cliente.');
                                         }
                                         $this->subcuenta = $subc0;
                                     } else {
                                         $this->new_error_msg('Subcuenta no encontrada.');
                                     }
                                 } else {
                                     if (isset($_POST['cuenta'])) {
                                         $cuenta0 = $this->cuenta->get($_POST['cuenta']);
                                         if ($cuenta0) {
                                             $subc0 = new subcuenta();
                                             $subc0->codcuenta = $cuenta0->codcuenta;
                                             $subc0->coddivisa = $this->default_items->coddivisa();
                                             $subc0->codejercicio = $cuenta0->codejercicio;
                                             $subc0->codsubcuenta = $_POST['codsubcuenta'];
                                             $subc0->descripcion = $this->proveedor->nombre;
                                             $subc0->idcuenta = $cuenta0->idcuenta;
                                             if ($subc0->save()) {
                                                 $subcuenta_proveedor->codproveedor = $this->proveedor->codproveedor;
                                                 $subcuenta_proveedor->idsubcuenta = $subc0->idsubcuenta;
                                                 $subcuenta_proveedor->codsubcuenta = $subc0->codsubcuenta;
                                                 $subcuenta_proveedor->codejercicio = $subc0->codejercicio;
                                                 if ($subcuenta_proveedor->save()) {
                                                     $this->new_message('Datos guardados correctamente.');
                                                 } else {
                                                     $this->new_error_msg('Imposible asignar la subcuenta al proveedor.');
                                                 }
                                                 $this->subcuenta = $subc0;
                                             } else {
                                                 $this->new_error_msg('Imposible crear la sucuenta.');
                                             }
                                         } else {
                                             $this->new_error_msg('Cuenta no encontrada.');
                                         }
                                     } else {
                                         foreach ($subcuenta_proveedor->all_from_proveedor($_REQUEST['pro']) as $sca) {
                                             if ($sca->codejercicio == $this->codejercicio) {
                                                 $this->subcuenta_a = $sca;
                                                 $this->subcuenta = $sca->get_subcuenta();
                                                 break;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 protected function private_core()
 {
     $albaran = new albaran_cliente();
     $this->agente = new agente();
     $this->serie = new serie();
     $this->mostrar = 'todo';
     if (isset($_GET['mostrar'])) {
         $this->mostrar = $_GET['mostrar'];
         setcookie('ventas_alb_mostrar', $this->mostrar, time() + FS_COOKIES_EXPIRE);
     } else {
         if (isset($_COOKIE['ventas_alb_mostrar'])) {
             $this->mostrar = $_COOKIE['ventas_alb_mostrar'];
         }
     }
     $this->offset = 0;
     if (isset($_REQUEST['offset'])) {
         $this->offset = intval($_REQUEST['offset']);
     }
     $this->order = 'fecha DESC';
     if (isset($_GET['order'])) {
         if ($_GET['order'] == 'fecha_desc') {
             $this->order = 'fecha DESC';
         } else {
             if ($_GET['order'] == 'fecha_asc') {
                 $this->order = 'fecha ASC';
             } else {
                 if ($_GET['order'] == 'codigo_desc') {
                     $this->order = 'codigo DESC';
                 } else {
                     if ($_GET['order'] == 'codigo_asc') {
                         $this->order = 'codigo ASC';
                     }
                 }
             }
         }
         setcookie('ventas_alb_order', $this->order, time() + FS_COOKIES_EXPIRE);
     } else {
         if (isset($_COOKIE['ventas_alb_order'])) {
             $this->order = $_COOKIE['ventas_alb_order'];
         }
     }
     if (isset($_POST['buscar_lineas'])) {
         $this->buscar_lineas();
     } else {
         if (isset($_REQUEST['buscar_cliente'])) {
             $this->buscar_cliente();
         } else {
             if (isset($_GET['ref'])) {
                 $this->template = 'extension/ventas_albaranes_articulo';
                 $articulo = new articulo();
                 $this->articulo = $articulo->get($_GET['ref']);
                 $linea = new linea_albaran_cliente();
                 $this->resultados = $linea->all_from_articulo($_GET['ref'], $this->offset);
             } else {
                 $this->share_extension();
                 $this->cliente = FALSE;
                 $this->codagente = '';
                 $this->codserie = '';
                 $this->desde = '';
                 $this->hasta = '';
                 $this->num_resultados = '';
                 $this->total_resultados = '';
                 $this->total_resultados_txt = '';
                 if (isset($_POST['delete'])) {
                     $this->delete_albaran();
                 } else {
                     if (!isset($_GET['mostrar']) and (isset($_REQUEST['codagente']) or isset($_REQUEST['codcliente']))) {
                         /**
                          * si obtenermos un codagente o un codcliente pasamos direcatemente
                          * a la pestaña de búsqueda, a menos que tengamos un mostrar, que
                          * entonces nos indica donde tenemos que estar.
                          */
                         $this->mostrar = 'buscar';
                     }
                     if (isset($_REQUEST['codcliente'])) {
                         if ($_REQUEST['codcliente'] != '') {
                             $cli0 = new cliente();
                             $this->cliente = $cli0->get($_REQUEST['codcliente']);
                         }
                     }
                     if (isset($_REQUEST['codagente'])) {
                         $this->codagente = $_REQUEST['codagente'];
                     }
                     if (isset($_REQUEST['codserie'])) {
                         $this->codserie = $_REQUEST['codserie'];
                         $this->desde = $_REQUEST['desde'];
                         $this->hasta = $_REQUEST['hasta'];
                     }
                 }
                 /// añadimos segundo nivel de ordenación
                 $order2 = '';
                 if ($this->order == 'fecha DESC') {
                     $order2 = ', codigo DESC';
                 } else {
                     if ($this->order == 'fecha ASC') {
                         $order2 = ', codigo ASC';
                     }
                 }
                 if ($this->mostrar == 'pendientes') {
                     $this->resultados = $albaran->all_ptefactura($this->offset, $this->order . $order2);
                     if ($this->offset == 0) {
                         $this->total_resultados = 0;
                         $this->total_resultados_txt = 'Suma total de esta página:';
                         foreach ($this->resultados as $alb) {
                             $this->total_resultados += $alb->total;
                         }
                     }
                 } else {
                     if ($this->mostrar == 'buscar') {
                         $this->buscar($order2);
                     } else {
                         $this->resultados = $albaran->all($this->offset, $this->order . $order2);
                     }
                 }
             }
         }
     }
 }
 private function informe_ventascli()
 {
     $sql = "SELECT l.referencia,f.codcliente,f.fecha,SUM(l.cantidad) as total" . " FROM facturascli f, lineasfacturascli l" . " WHERE f.idfactura = l.idfactura AND l.referencia IS NOT NULL" . " AND f.fecha >= " . $this->empresa->var2str($_POST['desde']) . " AND f.fecha <= " . $this->empresa->var2str($_POST['hasta']);
     if ($this->referencia != '') {
         $sql .= " AND l.referencia = " . $this->empresa->var2str($this->referencia);
     } else {
         if ($this->codfamilia != '') {
             $sql .= " AND l.referencia IN (SELECT referencia FROM articulos" . " WHERE codfamilia IN (";
             $coma = '';
             foreach ($this->get_subfamilias($this->codfamilia) as $fam) {
                 $sql .= $coma . $this->empresa->var2str($fam);
                 $coma = ',';
             }
             $sql .= "))";
         }
     }
     if ($_POST['minimo'] != '') {
         $sql .= " AND l.cantidad > " . $this->empresa->var2str($_POST['minimo']);
     }
     $sql .= " GROUP BY l.referencia,f.codcliente,f.fecha ORDER BY l.referencia ASC, f.codcliente ASC, f.fecha DESC;";
     $data = $this->db->select($sql);
     if ($data) {
         $this->template = FALSE;
         header("content-type:application/csv;charset=UTF-8");
         header("Content-Disposition: attachment; filename=\"informe_ventas_unidades.csv\"");
         echo "referencia;codcliente;nombre;año;ene;feb;mar;abr;may;jun;jul;ago;sep;oct;nov;dic;total;%VAR\n";
         $cliente = new cliente();
         $stats = array();
         foreach ($data as $d) {
             $anyo = date('Y', strtotime($d['fecha']));
             $mes = date('n', strtotime($d['fecha']));
             if (!isset($stats[$d['referencia']][$d['codcliente']][$anyo])) {
                 $stats[$d['referencia']][$d['codcliente']][$anyo] = array(1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 0);
             }
             $stats[$d['referencia']][$d['codcliente']][$anyo][$mes] += floatval($d['total']);
             $stats[$d['referencia']][$d['codcliente']][$anyo][13] += floatval($d['total']);
         }
         foreach ($stats as $i => $value) {
             foreach ($value as $j => $value2) {
                 /// calculamos la variación
                 $anterior = 0;
                 foreach (array_reverse($value2, TRUE) as $k => $value3) {
                     if ($anterior > 0) {
                         $value2[$k][14] = $value3[13] * 100 / $anterior - 100;
                     }
                     $anterior = $value3[13];
                 }
                 $cli = $cliente->get($j);
                 foreach ($value2 as $k => $value3) {
                     if ($cli) {
                         echo '"' . $i . '";"' . $j . '";' . $cli->nombre . ';' . $k;
                     } else {
                         echo '"' . $i . '";"' . $j . '";-;' . $k;
                     }
                     foreach ($value3 as $value4) {
                         echo ';' . number_format($value4, FS_NF0, ',', '');
                     }
                     echo "\n";
                 }
                 echo ";;;;;;;;;;;;;;;\n";
             }
             echo ";;;;;;;;;;;;;;;\n";
         }
     } else {
         $this->new_error_msg('Sin resultados.');
     }
 }
 protected function private_core()
 {
     /// ¿El usuario tiene permiso para eliminar en esta página?
     $this->allow_delete = $this->user->allow_delete_on(__CLASS__);
     $this->ppage = $this->page->get('ventas_facturas');
     $this->ejercicio = new ejercicio();
     $this->agente = FALSE;
     $this->agentes = array();
     $this->cliente = FALSE;
     $this->divisa = new divisa();
     $this->factura = FALSE;
     $this->forma_pago = new forma_pago();
     $this->pais = new pais();
     $this->rectificada = FALSE;
     $this->rectificativa = FALSE;
     $this->serie = new serie();
     /**
      * Si hay alguna extensión de tipo config y texto no_button_pagada,
      * desactivamos el botón de pagada/sin pagar.
      */
     $this->mostrar_boton_pagada = TRUE;
     foreach ($this->extensions as $ext) {
         if ($ext->type == 'config' and $ext->text == 'no_button_pagada') {
             $this->mostrar_boton_pagada = FALSE;
             break;
         }
     }
     /**
      * ¿Modificamos la factura?
      */
     $factura = new factura_cliente();
     if (isset($_POST['idfactura'])) {
         $this->factura = $factura->get($_POST['idfactura']);
         $this->modificar();
     } else {
         if (isset($_GET['id'])) {
             $this->factura = $factura->get($_GET['id']);
         }
     }
     if ($this->factura) {
         $this->page->title = $this->factura->codigo;
         /// cargamos el agente
         $agente = new agente();
         if (!is_null($this->factura->codagente)) {
             $this->agente = $agente->get($this->factura->codagente);
         }
         $this->agentes = $agente->all();
         /// cargamos el cliente
         $cliente = new cliente();
         $this->cliente = $cliente->get($this->factura->codcliente);
         if (isset($_GET['gen_asiento']) and isset($_GET['petid'])) {
             if ($this->duplicated_petition($_GET['petid'])) {
                 $this->new_error_msg('Petición duplicada. Evita hacer doble clic sobre los botones.');
             } else {
                 $this->generar_asiento($this->factura);
             }
         } else {
             if (isset($_GET['updatedir'])) {
                 $this->actualizar_direccion();
             } else {
                 if (isset($_REQUEST['pagada'])) {
                     $this->pagar($_REQUEST['pagada'] == 'TRUE');
                 } else {
                     if (isset($_POST['anular'])) {
                         $this->anular_factura();
                     }
                 }
             }
         }
         if ($this->factura->idfacturarect) {
             $this->rectificada = $factura->get($this->factura->idfacturarect);
         } else {
             $this->get_factura_rectificativa();
         }
         /// comprobamos la factura
         $this->factura->full_test();
     } else {
         $this->new_error_msg("¡Factura de cliente no encontrada!");
     }
 }
 protected function private_core()
 {
     $this->listado = FALSE;
     $this->ppage = $this->page->get('listado_clientes');
     // $this->agente = new agente();
     // $this->cuenta_banco = new cuenta_banco_cliente();
     // $this->divisa = new divisa();
     // $this->forma_pago = new forma_pago();
     // $this->grupo = new grupo_clientes();
     // $this->pais = new pais();
     // $this->serie = new serie();
     $this->maquinas = new maquinas();
     if (isset($_GET['id_aviso'])) {
         $this->page = "index.php?page=editar_maquina&cod=" . $this->{$_GET}['id_aviso'];
     }
     if (isset($_POST['numero_serie'])) {
         ///Nueva maquina
         if ($_POST['contrato']) {
             $contratada = "Si";
         } else {
             $contratada = "No";
         }
         if ($_POST['alquilada']) {
             $alquiler = "Si";
         } else {
             $alquiler = "No";
         }
         $this->maquinas->ubicacion = $_POST['ubicacion'];
         $this->maquinas->codcliente = $_POST['codcliente'];
         $this->maquinas->nombre_cliente = $_POST['nombrecliente'];
         $this->maquinas->equipo = $_POST['equipo'];
         $this->maquinas->marca = $_POST['marca'];
         $this->maquinas->modelo = $_POST['modelo'];
         $this->maquinas->contrato = $contratada;
         $this->maquinas->alquilada = $alquiler;
         $this->maquinas->numero_serie = $_POST['numero_serie'];
         $this->maquinas->contacto = $_POST['contacto'];
         $this->maquinas->costo_copia_negro = $_POST['costo_copia_negro'];
         $this->maquinas->costo_copia_color = $_POST['costo_copia_color'];
         $this->maquinas->notas = $_POST['notas'];
         if ($this->maquinas->save()) {
             $this->new_message('Datos guardados correctamante');
         } else {
             $this->new_error_msg('Error al Guardar');
         }
     }
     $this->listado = $this->maquinas->get_maquina_cliente($_GET['cod']);
     /// ¿El usuario tiene permiso para eliminar en esta página?
     $this->allow_delete = $this->user->allow_delete_on(__CLASS__);
     /// cargamos el cliente
     $cliente = new cliente();
     $this->cliente = FALSE;
     if (isset($_POST['codcliente'])) {
         $this->cliente = $cliente->get($_POST['codcliente']);
     } else {
         if (isset($_GET['cod'])) {
             $this->cliente = $cliente->get($_GET['cod']);
         }
     }
     /// ¿Hay que hacer algo más?
     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($_GET['delete_dir'])) {
             $dir = new direccion_cliente();
             $dir0 = $dir->get($_GET['delete_dir']);
             if ($dir0) {
                 if ($dir0->delete()) {
                     $this->new_message('Dirección eliminada correctamente.');
                 } else {
                     $this->new_error_msg('Imposible eliminar la dirección.');
                 }
             } else {
                 $this->new_error_msg('Dirección no encontrada.');
             }
         } else {
             if (isset($_POST['coddir'])) {
                 $dir = new direccion_cliente();
                 if ($_POST['coddir'] != '') {
                     $dir = $dir->get($_POST['coddir']);
                 }
                 $dir->apartado = $_POST['apartado'];
                 $dir->ciudad = $_POST['ciudad'];
                 $dir->codcliente = $this->cliente->codcliente;
                 $dir->codpais = $_POST['pais'];
                 $dir->codpostal = $_POST['codpostal'];
                 $dir->descripcion = $_POST['descripcion'];
                 $dir->direccion = $_POST['direccion'];
                 $dir->domenvio = isset($_POST['direnvio']);
                 $dir->domfacturacion = isset($_POST['dirfact']);
                 $dir->provincia = $_POST['provincia'];
                 if ($dir->save()) {
                     $this->new_message("Dirección guardada correctamente.");
                 } else {
                     $this->new_message("¡Imposible guardar la dirección!");
                 }
             }
         }
     }
     /*
           else if( isset($_POST['iban']) ) /// añadir/modificar dirección
           {
              if( isset($_POST['codcuenta']) )
              {
                 $cuentab = $this->cuenta_banco->get($_POST['codcuenta']);
              }
              else
              {
                 $cuentab = new cuenta_banco_cliente();
                 $cuentab->codcliente = $_POST['codcliente'];
              }
              
              $cuentab->descripcion = $_POST['descripcion'];
              $cuentab->iban = $_POST['iban'];
              $cuentab->swift = $_POST['swift'];
              $cuentab->principal = isset($_POST['principal']);
              
              if( $cuentab->save() )
              {
                 $this->new_message('Cuenta bancaria guardada correctamente.');
              }
              else
                 $this->new_error_msg('Imposible guardar la cuenta bancaria.');
           }
           else if( isset($_POST['codcliente']) ) /// modificar cliente
           {
              $this->cliente->nombre = $_POST['nombre'];
              $this->cliente->razonsocial = $_POST['razonsocial'];
              $this->cliente->cifnif = $_POST['cifnif'];
              $this->cliente->telefono1 = $_POST['telefono1'];
              $this->cliente->telefono2 = $_POST['telefono2'];
              $this->cliente->fax = $_POST['fax'];
              $this->cliente->web = $_POST['web'];
              $this->cliente->email = $_POST['email'];
              $this->cliente->observaciones = $_POST['observaciones'];
              $this->cliente->codserie = $_POST['codserie'];
              $this->cliente->codpago = $_POST['codpago'];
              $this->cliente->coddivisa = $_POST['coddivisa'];
              $this->cliente->regimeniva = $_POST['regimeniva'];
              $this->cliente->recargo = isset($_POST['recargo']);
              $this->cliente->debaja = isset($_POST['debaja']);
              
              $this->cliente->codagente = NULL;
              if($_POST['codagente'] != '---')
              {
                 $this->cliente->codagente = $_POST['codagente'];
              }
              
              $this->cliente->codgrupo = NULL;
              if($_POST['codgrupo'] != '---')
              {
                 $this->cliente->codgrupo = $_POST['codgrupo'];
              }
             
              if( $this->cliente->save() )
              {
                 $this->new_message("Datos del cliente modificados correctamente.");
              }
              else
                 $this->new_error_msg("¡Imposible modificar los datos del cliente!");
           }*/
     if ($this->cliente) {
         $this->page->title = $this->cliente->codcliente;
     } else {
         $this->new_error_msg("¡Cliente no encontrado!");
     }
 }
Beispiel #30
0
 protected function process()
 {
     $this->ppage = $this->page->get('ventas_facturas');
     $this->ejercicio = new ejercicio();
     $this->agente = FALSE;
     $this->cliente = FALSE;
     $factura = new factura_cliente();
     $this->factura = FALSE;
     $this->forma_pago = new forma_pago();
     /// ¿El usuario tiene permiso para eliminar en esta página?
     $this->allow_delete = $this->user->allow_delete_on(__CLASS__);
     /**
      * Si hay alguna extensión de tipo config y texto no_button_pagada,
      * desactivamos el botón de pagada/sin pagar.
      */
     $this->mostrar_boton_pagada = TRUE;
     foreach ($this->extensions as $ext) {
         if ($ext->type == 'config' and $ext->text == 'no_button_pagada') {
             $this->mostrar_boton_pagada = FALSE;
             break;
         }
     }
     /**
      * ¿Modificamos la factura?
      */
     if (isset($_POST['idfactura'])) {
         $this->factura = $factura->get($_POST['idfactura']);
         $this->factura->observaciones = $_POST['observaciones'];
         $this->factura->numero2 = $_POST['numero2'];
         /// obtenemos el ejercicio para poder acotar la fecha
         $eje0 = $this->ejercicio->get($this->factura->codejercicio);
         if ($eje0) {
             $this->factura->fecha = $eje0->get_best_fecha($_POST['fecha'], TRUE);
             $this->factura->hora = $_POST['hora'];
         } else {
             $this->new_error_msg('No se encuentra el ejercicio asociado a la factura.');
         }
         /// ¿cambiamos la forma de pago?
         if ($this->factura->codpago != $_POST['forma_pago']) {
             $this->factura->codpago = $_POST['forma_pago'];
             $this->factura->vencimiento = $this->nuevo_vencimiento($this->factura->fecha, $this->factura->codpago);
         } else {
             $this->factura->vencimiento = $_POST['vencimiento'];
         }
         if ($this->factura->save()) {
             $asiento = $this->factura->get_asiento();
             if ($asiento) {
                 $asiento->fecha = $this->factura->fecha;
                 if (!$asiento->save()) {
                     $this->new_error_msg("Imposible modificar la fecha del asiento.");
                 }
             }
             $this->new_message("Factura modificada correctamente.");
             $this->new_change('Factura Cliente ' . $this->factura->codigo, $this->factura->url());
         } else {
             $this->new_error_msg("¡Imposible modificar la factura!");
         }
     } else {
         if (isset($_GET['id'])) {
             $this->factura = $factura->get($_GET['id']);
         }
     }
     if ($this->factura) {
         $this->page->title = $this->factura->codigo;
         /// cargamos el agente
         if (!is_null($this->factura->codagente)) {
             $agente = new agente();
             $this->agente = $agente->get($this->factura->codagente);
         }
         /// cargamos el cliente
         $cliente = new cliente();
         $this->cliente = $cliente->get($this->factura->codcliente);
         if (isset($_GET['gen_asiento']) and isset($_GET['petid'])) {
             if ($this->duplicated_petition($_GET['petid'])) {
                 $this->new_error_msg('Petición duplicada. Evita hacer doble clic sobre los botones.');
             } else {
                 $this->generar_asiento();
             }
         } else {
             if (isset($_GET['updatedir'])) {
                 $this->actualizar_direccion();
             } else {
                 if (isset($_REQUEST['pagada'])) {
                     $this->factura->pagada = $_REQUEST['pagada'] == 'TRUE';
                     if ($this->factura->save()) {
                         $this->new_message("Factura modificada correctamente.");
                     } else {
                         $this->new_error_msg("¡Imposible modificar la factura!");
                     }
                 }
             }
         }
         /// comprobamos la factura
         $this->factura->full_test();
     } else {
         $this->new_error_msg("¡Factura de cliente no encontrada!");
     }
 }