private void button1_Click(object sender, EventArgs e) { if (dataGridView_vencimientos.SelectedRows[0].Cells[4].Value.ToString() == "0,00" && id_entidad_nuevo != "0") { String fechaHoy = (Convert.ToDateTime(DateTime.Now)).ToString("yyyy-MM-dd"); String idCuentaCom = Logica.FuncionesTesoreria.CuentaCompesaciones(idComunidad); if (idCuentaCom == "") { MessageBox.Show("Debes crear una cuenta de compesaciones para la comunidad"); return; } //BUSCO EJERCICIO String IdEjercicio = Logica.FuncionesTesoreria.ejercicioActivo(idComunidad, fechaHoy); //CREO EL MOVIMIENTO int idMov = Logica.FuncionesTesoreria.CreaMovimiento(IdEjercicio, idCuentaCom, "8", dataGridView_vencimientos.SelectedRows[0].Cells[6].Value.ToString(), fechaHoy, "ABONO"); //CREO EL DETALLE DEL MOVIMIENTO Logica.FuncionesTesoreria.CreaDetalleMovimiento(idMov.ToString(), dataGridView_vencimientos.SelectedRows[0].Cells[0].Value.ToString(), dataGridView_vencimientos.SelectedRows[0].Cells[3].Value.ToString().Replace(",", ".")); //CREO EL DETALLE DE ABONO int idDetOpAbono = Logica.FuncionesTesoreria.CreoVencimientoID(IdOp_pasada, dataGridView_vencimientos.SelectedRows[0].Cells[6].Value.ToString(), fechaHoy, "-" + dataGridView_vencimientos.SelectedRows[0].Cells[3].Value.ToString().Replace(",", "."), "-" + dataGridView_vencimientos.SelectedRows[0].Cells[3].Value.ToString().Replace(",", ".")); //CREO RECIBO ABONO int num_recibo = Logica.FuncionesTesoreria.CreoReciboID(idComunidad, dataGridView_vencimientos.SelectedRows[0].Cells[6].Value.ToString(), fechaHoy, "-" + dataGridView_vencimientos.SelectedRows[0].Cells[3].Value.ToString().Replace(",", "."), "-" + dataGridView_vencimientos.SelectedRows[0].Cells[3].Value.ToString().Replace(",", "."), "Abono " + dataGridView_vencimientos.SelectedRows[0].Cells[7].Value.ToString()); //ACTUALIZO EL IDRECIBO AL VENCIMIENTO String strActVtosRbo = "UPDATE com_opdetalles SET com_opdetalles.IdRecibo = " + num_recibo + " WHERE (((com_opdetalles.IdOpDet)=" + idDetOpAbono + "));"; Persistencia.SentenciasSQL.InsertarGenerico(strActVtosRbo); //CREO EL DETALLE DEL NUEVO COMUNERO int idDetOpRecibo = Logica.FuncionesTesoreria.CreoVencimientoID(IdOp_pasada, id_entidad_nuevo, fechaHoy, dataGridView_vencimientos.SelectedRows[0].Cells[3].Value.ToString().Replace(",", "."), dataGridView_vencimientos.SelectedRows[0].Cells[3].Value.ToString().Replace(",", ".")); //CREO RECIBO ABONO int num_reciboComunero = Logica.FuncionesTesoreria.CreoReciboID(idComunidad, id_entidad_nuevo, fechaHoy, dataGridView_vencimientos.SelectedRows[0].Cells[3].Value.ToString().Replace(",", "."), dataGridView_vencimientos.SelectedRows[0].Cells[3].Value.ToString().Replace(",", "."), dataGridView_vencimientos.SelectedRows[0].Cells[7].Value.ToString()); //ACTUALIZO EL IDRECIBO AL VENCIMIENTO String strActVtosRbo2 = "UPDATE com_opdetalles SET com_opdetalles.IdRecibo = " + num_reciboComunero + " WHERE (((com_opdetalles.IdOpDet)=" + idDetOpRecibo + "));"; Persistencia.SentenciasSQL.InsertarGenerico(strActVtosRbo2); MessageBox.Show("Vencimiento Reasignado"); cargarDatagrid(); FromOperacionesVer nueva = new FromOperacionesVer(IdOp_pasada, 2); nueva.Show(); this.Close(); } else { MessageBox.Show("El vencimiento debe estar completamente pagado. Por ahora"); } }
private void button_70001_Click(object sender, EventArgs e) { String OPCrea = "SELECT IdOpCrea FROM com_operaciones WHERE IdOp = " + id_operacion_cargado; DataTable OPCreaDT = Persistencia.SentenciasSQL.select(OPCrea); if (OPCreaDT.Rows.Count > 0 && OPCreaDT.Rows[0][0].ToString() != "") { FromOperacionesVer nueva = new FromOperacionesVer(OPCreaDT.Rows[0][0].ToString(), 3); nueva.Show(); } }
private void creoOperacion () { String fecha = (Convert.ToDateTime(maskedTextBox_fecha.Text)).ToString("yyyy-MM-dd"); String fecha_actualizacion = (Convert.ToDateTime(DateTime.Now)).ToString("yyyy-MM-dd hh:mm:ss"); //CREO OPERACIÓN String sqlInsertOp = "INSERT INTO com_operaciones (IdComunidad, IdEntidad, IdSubCuenta, IdTipoReparto, Fecha, Descripcion, IdEstado, ImpOp, ImpOpPte, NumMov, Guardada, IdURD, FAct) VALUES (" + id_comunidad + "," + id_entidad_nueva + "," + comboBox_subcuenta.SelectedItem.ToString().Split('-')[0] + ",1,'" + fecha + "','" + textBox_descripcion.Text + "',1," + Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text) + "," + Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text) + ",0,'No'," + Presentacion.Login.getId() + ",'" + fecha_actualizacion + "')"; int op = Persistencia.SentenciasSQL.InsertarGenericoID(sqlInsertOp); String sqlInsertIva = "INSERT INTO com_opdetiva (IdOp, Base, IdIVA, IVA) VALUES (" + op + "," + Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text) + ",1,0)"; Persistencia.SentenciasSQL.InsertarGenerico(sqlInsertIva); String sqlSelectBloqueFondo = (Persistencia.SentenciasSQL.select("SELECT IdBloque FROM com_fondos WHERE IdFondo = " + comboBox_fondos.SelectedValue.ToString())).Rows[0][0].ToString(); String sqlInsertReparto = "INSERT INTO com_opdetbloques (IdOp, IdBloque, Porcentaje, Importe) VALUES (" + op + "," + sqlSelectBloqueFondo + ",1," + Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text) + ")"; Persistencia.SentenciasSQL.InsertarGenerico(sqlInsertReparto); String sqlInsertVencimiento = "INSERT INTO com_opdetalles (IdOp, IdEntidad, Fecha, FechaPrev, Importe, ImpOpDetPte, NumMov, IdEstado) VALUES (" + op + "," + id_entidad_nueva + ",'" + fecha + "','" + fecha + "'," + Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text) + "," + Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text) + ",0,1)"; int opdet = Persistencia.SentenciasSQL.InsertarGenericoID(sqlInsertVencimiento); String sqlInsertDetLiq = "INSERT INTO com_opdetliquidacion (IdOp, IdLiquidacion, Porcentaje, Importe) VALUES (" + op + "," + comboBox_liquidación.SelectedValue.ToString() + ",1," + Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text) + ")"; Persistencia.SentenciasSQL.InsertarGenerico(sqlInsertDetLiq); //COMPRUEBO QUE SI ES DE STOCK, INTRODUZCAN LOS VALORES PERTINENTES. String sqlSelect = "SELECT com_fondos.IdFondo, com_fondos.Stock FROM com_fondos INNER JOIN com_liquidaciones ON com_fondos.IdFondo = com_liquidaciones.IdFondo WHERE com_liquidaciones.IdLiquidacion =" + comboBox_liquidación.SelectedValue.ToString(); DataTable esStock = Persistencia.SentenciasSQL.select(sqlSelect); if (esStock.Rows.Count > 0) { if (esStock.Rows[0][1].ToString() == "True") { FondosForms.FormModificarStock nueva2 = new FondosForms.FormModificarStock(esStock.Rows[0][0].ToString(), "-"); nueva2.Show(); } } int Idrecibo = Logica.FuncionesTesoreria.CreoReciboID(id_comunidad, id_entidad_nueva, fecha, Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text), Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text), textBox_descripcion.Text); Logica.FuncionesTesoreria.ActualizoIdReciboVencimiento(Idrecibo.ToString(), opdet.ToString()); form_anterior.cargardatagrid(); this.Close(); MessageBox.Show("Se ha generado el Recibo y debes informarlo"); FromOperacionesVer nueva = new FromOperacionesVer(op.ToString(), 1, id_comunidad); nueva.Show(); }
private void button1_Click(object sender, EventArgs e) { int numeroOperacion; if (Int32.TryParse(textBox_ver_operacion.Text, out numeroOperacion)) { OperacionesForms.FromOperacionesVer nueva = new OperacionesForms.FromOperacionesVer(id_comunidad_cargado, numeroOperacion.ToString()); try { nueva.Show(); }catch { return; } } else { MessageBox.Show("No existe esa operación"); } }
private void dataGridView_operaciones_DoubleClick(object sender, EventArgs e) { OperacionesForms.FromOperacionesVer nueva = new OperacionesForms.FromOperacionesVer(id_comunidad_cargado, dataGridView_operaciones.SelectedCells[0].Value.ToString()); nueva.Show(); }
private void button_guardar_Click(object sender, EventArgs e) { if (comprobarImporte()) { for (int a = 0; a < dataGridView_liquidacion.Rows.Count; a++) { if (filas_eliminadas.Count > 0) { eliminar_filas(); } if (dataGridView_liquidacion.Rows[a].Cells[3].Value != null && dataGridView_liquidacion.Rows[a].Cells[0].Value != null) { actualizar_filasReparto(dataGridView_liquidacion.Rows[a].Cells[0].Value.ToString(), dataGridView_liquidacion.Rows[a].Cells[4].Value.ToString(), dataGridView_liquidacion.Rows[a].Cells[2].Value.ToString(), dataGridView_liquidacion.Rows[a].Cells[3].Value.ToString()); } else if (dataGridView_liquidacion.Rows[a].Cells[3].Value != null && dataGridView_liquidacion.Rows[a].Cells[0].Value == null) { insertar_filasReparto(dataGridView_liquidacion.Rows[a].Cells[4].Value.ToString(), dataGridView_liquidacion.Rows[a].Cells[2].Value.ToString(), dataGridView_liquidacion.Rows[a].Cells[3].Value.ToString()); } } //Si el Tipo de Reparto es <> 1 - > generar operación de ingreso 7001. La op de ingreso se registra en IdOpCrea //Para cada liquidación, crear operaciones para cada reparto bool varliquidable; String TipoReparto = (Persistencia.SentenciasSQL.select("SELECT IdTipoReparto FROM com_operaciones WHERE IdOp = " + id_operacion_cargado)).Rows[0][0].ToString(); String TipoSubcuenta = (Persistencia.SentenciasSQL.select("SELECT IdSubCuenta FROM com_operaciones WHERE IdOp = " + id_operacion_cargado)).Rows[0][0].ToString(); if ((Convert.ToInt32(TipoSubcuenta) >= 60000 && Convert.ToInt32(TipoSubcuenta) <= 69999) || (Convert.ToInt32(TipoSubcuenta) >= 70100 && Convert.ToInt32(TipoSubcuenta) <= 76900)) { varliquidable = true; } else { varliquidable = false; } if (TipoReparto != "1" && varliquidable) { String varOpCrea = (Persistencia.SentenciasSQL.select("SELECT IdOpCrea FROM com_operaciones WHERE IdOp = " + id_operacion_cargado)).Rows[0][0].ToString(); String sqlBloqsOp = "SELECT com_opdetbloques.IdOp, com_opdetbloques.IdDivision, com_opdetbloques.IdEntidad, com_opdetbloques.Porcentaje From com_opdetbloques WHERE com_opdetbloques.IdOp = " + id_operacion_cargado; DataTable BloqsOp = Persistencia.SentenciasSQL.select(sqlBloqsOp); String sqlLiqsOp = "SELECT com_opdetliquidacion.IdOp, com_opdetliquidacion.IdLiquidacion, com_opdetliquidacion.Porcentaje, com_opdetliquidacion.Importe From com_opdetliquidacion WHERE com_opdetliquidacion.IdOp = " + id_operacion_cargado; DataTable LiqsOp = Persistencia.SentenciasSQL.select(sqlLiqsOp); int TotalLiqs = LiqsOp.Rows.Count; int CuentaLiqs = 1; for (int a = 0; a < LiqsOp.Rows.Count; a++) { for (int b = 0; b < LiqsOp.Rows.Count; b++) { String varImpReparto = (Convert.ToDouble(LiqsOp.Rows[a][3].ToString()) * Convert.ToDouble(LiqsOp.Rows[a][2].ToString())).ToString(); String strCuentaLiqs = CuentaLiqs + "/" + TotalLiqs; if (strCuentaLiqs == "1/1") { strCuentaLiqs = ""; } if (TipoReparto == "2") { Logica.FuncionesTesoreria.CreaOP_PartDiv(id_comunidad_cargado, BloqsOp.Rows[b][1].ToString(), LiqsOp.Rows[a][1].ToString(), varImpReparto.Replace(",", "."), id_operacion_cargado, strCuentaLiqs); } } CuentaLiqs++; } } if (vengoDePantallaVer) { form_anterior.cargarOperacion(id_operacion_cargado); } else { FromOperacionesVer nueva = new FromOperacionesVer(id_operacion_cargado, 1, id_comunidad_cargado); nueva.Show(); } guardada = "si"; this.Close(); } else { MessageBox.Show("Revise los importes, el total es : " + textBox_importe_actual.Text + " y debe ser " + textBox_importe_op.Text); } }
private void button_crear_Click(object sender, EventArgs e) { //CREAMOS CABECERA String sqlInsertCabe = ""; String fechaOp; if (id_op_bbdd != "") { try { fechaOp = (Convert.ToDateTime(maskedTextBox_nueva_fecha.Text)).ToString("yyyy-MM-dd"); } catch (Exception) { MessageBox.Show("Comprueba la fecha de la operación."); return; } String fechaAhora = (Convert.ToDateTime(DateTime.Now)).ToString("yyyy-MM-dd hh:mm:ss"); String sqlSelectCabe = "SELECT IdComunidad, IdEntidad, IdSubCuenta, IdTipoReparto, IdRetencion, BaseRet, Retencion, Notas, IdCuota, IdDivision, IdExpte FROM com_operaciones WHERE (((com_operaciones.IdOp) = " + id_op_bbdd + "));"; DataTable cabecera = Persistencia.SentenciasSQL.select(sqlSelectCabe); id_comunidad_cargado = cabecera.Rows[0][0].ToString(); if (cabecera.Rows[0][3].ToString() == "1") { if (cabecera.Rows[0][10].ToString() == "") { sqlInsertCabe = "INSERT INTO com_operaciones (IdComunidad, IdEntidad, IdSubCuenta, IdTipoReparto, Fecha, Documento, Descripcion,IdRetencion, BaseRet, Retencion, Notas, IdEstado, ImpOp, ImpOpPte, NumMov, Guardada, IdURD, FAct) VALUES (" + cabecera.Rows[0][0].ToString() + "," + cabecera.Rows[0][1].ToString() + "," + cabecera.Rows[0][2].ToString() + "," + cabecera.Rows[0][3].ToString() + ",'" + fechaOp + "','" + textBox_documento.Text + "','" + textBox_nuevo_nombre.Text + "'," + cabecera.Rows[0][4].ToString() + "," + cabecera.Rows[0][5].ToString().Replace(',', '.') + "," + cabecera.Rows[0][6].ToString().Replace(',', '.') + ",'" + cabecera.Rows[0][7].ToString() + "',1," + textBox_importe.Text.Replace(',', '.') + "," + textBox_importe.Text.Replace(',', '.') + ",0,'No'," + Login.getId() + ",'" + fechaAhora + "')"; } else { sqlInsertCabe = "INSERT INTO com_operaciones (IdComunidad, IdEntidad, IdSubCuenta, IdTipoReparto, Fecha, Documento, Descripcion,IdRetencion, BaseRet, Retencion, Notas, IdEstado, IdExpte, ImpOp, ImpOpPte, NumMov, Guardada, IdURD, FAct) VALUES (" + cabecera.Rows[0][0].ToString() + "," + cabecera.Rows[0][1].ToString() + "," + cabecera.Rows[0][2].ToString() + "," + cabecera.Rows[0][3].ToString() + ",'" + fechaOp + "','" + textBox_documento.Text + "','" + textBox_nuevo_nombre.Text + "'," + cabecera.Rows[0][4].ToString() + "," + cabecera.Rows[0][5].ToString().Replace(',', '.') + "," + cabecera.Rows[0][6].ToString().Replace(',', '.') + ",'" + cabecera.Rows[0][7].ToString() + "',1," + cabecera.Rows[0][10].ToString() + "," + textBox_importe.Text.Replace(',', '.') + "," + textBox_importe.Text.Replace(',', '.') + ",0,'No'," + Login.getId() + ",'" + fechaAhora + "')"; } id_op = Persistencia.SentenciasSQL.InsertarGenericoID(sqlInsertCabe); if (Convert.ToDouble(cabecera.Rows[0][6].ToString()) > 0.00) { tieneRetencion(id_op.ToString(), fechaOp); } //CREAMOS IVA String sqlSelectIva = "SELECT aux_iva.`%IVA`, com_opdetiva.IdIVA FROM com_opdetiva INNER JOIN aux_iva ON com_opdetiva.IdIVA = aux_iva.IdIVA WHERE(((com_opdetiva.IdOp) = " + id_op_bbdd + "));"; DataTable iva = Persistencia.SentenciasSQL.select(sqlSelectIva); if (iva.Rows.Count == 1) { int ivaPer = Convert.ToInt32(iva.Rows[0][0].ToString()); double ivaPerIntermedio = ivaPer / 100.00; double baseIVA = Convert.ToDouble(textBox_importe.Text.Replace('.', ',')) / (ivaPerIntermedio + 1); double ivaTotal = ((baseIVA * ivaPer) / 100.00); String sqlInsert = "INSERT INTO com_opdetiva (IdOp, Base, IdIVA, IVA) VALUES (" + id_op + "," + baseIVA.ToString().Replace(',', '.') + "," + iva.Rows[0][1].ToString() + "," + ivaTotal.ToString().Replace(',', '.') + ")"; Persistencia.SentenciasSQL.InsertarGenerico(sqlInsert); } else { MessageBox.Show("La Operacion tiene mas de una linea de IVA, por tanto se tiene que añadir el IVA manualmente."); String sqlTodosIvas = "SELECT Base, IdIVA, IVA FROM com_opdetiva WHERE IdOp = " + id_op_bbdd; DataTable variosIvas = Persistencia.SentenciasSQL.select(sqlTodosIvas); for (int a = 0; a < variosIvas.Rows.Count; a++) { String sqlInsertIvas = "INSERT INTO com_opdetiva (IdOp, Base, IdIVA, IVA) VALUES (" + id_op + "," + variosIvas.Rows[a][0].ToString().Replace(',', '.') + "," + variosIvas.Rows[a][1].ToString() + "," + variosIvas.Rows[a][2].ToString().Replace(',', '.') + ")"; Persistencia.SentenciasSQL.InsertarGenerico(sqlInsertIvas); } masDeUnaLineaIVA = true; } //CREAMOS REPARTO String sqlSelectReparto = "SELECT IdBloque, Porcentaje FROM com_opdetbloques WHERE IdOp = " + id_op_bbdd + ";"; DataTable repartos = Persistencia.SentenciasSQL.select(sqlSelectReparto); for (int a = 0; a < repartos.Rows.Count; a++) { double porcentaje = Convert.ToDouble(repartos.Rows[a][1].ToString()) * 100; double total = (Convert.ToDouble(textBox_importe.Text.Replace('.', ',')) * porcentaje) / 100; String sqlInsertReparto = "INSERT INTO com_opdetbloques (IdOp, IdBloque, Porcentaje, Importe) VALUES (" + id_op + "," + repartos.Rows[a][0].ToString() + "," + repartos.Rows[a][1].ToString().Replace(',', '.') + "," + total.ToString().Replace(',', '.') + ")"; Persistencia.SentenciasSQL.InsertarGenerico(sqlInsertReparto); } //CREAMOS VENCIMIENTOS String sqlEntidadVencimiento = "SELECT IdEntidad, Importe FROM com_opdetalles WHERE com_opdetalles.IdOp = " + id_op_bbdd + ";"; DataTable vencimientos = Persistencia.SentenciasSQL.select(sqlEntidadVencimiento); String fechaAhora2 = (Convert.ToDateTime(fechaOp)).ToString("yyyy-MM-dd"); if (vencimientos.Rows.Count > 1) { double cantidad = 0.00; for (int b = 0; b < vencimientos.Rows.Count; b++) { cantidad = cantidad + Convert.ToDouble(vencimientos.Rows[b][1].ToString()); String sqlInsertVencimiento = "INSERT INTO com_opdetalles (IdOp, IdEntidad, Fecha, Importe, ImpOpDetPte) VALUES (" + id_op + "," + vencimientos.Rows[b][0].ToString() + ",'" + fechaAhora2 + "'," + Logica.FuncionesGenerales.ArreglarImportes(vencimientos.Rows[b][1].ToString()) + "," + Logica.FuncionesGenerales.ArreglarImportes(vencimientos.Rows[b][1].ToString()) + ")"; Persistencia.SentenciasSQL.InsertarGenerico(sqlInsertVencimiento); } if (!cantidad.Equals(Convert.ToDouble(textBox_importe.Text.ToString().Replace(".", ",")))) { MessageBox.Show("EL IMPORTE NO SUMA CORRECTAMENTE LOS VENCIMIENTOS ¡ REVISAR !"); masDeUnaLineaVencimientos = true; } } else if (vencimientos.Rows.Count == 1) { String sqlInsertVencimiento = "INSERT INTO com_opdetalles (IdOp, IdEntidad, Fecha, Importe, ImpOpDetPte) VALUES (" + id_op + "," + vencimientos.Rows[0][0].ToString() + ",'" + fechaAhora2 + "'," + Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text) + "," + Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text) + ")"; Persistencia.SentenciasSQL.InsertarGenerico(sqlInsertVencimiento); } else { MessageBox.Show("La Operacion no tiene vencimientos"); } //LIQUIDACIONES String sqlSelectLiqui = "SELECT Porcentaje FROM com_opdetliquidacion WHERE com_opdetliquidacion.IdOp = " + id_op_bbdd + ";"; DataTable liquidaciones = Persistencia.SentenciasSQL.select(sqlSelectLiqui); //COJO LA FECHA String fecha = (Convert.ToDateTime(maskedTextBox_nueva_fecha.Text)).ToString("yyyy-MM-dd"); //Buscamos liquidacion a la que pertenece String sqlSelectLiquidacionesActivas = "SELECT com_liquidaciones.IdLiquidacion FROM com_ejercicios INNER JOIN com_liquidaciones ON com_ejercicios.IdEjercicio = com_liquidaciones.IdEjercicio WHERE(((com_liquidaciones.Cerrada) <> -1) AND((com_ejercicios.IdComunidad) = " + id_comunidad_cargado + ") AND((com_liquidaciones.Ppal) = -1) AND((com_liquidaciones.FIni) <= '" + fecha + "' ) AND ((com_liquidaciones.FFin) >= '" + fecha + "' ));"; DataTable liquidacionesActivas = Persistencia.SentenciasSQL.select(sqlSelectLiquidacionesActivas); if (liquidacionesActivas.Rows.Count > 0) { if (liquidaciones.Rows.Count == 1) { String sqlInsertarLiquidacionDet = "INSERT INTO com_opdetliquidacion (IdOp, IdLiquidacion, Porcentaje, Importe) VALUES (" + id_op + "," + liquidacionesActivas.Rows[0][0].ToString() + "," + liquidaciones.Rows[0][0].ToString() + "," + Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text) + ")"; Persistencia.SentenciasSQL.InsertarGenerico(sqlInsertarLiquidacionDet); } else { MessageBox.Show("La Operacion tiene mas de una linea de Liquidacion o ninguna, por tanto se tiene que añadir manualmente."); } } else { String sqlLiqPpal = "SELECT com_liquidaciones.IdLiquidacion FROM com_liquidaciones INNER JOIN com_ejercicios ON com_liquidaciones.IdEjercicio = com_ejercicios.IdEjercicio WHERE(((com_ejercicios.IdComunidad) = " + id_comunidad_cargado + ") AND((com_liquidaciones.Ppal) = -1));"; String LiqPpal = (Persistencia.SentenciasSQL.select(sqlLiqPpal)).Rows[0][0].ToString(); if (LiqPpal != "" || LiqPpal != null) { MessageBox.Show("¡¡ CUIDADO LA LIQUIDACIÓN SUGERIDA ESTA CERRADA !!"); String sqlInsertarLiquidacionDet = "INSERT INTO com_opdetliquidacion (IdOp, IdLiquidacion, Porcentaje, Importe) VALUES (" + id_op + "," + LiqPpal + "," + liquidaciones.Rows[0][0].ToString() + "," + Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text) + ")"; Persistencia.SentenciasSQL.InsertarGenerico(sqlInsertarLiquidacionDet); } else { MessageBox.Show("No hay liquidacion principal"); } } if (masDeUnaLineaIVA) { FromOperacionesVer nueva = new FromOperacionesVer(id_op.ToString(), 1, id_comunidad_cargado, textoBuscar); FormOperacionesAddIVA nuevaIVA = new FormOperacionesAddIVA(nueva, id_comunidad_cargado, id_op.ToString(), textBox_importe.Text.Replace('.', ','), true); nuevaIVA.Show(); nueva.Show(); nuevaIVA.TopMost = true; } else if (masDeUnaLineaVencimientos) { FromOperacionesVer nueva = new FromOperacionesVer(id_op.ToString(), 1, id_comunidad_cargado, textoBuscar); FormOperacionesVencimientos nuevaVencimientos = new FormOperacionesVencimientos(nueva, id_comunidad_cargado, id_op.ToString(), textBox_importe.Text.Replace('.', ','), true); nuevaVencimientos.Show(); nueva.Show(); nuevaVencimientos.TopMost = true; } else { FromOperacionesVer nueva = new FromOperacionesVer(id_op.ToString(), 1, id_comunidad_cargado, textoBuscar); nueva.Show(); } } else if (cabecera.Rows[0][3].ToString() == "3") { if (cabecera.Rows[0][10].ToString() == "") { sqlInsertCabe = "INSERT INTO com_operaciones (IdComunidad, IdEntidad, IdSubCuenta, IdTipoReparto, Fecha, Documento, Descripcion,IdRetencion, BaseRet, Retencion,Notas, IdEstado, ImpOp, ImpOpPte, NumMov, Guardada, IdURD, FAct) VALUES (" + cabecera.Rows[0][0].ToString() + "," + cabecera.Rows[0][1].ToString() + "," + cabecera.Rows[0][2].ToString() + "," + cabecera.Rows[0][3].ToString() + ",'" + fechaOp + "','" + textBox_documento.Text + "','" + textBox_nuevo_nombre.Text + "'," + cabecera.Rows[0][4].ToString() + "," + cabecera.Rows[0][5].ToString().Replace(',', '.') + "," + cabecera.Rows[0][6].ToString().Replace(',', '.') + ",'" + cabecera.Rows[0][7].ToString() + "',1," + textBox_importe.Text.Replace(',', '.') + "," + textBox_importe.Text.Replace(',', '.') + ",0,'No'," + Login.getId() + ",'" + fechaAhora + "')"; } else { sqlInsertCabe = "INSERT INTO com_operaciones (IdComunidad, IdEntidad, IdSubCuenta, IdTipoReparto, Fecha, Documento, Descripcion,IdRetencion, BaseRet, Retencion,Notas, IdEstado, IdExpte, ImpOp, ImpOpPte, NumMov, Guardada, IdURD, FAct) VALUES (" + cabecera.Rows[0][0].ToString() + "," + cabecera.Rows[0][1].ToString() + "," + cabecera.Rows[0][2].ToString() + "," + cabecera.Rows[0][3].ToString() + ",'" + fechaOp + "','" + textBox_documento.Text + "','" + textBox_nuevo_nombre.Text + "'," + cabecera.Rows[0][4].ToString() + "," + cabecera.Rows[0][5].ToString().Replace(',', '.') + "," + cabecera.Rows[0][6].ToString().Replace(',', '.') + ",'" + cabecera.Rows[0][7].ToString() + "',1," + cabecera.Rows[0][10].ToString() + "," + textBox_importe.Text.Replace(',', '.') + "," + textBox_importe.Text.Replace(',', '.') + ",0,'No'," + Login.getId() + ",'" + fechaAhora + "')"; } id_op = Persistencia.SentenciasSQL.InsertarGenericoID(sqlInsertCabe); //CREAMOS IVA String sqlSelectIva = "SELECT aux_iva.`%IVA`, com_opdetiva.IdIVA FROM com_opdetiva INNER JOIN aux_iva ON com_opdetiva.IdIVA = aux_iva.IdIVA WHERE(((com_opdetiva.IdOp) = " + id_op_bbdd + "));"; DataTable iva = Persistencia.SentenciasSQL.select(sqlSelectIva); if (iva.Rows.Count == 1) { int ivaPer = Convert.ToInt32(iva.Rows[0][0].ToString()); double ivaPerIntermedio = ivaPer / 100.00; double baseIVA = Convert.ToDouble(textBox_importe.Text.Replace('.', ',')) / (ivaPerIntermedio + 1); double ivaTotal = ((baseIVA * ivaPer) / 100.00); String sqlInsert = "INSERT INTO com_opdetiva (IdOp, Base, IdIVA, IVA) VALUES (" + id_op + "," + baseIVA.ToString().Replace(',', '.') + "," + iva.Rows[0][1].ToString() + "," + ivaTotal.ToString().Replace(',', '.') + ")"; Persistencia.SentenciasSQL.InsertarGenerico(sqlInsert); } else { MessageBox.Show("La Operacion tiene mas de una linea de IVA, por tanto se tiene que añadir el IVA manualmente."); String sqlTodosIvas = "SELECT Base, IdIVA, IVA FROM com_opdetiva WHERE IdOp = " + id_op_bbdd; DataTable variosIvas = Persistencia.SentenciasSQL.select(sqlTodosIvas); for (int a = 0; a < variosIvas.Rows.Count; a++) { String sqlInsertIvas = "INSERT INTO com_opdetiva (IdOp, Base, IdIVA, IVA) VALUES (" + id_op + "," + variosIvas.Rows[a][0].ToString().Replace(',', '.') + "," + variosIvas.Rows[a][1].ToString() + "," + variosIvas.Rows[a][2].ToString().Replace(',', '.') + ")"; Persistencia.SentenciasSQL.InsertarGenerico(sqlInsertIvas); } masDeUnaLineaIVA = true; } //CREAMOS REPARTO String sqlSelectReparto = "SELECT IdEntidad, Porcentaje FROM com_opdetbloques WHERE IdOp = " + id_op_bbdd + ";"; DataTable repartos = Persistencia.SentenciasSQL.select(sqlSelectReparto); for (int a = 0; a < repartos.Rows.Count; a++) { double porcentaje = Convert.ToDouble(repartos.Rows[a][1].ToString()) * 100; double total = (Convert.ToDouble(textBox_importe.Text.Replace('.', ',')) * porcentaje) / 100; String sqlInsertReparto = "INSERT INTO com_opdetbloques (IdOp, IdEntidad, Porcentaje, Importe) VALUES (" + id_op + "," + repartos.Rows[a][0].ToString() + "," + repartos.Rows[a][1].ToString().Replace(',', '.') + "," + total.ToString().Replace(',', '.') + ")"; Persistencia.SentenciasSQL.InsertarGenerico(sqlInsertReparto); } //CREAMOS VENCIMIENTOS String sqlEntidadVencimiento = "SELECT IdEntidad, Importe FROM com_opdetalles WHERE com_opdetalles.IdOp = " + id_op_bbdd + ";"; DataTable vencimientos = Persistencia.SentenciasSQL.select(sqlEntidadVencimiento); String fechaAhora2 = (Convert.ToDateTime(fechaOp)).ToString("yyyy-MM-dd"); if (vencimientos.Rows.Count > 0) { for (int a = 0; a < vencimientos.Rows.Count; a++) { if (vencimientos.Rows.Count > 1) { String sqlInsertVencimiento = "INSERT INTO com_opdetalles (IdOp, IdEntidad, Fecha, Importe, ImpOpDetPte) VALUES (" + id_op + "," + vencimientos.Rows[a][0].ToString() + ",'" + fechaAhora2 + "'," + Logica.FuncionesGenerales.ArreglarImportes(vencimientos.Rows[a][1].ToString()) + "," + Logica.FuncionesGenerales.ArreglarImportes(vencimientos.Rows[a][1].ToString()) + ")"; Persistencia.SentenciasSQL.InsertarGenerico(sqlInsertVencimiento); } else if (vencimientos.Rows.Count == 1) { String sqlInsertVencimiento = "INSERT INTO com_opdetalles (IdOp, IdEntidad, Fecha, Importe, ImpOpDetPte) VALUES (" + id_op + "," + vencimientos.Rows[a][0].ToString() + ",'" + fechaAhora2 + "'," + Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text) + "," + Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text) + ")"; Persistencia.SentenciasSQL.InsertarGenerico(sqlInsertVencimiento); } } } else { MessageBox.Show("La Operacion no tiene vencimientos"); } //LIQUIDACIONES String sqlSelectLiqui = "SELECT Porcentaje FROM com_opdetliquidacion WHERE com_opdetliquidacion.IdOp = " + id_op_bbdd + ";"; DataTable liquidaciones = Persistencia.SentenciasSQL.select(sqlSelectLiqui); //COJO LA FECHA String fecha = (Convert.ToDateTime(maskedTextBox_nueva_fecha.Text)).ToString("yyyy-MM-dd"); //Buscamos liquidacion a la que pertenece String sqlSelectLiquidacionesActivas = "SELECT com_liquidaciones.IdLiquidacion FROM com_ejercicios INNER JOIN com_liquidaciones ON com_ejercicios.IdEjercicio = com_liquidaciones.IdEjercicio WHERE(((com_liquidaciones.Cerrada) <> -1) AND((com_ejercicios.IdComunidad) = " + id_comunidad_cargado + ") AND((com_liquidaciones.Ppal) = -1) AND((com_liquidaciones.FIni) <= '" + fecha + "' ) AND ((com_liquidaciones.FFin) >= '" + fecha + "' ));"; DataTable liquidacionesActivas = Persistencia.SentenciasSQL.select(sqlSelectLiquidacionesActivas); if (liquidacionesActivas.Rows.Count > 0) { if (liquidaciones.Rows.Count == 1) { String sqlInsertarLiquidacionDet = "INSERT INTO com_opdetliquidacion (IdOp, IdLiquidacion, Porcentaje, Importe) VALUES (" + id_op + "," + liquidacionesActivas.Rows[0][0].ToString() + "," + liquidaciones.Rows[0][0].ToString() + "," + Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text) + ")"; Persistencia.SentenciasSQL.InsertarGenerico(sqlInsertarLiquidacionDet); } else { MessageBox.Show("La Operacion tiene mas de una linea de Liquidacion o ninguna, por tanto se tiene que añadir manualmente."); } } else { String sqlLiqPpal = "SELECT com_liquidaciones.IdLiquidacion FROM com_liquidaciones INNER JOIN com_ejercicios ON com_liquidaciones.IdEjercicio = com_ejercicios.IdEjercicio WHERE(((com_ejercicios.IdComunidad) = " + id_comunidad_cargado + ") AND((com_liquidaciones.Ppal) = -1));"; String LiqPpal = (Persistencia.SentenciasSQL.select(sqlLiqPpal)).Rows[0][0].ToString(); if (LiqPpal != "" || LiqPpal != null) { String sqlInsertarLiquidacionDet = "INSERT INTO com_opdetliquidacion (IdOp, IdLiquidacion, Porcentaje, Importe) VALUES (" + id_op + "," + LiqPpal + "," + liquidaciones.Rows[0][0].ToString() + "," + Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text) + ")"; Persistencia.SentenciasSQL.InsertarGenerico(sqlInsertarLiquidacionDet); } else { MessageBox.Show("No hay liquidacion principal"); } } int numRecibo = 0; String vencimientosRecibo = "SELECT com_opdetbloques.IdEntidad, com_operaciones.Fecha, com_opdetbloques.Importe, com_operaciones.Descripcion FROM com_operaciones INNER JOIN com_opdetbloques ON com_operaciones.IdOp = com_opdetbloques.IdOp WHERE(((com_operaciones.IdOp) = " + id_op + "));"; DataTable reparto = Persistencia.SentenciasSQL.select(vencimientosRecibo); for (int a = 0; a < reparto.Rows.Count; a++) { String fechaRecibo = (Convert.ToDateTime(reparto.Rows[a][1].ToString())).ToString("yyyy-MM-dd"); numRecibo = Logica.FuncionesTesoreria.CreoReciboID(id_comunidad_cargado, reparto.Rows[a][0].ToString(), fechaRecibo, reparto.Rows[a][2].ToString(), reparto.Rows[a][2].ToString(), reparto.Rows[a][3].ToString()); String id_opdet = (Persistencia.SentenciasSQL.select("SELECT IdOpDet FROM com_opdetalles WHERE IdOp = " + id_op)).Rows[0][0].ToString(); Logica.FuncionesTesoreria.ActualizoIdReciboVencimiento(numRecibo.ToString(), id_opdet); } if (masDeUnaLineaIVA) { FromOperacionesVer nueva = new FromOperacionesVer(id_op.ToString(), 1, id_comunidad_cargado, textoBuscar); FormOperacionesAddIVA nuevaIVA = new FormOperacionesAddIVA(nueva, id_comunidad_cargado, id_op.ToString(), textBox_importe.Text.Replace('.', ','), true); nuevaIVA.Show(); nueva.Show(); nuevaIVA.TopMost = true; } else { FromOperacionesVer nueva = new FromOperacionesVer(id_op.ToString(), 1, id_comunidad_cargado, textoBuscar); nueva.Show(); } } } }