550 lines
24 KiB
C#
550 lines
24 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using tsUtilidades.Extensiones;
|
|
|
|
namespace bdAsegasa.db
|
|
{
|
|
public partial class asientos
|
|
{
|
|
public enum TipoAsiento : int
|
|
{
|
|
NORMAL = 0,
|
|
APERTURA = 1,
|
|
REGULARIZACION = 2
|
|
}
|
|
|
|
public string Cuentas
|
|
{
|
|
get
|
|
{
|
|
if (this.apuntes.Count > 10)
|
|
{
|
|
return "** MÁS DE 10 **";
|
|
}
|
|
else
|
|
{
|
|
string sCuentas = "";
|
|
foreach (var ap in this.apuntes)
|
|
{
|
|
if (ap.idCuentaNavigation != null)
|
|
{
|
|
sCuentas += ap.idCuentaNavigation.NumeroCuenta + " ";
|
|
}
|
|
}
|
|
return sCuentas.Trim();
|
|
}
|
|
}
|
|
}
|
|
|
|
public string Documentos
|
|
{
|
|
get
|
|
{
|
|
string sDocumentos = "";
|
|
var docs = this.apuntes.ToList()
|
|
.Where(x => !string.IsNullOrEmpty(x.NumeroDocumento))
|
|
.GroupBy(x => x.NumeroDocumento);
|
|
|
|
foreach (var ap in docs)
|
|
{
|
|
sDocumentos += ap.First().NumeroDocumento + " ";
|
|
}
|
|
return sDocumentos.Trim();
|
|
}
|
|
}
|
|
|
|
public string Conceptos
|
|
{
|
|
get
|
|
{
|
|
string sConceptos = "";
|
|
var groups = this.apuntes.ToList().GroupBy(x => x.Concepto);
|
|
foreach (var ap in groups)
|
|
{
|
|
sConceptos += ap.First().Concepto + " ";
|
|
}
|
|
return sConceptos.Trim();
|
|
}
|
|
}
|
|
|
|
public int? idAsiento_Nulable
|
|
{
|
|
get
|
|
{
|
|
if (this.idAsiento == 0) return null;
|
|
return this.idAsiento;
|
|
}
|
|
}
|
|
|
|
public void RellenaCuentaTmp()
|
|
{
|
|
foreach (var ap in this.apuntes)
|
|
{
|
|
if (ap.idCuentaNavigation != null)
|
|
{
|
|
ap.NumeroCuentaTmp = ap.idCuentaNavigation.NumeroCuenta;
|
|
ap.DescripcionCuentaTmp = ap.idCuentaNavigation.Denominacion;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void GeneraAsientoRecibosContado(tscgestionasegasa bd, List<vf_recibosextendidos> Recibos, Action<string, Exception> DelegadoError)
|
|
{
|
|
var hoy = DateOnly.FromDateTime(DateTime.Now);
|
|
|
|
var ej = bd.ejercicioscontables.FirstOrDefault(x => x.FechaInicio <= hoy && x.FechaFin >= hoy && !x.FechaCierre.HasValue);
|
|
|
|
if (ej == null) ej = bdAsegasa.db.ejercicioscontables.AbreEjercicio(bd, new DateTime(hoy.Year, hoy.Month, hoy.Day));
|
|
|
|
var idTiporem = bd.enumeraciones.First(x => x.Codigo == "TIPREM.CO").idEnumeracion;
|
|
var tipospagos = bd.enumeraciones.Where(x => x.idGrupoEnumeracionNavigation.Grupo == "TIPP").ToList();
|
|
var idSituacion = bd.enumeraciones.First(x => x.Codigo == "SITR.PA").idEnumeracion;
|
|
var Cont = bd.enumeraciones.First(x => x.Codigo == "CONT.NUMGEN");
|
|
var Conceps = bd.conceptosapuntes.ToList();
|
|
|
|
if (Cont.ValorNumerico1.HasValue)
|
|
Cont.ValorNumerico1++;
|
|
else
|
|
Cont.ValorNumerico1 = 1;
|
|
|
|
var remesa = new remesas();
|
|
remesa.IBAN = "";
|
|
remesa.FechaCreacion = DateTime.Now;
|
|
remesa.Fecha = hoy;
|
|
remesa.idTipo = idTiporem;
|
|
|
|
bd.remesas.Add(remesa);
|
|
bd.SaveChanges();
|
|
|
|
int numgenerados = 0;
|
|
int numerrores = 0;
|
|
string sRecibosConErrores = "";
|
|
List<vf_recibosextendidos> lrg = new List<vf_recibosextendidos>();
|
|
|
|
foreach (var recibo in Recibos)
|
|
{
|
|
var r = bd.recibos.First(x => x.idRecibo == recibo.idRecibo);
|
|
try
|
|
{
|
|
GeneraAsientoReciboContado(bd, r, tipospagos, Conceps, idSituacion, remesa, (int)Cont.ValorNumerico1.Value);
|
|
lrg.Add(recibo);
|
|
numgenerados++;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sRecibosConErrores += recibo.CodigoRecibo + Environment.NewLine;
|
|
numerrores++;
|
|
DelegadoError?.Invoke("GeneraAsientoRecibosContado", ex);
|
|
}
|
|
}
|
|
|
|
string sDestinatarios = bd.enumeraciones.First(x => x.Codigo == "CONF.EMAILCONTA").ValorAlfabeticoLargo;
|
|
var cta = bd.cuentascorreo.First(x => x.Codigo == "SEG.GENERALES");
|
|
byte[] f = null;
|
|
|
|
if (lrg.Count > 0)
|
|
{
|
|
var lr = lrg.Select(x => new
|
|
{
|
|
x.CodigoRecibo,
|
|
x.NumeroPoliza,
|
|
x.NumeroSuplemento,
|
|
x.Tomador,
|
|
x.BienesAsegurados,
|
|
x.Ramo,
|
|
x.Compania
|
|
}).ToList();
|
|
// f = tsWPF.Utilidades.Varias.IEnumerableAExcel(lr);
|
|
// TODO: Implement Excel generation for .NET 8 if needed
|
|
}
|
|
|
|
string sCuerpo = "";
|
|
if (numgenerados > 0) sCuerpo = "Adjunto le remitimos listado de recibos marcados como remesados (Contado)";
|
|
if (numerrores > 0)
|
|
{
|
|
sCuerpo += Environment.NewLine + "Los siguientes recibos no pudieron ser marcados como remesados correctamente: " + Environment.NewLine + sRecibosConErrores;
|
|
}
|
|
|
|
if (numgenerados > 0)
|
|
{
|
|
bdAsegasa.db.correos.GeneraRegistroCorreoConAdjunto(null, "Se han marcado " + numgenerados.ToString() + " Recibos como remesados (Contado)", sCuerpo, cta, f, "Pagos-" + DateTime.Now.ToString("yyyy-MM-dd") + ".xlsx", "Listado Recibos de con fecha de pago " + DateTime.Now.ToString("yyyy-MM-dd"), sDestinatarios, "", "sevilla@tecnosis.net");
|
|
}
|
|
else
|
|
{
|
|
bdAsegasa.db.correos.GeneraRegistroCorreo(null, "Los siguientes recibos no pudieron ser marcados como remesados (Contado)", sCuerpo, cta, sDestinatarios, "", "sevilla@tecnosis.net");
|
|
}
|
|
}
|
|
|
|
public static void GeneraAsientoReciboContado(tscgestionasegasa bd, recibos Recibo, List<enumeraciones> TiposPago, List<conceptosapuntes> Conceptos, int idSituacion, remesas Remesa, int NumeroGeneracion, bool Inverso = false)
|
|
{
|
|
try
|
|
{
|
|
string Tipp = TiposPago.First(x => x.idEnumeracion == Recibo.idTipoPago).Codigo.Split('.')[1];
|
|
var ent = Recibo.idPolizaNavigation.EntidadPolizaTomador.idEntidadNavigation;
|
|
|
|
var na = new asientos();
|
|
bd.asientos.Add(na);
|
|
|
|
na.Fecha = Inverso ? DateOnly.FromDateTime(DateTime.Now) : Recibo.FechaPago.Value;
|
|
na.idEjercicio = ejercicioscontables.ObtieneidEjercicioAbierto(new DateTime(na.Fecha.Year, na.Fecha.Month, na.Fecha.Day));
|
|
na.Tipo = (int)asientos.TipoAsiento.NORMAL;
|
|
na.FechaIntroduccion = DateTime.Now;
|
|
if (bdAsegasa.db.Utilidades.dsc.idUsuario > 0) na.idUsuario = bdAsegasa.db.Utilidades.dsc.idUsuario;
|
|
|
|
var nap1 = new apuntes();
|
|
nap1.idAsientoNavigation = na;
|
|
nap1.Concepto = ent.RazonSocial;
|
|
nap1.NumeroDocumento = Recibo.idRecibo.ToString();
|
|
|
|
string Cta = "";
|
|
switch (Tipp)
|
|
{
|
|
case "PE":
|
|
if (string.IsNullOrEmpty(ent.CuentaContable)) throw new Exception("La entidad " + ent.RazonSocial + " no tiene asignada una cuenta contable");
|
|
Cta = ent.CuentaContable;
|
|
nap1.idConcepto = Conceptos.First(x => x.Codigo == "029").idConcepto;
|
|
break;
|
|
case "CO":
|
|
Cta = Recibo.OficinaAgente.ToUpper() == "SEVILLA" ? "57000000" : "57000002";
|
|
if (Recibo.TotalRecibo > 0)
|
|
nap1.idConcepto = Conceptos.First(x => x.Codigo == "015").idConcepto;
|
|
else
|
|
nap1.idConcepto = Conceptos.First(x => x.Codigo == "029").idConcepto;
|
|
break;
|
|
case "CTA":
|
|
if (Recibo.TotalRecibo > 0)
|
|
{
|
|
Cta = "57000001";
|
|
nap1.idConcepto = Conceptos.First(x => x.Codigo == "016").idConcepto;
|
|
}
|
|
else
|
|
{
|
|
Cta = "57200004";
|
|
nap1.idConcepto = Conceptos.First(x => x.Codigo == "029").idConcepto;
|
|
}
|
|
nap1.Concepto = "TRF. " + ent.RazonSocial;
|
|
break;
|
|
case "CTR":
|
|
Cta = "57200004";
|
|
nap1.idConcepto = Conceptos.First(x => x.Codigo == "015").idConcepto;
|
|
nap1.Concepto = "TRANS. " + ent.RazonSocial;
|
|
break;
|
|
case "CIN":
|
|
Cta = "57200004";
|
|
nap1.idConcepto = Conceptos.First(x => x.Codigo == "015").idConcepto;
|
|
nap1.Concepto = "TPV. " + ent.RazonSocial;
|
|
break;
|
|
default:
|
|
throw new Exception("Tipo de pago " + Tipp + " no soportado");
|
|
}
|
|
|
|
var cuenta = bd.cuentas.FirstOrDefault(x => x.NumeroCuenta == Cta && x.idEjercicio == na.idEjercicio);
|
|
if (cuenta == null)
|
|
{
|
|
var ctaant = bd.cuentas.Where(x => x.NumeroCuenta == Cta).OrderByDescending(x => x.idEjercicioNavigation.FechaInicio).FirstOrDefault();
|
|
if (ctaant != null) cuenta = bdAsegasa.db.cuentas.CreaCuenta(bd, na.idEjercicio, Cta, ctaant.Denominacion, ctaant.Observaciones);
|
|
}
|
|
|
|
if (cuenta == null) throw new Exception("No existe la cuenta " + Cta + " para el recibo " + Recibo.CodigoRecibo);
|
|
nap1.idCuentaNavigation = cuenta;
|
|
|
|
if (Inverso)
|
|
{
|
|
nap1.Haber = (double)Recibo.TotalRecibo.Value;
|
|
nap1.Debe = 0;
|
|
}
|
|
else
|
|
{
|
|
nap1.Haber = 0;
|
|
nap1.Debe = (double)Recibo.TotalRecibo.Value;
|
|
}
|
|
na.apuntes.Add(nap1);
|
|
|
|
var nap2 = new apuntes();
|
|
nap2.idAsientoNavigation = na;
|
|
string Cta2 = "4400" + Recibo.idPolizaNavigation.idCompaniaNavigation.Codigo;
|
|
nap2.idCuenta = bd.cuentas.First(x => x.NumeroCuenta == Cta2 && x.idEjercicio == na.idEjercicio).idCuenta;
|
|
|
|
if (Inverso)
|
|
{
|
|
nap2.Haber = 0;
|
|
nap2.Debe = Math.Round((double)Recibo.TotalRecibo.Value, 2, MidpointRounding.AwayFromZero);
|
|
}
|
|
else
|
|
{
|
|
nap2.Debe = 0;
|
|
nap2.Haber = Math.Round((double)Recibo.TotalRecibo.Value, 2, MidpointRounding.AwayFromZero);
|
|
}
|
|
nap2.Concepto = ent.RazonSocial;
|
|
nap2.idConcepto = Conceptos.First(x => x.Codigo == "005").idConcepto;
|
|
nap2.NumeroDocumento = Recibo.idRecibo.ToString();
|
|
na.apuntes.Add(nap2);
|
|
|
|
na.Importe = na.apuntes.Sum(x => x.Debe);
|
|
Recibo.idRemesa = Remesa.idRemesa;
|
|
Recibo.idSituacion = idSituacion;
|
|
bd.SaveChanges();
|
|
|
|
// Logic for amortization
|
|
if (Tipp == "PE" && nap1.idCuentaNavigation.idEmpresaAmortizacion.HasValue)
|
|
{
|
|
if (!Inverso)
|
|
{
|
|
var Amr = new amortizacionrecibos();
|
|
int iUltimoMes = 0;
|
|
var ud = bd.detallesamortizacionrecibos.Where(x => x.FechaAplicacion.HasValue).OrderByDescending(x => x.FechaAplicacion).FirstOrDefault();
|
|
if (ud != null) iUltimoMes = ud.Mes;
|
|
|
|
int iMesPago = Recibo.FechaPago.Value.Year * 100 + Recibo.FechaPago.Value.Month;
|
|
if (iUltimoMes >= iMesPago)
|
|
{
|
|
Amr.FechaInicioAmortizacion = new DateOnly(iUltimoMes / 100, iUltimoMes % 100, 1).AddMonths(1);
|
|
}
|
|
else
|
|
{
|
|
Amr.FechaInicioAmortizacion = Recibo.FechaPago.Value;
|
|
}
|
|
|
|
Amr.idRecibo = Recibo.idRecibo;
|
|
Amr.PorcentajeAnual = 100;
|
|
Amr.idEmpresa = nap1.idCuentaNavigation.idEmpresaAmortizacion.Value;
|
|
Amr.FechaFinAmortizacion = (new DateOnly(Amr.FechaInicioAmortizacion.Year, Amr.FechaInicioAmortizacion.Month, 1)).AddMonths(12);
|
|
Amr.NumeroCuenta = nap1.idCuentaNavigation.NumeroCuenta;
|
|
Amr.FechaAlta = DateOnly.FromDateTime(DateTime.Now);
|
|
|
|
DateTime FechaInicial = new DateTime(Amr.FechaInicioAmortizacion.Year, Amr.FechaInicioAmortizacion.Month, 1);
|
|
for (int i = 0; i <= 11; i++)
|
|
{
|
|
var amrd = new detallesamortizacionrecibos();
|
|
amrd.Mes = FechaInicial.AddMonths(i).Year * 100 + FechaInicial.AddMonths(i).Month;
|
|
if (i < 11)
|
|
{
|
|
amrd.ValorAmortizado = Math.Round(Recibo.TotalRecibo.Value / 12, 2, MidpointRounding.AwayFromZero);
|
|
amrd.ValorAcumulado = Math.Round(Recibo.TotalRecibo.Value / 12 * (i + 1), 2, MidpointRounding.AwayFromZero);
|
|
amrd.ValorResidual = Math.Round(Recibo.TotalRecibo.Value - amrd.ValorAcumulado, 2, MidpointRounding.AwayFromZero);
|
|
}
|
|
else
|
|
{
|
|
amrd.ValorAmortizado = Math.Round(Recibo.TotalRecibo.Value - Amr.detallesamortizacionrecibos.Sum(x => x.ValorAmortizado), 2, MidpointRounding.AwayFromZero);
|
|
amrd.ValorAcumulado = Recibo.TotalRecibo.Value;
|
|
amrd.ValorResidual = 0;
|
|
}
|
|
Amr.detallesamortizacionrecibos.Add(amrd);
|
|
}
|
|
bd.amortizacionrecibos.Add(Amr);
|
|
}
|
|
bd.SaveChanges();
|
|
|
|
var apas = new aplicacionesasientos();
|
|
apas.idAplicacion = Recibo.idRecibo;
|
|
apas.Tipo = Inverso ? (int)Enums.TipoAplicacionAsientoEnum.RECIBO_BAJA_TIPO_PAGO_PE : (int)Enums.TipoAplicacionAsientoEnum.RECIBO_CONTABILIZACION_PAGO_CONTADO;
|
|
apas.idAsiento = na.idAsiento;
|
|
bd.aplicacionesasientos.Add(apas);
|
|
bd.SaveChanges();
|
|
}
|
|
|
|
// Execute raw SQL if necessary for triggers or legacy compatibility
|
|
// bd.Database.ExecuteSqlRaw("UPDATE registrosactualizados SET FechaCreacion=Now() where FechaCreacion Is null and NumeroGeneracion={0};", NumeroGeneracion);
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message, ex);
|
|
}
|
|
}
|
|
|
|
public static asientos GeneraAsientoReciboPagadoEnCiaYaFacturado(tscgestionasegasa bd, recibos Recibo, int idEjercicio)
|
|
{
|
|
try
|
|
{
|
|
var ent = Recibo.idPolizaNavigation.EntidadPolizaTomador.idEntidadNavigation;
|
|
var na = new asientos();
|
|
bd.asientos.Add(na);
|
|
|
|
na.Fecha = DateOnly.FromDateTime(DateTime.Now);
|
|
na.idEjercicio = idEjercicio;
|
|
na.Tipo = (int)asientos.TipoAsiento.NORMAL;
|
|
na.FechaIntroduccion = DateTime.Now;
|
|
if (bdAsegasa.db.Utilidades.dsc.idUsuario > 0) na.idUsuario = bdAsegasa.db.Utilidades.dsc.idUsuario;
|
|
|
|
// Apunte 1: Desfacturacion Client (Haber)
|
|
var nap1 = new apuntes();
|
|
nap1.idAsientoNavigation = na;
|
|
nap1.Concepto = "RECIBO PAGADO EN CIA (DESFACTURACION) " + ent.RazonSocial;
|
|
nap1.NumeroDocumento = Recibo.idRecibo.ToString();
|
|
string Cta1 = "4400" + Recibo.idPolizaNavigation.idCompaniaNavigation.Codigo;
|
|
nap1.idCuentaNavigation = ObtieneCuenta(bd, Cta1, idEjercicio);
|
|
nap1.Haber = Math.Round((double)Recibo.TotalRecibo.Value, 2, MidpointRounding.AwayFromZero);
|
|
nap1.Debe = 0;
|
|
na.apuntes.Add(nap1);
|
|
|
|
// Apunte 2: Desfacturacion Company (Debe - NET)
|
|
var nap2 = new apuntes();
|
|
nap2.idAsientoNavigation = na;
|
|
string Cta2 = "4190" + Recibo.idPolizaNavigation.idCompaniaNavigation.Codigo;
|
|
nap2.idCuentaNavigation = ObtieneCuenta(bd, Cta2, idEjercicio);
|
|
nap2.Debe = Math.Round((double)(Recibo.TotalRecibo.Value - Recibo.TotalComision.Value), 2, MidpointRounding.AwayFromZero);
|
|
nap2.Haber = 0;
|
|
nap2.Concepto = "RECIBO PAGADO EN CIA (DESFACTURACION)" + ent.RazonSocial;
|
|
nap2.NumeroDocumento = Recibo.idRecibo.ToString();
|
|
na.apuntes.Add(nap2);
|
|
|
|
// Apunte 3: Desfacturacion Commission (Debe)
|
|
var nap3 = new apuntes();
|
|
nap3.idAsientoNavigation = na;
|
|
string Cta3 = "7050" + Recibo.idPolizaNavigation.idCompaniaNavigation.Codigo;
|
|
nap3.idCuentaNavigation = ObtieneCuenta(bd, Cta3, idEjercicio);
|
|
nap3.Debe = Math.Round((double)Recibo.TotalComision.Value, 2, MidpointRounding.AwayFromZero);
|
|
nap3.Haber = 0;
|
|
nap3.Concepto = "RECIBO PAGADO EN CIA (DESFACTURACION)" + ent.RazonSocial;
|
|
nap3.NumeroDocumento = Recibo.idRecibo.ToString();
|
|
na.apuntes.Add(nap3);
|
|
|
|
// Apunte 4: Pago en CIA (Debe - COM)
|
|
var nap4 = new apuntes();
|
|
nap4.idAsientoNavigation = na;
|
|
nap4.Concepto = "RECIBO PAGADO EN CIA " + ent.RazonSocial;
|
|
nap4.NumeroDocumento = Recibo.idRecibo.ToString();
|
|
nap4.idCuentaNavigation = ObtieneCuenta(bd, Cta2, idEjercicio);
|
|
nap4.Haber = 0;
|
|
nap4.Debe = Math.Round((double)Recibo.TotalComision.Value, 2, MidpointRounding.AwayFromZero);
|
|
na.apuntes.Add(nap4);
|
|
|
|
// Apunte 5: Pago en CIA (Haber - COM)
|
|
var nap5 = new apuntes();
|
|
nap5.idAsientoNavigation = na;
|
|
nap5.idCuentaNavigation = ObtieneCuenta(bd, Cta3, idEjercicio);
|
|
nap5.Debe = 0;
|
|
nap5.Haber = Math.Round((double)Recibo.TotalComision.Value, 2, MidpointRounding.AwayFromZero);
|
|
nap5.Concepto = "RECIBO PAGADO EN CIA " + ent.RazonSocial;
|
|
nap5.NumeroDocumento = Recibo.idRecibo.ToString();
|
|
na.apuntes.Add(nap5);
|
|
|
|
na.Importe = na.apuntes.Sum(x => x.Debe);
|
|
bd.SaveChanges();
|
|
|
|
var apas = new aplicacionesasientos();
|
|
apas.idAplicacion = Recibo.idRecibo;
|
|
apas.Tipo = (int)Enums.TipoAplicacionAsientoEnum.RECIBO_PAGADO_EN_CIA;
|
|
apas.idAsiento = na.idAsiento;
|
|
bd.aplicacionesasientos.Add(apas);
|
|
bd.SaveChanges();
|
|
|
|
return na;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message, ex);
|
|
}
|
|
}
|
|
|
|
public static asientos GeneraAsientoReciboPagadoEnCia(tscgestionasegasa bd, recibos Recibo)
|
|
{
|
|
try
|
|
{
|
|
var today = DateOnly.FromDateTime(DateTime.Now);
|
|
|
|
var ej = bd.ejercicioscontables.FirstOrDefault(x => x.FechaInicio <= today && x.FechaFin >= today && !x.FechaCierre.HasValue);
|
|
if (ej == null) ej = bdAsegasa.db.ejercicioscontables.AbreEjercicio(bd, DateTime.Today);
|
|
|
|
var ent = Recibo.idPolizaNavigation.EntidadPolizaTomador.idEntidadNavigation;
|
|
var na = new asientos();
|
|
bd.asientos.Add(na);
|
|
|
|
na.Fecha = today;
|
|
na.idEjercicio = ej.idEjercicio;
|
|
na.Tipo = (int)asientos.TipoAsiento.NORMAL;
|
|
na.FechaIntroduccion = DateTime.Now;
|
|
if (bdAsegasa.db.Utilidades.dsc.idUsuario > 0) na.idUsuario = bdAsegasa.db.Utilidades.dsc.idUsuario;
|
|
|
|
var nap1 = new apuntes();
|
|
nap1.idAsientoNavigation = na;
|
|
nap1.Concepto = "RECIBO PAGADO EN CIA " + ent.RazonSocial;
|
|
nap1.NumeroDocumento = Recibo.idRecibo.ToString();
|
|
string Cta1 = "4190" + Recibo.idPolizaNavigation.idCompaniaNavigation.Codigo;
|
|
nap1.idCuentaNavigation = ObtieneCuenta(bd, Cta1, ej.idEjercicio);
|
|
nap1.Haber = 0;
|
|
nap1.Debe = Math.Round((double)Recibo.TotalComision.Value, 2, MidpointRounding.AwayFromZero);
|
|
na.apuntes.Add(nap1);
|
|
|
|
var nap2 = new apuntes();
|
|
nap2.idAsientoNavigation = na;
|
|
string Cta2 = "7050" + Recibo.idPolizaNavigation.idCompaniaNavigation.Codigo;
|
|
nap2.idCuentaNavigation = ObtieneCuenta(bd, Cta2, ej.idEjercicio);
|
|
nap2.Debe = 0;
|
|
nap2.Haber = Math.Round((double)Recibo.TotalComision.Value, 2, MidpointRounding.AwayFromZero);
|
|
nap2.Concepto = "RECIBO PAGADO EN CIA " + ent.RazonSocial;
|
|
nap2.NumeroDocumento = Recibo.idRecibo.ToString();
|
|
na.apuntes.Add(nap2);
|
|
|
|
na.Importe = Math.Round(na.apuntes.Sum(x => x.Debe), 2, MidpointRounding.AwayFromZero);
|
|
bd.SaveChanges();
|
|
|
|
var apas = new aplicacionesasientos();
|
|
apas.idAplicacion = Recibo.idRecibo;
|
|
apas.Tipo = (int)Enums.TipoAplicacionAsientoEnum.RECIBO_PAGADO_EN_CIA;
|
|
apas.idAsiento = na.idAsiento;
|
|
bd.aplicacionesasientos.Add(apas);
|
|
bd.SaveChanges();
|
|
|
|
return na;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message, ex);
|
|
}
|
|
}
|
|
|
|
public void RefrescaExtensiones()
|
|
{
|
|
OnPropertyChanged("EjercicioTmp");
|
|
OnPropertyChanged("idAsiento_Nulable");
|
|
}
|
|
|
|
public static cuentas ObtieneCuenta(tscgestionasegasa bd, string cta, int idEjercicio)
|
|
{
|
|
var cuenta = bd.cuentas.FirstOrDefault(x => x.NumeroCuenta == cta && x.idEjercicio == idEjercicio);
|
|
if (cuenta == null)
|
|
{
|
|
var ctaant = bd.cuentas.Where(x => x.NumeroCuenta == cta).OrderByDescending(x => x.idEjercicioNavigation.FechaInicio).FirstOrDefault();
|
|
if (ctaant != null) cuenta = bdAsegasa.db.cuentas.CreaCuenta(bd, idEjercicio, cta, ctaant.Denominacion, ctaant.Observaciones);
|
|
}
|
|
return cuenta;
|
|
}
|
|
|
|
public bool Punteado
|
|
{
|
|
get => FechaPunteo.HasValue;
|
|
set
|
|
{
|
|
if (value)
|
|
FechaPunteo = DateTime.Now;
|
|
else
|
|
FechaPunteo = null;
|
|
}
|
|
}
|
|
|
|
private string _Ejercicio;
|
|
public string EjercicioTmp
|
|
{
|
|
get
|
|
{
|
|
if (string.IsNullOrEmpty(_Ejercicio) && this.idEjercicioNavigation!= null)
|
|
{
|
|
_Ejercicio = this.idEjercicioNavigation.Descripcion;
|
|
}
|
|
return _Ejercicio;
|
|
}
|
|
set
|
|
{
|
|
_Ejercicio = value;
|
|
OnPropertyChanged("EjercicioTmp");
|
|
}
|
|
}
|
|
}
|
|
}
|