private function generar_asiento($factura)
 {
     if ($this->empresa->contintegrada) {
         $asiento_factura = new asiento_factura();
         if ($asiento_factura->generar_asiento_venta($factura)) {
             $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 Cliente ' . $factura->codigo, $factura->url(), TRUE);
 }
 private function generar_asiento($factura)
 {
     if ($this->empresa->contintegrada) {
         $asiento_factura = new asiento_factura();
         $asiento_factura->generar_asiento_venta($factura);
         foreach ($asiento_factura->errors as $err) {
             $this->new_error_msg($err);
         }
         foreach ($asiento_factura->messages as $msg) {
             $this->new_message($msg);
         }
     }
 }
 /**
  * Genera el asiento para la factura, si procede
  * @param factura_cliente $factura
  */
 private function generar_asiento(&$factura)
 {
     if ($this->empresa->contintegrada) {
         $asiento_factura = new asiento_factura();
         $asiento_factura->generar_asiento_venta($factura);
         foreach ($asiento_factura->errors as $err) {
             $this->new_error_msg($err);
         }
         foreach ($asiento_factura->messages as $msg) {
             $this->new_message($msg);
         }
     } else {
         /// de todas formas forzamos la generación de las líneas de iva
         $factura->get_lineas_iva();
     }
 }
 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();
     }
 }
Beispiel #5
0
 private function generar_asiento()
 {
     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;
         if ($asiento_factura->generar_asiento_venta($this->factura)) {
             $this->new_message("<a href='" . $asiento_factura->asiento->url() . "'>Asiento</a> generado correctamente.");
             $this->new_change('Factura Cliente ' . $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);
         }
     }
 }
 private function pagar($pagada = TRUE)
 {
     /// ¿Hay asiento?
     if (is_null($this->factura->idasiento)) {
         $this->factura->pagada = $pagada;
         $this->factura->save();
     } else {
         if (!$pagada and $this->factura->pagada) {
             /// marcar como impagada
             $this->factura->pagada = FALSE;
             /// ¿Eliminamos el asiento de pago?
             $as1 = new asiento();
             $asiento = $as1->get($this->factura->idasientop);
             if ($asiento) {
                 $asiento->delete();
                 $this->new_message('Asiento de pago eliminado.');
             }
             $this->factura->idasientop = NULL;
             if ($this->factura->save()) {
                 $this->new_message('Factura marcada como impagada.');
             } else {
                 $this->new_error_msg('Error al modificar la factura.');
             }
         } else {
             if ($pagada and !$this->factura->pagada) {
                 /// marcar como pagada
                 $asiento = $this->factura->get_asiento();
                 if ($asiento) {
                     /// nos aseguramos que el cliente tenga subcuenta en el ejercicio actual
                     $subcli = FALSE;
                     $eje = $this->ejercicio->get_by_fecha($this->today());
                     if ($eje) {
                         $subcli = $this->cliente->get_subcuenta($eje->codejercicio);
                     }
                     $asiento_factura = new asiento_factura();
                     $this->factura->idasientop = $asiento_factura->generar_asiento_pago($asiento, $this->factura->codpago, $this->today(), $subcli);
                     if ($this->factura->idasientop) {
                         $this->factura->pagada = TRUE;
                         if ($this->factura->save()) {
                             $this->new_message('<a href="' . $this->factura->asiento_pago_url() . '">Asiento de pago</a> generado.');
                         } else {
                             $this->new_error_msg('Error al marcar la factura como pagada.');
                         }
                     }
                     foreach ($asiento_factura->errors as $err) {
                         $this->new_error_msg($err);
                     }
                 } else {
                     $this->new_error_msg('No se ha encontrado el asiento de la factura.');
                 }
             }
         }
     }
 }
 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 delete_factura()
 {
     $delete = \filter_input(INPUT_GET, 'delete');
     $fact = $this->factura->get($delete);
     $motivo = \filter_input(INPUT_POST, 'motivo');
     $fecha = \filter_input(INPUT_POST, 'fecha');
     $motivo_anulacion = $this->ncf_tipo_anulacion->get($motivo);
     if ($fact) {
         $albaranes = new albaran_cliente();
         /// ¿Sumamos stock?
         $art0 = new articulo();
         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);
                 }
             } else {
                 $idalbaran = $linea->idalbaran;
             }
         }
         if ($idalbaran) {
             $albaran0 = $albaranes->get($idalbaran);
             $new_albaran = clone $albaran0;
             $new_albaran->idalbaran = null;
             $new_albaran->idfactura = null;
             $new_albaran->observaciones = ucfirst(FS_ALBARAN) . " " . $albaran0->codigo . " anulado por eliminación de la factura asociada " . $fact->codigo;
             $new_albaran->fecha = $fecha;
             $new_albaran->neto = $new_albaran->neto * -1;
             $new_albaran->total = $new_albaran->total * -1;
             $new_albaran->totaliva = $new_albaran->totaliva * -1;
             $new_albaran->hora = \date('H:i:s');
             if ($new_albaran->save()) {
                 $linea0 = new linea_albaran_cliente();
                 $new_albaran_lineas = $linea0->all_from_albaran($idalbaran);
                 foreach ($new_albaran_lineas as $linea) {
                     $linea->idalbaran = $new_albaran->idalbaran;
                     $linea->idfactura = null;
                     $linea->idlinea = null;
                     $linea->cantidad = $linea->cantidad * -1;
                     $linea->pvptotal = $linea->pvptotal * -1;
                     $linea->pvpsindto = $linea->pvpsindto * -1;
                     $linea->save();
                 }
             }
         }
         $ncf0 = $this->ncf_ventas->get_ncf($this->empresa->id, $fact->idfactura, $fact->codcliente);
         $ncf0->motivo = $motivo_anulacion->codigo . " " . $motivo_anulacion->descripcion;
         $ncf0->estado = FALSE;
         $ncf0->usuario_modificacion = $this->user->nick;
         $ncf0->fecha_modificacion = Date('d-m-Y H:i:s');
         if ($ncf0->anular()) {
             $asiento_factura = new asiento_factura();
             $asiento_factura->soloasiento = TRUE;
             $fact_rectifica = $fact->idfacturarect;
             $factrectifica = !empty($fact->idfacturarect) ? $fact_rectifica : 'NULL';
             $fact->idfacturarect = $ncf0->tipo_comprobante == '04' ? null : $fact->idfactura;
             if ($asiento_factura->generar_asiento_venta($fact)) {
                 $this->db->exec("UPDATE facturascli set observaciones = '" . ucfirst(FS_FACTURA) . " eliminada por: " . $motivo_anulacion->descripcion . "', anulada = true, pagada = true, neto = 0, total = 0, totalirpf = 0, totaleuros = 0, totaliva = 0, idfacturarect = " . $factrectifica . " where idfactura = " . $fact->idfactura . ";");
                 $this->db->exec("DELETE FROM lineasivafactcli where idfactura = " . $fact->idfactura);
                 $fact_lineas = new linea_factura_cliente();
                 $lineas_fact = $fact_lineas->all_from_factura($fact->idfactura);
                 foreach ($lineas_fact as $linea) {
                     $linea->delete();
                 }
                 $fact->get_lineas_iva();
                 $this->new_message("<a href='" . $asiento_factura->asiento->url() . "'>Asiento</a> reversado correctamente.");
             }
             $this->new_message("<a href='" . $fact->url() . "'>Factura</a> cambiada a estado anulada por error correctamente.");
         } else {
             $this->new_error_msg("¡Imposible eliminar la factura!");
         }
     } else {
         $this->new_error_msg("Factura no encontrada.");
     }
 }
 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);
         }
     }
 }