private void button1_Click(object sender, EventArgs e) { // Cabecera de edicion aqui //id_comunidad_cargado + "," + id_entidad_nuevo + "," + comboBox_cuenta_gastos.SelectedValue.ToString() + "," + comboBox_tipo_reparto.SelectedValue.ToString() + ",'" + fechaInicio + "','" + textBox_documento.Text + "','" + textBox_descripcion.Text + "'," + comboBox_porcentage if (maskedTextBox_fecha.Text == " / /") { MessageBox.Show("La fecha no puede estar vacía"); maskedTextBox_fecha.Text = (Convert.ToDateTime(DateTime.Now)).ToString("dd-MM-yyyy"); return; } if (id_entidad_nuevo == null) { MessageBox.Show("La identidad no puede estar vacía"); return; } if (textBox_documento.Text == "") { MessageBox.Show("El Documento no puede estar vacío"); return; } if (textBox_importe.Text == "") { MessageBox.Show("El Importe no puede estar vacío"); return; } String fechaInicio = (Convert.ToDateTime(maskedTextBox_fecha.Text)).ToString("yyyy-MM-dd"); String fecha_actualizacion = (Convert.ToDateTime(DateTime.Now)).ToString("yyyy-MM-dd hh:mm:ss"); if (id_operacion_cargado != "0") { if (textBox_expediente.Text != "") { String sqlUpdate = "UPDATE com_operaciones SET IdEntidad=" + id_entidad_nuevo + ",IdSubCuenta=" + comboBox_cuenta_gastos.SelectedValue.ToString() + ", IdTipoReparto = " + comboBox_tipo_reparto.SelectedValue.ToString() + ",Fecha='" + fechaInicio + "',Documento='" + textBox_documento.Text + "',Descripcion='" + textBox_descripcion.Text + "',IdRetencion=" + comboBox_porcentage_retencion.SelectedValue.ToString() + ",BaseRet=" + textBox_base_retencion.Text.Replace(',', '.') + ",IdExpte= " + textBox_expediente.Text + " , Retencion=" + textBox_retencion.Text.Replace(',', '.') + ",Notas='" + textBox_notas.Text + "',ImpOp=" + Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text) + ",ImpOpPte = " + Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text) + ", IdURD = " + Presentacion.Login.getId() + ",FAct = '" + fecha_actualizacion + "' WHERE IdOp = " + id_operacion_cargado; Persistencia.SentenciasSQL.InsertarGenerico(sqlUpdate); } else { String sqlUpdate = "UPDATE com_operaciones SET IdEntidad=" + id_entidad_nuevo + ",IdSubCuenta=" + comboBox_cuenta_gastos.SelectedValue.ToString() + ", IdTipoReparto = " + comboBox_tipo_reparto.SelectedValue.ToString() + ",Fecha='" + fechaInicio + "',Documento='" + textBox_documento.Text + "',Descripcion='" + textBox_descripcion.Text + "',IdRetencion=" + comboBox_porcentage_retencion.SelectedValue.ToString() + ",BaseRet=" + textBox_base_retencion.Text.Replace(',', '.') + ",Retencion=" + textBox_retencion.Text.Replace(',', '.') + ",Notas='" + textBox_notas.Text + "',ImpOp=" + Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text) + ",ImpOpPte = " + Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text) + ", IdURD = " + Presentacion.Login.getId() + ",FAct = '" + fecha_actualizacion + "' WHERE IdOp = " + id_operacion_cargado; Persistencia.SentenciasSQL.InsertarGenerico(sqlUpdate); } form_anterior.cargarOperacion(id_operacion_cargado); this.Close(); } else { int idop; if (textBox_expediente.Text != "") { String sqlInsert = "INSERT INTO com_operaciones(IdComunidad, IdEntidad, IdSubCuenta, IdTipoReparto, Fecha, Documento, Descripcion, IdRetencion, BaseRet, Retencion, Notas, IdEstado, IdExpte, ImpOp, ImpOpPte, NumMov, Guardada, IdURD, FAct) VALUES (" + id_comunidad_cargado + "," + id_entidad_nuevo + "," + comboBox_cuenta_gastos.SelectedValue.ToString() + "," + comboBox_tipo_reparto.SelectedValue.ToString() + ",'" + fechaInicio + "','" + textBox_documento.Text + "','" + textBox_descripcion.Text + "'," + comboBox_porcentage_retencion.SelectedValue.ToString() + "," + textBox_base_retencion.Text + "," + textBox_retencion.Text + ",'" + textBox_notas.Text + "','1'," + textBox_expediente.Text + "," + Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text) + "," + Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text) + ",0,'No'," + Presentacion.Login.getId() + ",'" + fecha_actualizacion + "')"; idop = Persistencia.SentenciasSQL.InsertarGenericoID(sqlInsert); } else { String sqlInsert = "INSERT INTO com_operaciones(IdComunidad, IdEntidad, IdSubCuenta, IdTipoReparto, Fecha, Documento, Descripcion, IdRetencion, BaseRet, Retencion, Notas, IdEstado, ImpOp, ImpOpPte, NumMov, Guardada, IdURD, FAct) VALUES (" + id_comunidad_cargado + "," + id_entidad_nuevo + "," + comboBox_cuenta_gastos.SelectedValue.ToString() + "," + comboBox_tipo_reparto.SelectedValue.ToString() + ",'" + fechaInicio + "','" + textBox_documento.Text + "','" + textBox_descripcion.Text + "'," + comboBox_porcentage_retencion.SelectedValue.ToString() + "," + textBox_base_retencion.Text + "," + textBox_retencion.Text + ",'" + textBox_notas.Text + "','1'," + Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text) + "," + Logica.FuncionesGenerales.ArreglarImportes(textBox_importe.Text) + ",0,'No'," + Presentacion.Login.getId() + ",'" + fecha_actualizacion + "')"; idop = Persistencia.SentenciasSQL.InsertarGenericoID(sqlInsert); } if (Convert.ToDouble(textBox_retencion.Text) > 0.00) { tieneRetencion(idop.ToString()); } FormOperacionesAddIVA nueva = new FormOperacionesAddIVA(id_comunidad_cargado, idop.ToString(), textBox_importe.Text.Replace('.', ',')); nueva.Show(); this.Close(); } }
private void button_add_iva_Click(object sender, EventArgs e) { FormOperacionesAddIVA nueva = new FormOperacionesAddIVA(this, id_comunidad_cargado, id_operacion_cargado, textBox_importe.Text, true); nueva.Show(); }
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(); } } } }