Private
Public Access
hecha funcionalidad de modificacion/cancelacion de facturas
Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
1 parent
94a4e292c4
commit
6331e16dc5
39 files changed
+2283
-104
No files matched your search
@@ -44,6 +44,91 @@ func RegistrarAsientoVenta(
|
||||
return repo.Contabilidad.CrearAsientoConMovimientos(tx, asiento)
|
||||
}
|
||||
|
||||
// RegistrarAsientoNotaCredito registra el reverso parcial o total de una venta.
|
||||
// El importe de la nota incluye IVA; se separa la base imponible para que las
|
||||
// cuentas de resultado y de IVA queden consistentes.
|
||||
func RegistrarAsientoNotaCredito(
|
||||
tx *gorm.DB,
|
||||
repo *repositorios.Repositorios,
|
||||
nota *models.NotaCredito,
|
||||
alicuota float64,
|
||||
) error {
|
||||
if nota == nil {
|
||||
return gorm.ErrInvalidValue
|
||||
}
|
||||
|
||||
base, impuesto := desglosarImporteConIVA(nota.Total, alicuota)
|
||||
asiento := &contabilidad.AsientoContable{
|
||||
ComprobanteTipo: "NOTA_CREDITO",
|
||||
ComprobanteID: nota.ID,
|
||||
}
|
||||
|
||||
if err := agregarMovimiento(tx, repo, asiento, "Clientes", "activo", 0, nota.Total, "Nota de crédito a clientes"); err != nil {
|
||||
return err
|
||||
}
|
||||
if base > 0 {
|
||||
if err := agregarMovimiento(tx, repo, asiento, "Devoluciones sobre ventas", "resultado", base, 0, "Devolución sobre ventas"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if impuesto > 0 {
|
||||
if err := agregarMovimiento(tx, repo, asiento, "IVA Débito Fiscal", "pasivo", impuesto, 0, "IVA de nota de crédito"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return repo.Contabilidad.CrearAsientoConMovimientos(tx, asiento)
|
||||
}
|
||||
|
||||
// RegistrarAsientoNotaDebito registra el incremento de la venta por un ajuste
|
||||
// posterior a la emisión de la factura.
|
||||
func RegistrarAsientoNotaDebito(
|
||||
tx *gorm.DB,
|
||||
repo *repositorios.Repositorios,
|
||||
nota *models.NotaDebito,
|
||||
alicuota float64,
|
||||
) error {
|
||||
if nota == nil {
|
||||
return gorm.ErrInvalidValue
|
||||
}
|
||||
|
||||
base, impuesto := desglosarImporteConIVA(nota.Total, alicuota)
|
||||
asiento := &contabilidad.AsientoContable{
|
||||
ComprobanteTipo: "NOTA_DEBITO",
|
||||
ComprobanteID: nota.ID,
|
||||
}
|
||||
|
||||
if err := agregarMovimiento(tx, repo, asiento, "Clientes", "activo", nota.Total, 0, "Nota de débito a clientes"); err != nil {
|
||||
return err
|
||||
}
|
||||
if base > 0 {
|
||||
if err := agregarMovimiento(tx, repo, asiento, "Ventas", "resultado", 0, base, "Ingreso adicional por ventas"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if impuesto > 0 {
|
||||
if err := agregarMovimiento(tx, repo, asiento, "IVA Débito Fiscal", "pasivo", 0, impuesto, "IVA de nota de débito"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return repo.Contabilidad.CrearAsientoConMovimientos(tx, asiento)
|
||||
}
|
||||
|
||||
// desglosarImporteConIVA separa un importe final en base imponible e IVA.
|
||||
func desglosarImporteConIVA(total, alicuota float64) (base, impuesto float64) {
|
||||
if total <= 0 {
|
||||
return 0, 0
|
||||
}
|
||||
if alicuota < 0 {
|
||||
alicuota = 0
|
||||
}
|
||||
divisor := 1 + alicuota/100
|
||||
base = redondearMonto(total / divisor)
|
||||
impuesto = redondearMonto(total - base)
|
||||
return base, impuesto
|
||||
}
|
||||
|
||||
func agregarMovimiento(
|
||||
tx *gorm.DB,
|
||||
repo *repositorios.Repositorios,
|
||||
|
||||
Reference in new issue
Block a user