Beispiel #1
0
 protected function process()
 {
     $this->albaran = FALSE;
     $this->articulo_proveedor = new articulo_proveedor();
     $this->proveedor = FALSE;
     $this->factura = FALSE;
     $this->impuesto = new impuesto();
     if (isset($_REQUEST['albaran']) and isset($_REQUEST['id'])) {
         $alb = new albaran_proveedor();
         $this->albaran = $alb->get($_REQUEST['id']);
         if ($this->albaran) {
             $proveedor = new proveedor();
             $this->proveedor = $proveedor->get($this->albaran->codproveedor);
         }
         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_proveedor();
             $this->factura = $fac->get($_REQUEST['id']);
             if ($this->factura) {
                 $proveedor = new proveedor();
                 $this->proveedor = $proveedor->get($this->factura->codproveedor);
             }
             $this->generar_pdf_factura();
         }
     }
     $this->share_extensions();
 }
 protected function process()
 {
     $this->albaran = FALSE;
     $this->articulo_proveedor = new articulo_proveedor();
     $this->proveedor = FALSE;
     $this->factura = FALSE;
     $this->impuesto = new impuesto();
     $this->fecha_hoy = Date('d-m-Y');
     if (isset($_REQUEST['albaran']) and isset($_REQUEST['id'])) {
         $alb = new albaran_proveedor();
         $this->albaran = $alb->get($_REQUEST['id']);
         if ($this->albaran) {
             $proveedor = new proveedor();
             $this->proveedor = $proveedor->get($this->albaran->codproveedor);
         }
         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_proveedor();
             $this->factura = $fac->get($_REQUEST['id']);
             if ($this->factura) {
                 $proveedor = new proveedor();
                 $this->proveedor = $proveedor->get($this->factura->codproveedor);
             }
             $this->generar_pdf_factura();
         } else {
             if (isset($_REQUEST['ordenes'])) {
                 if ($_GET['forma'] == '1') {
                     $desde = $_GET['desde'];
                     $hasta = $_GET['hasta'];
                     $proveedor = $_GET['proveedor'];
                     $codproveedor = $_GET['codproveedor'];
                     $this->imprimir_ordenes($desde, $hasta, $proveedor, $codproveedor);
                 } else {
                     if (isset($_GET['forma']) == 2) {
                         $idorden = $_GET['idorden'];
                         $this->imprimir_ordenes_indiv($idorden);
                     }
                 }
             } else {
                 if (isset($_REQUEST['anticipos'])) {
                     $idanticipo = $_GET['idanticipo'];
                     $this->imprimir_anticipo($idanticipo);
                 }
             }
         }
     }
     $this->share_extensions();
 }
 protected function private_core()
 {
     $this->share_extension();
     $this->serie = new serie();
     $this->ncf_tipo_anulacion = new ncf_tipo_anulacion();
     $fact0 = new factura_proveedor();
     $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.');
     }
 }
 protected function private_core()
 {
     $this->albaran = FALSE;
     $this->articulo_proveedor = new articulo_proveedor();
     $this->proveedor = 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_proveedor();
         $this->albaran = $alb->get($_REQUEST['id']);
         if ($this->albaran) {
             $proveedor = new proveedor();
             $this->proveedor = $proveedor->get($this->albaran->codproveedor);
         }
         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_proveedor();
             $this->factura = $fac->get($_REQUEST['id']);
             if ($this->factura) {
                 $proveedor = new proveedor();
                 $this->proveedor = $proveedor->get($this->factura->codproveedor);
             }
             $this->generar_pdf_factura();
         }
     }
     $this->share_extensions();
 }
Beispiel #5
0
 protected function process()
 {
     $this->show_fs_toolbar = FALSE;
     $this->serie = new serie();
     $this->share_extensions();
     if (isset($_REQUEST['buscar_proveedor'])) {
         $this->buscar_proveedor();
     }
     $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->codproveedor = FALSE;
     if (!isset($_POST['todos']) and isset($_POST['codproveedor'])) {
         $this->codproveedor = $_POST['codproveedor'];
     }
     $this->codserie = FALSE;
     if (isset($_POST['codserie'])) {
         $this->codserie = $_POST['codserie'];
     }
     /// ¿Marcamos ya las facturas?
     if (isset($_POST['idfactura'])) {
         $num = 0;
         $fact0 = new factura_proveedor();
         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();
     }
 }
 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_proveedor();
         foreach ($lineas as $l) {
             $facturalist[] = $factura->get($l['idfactura']);
         }
     }
     return $facturalist;
 }
Beispiel #7
0
 protected function process()
 {
     $this->ppage = $this->page->get('compras_facturas');
     $this->agente = FALSE;
     $this->ejercicio = new ejercicio();
     $factura = new factura_proveedor();
     $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;
         }
     }
     if (isset($_POST['idfactura'])) {
         $this->factura = $factura->get($_POST['idfactura']);
         $this->factura->numproveedor = $_POST['numproveedor'];
         $this->factura->observaciones = $_POST['observaciones'];
         $this->factura->codpago = $_POST['forma_pago'];
         /// 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.');
         }
         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 Proveedor ' . $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;
         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($_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();
         /// cargamos el agente
         if (!is_null($this->factura->codagente)) {
             $agente = new agente();
             $this->agente = $agente->get($this->factura->codagente);
         }
     } else {
         $this->new_error_msg("¡Factura de proveedor no encontrada!");
     }
 }
 public function boton_restab_anulada($idfactura)
 {
     $factura = new factura_proveedor();
     $fact = $factura->get($idfactura);
     if ($fact) {
         /// ¿Descontamos 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, TRUE);
                     $inventario->inventario_agregar($fact->codalmacen, $linea->referencia, $linea->cantidad, $linea->pvpunitario);
                 }
             }
         }
         $sql = "UPDATE facturasprov SET idpagodevol = '0'   WHERE idfactura = " . $_GET['id'] . ";";
         if ($this->db->exec($sql)) {
             $this->idfactura = $this->db->lastval();
             return TRUE;
         } else {
             return FALSE;
         }
     } else {
         $this->new_error_msg("Factura no encontrada.");
     }
 }
 private function restab_anulada()
 {
     $anular = new factura_proveedor();
     $anular->boton_restab_anulada($_REQUEST['id']);
     $factura = new factura_proveedor();
     $var_idpagodevol = $factura->get($_REQUEST['id']);
     $this->factura_anulada = $var_idpagodevol->idpagodevol;
 }
 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_proveedor();
         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_proveedor();
     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_proveedor();
                 $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.');
 }
Beispiel #11
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_proveedor();
                     $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_proveedor();
         $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_proveedor();
             $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_proveedor();
                 $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();
 }
 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->codproveedor = FALSE;
     if (!isset($_POST['todos']) and isset($_POST['codproveedor'])) {
         $this->codproveedor = $_POST['codproveedor'];
         $pro0 = new proveedor();
         $this->proveedor = $pro0->get($this->codproveedor);
     }
     $this->serie = new serie();
     $this->codserie = FALSE;
     if (isset($_POST['codserie'])) {
         $this->codserie = $_POST['codserie'];
     }
     if (isset($_REQUEST['buscar_proveedor'])) {
         $this->buscar_proveedor();
     } 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_proveedor();
                 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 nuevo_asiento_devolucion_prov($id)
 {
     $varfactura = new factura_proveedor();
     $factura = $varfactura->get($_REQUEST['id']);
     // con id toma de factura codproveedor,codejercicio, url(),codigo factura, nombreproveeedor fecha total
     $ok = FALSE;
     $this->asiento = FALSE;
     $proveedor0 = new proveedor();
     $subcuenta_prov = FALSE;
     // toma de proveedor subcuenta con el codejercicio
     $proveedor = $proveedor0->get($factura->codproveedor);
     if ($proveedor) {
         $subcuenta_prov = $proveedor->get_subcuenta($factura->codejercicio);
     }
     if (!$subcuenta_prov) {
         $eje0 = $this->ejercicio->get($factura->codejercicio);
         $this->new_message("No se ha podido generar una subcuenta para el proveedor ");
         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;
         $concepto_fact = $this->fact_tipo_num($factura->numproveedor, $factura->nombre);
         $asiento->concepto = "Nota de crédito " . $factura->codigo . " - " . $factura->nombre;
         $asiento->documento = $factura->codigo;
         $asiento->editable = TRUE;
         $asiento->fecha = $factura->fecha;
         $asiento->importe = $factura->total;
         $asiento->tipodocumento = "Egreso proveedor";
         if ($asiento->save()) {
             $asiento_correcto = TRUE;
             $subcuenta = new subcuenta();
             $partida0 = new partida();
             $lineas_f = new linea_factura_proveedor();
             $lineas_fact = $lineas_f->all_from_factura($factura->idfactura);
             //		 $subcuenta_compras = $subcuenta->get_cuentaesp('DEVCOM', $asiento->codejercicio);
             $partida2 = new partida();
             $partida2->idasiento = $asiento->idasiento;
             $partida2->concepto = $asiento->concepto;
             $partida2->idsubcuenta = $subcuenta_prov->idsubcuenta;
             $partida2->codsubcuenta = $subcuenta_prov->codsubcuenta;
             ///////// Proveedor compra debe  ////////////////////////
             $partida2->debe = $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 . "!");
             }
             //////////////////////////////////////////////////////////
             ///  Separa las subcuentas de las facturas y crea los asientos
             //////////////////////////////////////////////////////////
             for ($i = 0; $i < count($lineas_fact); $i++) {
                 $total_sub = 0;
                 $finaliza = 0;
                 $subcuenta1 = $lineas_fact[$i]->codsubcuenta;
                 $idsubcuen = $lineas_fact[$i]->idsubcuenta;
                 for ($j = 0; $j < $i; $j++) {
                     if ($subcuenta1 == $lineas_fact[$j]->codsubcuenta) {
                         $finaliza = 1;
                     }
                 }
                 if ($finaliza == 0) {
                     for ($k = 0; $k < count($lineas_fact); $k++) {
                         if ($subcuenta1 == $lineas_fact[$k]->codsubcuenta) {
                             $total_sub = $total_sub + $lineas_fact[$k]->pvptotal;
                         }
                     }
                     /////// Acá se genera la partida con cada subcuenta
                     $subcuenta_compras = $subcuenta->get_cuentaesp('DEVCOM', $asiento->codejercicio);
                     $partida0->idasiento = $asiento->idasiento;
                     $partida0->concepto = $asiento->concepto;
                     $partida0->idsubcuenta = $idsubcuen;
                     $partida0->codsubcuenta = $subcuenta1;
                     ///////////  Proveedor  haber			/////////
                     $partida0->haber = $total_sub;
                     $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 ($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!");
                 }
             }
         }
     }
     return $ok;
 }
 protected function process()
 {
     $this->ppage = $this->page->get('compras_facturas');
     $this->agente = FALSE;
     $this->ejercicio = new ejercicio();
     $factura = new factura_proveedor();
     $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->numproveedor = $_POST['numproveedor'];
         $this->factura->observaciones = $_POST['observaciones'];
         /// 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 Proveedor ' . $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;
         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($_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();
         /// cargamos el agente
         if (!is_null($this->factura->codagente)) {
             $agente = new agente();
             $this->agente = $agente->get($this->factura->codagente);
         }
     } else {
         $this->new_error_msg("¡Factura de proveedor no encontrada!");
     }
 }
 private function nuevo_recibo()
 {
     $factura = new factura_proveedor();
     $this->factura = $factura->get($_POST['idfactura']);
     if ($this->factura) {
         $recibo = new recibo_proveedor();
         $recibo->cifnif = $this->factura->cifnif;
         $recibo->coddivisa = $this->factura->coddivisa;
         $recibo->tasaconv = $this->factura->tasaconv;
         $recibo->codpago = $this->factura->codpago;
         $recibo->codproveedor = $this->factura->codproveedor;
         $recibo->codserie = $this->factura->codserie;
         $recibo->estado = 'Emitido';
         $recibo->fecha = $_POST['fecha'];
         $recibo->fechav = $_POST['fechav'];
         $recibo->idfactura = $this->factura->idfactura;
         $recibo->importe = floatval($_POST['importe']);
         $recibo->nombreproveedor = $this->factura->nombre;
         $recibo->numero = $recibo->new_numero($recibo->idfactura);
         $recibo->codigo = $this->factura->codigo . '-' . sprintf('%02s', $recibo->numero);
         $cbp = new cuenta_banco_proveedor();
         foreach ($cbp->all_from_proveedor($recibo->codproveedor) 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.');
     }
 }
 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('compras_facturas');
     $this->agente = FALSE;
     $this->divisa = new divisa();
     $this->ejercicio = new ejercicio();
     $factura = new factura_proveedor();
     $this->factura = FALSE;
     $this->forma_pago = new forma_pago();
     $this->proveedor = FALSE;
     $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;
         }
     }
     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
         if (!is_null($this->factura->codagente)) {
             $agente = new agente();
             $this->agente = $agente->get($this->factura->codagente);
         }
         /// cargamos el proveedor
         $proveedor = new proveedor();
         $this->proveedor = $proveedor->get($this->factura->codproveedor);
         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($_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 proveedor no encontrada!");
     }
 }
 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_proveedor();
             $factura0 = $factura->get($this->idfactura);
             if ($factura0) {
                 $factura0->delete();
             }
         }
         return TRUE;
     } else {
         return FALSE;
     }
 }
 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_proveedor();
     $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_proveedor();
         $this->factura = $fact->get($this->recibo->idfactura);
         $this->check_recibo();
         $this->get_subcuentas();
         $pago = new pago_recibo_proveedor();
         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.');
     }
 }