2026-04-08 12:31:02 +00:00
|
|
|
package internal
|
|
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
|
|
|
|
|
type InvoiceData struct {
|
|
|
|
|
Tipo string
|
|
|
|
|
EmisorNIF string
|
|
|
|
|
NumSerie string
|
|
|
|
|
Fecha time.Time
|
|
|
|
|
TipoFactura string
|
|
|
|
|
Descripcion string
|
|
|
|
|
Destinatario *Destinatario
|
|
|
|
|
IVA []IVARegularizacion
|
|
|
|
|
CuotaTotal float64
|
|
|
|
|
ImporteTotal float64
|
|
|
|
|
Sistema Sistema
|
|
|
|
|
FechaGen time.Time
|
|
|
|
|
Huella string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Destinatario struct {
|
|
|
|
|
Nombre string
|
|
|
|
|
NIF string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type IVARegularizacion struct {
|
|
|
|
|
Base float64
|
|
|
|
|
Cuota float64
|
|
|
|
|
Tipo float64
|
|
|
|
|
ClaveRegimen string
|
|
|
|
|
Calificacion string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Sistema struct {
|
|
|
|
|
Nombre string
|
|
|
|
|
NIFProveedor string
|
|
|
|
|
NombreSistema string
|
|
|
|
|
IDSistema string
|
|
|
|
|
Version string
|
|
|
|
|
NumeroInstalacion string
|
|
|
|
|
TipoUsoVerifactu string
|
|
|
|
|
TipoUsoMultiOT string
|
|
|
|
|
IndicadorMultiOT string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TransformToInvoiceData(in *InvoiceInput) (*InvoiceData, error) {
|
|
|
|
|
fecha, _ := time.Parse("02-01-2006", in.Factura.FechaExpedicion)
|
|
|
|
|
|
|
|
|
|
destinatario := in.Factura.Destinatario
|
|
|
|
|
var dest *Destinatario
|
|
|
|
|
if destinatario != nil {
|
|
|
|
|
dest = &Destinatario{
|
|
|
|
|
Nombre: destinatario.Nombre,
|
|
|
|
|
NIF: destinatario.NIF,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ivaList := make([]IVARegularizacion, len(in.Factura.IVA))
|
|
|
|
|
for i, iva := range in.Factura.IVA {
|
|
|
|
|
ivaList[i] = IVARegularizacion{
|
|
|
|
|
Base: iva.Base,
|
|
|
|
|
Cuota: iva.Cuota,
|
|
|
|
|
Tipo: iva.Tipo,
|
|
|
|
|
ClaveRegimen: "01",
|
|
|
|
|
Calificacion: "S1",
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cuotaTotal := 0.0
|
|
|
|
|
for _, iva := range in.Factura.IVA {
|
|
|
|
|
cuotaTotal += iva.Cuota
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-17 11:03:06 +00:00
|
|
|
descripcion := in.Factura.Descripcion
|
|
|
|
|
if descripcion == "" {
|
|
|
|
|
descripcion = "Factura"
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-08 12:31:02 +00:00
|
|
|
sistema := Sistema{
|
|
|
|
|
Nombre: in.Sistema.Nombre,
|
|
|
|
|
NIFProveedor: in.Sistema.NIFProveedor,
|
|
|
|
|
NombreSistema: in.Sistema.Nombre,
|
|
|
|
|
IDSistema: "1",
|
|
|
|
|
Version: in.Sistema.Version,
|
|
|
|
|
NumeroInstalacion: "1",
|
|
|
|
|
TipoUsoVerifactu: "S",
|
|
|
|
|
TipoUsoMultiOT: "N",
|
|
|
|
|
IndicadorMultiOT: "N",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &InvoiceData{
|
|
|
|
|
Tipo: in.Tipo,
|
|
|
|
|
EmisorNIF: in.Factura.EmisorNIF,
|
|
|
|
|
NumSerie: in.Factura.NumSerie,
|
|
|
|
|
Fecha: fecha,
|
|
|
|
|
TipoFactura: in.Factura.TipoFactura,
|
2026-04-17 11:03:06 +00:00
|
|
|
Descripcion: descripcion,
|
2026-04-08 12:31:02 +00:00
|
|
|
Destinatario: dest,
|
|
|
|
|
IVA: ivaList,
|
|
|
|
|
CuotaTotal: cuotaTotal,
|
|
|
|
|
ImporteTotal: in.Factura.ImporteTotal,
|
|
|
|
|
Sistema: sistema,
|
|
|
|
|
FechaGen: time.Now(),
|
|
|
|
|
}, nil
|
|
|
|
|
}
|