/// <summary> /// Método desusado para agregar un nuevo objeto al EntitySet SaldoxComprobante. Considere la posibilidad de usar el método .Add de la propiedad ObjectSet<T> asociada. /// </summary> public void AddToSaldoxComprobante(SaldoxComprobante saldoxComprobante) { base.AddObject("SaldoxComprobante", saldoxComprobante); }
public Boolean insert(List<clsvwComprobanteMayorizar> lista) { try { using (EntitiesContabilidad2 ent =new EntitiesContabilidad2()) { foreach (var item in lista) { var s =from q in ent.DetalleComprobante where q.IdEmpresa==item.IdEmpresa && q.cabecera_comprobante==item.numero_comprobante select q; foreach (var item2 in s) { try { EntitiesContabilidad2 ent2 = new EntitiesContabilidad2(); DateTime fecha=(from q in ent2.PeriodoContable where q.FechaInicio < item.fecha && q.FechaFin > item.fecha select q.FechaFin).First(); if ((from q in ent.Saldo where q.fecha == fecha select q).Count() > 0) { var saldo = (from q in ent2.Saldo where q.fecha == fecha && q.cuenta == item2.cuenta select q).First(); saldo.saldo_deudor = saldo.saldo_deudor + item2.debe; saldo.saldo_acreedor = saldo.saldo_acreedor + item2.haber; ent2.SaveChanges(); } else { Saldo sald = new Saldo() { IdEmpresa = 1, cuenta = item2.cuenta, //esta fecha debe ser la fechafinal del periodo fecha = Convert.ToDateTime((from q in ent.PeriodoContable where q.FechaInicio < item.fecha && q.FechaFin > item.fecha select q.FechaFin).First()), //el debe y el haber se debe acumular segun la cuenta y la fecha del periodo si ya existe en la base saldo_deudor = item2.debe, saldo_acreedor = item2.haber, IdUsuario = 1, FechaModificacion = DateTime.Now }; ent.AddToSaldo(sald); } } catch (Exception) { Saldo sald = new Saldo() { IdEmpresa = 1, cuenta = item2.cuenta, //esta fecha debe ser la fechafinal del periodo fecha = Convert.ToDateTime((from q in ent.PeriodoContable where q.FechaInicio < item.fecha && q.FechaFin > item.fecha select q.FechaFin).First()), //el debe y el haber se debe acumular segun la cuenta y la fecha del periodo si ya existe en la base saldo_deudor = item2.debe, saldo_acreedor = item2.haber, IdUsuario = 1, FechaModificacion = DateTime.Now }; ent.AddToSaldo(sald); } } SaldoxComprobante xc = new SaldoxComprobante() { IdEmpresa=1, numero_comprobante=item.numero_comprobante }; ent.AddToSaldoxComprobante(xc); } ent.SaveChanges(); } return true; } catch (Exception) { return false; } }
/// <summary> /// Crear un nuevo objeto SaldoxComprobante. /// </summary> /// <param name="idEmpresa">Valor inicial de la propiedad IdEmpresa.</param> /// <param name="numero_comprobante">Valor inicial de la propiedad numero_comprobante.</param> public static SaldoxComprobante CreateSaldoxComprobante(global::System.Int32 idEmpresa, global::System.Decimal numero_comprobante) { SaldoxComprobante saldoxComprobante = new SaldoxComprobante(); saldoxComprobante.IdEmpresa = idEmpresa; saldoxComprobante.numero_comprobante = numero_comprobante; return saldoxComprobante; }