private bool AccionGuardar() { if (!this.Validar()) { return(false); } Cargando.Mostrar(); int iSucursalID = Util.Entero(this.cmbSucursal.SelectedValue); // Se guardan las metas específicas Meta oMeta; foreach (DataGridViewRow oFila in this.dgvEspecificas.Rows) { if (oFila.IsNewRow) { continue; } int iMetaID = Util.Entero(oFila.Cells["mesMetaID"].Value); int iCambio = Util.Entero(oFila.Cells["mesCambio"].Value); switch (iCambio) { case Cat.TiposDeAfectacion.Agregar: case Cat.TiposDeAfectacion.Modificar: if (iCambio == Cat.TiposDeAfectacion.Agregar) { oMeta = new Meta() { SucursalID = iSucursalID } } ; else { oMeta = Datos.GetEntity <Meta>(c => c.MetaID == iMetaID); } oMeta.VendedorID = (Util.Entero(oFila.Cells["mesUsuarioID"].Value) > 0 ? (int?)Util.Entero(oFila.Cells["mesUsuarioID"].Value) : null); oMeta.MarcaParteID = (Util.Entero(oFila.Cells["mesMarcaID"].Value) > 0 ? (int?)Util.Entero(oFila.Cells["mesMarcaID"].Value): null); oMeta.LineaID = (Util.Entero(oFila.Cells["mesLineaID"].Value) > 0 ? (int?)Util.Entero(oFila.Cells["mesLineaID"].Value) : null); oMeta.ParteID = (Util.Entero(oFila.Cells["mesParteID"].Value) > 0 ? (int?)Util.Entero(oFila.Cells["mesParteID"].Value) : null); oMeta.NombreMeta = Util.Cadena(oFila.Cells["mesNombre"].Value); oMeta.Cantidad = Util.Decimal(oFila.Cells["mesCantidad"].Value); oMeta.RutaImagen = Util.Cadena(oFila.Cells["mesRutaImagen"].Value); Datos.Guardar <Meta>(oMeta); break; case Cat.TiposDeAfectacion.Borrar: oMeta = Datos.GetEntity <Meta>(c => c.MetaID == iMetaID); Datos.Eliminar <Meta>(oMeta); break; } } Cargando.Cerrar(); this.CargarDatos(); return(true); }
private void LlenarProgreso() { Cargando.Mostrar(); var oParams = new Dictionary <string, object>(); oParams.Add("Opcion", 1); oParams.Add("Desde", this.dtpDesde.Value); oParams.Add("Hasta", this.dtpHasta.Value); // Se obtienen los datos para el programa a futuro var oDatos = Datos.ExecuteProcedure <pauInventarioProgreso_Result>("pauInventarioProgreso", oParams); var oPeriodicidad = Datos.GetListOf <InventarioLineaPeriodicidad>(); var oFechasPer = new Dictionary <int, DateTime>(); this.dgvProgreso.Rows.Clear(); // Se llenan los datos de las líneas ya procesadas int iFila = 0; DateTime dAvance = this.dtpDesde.Value; int iPrimeraVuelta = int.MaxValue; var oVueltas = new List <string>(); foreach (var oReg in oDatos) { iFila = this.dgvProgreso.Rows.Add(oReg.LineaID, oReg.Linea, oReg.Partes, oReg.Costo, oReg.Dias, oReg.PorMatriz , oReg.PorSuc2, oReg.PorSuc3, oReg.FechaIniciado, oReg.FechaCompletado); this.dgvProgreso["Progreso_FechaIniciado", iFila].Style.ForeColor = Color.Black; if (oReg.FechaCompletado.HasValue) { this.dgvProgreso["Progreso_FechaCompletado", iFila].Style.ForeColor = Color.Black; } else { this.dgvProgreso["Progreso_FechaCompletado", iFila].Value = oReg.FechaIniciado.Valor().AddDays((double)oReg.Dias); } // Para determinar la fecha de avance if (Util.FechaHora(this.dgvProgreso["Progreso_FechaCompletado", iFila].Value) > dAvance) { dAvance = Util.FechaHora(this.dgvProgreso["Progreso_FechaCompletado", iFila].Value); } // Para saber cuáles líneas ya fueron procesadas if (oReg.AvVuelta.HasValue && iPrimeraVuelta > oReg.AvVuelta) { iPrimeraVuelta = oReg.AvVuelta.Valor(); } oVueltas.Add(string.Format("{0}-{1}", oReg.LineaID, oReg.AvVuelta)); } // Se meten los datos del programa a futuro oParams["Opcion"] = 2; oDatos = Datos.ExecuteProcedure <pauInventarioProgreso_Result>("pauInventarioProgreso", oParams); int iExistentes = this.dgvProgreso.Rows.Count; int iReg = 0; while (dAvance <= this.dtpHasta.Value) { if (iReg >= oDatos.Count) { iReg = 0; iPrimeraVuelta++; // Se verifica el avance de fechas si ya se dió una vuelta, por si no hay avance, detener el proceso y no se cicle if (dAvance == this.dtpDesde.Value) { break; } } var oReg = oDatos[iReg++]; // Se verifica si la línea ya fue contada /* if (iExistentes >= iReg) * { * // No recuerdo para qué eran estas líneas * if (oReg.LineaID == Util.ConvertirEntero(this.dgvProgreso["Progreso_LineaID", iReg - 1].Value) * && (Util.ConvertirFechaHora(this.dgvProgreso["Progreso_FechaIniciado", iReg - 1].Value) - dAvance).Days < 2) * continue; * dAvance = Util.ConvertirFechaHora(this.dgvProgreso["Progreso_FechaCompletado", iFila].Value); * } */ if (oVueltas.Count > 0) { string sVuelta = string.Format("{0}-{1}", oReg.LineaID, iPrimeraVuelta); if (oVueltas.Contains(sVuelta)) { oVueltas.Remove(sVuelta); continue; } } // Se agrega el registro iFila = this.dgvProgreso.Rows.Add(oReg.LineaID, oReg.Linea, oReg.Partes, oReg.Costo, oReg.Dias); // Se determinan this.dgvProgreso["Progreso_FechaIniciado", iFila].Value = dAvance; dAvance = dAvance.AddDays((double)oReg.Dias.Valor()); this.dgvProgreso["Progreso_FechaCompletado", iFila].Value = dAvance; // Se revisa lo de la periodicidad foreach (var oPer in oPeriodicidad) { if (!oFechasPer.ContainsKey(oPer.LineaID)) { oFechasPer.Add(oPer.LineaID, this.dtpDesde.Value); } if (oPer.LineaID == oReg.LineaID) { oFechasPer[oPer.LineaID] = dAvance; } if ((dAvance - oFechasPer[oPer.LineaID]).TotalDays >= oPer.Periodicidad) { var oLinea = oDatos.FirstOrDefault(c => c.LineaID == oPer.LineaID); if (oLinea != null) { iFila = this.dgvProgreso.Rows.Add(oLinea.LineaID, oLinea.Linea, oLinea.Partes, oLinea.Costo, oLinea.Dias, 0, 0, 0 , dAvance, dAvance = dAvance.AddDays((double)oLinea.Dias)); } oFechasPer[oPer.LineaID] = dAvance; } } } Cargando.Cerrar(); }
public bool AccionGuardar() { // Se valida if (!this.Validar()) { return(false); } Cargando.Mostrar(); // Se guardan los datos // DateTime dAhora = DateTime.Now; int?iDocID = Util.Entero(this.cmbDocumento.SelectedValue); // Se guarda el gasto ContaEgreso oGasto = (this.EsMod ? this.oEgreso : new ContaEgreso()); oGasto.ContaCuentaAuxiliarID = Util.Entero(this.cmbCuentaAuxiliar.SelectedValue); oGasto.Fecha = this.dtpFecha.Value; oGasto.Importe = Util.Decimal(this.txtImporte.Text); oGasto.TipoFormaPagoID = Util.Entero(this.cmbFormaDePago.SelectedValue); oGasto.FolioDePago = this.txtFolioDePago.Text; oGasto.FolioFactura = this.txtFolioFactura.Text; oGasto.BancoCuentaID = (int?)this.cmbCuentaBancaria.SelectedValue; oGasto.TipoDocumentoID = (iDocID > 0 ? iDocID : null); oGasto.EsFiscal = this.chkEsFiscal.Checked; oGasto.Observaciones = this.txtObservaciones.Text; oGasto.RealizoUsuarioID = GlobalClass.UsuarioGlobal.UsuarioID; oGasto.SucursalID = GlobalClass.SucursalID; Datos.Guardar <ContaEgreso>(oGasto); // Se guarda el detalle, si aplica foreach (DataGridViewRow Fila in this.dgvDetalle.Rows) { if (Fila.IsNewRow) { continue; } int iCambioID = Util.Entero(Fila.Cells["_Cambio"].Value); if (iCambioID == Cat.TiposDeAfectacion.SinCambios) { continue; } ContaEgresoDetalle oGastoDet; if (iCambioID == Cat.TiposDeAfectacion.Agregar) { oGastoDet = new ContaEgresoDetalle(); oGastoDet.ContaEgresoID = oGasto.ContaEgresoID; } else { oGastoDet = (Fila.Tag as ContaEgresoDetalle); if (iCambioID == Cat.TiposDeAfectacion.Borrar) { Datos.Eliminar <ContaEgresoDetalle>(oGastoDet, true); continue; } } oGastoDet.ContaConsumibleID = Util.Entero(Fila.Cells["ContaConsumibleID"].Value); oGastoDet.Cantidad = Util.Decimal(Fila.Cells["Cantidad"].Value); oGastoDet.Importe = Util.Decimal(Fila.Cells["Precio"].Value); Datos.Guardar <ContaEgresoDetalle>(oGastoDet); } // Se manda devengar automáticamente, si aplica ContaProc.GastoVerDevengarAutomaticamente(oGasto); // Se ejecutan procesos para gastos nuevos únicamente if (!this.EsMod) { // Se crean la pólizas contable correspondientes (AfeConta), ContaProc.CrearPolizasDeGastoContable(oGasto); // Se crea el movimiento bancario correspondiente, si aplica // Como se afecta la cuenta de bancos, se crea el movimiento bancario para mandarlo a conciliación y así llevar el control de todos los // movimientos bancarios if (oGasto.TipoFormaPagoID == Cat.FormasDePago.Cheque || oGasto.TipoFormaPagoID == Cat.FormasDePago.Tarjeta || oGasto.TipoFormaPagoID == Cat.FormasDePago.Transferencia) { var oMovBanc = new BancoCuentaMovimiento() { BancoCuentaID = oGasto.BancoCuentaID, EsIngreso = false, Fecha = oGasto.Fecha, FechaAsignado = oGasto.Fecha, SucursalID = oGasto.SucursalID, Importe = oGasto.Importe, Concepto = oGasto.Observaciones, Referencia = oGasto.FolioFactura, TipoFormaPagoID = oGasto.TipoFormaPagoID, RelacionTabla = Cat.Tablas.ContaEgreso, RelacionID = oGasto.ContaEgresoID }; ContaProc.RegistrarMovimientoBancario(oMovBanc); } } Cargando.Cerrar(); // Se muestra una notificación this.RestaurarControles(); UtilLocal.MostrarNotificacion("Proceso completado correctamente."); return(true); }
private void CargarConfiguracion() { Cargando loading = new Cargando(); if (!System.Security.Principal.WindowsIdentity.GetCurrent().Name.Contains("omartinez")) { loading.Topmost = true; loading.WindowStyle = WindowStyle.None; } loading.Show(); BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += (s, e) => { try { this.config = BDConfiguracion.Leer(); Store.Bancada = BDSQL.Select.ObtenerBancadaPorId(this.config.IdBancada); if (Store.Bancada != null && Store.Bancada.EsMaster && Store.Bancada.IdHermano.HasValue) { Store.BancadaEsclavo = BDSQL.Select.ObtenerBancadaPorId(Store.Bancada.IdHermano.Value); } else if (Store.Bancada != null && !Store.Bancada.EsMaster && Store.Bancada.IdHermano.HasValue) { Store.BancadaMaster = BDSQL.Select.ObtenerBancadaPorId(Store.Bancada.IdHermano.Value); } DateTime ahora = DateTime.Now; Turno turno = Horario.CalcularTurnoAFecha(ahora); DateTime fechaInicio; DateTime fechaFin; Horario.CalcularHorarioTurno(turno, ahora, out fechaInicio, out fechaFin); var paquetes = new List <MaquinasRegistrosDatos>(); foreach (var maquina in Store.Bancada.Maquinas) { paquetes.AddRange(Select.HistoricoPaquetesOperario(maquina.IpAutomata, maquina.Posicion, fechaInicio, fechaFin)); } foreach (var paquete in paquetes.Where(x => x.PiezaIntroducida)) { var maq = Store.Bancada.Maquinas.FirstOrDefault(x => x.IpAutomata == paquete.IpAutomata && x.Posicion == paquete.PosicionMaquina); if (maq != null) { maq.Pulsos.Add(new PulsoMaquina { IdTarea = paquete.IdTarea, CodigoEtiqueta = paquete.CodigoEtiqueta, Control = BuscarControl(paquete.IdOperacion, maq), Fecha = paquete.FechaCreacion, Pares = paquete.Pares, IdOperario = paquete.IdOperario, CodigoOrden = paquete.CodigoOrden, Talla = paquete.Talla, }); } } } catch (Exception ex) { Log.Write(ex); } }; bw.RunWorkerCompleted += (s, e) => { try { if (Store.Bancada != null && Store.Bancada.Maquinas.Any()) { if (Store.Bancada.EsMaster) { var maquinasUart = Store.Bancada.Maquinas.ToList(); if (Store.BancadaEsclavo != null) { maquinasUart.AddRange(Store.BancadaEsclavo.Maquinas.ToList()); } uart = new Uart(maquinasUart); uart.OnPulsoGenerado += this.Uart_OnPulsoGenerado; } this.IniciarMQTT(); } else { MessageBox.Show("Bancada no configurada", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } loading.Close(); } catch (Exception ex) { Log.Write(ex); loading.Close(); } Notifica(); }; bw.RunWorkerAsync(); }
private void ProcesarDatos() { if (this.dgvDatos.Rows.Count <= 0) { return; } Cargando.Mostrar(); // Se obtienen los rangos var oRangos = Datos.GetListOf <ParteAbcRango>(); // Se obtiene el listado de partes, para sacar los porcentajes de utilidad var oPorUtilAcum = new Dictionary <int, decimal>(); var oPartesUtil = this.oPartesAbc.OrderByDescending(q => q.Utilidad); decimal mTotalUtil = oPartesUtil.Sum(q => q.Utilidad); decimal mPorUtilAcum = 0; foreach (var oParteU in oPartesUtil) { mPorUtilAcum += ((oParteU.Utilidad / mTotalUtil) * 100); oPorUtilAcum.Add(oParteU.ParteID, mPorUtilAcum); } // Se obtiene el listado de utilidades por proveedor var oPorUtilAcumProv = new Dictionary <int, decimal>(); var oProvUtil = this.oPartesAbc.GroupBy(g => g.ProveedorID).Select(o => new { ProveedorID = o.Key, Utilidad = o.Sum(q => q.Utilidad) }) .OrderByDescending(q => q.Utilidad); mPorUtilAcum = 0; foreach (var oProv in oProvUtil) { mPorUtilAcum += ((oProv.Utilidad / mTotalUtil) * 100); oPorUtilAcumProv.Add(oProv.ProveedorID, mPorUtilAcum); } // Se obtiene el listado de utilidades por línea var oPorUtilAcumLinea = new Dictionary <int, decimal>(); var oLineaUtil = this.oPartesAbc.GroupBy(g => g.LineaID).Select(o => new { LineaID = o.Key, Utilidad = o.Sum(q => q.Utilidad) }) .OrderByDescending(q => q.Utilidad); mPorUtilAcum = 0; foreach (var oLinea in oLineaUtil) { mPorUtilAcum += ((oLinea.Utilidad / mTotalUtil) * 100); oPorUtilAcumLinea.Add(oLinea.LineaID, mPorUtilAcum); } // Se comienzan a procesar las partes pauPartesAbc_Result oParte; bool bYaVentas, bYaUtilidad, bYaNegocio, bYaProveedor, bYaLinea; decimal mCantidad, mUtilidadUni; mPorUtilAcum = 0; decimal mPorUtilAcumProv = 0, mPorUtilAcumLinea = 0; foreach (DataGridViewRow Fila in this.dgvDatos.Rows) { // Se limpian los Abc actuales Fila.Cells["AbcDeVentas"].Value = ""; Fila.Cells["AbcDeUtilidad"].Value = ""; Fila.Cells["AbcDeNegocio"].Value = ""; Fila.Cells["AbcDeProveedor"].Value = ""; Fila.Cells["AbcDeLinea"].Value = ""; // oParte = (Fila.Tag as pauPartesAbc_Result); bYaVentas = bYaUtilidad = bYaNegocio = bYaProveedor = bYaLinea = false; mCantidad = Math.Round(oParte.Cantidad, 0); mUtilidadUni = Math.Round(oParte.UtilidadUniP1, 2); mPorUtilAcum = Math.Round(oPorUtilAcum[oParte.ParteID], 0); mPorUtilAcumProv = Math.Round(oPorUtilAcumProv[oParte.ProveedorID], 1); mPorUtilAcumLinea = Math.Round(oPorUtilAcumLinea[oParte.LineaID], 0); // Se recorren los rangos en busca del que coincida con el valor de la parte foreach (var oRango in oRangos) { switch (oRango.TipoDeRango) { // Se calcula el Abc de Ventas case Cat.TiposDeAbc.Ventas: if (bYaVentas) { break; } if ((oRango.Inicial == null || mCantidad >= oRango.Inicial) && (oRango.Final == null || mCantidad <= oRango.Final)) { oParte.AbcDeVentas = oRango.Abc; bYaVentas = true; } break; // Se calcula el Abc de Utilidad case Cat.TiposDeAbc.Utilidad: if (bYaUtilidad) { break; } if ((oRango.Inicial == null || mUtilidadUni >= oRango.Inicial) && (oRango.Final == null || mUtilidadUni <= oRango.Final)) { oParte.AbcDeUtilidad = oRango.Abc; bYaUtilidad = true; } break; // Se calcula el Abc de Negocio case Cat.TiposDeAbc.Negocio: if (bYaNegocio) { break; } if ((oRango.Inicial == null || mPorUtilAcum >= oRango.Inicial) && (oRango.Final == null || mPorUtilAcum <= oRango.Final)) { oParte.AbcDeNegocio = oRango.Abc; bYaNegocio = true; } break; // Se calcula el Abc de Proveedor case Cat.TiposDeAbc.Proveedor: if (bYaProveedor) { break; } if ((oRango.Inicial == null || mPorUtilAcumProv >= oRango.Inicial) && (oRango.Final == null || mPorUtilAcumProv <= oRango.Final)) { oParte.AbcDeProveedor = oRango.Abc; bYaProveedor = true; } break; // Se calcula el Abc de Línea case Cat.TiposDeAbc.Linea: if (bYaLinea) { break; } if ((oRango.Inicial == null || mPorUtilAcumLinea >= oRango.Inicial) && (oRango.Final == null || mPorUtilAcumLinea <= oRango.Final)) { oParte.AbcDeLinea = oRango.Abc; bYaLinea = true; } break; } } // Se registran los Abc Fila.Cells["AbcDeVentas"].Value = oParte.AbcDeVentas; Fila.Cells["AbcDeUtilidad"].Value = oParte.AbcDeUtilidad; Fila.Cells["AbcDeNegocio"].Value = oParte.AbcDeNegocio; Fila.Cells["AbcDeProveedor"].Value = oParte.AbcDeProveedor; Fila.Cells["AbcDeLinea"].Value = oParte.AbcDeLinea; } Cargando.Cerrar(); }
private void CargarDatos() { Cargando.Mostrar(); var oParams = this.ObtenerParametros(); var oDatos = Datos.ExecuteProcedure <pauCuadroDeControlGeneralNuevo_Result>("pauCuadroDeControlGeneral", oParams); var oTotales = this.ObtenerTotales(oDatos); // Se llena el grid de por semana var oPorSemana = this.AgruparPorEntero(oDatos.GroupBy(g => UtilTheos.SemanaSabAVie(g.Fecha))); this.dgvSemana.Rows.Clear(); // this.chrSemana.Series["Actual"].Points.Clear(); // this.chrSemana.Series["Pasado"].Points.Clear(); foreach (var oReg in oPorSemana) { this.dgvSemana.Rows.Add(oReg.Llave, oReg.Llave, oReg.Actual, oReg.Anterior , Util.DividirONull(oReg.Actual, oReg.Anterior), (Util.DividirONull(oReg.Actual, oTotales.Actual) * 100)); // this.chrSemana.Series["Actual"].Points.AddXY(oReg.Semana, oReg.Actual); // this.chrSemana.Series["Pasado"].Points.AddXY(oReg.Semana, oReg.Anterior); } this.dgvSemanaT["SemanaT_Actual", 0].Value = oTotales.Actual; this.dgvSemanaT["SemanaT_Anterior", 0].Value = oTotales.Anterior; this.dgvSemanaT["SemanaT_Resultado", 0].Value = Util.DividirONull(oTotales.Actual, oTotales.Anterior); // Se llena el grid de Vendedores con semanas int iFila; Dictionary <string, decimal> oSemanasT = new Dictionary <string, decimal>(); var oPorVendedor = this.AgruparPorEnteroCadenaEntero(oDatos.GroupBy(g => new AgrupadoPorEnteroCadenaEntero() { Llave = g.VendedorID, Cadena = g.Vendedor, Entero = UtilTheos.SemanaSabAVie(g.Fecha) })).OrderBy(c => c.Entero); this.dgvVendedorSem.Rows.Clear(); foreach (var oReg in oPorVendedor) { // Se encuentra la fila del vendedor, o se agrega si no existe iFila = this.dgvVendedorSem.EncontrarIndiceDeValor("VendedorSem_Id", oReg.Llave); if (iFila < 0) { var oVendedor = oPorVendedor.Where(c => c.Llave == oReg.Llave); iFila = this.dgvVendedorSem.Rows.Add(oReg.Llave, oReg.Cadena , oVendedor.Average(c => c.Actual), oVendedor.Sum(c => c.Actual)); } // Se verifica si existe la columna de la semana, si no, se agrega string sColSem = ("VendedorSem_" + oReg.Entero.ToString()); if (!this.dgvVendedorSem.Columns.Contains(sColSem)) { this.dgvVendedorSem.Columns.Add(sColSem, ("Sem " + oReg.Entero.ToString())); this.dgvVendedorSem.Columns[sColSem].FormatoMoneda(); } if (!oSemanasT.ContainsKey(sColSem)) { oSemanasT.Add(sColSem, 0); } // Se llenan los datos this.dgvVendedorSem[sColSem, iFila].Value = oReg.Actual; oSemanasT[sColSem] += oReg.Actual; // Para el formato de la columna // this.dgvVendedorSem.Columns[sColSem].DefaultCellStyle.Format = (this.cmbCalculo.Text == "Ventas" ? "N0" : "C2"); } // Se agrega la fila de total // this.dgvVendedorSem.Rows.Add(); iFila = this.dgvVendedorSem.Rows.Add(0, "Totales", oPorVendedor.Average(c => c.Actual), oPorVendedor.Sum(c => c.Actual)); this.dgvVendedorSem.Rows[iFila].DefaultCellStyle.Font = new Font(this.dgvVendedorSem.Font, FontStyle.Bold); foreach (DataGridViewColumn oCol in this.dgvVendedorSem.Columns) { if (oCol.Index < 4) { continue; } if (!oSemanasT.ContainsKey(oCol.Name)) { continue; } this.dgvVendedorSem[oCol.Name, iFila].Value = oSemanasT[oCol.Name]; } // Se configuran columnas del grid this.AplicarFormatoColumnas(); Cargando.Cerrar(); }
public void LlenarCuentasTotales() { Cargando.Mostrar(); // Se guarda la selección actual var oRutaNodoAct = new List <int>(); var oNodo = this.tgvCuentas.CurrentNode; while (oNodo != null && oNodo.Level > 0) { oRutaNodoAct.Insert(0, oNodo.Index); oNodo = oNodo.Parent; } var oParams = new Dictionary <string, object>(); oParams.Add("Desde", this.dtpDesde.Value); oParams.Add("Hasta", this.dtpHasta.Value); // Se llenan los datos var oDatos = Datos.ExecuteProcedure <pauContaCuentasTotales_Result>("pauContaCuentasTotales", oParams); TreeGridNode oNodoCuenta = null, oNodoSubcuenta = null, oNodoCuentaDeMayor = null; string sCuenta = "", sSubcuenta = "", sCuentaDeMayor = ""; this.tgvCuentas.Nodes.Clear(); this.oIndiceCuentas.Clear(); foreach (var oCuenta in oDatos) { // Nodo de Cuenta if (oCuenta.Cuenta != sCuenta) { sCuenta = oCuenta.Cuenta; oNodoCuenta = this.tgvCuentas.Nodes.Add(oCuenta.ContaCuentaID, sCuenta); oNodoCuenta.DefaultCellStyle.Font = new Font(this.tgvCuentas.Font.FontFamily, 10); this.oIndiceCuentas.Add(new ContaModelos.IndiceCuentasContables() { Cuenta = sCuenta.ToLower(), Nivel = 1, IndiceCuenta = oNodoCuenta.Index }); sSubcuenta = ""; } // Nodo de Subcuenta if (oCuenta.Subcuenta == null) { continue; } else if (oCuenta.Subcuenta != sSubcuenta) { sSubcuenta = oCuenta.Subcuenta; oNodoSubcuenta = oNodoCuenta.Nodes.Add(oCuenta.ContaSubcuentaID, sSubcuenta); oNodoSubcuenta.DefaultCellStyle.Font = new Font(this.tgvCuentas.Font.FontFamily, 9); this.oIndiceCuentas.Add(new ContaModelos.IndiceCuentasContables() { Cuenta = sSubcuenta.ToLower(), Nivel = 2 , IndiceCuenta = oNodoCuenta.Index, IndiceSubcuenta = oNodoSubcuenta.Index }); sCuentaDeMayor = ""; } // Nodo de Cuenta de mayor if (oCuenta.CuentaDeMayor == null) { continue; } else if (oCuenta.CuentaDeMayor != sCuentaDeMayor) { sCuentaDeMayor = oCuenta.CuentaDeMayor; oNodoCuentaDeMayor = oNodoSubcuenta.Nodes.Add(oCuenta.ContaCuentaDeMayorID, sCuentaDeMayor); oNodoCuentaDeMayor.DefaultCellStyle.Font = new Font(this.tgvCuentas.Font, FontStyle.Bold); this.oIndiceCuentas.Add(new ContaModelos.IndiceCuentasContables() { Cuenta = sCuentaDeMayor.ToLower(), Nivel = 3 , IndiceCuenta = oNodoCuenta.Index, IndiceSubcuenta = oNodoSubcuenta.Index, IndiceCuentaDeMayor = oNodoCuentaDeMayor.Index }); } // Se agrega la cuenta auxiliar if (oCuenta.CuentaAuxiliar == null) { continue; } var oNodoCuentaAux = oNodoCuentaDeMayor.Nodes.Add( oCuenta.ContaCuentaAuxiliarID, oCuenta.CuentaAuxiliar, 0, oCuenta.Fiscal, oCuenta.Total, oCuenta.Matriz, oCuenta.Suc02, oCuenta.Suc03, (oCuenta.ImporteDev + oCuenta.ImporteDevEsp) ); this.oIndiceCuentas.Add(new ContaModelos.IndiceCuentasContables() { Cuenta = oCuenta.CuentaAuxiliar.ToLower(), Nivel = 4, IndiceCuenta = oNodoCuenta.Index, IndiceSubcuenta = oNodoSubcuenta.Index, IndiceCuentaDeMayor = oNodoCuentaDeMayor.Index, IndiceCuentaAuxiliar = oNodoCuentaAux.Index }); // Se agregan totales para los niveles superiores decimal mImporte = 0; for (int iCol = 2; iCol < this.tgvCuentas.Columns.Count; iCol++) { switch (iCol) { case ColsCuentas.Fiscal: mImporte = oCuenta.Fiscal.Valor(); break; case ColsCuentas.Total: mImporte = oCuenta.Total.Valor(); break; case ColsCuentas.Matriz: mImporte = oCuenta.Matriz.Valor(); break; case ColsCuentas.Sucursal2: mImporte = oCuenta.Suc02.Valor(); break; case ColsCuentas.Sucursal3: mImporte = oCuenta.Suc03.Valor(); break; case ColsCuentas.ImporteDev: mImporte = (oCuenta.ImporteDev.Valor() + oCuenta.ImporteDevEsp.Valor()); break; } oNodoCuentaDeMayor.Cells[iCol].Value = (Util.Decimal(oNodoCuentaDeMayor.Cells[iCol].Value) + mImporte); oNodoSubcuenta.Cells[iCol].Value = (Util.Decimal(oNodoSubcuenta.Cells[iCol].Value) + mImporte); oNodoCuenta.Cells[iCol].Value = (Util.Decimal(oNodoCuenta.Cells[iCol].Value) + mImporte); } } // Se aplica el formato y el color, y se llena el porcentaje decimal mCuenta = 0, mSubcuenta = 0, mCuentaDeMayor = 0, mCuentaAux = 0; foreach (var oNodCuenta in this.tgvCuentas.Nodes) { oNodCuenta.Expand(); mCuenta = Util.Decimal(oNodCuenta.Cells["Cuentas_Total"].Value); oNodCuenta.Cells["Cuentas_Porcentaje"].Value = "-"; foreach (var oNodSubcuenta in oNodCuenta.Nodes) { oNodSubcuenta.Expand(); mSubcuenta = Util.Decimal(oNodSubcuenta.Cells["Cuentas_Total"].Value); if (mCuenta != 0) { oNodSubcuenta.Cells["Cuentas_Porcentaje"].Value = ((mSubcuenta / mCuenta) * 100); } foreach (var oNodCuentaDeMayor in oNodSubcuenta.Nodes) { mCuentaDeMayor = Util.Decimal(oNodCuentaDeMayor.Cells["Cuentas_Total"].Value); if (mSubcuenta != 0) { oNodCuentaDeMayor.Cells["Cuentas_Porcentaje"].Value = ((mCuentaDeMayor / mSubcuenta) * 100); } foreach (var oNodCuentaAuxiliar in oNodCuentaDeMayor.Nodes) { this.AplicarColor(oNodCuentaAuxiliar); this.FormatoColumnasImporte(oNodCuentaAuxiliar); mCuentaAux = Util.Decimal(oNodCuentaAuxiliar.Cells[ColsCuentas.Total].Value); if (mCuentaDeMayor != 0) { oNodCuentaAuxiliar.Cells[ColsCuentas.Porcentaje].Value = ((mCuentaAux / mCuentaDeMayor) * 100); } } this.AplicarColor(oNodCuentaDeMayor); this.FormatoColumnasImporte(oNodCuentaDeMayor); oNodCuentaDeMayor.Collapse(); } this.AplicarColor(oNodSubcuenta); this.FormatoColumnasImporte(oNodSubcuenta); } this.AplicarColor(oNodCuenta); this.FormatoColumnasImporte(oNodCuenta); } // Se selecciona el nodo previamente seleccionado oNodo = (oRutaNodoAct.Count > 0 ? this.tgvCuentas.Nodes[oRutaNodoAct[0]] : null); for (int iNodo = 1; iNodo < oRutaNodoAct.Count; iNodo++) { oNodo.Expand(); oNodo = oNodo.Nodes[oRutaNodoAct[iNodo]]; this.tgvCuentas.CurrentCell = oNodo.Cells["Cuentas_Cuenta"]; } Cargando.Cerrar(); }
private void LlenarVencimientos() { Cargando.Mostrar(); DateTime dAhora = DateTime.Now; var oVentasC = Datos.GetListOf <VentasACreditoView>(c => dAhora > c.Vencimiento && c.Restante > 0).OrderBy(o => o.Cliente); this.dgvVencimientos.Rows.Clear(); int iClienteID = 0; string sCliente = ""; decimal mSem1, mSem2, mSem3, mSem4, mMes; mSem1 = mSem2 = mSem3 = mSem4 = mMes = 0; bool bPrimeraVuelta = true; foreach (var oVenta in oVentasC) { // Se verifica si es la primera vuelta, para no agregar nada pues falta ver si la siguiente es el mismo cliente if (bPrimeraVuelta) { iClienteID = oVenta.ClienteID; sCliente = oVenta.Cliente; bPrimeraVuelta = false; } // if (oVenta.ClienteID != iClienteID) { // Se agrega el cliente al grid this.dgvVencimientos.Rows.Add(iClienteID, sCliente, (mSem1 + mSem2 + mSem3 + mSem4 + mMes), mSem1, mSem2, mSem3, mSem4, mMes); // Se restauran los valores con el siguiente cliente iClienteID = oVenta.ClienteID; sCliente = oVenta.Cliente; mSem1 = mSem2 = mSem3 = mSem4 = mMes = 0; } // Se calculan los importes de vencimiento por períodos de tiempo int iDiasVencido = (dAhora - oVenta.Vencimiento.Valor()).Days; if (iDiasVencido < 8) { mSem1 += oVenta.Restante; } else if (iDiasVencido < 15) { mSem2 += oVenta.Restante; } else if (iDiasVencido < 22) { mSem3 += oVenta.Restante; } else if (iDiasVencido < 29) { mSem4 += oVenta.Restante; } else { mMes += oVenta.Restante; } } // Se agrega el último cliente, si aplica if (iClienteID > 0) { this.dgvVencimientos.Rows.Add(iClienteID, sCliente, (mSem1 + mSem2 + mSem3 + mSem4 + mMes), mSem1, mSem2, mSem3, mSem4, mMes); } // Se ordena según var oListaGrid = new[] { new { ClienteID = 1, Cliente = "uno", Vencido = 1.1 , UnaSem = 1.1, DosSem = 1.1, TresSem = 1.1, CuatroSem = 1.1, MasMes = 1.1 } }.ToList(); oListaGrid.Clear(); foreach (DataGridViewRow oFila in this.dgvVencimientos.Rows) { oListaGrid.Add(new { ClienteID = Util.Entero(oFila.Cells["ClienteID"].Value), Cliente = Util.Cadena(oFila.Cells["colCliente"].Value), Vencido = Util.Doble(oFila.Cells["Vencido"].Value), UnaSem = Util.Doble(oFila.Cells["UnaSem"].Value), DosSem = Util.Doble(oFila.Cells["DosSem"].Value), TresSem = Util.Doble(oFila.Cells["TresSem"].Value), CuatroSem = Util.Doble(oFila.Cells["CuatroSem"].Value), MasMes = Util.Doble(oFila.Cells["MasMes"].Value) }); } oListaGrid = oListaGrid.OrderByDescending(c => c.MasMes).ThenByDescending(c => c.CuatroSem).ThenByDescending(c => c.TresSem) .ThenByDescending(c => c.DosSem).ThenByDescending(c => c.UnaSem).ToList(); // Se llenan los totales for (int iCol = 1; iCol < this.dgvVencimientosTotales.Columns.Count; iCol++) { this.dgvVencimientosTotales[iCol, 0].Value = 0; } if (oListaGrid.Count > 0) { this.dgvVencimientosTotales["tvVencido", 0].Value = oListaGrid.Sum(c => c.Vencido); this.dgvVencimientosTotales["tvUnaSem", 0].Value = oListaGrid.Sum(c => c.UnaSem); this.dgvVencimientosTotales["tvDosSem", 0].Value = oListaGrid.Sum(c => c.DosSem); this.dgvVencimientosTotales["tvTresSem", 0].Value = oListaGrid.Sum(c => c.TresSem); this.dgvVencimientosTotales["tvCuatroSem", 0].Value = oListaGrid.Sum(c => c.CuatroSem); this.dgvVencimientosTotales["tvMasMes", 0].Value = oListaGrid.Sum(c => c.MasMes); } // var oDatos = this.dgvVencimientos.ADataTable(); this.dgvVencimientos.Rows.Clear(); foreach (var oReg in oListaGrid) { this.dgvVencimientos.Rows.Add(oReg.ClienteID, oReg.Cliente, oReg.Vencido, oReg.UnaSem, oReg.DosSem, oReg.TresSem, oReg.CuatroSem, oReg.MasMes); } Cargando.Cerrar(); }
private void Ncf_CrearNotaDeCreditoFiscal() { // Se verifica si hay ventas seleccionadas if (this.dgvNcf_Facturas.ContarIncidencias("Ncf_Aplicar", true) == 0) { UtilLocal.MensajeAdvertencia("No hay ninguna venta seleccionada."); return; } // Se obtiene el concepto var oConcepto = UtilLocal.ObtenerValor("Concepto de Nota de Crédito:", "", MensajeObtenerValor.Tipo.TextoLargo); if (oConcepto == null) { return; } // Se valida el permiso var oResU = UtilLocal.ValidarObtenerUsuario("Ventas.NotasDeCreditoFiscales.Agregar"); if (oResU.Error) { return; } int iUsuarioID = oResU.Respuesta.UsuarioID; // Se solicita la validación de autorización var oResA = UtilLocal.ValidarObtenerUsuario("Autorizaciones.Ventas.NotasDeCreditoFiscales.Agregar", "Autorización"); int?iAutorizoID = (oResA.Respuesta == null ? null : (int?)oResA.Respuesta.UsuarioID); // Se genera el detalle de la nota de crédito, para mandar a hacer la factura decimal mTotal = 0; var oNotaDetalle = new List <ProductoVenta>(); oNotaDetalle.Add(new ProductoVenta() { NombreDeParte = Util.Cadena(oConcepto), UnidadDeMedida = "." }); // Se meten las facturas afectadas foreach (DataGridViewRow oFila in this.dgvNcf_Facturas.Rows) { if (!Util.Logico(oFila.Cells["Ncf_Aplicar"].Value)) { continue; } int iVentaID = Util.Entero(oFila.Cells["Ncf_VentaID"].Value); decimal mImporte = Util.Decimal(oFila.Cells["Ncf_Diferencia"].Value); mTotal += mImporte; var oVenta = Datos.GetEntity <Venta>(c => c.VentaID == iVentaID && c.Estatus); oNotaDetalle.Add(new ProductoVenta() { NumeroDeParte = iVentaID.ToString(), // Se usa para mete la VentaID NombreDeParte = string.Format("FACTURA: {0}", oVenta.Folio), // Se usa para mostrar la factura Cantidad = 1, PrecioUnitario = UtilTheos.ObtenerPrecioSinIva(mImporte), Iva = UtilTheos.ObtenerIvaDePrecio(mImporte), UnidadDeMedida = "." }); } if (mTotal == 0) { return; } Cargando.Mostrar(); // Se manda hacer la nota de crédito fiscal var oRes = VentasLoc.GenerarNotaDeCreditoFiscal(oNotaDetalle, this.Cliente.ClienteID, iUsuarioID); if (oRes.Error) { Cargando.Cerrar(); UtilLocal.MensajeAdvertencia(string.Format("Ocurrió un error al hacer la Nota de Crédito Fiscal\n\n{0}", oRes.Mensaje)); return; } // Se modifica el detalle de la Nota de Crédito Fiscal, con datos adicionales de las ventas afectadas var oNcVentas = Datos.GetListOf <NotaDeCreditoFiscalDetalle>(c => c.NotaDeCreditoFiscalID == oRes.Respuesta); foreach (DataGridViewRow oFila in this.dgvNcf_Facturas.Rows) { if (!Util.Logico(oFila.Cells["Ncf_Aplicar"].Value)) { continue; } int iVentaID = Util.Entero(oFila.Cells["Ncf_VentaID"].Value); int iListaPre = Util.Entero(oFila.Cells["Ncf_ListaDePrecios"].Value); var oVentaV = Datos.GetEntity <VentasView>(c => c.VentaID == iVentaID); var oNcVenta = oNcVentas.FirstOrDefault(c => c.VentaID == iVentaID); if (oNcVenta == null) { continue; } oNcVenta.ListaDePreciosUsada = iListaPre; oNcVenta.ImporteAntes = oVentaV.Total; Datos.Guardar <NotaDeCreditoFiscalDetalle>(oNcVenta); } // Se descuenta el importe en cada artículo de las ventas afectadas foreach (DataGridViewRow oFila in this.dgvNcf_Facturas.Rows) { if (!Util.Logico(oFila.Cells["Ncf_Aplicar"].Value)) { continue; } int iVentaID = Util.Entero(oFila.Cells["Ncf_VentaID"].Value); int iListaPre = Util.Entero(oFila.Cells["Ncf_ListaDePrecios"].Value); var oPartes = Datos.GetListOf <VentaDetalle>(c => c.VentaID == iVentaID && c.Estatus); decimal mPrecio = 0; foreach (var oReg in oPartes) { var oPrecio = Datos.GetEntity <PartePrecio>(c => c.ParteID == oReg.ParteID && c.Estatus); switch (iListaPre) { case 1: mPrecio = oPrecio.PrecioUno.Valor(); break; case 2: mPrecio = oPrecio.PrecioDos.Valor(); break; case 3: mPrecio = oPrecio.PrecioTres.Valor(); break; case 4: mPrecio = oPrecio.PrecioCuatro.Valor(); break; case 5: mPrecio = oPrecio.PrecioCinco.Valor(); break; } // Se calcula el Iva oReg.PrecioUnitario = UtilTheos.ObtenerPrecioSinIva(mPrecio); oReg.Iva = (mPrecio - oReg.PrecioUnitario); Datos.Guardar <VentaDetalle>(oReg); } } // Se crea la póliza contable correspondiente (AfeConta) // Una póliza por cada venta afectada var oNotaV = Datos.GetEntity <NotasDeCreditoFiscalesView>(c => c.NotaDeCreditoFiscalID == oRes.Respuesta); foreach (var oReg in oNcVentas) { ContaProc.CrearPolizaAfectacion(Cat.ContaAfectaciones.NotaDeCreditoDescuentoVenta, oReg.NotaDeCreditoFiscalDetalleID , (oNotaV.Serie + oNotaV.Folio), oNotaV.Cliente); } // Se guarda la autorización VentasProc.GenerarAutorizacion(Cat.AutorizacionesProcesos.NotaDeCreditoFiscalCrear, "NotaDeCreditoFiscal", oRes.Respuesta, iAutorizoID); Cargando.Cerrar(); this.NcfLlenarFacturas(); }
private void CargarDatos() { Cargando.Mostrar(); var oFuenteT = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Bold); // Se limpian los datos this.dgvDatos.Rows.Clear(); foreach (var oSerie in this.chrPorSemana.Series) { oSerie.Points.Clear(); } // Se llenan las columnas del año int iAnio = Util.Entero(this.cmbAnio.Text); this.LlenarColumnasAnio(iAnio); // Se obtienen los datos para los ingresos int iSucursalID = Util.Entero(this.cmbSucursal.SelectedValue); DateTime dDesde = new DateTime(iAnio, 1, 1); DateTime dHasta = new DateTime(iAnio, 12, 31); var oParams = new Dictionary <string, object>(); oParams.Add("SucursalID", (iSucursalID == 0 ? null : (int?)iSucursalID)); oParams.Add("Pagadas", true); oParams.Add("Cobradas", false); oParams.Add("Solo9500", false); oParams.Add("OmitirDomingo", false); oParams.Add("Desde", dDesde); oParams.Add("Hasta", dHasta); var oDatos = Datos.ExecuteProcedure <pauCuadroDeControlGeneralNuevo_Result>("pauCuadroDeControlGeneral", oParams); var oSemanas = oDatos.Where(c => c.Fecha >= dDesde) .GroupBy(c => new { Semana = UtilTheos.InicioSemanaSabAVie(c.Fecha), c.Sucursal }) .Select(c => new { c.Key.Semana, c.Key.Sucursal, PrecioSinIva = c.Sum(s => s.PrecioSinIvaActual), Costo = c.Sum(s => s.CostoDescActual) }) .OrderBy(c => c.Sucursal).ThenBy(c => c.Semana); // Se agrega la fila de ingresos int iFilaIngresos = this.dgvDatos.Rows.Add("+ Ingresos", oSemanas.Sum(c => c.PrecioSinIva), oSemanas.Average(c => c.PrecioSinIva)); this.dgvDatos.Rows[iFilaIngresos].DefaultCellStyle.Font = oFuenteT; // Se llenan los ingresos string sSucursal = ""; int iFila = 0; foreach (var oReg in oSemanas) { if (sSucursal != oReg.Sucursal) { sSucursal = oReg.Sucursal; iFila = this.dgvDatos.Rows.Add(sSucursal, oSemanas.Where(c => c.Sucursal == sSucursal).Sum(c => c.PrecioSinIva) , oSemanas.Where(c => c.Sucursal == sSucursal).Average(c => c.PrecioSinIva)); } string sSemana = oReg.Semana.ToShortDateString(); this.dgvDatos[sSemana, iFila].Value = (Util.Decimal(this.dgvDatos[sSemana, iFila].Value) + oReg.PrecioSinIva); this.dgvDatos[sSemana, iFilaIngresos].Value = (Util.Decimal(this.dgvDatos[sSemana, iFilaIngresos].Value) + oReg.PrecioSinIva); } // Se agrega la fila de Costos int iFilaCostos = this.dgvDatos.Rows.Add("- Costos", oSemanas.Sum(c => c.Costo), oSemanas.Average(c => c.Costo)); this.dgvDatos.Rows[iFilaCostos].DefaultCellStyle.Font = oFuenteT; // Se llenan los costos sSucursal = ""; foreach (var oReg in oSemanas) { if (sSucursal != oReg.Sucursal) { sSucursal = oReg.Sucursal; iFila = this.dgvDatos.Rows.Add(sSucursal, oSemanas.Where(c => c.Sucursal == sSucursal).Sum(c => c.Costo) , oSemanas.Where(c => c.Sucursal == sSucursal).Average(c => c.Costo)); } string sSemana = oReg.Semana.ToShortDateString(); this.dgvDatos[sSemana, iFila].Value = (Util.Decimal(this.dgvDatos[sSemana, iFila].Value) + oReg.Costo); this.dgvDatos[sSemana, iFilaCostos].Value = (Util.Decimal(this.dgvDatos[sSemana, iFilaCostos].Value) + oReg.Costo); } // Se agrega la fila de margen bruto int iFilaMargen = this.dgvDatos.Rows.Add("= Margen Bruto"); this.dgvDatos.Rows[iFilaMargen].DefaultCellStyle.Font = oFuenteT; foreach (DataGridViewColumn oCol in this.dgvDatos.Columns) { if (oCol.Index == 0) { continue; } this.dgvDatos[oCol.Index, iFilaMargen].Value = ( Util.Decimal(this.dgvDatos[oCol.Index, iFilaIngresos].Value) - Util.Decimal(this.dgvDatos[oCol.Index, iFilaCostos].Value) ); } // Se obtienen los datos para los gastos oParams.Clear(); oParams.Add("Desde", dDesde); oParams.Add("Hasta", dHasta); var oGastos = Datos.ExecuteProcedure <pauContaCuentasPorSemana_Result>("pauContaCuentasPorSemana", oParams); var oGastosSemFijo = oGastos.GroupBy(c => new { Semana = UtilTheos.InicioSemanaSabAVie(c.Fecha), c.Sucursal }) .Select(c => new ContaProc.GastoSem() { Semana = c.Key.Semana, Grupo = c.Key.Sucursal, Importe = c.Sum(s => s.ImporteDev).Valor() }); // Se obtiene los datos según el tipo de semanalización List <ContaProc.GastoSem> oGastosSem; if (this.rdbSemanalizar.Checked) { oGastosSem = ContaProc.GastosSemanalizados(oGastos, Util.FechaHora(this.dgvDatos.Columns[this.dgvDatos.Columns.Count - 1].Name)); } else { oGastosSem = oGastosSemFijo.OrderBy(c => c.Grupo).ThenBy(c => c.Semana).ToList(); } // Se agrega la fila de los Gastos int iFilaGastos = this.dgvDatos.Rows.Add("- Gastos", oGastosSem.Sum(c => c.Importe), oGastosSem.Average(c => c.Importe)); this.dgvDatos.Rows[iFilaGastos].DefaultCellStyle.Font = oFuenteT; // Se llenan los gastos sSucursal = ""; foreach (var oReg in oGastosSem) { if (sSucursal != oReg.Grupo) { sSucursal = oReg.Grupo; iFila = this.dgvDatos.Rows.Add(sSucursal, oGastosSem.Where(c => c.Grupo == sSucursal).Sum(c => c.Importe) , oGastosSem.Where(c => c.Grupo == sSucursal).Average(c => c.Importe)); } string sSemana = oReg.Semana.ToShortDateString(); this.dgvDatos[sSemana, iFila].Value = (Util.Decimal(this.dgvDatos[sSemana, iFila].Value) + oReg.Importe); this.dgvDatos[sSemana, iFilaGastos].Value = (Util.Decimal(this.dgvDatos[sSemana, iFilaGastos].Value) + oReg.Importe); } // Se agrega la fila de utilidad, con cada una de las sucursales int iFilaUtilidad = this.dgvDatos.Rows.Add("= Utilidad"); this.dgvDatos.Rows[iFilaUtilidad].DefaultCellStyle.Font = oFuenteT; // Sucursales var oSucursales = Datos.GetListOf <Sucursal>(c => c.Estatus).OrderBy(c => c.NombreSucursal).ToList(); foreach (var oReg in oSucursales) { this.dgvDatos.Rows.Add(oReg.NombreSucursal); } // Se llenan los datos foreach (DataGridViewColumn oCol in this.dgvDatos.Columns) { if (oCol.Index == 0) { continue; } // Utilidad total this.dgvDatos[oCol.Index, iFilaUtilidad].Value = ( Util.Decimal(this.dgvDatos[oCol.Index, iFilaMargen].Value) - Util.Decimal(this.dgvDatos[oCol.Index, iFilaGastos].Value) ); // Sucursales for (int i = 1; i <= oSucursales.Count; i++) { this.dgvDatos[oCol.Index, iFilaUtilidad + i].Value = ( Util.Decimal(this.dgvDatos[oCol.Index, iFilaIngresos + i].Value) - Util.Decimal(this.dgvDatos[oCol.Index, iFilaCostos + i].Value) - Util.Decimal(this.dgvDatos[oCol.Index, iFilaGastos + i].Value) ); } } // Se obtienen los datos de gastos especiales DateTime dHastaMas1 = dHasta.AddDays(1); // Se obtiene los datos según el tipo de semanalización List <ContaProc.GastoSem> oGastosSemEsp; var oGastosSemEspFijo = Datos.GetListOf <ContaEgresosDevengadoEspecialCuentasView>(c => c.Fecha >= dDesde && c.Fecha < dHastaMas1) .GroupBy(c => new { c.Duenio, Semana = UtilTheos.InicioSemanaSabAVie(c.Fecha) }) .Select(c => new ContaProc.GastoSem() { Semana = c.Key.Semana, Grupo = c.Key.Duenio, Importe = c.Sum(s => s.ImporteDev) }); if (this.rdbSemanalizar.Checked) { oGastosSemEsp = ContaProc.GastosSemanalizados(Datos.GetListOf <ContaEgresosDevengadoEspecialCuentasView>(c => c.Fecha >= dDesde && c.Fecha < dHastaMas1) , Util.FechaHora(this.dgvDatos.Columns[this.dgvDatos.Columns.Count - 1].Name)); } else { oGastosSemEsp = oGastosSemEspFijo.OrderBy(c => c.Grupo).ThenBy(c => c.Semana).ToList(); } // Se agrega la fila de Especiales bool bHay = (oGastosSemEspFijo.Count() > 0); int iFilaEsp = this.dgvDatos.Rows.Add("- Especiales", (bHay ? oGastosSemEspFijo.Sum(c => c.Importe) : 0) , (bHay ? oGastosSemEspFijo.Average(c => c.Importe) : 0)); this.dgvDatos.Rows[iFilaEsp].DefaultCellStyle.Font = oFuenteT; // Se llenan los gastos string sDuenio = ""; foreach (var oReg in oGastosSemEsp) { if (sDuenio != oReg.Grupo) { sDuenio = oReg.Grupo; iFila = this.dgvDatos.Rows.Add(sDuenio, oGastosSemEspFijo.Where(c => c.Grupo == sDuenio).Sum(c => c.Importe) , oGastosSemEspFijo.Where(c => c.Grupo == sDuenio).Average(c => c.Importe)); } string sSemana = oReg.Semana.ToShortDateString(); this.dgvDatos[sSemana, iFila].Value = (Util.Decimal(this.dgvDatos[sSemana, iFila].Value) + oReg.Importe); this.dgvDatos[sSemana, iFilaEsp].Value = (Util.Decimal(this.dgvDatos[sSemana, iFilaEsp].Value) + oReg.Importe); } // Se agrega la fila de utilidad neta int iFilaDividendos = this.dgvDatos.Rows.Add("= Dividendos"); this.dgvDatos.Rows[iFilaDividendos].DefaultCellStyle.Font = oFuenteT; foreach (DataGridViewColumn oCol in this.dgvDatos.Columns) { if (oCol.Index == 0) { continue; } this.dgvDatos[oCol.Index, iFilaDividendos].Value = ( Util.Decimal(this.dgvDatos[oCol.Index, iFilaMargen].Value) - Util.Decimal(this.dgvDatos[oCol.Index, iFilaGastos].Value) - Util.Decimal(this.dgvDatos[oCol.Index, iFilaEsp].Value) ); } // Se obtienen los datos para lo de reinversión var oReinversiones = Datos.GetListOf <ContaPolizasDetalleAvanzadoView>(c => c.FechaPoliza >= dDesde && c.FechaPoliza < dHastaMas1 && ( c.ContaCuentaDeMayorID == Cat.ContaCuentasDeMayor.CuentasPorPagarLargoPlazo || (c.ContaCuentaDeMayorID == Cat.ContaCuentasDeMayor.CuentasPorPagarCortoPlazo && c.ContaCuentaAuxiliarID != Cat.ContaCuentasAuxiliares.TarjetaDeCredito) || c.ContaCuentaDeMayorID == Cat.ContaCuentasDeMayor.AcreedoresDiversos || (c.ContaSubcuentaID == Cat.ContaSubcuentas.ActivoFijo && c.ContaCuentaDeMayorID != Cat.ContaCuentasDeMayor.Edificios) )); var oDeudas = oReinversiones.Where(c => c.ContaCuentaDeMayorID == Cat.ContaCuentasDeMayor.CuentasPorPagarLargoPlazo || c.ContaCuentaDeMayorID == Cat.ContaCuentasDeMayor.CuentasPorPagarCortoPlazo || c.ContaCuentaDeMayorID == Cat.ContaCuentasDeMayor.AcreedoresDiversos) .GroupBy(c => UtilTheos.InicioSemanaSabAVie(c.FechaPoliza.Valor())) .Select(c => new { Semana = c.Key, Importe = c.Sum(s => s.Cargo) }); var oInversiones = oReinversiones.Where(c => c.ContaSubcuentaID == Cat.ContaSubcuentas.ActivoFijo) .GroupBy(c => UtilTheos.InicioSemanaSabAVie(c.FechaPoliza.Valor())).Select(c => new { Semana = c.Key, Importe = c.Sum(s => s.Cargo) }); // Se agrega la fila de Reinversión decimal mDeudas = (oDeudas.Count() > 0 ? oDeudas.Sum(c => c.Importe) : 0); decimal mDeudasProm = (oDeudas.Count() > 0 ? oDeudas.Average(c => c.Importe) : 0); decimal mInversiones = (oInversiones.Count() > 0 ? oInversiones.Sum(c => c.Importe) : 0); decimal mInversionesProm = (oInversiones.Count() > 0 ? oInversiones.Average(c => c.Importe) : 0); int iFilaReinversion = this.dgvDatos.Rows.Add("- Reinversión", (mDeudas + mInversiones), ((mDeudasProm + mInversionesProm) / 2)); this.dgvDatos.Rows[iFilaReinversion].DefaultCellStyle.Font = oFuenteT; // Se llenan los datos de reinversión // Deudas iFila = this.dgvDatos.Rows.Add("Deudas", mDeudas, mDeudasProm); foreach (var oReg in oDeudas) { string sSemana = oReg.Semana.ToShortDateString(); this.dgvDatos[sSemana, iFila].Value = (Util.Decimal(this.dgvDatos[sSemana, iFila].Value) + oReg.Importe); this.dgvDatos[sSemana, iFilaReinversion].Value = (Util.Decimal(this.dgvDatos[sSemana, iFilaReinversion].Value) + oReg.Importe); } // Inversión iFila = this.dgvDatos.Rows.Add("Inversiones", mInversiones, mInversionesProm); foreach (var oReg in oInversiones) { string sSemana = oReg.Semana.ToShortDateString(); this.dgvDatos[sSemana, iFila].Value = (Util.Decimal(this.dgvDatos[sSemana, iFila].Value) + oReg.Importe); this.dgvDatos[sSemana, iFilaReinversion].Value = (Util.Decimal(this.dgvDatos[sSemana, iFilaReinversion].Value) + oReg.Importe); } // Se agrega el saldo final int iFilaSaldo = this.dgvDatos.Rows.Add("= Saldo final"); this.dgvDatos.Rows[iFilaSaldo].DefaultCellStyle.Font = oFuenteT; foreach (DataGridViewColumn oCol in this.dgvDatos.Columns) { if (oCol.Index == 0) { continue; } this.dgvDatos[oCol.Index, iFilaSaldo].Value = ( Util.Decimal(this.dgvDatos[oCol.Index, iFilaDividendos].Value) - Util.Decimal(this.dgvDatos[oCol.Index, iFilaReinversion].Value) ); } // Se llena la gráfica, en base al grid ya cargado for (int iCol = this.iColumnasFijas; iCol < this.dgvDatos.Columns.Count; iCol++) { this.chrPorSemana.Series["Ingresos"].Points.AddY(Util.Decimal(this.dgvDatos[iCol, iFilaIngresos].Value)); this.chrPorSemana.Series["Costos"].Points.AddY(Util.Decimal(this.dgvDatos[iCol, iFilaCostos].Value)); this.chrPorSemana.Series["Margen"].Points.AddY(Util.Decimal(this.dgvDatos[iCol, iFilaMargen].Value)); this.chrPorSemana.Series["Gastos"].Points.AddY(Util.Decimal(this.dgvDatos[iCol, iFilaGastos].Value)); this.chrPorSemana.Series["Utilidad"].Points.AddY(Util.Decimal(this.dgvDatos[iCol, iFilaUtilidad].Value)); this.chrPorSemana.Series["Especiales"].Points.AddY(Util.Decimal(this.dgvDatos[iCol, iFilaEsp].Value)); this.chrPorSemana.Series["Dividendos"].Points.AddY(Util.Decimal(this.dgvDatos[iCol, iFilaDividendos].Value)); } Cargando.Cerrar(); }
private void CargarDatosPorTipo() { Cargando.Mostrar(); var oFuenteT = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Bold); // Se limpian los datos this.dgvDatos.Rows.Clear(); foreach (var oSerie in this.chrPorSemana.Series) { oSerie.Points.Clear(); } // Se borran las columnas de semanas for (int iCol = (this.dgvDatos.Columns.Count - 1); iCol >= this.iColumnasFijas; iCol--) { this.dgvDatos.Columns.RemoveAt(iCol); } // Se llenan las columnas string sPrefijo = ""; switch (this.cmbTipo.Text) { case "Mensual": sPrefijo = "Mes"; for (int iMes = 1; iMes <= 12; iMes++) { this.dgvDatos.Columns.Add((sPrefijo + iMes.ToString()), DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(iMes).PrimeraMayus()); } break; case "Trimestral": sPrefijo = "Tri"; for (int iMes = 1; iMes <= 12; iMes += 3) { this.dgvDatos.Columns.Add((sPrefijo + iMes.ToString()), DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(iMes).PrimeraMayus()); } break; case "Semestral": sPrefijo = "Sem"; for (int iMes = 1; iMes <= 12; iMes += 6) { this.dgvDatos.Columns.Add((sPrefijo + iMes.ToString()), DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(iMes).PrimeraMayus()); } break; } this.FormatoColumnas(); // Se obtienen los datos para los ingresos int iAnio = Util.Entero(this.cmbAnio.Text); int iSucursalID = Util.Entero(this.cmbSucursal.SelectedValue); DateTime dDesde = new DateTime(iAnio, 1, 1); DateTime dHasta = new DateTime(iAnio, 12, 31); DateTime dHastaMas1 = dHasta.AddDays(1); var oParams = new Dictionary <string, object>(); oParams.Add("SucursalID", (iSucursalID == 0 ? null : (int?)iSucursalID)); oParams.Add("Pagadas", true); oParams.Add("Cobradas", false); oParams.Add("Solo9500", false); oParams.Add("OmitirDomingo", false); oParams.Add("Desde", dDesde); oParams.Add("Hasta", dHasta); var oDatos = Datos.ExecuteProcedure <pauCuadroDeControlGeneralNuevo_Result>("pauCuadroDeControlGeneral", oParams); oDatos = oDatos.Where(c => c.Fecha >= dDesde).ToList(); List <ConsultaEdr> oConsulta = null; switch (this.cmbTipo.Text) { case "Mensual": oConsulta = oDatos.GroupBy(c => new { Mes = c.Fecha.Month, c.Sucursal }) .Select(c => new ConsultaEdr() { Mes = c.Key.Mes, Sucursal = c.Key.Sucursal , PrecioSinIva = c.Sum(s => s.PrecioSinIvaActual).Valor(), Costo = c.Sum(s => s.CostoDescActual).Valor() }) .OrderBy(c => c.Sucursal).ThenBy(c => c.Mes).ToList(); break; case "Trimestral": oConsulta = oDatos.GroupBy(c => new { Mes = UtilTheos.ObtenerTrimestre(c.Fecha), Sucursal = c.Sucursal }) .Select(c => new ConsultaEdr() { Mes = c.Key.Mes, Sucursal = c.Key.Sucursal , PrecioSinIva = c.Sum(s => s.PrecioSinIvaActual).Valor(), Costo = c.Sum(s => s.CostoDescActual).Valor() }) .OrderBy(c => c.Sucursal).ThenBy(c => c.Mes).ToList(); break; case "Semestral": oConsulta = oDatos.GroupBy(c => new { Mes = UtilTheos.ObtenerSemestre(c.Fecha), Sucursal = c.Sucursal }) .Select(c => new ConsultaEdr() { Mes = c.Key.Mes, Sucursal = c.Key.Sucursal , PrecioSinIva = c.Sum(s => s.PrecioSinIvaActual).Valor(), Costo = c.Sum(s => s.CostoDescActual).Valor() }) .OrderBy(c => c.Sucursal).ThenBy(c => c.Mes).ToList(); break; } // Se agrega la fila de ingresos int iFilaIngresos = this.dgvDatos.Rows.Add("+ Ingresos", oConsulta.Sum(c => c.PrecioSinIva), oConsulta.Average(c => c.PrecioSinIva)); this.dgvDatos.Rows[iFilaIngresos].DefaultCellStyle.Font = oFuenteT; // Se llenan los ingresos string sSucursal = ""; int iFila = 0; foreach (var oReg in oConsulta) { if (sSucursal != oReg.Sucursal) { sSucursal = oReg.Sucursal; iFila = this.dgvDatos.Rows.Add(sSucursal, oConsulta.Where(c => c.Sucursal == sSucursal).Sum(c => c.PrecioSinIva) , oConsulta.Where(c => c.Sucursal == sSucursal).Average(c => c.PrecioSinIva)); } string sColumna = (sPrefijo + oReg.Mes.ToString()); this.dgvDatos[sColumna, iFila].Value = (Util.Decimal(this.dgvDatos[sColumna, iFila].Value) + oReg.PrecioSinIva); this.dgvDatos[sColumna, iFilaIngresos].Value = (Util.Decimal(this.dgvDatos[sColumna, iFilaIngresos].Value) + oReg.PrecioSinIva); } // Se agrega la fila de Costos int iFilaCostos = this.dgvDatos.Rows.Add("- Costos", oConsulta.Sum(c => c.Costo), oConsulta.Average(c => c.Costo)); this.dgvDatos.Rows[iFilaCostos].DefaultCellStyle.Font = oFuenteT; // Se llenan los costos sSucursal = ""; foreach (var oReg in oConsulta) { if (sSucursal != oReg.Sucursal) { sSucursal = oReg.Sucursal; iFila = this.dgvDatos.Rows.Add(sSucursal, oConsulta.Where(c => c.Sucursal == sSucursal).Sum(c => c.Costo) , oConsulta.Where(c => c.Sucursal == sSucursal).Average(c => c.Costo)); } string sColumna = (sPrefijo + oReg.Mes.ToString()); this.dgvDatos[sColumna, iFila].Value = (Util.Decimal(this.dgvDatos[sColumna, iFila].Value) + oReg.Costo); this.dgvDatos[sColumna, iFilaCostos].Value = (Util.Decimal(this.dgvDatos[sColumna, iFilaCostos].Value) + oReg.Costo); } // Se agrega la fila de margen bruto int iFilaMargen = this.dgvDatos.Rows.Add("= Margen Bruto"); this.dgvDatos.Rows[iFilaMargen].DefaultCellStyle.Font = oFuenteT; foreach (DataGridViewColumn oCol in this.dgvDatos.Columns) { if (oCol.Index == 0) { continue; } this.dgvDatos[oCol.Index, iFilaMargen].Value = ( Util.Decimal(this.dgvDatos[oCol.Index, iFilaIngresos].Value) - Util.Decimal(this.dgvDatos[oCol.Index, iFilaCostos].Value) ); } // Se obtienen los datos para los gastos oParams.Clear(); oParams.Add("Desde", dDesde); oParams.Add("Hasta", dHasta); var oGastos = Datos.GetListOf <ContaEgresosView>(c => c.Fecha >= dDesde && c.Fecha < dHastaMas1); oConsulta = null; switch (this.cmbTipo.Text) { case "Mensual": oConsulta = oGastos.GroupBy(c => new { Mes = c.Fecha.Month, c.Sucursal }) .Select(c => new ConsultaEdr() { Mes = c.Key.Mes, Sucursal = c.Key.Sucursal, Importe = c.Sum(s => s.ImporteDev).Valor() }) .OrderBy(c => c.Sucursal).ThenBy(c => c.Mes).ToList(); break; case "Trimestral": oConsulta = oGastos.GroupBy(c => new { Mes = UtilTheos.ObtenerTrimestre(c.Fecha), c.Sucursal }) .Select(c => new ConsultaEdr() { Mes = c.Key.Mes, Sucursal = c.Key.Sucursal, Importe = c.Sum(s => s.ImporteDev).Valor() }) .OrderBy(c => c.Sucursal).ThenBy(c => c.Mes).ToList(); break; case "Semestral": oConsulta = oGastos.GroupBy(c => new { Mes = UtilTheos.ObtenerSemestre(c.Fecha), c.Sucursal }) .Select(c => new ConsultaEdr() { Mes = c.Key.Mes, Sucursal = c.Key.Sucursal, Importe = c.Sum(s => s.ImporteDev).Valor() }) .OrderBy(c => c.Sucursal).ThenBy(c => c.Mes).ToList(); break; } // Se agrega la fila de los Gastos int iFilaGastos = this.dgvDatos.Rows.Add("- Gastos", oConsulta.Sum(c => c.Importe), oConsulta.Average(c => c.Importe)); this.dgvDatos.Rows[iFilaGastos].DefaultCellStyle.Font = oFuenteT; // Se llenan los gastos sSucursal = ""; foreach (var oReg in oConsulta) { if (sSucursal != oReg.Sucursal) { sSucursal = oReg.Sucursal; iFila = this.dgvDatos.Rows.Add(sSucursal, oConsulta.Where(c => c.Sucursal == sSucursal).Sum(c => c.Importe) , oConsulta.Where(c => c.Sucursal == sSucursal).Average(c => c.Importe)); } string sColumna = (sPrefijo + oReg.Mes.ToString()); this.dgvDatos[sColumna, iFila].Value = (Util.Decimal(this.dgvDatos[sColumna, iFila].Value) + oReg.Importe); this.dgvDatos[sColumna, iFilaGastos].Value = (Util.Decimal(this.dgvDatos[sColumna, iFilaGastos].Value) + oReg.Importe); } // Se agrega la fila de utilidad, con cada una de las sucursales int iFilaUtilidad = this.dgvDatos.Rows.Add("= Utilidad"); this.dgvDatos.Rows[iFilaUtilidad].DefaultCellStyle.Font = oFuenteT; // Sucursales var oSucursales = Datos.GetListOf <Sucursal>(c => c.Estatus).OrderBy(c => c.NombreSucursal).ToList(); foreach (var oReg in oSucursales) { this.dgvDatos.Rows.Add(oReg.NombreSucursal); } // Se llenan los datos foreach (DataGridViewColumn oCol in this.dgvDatos.Columns) { if (oCol.Index == 0) { continue; } // Utilidad total this.dgvDatos[oCol.Index, iFilaUtilidad].Value = ( Util.Decimal(this.dgvDatos[oCol.Index, iFilaMargen].Value) - Util.Decimal(this.dgvDatos[oCol.Index, iFilaGastos].Value) ); // Sucursales for (int i = 1; i <= oSucursales.Count; i++) { this.dgvDatos[oCol.Index, iFilaUtilidad + i].Value = ( Util.Decimal(this.dgvDatos[oCol.Index, iFilaIngresos + i].Value) - Util.Decimal(this.dgvDatos[oCol.Index, iFilaCostos + i].Value) - Util.Decimal(this.dgvDatos[oCol.Index, iFilaGastos + i].Value) ); } } // Se obtienen los datos de gastos especiales var oGastosEsp = Datos.GetListOf <ContaEgresosDevengadoEspecialCuentasView>(c => c.Fecha >= dDesde && c.Fecha < dHastaMas1); oConsulta = null; switch (this.cmbTipo.Text) { case "Mensual": oConsulta = oGastosEsp.GroupBy(c => new { Mes = c.Fecha.Month, c.Duenio }) .Select(c => new ConsultaEdr() { Mes = c.Key.Mes, Sucursal = c.Key.Duenio, Importe = c.Sum(s => s.ImporteDev) }) .OrderBy(c => c.Sucursal).ThenBy(c => c.Mes).ToList(); break; case "Trimestral": oConsulta = oGastosEsp.GroupBy(c => new { Mes = UtilTheos.ObtenerTrimestre(c.Fecha), c.Duenio }) .Select(c => new ConsultaEdr() { Mes = c.Key.Mes, Sucursal = c.Key.Duenio, Importe = c.Sum(s => s.ImporteDev) }) .OrderBy(c => c.Sucursal).ThenBy(c => c.Mes).ToList(); break; case "Semestral": oConsulta = oGastosEsp.GroupBy(c => new { Mes = UtilTheos.ObtenerSemestre(c.Fecha), c.Duenio }) .Select(c => new ConsultaEdr() { Mes = c.Key.Mes, Sucursal = c.Key.Duenio, Importe = c.Sum(s => s.ImporteDev) }) .OrderBy(c => c.Sucursal).ThenBy(c => c.Mes).ToList(); break; } // Se agrega la fila de Especiales bool bHay = (oConsulta.Count() > 0); int iFilaEsp = this.dgvDatos.Rows.Add("- Especiales", (bHay ? oConsulta.Sum(c => c.Importe) : 0), (bHay ? oConsulta.Average(c => c.Importe) : 0)); this.dgvDatos.Rows[iFilaEsp].DefaultCellStyle.Font = oFuenteT; // Se llenan los gastos string sDuenio = ""; foreach (var oReg in oConsulta) { if (sDuenio != oReg.Sucursal) { sDuenio = oReg.Sucursal; iFila = this.dgvDatos.Rows.Add(sDuenio, oConsulta.Where(c => c.Sucursal == sDuenio).Sum(c => c.Importe) , oConsulta.Where(c => c.Sucursal == sDuenio).Average(c => c.Importe)); } string sColumna = (sPrefijo + oReg.Mes.ToString()); this.dgvDatos[sColumna, iFila].Value = (Util.Decimal(this.dgvDatos[sColumna, iFila].Value) + oReg.Importe); this.dgvDatos[sColumna, iFilaEsp].Value = (Util.Decimal(this.dgvDatos[sColumna, iFilaEsp].Value) + oReg.Importe); } // Se agrega la fila de utilidad neta int iFilaDividendos = this.dgvDatos.Rows.Add("= Dividendos"); this.dgvDatos.Rows[iFilaDividendos].DefaultCellStyle.Font = oFuenteT; foreach (DataGridViewColumn oCol in this.dgvDatos.Columns) { if (oCol.Index == 0) { continue; } this.dgvDatos[oCol.Index, iFilaDividendos].Value = ( Util.Decimal(this.dgvDatos[oCol.Index, iFilaMargen].Value) - Util.Decimal(this.dgvDatos[oCol.Index, iFilaGastos].Value) - Util.Decimal(this.dgvDatos[oCol.Index, iFilaEsp].Value) ); } // Se obtienen los datos para lo de reinversión var oReinversiones = Datos.GetListOf <ContaPolizasDetalleAvanzadoView>(c => c.FechaPoliza >= dDesde && c.FechaPoliza < dHastaMas1 && ( c.ContaCuentaDeMayorID == Cat.ContaCuentasDeMayor.CuentasPorPagarLargoPlazo || (c.ContaCuentaDeMayorID == Cat.ContaCuentasDeMayor.CuentasPorPagarCortoPlazo && c.ContaCuentaAuxiliarID != Cat.ContaCuentasAuxiliares.TarjetaDeCredito) || c.ContaCuentaDeMayorID == Cat.ContaCuentasDeMayor.AcreedoresDiversos || (c.ContaSubcuentaID == Cat.ContaSubcuentas.ActivoFijo && c.ContaCuentaDeMayorID != Cat.ContaCuentasDeMayor.Edificios) )); var oDeudas = oReinversiones.Where(c => c.ContaCuentaDeMayorID == Cat.ContaCuentasDeMayor.CuentasPorPagarLargoPlazo || c.ContaCuentaDeMayorID == Cat.ContaCuentasDeMayor.CuentasPorPagarCortoPlazo || c.ContaCuentaDeMayorID == Cat.ContaCuentasDeMayor.AcreedoresDiversos); var oInversiones = oReinversiones.Where(c => c.ContaSubcuentaID == Cat.ContaSubcuentas.ActivoFijo); List <ConsultaEdr> oDeudasGr = null; List <ConsultaEdr> oInversionesGr = null; switch (this.cmbTipo.Text) { case "Mensual": oDeudasGr = oDeudas.GroupBy(c => c.FechaPoliza.Valor().Month).Select(c => new ConsultaEdr() { Mes = c.Key, Importe = c.Sum(s => s.Cargo) }).ToList(); oInversionesGr = oInversiones.GroupBy(c => c.FechaPoliza.Valor().Month).Select(c => new ConsultaEdr() { Mes = c.Key, Importe = c.Sum(s => s.Cargo) }).ToList(); break; case "Trimestral": oDeudasGr = oDeudas.GroupBy(c => UtilTheos.ObtenerTrimestre(c.FechaPoliza.Valor())) .Select(c => new ConsultaEdr() { Mes = c.Key, Importe = c.Sum(s => s.Cargo) }).ToList(); oInversionesGr = oInversiones.GroupBy(c => UtilTheos.ObtenerTrimestre(c.FechaPoliza.Valor())) .Select(c => new ConsultaEdr() { Mes = c.Key, Importe = c.Sum(s => s.Cargo) }).ToList(); break; case "Semestral": oDeudasGr = oDeudas.GroupBy(c => UtilTheos.ObtenerSemestre(c.FechaPoliza.Valor())) .Select(c => new ConsultaEdr() { Mes = c.Key, Importe = c.Sum(s => s.Cargo) }).ToList(); oInversionesGr = oInversiones.GroupBy(c => UtilTheos.ObtenerSemestre(c.FechaPoliza.Valor())) .Select(c => new ConsultaEdr() { Mes = c.Key, Importe = c.Sum(s => s.Cargo) }).ToList(); break; } // Se agrega la fila de Reinversión decimal mDeudas = (oDeudasGr.Count() > 0 ? oDeudasGr.Sum(c => c.Importe) : 0); decimal mDeudasProm = (oDeudasGr.Count() > 0 ? oDeudasGr.Average(c => c.Importe) : 0); decimal mInversiones = (oInversionesGr.Count() > 0 ? oInversionesGr.Sum(c => c.Importe) : 0); decimal mInversionesProm = (oInversionesGr.Count() > 0 ? oInversionesGr.Average(c => c.Importe) : 0); int iFilaReinversion = this.dgvDatos.Rows.Add("- Reinversión", (mDeudas + mInversiones), ((mDeudasProm + mInversionesProm) / 2)); this.dgvDatos.Rows[iFilaReinversion].DefaultCellStyle.Font = oFuenteT; // Se llenan los datos de reinversión // Deudas iFila = this.dgvDatos.Rows.Add("Deudas", mDeudas, mDeudasProm); foreach (var oReg in oDeudasGr) { string sColumna = (sPrefijo + oReg.Mes.ToString()); this.dgvDatos[sColumna, iFila].Value = (Util.Decimal(this.dgvDatos[sColumna, iFila].Value) + oReg.Importe); this.dgvDatos[sColumna, iFilaReinversion].Value = (Util.Decimal(this.dgvDatos[sColumna, iFilaReinversion].Value) + oReg.Importe); } // Inversión iFila = this.dgvDatos.Rows.Add("Inversiones", mInversiones, mInversionesProm); foreach (var oReg in oInversionesGr) { string sColumna = (sPrefijo + oReg.Mes.ToString()); this.dgvDatos[sColumna, iFila].Value = (Util.Decimal(this.dgvDatos[sColumna, iFila].Value) + oReg.Importe); this.dgvDatos[sColumna, iFilaReinversion].Value = (Util.Decimal(this.dgvDatos[sColumna, iFilaReinversion].Value) + oReg.Importe); } // Se agrega el saldo final int iFilaSaldo = this.dgvDatos.Rows.Add("= Saldo final"); this.dgvDatos.Rows[iFilaSaldo].DefaultCellStyle.Font = oFuenteT; foreach (DataGridViewColumn oCol in this.dgvDatos.Columns) { if (oCol.Index == 0) { continue; } this.dgvDatos[oCol.Index, iFilaSaldo].Value = ( Util.Decimal(this.dgvDatos[oCol.Index, iFilaDividendos].Value) - Util.Decimal(this.dgvDatos[oCol.Index, iFilaReinversion].Value) ); } // Se llena la gráfica, en base al grid ya cargado for (int iCol = this.iColumnasFijas; iCol < this.dgvDatos.Columns.Count; iCol++) { this.chrPorSemana.Series["Ingresos"].Points.AddY(Util.Decimal(this.dgvDatos[iCol, iFilaIngresos].Value)); this.chrPorSemana.Series["Costos"].Points.AddY(Util.Decimal(this.dgvDatos[iCol, iFilaCostos].Value)); this.chrPorSemana.Series["Margen"].Points.AddY(Util.Decimal(this.dgvDatos[iCol, iFilaMargen].Value)); this.chrPorSemana.Series["Gastos"].Points.AddY(Util.Decimal(this.dgvDatos[iCol, iFilaGastos].Value)); this.chrPorSemana.Series["Utilidad"].Points.AddY(Util.Decimal(this.dgvDatos[iCol, iFilaUtilidad].Value)); this.chrPorSemana.Series["Especiales"].Points.AddY(Util.Decimal(this.dgvDatos[iCol, iFilaEsp].Value)); this.chrPorSemana.Series["Dividendos"].Points.AddY(Util.Decimal(this.dgvDatos[iCol, iFilaDividendos].Value)); } Cargando.Cerrar(); }
private void CargarDatos() { Cargando.Mostrar(); int iSucursalID = Util.Entero(this.cmbSucursal.SelectedValue); DateTime dDia = this.dtpDia.Value.Date; var oCierre = Datos.GetEntity <CajaEfectivoPorDia>(c => c.Dia == dDia && c.SucursalID == iSucursalID && c.Estatus); var oDatos = Datos.GetListOf <CorteValidacionView>(c => c.Dia == dDia && c.SucursalID == iSucursalID).OrderBy(c => c.Concepto); var oFacturaGlobal = Datos.GetEntity <CajaFacturaGlobal>(c => c.Dia == dDia && c.SucursalID == iSucursalID); if (oCierre == null || oFacturaGlobal == null) { Cargando.Cerrar(); UtilLocal.MensajeAdvertencia("No hay datos del cierre o factura global del día especificado."); return; } // Se llenan los datos del cierre this.lblCorteDeCaja.Text = oCierre.CierreDebeHaber.Valor().ToString(GlobalClass.FormatoMoneda); this.lblHuboEnCaja.Text = oCierre.Cierre.Valor().ToString(GlobalClass.FormatoMoneda); this.lblDiferencia.Text = (oCierre.Cierre - oCierre.CierreDebeHaber).Valor().ToString(GlobalClass.FormatoMoneda); this.lblDiferencia.ForeColor = ((oCierre.Cierre - oCierre.CierreDebeHaber) < 0 ? Color.Red : Color.White); // Se llenan las ventas this.dgvVentas.Rows.Clear(); var oVentas = oDatos.Where(c => c.CorteCategoriaID == Cat.CategoriasCorte.Ventas); var oFuenteT = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Bold); this.dgvVentas.Rows.Add("Ventas"); this.dgvVentas.Rows[this.dgvVentas.Rows.Count - 1].DefaultCellStyle.Font = oFuenteT; var oTickets = new CorteValidacionView() { Efectivo = 0, Cheque = 0, Tarjeta = 0, Transferencia = 0, Vale = 0, KardexImporte = 0, KardexCantidad = 0, ExistenciaCantidad = 0 }; foreach (var oReg in oVentas) { if (oReg.Factura.Valor()) { this.dgvVentas.Rows.Add(oReg.Concepto, oReg.Efectivo, oReg.Cheque, oReg.Tarjeta, oReg.Transferencia, oReg.Vale, oReg.Importe , oReg.ContaPolizaID, oReg.CuentaCaja, oReg.CuentaAnticipoClientes, (oReg.CuentaCaja + oReg.CuentaAnticipoClientes), oReg.CuentaInventario , oReg.KardexImporte, oReg.KardexCantidad, Math.Abs(oReg.ExistenciaCantidad.Valor()), null); } else { oTickets.Efectivo += oReg.Efectivo; oTickets.Cheque += oReg.Cheque; oTickets.Tarjeta += oReg.Tarjeta; oTickets.Transferencia += oReg.Transferencia; oTickets.Vale += oReg.Vale; oTickets.Importe += oReg.Importe; oTickets.KardexImporte += oReg.KardexImporte; oTickets.KardexCantidad += oReg.KardexCantidad; oTickets.ExistenciaCantidad += Math.Abs(oReg.ExistenciaCantidad.Valor()); } } this.dgvVentas.Rows.Add("Tickets", oTickets.Efectivo, oTickets.Cheque, oTickets.Tarjeta, oTickets.Transferencia, oTickets.Vale, oTickets.Importe , null, null, null, null, null, oTickets.KardexImporte, oTickets.KardexCantidad, oTickets.ExistenciaCantidad, oFacturaGlobal.Tickets); // Se llenan las devoluciones del día var oDevolucionesDia = oDatos.Where(c => c.CorteCategoriaID == Cat.CategoriasCorte.CancelacionesDia); this.dgvVentas.Rows.Add("Canc. día"); this.dgvVentas.Rows[this.dgvVentas.Rows.Count - 1].DefaultCellStyle.Font = oFuenteT; oTickets = new CorteValidacionView() { Efectivo = 0, Cheque = 0, Tarjeta = 0, Transferencia = 0, Vale = 0, KardexImporte = 0, KardexCantidad = 0, ExistenciaCantidad = 0 }; foreach (var oReg in oDevolucionesDia) { if (oReg.Factura.Valor()) { this.dgvVentas.Rows.Add(oReg.Concepto, oReg.Efectivo, oReg.Cheque, oReg.Tarjeta, oReg.Transferencia, oReg.Vale, oReg.Importe , oReg.ContaPolizaID, oReg.CuentaCaja, oReg.CuentaAnticipoClientes, (oReg.CuentaCaja + oReg.CuentaAnticipoClientes), oReg.CuentaInventario , oReg.KardexImporte, oReg.KardexCantidad, oReg.ExistenciaCantidad, null); } else { oTickets.Efectivo += oReg.Efectivo; oTickets.Cheque += oReg.Cheque; oTickets.Tarjeta += oReg.Tarjeta; oTickets.Transferencia += oReg.Transferencia; oTickets.Vale += oReg.Vale; oTickets.Importe += oReg.Importe; oTickets.KardexImporte += oReg.KardexImporte; oTickets.KardexCantidad += oReg.KardexCantidad; oTickets.ExistenciaCantidad += Math.Abs(oReg.ExistenciaCantidad.Valor()); } } this.dgvVentas.Rows.Add("Tickets", oTickets.Efectivo, oTickets.Cheque, oTickets.Tarjeta, oTickets.Transferencia, oTickets.Vale, oTickets.Importe , null, null, null, null, null, oTickets.KardexImporte, oTickets.KardexCantidad, oTickets.ExistenciaCantidad, oFacturaGlobal.DevolucionesDia); // Se llenan las devoluciones de días anteriores var oDevolucionesDiasAnt = oDatos.Where(c => c.CorteCategoriaID == Cat.CategoriasCorte.CancelacionesDiasAnteriores); this.dgvVentas.Rows.Add("Canc. ant."); this.dgvVentas.Rows[this.dgvVentas.Rows.Count - 1].DefaultCellStyle.Font = oFuenteT; oTickets = new CorteValidacionView() { Efectivo = 0, Cheque = 0, Tarjeta = 0, Transferencia = 0, Vale = 0, KardexImporte = 0, KardexCantidad = 0, ExistenciaCantidad = 0 }; foreach (var oReg in oDevolucionesDiasAnt) { if (oReg.Factura.Valor()) { this.dgvVentas.Rows.Add(oReg.Concepto, oReg.Efectivo, oReg.Cheque, oReg.Tarjeta, oReg.Transferencia, oReg.Vale, oReg.Importe , oReg.ContaPolizaID, oReg.CuentaCaja, oReg.CuentaAnticipoClientes, (oReg.CuentaCaja + oReg.CuentaAnticipoClientes), oReg.CuentaInventario , oReg.KardexImporte, oReg.KardexCantidad, oReg.ExistenciaCantidad, null); } else { oTickets.Efectivo += oReg.Efectivo; oTickets.Cheque += oReg.Cheque; oTickets.Tarjeta += oReg.Tarjeta; oTickets.Transferencia += oReg.Transferencia; oTickets.Vale += oReg.Vale; oTickets.Importe += oReg.Importe; oTickets.KardexImporte += oReg.KardexImporte; oTickets.KardexCantidad += oReg.KardexCantidad; oTickets.ExistenciaCantidad += Math.Abs(oReg.ExistenciaCantidad.Valor()); } } this.dgvVentas.Rows.Add("Tickets", oTickets.Efectivo, oTickets.Cheque, oTickets.Tarjeta, oTickets.Transferencia, oTickets.Vale, oTickets.Importe , null, null, null, null, null, oTickets.KardexImporte, oTickets.KardexCantidad, oTickets.ExistenciaCantidad, oFacturaGlobal.DevolucionesDiasAnt); // Se llenan las garantías del día var oGarantiasDia = oDatos.Where(c => c.CorteCategoriaID == Cat.CategoriasCorte.GarantiasDia); this.dgvVentas.Rows.Add("Gar. día"); this.dgvVentas.Rows[this.dgvVentas.Rows.Count - 1].DefaultCellStyle.Font = oFuenteT; oTickets = new CorteValidacionView() { Efectivo = 0, Cheque = 0, Tarjeta = 0, Transferencia = 0, Vale = 0, KardexImporte = 0, KardexCantidad = 0, ExistenciaCantidad = 0 }; foreach (var oReg in oGarantiasDia) { if (oReg.Factura.Valor()) { this.dgvVentas.Rows.Add(oReg.Concepto, oReg.Efectivo, oReg.Cheque, oReg.Tarjeta, oReg.Transferencia, oReg.Vale, oReg.Importe , oReg.ContaPolizaID, oReg.CuentaCaja, oReg.CuentaAnticipoClientes, (oReg.CuentaCaja + oReg.CuentaAnticipoClientes), oReg.CuentaInventario , oReg.KardexImporte, oReg.KardexCantidad, oReg.ExistenciaCantidad, null); } else { oTickets.Efectivo += oReg.Efectivo; oTickets.Cheque += oReg.Cheque; oTickets.Tarjeta += oReg.Tarjeta; oTickets.Transferencia += oReg.Transferencia; oTickets.Vale += oReg.Vale; oTickets.Importe += oReg.Importe; oTickets.KardexImporte += oReg.KardexImporte; oTickets.KardexCantidad += oReg.KardexCantidad; oTickets.ExistenciaCantidad += Math.Abs(oReg.ExistenciaCantidad.Valor()); } } this.dgvVentas.Rows.Add("Tickets", oTickets.Efectivo, oTickets.Cheque, oTickets.Tarjeta, oTickets.Transferencia, oTickets.Vale, oTickets.Importe , null, null, null, null, null, oTickets.KardexImporte, oTickets.KardexCantidad, oTickets.ExistenciaCantidad, oFacturaGlobal.GarantiasDia); // Se llenan las garantías de días anteriores var oGarantiasDiasAnt = oDatos.Where(c => c.CorteCategoriaID == Cat.CategoriasCorte.GarantiasDiasAnteriores); this.dgvVentas.Rows.Add("Gar. ant."); this.dgvVentas.Rows[this.dgvVentas.Rows.Count - 1].DefaultCellStyle.Font = oFuenteT; oTickets = new CorteValidacionView() { Efectivo = 0, Cheque = 0, Tarjeta = 0, Transferencia = 0, Vale = 0, KardexImporte = 0, KardexCantidad = 0, ExistenciaCantidad = 0 }; foreach (var oReg in oGarantiasDiasAnt) { if (oReg.Factura.Valor()) { this.dgvVentas.Rows.Add(oReg.Concepto, oReg.Efectivo, oReg.Cheque, oReg.Tarjeta, oReg.Transferencia, oReg.Vale, oReg.Importe , oReg.ContaPolizaID, oReg.CuentaCaja, oReg.CuentaAnticipoClientes, (oReg.CuentaCaja + oReg.CuentaAnticipoClientes), oReg.CuentaInventario , oReg.KardexImporte, oReg.KardexCantidad, oReg.ExistenciaCantidad, null); } else { oTickets.Efectivo += oReg.Efectivo; oTickets.Cheque += oReg.Cheque; oTickets.Tarjeta += oReg.Tarjeta; oTickets.Transferencia += oReg.Transferencia; oTickets.Vale += oReg.Vale; oTickets.Importe += oReg.Importe; oTickets.KardexImporte += oReg.KardexImporte; oTickets.KardexCantidad += oReg.KardexCantidad; oTickets.ExistenciaCantidad += Math.Abs(oReg.ExistenciaCantidad.Valor()); } } this.dgvVentas.Rows.Add("Tickets", oTickets.Efectivo, oTickets.Cheque, oTickets.Tarjeta, oTickets.Transferencia, oTickets.Vale, oTickets.Importe , null, null, null, null, null, oTickets.KardexImporte, oTickets.KardexCantidad, oTickets.ExistenciaCantidad, oFacturaGlobal.GarantiasDiasAnt); // Se llena la cobranza this.dgvCobranza.Rows.Clear(); var oCobranza = oDatos.Where(c => c.CorteCategoriaID == Cat.CategoriasCorte.Cobranza); oTickets = new CorteValidacionView() { Efectivo = 0, Cheque = 0, Tarjeta = 0, Transferencia = 0, Vale = 0, KardexImporte = 0, KardexCantidad = 0, ExistenciaCantidad = 0 }; foreach (var oReg in oCobranza) { if (oReg.Factura.Valor()) { this.dgvCobranza.Rows.Add(oReg.Concepto, oReg.Efectivo, oReg.Cheque, oReg.Tarjeta, oReg.Transferencia, oReg.Vale, oReg.Importe , oReg.ContaPolizaID, oReg.CuentaCaja, oReg.CuentaAnticipoClientes, (oReg.CuentaCaja + oReg.CuentaAnticipoClientes), oReg.CuentaInventario , null); } else { oTickets.Efectivo += oReg.Efectivo; oTickets.Cheque += oReg.Cheque; oTickets.Tarjeta += oReg.Tarjeta; oTickets.Transferencia += oReg.Transferencia; oTickets.Vale += oReg.Vale; oTickets.Importe += oReg.Importe; } } this.dgvCobranza.Rows.Add("Tickets", oTickets.Efectivo, oTickets.Cheque, oTickets.Tarjeta, oTickets.Transferencia, oTickets.Vale, oTickets.Importe , null, null, null, null, null, oFacturaGlobal.Cobranza); // Se llenan los gastos this.dgvGastos.Rows.Clear(); var oGastos = oDatos.Where(c => c.CorteCategoriaID == Cat.CategoriasCorte.Gastos); foreach (var oReg in oGastos) { // Se obtiene la cuenta auxiliar correspondiente, var oEgresoV = Datos.GetEntity <CajaEgresosView>(c => c.CajaEgresoID == oReg.RelacionID); this.dgvGastos.Rows.Add(oReg.RelacionID, oReg.Importe, oEgresoV.CuentaAuxiliar, (oEgresoV.AfectadoEnPolizas == true ? null : (decimal?)oReg.Importe) , oReg.ContaPolizaID, oReg.CuentaCaja); } // Se llenan los vales creados this.dgvVales.Rows.Clear(); var oVales = oDatos.Where(c => c.CorteCategoriaID == Cat.CategoriasCorte.ValesCreados); foreach (var oReg in oVales) { int iFila = this.dgvVales.Rows.Add(oReg.RelacionID, oReg.Importe, oReg.ContaPolizaID, oReg.CuentaAnticipoClientes); // Si no hay póliza, se revisa si fue por devolución o garantía if (!oReg.ContaPolizaID.HasValue) { var oVale = Datos.GetEntity <NotaDeCredito>(c => c.NotaDeCreditoID == oReg.RelacionID && c.Estatus); ContaPolizasDetalleAvanzadoView oPolizaCuenta = null; switch (oVale.OrigenID) { case Cat.OrigenesNotaDeCredito.Devolucion: var oDevV = Datos.GetEntity <VentasDevolucionesView>(c => c.NotaDeCreditoID == oVale.NotaDeCreditoID); oPolizaCuenta = Datos.GetEntity <ContaPolizasDetalleAvanzadoView>(c => c.RelacionTabla == Cat.Tablas.VentaDevolucion && c.RelacionID == oDevV.VentaDevolucionID && c.ContaCuentaAuxiliarID == Cat.ContaCuentasAuxiliares.AnticipoClientes); break; case Cat.OrigenesNotaDeCredito.Garantia: var oGarV = Datos.GetEntity <VentasGarantiasView>(c => c.NotaDeCreditoID == oVale.NotaDeCreditoID); oPolizaCuenta = Datos.GetEntity <ContaPolizasDetalleAvanzadoView>(c => c.RelacionTabla == Cat.Tablas.VentaGarantia && c.RelacionID == oGarV.VentaGarantiaID && c.ContaCuentaAuxiliarID == Cat.ContaCuentasAuxiliares.AnticipoClientes); break; } if (oPolizaCuenta != null) { this.dgvVales["val_Poliza", iFila].Value = oPolizaCuenta.ContaPolizaID; this.dgvVales["val_CuentaAnticipoClientes", iFila].Value = oPolizaCuenta.Abono; } } } // Se llenan los refuerzos this.dgvRefuerzos.Rows.Clear(); var oRefuerzos = oDatos.Where(c => c.CorteCategoriaID == Cat.CategoriasCorte.Refuerzos); foreach (var oReg in oRefuerzos) { this.dgvRefuerzos.Rows.Add(oReg.RelacionID, oReg.Importe, oReg.ContaPolizaID, oReg.CuentaCaja); } // Se llenan los resguardos this.dgvResguardos.Rows.Clear(); var oResguardos = oDatos.Where(c => c.CorteCategoriaID == Cat.CategoriasCorte.Resguardos); foreach (var oReg in oResguardos) { this.dgvResguardos.Rows.Add(oReg.RelacionID, oReg.Importe, oReg.ContaPolizaID, oReg.CuentaCaja); } Cargando.Cerrar(); }
public void ActualizarDatos() { // Se muestra la ventana de "Cargando.." Cargando.Mostrar(); this.Actualizando = true; this.dgvDetalle.Rows.Clear(); decimal mTotal = 0; int iFila; var oParams = new Dictionary <string, object>(); oParams.Add("OpcionID", CajaDetalleCorte.Opciones.Ventas); oParams.Add("SucursalID", GlobalClass.SucursalID); //oParams.Add("Dia", DateTime.Now.Date.AddDays(-38)); oParams.Add("Dia", DateTime.Now.Date); oParams.Add("DevDiasAnt", false); #region [ Ventas ] // Se llenan las ventas var Pagos = Datos.ExecuteProcedure <cdcVentas>("pauCajaDetalleCorte", oParams); this.AgregarLineaTitulo("Relación de Ventas"); this.AgregarLineaEncabezado( "Folio".PadRight(8 + 1) + "Nombre del Cliente".PadRight(22 + 1) + "Forma Pago".PadRight(19 + 1) + "Usuario".PadRight(10 + 1) + "Caract.".PadRight(10 + 1) + "Importe".PadRight(10) ); int iUltOrden = 0; foreach (var oPago in Pagos) { // Se establecen un título para cada grupo de ventas if (oPago.Orden != iUltOrden) { iUltOrden = oPago.Orden; switch (iUltOrden) { case 1: this.AgregarLineaEncabezado("**** FACTURAS DE VENTAS ANTERIORES ****"); break; case 2: this.AgregarLineaEncabezado("**** VENTAS PAGADAS DE CONTADO ****"); break; case 3: this.AgregarLineaEncabezado("**** VENTAS A CRÉDITO ****"); break; } } iFila = this.AgregarLineaDetalle( Util.Cadena(oPago.Folio).RellenarCortarDerecha(8) + " " + oPago.Cliente.RellenarCortarDerecha(22) + " " + oPago.FormaDePago.RellenarCortarDerecha(19) + " " + oPago.Usuario.RellenarCortarDerecha(10) + " " + oPago.Caracteristica.RellenarCortarDerecha(10) + " $" + oPago.Importe.ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(9) , true , (oPago.FechaVistoBueno == null ? "" : oPago.FechaVistoBueno.Valor().ToString(CajaDetalleCorte.FormatoHora)) , (oPago.CatTabla) , oPago.RegistroID ); if (oPago.FormaDePago != "") { mTotal += oPago.Importe; } if (oPago.Devolucion == 1) { this.dgvDetalle.Rows[iFila].DefaultCellStyle.ForeColor = Color.Red; this.dgvDetalle["Caracteristica", iFila].Value = "D"; } } this.AgregarLineaEncabezado("Total".PadLeft(73) + " $" + mTotal.ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(9)); #endregion #region [ Devoluciones ] // Se llenan las devoluciones - del día mTotal = 0; this.AgregarLineaEspacio(); oParams["OpcionID"] = CajaDetalleCorte.Opciones.Devoluciones; var DevDia = Datos.ExecuteProcedure <cdcDevoluciones>("pauCajaDetalleCorte", oParams); this.AgregarLineaTitulo("Devoluciones y Cancelaciones del día"); this.AgregarLineaEncabezado( "Folio".PadRight(8 + 1) + "Tipo".PadRight(8 + 1) + "Cliente".PadRight(23 + 1) + "Salida".PadRight(15 + 1) + "Autorización".PadRight(15 + 1) + "Importe".PadRight(10) ); foreach (var oMov in DevDia) { iFila = this.AgregarLineaDetalle( Util.Cadena(oMov.Folio).RellenarCortarDerecha(8) + " " + oMov.Tipo.RellenarCortarDerecha(8) + " " + oMov.Cliente.RellenarCortarDerecha(23) + " " + oMov.Salida.RellenarCortarDerecha(15) + " " + oMov.Autorizacion.RellenarCortarDerecha(15) + " $" + oMov.Importe.ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(9) , true , (oMov.FechaVistoBueno == null ? "" : oMov.FechaVistoBueno.Valor().ToString(CajaDetalleCorte.FormatoHora)) , ("Devoluciones." + Cat.Tablas.VentaDevolucion) , oMov.VentaDevolucionID ); mTotal += oMov.Importe; if (oMov.Autorizacion.EndsWith("> ")) { this.dgvDetalle.Rows[iFila].DefaultCellStyle.ForeColor = Color.Red; } } this.AgregarLineaEncabezado("Total".PadLeft(73) + " $" + mTotal.ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(9)); // Se llenan las devoluciones - días anteriores mTotal = 0; this.AgregarLineaEspacio(); // oParams["OpcionID"] = 2; oParams["DevDiasAnt"] = true; var DevAnt = Datos.ExecuteProcedure <cdcDevoluciones>("pauCajaDetalleCorte", oParams); this.AgregarLineaTitulo("Devoluciones y Cancelaciones de días anteriores"); this.AgregarLineaEncabezado( "Folio".PadRight(8 + 1) + "Tipo".PadRight(8 + 1) + "Cliente".PadRight(23 + 1) + "Salida".PadRight(15 + 1) + "Autorización".PadRight(15 + 1) + "Importe".PadRight(10) ); foreach (var oMov in DevAnt) { iFila = this.AgregarLineaDetalle( Util.Cadena(oMov.Folio).RellenarCortarDerecha(8) + " " + oMov.Tipo.RellenarCortarDerecha(8) + " " + oMov.Cliente.RellenarCortarDerecha(23) + " " + oMov.Salida.RellenarCortarDerecha(15) + " " + oMov.Autorizacion.RellenarCortarDerecha(15) + " $" + oMov.Importe.ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(9) , true , (oMov.FechaVistoBueno == null ? "" : oMov.FechaVistoBueno.Valor().ToString(CajaDetalleCorte.FormatoHora)) , ("Devoluciones." + Cat.Tablas.VentaDevolucion) , oMov.VentaDevolucionID ); mTotal += oMov.Importe; if (oMov.Autorizacion.EndsWith("> ")) { this.dgvDetalle.Rows[iFila].DefaultCellStyle.ForeColor = Color.Red; } } this.AgregarLineaEncabezado("Total".PadLeft(73) + " $" + mTotal.ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(9)); #endregion #region [ Garantías ] // Se llenan las Garantías - del día mTotal = 0; this.AgregarLineaEspacio(); oParams["OpcionID"] = CajaDetalleCorte.Opciones.Garantias; oParams["DevDiasAnt"] = false; var oGarantiasDia = Datos.ExecuteProcedure <cdcGarantias>("pauCajaDetalleCorte", oParams); this.AgregarLineaTitulo("Garantías del día"); this.AgregarLineaEncabezado( "Folio".PadRight(8 + 1) + "Cliente".PadRight(23 + 1) + "Salida".PadRight(15 + 1) + "Autorización".PadRight(15 + 9 + 1) + "Importe".PadRight(10) ); foreach (var oMov in oGarantiasDia) { iFila = this.AgregarLineaDetalle( Util.Cadena(oMov.Folio).RellenarCortarDerecha(8) + " " + oMov.Cliente.RellenarCortarDerecha(23) + " " + oMov.Salida.RellenarCortarDerecha(15) + " " + oMov.Autorizacion.RellenarCortarDerecha(15 + 9) + " $" + oMov.Importe.ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(9) , true , (oMov.FechaVistoBueno == null ? "" : oMov.FechaVistoBueno.Valor().ToString(CajaDetalleCorte.FormatoHora)) , ("Garantias." + Cat.Tablas.VentaGarantia) , oMov.VentaGarantiaID ); mTotal += oMov.Importe; if (oMov.Autorizacion.EndsWith("> ")) { this.dgvDetalle.Rows[iFila].DefaultCellStyle.ForeColor = Color.Red; } } this.AgregarLineaEncabezado("Total".PadLeft(73) + " $" + mTotal.ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(9)); // Se llenan las Garantías - días anteriores mTotal = 0; this.AgregarLineaEspacio(); // oParams["OpcionID"] = 2; oParams["DevDiasAnt"] = true; var oGarantiasAnt = Datos.ExecuteProcedure <cdcGarantias>("pauCajaDetalleCorte", oParams); this.AgregarLineaTitulo("Garantías de días anteriores"); this.AgregarLineaEncabezado( "Folio".PadRight(8 + 1) + "Cliente".PadRight(23 + 1) + "Salida".PadRight(15 + 1) + "Autorización".PadRight(15 + 9 + 1) + "Importe".PadRight(10) ); foreach (var oMov in oGarantiasAnt) { iFila = this.AgregarLineaDetalle( Util.Cadena(oMov.Folio).RellenarCortarDerecha(8) + " " + oMov.Cliente.RellenarCortarDerecha(23) + " " + oMov.Salida.RellenarCortarDerecha(15) + " " + oMov.Autorizacion.RellenarCortarDerecha(15 + 9) + " $" + oMov.Importe.ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(9) , true , (oMov.FechaVistoBueno == null ? "" : oMov.FechaVistoBueno.Valor().ToString(CajaDetalleCorte.FormatoHora)) , ("Garantias." + Cat.Tablas.VentaGarantia) , oMov.VentaGarantiaID ); mTotal += oMov.Importe; if (oMov.Autorizacion.EndsWith("> ")) { this.dgvDetalle.Rows[iFila].DefaultCellStyle.ForeColor = Color.Red; } } this.AgregarLineaEncabezado("Total".PadLeft(73) + " $" + mTotal.ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(9)); #endregion #region [ 9500 ] // Se llenan los 9500 mTotal = 0; this.AgregarLineaEspacio(); oParams["OpcionID"] = CajaDetalleCorte.Opciones._9500; var Ventas9500 = Datos.ExecuteProcedure <cdc9500>("pauCajaDetalleCorte", oParams); this.AgregarLineaTitulo("9500"); this.AgregarLineaEncabezado( "Folio".PadRight(8 + 1) + "Cliente".PadRight(64 + 1) + "Importe".PadRight(10) ); foreach (var oMov in Ventas9500) { this.AgregarLineaDetalle( Util.Cadena(oMov.Folio).RellenarCortarDerecha(8) + " " + oMov.Cliente.RellenarCortarDerecha(64) + " $" + oMov.Anticipo.ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(9) , true , (oMov.FechaVistoBueno == null ? "" : oMov.FechaVistoBueno.Valor().ToString(CajaDetalleCorte.FormatoHora)) , ("9500." + Cat.Tablas.Tabla9500) , oMov.Cotizacion9500ID ); mTotal += oMov.Anticipo; } this.AgregarLineaEncabezado("Total".PadLeft(73) + " $" + mTotal.ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(9)); #endregion #region [ Cobranza ] // Se llenan los pagos de ventas a crédito (Cobranza) mTotal = 0; this.AgregarLineaEspacio(); oParams["OpcionID"] = CajaDetalleCorte.Opciones.Cobranza; var Cobranza = Datos.ExecuteProcedure <cdcCobranza>("pauCajaDetalleCorte", oParams); this.AgregarLineaTitulo("Cobranza"); this.AgregarLineaEncabezado( "Folio".PadRight(8 + 1) + "Nombre del Cliente".PadRight(44 + 1) + "Forma Pago".PadRight(19 + 1) + "Importe".PadRight(10) ); foreach (var oMov in Cobranza) { this.AgregarLineaDetalle( Util.Cadena(oMov.Folio).RellenarCortarDerecha(8) + " " + oMov.Cliente.RellenarCortarDerecha(44) + " " + oMov.FormaDePago.RellenarCortarDerecha(19) + " $" + oMov.Importe.ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(9) , true , (oMov.FechaVistoBueno == null ? "" : oMov.FechaVistoBueno.Valor().ToString(CajaDetalleCorte.FormatoHora)) , ("Cobranza." + Cat.Tablas.VentaPago) , oMov.VentaPagoID ); mTotal += oMov.Importe; } this.AgregarLineaEncabezado("Total".PadLeft(73) + " $" + mTotal.ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(9)); #endregion #region [ Gastos ] // Se llenan los gastos mTotal = 0; this.AgregarLineaEspacio(); oParams["OpcionID"] = CajaDetalleCorte.Opciones.Egresos; var Egresos = Datos.ExecuteProcedure <cdcIngresosEgresos>("pauCajaDetalleCorte", oParams); this.AgregarLineaTitulo("Gastos"); this.AgregarLineaEncabezado( "Concepto".PadRight(48 + 1) + "Autorización".PadRight(24 + 1) + "Importe".PadRight(10) ); foreach (var oMov in Egresos) { iFila = this.AgregarLineaDetalle( oMov.Concepto.RellenarCortarDerecha(48) + " " + oMov.Autorizacion.RellenarCortarDerecha(23) + " $" + oMov.Importe.ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(9) , true , (oMov.FechaVistoBueno == null ? "" : oMov.FechaVistoBueno.Valor().ToString(CajaDetalleCorte.FormatoHora)) , ("Egresos." + Cat.Tablas.CajaEgreso) , oMov.RegistroID ); mTotal += oMov.Importe; if (oMov.Autorizacion.EndsWith("> ")) { this.dgvDetalle.Rows[iFila].DefaultCellStyle.ForeColor = Color.Red; } } this.AgregarLineaEncabezado("Total".PadLeft(73) + " $" + mTotal.ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(9)); #endregion #region [ Ingresos ] // Se llenan los otros ingresos mTotal = 0; this.AgregarLineaEspacio(); oParams["OpcionID"] = CajaDetalleCorte.Opciones.Ingresos; var Ingresos = Datos.ExecuteProcedure <cdcIngresosEgresos>("pauCajaDetalleCorte", oParams); this.AgregarLineaTitulo("Otros Ingresos"); this.AgregarLineaEncabezado( "Concepto".PadRight(48 + 1) + "Autorización".PadRight(24 + 1) + "Importe".PadRight(10) ); foreach (var oMov in Ingresos) { iFila = this.AgregarLineaDetalle( oMov.Concepto.RellenarCortarDerecha(48) + " " + oMov.Autorizacion.RellenarCortarDerecha(23) + " $" + oMov.Importe.ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(9) , true , (oMov.FechaVistoBueno == null ? "" : oMov.FechaVistoBueno.Valor().ToString(CajaDetalleCorte.FormatoHora)) , ("Ingresos." + Cat.Tablas.CajaIngreso) , oMov.RegistroID ); mTotal += oMov.Importe; if (oMov.Autorizacion.EndsWith("> ")) { this.dgvDetalle.Rows[iFila].DefaultCellStyle.ForeColor = Color.Red; } } this.AgregarLineaEncabezado("Total".PadLeft(73) + " $" + mTotal.ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(9)); #endregion this.Actualizando = false; // Se cierra la ventana de "Cargando.." Cargando.Cerrar(); }
public void IniciarVerificacion() { preloader = new Cargando(); AbrirModulo(preloader); preloader.IniciarVerificacion(); }
public bool Ejecutar() { // Se verifica si ya se hizo el cierre de caja if (UtilDatos.VerCierreDeDaja()) { UtilLocal.MensajeAdvertencia("Ya se hizo el Corte de Caja. No se puede continuar."); return(false); } // Se valida el cliente if (this.oControlVentas.Cliente == null) { UtilLocal.MensajeAdvertencia("No hay ningún cliente seleccionado o cliente inválido."); return(false); } // Se validan los productos if (!this.oControlVentas.Validar()) { return(false); } // Se validan si hay una parte de cobro de diferencia de casco, sea la única en la venta var oVentaDet = this.oControlVentas.GenerarVentaDetalle(); foreach (var oReg in oVentaDet) { if (Datos.Exists <Parte>(c => c.ParteID == oReg.ParteID && c.EsCascoPara > 0) || oReg.ParteID == Cat.Partes.DiferenciaDeCascos) { if (oVentaDet.Count > 1) { UtilLocal.MensajeAdvertencia("La venta contiene un artículo Casco, por lo cual no puede contener otros artículos."); return(false); } } } // Se verifica si se debe mostrar la opción de cobro if (!this.oControlVentas.CobroAlFrente) { if (this.oControlVentas.ctlCobro == null) { this.oControlVentas.ctlCobro = new Cobro() { Dock = DockStyle.Fill }; this.oControlVentas.pnlContenidoDetalle.Controls.Add(this.oControlVentas.ctlCobro); // Se configura el evento Click para el botón de cotización this.oControlVentas.ctlCobro.Cotizacion_Click += new EventHandler((s, e) => { this.GenerarCotizacion(); }); } this.oControlVentas.ctlCobro.CambiarCliente(this.oControlVentas.Cliente.ClienteID); this.oControlVentas.ctlCobro.Total = this.oControlVentas.Total; // Sólo se permite cambiar el vendedor, no cobrar this.oControlVentas.ctlCobro.HabilitarTipoDePago = false; this.oControlVentas.ctlCobro.MostrarFacturar = false; this.oControlVentas.ctlCobro.MostrarFacturarDividir = false; this.oControlVentas.ctlCobro.HabilitarCotizacion = true; this.oControlVentas.ctlCobro.HabilitarFormasDePago = false; this.oControlVentas.ctlCobro.Total = 0; this.oControlVentas.ctlCobro.BringToFront(); return(false); } // Se verifica si es cotización if (this.oControlVentas.EsCotizacion) { UtilLocal.MensajeAdvertencia("No se puede realizar la venta porque esta es sólo una cotización."); return(false); } // Se intenta completar if (!this.oControlVentas.ctlCobro.CompletarCobro()) { return(false); } //decimal mImportePato = Util.Decimal(Config.Valor("Ventas.ImportePato")); //bool esPato = false; //if (this.oControlVentas.Total >= mImportePato) //{ // var hunt = new Duck(UtilLocal.RutaRecursos() + "huntduck2.wmv"); // hunt.Show(Principal.Instance); // esPato = true; //} else // Se muestra la ventana de "Cargando.." Cargando.Mostrar(); // Se procede a guardar la venta DateTime dAhora = DateTime.Now; // Se crea el objeto de la nueva venta Venta oVenta = new Venta() { Fecha = dAhora, ClienteID = this.oControlVentas.Cliente.ClienteID, VentaEstatusID = Cat.VentasEstatus.Realizada, RealizoUsuarioID = this.oControlVentas.ctlCobro.VendodorID, RepartidorID = (this.oControlVentas.ctlCobro.RepartidorID > 0 ? (int?)this.oControlVentas.ctlCobro.RepartidorID : null), ComisionistaClienteID = this.oControlVentas.ctlCobro.ComisionistaID, ClienteVehiculoID = this.oControlVentas.ctlCobro.ClienteVehiculoID, Kilometraje = this.oControlVentas.ctlCobro.Kilometraje }; // Se manda a guardar la venta var oVentaDetalle = this.oControlVentas.GenerarVentaDetalle(); Guardar.Venta(oVenta, oVentaDetalle); // Se agrega al Kardex // ** Se hace al momento de cobrar :\ // Se generan los datos de pago (no en la primer versión) /* var oPago = this.ctlCobro.GenerarPago(); * oPago.VentaID = oVenta.VentaID; * oPago.Fecha = dAhora; * var oPagoDetalle = this.ctlCobro.GenerarPagoDetalle(); * // Se mandan guardar los datos del pago * Guardar.VentaPago(oPago, oPagoDetalle); */ // Se imprimen los tickets correspondientes // .. aquí no hay tickets, sino hasta que se paga, creo // Se guarda la leyenda, para usarla en el ticket, después de cobrar if (this.oControlVentas.ctlCobro.Leyenda != "") { VentasProc.AgregarLeyenda(oVenta.VentaID, this.oControlVentas.ctlCobro.Leyenda); } // Se hace verificación para control de cascos foreach (var oReg in oVentaDetalle) { if (Datos.Exists <Parte>(c => c.ParteID == oReg.ParteID && c.RequiereCascoDe > 0 && c.Estatus)) { // Se agrega el registro para casco, uno por cada casco según la cantidad for (int i = 0; i < oReg.Cantidad; i++) { var oCascoReg = new CascoRegistro() { Fecha = dAhora, VentaID = oVenta.VentaID, ParteID = oReg.ParteID }; Datos.Guardar <CascoRegistro>(oCascoReg); } } } // Se guardan los datos de la aplicación, si hubiera if (this.oControlVentas.oAplicaciones != null && this.oControlVentas.oAplicaciones.Count > 0) { foreach (var oReg in this.oControlVentas.oAplicaciones) { var oRegVentaD = oVentaDetalle.FirstOrDefault(c => c.ParteID == oReg.ParteID); oReg.VentaID = oVenta.VentaID; oReg.Cantidad = oRegVentaD.Cantidad; Datos.Guardar <VentaParteAplicacion>(oReg); } } // Se cierra la ventana de "Cargando.." //if(!esPato) Cargando.Cerrar(); // Se muestra notificación y se limpia el formulario UtilLocal.MostrarNotificacion("La Venta ha sido guardada correctamente."); return(true); }
public void CargarDatos() { Cargando.Mostrar(); var oParams = new Dictionary <string, object>(); int iAnio = Util.Entero(this.cmbAnio.Text); DateTime dDesde = new DateTime(iAnio, 1, 1); DateTime dHasta = new DateTime(iAnio, 12, 31); oParams.Add("Desde", dDesde); oParams.Add("Hasta", dHasta); oParams.Add("AfectaMetas", this.chkAfectaMetas.Checked); // Se llenan los datos var oDatos = Datos.ExecuteProcedure <pauContaCuentasPorSemana_Result>("pauContaCuentasPorSemana", oParams); this.tgvDatos.Nodes.Clear(); TreeGridNode oNodoSucursal = null, oNodoCuenta = null, oNodoSubcuenta = null, oNodoCuentaDeMayor = null, oNodoCuentaAuxiliar = null; string sSucursal = "", sCuenta = "", sSubcuenta = "", sCuentaDeMayor = "", sCuentaAuxiliar = ""; foreach (var oReg in oDatos) { // Nodo de Sucursal if (oReg.Sucursal != sSucursal) { sSucursal = oReg.Sucursal; oNodoSucursal = this.tgvDatos.Nodes.Add(sSucursal); oNodoSucursal.Tag = false; // Se marca como false para indicar que no es devengado especial sCuenta = ""; } // Nodo de Cuenta if (oReg.Cuenta != sCuenta) { sCuenta = oReg.Cuenta; oNodoCuenta = oNodoSucursal.Nodes.Add(sCuenta); sSubcuenta = ""; } // Nodo de Subcuenta if (oReg.Subcuenta != sSubcuenta) { sSubcuenta = oReg.Subcuenta; oNodoSubcuenta = oNodoCuenta.Nodes.Add(sSubcuenta); sCuentaDeMayor = ""; } // Nodo de Cuenta de mayor if (oReg.CuentaDeMayor != sCuentaDeMayor) { sCuentaDeMayor = oReg.CuentaDeMayor; oNodoCuentaDeMayor = oNodoSubcuenta.Nodes.Add(sCuentaDeMayor); sCuentaAuxiliar = ""; } // Se agrega la cuenta auxiliar if (oReg.CuentaAuxiliar != sCuentaAuxiliar) { sCuentaAuxiliar = oReg.CuentaAuxiliar; oNodoCuentaAuxiliar = oNodoCuentaDeMayor.Nodes.Add(oReg.CuentaAuxiliar); } // Se meten los valores de las semanas, y los totales if (oReg.PeriodicidadMes.HasValue) { DateTime dInicioPer = oReg.Fecha.DiaPrimero().Date; DateTime dFinPer = dInicioPer.AddMonths(oReg.PeriodicidadMes.Valor()).AddDays(-1); decimal mImporteDiario = (oReg.ImporteDev.Valor() / ((dFinPer - dInicioPer).Days + 1)); decimal mImporte; int iDias; DateTime dIniSem = UtilTheos.InicioSemanaSabAVie(dInicioPer).Date; for (int iCol = (this.tgvDatos.Columns["Sem" + dIniSem.ToString("d")].Index); iCol < this.tgvDatos.Columns.Count; iCol++) { // Se verifica si se debe de seguir semanalizando if (oReg.FinSemanalizar.HasValue && oReg.FinSemanalizar <= dIniSem) { break; } // Se verifica la fecha final, if (oNodoCuentaAuxiliar.Tag != null && dIniSem > dFinPer) { break; } // Se calcula el importe correspondiente DateTime dFinSem = dIniSem.AddDays(6); if (dIniSem < dInicioPer) { iDias = dFinSem.Day; } else if (dIniSem <= dFinPer && dFinSem > dFinPer) { iDias = ((dIniSem.DiaUltimo().Day - dIniSem.Day) + 1); } else if (dIniSem > dFinPer && (dIniSem - dFinPer).Days < 7) { iDias = (dIniSem.Day - 1); iCol--; } else { iDias = 7; // Se verifica si es /* if (oReg.CuentaAuxiliar == sCuentaAuxiliar) * { * oNodoCuentaAuxiliar.Cells[iCol].Value = 0; * oNodoCuentaAuxiliar.Cells[iCol].Tag = null; * } */ } // int iDias = (dIniSem < dInicioPer ? dFinSem.Day : (dFinSem > dFinPer ? ((dIniSem.DiaUltimo().Day - dIniSem.Day) + 1) : 7)); mImporte = (mImporteDiario * iDias); dIniSem = dIniSem.AddDays(7); // Para guardar los datos relacionados if (oNodoCuentaAuxiliar.Cells[iCol].Tag == null) { oNodoCuentaAuxiliar.Cells[iCol].Tag = new List <int>(); } (oNodoCuentaAuxiliar.Cells[iCol].Tag as List <int>).Add(oReg.ContaEgresoDevengadoID); // Para llenar las celdas oNodoCuentaAuxiliar.Cells[iCol].Value = (Util.Decimal(oNodoCuentaAuxiliar.Cells[iCol].Value) + mImporte); // mImporte; /* * // Para los niveles superiores * oNodoCuentaDeMayor.Cells[iCol].Value = (Util.ConvertirDecimal(oNodoCuentaDeMayor.Cells[iCol].Value) + mImporte); * oNodoSubcuenta.Cells[iCol].Value = (Util.ConvertirDecimal(oNodoSubcuenta.Cells[iCol].Value) + mImporte); * oNodoCuenta.Cells[iCol].Value = (Util.ConvertirDecimal(oNodoCuenta.Cells[iCol].Value) + mImporte); * oNodoSucursal.Cells[iCol].Value = (Util.ConvertirDecimal(oNodoSucursal.Cells[iCol].Value) + mImporte); * * // Para la columna de totales * oNodoCuentaAuxiliar.Cells[1].Value = (Util.ConvertirDecimal(oNodoCuentaAuxiliar.Cells[1].Value) + mImporte); // mImporteTotal; * oNodoCuentaDeMayor.Cells[1].Value = (Util.ConvertirDecimal(oNodoCuentaDeMayor.Cells[1].Value) + mImporte); * oNodoSubcuenta.Cells[1].Value = (Util.ConvertirDecimal(oNodoSubcuenta.Cells[1].Value) + mImporte); * oNodoCuenta.Cells[1].Value = (Util.ConvertirDecimal(oNodoCuenta.Cells[1].Value) + mImporte); * oNodoSucursal.Cells[1].Value = (Util.ConvertirDecimal(oNodoSucursal.Cells[1].Value) + mImporte); */ } // Se marca la cuenta, para que ya no se semanalice hasta el final if (oNodoCuentaAuxiliar.Tag == null) { oNodoCuentaAuxiliar.Tag = true; } } else { DateTime dIniSem = UtilTheos.InicioSemanaSabAVie(oReg.Fecha).Date; int iCol = this.tgvDatos.Columns["Sem" + dIniSem.ToString("d")].Index; // Para guardar los datos relacionados if (oNodoCuentaAuxiliar.Cells[iCol].Tag == null) { oNodoCuentaAuxiliar.Cells[iCol].Tag = new List <int>(); } (oNodoCuentaAuxiliar.Cells[iCol].Tag as List <int>).Add(oReg.ContaEgresoDevengadoID); // Para llenar el importe oNodoCuentaAuxiliar.Cells[iCol].Value = (Util.Decimal(oNodoCuentaAuxiliar.Cells[iCol].Value) + oReg.ImporteDev); } } // Se llenan los datos de devengados especiales DateTime dHastaMas1 = dHasta.AddDays(1); var oDevEsp = Datos.GetListOf <ContaEgresosDevengadoEspecialCuentasView>(c => c.Fecha >= dDesde && c.Fecha < dHastaMas1) .OrderBy(c => c.Duenio).ThenBy(c => c.Cuenta).ThenBy(c => c.Subcuenta).ThenBy(c => c.CuentaDeMayor).ThenBy(c => c.CuentaAuxiliar) .ThenByDescending(c => c.Fecha); TreeGridNode oNodoDuenio = oNodoCuenta = oNodoSubcuenta = oNodoCuentaDeMayor = oNodoCuentaAuxiliar = null; string sDuenio = sCuenta = sSubcuenta = sCuentaDeMayor = sCuentaAuxiliar = ""; foreach (var oReg in oDevEsp) { // Nodo de Sucursal if (oReg.Duenio != sDuenio) { sDuenio = oReg.Duenio; oNodoDuenio = this.tgvDatos.Nodes.Add(sDuenio); oNodoDuenio.Tag = true; // Se marca como true para indicar que es devengado especial sCuenta = ""; } // Nodo de Cuenta if (oReg.Cuenta != sCuenta) { sCuenta = oReg.Cuenta; oNodoCuenta = oNodoDuenio.Nodes.Add(sCuenta); sSubcuenta = ""; } // Nodo de Subcuenta if (oReg.Subcuenta != sSubcuenta) { sSubcuenta = oReg.Subcuenta; oNodoSubcuenta = oNodoCuenta.Nodes.Add(sSubcuenta); sCuentaDeMayor = ""; } // Nodo de Cuenta de mayor if (oReg.CuentaDeMayor != sCuentaDeMayor) { sCuentaDeMayor = oReg.CuentaDeMayor; oNodoCuentaDeMayor = oNodoSubcuenta.Nodes.Add(sCuentaDeMayor); sCuentaAuxiliar = ""; } // Se agrega la cuenta auxiliar if (oReg.CuentaAuxiliar != sCuentaAuxiliar) { sCuentaAuxiliar = oReg.CuentaAuxiliar; oNodoCuentaAuxiliar = oNodoCuentaDeMayor.Nodes.Add(oReg.CuentaAuxiliar); } // Se meten los valores de las semanas, y los totales /* DateTime dIniSem = UtilTheos.InicioSemanaSabAVie(oReg.Fecha).Date; * int iCol = this.tgvDatos.Columns["Sem" + dIniSem.ToString("d")].Index; * // Para llenar el importe * oNodoCuentaAuxiliar.Cells[iCol].Value = (Util.ConvertirDecimal(oNodoCuentaAuxiliar.Cells[iCol].Value) + oReg.ImporteDev); */ if (oReg.PeriodicidadMes.HasValue) { DateTime dInicioPer = oReg.Fecha.DiaPrimero().Date; DateTime dFinPer = dInicioPer.AddMonths(oReg.PeriodicidadMes.Valor()).AddDays(-1); decimal mImporteDiario = (oReg.ImporteDev / ((dFinPer - dInicioPer).Days + 1)); decimal mImporte; int iDias; DateTime dIniSem = UtilTheos.InicioSemanaSabAVie(dInicioPer).Date; for (int iCol = (this.tgvDatos.Columns["Sem" + dIniSem.ToString("d")].Index); iCol < this.tgvDatos.Columns.Count; iCol++) { // Se verifica si se debe de seguir semanalizando if (oReg.FinSemanalizar.HasValue && oReg.FinSemanalizar <= dIniSem) { break; } // Se verifica la fecha final, if (oNodoCuentaAuxiliar.Tag != null && dIniSem > dFinPer) { break; } // Se calcula el importe correspondiente DateTime dFinSem = dIniSem.AddDays(6); if (dIniSem < dInicioPer) { iDias = dFinSem.Day; } else if (dIniSem <= dFinPer && dFinSem > dFinPer) { iDias = ((dIniSem.DiaUltimo().Day - dIniSem.Day) + 1); } else if (dIniSem > dFinPer && (dIniSem - dFinPer).Days < 7) { iDias = (dIniSem.Day - 1); iCol--; } else { iDias = 7; } // int iDias = (dIniSem < dInicioPer ? dFinSem.Day : (dFinSem > dFinPer ? ((dIniSem.DiaUltimo().Day - dIniSem.Day) + 1) : 7)); mImporte = (mImporteDiario * iDias); dIniSem = dIniSem.AddDays(7); // Para guardar los datos relacionados, para el grid de detalle devengado if (oNodoCuentaAuxiliar.Cells[iCol].Tag == null) { oNodoCuentaAuxiliar.Cells[iCol].Tag = new List <int>(); } (oNodoCuentaAuxiliar.Cells[iCol].Tag as List <int>).Add(oReg.ContaEgresoDevengadoEspecialID); // Para llenar las celdas oNodoCuentaAuxiliar.Cells[iCol].Value = (Util.Decimal(oNodoCuentaAuxiliar.Cells[iCol].Value) + mImporte); // mImporte; } // Se marca la cuenta, para que ya no se semanalice hasta el final if (oNodoCuentaAuxiliar.Tag == null) { oNodoCuentaAuxiliar.Tag = true; } } else { DateTime dIniSem = UtilTheos.InicioSemanaSabAVie(oReg.Fecha).Date; int iCol = this.tgvDatos.Columns["Sem" + dIniSem.ToString("d")].Index; // Para guardar los datos relacionados, para el grid de detalle devengado if (oNodoCuentaAuxiliar.Cells[iCol].Tag == null) { oNodoCuentaAuxiliar.Cells[iCol].Tag = new List <int>(); } (oNodoCuentaAuxiliar.Cells[iCol].Tag as List <int>).Add(oReg.ContaEgresoDevengadoEspecialID); // Para llenar el importe oNodoCuentaAuxiliar.Cells[iCol].Value = (Util.Decimal(oNodoCuentaAuxiliar.Cells[iCol].Value) + oReg.ImporteDev); } } // Se llena el nuevo grupo de Empresa (Totales) int iColCuenta = ColsCuentas.Cuenta; this.tgvDatos.Nodes.Insert(0, new TreeGridNode()); var oNodEmpresa = this.tgvDatos.Nodes[0]; oNodEmpresa.Cells[iColCuenta].Value = "EMPRESA"; foreach (var oNodSucursal in this.tgvDatos.Nodes) { if (Util.Cadena(oNodSucursal.Cells[iColCuenta].Value) == "EMPRESA") { continue; } foreach (var oNodCuenta in oNodSucursal.Nodes) { var oNECuenta = oNodEmpresa.Nodes.FirstOrDefault(c => c.Cells[iColCuenta].Value.ToString() == oNodCuenta.Cells[iColCuenta].Value.ToString()); if (oNECuenta == null) { oNECuenta = oNodEmpresa.Nodes.Add(oNodCuenta.Cells[iColCuenta].Value); } foreach (var oNodSubcuenta in oNodCuenta.Nodes) { var oNESubcuenta = oNECuenta.Nodes.FirstOrDefault(c => c.Cells[iColCuenta].Value.ToString() == oNodSubcuenta.Cells[iColCuenta].Value.ToString()); if (oNESubcuenta == null) { oNESubcuenta = oNECuenta.Nodes.Add(oNodSubcuenta.Cells[iColCuenta].Value); } foreach (var oNodCuentaDeMayor in oNodSubcuenta.Nodes) { var oNECuentaDeMayor = oNESubcuenta.Nodes.FirstOrDefault(c => c.Cells[iColCuenta].Value.ToString() == oNodCuentaDeMayor.Cells[iColCuenta].Value.ToString()); if (oNECuentaDeMayor == null) { oNECuentaDeMayor = oNESubcuenta.Nodes.Add(oNodCuentaDeMayor.Cells[iColCuenta].Value); } foreach (var oNodCuentaAuxiliar in oNodCuentaDeMayor.Nodes) { var oNECuentaAuxiliar = oNECuentaDeMayor.Nodes.FirstOrDefault(c => c.Cells[iColCuenta].Value.ToString() == oNodCuentaAuxiliar.Cells[iColCuenta].Value.ToString()); if (oNECuentaAuxiliar == null) { oNECuentaAuxiliar = oNECuentaDeMayor.Nodes.Add(oNodCuentaAuxiliar.Cells[iColCuenta].Value); } for (int iCol = 2; iCol < this.tgvDatos.Columns.Count; iCol++) { decimal mImporte = Util.Decimal(oNodCuentaAuxiliar.Cells[iCol].Value); oNECuentaAuxiliar.Cells[iCol].Value = (Util.Decimal(oNECuentaAuxiliar.Cells[iCol].Value) + mImporte); } } } } } } // Se llenan los totales foreach (var oNodSucursal in this.tgvDatos.Nodes) { foreach (var oNodCuenta in oNodSucursal.Nodes) { foreach (var oNodSubcuenta in oNodCuenta.Nodes) { foreach (var oNodCuentaDeMayor in oNodSubcuenta.Nodes) { foreach (var oNodCuentaAuxiliar in oNodCuentaDeMayor.Nodes) { for (int iCol = 2; iCol < this.tgvDatos.Columns.Count; iCol++) { decimal mImporte = Util.Decimal(oNodCuentaAuxiliar.Cells[iCol].Value); // Para los niveles superiores oNodCuentaDeMayor.Cells[iCol].Value = (Util.Decimal(oNodCuentaDeMayor.Cells[iCol].Value) + mImporte); oNodSubcuenta.Cells[iCol].Value = (Util.Decimal(oNodSubcuenta.Cells[iCol].Value) + mImporte); oNodCuenta.Cells[iCol].Value = (Util.Decimal(oNodCuenta.Cells[iCol].Value) + mImporte); oNodSucursal.Cells[iCol].Value = (Util.Decimal(oNodSucursal.Cells[iCol].Value) + mImporte); // Para la columna de totales oNodCuentaAuxiliar.Cells[1].Value = (Util.Decimal(oNodCuentaAuxiliar.Cells[1].Value) + mImporte); // mImporteTotal; oNodCuentaDeMayor.Cells[1].Value = (Util.Decimal(oNodCuentaDeMayor.Cells[1].Value) + mImporte); oNodSubcuenta.Cells[1].Value = (Util.Decimal(oNodSubcuenta.Cells[1].Value) + mImporte); oNodCuenta.Cells[1].Value = (Util.Decimal(oNodCuenta.Cells[1].Value) + mImporte); oNodSucursal.Cells[1].Value = (Util.Decimal(oNodSucursal.Cells[1].Value) + mImporte); } } } } } } // Se aplica el formato y el color foreach (var oNodSucursal in this.tgvDatos.Nodes) { // Se aplica el formato oNodSucursal.DefaultCellStyle.BackColor = Color.FromArgb(58, 79, 109); oNodSucursal.DefaultCellStyle.ForeColor = Color.White; oNodSucursal.DefaultCellStyle.Font = new Font(this.tgvDatos.Font, FontStyle.Bold); // oNodSucursal.Expand(); // Si su valor es cero, se pone un guión this.PonerGuionCeldas(oNodSucursal); foreach (var oNodCuenta in oNodSucursal.Nodes) { // Se aplica el formato oNodCuenta.DefaultCellStyle.BackColor = Color.FromArgb(67, 87, 123); oNodCuenta.DefaultCellStyle.ForeColor = Color.White; oNodCuenta.DefaultCellStyle.Font = new Font(this.tgvDatos.Font, FontStyle.Bold); oNodCuenta.DefaultCellStyle.Font = new Font(this.tgvDatos.Font.FontFamily, (float)7.75); // oNodCuenta.Expand(); // Si su valor es cero, se pone un guión this.PonerGuionCeldas(oNodCuenta); foreach (var oNodSubcuenta in oNodCuenta.Nodes) { // Se aplica el formato oNodSubcuenta.DefaultCellStyle.BackColor = Color.FromArgb(0, 112, 192); oNodSubcuenta.DefaultCellStyle.ForeColor = Color.White; // oNodSubcuenta.Expand(); // Si su valor es cero, se pone un guión this.PonerGuionCeldas(oNodSubcuenta); foreach (var oNodCuentaDeMayor in oNodSubcuenta.Nodes) { // Se aplica el formato oNodCuentaDeMayor.DefaultCellStyle.ForeColor = Color.FromArgb(58, 79, 109); oNodCuentaDeMayor.DefaultCellStyle.Font = new Font(this.tgvDatos.Font, FontStyle.Bold); oNodCuentaDeMayor.DefaultCellStyle.Font = new Font(this.tgvDatos.Font.FontFamily, (float)7.75); // Si su valor es cero, se pone un guión this.PonerGuionCeldas(oNodCuentaDeMayor); foreach (var oNodCuentaAuxiliar in oNodCuentaDeMayor.Nodes) { oNodCuentaAuxiliar.DefaultCellStyle.ForeColor = Color.FromArgb(58, 79, 109); // Si su valor es cero, se pone un guión this.PonerGuionCeldas(oNodCuentaAuxiliar); } } } } } Cargando.Cerrar(); }
public void ActualizarDatos() { // Se muestra la ventana de "Cargando.." Cargando.Mostrar(); this.dgvDetalle.Rows.Clear(); this.Total = 0; decimal mTickets = 0, mFacturas = 0; int iFila; var oParams = new Dictionary <string, object>(); oParams.Add("SucursalID", GlobalClass.SucursalID); oParams.Add("Dia", DateTime.Now.Date); // var Corte = Datos.ExecuteProcedure <pauCajaCorte_Result>("pauCajaCorte", oParams); // Se comienza a llenar los datos foreach (var oMov in Corte) { switch (oMov.Orden) { // Fondo de caja case 1: iFila = this.AgregarLineaTitulo(oMov.Concepto); this.dgvDetalle["Totales", iFila].Value = ("$" + oMov.Total.Valor().ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(10)); // this.AgregarLineaTitulo("Ingresos"); this.AgregarLineaTitulo( "Ingresos".PadRight(20 + 1) + "Tickets".PadRight(12 + 1) + "Facturas".PadRight(12 + 1) + "Suma".PadRight(12 + 1) , "Total"); this.Total += oMov.Total.Valor(); break; // Pagos que cuentan en el corte case 2: case 3: case 4: case 5: case 6: case 7: case 8: this.AgregarLineaDetalle( oMov.Pendientes.Valor() , oMov.Concepto.RellenarCortarDerecha(20) + " $" + oMov.Tickets.Valor().ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(11) + " $" + oMov.Facturas.Valor().ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(11) + " $" + oMov.Total.Valor().ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(11) + " [+]" , "" ); mTickets += oMov.Tickets.Valor(); mFacturas += oMov.Facturas.Valor(); this.Total += (oMov.Tickets.Valor() + oMov.Facturas.Valor()); if (oMov.Orden == 8) { this.AgregarLineaEncabezado( " ".PadRight(20) + " $" + mTickets.ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(11) + " $" + mFacturas.ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(11) , "$" + (mTickets + mFacturas).ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(12) ); mTickets = mFacturas = 0; } break; // Refuerzos / Otros ingresos case 9: case 10: iFila = this.AgregarLineaDetalle( oMov.Pendientes.Valor() , oMov.Concepto.RellenarCortarDerecha(46) + " $" + oMov.Total.Valor().ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(11) + " [+]" , "$" + oMov.Total.Valor().ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(12) ); this.Total += oMov.Total.Valor(); break; // Pagos con notas de crédito y ventas a crédito case 11: case 12: this.AgregarLineaDetalle( oMov.Pendientes.Valor() , oMov.Concepto.RellenarCortarDerecha(20) + " $" + oMov.Tickets.Valor().ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(11) + " $" + oMov.Facturas.Valor().ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(11) + " $" + oMov.Total.Valor().ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(11) , "" ); if (oMov.Orden == 12) { // this.AgregarLineaTitulo("Egresos"); this.AgregarLineaTitulo( "Egresos".PadRight(20 + 1) + "Tickets".PadRight(12 + 1) + "Facturas".PadRight(12 + 1) + "Suma".PadRight(12 + 1) , "Total"); } break; // Devoluciones case 13: case 14: case 15: case 16: iFila = this.AgregarLineaDetalle( oMov.Pendientes.Valor() , oMov.Concepto.RellenarCortarDerecha(20) + " $" + oMov.Tickets.Valor().ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(11) + " $" + oMov.Facturas.Valor().ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(11) + " $" + oMov.Total.Valor().ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(11) , "" ); mTickets += oMov.Tickets.Valor(); mFacturas += oMov.Facturas.Valor(); if (oMov.Orden == 14 || oMov.Orden == 16) { this.dgvDetalle["Contenido", iFila].Value += " [-]"; this.dgvDetalle["Totales", iFila].Value = ("$" + oMov.Total.Valor().ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(12)); this.Total -= oMov.Total.Valor(); } if (oMov.Orden == 16) { this.AgregarLineaEncabezado( " ".PadRight(20) + " $" + mTickets.ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(11) + " $" + mFacturas.ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(11) + " $" + (mTickets + mFacturas).ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(11) , "" ); mTickets = mFacturas = 0; } break; // Resguardos / Gastos case 17: case 18: iFila = this.AgregarLineaDetalle( oMov.Pendientes.Valor() , oMov.Concepto.RellenarCortarDerecha(46) + " $" + oMov.Total.Valor().ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(11) + " [-]" , "$" + oMov.Total.Valor().ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(12) ); this.Total -= oMov.Total.Valor(); break; case 19: case 20: this.AgregarLineaDetalle( oMov.Pendientes.Valor() , oMov.Concepto.RellenarCortarDerecha(20) + " $" + oMov.Tickets.Valor().ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(11) + " $" + oMov.Facturas.Valor().ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(11) + " $" + oMov.Total.Valor().ToString(GlobalClass.FormatoDecimal).RellenarCortarIzquierda(11) , "" ); break; } } // Se llenan los totales this.AgregarLineaEncabezado("Debe haber en Caja".PadLeft(60), "$" + this.Total.ToString(GlobalClass.FormatoDecimal).PadLeft(12)); this.AgregarLineaEncabezado("Hay en Caja".PadLeft(60), "$" + "0.00".PadLeft(12)); this.AgregarLineaEncabezado("Diferencia".PadLeft(60), "$" + this.Total.ToString(GlobalClass.FormatoDecimal).PadLeft(12)); // Se llenan los cambios this.dgvCambios.Rows.Clear(); oParams.Add("OpcionID", CajaDetalleCorte.Opciones.Cambios); var oCambios = Datos.ExecuteProcedure <cdcCambios>("pauCajaDetalleCorte", oParams); // Se agrega el título this.dgvCambios.Rows.Add("Titulo", "Ventas con cambio".ToUpper()); // Se agrega el encabezado this.dgvCambios.Rows.Add( "Encabezado", ( "Folio".PadRight(7 + 1) + "Nombre del Cliente".PadRight(20 + 1) + "F. pago".PadRight(32 + 1) + "Usuario".PadRight(12 + 1) + "Comisionista".PadRight(12) ).ToUpper() ); // Se llenan los datos foreach (var oCambio in oCambios) { this.dgvCambios.Rows.Add( "Detalle" , oCambio.Folio.RellenarCortarDerecha(7) + " " + oCambio.Cliente.RellenarCortarDerecha(20) + " " + oCambio.FormasDePago.RellenarCortarDerecha(32) + " " + oCambio.Vendedor.RellenarCortarDerecha(12) + " " + oCambio.Comisionista.RellenarCortarDerecha(12) ); } // Se cierra la ventana de "Cargando.." Cargando.Cerrar(); }
private bool AccionGuardar() { if (!this.Validar()) { return(false); } Cargando.Mostrar(); // Se obtiene la póliza ContaPoliza oPoliza; if (this.iPolizaID > 0) { oPoliza = Datos.GetEntity <ContaPoliza>(c => c.ContaPolizaID == iPolizaID); } else { oPoliza = new ContaPoliza() { SucursalID = GlobalClass.SucursalID, RealizoUsuarioID = GlobalClass.UsuarioGlobal.UsuarioID, FueManual = true } }; // Se guarda la póliza oPoliza.Fecha = this.dtpFecha.Value; oPoliza.ContaTipoPolizaID = Util.Entero(this.cmbTipoPoliza.SelectedValue); oPoliza.Concepto = this.txtConcepto.Text; oPoliza.Origen = this.txtOrigen.Text; oPoliza.Error = false; Datos.Guardar <ContaPoliza>(oPoliza); // Se procede a guardar el detalle ContaPolizaDetalle oReg = null; foreach (DataGridViewRow oFila in this.dgvDetalle.Rows) { if (oFila.IsNewRow) { continue; } int iCuentaAuxID = Util.Entero(oFila.Cells["ContaCuentaAuxiliarID"].Value); int iId = this.dgvDetalle.ObtenerId(oFila); int iCambio = this.dgvDetalle.ObtenerIdCambio(oFila); switch (iCambio) { case Cat.TiposDeAfectacion.Agregar: case Cat.TiposDeAfectacion.Modificar: if (iCambio == Cat.TiposDeAfectacion.Agregar) { oReg = new ContaPolizaDetalle() { ContaPolizaID = oPoliza.ContaPolizaID } } ; else { oReg = Datos.GetEntity <ContaPolizaDetalle>(c => c.ContaPolizaDetalleID == iId); } oReg.ContaCuentaAuxiliarID = iCuentaAuxID; oReg.Cargo = Util.Decimal(oFila.Cells["Cargo"].Value); oReg.Abono = Util.Decimal(oFila.Cells["Abono"].Value); oReg.Referencia = Util.Cadena(oFila.Cells["Referencia"].Value); oReg.SucursalID = Util.Entero(oFila.Cells["SucursalID"].Value); Datos.Guardar <ContaPolizaDetalle>(oReg); break; case Cat.TiposDeAfectacion.Borrar: oReg = Datos.GetEntity <ContaPolizaDetalle>(c => c.ContaPolizaDetalleID == iId); Datos.Eliminar <ContaPolizaDetalle>(oReg); break; } // Se verifica si se afecta una cuenta bancaria, en cuyo caso, se crea un movimiento bancario if (iCambio == Cat.TiposDeAfectacion.Agregar) { var oCuentaAux = Datos.GetEntity <ContaCuentaAuxiliar>(c => c.ContaCuentaAuxiliarID == iCuentaAuxID); if ((oCuentaAux.ContaCuentaDeMayorID == Cat.ContaCuentasDeMayor.Bancos || oCuentaAux.ContaCuentaDeMayorID == Cat.ContaCuentasDeMayor.CuentasPorPagarCortoPlazo) && oCuentaAux.RelacionID.HasValue) { var oMovBanc = new BancoCuentaMovimiento() { BancoCuentaID = oCuentaAux.RelacionID.Valor(), EsIngreso = (oReg.Cargo > 0), Fecha = oPoliza.Fecha, FechaAsignado = oPoliza.Fecha, SucursalID = oPoliza.SucursalID, Importe = (oReg.Cargo > 0 ? oReg.Cargo : oReg.Abono), Concepto = oPoliza.Concepto, Referencia = oReg.Referencia, TipoFormaPagoID = Cat.FormasDePago.Efectivo, RelacionID = oReg.ContaPolizaDetalleID }; ContaProc.RegistrarMovimientoBancario(oMovBanc); } } } Cargando.Cerrar(); return(true); }
private void CargarDatos() { Cargando.Mostrar(); int iSucursalID = Util.Entero(this.cmbSucursal.SelectedValue); var oParams = new Dictionary <string, object>(); oParams.Add("SucursalID", (iSucursalID == 0 ? null : (int?)iSucursalID)); oParams.Add("Pagadas", this.chkPagadas.Checked); oParams.Add("Cobradas", this.chkCobradas.Checked); oParams.Add("Solo9500", this.chk9500.Checked); oParams.Add("OmitirDomingo", this.chkOmitirDomingos.Checked); // oParams.Add("CostoConDescuento", this.chkCostoConDescuento.Checked); oParams.Add("Desde", this.dtpDesde.Value); oParams.Add("Hasta", this.dtpHasta.Value); var oDatos = Datos.ExecuteProcedure <pauCuadroDeControlGeneralNuevo_Result>("pauCuadroDeControlGeneral", oParams); var oTotales = this.ObtenerTotales(oDatos); // Se llena el grid de por día var oPorDia = this.AgruparPorDia(oDatos); this.dgvPorDia.Rows.Clear(); foreach (var oReg in oPorDia) { this.dgvPorDia.Rows.Add(oReg.Llave, oReg.Actual, oReg.Anterior , Util.DividirONull(oReg.Actual, oReg.Anterior), (Util.DividirONull(oReg.Actual, oTotales.Actual) * 100)); } this.dgvPorDiaT["DiaT_Actual", 0].Value = (oPorDia.Count() > 0 ? oPorDia.Average(c => c.Actual) : 0); this.dgvPorDiaT["DiaT_Anterior", 0].Value = (oPorDia.Count() > 0 ? oPorDia.Average(c => c.Anterior) : 0); // Se llena el grid de por semana var oPorSemana = this.AgruparPorEntero(oDatos.GroupBy(g => UtilTheos.SemanaSabAVie(g.Fecha))); this.dgvPorSemana.Rows.Clear(); this.chrPorSemana.Series["Actual"].Points.Clear(); this.chrPorSemana.Series["Pasado"].Points.Clear(); foreach (var oReg in oPorSemana) { this.dgvPorSemana.Rows.Add(oReg.Llave, oReg.Actual, oReg.Anterior , Util.DividirONull(oReg.Actual, oReg.Anterior), (Util.DividirONull(oReg.Actual, oTotales.Actual) * 100)); this.chrPorSemana.Series["Actual"].Points.AddXY(oReg.Llave, oReg.Actual); this.chrPorSemana.Series["Pasado"].Points.AddXY(oReg.Llave, oReg.Anterior); } this.dgvPorSemanaT["SemanaT_Actual", 0].Value = (oPorSemana.Count() > 0 ? oPorSemana.Average(c => c.Actual) : 0); this.dgvPorSemanaT["SemanaT_Anterior", 0].Value = (oPorSemana.Count() > 0 ? oPorSemana.Average(c => c.Anterior) : 0); // Se llena el grid de por mes var oPorMes = this.AgruparPorEntero(oDatos.GroupBy(g => g.Fecha.Month)); this.dgvPorMes.Rows.Clear(); this.chrPorMes.Series["Actual"].Points.Clear(); this.chrPorMes.Series["Pasado"].Points.Clear(); foreach (var oReg in oPorMes) { this.dgvPorMes.Rows.Add(CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(oReg.Llave).ToUpper(), oReg.Actual, oReg.Anterior , Util.DividirONull(oReg.Actual, oReg.Anterior), (Util.DividirONull(oReg.Actual, oTotales.Actual) * 100)); this.chrPorMes.Series["Actual"].Points.AddXY(oReg.Llave, oReg.Actual); this.chrPorMes.Series["Pasado"].Points.AddXY(oReg.Llave, oReg.Anterior); } // Se llena el grid de días oParams["Desde"] = this.dtpDesde.Value; oParams["Hasta"] = this.dtpHasta.Value; oDatos = Datos.ExecuteProcedure <pauCuadroDeControlGeneralNuevo_Result>("pauCuadroDeControlGeneral", oParams); var oPorDiaSem = oDatos.GroupBy(g => g.Fecha.DayOfWeek).Select(c => new { Dia = c.Key, Actual = c.Sum(s => s.Actual), Anterior = c.Sum(s => s.Anterior) }) .OrderBy(o => (int)o.Dia); decimal mTotalDiaSem = (oDatos.Count > 0 ? oDatos.Sum(c => c.Actual).Valor() : 0); this.dgvDias.Rows.Clear(); this.chrPorDiaSem.Series["Actual"].Points.Clear(); foreach (var oReg in oPorDiaSem) { this.dgvDias.Rows.Add(CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(oReg.Dia).ToUpper(), oReg.Actual, oReg.Anterior , Util.DividirONull(oReg.Actual, oReg.Anterior), (Util.DividirONull(oReg.Actual, mTotalDiaSem) * 100)); int iPunto = this.chrPorDiaSem.Series["Actual"].Points.AddXY((int)oReg.Dia, oReg.Actual); this.chrPorDiaSem.Series["Actual"].Points[iPunto].AxisLabel = CultureInfo.CurrentCulture.DateTimeFormat.GetShortestDayName(oReg.Dia).ToUpper(); } // Se llena el grid de horas var oPorHora = this.AgruparPorEntero(oDatos.GroupBy(g => g.Fecha.Hour)); this.dgvHoras.Rows.Clear(); this.chrPorHora.Series.Clear(); foreach (var oReg in oPorHora) { this.dgvHoras.Rows.Add(string.Format("{0:00}:00", oReg.Llave), oReg.Actual, oReg.Anterior , Util.DividirONull(oReg.Actual, oReg.Anterior), (Util.DividirONull(oReg.Actual, mTotalDiaSem) * 100)); this.AgregarSerieCilindro(this.chrPorHora, oReg.Llave, oReg.Actual); } // Se llena el grid de sucursales var oPorSucursal = this.AgruparPorEntero(oDatos.GroupBy(g => g.SucursalID)); var oSucursales = oDatos.Select(c => new { c.SucursalID, c.Sucursal }).Distinct(); this.dgvSucursales.Rows.Clear(); foreach (var oReg in oPorSucursal) { string sSucursal = oSucursales.FirstOrDefault(c => c.SucursalID == oReg.Llave).Sucursal; this.dgvSucursales.Rows.Add(sSucursal, oReg.Actual, oReg.Anterior , Util.DividirONull(oReg.Actual, oReg.Anterior), (Util.DividirONull(oReg.Actual, mTotalDiaSem) * 100)); } // Se llena el grid de por año oParams.Remove("Desde"); oParams.Remove("Hasta"); var oPorAnio = Datos.ExecuteProcedure <pauCuadroDeControlPorAnio_Result>("pauCuadroDeControlPorAnio", oParams); this.dgvPorAnio.Rows.Clear(); foreach (var oReg in oPorAnio) { decimal mDato = this.ObtenerDatoAnio(oReg); this.dgvPorAnio.Rows.Add(oReg.Anio, mDato); this.chrPorAnio.Series["Actual"].Points.AddXY(oReg.Anio, mDato); } // Se configuran columnas del grid this.AplicarFormatoColumnas(); // Se llenan los totales this.txtAnioActual.Text = oTotales.Actual.ToString(GlobalClass.FormatoMoneda); this.txtAnioAnterior.Text = oTotales.Anterior.ToString(GlobalClass.FormatoMoneda); this.txtResultado.Text = Util.DividirONull(oTotales.Actual, oTotales.Anterior).Valor().ToString(GlobalClass.FormatoDecimal); Cargando.Cerrar(); }
public override bool Ejecutar() { // Se valida la opción if (!this.ctlFacturar.Validar()) { return(false); } // Se pregunta si se debe facturar al mismo cliente de las ventas o a otro int iAFClienteID = this.Cliente.ClienteID; if (UtilLocal.MensajePregunta("¿Deseas hacer la factura a nombre del cliente seleccionado?") == DialogResult.No) { iAFClienteID = 0; var frmValor = new MensajeObtenerValor("Selecciona el cliente para facturar:", "", MensajeObtenerValor.Tipo.Combo); frmValor.CargarCombo("ClienteID", "Nombre", Datos.GetListOf <Cliente>(q => q.ClienteID != Cat.Clientes.Mostrador && q.Estatus)); if (frmValor.ShowDialog(Principal.Instance) == DialogResult.OK) { iAFClienteID = Util.Entero(frmValor.Valor); } frmValor.Dispose(); } if (iAFClienteID == 0) { return(false); } // Se solicita el usuario que realiza el proceso int iUsuarioID = 0; var Res = UtilLocal.ValidarObtenerUsuario("Ventas.FacturarTickets.Agregar"); if (Res.Error) { return(false); } iUsuarioID = Res.Respuesta.UsuarioID; // Se muestra la ventana de "Cargando.." Cargando.Mostrar(); // DateTime dAhora = DateTime.Now; // Se obtienen los datos de los productos, por si se cambió la descripción List <ProductoVenta> oPartes = null; if (this.ctlFacturar.MostrarTodasLasPartes) { oPartes = this.ctlDetalle.ObtenerListaVenta(); } // Se procede a generar la factura var oVentasAF = this.ctlFacturar.GenerarListaDeVentas(); var oFormasDePago = this.ctlFacturar.FormasDePagoLibre; var ResFe = VentasLoc.GenerarFacturaElectronica(oVentasAF, iAFClienteID, oPartes, oFormasDePago, this.ctlFacturar.Observacion, null); if (ResFe.Error) { UtilLocal.MensajeAdvertencia(ResFe.Mensaje); return(false); } // Se guarda el dato de que fue una factura de ventas var oFactura = Datos.GetEntity <VentaFactura>(q => q.VentaFacturaID == ResFe.Respuesta && q.Estatus); oFactura.Convertida = true; oFactura.RealizoUsuarioID = iUsuarioID; Datos.Guardar <VentaFactura>(oFactura); // Se manda a afectar contabilidad (AfeConta) foreach (int iVentaID in oVentasAF) { var oVentaV = Datos.GetEntity <VentasView>(c => c.VentaID == iVentaID); if (oVentaV.ACredito) { ContaProc.CrearPolizaAfectacion(Cat.ContaAfectaciones.VentaCredito, iVentaID, (oFactura.Serie + oFactura.Folio), oVentaV.Cliente); // Se verifica si el ticket ya está pagado, para hacer la póliza correspondiente a dicho pago if (oVentaV.Pagado > 0) { var oPagos = Datos.GetListOf <VentaPago>(c => c.VentaID == iVentaID && c.Estatus); foreach (var oReg in oPagos) { ContaProc.CrearPolizaAfectacion(Cat.ContaAfectaciones.PagoVentaCredito, oReg.VentaPagoID , ((oFactura.Serie + oFactura.Folio) + " / " + UtilDatos.VentaPagoFormasDePago(oReg.VentaPagoID)) , oVentaV.Cliente, oReg.SucursalID); } } // Se borra la póliza temporal creada por ser ticket a crédito ContaProc.BorrarPolizaTemporalTicketCredito(iVentaID); } else { ContaProc.CrearPolizaAfectacion(Cat.ContaAfectaciones.VentaContadoFacturaConvertida, iVentaID , (oFactura.Serie + oFactura.Folio), oVentaV.Cliente, oVentaV.SucursalID); } } // Se guarda el dato de pendiente por descontar en la factura global, si aplica // Se guardan datos cuando se están facturando tickets abonados en otras sucursales foreach (int iVentaID in oVentasAF) { // Se obtienen los abonos de otras sucursales var oAbonos = Datos.GetListOf <VentasPagosView>(c => c.VentaID == iVentaID && c.SucursalID != GlobalClass.SucursalID) .GroupBy(c => new { c.VentaID, c.SucursalID }).Select(c => new { c.Key.VentaID, c.Key.SucursalID, Abonado = c.Sum(s => s.Importe) }); if (oAbonos != null && oAbonos.Count() > 0) { foreach (var oReg in oAbonos) { var oPendiente = new FacturaGlobalPendientePorDescontar() { VentaID = oReg.VentaID, Fecha = dAhora, SucursalID = oReg.SucursalID, Importe = oReg.Abonado }; Datos.Guardar <FacturaGlobalPendientePorDescontar>(oPendiente); } } } // Se cierra la ventana de "Cargando.." Cargando.Cerrar(); // Se muestra una notifiación con el resultado UtilLocal.MostrarNotificacion("Procedimiento ejecutado correctamente."); // Se limpia después de haberse guardado this.Limpiar(); return(true); }
private bool AccionAceptar() { // Cargando.Mostrar(); decimal mFaltante = 0; int iClienteID = 0; int iCobroVentaID = 0; bool bUsarCascosAFavor = false; bool bCrearVale = false; bool bCascoAFavor = false; int iCascoRecibido = Util.Entero(this.cmbCascoRecibido.SelectedValue); int iSucursalID = GlobalClass.SucursalID; int iCascoRegistroID = this.oCascoRegistro.CascoRegistroID; int iParteID = this.oCascoRegistro.ParteID; var oParte = Datos.GetEntity <Parte>(c => c.ParteID == iParteID && c.Estatus); var oVenta = Datos.GetEntity <Venta>(c => c.VentaID == this.oCascoRegistro.VentaID && c.Estatus); iClienteID = oVenta.ClienteID; var oCliente = Datos.GetEntity <Cliente>(c => c.ClienteID == oVenta.ClienteID && c.Estatus); if (iCascoRecibido != oParte.RequiereCascoDe) { // Si se recibió algún casco if (iCascoRecibido > 0) { // Se obtienen el importe requerido var oPrecioReq = Datos.GetEntity <PartePrecio>(c => c.ParteID == oParte.RequiereCascoDe && c.Estatus); var oPrecioRec = Datos.GetEntity <PartePrecio>(c => c.ParteID == iCascoRecibido && c.Estatus); if (oPrecioReq == null || oPrecioRec == null) { UtilLocal.MensajeAdvertencia("Hubo un error al obtener el Casco requerido."); return(false); } // Se calcula el importe faltante decimal?[] aPreciosReq = new decimal?[5] { oPrecioReq.PrecioUno, oPrecioReq.PrecioDos, oPrecioReq.PrecioTres, oPrecioReq.PrecioCuatro, oPrecioReq.PrecioCinco }; decimal?[] aPreciosRec = new decimal?[5] { oPrecioRec.PrecioUno, oPrecioRec.PrecioDos, oPrecioRec.PrecioTres, oPrecioRec.PrecioCuatro, oPrecioRec.PrecioCinco }; mFaltante = (aPreciosReq[oCliente.ListaDePrecios - 1] - aPreciosRec[oCliente.ListaDePrecios - 1]).Valor(); // Se evalúa el importe faltante, para tomar alguna acción if (mFaltante != 0) { // Si el casco recibido es menor que el casco esperado if (mFaltante > 0) { // Se busca por folio de cobro o por cascos a favor, según sea el caso if (this.txtFolioDeCobro.Text == "") { decimal mTotalAFavor = Util.Decimal(this.lblTotalAFavor.Text); if (mTotalAFavor != mFaltante) { UtilLocal.MensajeAdvertencia("El importe seleccionado con los Cascos a favor debe ser de " + mFaltante.ToString(GlobalClass.FormatoMoneda)); return(false); } bUsarCascosAFavor = true; } else { // Se obtiene el importe de la venta var oVentaCobroV = Datos.GetEntity <VentasView>(c => c.Folio == this.txtFolioDeCobro.Text && c.SucursalID == GlobalClass.SucursalID && (c.VentaEstatusID == Cat.VentasEstatus.Cobrada || c.VentaEstatusID == Cat.VentasEstatus.Completada)); if (oVentaCobroV == null) { UtilLocal.MensajeAdvertencia("La venta específicada no existe, no es de esta sucursal o no ha sido cobrada."); return(false); } iCobroVentaID = oVentaCobroV.VentaID; // Se valida que la parte de la venta sea una "diferencia de casco" if (!Datos.Exists <VentaDetalle>(c => c.VentaID == iCobroVentaID && c.ParteID == Cat.Partes.DiferenciaDeCascos && c.Estatus)) { UtilLocal.MensajeAdvertencia("La venta especificada no corresponde a una Diferencia de Casco."); return(false); } // Se valida que el importe cobrado sea el correspondiente if (oVentaCobroV.Total != mFaltante) { UtilLocal.MensajeAdvertencia("El cobro por la diferencia debe de ser de " + mFaltante.ToString(GlobalClass.FormatoMoneda)); return(false); } } } // Si el casco recibido es mayor que el casco esperado else if (mFaltante < 0) { var oRes = UtilLocal.MensajePreguntaCancelar("El importe del casco recibido es mayor al esperado. ¿Deseas crear un Vale a favor del Cliente?"); if (oRes == DialogResult.Cancel) { return(false); } bCrearVale = (oRes == DialogResult.Yes); bCascoAFavor = !bCrearVale; } } } else // Si no se recibió ningún casco, se evalúa la venta { // Se obtiene la VentaID var oVentaCobro = Datos.GetEntity <Venta>(c => c.Folio == this.txtFolioDeCobro.Text && c.SucursalID == GlobalClass.SucursalID && (c.VentaEstatusID == Cat.VentasEstatus.Cobrada || c.VentaEstatusID == Cat.VentasEstatus.Completada) && c.Estatus); if (oVentaCobro == null) { UtilLocal.MensajeAdvertencia("La venta específicada no existe, no es de esta sucursal o no ha sido cobrada."); return(false); } iCobroVentaID = oVentaCobro.VentaID; // Se valida que la venta tenga la Parte correspondiente al casco if (!Datos.Exists <VentaDetalle>(c => c.VentaID == iCobroVentaID && c.ParteID == oParte.RequiereDepositoDe && c.Estatus)) { UtilLocal.MensajeAdvertencia("El cobro del Casco no corresonde al Artículo."); return(false); } } } // Cargando.Cerrar(); // Se solicita la contraseña var oResU = UtilLocal.ValidarObtenerUsuario("Ventas.ControlDeCascos.Completar"); if (oResU.Error) { return(false); } Cargando.Mostrar(); // Se completa el registro de casco DateTime dAhora = DateTime.Now; // Se registran y modifican los Cascos a favor usados, si aplica if (bUsarCascosAFavor) { foreach (DataGridViewRow oFila in this.dgvImportesAFavor.Rows) { if (Util.Logico(oFila.Cells["Sel"].Value)) { // Se registra el importe usado para el CascoImporte int iCascoImporteID = Util.Entero(oFila.Cells["CascoImporteID"].Value); decimal mAUsar = Util.Decimal(oFila.Cells["ImporteAUsar"].Value); var oCascoImporte = Datos.GetEntity <CascoImporte>(c => c.CascoImporteID == iCascoImporteID); oCascoImporte.ImporteUsado += mAUsar; Datos.Guardar <CascoImporte>(oCascoImporte); // Se registra la relación entre el CascoRegistro y el CascoImporte var oCascoRegImp = new CascoRegistroImporte() { CascoRegistroID = this.oCascoRegistro.CascoRegistroID, CascoImporteID = oCascoImporte.CascoImporteID, Importe = mAUsar }; Datos.Guardar <CascoRegistroImporte>(oCascoRegImp); } } } // Se crea el vale, si aplica if (bCrearVale) { var oRes = VentasProc.GenerarNotaDeCredito(iClienteID, (mFaltante * -1), "", Cat.OrigenesNotaDeCredito.CascoDeMayorValor , this.oCascoRegistro.CascoRegistroID); // Se crea la póliza contable (AfeConta) ContaProc.CrearPolizaAfectacion(Cat.ContaAfectaciones.ValeDirecto, oRes.Respuesta, oCliente.Nombre, "POR CASCO MAYOR"); // Se manda a imprimir el ticket VentasLoc.GenerarTicketNotaDeCredito(oRes.Respuesta); } // Se registra el casco a favor, si aplica if (bCascoAFavor) { var oCascoImporte = new CascoImporte() { Fecha = dAhora, OrigenID = this.oCascoRegistro.CascoRegistroID, Importe = (mFaltante * -1) }; Datos.Guardar <CascoImporte>(oCascoImporte); } // Se afecta la existencia y el kárdex del casco recibido if (iCascoRecibido > 0) { var oSucursal = Datos.GetEntity <Sucursal>(c => c.SucursalID == iSucursalID && c.Estatus); var oPrecioRec = Datos.GetEntity <PartePrecio>(c => c.ParteID == iCascoRecibido && c.Estatus); AdmonProc.AfectarExistenciaYKardex(iCascoRecibido, GlobalClass.SucursalID, Cat.OperacionesKardex.EntradaInventario, iCascoRegistroID.ToString() , oResU.Respuesta.UsuarioID, oCliente.Nombre, "CONTROL DE CASCOS", oSucursal.NombreSucursal, 1, oPrecioRec.Costo.Valor() , Cat.Tablas.CascoRegistro, iCascoRegistroID); } // Se guardan los datos del registro de casco this.oCascoRegistro.RecibidoCascoID = (iCascoRecibido > 0 ? (int?)iCascoRecibido : null); this.oCascoRegistro.RealizoUsuarioID = oResU.Respuesta.UsuarioID; this.oCascoRegistro.CobroVentaID = (iCobroVentaID > 0 ? (int?)iCobroVentaID : null); Datos.Guardar <CascoRegistro>(this.oCascoRegistro); // Se manda a imprimir el ticket correspondiente var oCascoRegV = Datos.GetEntity <CascosRegistrosView>(c => c.CascoRegistroID == iCascoRegistroID); var oRep = new Report(); oRep.Load(GlobalClass.ConfiguracionGlobal.pathReportes + "ControlDeCascos.frx"); VentasLoc.TicketAgregarLeyendas(ref oRep); oRep.RegisterData(new List <CascosRegistrosView>() { oCascoRegV }, "ControlDeCasco"); UtilLocal.EnviarReporteASalida("Reportes.ControlDeCascos.Completar.Salida", oRep); Cargando.Cerrar(); UtilLocal.MostrarNotificacion("Control de casco completado correctamente."); return(true); }
private void LlenarVentasProc() { // Se muestra la ventana de "Cargando.." Cargando.Mostrar(); int iVendedorID = Util.Entero(this.cmbVendedor.SelectedValue); this.oComisiones.ctlDetalle.LimpiarDetalle(); //this.dgvGerentesComisiones.Visible = false; this.pnlUtVendedores.Visible = false; //this.lblUtilSuc.Visible = false; // Se muestra u oculta la columna de Utilidad this.dgvVentas.Columns["Utilidad"].Visible = this.bVerAdicional; this.dgvTotales.Columns["TotalesUtilidad"].Visible = this.bVerAdicional; // Se obtienen los datos del vendedor this.oMetaVendedor = Datos.GetEntity <MetaVendedor>(c => c.VendedorID == iVendedorID); if (this.oMetaVendedor == null) { Cargando.Cerrar(); UtilLocal.MensajeInformacion("No se ha especificado una meta al vendedor."); return; } this.oMetaSucursal = Datos.GetEntity <MetaSucursal>(c => c.SucursalID == this.oMetaVendedor.SucursalID); this.mMetaSucursal = this.oMetaSucursal.UtilSucursal; this.mMetaVendedor = (this.oMetaVendedor.EsGerente ? this.oMetaSucursal.UtilGerente : this.oMetaSucursal.UtilVendedor); // Quitar variables globales de metavendedor y metasucursa, sólo deberían usarse las locales. Revisar // Se manda llamar el procedimiento para obtener los datos var oParams = new Dictionary <string, object>(); oParams.Add("ModoID", 1); oParams.Add("VendedorID", iVendedorID); oParams.Add("Desde", this.dtpDe.Value.Date); oParams.Add("Hasta", this.dtpA.Value.Date); oParams.Add("SucursalID", Theos.SucursalID); //var oDatos = Datos.ExecuteProcedure<pauComisiones_Result>("pauComisiones", oParams); var oDatos = Datos.ExecuteProcedure <pauComisiones2_Result>("pauComisiones2test", oParams).OrderBy(c => c.Caracteristica == "D"); //var oDatos = Datos.ExecuteProcedure<pauComisiones2_Result>("pauComisiones", oParams); //var oDatos = Datos.ExecuteProcedure<pauComisiones2_Result>("pauComisiones3test5", oParams); #region LLenarGrid // Se llena el grid this.dgvVentas.Rows.Clear(); foreach (var oReg in oDatos) { //int iFila = this.dgvVentas.Rows.Add(oReg.VentaID, oReg.Caracteristica, oReg.Fecha, oReg.Cliente, oReg.Folio, oReg.Importe, oReg.Cobranza // , oReg.Utilidad, oReg.Comision, (oReg.Caracteristica.EndsWith("9500") ? "SÍ" : "")); int iFila = this.dgvVentas.Rows.Add(oReg.VentaID, oReg.Caracteristica, oReg.Fecha, oReg.Cliente, oReg.Folio, oReg.Importe, oReg.Cobranza , oReg.Utilidad, oReg.Comision, oReg.ComisionFija, (oReg.Es9500.Valor() ? "SÍ" : "")); // Se marcan los colores switch (oReg.Caracteristica) { case "VD9500": case "VD": this.dgvVentas.Rows[iFila].DefaultCellStyle.ForeColor = Color.Gray; break; case "D9500": case "D": this.dgvVentas.Rows[iFila].DefaultCellStyle.ForeColor = Color.Red; break; } } #endregion // Se llena la línea de totales, del grid decimal mTotalImporte = 0, mTotalCobranza = 0; decimal mComision = 0, mUtilidad = 0; decimal mComisionVariable = 0, mComisionNegativa = 0; decimal mComision9500 = 0, mUtilidad9500 = 0, mComNeg9500 = 0, mUtilNeg9500 = 0; decimal mComisionFija = 0; decimal mComisionFijaDev = 0; decimal mComision9500Dev = 0; #region CalculaComisiones foreach (DataGridViewRow Fila in this.dgvVentas.Rows) { mTotalImporte += Util.Decimal(Fila.Cells["Importe"].Value); mTotalCobranza += Util.Decimal(Fila.Cells["Cobranza"].Value); mUtilidad += Util.Decimal(Fila.Cells["Utilidad"].Value); mComision = Util.Decimal(Fila.Cells["Comision"].Value); // bool b9500 = Util.Cadena(Fila.Cells["Caracteristica"].Value).Contains("9500"); bool b9500 = (Util.Cadena(Fila.Cells["Detalle_9500"].Value) == "SÍ"); //si es 9500 y es devolución se suman la cantidad if (b9500) { if (Util.Cadena(Fila.Cells["Caracteristica"].Value).Substring(0, 1) == "D") { mComision9500Dev += Util.Decimal(Fila.Cells["Comision"].Value); } } if (Util.Cadena(Fila.Cells["Caracteristica"].Value).Substring(0, 1) == "V") { mComisionVariable += mComision; mComision9500 += (b9500 ? mComision : 0); mUtilidad9500 += (b9500 ? mUtilidad : 0); mComisionFija += Util.Decimal(Fila.Cells["ComisionFija"].Value); } else { //mComisionNegativa += mComision; if (!b9500) { mComisionNegativa += Util.Decimal(Fila.Cells["Comision"].Value); } mComNeg9500 += (b9500 ? mComision : 0); mUtilNeg9500 += (b9500 ? mUtilidad : 0); mComisionFijaDev += Util.Decimal(Fila.Cells["ComisionFija"].Value); } // Para sumar la comisión de las ventas 9500 /* if (Util.ConvertirCadena(Fila.Cells["Caracteristica"].Value) == "V9500") * { * mComision9500 += mComision; * mUtilidad9500 += mUtilidad; * } */ } #endregion this.dgvTotales["TotalesImporte", 0].Value = mTotalImporte; this.dgvTotales["TotalesCobranza", 0].Value = mTotalCobranza; this.dgvTotales["TotalesUtilidad", 0].Value = mUtilidad; this.dgvTotales["TotalesComision", 0].Value = (mComisionVariable + mComisionNegativa + mComNeg9500); //se cambio a resta, original suma this.dgvTotales["TotalFija", 0].Value = mComisionFija; // Se obtienen los totales de tienda this.LlenarUtilidadSuc(); #region LlenarEtiquetas // Se llenan los totales del vendedor decimal mFijo = this.oMetaVendedor.SueldoFijo; decimal mUtilidadSuc = this.mUtilidadSuc; // (this.mUtilidadSuc - this.mGastoSuc); // Se calcula el total decimal mUtilMinimo = (this.oMetaVendedor.EsGerente ? this.oMetaSucursal.UtilGerente : this.oMetaSucursal.UtilVendedor); decimal mComisionGerente = 0; if (mUtilidadSuc >= this.oMetaSucursal.UtilSucursalMinimo && mUtilidad >= mUtilMinimo) { if (this.oMetaVendedor.EsGerente) { /* * decimal mExcedente = (mUtilidadSuc - this.mMetaSucursal); * int iMultiplicador = (int)(mExcedente / this.oMetaVendedor.IncrementoUtil.Valor()); * decimal mComisionGerente = (this.oMetaVendedor.IncrementoFijo.Valor() * iMultiplicador); */ mComisionGerente = VentasProc.CalcularComisionGerente(this.oMetaSucursal.UtilSucursalMinimo, mUtilidadSuc, this.oMetaVendedor.IncrementoUtil.Valor() , this.oMetaVendedor.IncrementoFijo.Valor()); this.lblVariable.Text = mComisionGerente.ToString(GlobalClass.FormatoMoneda); this.lblTotal.Text = (this.oMetaVendedor.SueldoFijo + mComisionGerente + mComision9500 + (mComNeg9500)).ToString(GlobalClass.FormatoMoneda); } } else { //if (this.oMetaVendedor.EsGerente) // this.lblVariable.Text = 0.ToString(GlobalClass.FormatoMoneda); //this.lblTotal.Text = "--"; } if (!this.oMetaVendedor.MetaConsiderar9500) { mUtilidad -= mUtilidad9500; } //this.lblUtilSuc.Text = mUtilidadSuc.ToString(GlobalClass.FormatoMoneda); //subtotal comisiones y fijo this.lblFijo.Text = mFijo.ToString(GlobalClass.FormatoMoneda); //subtotal variable if (this.oMetaVendedor.EsGerente) { this.lblVariable.Text = mComisionGerente.ToString(GlobalClass.FormatoMoneda); this.lblDevoluciones.Text = 0.ToString(GlobalClass.FormatoMoneda); this.lblSubVariable.Text = mComisionGerente.ToString(GlobalClass.FormatoMoneda); } else { this.lblVariable.Text = (mComisionVariable - mComision9500).ToString(GlobalClass.FormatoMoneda); this.lblDevoluciones.Text = (mComisionNegativa).ToString(GlobalClass.FormatoMoneda); this.lblSubVariable.Text = ((mComisionVariable - mComision9500) - Math.Abs(mComisionNegativa)).ToString(GlobalClass.FormatoMoneda); } //Subtotal 9500 this.lbl9500.Text = (mComision9500).ToString(GlobalClass.FormatoMoneda); this.lblDev9500.Text = (mComision9500Dev).ToString(GlobalClass.FormatoMoneda); this.lblSub9500.Text = (mComision9500 - Math.Abs(mComision9500Dev)).ToString(GlobalClass.FormatoMoneda); //subtotal comision fija //this.lblTotal.Text = (mFijo + mComisionVariable + (mComisionNegativa)).ToString(GlobalClass.FormatoMoneda); this.lblComisionFija.Text = (mComisionFija).ToString(GlobalClass.FormatoMoneda); this.lblDevFija.Text = (mComisionFijaDev).ToString(GlobalClass.FormatoMoneda); this.lblSubFija.Text = (mComisionFija + mComisionFijaDev).ToString(GlobalClass.FormatoMoneda); decimal Total = 0; //total y meta if (this.oMetaVendedor.EsGerente) { Total = (mFijo + (mComisionGerente) + mComision9500 + mComisionFija + mComision9500Dev); } else { Total = (mFijo + (mComisionVariable - mComision9500) + mComision9500 + mComisionFija + mComisionFijaDev + mComisionNegativa + mComision9500Dev); } this.lblTotal.Text = (Total).ToString(GlobalClass.FormatoMoneda); if (this.oMetaVendedor.SueldoMeta - Total < 0) { this.lblMetaRes.Text = (0).ToString(GlobalClass.FormatoMoneda); } else { this.lblMetaRes.Text = (this.oMetaVendedor.SueldoMeta - Total).ToString(GlobalClass.FormatoMoneda); } #endregion if (this.oMetaVendedor.EsGerente) { decimal meta = this.oMetaSucursal.UtilSucursalMinimo; ComisionesVendedorPorSucursal(mUtilidadSuc, this.oMetaSucursal.UtilSucursalMinimo, mComisionGerente); } // Se cierra la ventana de "Cargando.." Cargando.Cerrar(); this.ComisionesAct = true; }
private void CargarDatos() { Cargando.Mostrar(); var oFuenteT = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Bold); // Se limpian los datos this.dgvDatos.Rows.Clear(); foreach (var oSerie in this.chrPorSemana.Series) { oSerie.Points.Clear(); } // Se llenan las columnas del año int iAnio = Util.Entero(this.cmbAnio.Text); this.LlenarColumnasAnio(iAnio); // Se agrega la fila de ingresos int iFilaIngresos = this.dgvDatos.Rows.Add("+ Ingresos"); this.dgvDatos.Rows[iFilaIngresos].DefaultCellStyle.Font = oFuenteT; decimal mTotal = 0, mPromedio = 0; // Se agrega la fila de saldo inicial int iFilaSaldoInicial = this.dgvDatos.Rows.Add("Saldo inicial"); // Se obtienen los datos para las ventas // int iSucursalID = Util.ConvertirEntero(this.cmbSucursal.SelectedValue); DateTime dDesde = new DateTime(iAnio, 1, 1); DateTime dHasta = new DateTime(iAnio, 12, 31); DateTime dDesdeSemUno = UtilTheos.InicioSemanaSabAVie(dDesde); var oParams = new Dictionary <string, object>(); // oParams.Add("SucursalID", (iSucursalID == 0 ? null : (int?)iSucursalID)); oParams.Add("Pagadas", true); oParams.Add("Cobradas", false); oParams.Add("Solo9500", false); oParams.Add("OmitirDomingo", false); oParams.Add("Desde", dDesdeSemUno); oParams.Add("Hasta", dHasta); var oDatos = Datos.ExecuteProcedure <pauCuadroDeControlGeneralNuevo_Result>("pauCuadroDeControlGeneral", oParams); var oSemanas = oDatos.Where(c => c.Fecha >= dDesdeSemUno) .GroupBy(c => new { Semana = UtilTheos.InicioSemanaSabAVie(c.Fecha) }) .Select(c => new { c.Key.Semana, PrecioSinIva = c.Sum(s => s.PrecioSinIvaActual) }) .OrderBy(c => c.Semana); mTotal += oSemanas.Sum(c => c.PrecioSinIva).Valor(); mPromedio += oSemanas.Average(c => c.PrecioSinIva).Valor(); // Se agrega la fila de ventas int iFila = this.dgvDatos.Rows.Add("Ventas", oSemanas.Sum(c => c.PrecioSinIva), oSemanas.Average(c => c.PrecioSinIva)); foreach (var oReg in oSemanas) { string sSemana = oReg.Semana.ToShortDateString(); this.dgvDatos[sSemana, iFila].Value = (Util.Decimal(this.dgvDatos[sSemana, iFila].Value) + oReg.PrecioSinIva); this.dgvDatos[sSemana, iFilaIngresos].Value = (Util.Decimal(this.dgvDatos[sSemana, iFilaIngresos].Value) + oReg.PrecioSinIva); } // Se obtienen datos para varios grupos DateTime dHastaMas1 = dHasta.AddDays(1); // DateTime dDesdeMas1 = dDesde.AddDays(1); var oReinversiones = Datos.GetListOf <ContaPolizasDetalleAvanzadoView>(c => c.FechaPoliza >= dDesdeSemUno && c.FechaPoliza < dHastaMas1 && ( c.ContaCuentaDeMayorID == Cat.ContaCuentasDeMayor.CuentasPorPagarLargoPlazo || (c.ContaCuentaDeMayorID == Cat.ContaCuentasDeMayor.CuentasPorPagarCortoPlazo && c.ContaCuentaAuxiliarID != Cat.ContaCuentasAuxiliares.TarjetaDeCredito) || c.ContaCuentaDeMayorID == Cat.ContaCuentasDeMayor.AcreedoresDiversos || c.ContaSubcuentaID == Cat.ContaSubcuentas.ActivoFijo ) ); // Se agrega la fila de préstamos var oPrestamos = oReinversiones.Where(c => c.ContaCuentaDeMayorID == Cat.ContaCuentasDeMayor.CuentasPorPagarLargoPlazo || c.ContaCuentaDeMayorID == Cat.ContaCuentasDeMayor.CuentasPorPagarCortoPlazo) .GroupBy(c => UtilTheos.InicioSemanaSabAVie(c.FechaPoliza.Valor())) .Select(c => new { Semana = c.Key, Importe = c.Sum(s => s.Abono) }); mTotal += oPrestamos.Sum(c => c.Importe); decimal mPromedioAct = (oPrestamos.Count() > 0 ? oPrestamos.Average(c => c.Importe) : 0); mPromedio += mPromedioAct; iFila = this.dgvDatos.Rows.Add("Préstamos", oPrestamos.Sum(c => c.Importe), mPromedioAct); foreach (var oReg in oPrestamos) { string sSemana = oReg.Semana.ToShortDateString(); this.dgvDatos[sSemana, iFila].Value = (Util.Decimal(this.dgvDatos[sSemana, iFila].Value) + oReg.Importe); this.dgvDatos[sSemana, iFilaIngresos].Value = (Util.Decimal(this.dgvDatos[sSemana, iFilaIngresos].Value) + oReg.Importe); } // Se llenan los totales de ingresos this.dgvDatos["Total", iFilaIngresos].Value = mTotal; this.dgvDatos["Promedio", iFilaIngresos].Value = (mPromedio / 2); // Se agrega la fila de egresos int iFilaEgresos = this.dgvDatos.Rows.Add("- Egresos"); this.dgvDatos.Rows[iFilaEgresos].DefaultCellStyle.Font = oFuenteT; mTotal = mPromedio = 0; // Se obtienen los datos para los gastos oParams.Clear(); oParams.Add("Desde", dDesdeSemUno); oParams.Add("Hasta", dHasta); var oGastos = Datos.ExecuteProcedure <pauContaCuentasPorSemana_Result>("pauContaCuentasPorSemana", oParams); var oGastosSem = ContaProc.GastosSemanalizados(oGastos, Util.FechaHora(this.dgvDatos.Columns[this.dgvDatos.Columns.Count - 1].Name)); oGastosSem = oGastosSem.Where(c => c.Semana >= dDesdeSemUno) .GroupBy(c => new { c.Semana }).Select(c => new ContaProc.GastoSem() { Semana = c.Key.Semana, Importe = c.Sum(s => s.Importe) }).ToList(); mTotal += oGastosSem.Sum(c => c.Importe); mPromedio += oGastosSem.Average(c => c.Importe); // Se agrega la fila de los Gastos iFila = this.dgvDatos.Rows.Add("Gastos", oGastosSem.Sum(c => c.Importe), oGastosSem.Average(c => c.Importe)); foreach (var oReg in oGastosSem) { string sSemana = oReg.Semana.ToShortDateString(); this.dgvDatos[sSemana, iFila].Value = (Util.Decimal(this.dgvDatos[sSemana, iFila].Value) + oReg.Importe); this.dgvDatos[sSemana, iFilaEgresos].Value = (Util.Decimal(this.dgvDatos[sSemana, iFilaEgresos].Value) + oReg.Importe); } // Para las compras var oCompras = Datos.GetListOf <ProveedoresPolizasDetalleAvanzadoView>(c => c.Fecha >= dDesdeSemUno && c.Fecha < dHastaMas1 && (c.OrigenID == Cat.OrigenesPagosAProveedores.PagoDirecto || c.OrigenID == Cat.OrigenesPagosAProveedores.PagoDeCaja)) .GroupBy(c => new { Semana = UtilTheos.InicioSemanaSabAVie(c.Fecha.Valor()) }) .Select(c => new { c.Key.Semana, Importe = c.Sum(s => s.Subtotal) }) .OrderBy(c => c.Semana); mTotal += oCompras.Sum(c => c.Importe); mPromedioAct = (oCompras.Count() > 0 ? oCompras.Average(c => c.Importe) : 0); mPromedio += mPromedioAct; // Se agrega la fila de compras iFila = this.dgvDatos.Rows.Add("Compras", oCompras.Sum(c => c.Importe), mPromedioAct); foreach (var oReg in oCompras) { string sSemana = oReg.Semana.ToShortDateString(); this.dgvDatos[sSemana, iFila].Value = (Util.Decimal(this.dgvDatos[sSemana, iFila].Value) + oReg.Importe); this.dgvDatos[sSemana, iFilaEgresos].Value = (Util.Decimal(this.dgvDatos[sSemana, iFilaEgresos].Value) + oReg.Importe); } // Para las deudas var oDeudas = oReinversiones.Where(c => c.ContaCuentaDeMayorID == Cat.ContaCuentasDeMayor.CuentasPorPagarLargoPlazo || c.ContaCuentaDeMayorID == Cat.ContaCuentasDeMayor.CuentasPorPagarCortoPlazo || c.ContaCuentaDeMayorID == Cat.ContaCuentasDeMayor.AcreedoresDiversos) .GroupBy(c => UtilTheos.InicioSemanaSabAVie(c.FechaPoliza.Valor())) .Select(c => new { Semana = c.Key, Importe = c.Sum(s => s.Cargo) }); mTotal += oDeudas.Sum(c => c.Importe); mPromedioAct = (oDeudas.Count() > 0 ? oDeudas.Average(c => c.Importe) : 0); mPromedio += mPromedioAct; // Se agrega la fila de deudas iFila = this.dgvDatos.Rows.Add("Deudas", oDeudas.Sum(c => c.Importe), mPromedioAct); foreach (var oReg in oDeudas) { string sSemana = oReg.Semana.ToShortDateString(); this.dgvDatos[sSemana, iFila].Value = (Util.Decimal(this.dgvDatos[sSemana, iFila].Value) + oReg.Importe); this.dgvDatos[sSemana, iFilaEgresos].Value = (Util.Decimal(this.dgvDatos[sSemana, iFilaEgresos].Value) + oReg.Importe); } // Para las inversiones var oInversiones = oReinversiones.Where(c => c.ContaSubcuentaID == Cat.ContaSubcuentas.ActivoFijo) .GroupBy(c => UtilTheos.InicioSemanaSabAVie(c.FechaPoliza.Valor())) .Select(c => new { Semana = c.Key, Importe = c.Sum(s => s.Cargo) }); mTotal += oInversiones.Sum(c => c.Importe); mPromedioAct = (oInversiones.Count() > 0 ? oInversiones.Average(c => c.Importe) : 0); mPromedio += mPromedioAct; // Se agrega la fila de deudas iFila = this.dgvDatos.Rows.Add("Inversiones", oInversiones.Sum(c => c.Importe), mPromedioAct); foreach (var oReg in oInversiones) { string sSemana = oReg.Semana.ToShortDateString(); this.dgvDatos[sSemana, iFila].Value = (Util.Decimal(this.dgvDatos[sSemana, iFila].Value) + oReg.Importe); this.dgvDatos[sSemana, iFilaEgresos].Value = (Util.Decimal(this.dgvDatos[sSemana, iFilaEgresos].Value) + oReg.Importe); } // Para lo de Isidro y Don Isidro var oGastosSemEsp = ContaProc.GastosSemanalizados(Datos.GetListOf <ContaEgresosDevengadoEspecialCuentasView>(c => c.Fecha >= dDesdeSemUno && c.Fecha < dHastaMas1) , Util.FechaHora(this.dgvDatos.Columns[this.dgvDatos.Columns.Count - 1].Name)); oGastosSemEsp = oGastosSemEsp.Where(c => c.Semana >= dDesdeSemUno).ToList(); mTotal += oGastosSemEsp.Sum(c => c.Importe); mPromedioAct = (oGastosSemEsp.Count() > 0 ? oGastosSemEsp.Average(c => c.Importe) : 0); mPromedio += mPromedioAct; // Se agregan las filas string sDuenio = ""; foreach (var oReg in oGastosSemEsp) { if (sDuenio != oReg.Grupo) { sDuenio = oReg.Grupo; iFila = this.dgvDatos.Rows.Add(sDuenio, oGastosSemEsp.Where(c => c.Grupo == sDuenio).Sum(c => c.Importe) , oGastosSemEsp.Where(c => c.Grupo == sDuenio).Average(c => c.Importe)); } string sSemana = oReg.Semana.ToShortDateString(); this.dgvDatos[sSemana, iFila].Value = (Util.Decimal(this.dgvDatos[sSemana, iFila].Value) + oReg.Importe); this.dgvDatos[sSemana, iFilaEgresos].Value = (Util.Decimal(this.dgvDatos[sSemana, iFilaEgresos].Value) + oReg.Importe); } // Se llenan los totales de egresos this.dgvDatos["Total", iFilaEgresos].Value = mTotal; this.dgvDatos["Promedio", iFilaEgresos].Value = (mPromedio / 2); // Ajuste especial para el año 2015, se quitan los datos antes del 01 de Julio if (dDesde.Year == 2015) { DateTime dInicio = new DateTime(2015, 6, 1); foreach (DataGridViewRow oFila in this.dgvDatos.Rows) { mPromedio = 0; for (int iCol = this.iColumnasFijas; iCol < this.dgvDatos.Columns.Count; iCol++) { DateTime dSem = Util.FechaHora(this.dgvDatos.Columns[iCol].Name); oFila.Cells["Total"].Value = 0; if (dSem >= dInicio) { mPromedio++; oFila.Cells["Total"].Value = (Util.Decimal(oFila.Cells["Total"].Value) + Util.Decimal(oFila.Cells[iCol].Value)); } else { oFila.Cells[iCol].Value = null; } } oFila.Cells["Promedio"].Value = (Util.Decimal(oFila.Cells["Total"].Value) / mPromedio); } } // Se agrega el saldo final int iFilaSaldo = this.dgvDatos.Rows.Add("= Saldo final"); this.dgvDatos.Rows[iFilaSaldo].DefaultCellStyle.Font = oFuenteT; foreach (DataGridViewColumn oCol in this.dgvDatos.Columns) { if (oCol.Index == 0) { continue; } // Se modifica el saldo inicial de la semana actual, y se suma a la fila de ingresos if (oCol.Index >= this.iColumnasFijas) { this.dgvDatos[oCol.Index, iFilaIngresos].Value = ( Util.Decimal(this.dgvDatos[oCol.Index, iFilaIngresos].Value) + Util.Decimal(this.dgvDatos[oCol.Index, iFilaSaldoInicial].Value) ); } decimal mSaldo = ( Util.Decimal(this.dgvDatos[oCol.Index, iFilaIngresos].Value) - Util.Decimal(this.dgvDatos[oCol.Index, iFilaEgresos].Value) ); this.dgvDatos[oCol.Index, iFilaSaldo].Value = mSaldo; // Se llena el saldo inicial de la siguiente semana, si hay if (oCol.Index >= this.iColumnasFijas && oCol.Index < (this.dgvDatos.Columns.Count - 1)) { this.dgvDatos[oCol.Index + 1, iFilaSaldoInicial].Value = mSaldo; } } // Se llena la gráfica, en base al grid ya cargado for (int iCol = this.iColumnasFijas; iCol < this.dgvDatos.Columns.Count; iCol++) { this.chrPorSemana.Series["Ventas"].Points.AddY(Util.Decimal(this.dgvDatos[iCol, iFilaIngresos + 1].Value)); this.chrPorSemana.Series["Prestamos"].Points.AddY(Util.Decimal(this.dgvDatos[iCol, iFilaIngresos + 2].Value)); this.chrPorSemana.Series["Gastos"].Points.AddY(Util.Decimal(this.dgvDatos[iCol, iFilaEgresos + 1].Value)); this.chrPorSemana.Series["Compras"].Points.AddY(Util.Decimal(this.dgvDatos[iCol, iFilaEgresos + 2].Value)); this.chrPorSemana.Series["Deudas"].Points.AddY(Util.Decimal(this.dgvDatos[iCol, iFilaEgresos + 3].Value)); this.chrPorSemana.Series["Inversiones"].Points.AddY(Util.Decimal(this.dgvDatos[iCol, iFilaEgresos + 4].Value)); if (this.dgvDatos.Rows.Count > 10) { this.chrPorSemana.Series["Isidro"].Points.AddY(Util.Decimal(this.dgvDatos[iCol, iFilaEgresos + 5].Value)); this.chrPorSemana.Series["DonIsidro"].Points.AddY(Util.Decimal(this.dgvDatos[iCol, iFilaEgresos + 6].Value)); } } Cargando.Cerrar(); }
private void enviarBtn_Click(object sender, EventArgs e) { // ver comentario en contacto_new_update.cs respecto de la expresion regular Regex reg = new Regex(@"^[^ /?@\x00-\x1f()<>]+@([^. /?@\x00-\x1f()<>]+\.)*[a-zA-Z]{2,}\.?$"); if (!reg.IsMatch(toTxt.Text)) { var form = new frmAlert(this, "Ingresar destinatario", "Debe agregar un destinatario correcto en el campo Para", "close"); DialogResult vr = form.ShowDialog(this); return; } Cargando carg = new Cargando(); carg.Ejecutar(); To = toTxt.Text; Subject = asuntoTxt.Text; Body = cuerpoTxt.Text + "<br><br>" + webBrowser.DocumentText; mail = new MailMessage(); mail.To.Add(new MailAddress(this.To)); mail.From = new MailAddress(G.user.Mail, G.user.Mail); mail.Subject = Subject; mail.Body = Body; mail.IsBodyHtml = true; SmtpClient client = new SmtpClient(G.user.SMTPserver, G.user.SMTPport); client.Credentials = new System.Net.NetworkCredential(G.user.Mail, G.user.Password); client.EnableSsl = G.user.SMTPssl; try { client.Send(mail); if (contactoID > 0) { G.user.contacto_enviado(contactoID); } if (asuntoID > 0) { G.user.asunto_usado(asuntoID); } if (mensajeID > 0) { G.user.mensaje_usado(mensajeID); } mail_enviado mailEnviado = new mail_enviado(); mailEnviado.__para = To; mailEnviado.__asunto = Subject; mailEnviado.__mensaje = Body; G.user.guardarMailEnviado(mailEnviado); carg.Detener(); var form2 = new frmAlert(this, "Mail enviado", "El mail ha sido enviado exitosamente", "close"); form2.Show(); } catch { carg.Detener(); var form2 = new frmAlert(this, "Error", "Hubo un inconveniente técnico. \nVuelva a intentarlo más tarde.", "close"); form2.Show(); } }
private void GuardarAsignacion() { // Se valida que la línea quede completa var oSucPartes = new Dictionary <string, int>(); var oSucCant = new Dictionary <string, int>(); foreach (DataGridViewRow oFila in this.dgvAsignacionManual.Rows) { string sSucursal = Util.Cadena(oFila.Cells["Asignacion_Sucursal"].Value); oSucPartes[sSucursal] = Util.Entero(oFila.Cells["Asignacion_Partes"].Value); if (!oSucCant.ContainsKey(sSucursal)) { oSucCant.Add(sSucursal, 0); } oSucCant[sSucursal] += Util.Entero(oFila.Cells["Asignacion_Cantidad"].Value); } this.ctlError.LimpiarErrores(); string sError = ""; foreach (var oSucursal in oSucPartes) { if (oSucCant[oSucursal.Key] != oSucursal.Value) { sError += string.Format("La cantidad asignada a la sucursal {0}, es diferente a las partes existentes para el conteo.\n", oSucursal.Key); } } if (sError != "") { this.ctlError.PonerError(this.btnAsignar, sError, ErrorIconAlignment.MiddleLeft); return; } this.btnAsignar.Enabled = false; Cargando.Mostrar(); // Se procede a guardar los datos int iLineaID = Util.Entero(this.cmbLinea.SelectedValue); var oAvManual = Datos.GetListOf <InventarioLinea>(c => c.AvManual > 0); int iAvManual = (oAvManual.Count > 0 ? (oAvManual.Max(c => c.AvManual).Valor() + 1) : 1); var oPartes = Datos.GetListOf <Parte>(c => c.LineaID == iLineaID && c.Estatus); int iParte = 0, iSucursalID = 0, iCantidad, iUsuarioID; var oInvLineas = new Dictionary <int, int>(); DateTime dAhora = DateTime.Now; foreach (DataGridViewRow oFila in this.dgvAsignacionManual.Rows) { if (Util.Entero(oFila.Cells["Asignacion_SucursalID"].Value) != iSucursalID) { iSucursalID = Util.Entero(oFila.Cells["Asignacion_SucursalID"].Value); iParte = 0; } iCantidad = Util.Entero(oFila.Cells["Asignacion_Cantidad"].Value); iUsuarioID = Util.Entero(oFila.Cells["Asignacion_UsuarioID"].Value); while (iCantidad > 0 && iParte < oPartes.Count) { int iParteID = oPartes[iParte++].ParteID; // Se valida la existencia var oParteEx = Datos.GetEntity <ParteExistencia>(c => c.ParteID == iParteID && c.SucursalID == iSucursalID && c.Estatus); if (oParteEx.Existencia <= 0) { continue; } // Se agrega el InventarioLinea, si no se ha agregado if (!oInvLineas.ContainsKey(iSucursalID)) { var oInvLinea = new InventarioLinea() { SucursalID = iSucursalID , LineaID = iLineaID , EstatusGenericoID = Cat.EstatusGenericos.EnCurso , FechaIniciado = dAhora , AvManual = iAvManual }; Datos.Guardar <InventarioLinea>(oInvLinea); oInvLineas.Add(iSucursalID, oInvLinea.InventarioLineaID); } // Se agrega al conteo var oConteo = new InventarioConteo() { InventarioLineaID = oInvLineas[iSucursalID] , Dia = dAhora , ConteoUsuarioID = iUsuarioID , ParteID = iParteID }; Datos.Guardar <InventarioConteo>(oConteo); // iCantidad--; } } Cargando.Cerrar(); }
private void LlenarMovimientosCuenta(int iCuentaID) { Cargando.Mostrar(); DateTime dDesde = this.dtpDesde.Value.Date; DateTime dHasta = this.dtpHasta.Value.Date; int iSucursalID = Util.Entero(this.cmbSucursal.SelectedValue); // var oMovs = General.GetListOf<ContaPolizasDetalleAvanzadoView>(c => // c.ContaCuentaAuxiliarID == iCuentaID && (c.FechaPoliza >= dDesde && c.FechaPoliza < dHasta) && (iSucursalID == 0 || c.SucursalID == iSucursalID)) // .OrderBy(c => c.FechaPoliza).ToList(); var oParams = new Dictionary <string, object>(); oParams.Add("CuentaAuxiliarID", iCuentaID); oParams.Add("Desde", dDesde); oParams.Add("Hasta", dHasta); if (iSucursalID > 0) { oParams.Add("SucursalID", iSucursalID); } var oMovs = Datos.ExecuteProcedure <pauContaCuentaAuxiliarPolizas_Result>("pauContaCuentaAuxiliarPolizas", oParams); // Se llena a partir de un DataTable this.bdsDetalle = new BindingSource(); this.bdsDetalle.DataSource = Util.ListaEntityADataTable <pauContaCuentaAuxiliarPolizas_Result>(oMovs); this.dgvDetalle.Columns.Clear(); this.dgvDetalle.DataSource = null; this.dgvDetalle.DataSource = this.bdsDetalle; if (oMovs.Count <= 0) { return; } // Se configuran las columnas this.dgvDetalle.OcultarColumnas("ContaPolizaDetalleID", "FueManual", "Error"); this.dgvDetalle.Columns["ContaPolizaID"].HeaderText = "Póliza"; this.dgvDetalle.Columns["Concepto"].HeaderText = "Observación"; // Se agrega la columna de "Manual" this.dgvDetalle.Columns.Add("Manual", "Manual"); // // this.dgvDetalle.AutoResizeColumns(); this.dgvDetalle.Columns["Fecha"].Width = 136; this.dgvDetalle.Columns["ContaPolizaID"].Width = 50; this.dgvDetalle.Columns["Referencia"].Width = 80; this.dgvDetalle.Columns["Sucursal"].Width = 80; this.dgvDetalle.Columns["Concepto"].Width = 280; this.dgvDetalle.Columns["Manual"].Width = 50; this.dgvDetalle.Columns["Cargo"].FormatoMoneda(); this.dgvDetalle.Columns["Abono"].FormatoMoneda(); // Se marcan en rojo las que tengan error this.MovimientosCuentaFormatoAdicional(); /* this.dgvDetalle.Rows.Clear(); * foreach (var oMov in oMovs) * { * int iFila = this.dgvDetalle.Rows.Add(oMov.ContaPolizaDetalleID, oMov.FechaPoliza, oMov.ContaPolizaID.ToString(), oMov.Referencia * , oMov.Cargo, oMov.Abono, oMov.Sucursal, oMov.ConceptoPoliza); * // Se aplica el color de error, cuando hay * if (oMov.Error.Valor()) * this.dgvDetalle.Rows[iFila].DefaultCellStyle.ForeColor = Color.Red; * } */ // Si existían un filtro previamente, se ejecuta nuevamente if (this.txtBusquedaPolizaDet.Text != "") { this.txtBusquedaPolizaDet_TextChanged(this, null); } Cargando.Cerrar(); }
protected override bool AccionGuardar() { // Se valida if (!this.Validar()) { return(false); } int iUsuarioID = Util.Entero(this.cmbUsuario.SelectedValue); if (iUsuarioID <= 0) { return(false); } Cargando.Mostrar(); UsuarioNominaOficial oReg; foreach (DataGridViewRow oFila in this.dgvDatos.Rows) { if (oFila.IsNewRow) { continue; } int iId = this.dgvDatos.ObtenerId(oFila); int iCambio = this.dgvDatos.ObtenerIdCambio(oFila); switch (iCambio) { case Cat.TiposDeAfectacion.Agregar: case Cat.TiposDeAfectacion.Modificar: if (iCambio == Cat.TiposDeAfectacion.Agregar) { oReg = new UsuarioNominaOficial() { IdUsuario = iUsuarioID } } ; else { oReg = Datos.GetEntity <UsuarioNominaOficial>(c => c.UsuarioNominaOficialID == iId); } // Se llenan los datos oReg.ContaCuentaDeMayorID = Util.Entero(oFila.Cells["ContaCuentaDeMayorID"].Value); oReg.Importe = Util.Decimal(oFila.Cells["Importe"].Value); Datos.Guardar <UsuarioNominaOficial>(oReg); break; case Cat.TiposDeAfectacion.Borrar: oReg = Datos.GetEntity <UsuarioNominaOficial>(c => c.UsuarioNominaOficialID == iId); Datos.Eliminar <UsuarioNominaOficial>(oReg); break; } } // Se guarda el dato de Sueldo Fijo var oNomina = Datos.GetEntity <UsuarioNomina>(c => c.IdUsuario == iUsuarioID); if (oNomina == null) { oNomina = new UsuarioNomina() { IdUsuario = iUsuarioID } } ; oNomina.SucursalID = Util.Entero(this.cmbSucursal.SelectedValue); oNomina.SueldoFijo = Util.Decimal(this.txtSueldoFijo.Text); Datos.Guardar <UsuarioNomina>(oNomina); Cargando.Cerrar(); this.CargarDatos(); return(true); }
public void LlenarArbol() { Cargando.Mostrar(); // Se guarda la selección actual var oRutaNodoAct = new List <int>(); var oNodo = this.tgvCuentas.CurrentNode; while (oNodo != null && oNodo.Level > 0) { oRutaNodoAct.Insert(0, oNodo.Index); oNodo = oNodo.Parent; } // Se configuran los parámetros var oParams = new Dictionary <string, object>(); oParams.Add("Desde", this.dtpDesde.Value); oParams.Add("Hasta", this.dtpHasta.Value); // Se llenan los datos var oDatos = Datos.ExecuteProcedure <pauContaCuentasPolizas_Result>("pauContaCuentasPolizas", oParams); TreeGridNode oNodoCuenta = null, oNodoSubcuenta = null, oNodoCuentaDeMayor = null; string sCuenta = "", sSubcuenta = "", sCuentaDeMayor = ""; TreeGridNode oNodoClientes = null; this.tgvCuentas.Nodes.Clear(); this.oIndiceCuentas.Clear(); foreach (var oCuenta in oDatos) { // Nodo de Cuenta if (oCuenta.Cuenta != sCuenta) { sCuenta = oCuenta.Cuenta; oNodoCuenta = this.tgvCuentas.Nodes.Add(oCuenta.ContaCuentaID, NivelesArbol.Cuenta, sCuenta); oNodoCuenta.DefaultCellStyle.Font = new Font(this.tgvCuentas.Font.FontFamily, 10); this.oIndiceCuentas.Add(new ContaModelos.IndiceCuentasContables() { Cuenta = sCuenta.ToLower(), Nivel = 1, IndiceCuenta = oNodoCuenta.Index }); sSubcuenta = ""; } // Nodo de Subcuenta if (oCuenta.Subcuenta == null) { continue; } else if (oCuenta.Subcuenta != sSubcuenta) { sSubcuenta = oCuenta.Subcuenta; oNodoSubcuenta = oNodoCuenta.Nodes.Add(oCuenta.ContaSubcuentaID, NivelesArbol.Subcuenta, sSubcuenta); oNodoSubcuenta.DefaultCellStyle.Font = new Font(this.tgvCuentas.Font.FontFamily, 9); this.oIndiceCuentas.Add(new ContaModelos.IndiceCuentasContables() { Cuenta = sSubcuenta.ToLower(), Nivel = 2 , IndiceCuenta = oNodoCuenta.Index, IndiceSubcuenta = oNodoSubcuenta.Index }); sCuentaDeMayor = ""; } // Nodo de Cuenta de mayor if (oCuenta.CuentaDeMayor == null) { continue; } else if (oCuenta.CuentaDeMayor != sCuentaDeMayor) { sCuentaDeMayor = oCuenta.CuentaDeMayor; oNodoCuentaDeMayor = oNodoSubcuenta.Nodes.Add(oCuenta.ContaCuentaDeMayorID, NivelesArbol.CuentaDeMayor, sCuentaDeMayor); oNodoCuentaDeMayor.DefaultCellStyle.Font = new Font(this.tgvCuentas.Font, FontStyle.Bold); this.oIndiceCuentas.Add(new ContaModelos.IndiceCuentasContables() { Cuenta = sCuentaDeMayor.ToLower(), Nivel = 3 , IndiceCuenta = oNodoCuenta.Index, IndiceSubcuenta = oNodoSubcuenta.Index, IndiceCuentaDeMayor = oNodoCuentaDeMayor.Index }); if (oCuenta.ContaCuentaDeMayorID == Cat.ContaCuentasDeMayor.Clientes) { oNodoClientes = oNodoCuentaDeMayor; } } // Se agrega la cuenta auxiliar if (oCuenta.CuentaAuxiliar == null) { continue; } var oNodoCuentaAux = oNodoCuentaDeMayor.Nodes.Add( oCuenta.ContaCuentaAuxiliarID, NivelesArbol.CuentaAuxiliar, oCuenta.CuentaAuxiliar, oCuenta.Total, oCuenta.Matriz, oCuenta.Suc02, oCuenta.Suc03 ); this.oIndiceCuentas.Add(new ContaModelos.IndiceCuentasContables() { Cuenta = oCuenta.CuentaAuxiliar.ToLower(), Nivel = 4 , IndiceCuenta = oNodoCuenta.Index, IndiceSubcuenta = oNodoSubcuenta.Index, IndiceCuentaDeMayor = oNodoCuentaDeMayor.Index , IndiceCuentaAuxiliar = oNodoCuentaAux.Index }); // Se marca con rojo si hay error if (oCuenta.Error) { oNodoCuentaAux.DefaultCellStyle.ForeColor = Color.Red; } // Se agregan totales para los niveles superiores decimal mImporte = 0; for (int iCol = ColumnasArbol.Total; iCol < this.tgvCuentas.Columns.Count; iCol++) { switch (iCol) { case 3: mImporte = oCuenta.Total.Valor(); break; case 4: mImporte = oCuenta.Matriz.Valor(); break; case 5: mImporte = oCuenta.Suc02.Valor(); break; case 6: mImporte = oCuenta.Suc03.Valor(); break; } oNodoCuentaDeMayor.Cells[iCol].Value = (Util.Decimal(oNodoCuentaDeMayor.Cells[iCol].Value) + mImporte); oNodoSubcuenta.Cells[iCol].Value = (Util.Decimal(oNodoSubcuenta.Cells[iCol].Value) + mImporte); oNodoCuenta.Cells[iCol].Value = (Util.Decimal(oNodoCuenta.Cells[iCol].Value) + mImporte); } } // Se aplica el formato y el color foreach (var oNodCuenta in this.tgvCuentas.Nodes) { oNodCuenta.Expand(); foreach (var oNodSubcuenta in oNodCuenta.Nodes) { oNodSubcuenta.Expand(); foreach (var oNodCuentaDeMayor in oNodSubcuenta.Nodes) { foreach (var oNodCuentaAuxiliar in oNodCuentaDeMayor.Nodes) { // this.AplicarColor(oNodCuentaAuxiliar); this.FormatoColumnasImporte(oNodCuentaAuxiliar); // Se marcan los niveles superiores con error, si aplica if (oNodCuentaAuxiliar.DefaultCellStyle.ForeColor == Color.Red) { oNodCuentaDeMayor.DefaultCellStyle.ForeColor = Color.Red; oNodSubcuenta.DefaultCellStyle.ForeColor = Color.Red; oNodCuenta.DefaultCellStyle.ForeColor = Color.Red; } } // this.AplicarColor(oNodCuentaDeMayor); this.FormatoColumnasImporte(oNodCuentaDeMayor); oNodCuentaDeMayor.Collapse(); } // this.AplicarColor(oNodSubcuenta); this.FormatoColumnasImporte(oNodSubcuenta); } // this.AplicarColor(oNodCuenta); this.FormatoColumnasImporte(oNodCuenta); } // Se marcan las diferencias en adeudos, en la cuenta de Clientes, /* if (oNodoClientes != null) * { * foreach (var oNodoCliente in oNodoClientes.Nodes) * { * int iCuentaAuxID = Util.ConvertirEntero(oNodoCliente.Cells[ColumnasArbol.Id].Value); * var oCuentaAuxCliente = General.GetEntity<ContaCuentaAuxiliar>(c => c.ContaCuentaAuxiliarID == iCuentaAuxID); * if (oCuentaAuxCliente == null || !oCuentaAuxCliente.RelacionID.HasValue) * { * oNodoCliente.DefaultCellStyle.ForeColor = Color.Red; * } * else * { * int iClienteID = oCuentaAuxCliente.RelacionID.Valor(); * var oClienteAd = General.GetEntity<ClientesCreditoView>(c => c.ClienteID == iClienteID); * decimal mTotal = Util.ConvertirDecimal(oNodoCliente.Cells[ColumnasArbol.Total].Value); * if (mTotal != oClienteAd.AdeudoVencido.Valor()) * oNodoCliente.DefaultCellStyle.ForeColor = Color.Blue; * } * } * } */ // Se selecciona el nodo previamente seleccionado oNodo = (oRutaNodoAct.Count > 0 ? this.tgvCuentas.Nodes[oRutaNodoAct[0]] : null); for (int iNodo = 1; iNodo < oRutaNodoAct.Count; iNodo++) { oNodo.Expand(); oNodo = oNodo.Nodes[oRutaNodoAct[iNodo]]; this.tgvCuentas.CurrentCell = oNodo.Cells["Cuentas_Cuenta"]; } Cargando.Cerrar(); }
private void CargarClientes() { Cargando.Mostrar(); // Se cargan los datos base var oParams = this.ObtenerParametros(); this.oDatos = Datos.ExecuteProcedure <pauCuadroDeControlGeneralNuevo_Result>("pauCuadroDeControlGeneral", oParams); // Se obtienen los datos para partes this.oDatosPartes = Datos.ExecuteProcedure <pauCuadroDeControlPartes_Result>("pauCuadroDeControlPartes", oParams); // Se obtienen los datos por año oParams.Remove("Desde"); oParams.Remove("Hasta"); this.oDatosPorAnio = Datos.ExecuteProcedure <pauCuadroDeControlPorAnio_Result>("pauCuadroDeControlPorAnio", oParams); // Se obtienen los datos agrupados por clientes y semanas, para marcar en rojo var oCliSem = this.ObtenerClientesSemanas(this.oDatos).OrderByDescending(c => c.Semana).ToList(); var oCliProm = oCliSem.GroupBy(c => c.ClienteID).Select(c => new { ClienteID = c.Key, Promedio = c.Average(s => s.Actual) }).ToList(); // Se llena el grid de clientes var oPorCliente = this.AgruparPorEnteroCadena(this.oDatos.GroupBy(g => new EnteroCadenaAgrupar() { Entero = g.ClienteID, Cadena = g.Cliente })) .OrderByDescending(c => c.Actual); decimal mTotal = (oPorCliente.Count() > 0 ? oPorCliente.Sum(c => c.Actual) : 0); this.dgvClientes.Rows.Clear(); foreach (var oReg in oPorCliente) { int iFila = this.dgvClientes.Rows.Add(oReg.Llave, oReg.Cadena, oReg.Actual, Util.DividirONull(oReg.Actual, oReg.Anterior) , Util.DividirONull(oReg.Actual, mTotal)); // Se obtiene un el dato de si tiene más de 2 semanas abajo del promedio, para marcarlo en rojo decimal mPromedio = oCliProm.FirstOrDefault(c => c.ClienteID == oReg.Llave).Promedio; if (oCliSem.Where(c => c.ClienteID == oReg.Llave).Take(3).Any(c => c.Actual < mPromedio)) { this.dgvClientes.Rows[iFila].DefaultCellStyle.ForeColor = Color.Black; } } int iTotalClientes = this.dgvClientes.Rows.Count; // Se llena el dato de acumulado decimal mPorAcum = 0; foreach (DataGridViewRow oFila in this.dgvClientes.Rows) { mPorAcum += Util.Decimal(oFila.Cells["cli_Porcentaje"].Value); oFila.Cells["cli_Acumulado"].Value = mPorAcum; // Se valida si se pasa del máximo, para ocultarlo if ((mPorAcum * 100) > this.nudAcumuladoMostrar.Value) { oFila.Visible = false; iTotalClientes--; } } // Para configurar las columnas de los grids this.lblClientes.Text = iTotalClientes.ToString(Con.Formatos.Entero); this.AplicarFormatoColumnas(); Cargando.Cerrar(); }
private void GuardarCaracteristicas() { Cargando.Mostrar(); LineaCaracteristica oReg; foreach (DataGridViewRow oFila in this.dgvCaracteristicas.Rows) { if (oFila.IsNewRow) { continue; } int iId = this.dgvCaracteristicas.ObtenerId(oFila); int iCambio = this.dgvCaracteristicas.ObtenerIdCambio(oFila); switch (iCambio) { case Cat.TiposDeAfectacion.Agregar: case Cat.TiposDeAfectacion.Modificar: if (iCambio == Cat.TiposDeAfectacion.Agregar) { oReg = new LineaCaracteristica(); } else { oReg = Datos.GetEntity <LineaCaracteristica>(c => c.LineaCaracteristicaID == iId); } // Se llenan los datos oReg.LineaID = this.Linea.LineaID; oReg.CaracteristicaID = Util.Entero(oFila.Cells["colCaracteristicaID"].Value); // Se valida que no exista ya if (iCambio == Cat.TiposDeAfectacion.Agregar) { if (Datos.Exists <LineaCaracteristica>(c => c.LineaID == this.Linea.LineaID && c.CaracteristicaID == oReg.CaracteristicaID)) { continue; } } // Se verifican los cambios a la característica en sí var oCaracteristica = Datos.GetEntity <Caracteristica>(c => c.CaracteristicaID == oReg.CaracteristicaID); if (oCaracteristica == null) { oCaracteristica = new Caracteristica() { Caracteristica1 = Util.Cadena((oFila.Cells["colCaracteristicaID"] as DataGridViewComboBoxCell).FormattedValue) } } ; // Se valida si cambiaron las opciones bool bOpcionEnUso = false; string sOpciones = Util.Cadena(oFila.Cells["colMultipleOpciones"].Value); if (oCaracteristica.MultipleOpciones != null && sOpciones != oCaracteristica.MultipleOpciones) { var oOpcionesAnt = oCaracteristica.MultipleOpciones.Split(','); var oOpciones = sOpciones.Split(','); var oDif = oOpcionesAnt.Except(oOpciones); foreach (var sOpcion in oDif) { if (Datos.Exists <ParteCaracteristica>(c => c.CaracteristicaID == oReg.CaracteristicaID && c.Valor == sOpcion)) { UtilLocal.MensajeError("Alguna de las características removidas está siendo usada. No se puede guardar."); bOpcionEnUso = true; break; } } } if (!bOpcionEnUso) { // oCaracteristica.MultipleOpciones = sOpciones; oCaracteristica.Multiple = (oCaracteristica.MultipleOpciones != ""); Datos.Guardar <Caracteristica>(oCaracteristica); // Se guarda oReg.CaracteristicaID = oCaracteristica.CaracteristicaID; Datos.Guardar <LineaCaracteristica>(oReg); } break; case Cat.TiposDeAfectacion.Borrar: oReg = Datos.GetEntity <LineaCaracteristica>(c => c.LineaCaracteristicaID == iId); Datos.Eliminar <LineaCaracteristica>(oReg); break; } } Cargando.Cerrar(); // this.CargarCaracteristicas(); }