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!");
     }
 }
Example #3
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();
 }
 protected function private_core()
 {
     $this->share_extension();
     $this->serie = new serie();
     $fact0 = new factura_cliente();
     $this->factura = FALSE;
     if (isset($_REQUEST['id'])) {
         $this->factura = $fact0->get($_REQUEST['id']);
     }
     if ($this->factura) {
         if (isset($_POST['id'])) {
             $this->nueva_rectificativa();
         }
     } else {
         $this->new_error_msg('Factura no encontrada.');
     }
 }
Example #6
0
 protected function process()
 {
     $this->show_fs_toolbar = FALSE;
     $this->serie = new serie();
     $this->share_extensions();
     if (isset($_REQUEST['buscar_cliente'])) {
         $this->buscar_cliente();
     }
     $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->codcliente = FALSE;
     if (!isset($_POST['todos']) and isset($_POST['codcliente'])) {
         $this->codcliente = $_POST['codcliente'];
     }
     $this->codserie = FALSE;
     if (isset($_POST['codserie'])) {
         $this->codserie = $_POST['codserie'];
     }
     /// ¿Marcamos ya las facturas?
     if (isset($_POST['idfactura'])) {
         $num = 0;
         $fact0 = new factura_cliente();
         foreach ($_POST['idfactura'] as $id) {
             $factura = $fact0->get($id);
             if ($factura) {
                 $factura->pagada = TRUE;
                 $factura->save();
                 $num++;
             }
         }
         $this->new_message($num . ' facturas marcadas como pagadas, estas son las siguientes.');
     }
     $this->resultados = FALSE;
     if (isset($_POST['desde'])) {
         $this->resultados = $this->buscar_facturas();
     }
 }
 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->modelonumero = new modelonumero();
     $this->ppage = $this->page->get('ventas_facturas');
     $this->ejercicio = new ejercicio();
     $this->agente = FALSE;
     $this->agentes = array();
     $this->cliente = FALSE;
     $this->divisa = new divisa();
     $factura = new factura_cliente();
     $this->factura = FALSE;
     $this->forma_pago = new forma_pago();
     $this->pais = new pais();
     $this->rectificada = FALSE;
     $this->rectificativa = FALSE;
     $this->serie = new serie();
     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 ($this->factura->idfacturarect) {
             $this->rectificada = $factura->get($this->factura->idfacturarect);
         } else {
             $this->get_factura_rectificativa();
         }
     } else {
         $this->new_error_msg("¡Factura de cliente no encontrada!");
     }
 }
 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();
 }
 /**
  * Genera el asiento contable para una devolucion factura de venta.
  * Devuelve TRUE si el asiento se ha generado correctamente, False en caso contrario.
  * Si genera el asiento, este es accesible desde $this->asiento.
  * @param type $factura
  */
 public function nuevo_asiento_devolucion_cli($id)
 {
     $varfactura = new factura_cliente();
     $factura = $varfactura->get($_REQUEST['idfaccli']);
     $ok = FALSE;
     $this->asiento = FALSE;
     $cliente0 = new cliente();
     $subcuenta_cli = FALSE;
     $cliente = $cliente0->get($factura->codcliente);
     if ($cliente) {
         $subcuenta_cli = $cliente->get_subcuenta($factura->codejercicio);
     }
     if (!$subcuenta_cli) {
         $eje0 = $this->ejercicio->get($factura->codejercicio);
         $this->new_message("No se ha podido generar una subcuenta para el cliente\n            <a href='" . $eje0->url() . "'>¿Has importado los datos del ejercicio?</a>");
         if (!$this->soloasiento) {
             $this->new_message("Aun así la <a href='" . $factura->url() . "'>factura</a> se ha generado correctamente,\n            pero sin asiento contable.");
         }
     } else {
         $asiento = new asiento();
         $asiento->codejercicio = $factura->codejercicio;
         $asiento->concepto = "Nota de crédito " . $factura->codigo . " - " . $factura->nombrecliente;
         $asiento->documento = $factura->codigo;
         $asiento->editable = TRUE;
         $asiento->fecha = $factura->fecha;
         $asiento->importe = $factura->total;
         $asiento->tipodocumento = 'Egreso';
         if ($asiento->save()) {
             $asiento_correcto = TRUE;
             $subcuenta = new subcuenta();
             $partida0 = new partida();
             $subcuenta_ventas = $subcuenta->get_cuentaesp('DEVVEN', $asiento->codejercicio);
             $partida0->idasiento = $asiento->idasiento;
             $partida0->concepto = $asiento->concepto;
             $partida0->idsubcuenta = $subcuenta_ventas->idsubcuenta;
             $partida0->codsubcuenta = $subcuenta_ventas->codsubcuenta;
             $partida0->debe = $factura->total;
             $partida0->coddivisa = $factura->coddivisa;
             $partida0->tasaconv = $factura->tasaconv;
             $partida0->codserie = $factura->codserie;
             if (!$partida0->save()) {
                 $asiento_correcto = FALSE;
                 $this->new_error_msg("¡Imposible generar la partida para la subcuenta " . $partida0->codsubcuenta . "!");
             }
             if ($subcuenta_ventas and $asiento_correcto) {
                 $partida2 = new partida();
                 $partida2->idasiento = $asiento->idasiento;
                 $partida2->concepto = $asiento->concepto;
                 $partida2->idsubcuenta = $subcuenta_cli->idsubcuenta;
                 $partida2->codsubcuenta = $subcuenta_cli->codsubcuenta;
                 $partida2->haber = $factura->neto;
                 $partida2->coddivisa = $factura->coddivisa;
                 $partida2->tasaconv = $factura->tasaconv;
                 $partida2->codserie = $factura->codserie;
                 if (!$partida2->save()) {
                     $asiento_correcto = FALSE;
                     $this->new_error_msg("¡Imposible generar la partida para la subcuenta " . $partida2->codsubcuenta . "!");
                 }
             }
             if ($asiento_correcto) {
                 $factura->idasiento = $asiento->idasiento;
                 if ($factura->save()) {
                     $ok = TRUE;
                     $this->asiento = $asiento;
                 } else {
                     $this->new_error_msg("¡Imposible añadir el asiento a la factura!");
                 }
             } else {
                 if ($asiento->delete()) {
                     $this->new_message("El asiento se ha borrado.");
                 } else {
                     $this->new_error_msg("¡Imposible borrar el asiento!");
                 }
             }
         } else {
             $this->new_error_msg("¡Imposible guardar el asiento!");
         }
     }
     return $ok;
 }
Example #10
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!");
     }
 }
 protected function private_core()
 {
     $this->share_extensions();
     $this->documento = FALSE;
     $this->editable = FALSE;
     if (isset($_REQUEST['albaran'])) {
         $alb0 = new albaran_cliente();
         $this->documento = $alb0->get($_REQUEST['id']);
         if ($this->documento) {
             $this->titulo = FS_ALBARAN . ' ' . $this->documento->codigo;
             $this->lineas = $this->documento->get_lineas();
             $this->editable = $this->documento->ptefactura;
             if (isset($_POST['idlinea'])) {
                 if ($this->editable) {
                     $orden = 1 + count($_POST['idlinea']);
                     foreach ($_POST['idlinea'] as $idl) {
                         foreach ($this->lineas as $lin) {
                             if ($lin->idlinea == $idl) {
                                 $lin->orden = $orden;
                                 $lin->save();
                                 break;
                             }
                         }
                         $orden--;
                     }
                     $this->new_message('Datos guardados correctamente.');
                     $this->lineas = $this->documento->get_lineas();
                 } else {
                     $this->new_error_msg('El documento ya no es editable.');
                 }
             }
         }
     } else {
         if (isset($_REQUEST['factura'])) {
             $fact0 = new factura_cliente();
             $this->documento = $fact0->get($_REQUEST['id']);
             if ($this->documento) {
                 $this->titulo = 'Factura ' . $this->documento->codigo;
                 $this->lineas = $this->documento->get_lineas();
                 $this->editable = TRUE;
                 if (isset($_POST['idlinea'])) {
                     if ($this->editable) {
                         $orden = 1 + count($_POST['idlinea']);
                         foreach ($_POST['idlinea'] as $idl) {
                             foreach ($this->lineas as $lin) {
                                 if ($lin->idlinea == $idl) {
                                     $lin->orden = $orden;
                                     $lin->save();
                                     break;
                                 }
                             }
                             $orden--;
                         }
                         $this->new_message('Datos guardados correctamente.');
                         $this->lineas = $this->documento->get_lineas();
                     } else {
                         $this->new_error_msg('El documento ya no es editable.');
                     }
                 }
             }
         }
     }
 }
 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!");
     }
 }
Example #13
0
 private function nuevo_recibo()
 {
     $factura = new factura_cliente();
     $this->factura = $factura->get($_POST['idfactura']);
     if ($this->factura) {
         $recibo = new recibo_cliente();
         $recibo->apartado = $this->factura->apartado;
         $recibo->cifnif = $this->factura->cifnif;
         $recibo->ciudad = $this->factura->ciudad;
         $recibo->codcliente = $this->factura->codcliente;
         $recibo->coddir = $this->factura->coddir;
         $recibo->coddivisa = $this->factura->coddivisa;
         $recibo->tasaconv = $this->factura->tasaconv;
         $recibo->codpago = $this->factura->codpago;
         $recibo->codserie = $this->factura->codserie;
         $recibo->numero = $recibo->new_numero($_POST['idfactura']);
         $recibo->codigo = $this->factura->codigo . '-' . sprintf('%02s', $recibo->numero);
         $recibo->codpais = $this->factura->codpais;
         $recibo->codpostal = $this->factura->codpostal;
         $recibo->direccion = $this->factura->direccion;
         $recibo->estado = 'Emitido';
         $recibo->fecha = $_POST['fecha'];
         $recibo->fechav = $_POST['fechav'];
         $recibo->idfactura = $_POST['idfactura'];
         $recibo->importe = floatval($_POST['importe']);
         $recibo->nombrecliente = $this->factura->nombrecliente;
         $recibo->provincia = $this->factura->provincia;
         $cbc = new cuenta_banco_cliente();
         foreach ($cbc->all_from_cliente($this->factura->codcliente) as $cuenta) {
             if (is_null($recibo->codcuenta) or $cuenta->principal) {
                 $recibo->codcuenta = $cuenta->codcuenta;
                 $recibo->iban = $cuenta->iban;
                 $recibo->swift = $cuenta->swift;
             }
         }
         if ($recibo->save()) {
             $this->new_message('Recibo creado correctamente.');
             header('Location: ' . $recibo->url());
         } else {
             $this->new_error_msg('Error al guardar el recibo.');
         }
     } else {
         $this->new_error_msg('Factura no encontrada.');
     }
 }
 private static function get_factura($idFactura)
 {
     $factura = new factura_cliente();
     return $factura->get($idFactura);
 }
 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;
     /// desactivamos la barra de botones
     $this->show_fs_toolbar = FALSE;
     if (isset($_POST['idfactura'])) {
         $this->factura = $factura->get($_POST['idfactura']);
         $this->factura->observaciones = $_POST['observaciones'];
         $this->factura->numero2 = $_POST['numero2'];
         $this->cambiar_numero_factura();
         /// 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);
         } else {
             $this->new_error_msg('No se encuentra el ejercicio asociado a la factura.');
         }
         if ($this->factura->save()) {
             $asiento = $this->factura->get_asiento();
             if ($asiento) {
                 $asiento->fecha = $_POST['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!");
     }
 }
 private function nuevo_asiento_devolucion()
 {
     $anular = new factura_cliente();
     $facturadev = new asiento_factura();
     if ($facturadev->nuevo_asiento_devolucion_cli($_REQUEST['idfaccli'])) {
         $anular->boton_anular($_REQUEST['idfaccli']);
     }
     $factura = new factura_cliente();
     $var_idpagodevol = $factura->get($_GET['id']);
     /// da el valor al botón
     $this->factura_anulada = $var_idpagodevol->idpagodevol;
 }
Example #17
0
 private function pagar_facturas()
 {
     $num = 0;
     /// ¿Generamos el asiento de pago?
     $asientop = NULL;
     if ($this->empresa->contintegrada) {
         /// ¿Cuanto es el total?
         $coddivisa = NULL;
         $importe = 0;
         $tasaconv = 1;
         $rec0 = new recibo_cliente();
         foreach ($_POST['idfactura'] as $id) {
             $recibos = $rec0->all_from_factura($id);
             foreach ($recibos as $recibo) {
                 if ($recibo->estado != 'Pagado') {
                     $coddivisa = $recibo->coddivisa;
                     $importe += $recibo->importe;
                     $tasaconv = $recibo->tasaconv;
                 }
             }
         }
         $asientop = $this->nuevo_asiento_pago($importe, $coddivisa, $tasaconv);
     }
     $fac0 = new factura_cliente();
     foreach ($_POST['idfactura'] as $id) {
         $error = FALSE;
         $recibos = $rec0->all_from_factura($id);
         foreach ($recibos as $recibo) {
             if ($recibo->estado != 'Pagado') {
                 $pago = new pago_recibo_cliente();
                 $pago->idrecibo = $recibo->idrecibo;
                 if ($asientop) {
                     $pago->idasiento = $asientop->idasiento;
                 }
                 if ($pago->save()) {
                     $recibo->estado = 'Pagado';
                     if (!$recibo->save()) {
                         $error = TRUE;
                     }
                 }
             }
         }
         if (!$error) {
             /// marcamos la factura como pagada
             $factura = $fac0->get($id);
             if ($factura) {
                 $factura->pagada = TRUE;
                 if ($factura->save()) {
                     $num++;
                 }
             }
         }
     }
     $this->new_message($num . ' facturas marcadas como pagadas, estas son las siguientes.');
 }
Example #18
0
 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();
     }
 }
 public function facturas_from_albaran($id)
 {
     $facturalist = array();
     $lineas = $this->db->select("SELECT DISTINCT idfactura FROM " . $this->table_name . " WHERE idalbaran = " . $this->var2str($id) . ";");
     if ($lineas) {
         $factura = new factura_cliente();
         foreach ($lineas as $l) {
             $facturalist[] = $factura->get($l['idfactura']);
         }
     }
     return $facturalist;
 }
 public function boton_anular($idfactura)
 {
     $factura = new factura_cliente();
     $fact = $factura->get($idfactura);
     if ($fact) {
         /// ¿Sumamos stock?
         $art0 = new articulo();
         $inventario = new inventario();
         foreach ($fact->get_lineas() as $linea) {
             if (is_null($linea->idalbaran)) {
                 $articulo = $art0->get($linea->referencia);
                 if ($articulo) {
                     $articulo->sum_stock($fact->codalmacen, $linea->cantidad);
                     $inventario->inventario_agregar($fact->codalmacen, $linea->referencia, $linea->cantidad, $linea->pvpunitario);
                 }
             }
         }
         $sql = "UPDATE " . $this->table_name . " SET idpagodevol = '1'   WHERE idfactura = " . $this->var2str($idfactura) . ";";
         if ($this->db->exec($sql)) {
             $this->idfactura = $this->db->lastval();
             return TRUE;
         } else {
             return FALSE;
         }
     } else {
         $this->new_error_msg("Factura no encontrada.");
     }
 }
Example #21
0
 protected function private_core()
 {
     $this->pagado = FALSE;
     $this->pago = new pago();
     $this->pagos = array();
     $this->pendiente = 0;
     if (isset($_GET['delete'])) {
         $pago = $this->pago->get($_GET['delete']);
         if ($pago) {
             if ($pago->delete()) {
                 $this->new_message('Pago eliminado correctamente.');
                 if (!is_null($pago->idfactura)) {
                     $fact0 = new factura_cliente();
                     $factura = $fact0->get($pago->idfactura);
                     if ($factura) {
                         if ($factura->pagada) {
                             $factura->pagada = FALSE;
                             $factura->save();
                         }
                     }
                 }
             } else {
                 $this->new_error_msg('Error al eliminar el pago.');
             }
         } else {
             $this->new_error_msg('Pago no encontrado.');
         }
     } else {
         if (isset($_POST['idpago'])) {
             $pago = $this->pago->get($_POST['idpago']);
             if ($pago) {
                 $pago->fecha = $_POST['fecha'];
                 $pago->importe = floatval($_POST['importe']);
                 $pago->nota = $_POST['nota'];
                 if ($pago->save()) {
                     $this->new_message('Pago modificado correctamente.');
                 } else {
                     $this->new_error_msg('Error al modificar el pago.');
                 }
             } else {
                 $this->new_error_msg('Pago no encontrado.');
             }
         } else {
             if (isset($_POST['importe'])) {
                 if (isset($_REQUEST['factura'])) {
                     $this->pago->fase = 'Factura';
                     $this->pago->idfactura = $_REQUEST['id'];
                 } else {
                     if (isset($_REQUEST['albaran'])) {
                         $this->pago->fase = ucfirst(FS_ALBARAN);
                         $this->pago->idalbaran = $_REQUEST['id'];
                     } else {
                         if (isset($_REQUEST['pedido'])) {
                             $this->pago->fase = ucfirst(FS_PEDIDO);
                             $this->pago->idpedido = $_REQUEST['id'];
                         }
                     }
                 }
                 $this->pago->fecha = $_POST['fecha'];
                 $this->pago->importe = floatval($_POST['importe']);
                 $this->pago->nota = $_POST['nota'];
                 if ($this->pago->save()) {
                     $this->new_message('Pago guardado correctamente.');
                 } else {
                     $this->new_error_msg('Error al guardar el pago.');
                 }
             }
         }
     }
     if (isset($_REQUEST['factura'])) {
         /// esto es la fase de factura
         $fact0 = new factura_cliente();
         $factura = $fact0->get($_REQUEST['id']);
         if ($factura) {
             /// buscamos pagos de la fase albarán
             /// una factura puede ser una agrupación de muchos albaranes
             $idalbaran = NULL;
             foreach ($factura->get_lineas() as $linea) {
                 /// el idalbaran lo tienes en las lineas de la factura
                 if ($linea->idalbaran != $idalbaran) {
                     $idalbaran = $linea->idalbaran;
                     $this->db->exec("UPDATE pagos SET idfactura = " . $fact0->var2str($_REQUEST['id']) . " WHERE idalbaran = " . $fact0->var2str($idalbaran) . ";");
                 }
             }
             $this->pagos = $this->pago->all_from_factura($_REQUEST['id']);
             $this->pendiente = $factura->total;
             foreach ($this->pagos as $i => $value) {
                 $this->pendiente -= $value->importe;
                 $this->pagos[$i]->pendiente = $this->pendiente;
             }
             /// si nos han pagado el total, marcamos la factura como pagada
             if (!$factura->pagada and abs($this->pendiente) < 0.1) {
                 $factura->pagada = TRUE;
                 $factura->save();
             }
             $this->pagado = $factura->pagada;
         }
     } else {
         if (isset($_REQUEST['albaran'])) {
             /// fase de albarán
             $this->pagos = $this->pago->all_from_albaran($_REQUEST['id']);
             /**
              * Falta poner el idalbaran a los pagos de los pedidos que forman este
              * albarán. Si es que hay.
              * Copia esto de la fase de factura.
              */
             $alb0 = new albaran_cliente();
             $albaran = $alb0->get($_REQUEST['id']);
             if ($albaran) {
                 $this->pendiente = $albaran->total;
                 foreach ($this->pagos as $i => $value) {
                     $this->pendiente -= $value->importe;
                     $this->pagos[$i]->pendiente = $this->pendiente;
                 }
                 if (abs($this->pendiente) < 0.1) {
                     $this->pagado = TRUE;
                 }
             }
         } else {
             if (isset($_REQUEST['pedido'])) {
                 /// fose de pedido
                 $this->pagos = $this->pago->all_from_pedido($_REQUEST['id']);
                 $ped0 = new pedido_cliente();
                 $pedido = $ped0->get($_REQUEST['id']);
                 if ($pedido) {
                     $this->pendiente = $pedido->total;
                     foreach ($this->pagos as $i => $value) {
                         $this->pendiente -= $value->importe;
                         $this->pagos[$i]->pendiente = $this->pendiente;
                     }
                     if (abs($this->pendiente) < 0.1) {
                         $this->pagado = TRUE;
                     }
                 }
             }
         }
     }
     $this->share_extensions();
 }
 private function enviar_email($doc, $tipo = 'ncf')
 {
     $factura = new factura_cliente();
     $factura_enviar = $factura->get($doc);
     if ($this->empresa->can_send_mail()) {
         if ($_POST['email'] != $this->cliente->email and isset($_POST['guardar'])) {
             $this->cliente->email = $_POST['email'];
             $this->cliente->save();
         }
         $filename = 'factura_' . $factura_enviar->numero2 . '.pdf';
         if ($tipo == 'ncf') {
             $this->procesar_facturas(array($factura_enviar->idfactura), $filename);
         }
         if (file_exists('tmp/' . FS_TMP_NAME . 'enviar/' . $filename)) {
             $mail = $this->empresa->new_mail();
             $mail->FromName = $this->user->get_agente_fullname();
             $mail->addReplyTo($_POST['de'], $mail->FromName);
             $mail->addAddress($_POST['email'], $this->cliente->razonsocial);
             if ($_POST['email_copia']) {
                 if (isset($_POST['cco'])) {
                     $mail->addBCC($_POST['email_copia'], $this->cliente->razonsocial);
                 } else {
                     $mail->addCC($_POST['email_copia'], $this->cliente->razonsocial);
                 }
             }
             $mail->Subject = $this->empresa->nombre . ': Su factura ' . $this->factura->codigo;
             $mail->AltBody = $_POST['mensaje'];
             $mail->msgHTML(nl2br($_POST['mensaje']));
             $mail->isHTML(TRUE);
             $mail->addAttachment('tmp/' . FS_TMP_NAME . 'enviar/' . $filename);
             if (is_uploaded_file($_FILES['adjunto']['tmp_name'])) {
                 $mail->addAttachment($_FILES['adjunto']['tmp_name'], $_FILES['adjunto']['name']);
             }
             if ($mail->smtpConnect($this->empresa->smtp_options())) {
                 if ($mail->send()) {
                     $this->template = 'ventas_imprimir';
                     $this->new_message('Mensaje enviado correctamente.');
                     /// nos guardamos la fecha de envío
                     $factura_enviar->femail = $this->today();
                     $factura_enviar->save();
                     $this->empresa->save_mail($mail);
                 } else {
                     $this->new_error_msg("Error al enviar el email: " . $mail->ErrorInfo);
                 }
             } else {
                 $this->new_error_msg("Error al enviar el email: " . $mail->ErrorInfo);
             }
             unlink('tmp/' . FS_TMP_NAME . 'enviar/' . $filename);
         } else {
             $this->new_error_msg('Imposible generar el PDF.');
         }
     }
 }
 public function extornar_factura()
 {
     $value_factura = \filter_input(INPUT_GET, 'factura');
     $lista_facturas = explode(',', $value_factura);
     $fact0 = new factura_cliente();
     foreach ($lista_facturas as $factura) {
         $datos_factura = explode('-', $value_factura);
         $factura = $fact0->get($datos_factura[0]);
         $num = 0;
         if ($factura) {
             $factura->pagada = FALSE;
             $factura->save();
             $num++;
         }
     }
     $data['success'] = TRUE;
     $data['facturas_procesadas'] = $num;
     $this->template = false;
     header('Content-Type: application/json');
     echo json_encode($data);
 }
Example #24
0
 public function delete()
 {
     if ($this->db->exec("DELETE FROM " . $this->table_name . " WHERE idalbaran = " . $this->var2str($this->idalbaran) . ";")) {
         if ($this->idfactura) {
             /**
              * Delegamos la eliminación de la factura en la clase correspondiente,
              * que tendrá que hacer más cosas.
              */
             $factura = new factura_cliente();
             $factura0 = $factura->get($this->idfactura);
             if ($factura0) {
                 $factura0->delete();
             }
         }
         return TRUE;
     } else {
         return FALSE;
     }
 }
Example #25
0
 protected function private_core()
 {
     /// ¿El usuario tiene permiso para eliminar en esta página?
     $this->allow_delete = $this->user->allow_delete_on(__CLASS__);
     $recibo = new recibo_cliente();
     $this->recibo = FALSE;
     if (isset($_REQUEST['id'])) {
         $this->recibo = $recibo->get($_REQUEST['id']);
     }
     if ($this->recibo) {
         if (isset($_POST['fechav'])) {
             $this->recibo->importe = floatval($_POST['importe']);
             $this->recibo->fecha = $_POST['emitido'];
             $this->recibo->fechav = $_POST['fechav'];
             $this->recibo->iban = $_POST['iban'];
             $this->recibo->swift = $_POST['swift'];
             if ($this->recibo->save()) {
                 $this->new_message('Datos guardados correctamente.');
             } else {
                 $this->new_error_msg('Error al guardar los datos.');
             }
         }
         $this->page->title = 'Recibo ' . $this->recibo->codigo;
         $fact = new factura_cliente();
         $this->factura = $fact->get($this->recibo->idfactura);
         $this->check_recibo();
         $this->get_subcuentas();
         $pago = new pago_recibo_cliente();
         if (isset($_POST['nuevopago'])) {
             $pago->idrecibo = $this->recibo->idrecibo;
             $pago->fecha = $_POST['fecha'];
             $pago->tipo = $_POST['tipo'];
             foreach ($this->subcuentas_pago as $sc) {
                 if ($sc->codsubcuenta == $_POST['codsubcuenta']) {
                     $pago->idsubcuenta = $sc->idsubcuenta;
                     $pago->codsubcuenta = $sc->codsubcuenta;
                 }
             }
             if ($pago->tipo == 'Pago') {
                 if ($this->empresa->contintegrada and isset($_POST['generarasiento'])) {
                     $pago->idasiento = $this->nuevo_asiento_pago($pago, $this->ejercicio);
                 }
                 $this->recibo->estado = 'Pagado';
                 $this->recibo->fechap = $_POST['fecha'];
             } else {
                 if ($this->empresa->contintegrada and isset($_POST['generarasiento'])) {
                     $pago->idasiento = $this->nuevo_asiento_devolucion($pago, $this->ejercicio);
                 }
                 $this->recibo->estado = 'Devuelto';
             }
             if ($pago->save()) {
                 $this->new_message('Pago guardado correctamente.');
                 $this->recibo->save();
             } else {
                 $this->new_error_msg('Error al guardar los pagos.');
             }
         } else {
             if (isset($_GET['deletep'])) {
                 foreach ($pago->all_from_recibo($this->recibo->idrecibo) as $pg) {
                     if ($pg->idpagodevol == intval($_GET['deletep'])) {
                         if ($pg->delete()) {
                             $this->new_message($pg->tipo . ' eliminado correctamente');
                             $this->recibo->estado = 'Emitido';
                             $this->recibo->save();
                         } else {
                             $this->new_error_msg('Error al eliminar el ' . $pg->tipo);
                         }
                         break;
                     }
                 }
             }
         }
         $this->pagos = $pago->all_from_recibo($this->recibo->idrecibo);
         $this->recibos = $this->recibo->all_from_factura($this->recibo->idfactura);
         $this->sync_factura();
     } else {
         $this->new_error_msg('Recibo no encontrado.');
     }
 }