private function generar_asiento(&$factura)
 {
     if ($this->empresa->contintegrada) {
         $genero = 0;
         $asiento_factura = new asiento_factura();
         if ($factura->tipo == 'Q' || $factura->tipo == 'C') {
             if ($asiento_factura->generar_asiento_compra_credito($factura)) {
                 $genero = 1;
             }
         } else {
             if ($asiento_factura->generar_asiento_compra($factura)) {
                 $genero = 1;
             }
         }
         if ($genero == 1) {
             $this->new_message("<a href='" . $factura->url() . "'>Factura</a> generada correctamente.");
         }
         foreach ($asiento_factura->errors as $err) {
             $this->new_error_msg($err);
         }
         foreach ($asiento_factura->messages as $msg) {
             $this->new_message($msg);
         }
     } else {
         $this->new_message("<a href='" . $factura->url() . "'>Factura</a> generada correctamente.");
     }
     $this->new_change('Factura Proveedor ' . $factura->codigo, $factura->url(), TRUE);
 }
 private function generar_asiento_credito()
 {
     // toma un asiento existente con su id
     if ($this->factura->get_asiento()) {
         $this->new_error_msg('Ya hay un asiento asociado a esta factura.');
     } else {
         $asiento_factura = new asiento_factura();
         $asiento_factura->soloasiento = TRUE;
         // Genera la partida que está en asiento_factura
         if ($asiento_factura->generar_asiento_compra_credito($this->factura)) {
             $this->new_message("<a href='" . $asiento_factura->asiento->url() . "'>Asiento</a> generado correctamente.");
             $this->new_change('Factura Proveedor ' . $this->factura->codigo, $this->factura->url());
         }
         foreach ($asiento_factura->errors as $err) {
             $this->new_error_msg($err);
         }
         foreach ($asiento_factura->messages as $msg) {
             $this->new_message($msg);
         }
     }
 }