139 lines
5.8 KiB
C#
139 lines
5.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace bdAsegasa.db
|
|
{
|
|
public partial class liquidacionesagentes
|
|
{
|
|
public double TotalFacturaSinIRPF
|
|
{
|
|
get
|
|
{
|
|
return Math.Round(BaseImponible + IVA, 2, MidpointRounding.AwayFromZero);
|
|
}
|
|
}
|
|
public string NumeroFacturaVF(string? PrefijoPruebas)
|
|
{
|
|
if (PrefijoPruebas != null)
|
|
{
|
|
|
|
return PrefijoPruebas + NumeroFactura;
|
|
}
|
|
else
|
|
{
|
|
return NumeroFactura;
|
|
}
|
|
}
|
|
public const string Prod = "https://www2.agenciatributaria.gob.es/wlpl/TIKE-CONT/ValidarQR";
|
|
public const string TestValidate = "https://prewww2.aeat.es/wlpl/TIKE-CONT/ValidarQR";
|
|
|
|
public string EnlaceQR
|
|
{
|
|
get
|
|
{
|
|
|
|
DateTime fechaCmp = this.Fecha != DateOnly.MinValue ? new DateTime(this.Fecha.Year, this.Fecha.Month, this.Fecha.Day) : DateTime.Now;
|
|
|
|
var confsi = enumeraciones.LConfsi?.Where(x => x.Fecha1.HasValue && x.Fecha1.Value <= fechaCmp).OrderByDescending(x => x.Fecha1).FirstOrDefault();
|
|
|
|
if (confsi != null)
|
|
{
|
|
if (confsi.ValorNumerico4 > 0)
|
|
{
|
|
return Prod + "?nif=" + this.idAgenteNavigation?.CIF + "&numserie=" + NumeroFactura + "&fecha=" + this.Fecha.ToString("dd-MM-yyyy") + "&importe=" + Math.Round(TotalFacturaSinIRPF, 2, MidpointRounding.AwayFromZero).ToString(System.Globalization.CultureInfo.InvariantCulture);
|
|
}
|
|
else
|
|
{
|
|
string nf = NumeroFacturaVF(confsi.ValorAlfabetico4);
|
|
return TestValidate + "?nif=" + this.idAgenteNavigation?.CIF + "&numserie=" + nf + "&fecha=" + this.Fecha.ToString("dd-MM-yyyy") + "&importe=" + Math.Round(TotalFacturaSinIRPF, 2, MidpointRounding.AwayFromZero).ToString(System.Globalization.CultureInfo.InvariantCulture);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
string nf = NumeroFacturaVF(null);
|
|
return TestValidate + "?nif=" + this.idAgenteNavigation?.CIF + "&numserie=" + nf + "&fecha=" + this.Fecha.ToString("dd-MM-yyyy") + "&importe=" + Math.Round(TotalFacturaSinIRPF, 2, MidpointRounding.AwayFromZero).ToString(System.Globalization.CultureInfo.InvariantCulture);
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool QRVisible
|
|
{
|
|
get
|
|
{
|
|
DateTime fechaCmp = this.Fecha != DateOnly.MinValue ? new DateTime(this.Fecha.Year, this.Fecha.Month, this.Fecha.Day) : DateTime.Now;
|
|
var confsi = enumeraciones.LConfsi?.Where(x => x.Fecha1.HasValue && x.Fecha1.Value <= fechaCmp).OrderByDescending(x => x.Fecha1).FirstOrDefault();
|
|
if (confsi != null)
|
|
{
|
|
return confsi.ValorNumerico4 > 0;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
public string DescripcionEstadoVerifactu
|
|
{
|
|
get
|
|
{
|
|
return EstadoVerifactu.ToString().Replace("_", " ");
|
|
}
|
|
}
|
|
|
|
public EstadoVerifactuEnum EstadoVerifactu
|
|
{
|
|
get
|
|
{
|
|
var bd = tscgestionasegasa.NuevoContexto();
|
|
var rvf = bd.registrosverifactu.Where(x => x.idAplicacion == idLiquidacionAgente).OrderByDescending(x => x.idRegistro).FirstOrDefault();
|
|
if (rvf != null)
|
|
{
|
|
return (EstadoVerifactuEnum)(rvf.Estado);
|
|
}
|
|
else
|
|
{
|
|
return EstadoVerifactuEnum.SIN_REGISTROS;
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum EstadoVerifactuEnum
|
|
{
|
|
PENDIENTE_RESPUESTA = 0,
|
|
CORRECTO = 1,
|
|
ACEPTADO_CON_ERRORES = 2,
|
|
INCORRECTO = 3,
|
|
COMPLETADO = 10,
|
|
SIN_REGISTROS = 100
|
|
}
|
|
|
|
public string ObtieneNumeroFactura()
|
|
{
|
|
var bd = tscgestionasegasa.NuevoContexto();
|
|
int AnoAct = DateTime.Today.Year;
|
|
if (this.FechaFactura.HasValue && this.FechaFactura.Value.Year < 2026)
|
|
{
|
|
var UltimaLiquidacion = bd.liquidacionesagentes.Where(x => x.FechaFactura.HasValue && x.FechaFactura.Value.Year == AnoAct).OrderByDescending(x => x.NumeroFactura).FirstOrDefault();
|
|
int UltimaFactura = 1;
|
|
if (UltimaLiquidacion != null && !string.IsNullOrEmpty(UltimaLiquidacion.NumeroFactura) && UltimaLiquidacion.NumeroFactura.Contains("-"))
|
|
UltimaFactura = int.Parse(UltimaLiquidacion.NumeroFactura.Split('-')[1]) + 1;
|
|
return DateTime.Today.Year.ToString() + "-" + UltimaFactura.ToString().PadLeft(5, '0');
|
|
}
|
|
else
|
|
{
|
|
var UltimaLiquidacion = bd.liquidacionesagentes.Where(x => x.FechaFactura.HasValue && x.FechaFactura.Value.Year == AnoAct && x.idSerieFactura == this.idSerieFactura).OrderByDescending(x => x.NumeroFactura).FirstOrDefault();
|
|
int UltimaFactura = 1;
|
|
if (UltimaLiquidacion != null && !string.IsNullOrEmpty(UltimaLiquidacion.NumeroFactura) && UltimaLiquidacion.NumeroFactura.Contains("-"))
|
|
UltimaFactura = int.Parse(UltimaLiquidacion.NumeroFactura.Split('-')[1].Substring(2)) + 1;
|
|
var sf = bd.seriesfacturas.First(x => x.idSerieFactura == idSerieFactura).Serie;
|
|
return sf + "-" + DateTime.Today.Year.ToString().Substring(2) + UltimaFactura.ToString().PadLeft(5, '0');
|
|
}
|
|
}
|
|
}
|
|
}
|