/// <summary>Este método permite cargar las facturas seleccionadas en el pago.</summary> /// <param name="_P_Obj_Combo">Combo donde se van a mostrar las facturas seleccionadas.</param> /// <param name="_P_Str_Compañia">Código de la compañía para efecutar el filtro.</param> private void _Mtd_CargarComboFacturas(ComboBox _P_Obj_Combo, string _P_Str_Compañia) { string _Str_SQL, _Str_WHERE = ""; //Valor por defecto _Str_SQL = "select '0' as cfactura, '...' as cdescripcion UNION "; //Consutamos _Str_SQL += "select distinct convert(varchar, TFACTURAM.cfactura) as cfactura, ('Factura: ' + convert(varchar, TFACTURAM.cfactura) + ' - Bs F. ' + dbo.Fnc_Formatear(Abs(cmontosaldo))) as cdescripcion from TFACTURAM"; _Str_SQL += " inner join TTRCDOCUMENTO on TFACTURAM.ccompany = TTRCDOCUMENTO.ccompany and TFACTURAM.cfactura = TTRCDOCUMENTO.cfactura"; foreach (DataGridViewRow oFactura in _G_Obj_Facturas.Rows) { var _Bol_EsContribuyenteEspecial = Frm_RC_Pago._Mtd_ClienteEsContribuyenteEspecial(oFactura.Cells["colClienteFactura"].Value.ToString()); if ((oFactura.Cells[0].Value != null) && ((bool)oFactura.Cells[0].Value) && _Bol_EsContribuyenteEspecial) { _Str_WHERE += ((_Str_WHERE == "") ? " where (" : " or ") + "((TFACTURAM.cfactura=" + oFactura.Cells[2].Value.ToString() + "))"; } } _Str_SQL += " AND (cmontodocumentoimpuesto > 0.00) "; //QUE NO EXISTA EN EL GRID NI EN LA BD _G_Obj_Retenciones.Rows.Cast <DataGridViewRow>().ToList().ForEach(_Row => { _Str_SQL += "AND (TFACTURAM.cfactura <> " + _Row.Cells["colRetencionFactura"].Value.ToString() + ") "; }); //QUE NO EXISTAN EN LA BD if (_G_Str_IdPago != "") { _Str_SQL += "AND NOT EXISTS (SELECT TTRCRETENCION.cfactura FROM TTRCRETENCION WHERE ISNULL(TTRCRETENCION.cdelete,0)=0 AND TTRCRETENCION.cfactura=TFACTURAM.cfactura AND cidpago <> " + _G_Str_IdPago + ") "; } else { _Str_SQL += "AND NOT EXISTS (SELECT TTRCRETENCION.cfactura FROM TTRCRETENCION WHERE ISNULL(TTRCRETENCION.cdelete,0)=0 AND TTRCRETENCION.cfactura=TFACTURAM.cfactura) "; } if (_Str_WHERE != "") { var _SQL = _Str_SQL + _Str_WHERE + " and (TFACTURAM.ccompany='" + _P_Str_Compañia.Trim() + "'));"; DataSet oResultado = Program._MyClsCnn._mtd_conexion._Mtd_RetornarDataset(_SQL); _P_Obj_Combo.DataSource = oResultado.Tables[0]; _P_Obj_Combo.DisplayMember = "cdescripcion"; _P_Obj_Combo.ValueMember = "cfactura"; _P_Obj_Combo.SelectedIndex = 0; //Seleccionamos el valor por defecto } }
/// <summary>Este método calcula el monto de la retención y lo asigna al control.</summary> /// <param name="_P_Str_Compañia">Código de la compañía para efecutar el filtro.</param> /// <param name="_P_Str_Factura">Código de la factura para efecutar el filtro.</param> private void _Mtd_CargarMontoRetencion(string _P_Str_Compañia, string _P_Str_Factura) { double _Dbl_MontoImpuesto = 0; double _Dbl_MontoPorcentaje = 0; double _Dbl_MontoMaximoImpuesto = 0; //Valores _Dbl_MontoImpuesto = Frm_RC_Pago._Mtd_ObtenerImpuesto(_G_Str_Compañia, _P_Str_Factura); _Dbl_MontoPorcentaje = Frm_RC_Pago._Mtd_ObtenerPorcentajeRetencionImpuesto(_G_Str_Compañia); _Dbl_MontoMaximoImpuesto = _Dbl_MontoImpuesto * (_Dbl_MontoPorcentaje / 100); //redondeos _Dbl_MontoMaximoImpuesto = Math.Round(_Dbl_MontoMaximoImpuesto, 2); _Txt_Monto.Tag = _Dbl_MontoMaximoImpuesto; _Txt_Monto.Text = _Dbl_MontoMaximoImpuesto.ToString("c"); }
private void _Btn_Guardar_Click(object sender, EventArgs e) { double _Dbl_MontoImpuesto = 0; double _Dbl_MontoIntroducido = 0; double _Dbl_MontoPorcentaje = 0; double _Dbl_MontoMaximoImpuesto = 0; double _Dbl_MontoTolerancia = 0; if (_Cmb_Factura.SelectedIndex == 0) { MessageBox.Show ( "Debe seleccionar una factura.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Error ); _Cmb_Factura.Focus(); return; } if (_Txt_NumeroControl.Text.Trim() == "") { MessageBox.Show ( "Indica el número de control de la factura.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Error ); _Txt_NumeroControl.Focus(); return; } if (_Txt_NumeroControl.Text.Trim() != _G_Str_NumeroDeControl) { MessageBox.Show ( "El número de control que introdujo no corresponde con el de la factura.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Error ); _Txt_NumeroControl.Focus(); return; } var _Str_Numeroretencion = _Txt_NumeroRetencion_Izquierda.Text + _Txt_NumeroRetencion_Derecha.Text.Trim(); if (_Str_Numeroretencion == "") { MessageBox.Show ( "Indica el número de retención de la factura.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Error ); _Txt_NumeroRetencion_Derecha.Focus(); return; } if (_Str_Numeroretencion.Length != 14) { MessageBox.Show ( "El número de la retención debe tener 14 dígitos.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Error ); _Txt_NumeroRetencion_Derecha.Focus(); return; } if (_Dtp_Fecha.Value.Date > DateTime.Now.Date) { MessageBox.Show ( "La fecha no puede ser posterior al día de hoy.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Error ); _Dtp_Fecha.Focus(); return; } if ((_Txt_Monto.Tag.ToString() == "") || (_Txt_Monto.Tag.ToString() == "0")) { MessageBox.Show ( "El monto es incorrecto o no puede ser cero.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Error ); _Txt_Monto.Focus(); return; } if ((_G_Enum_EstadoRetencion == TiposEstadoRetencion.EstadoRetencionNuevo) && (Frm_RC_Pago._Mtd_ExisteRetencionGuardada(_G_Str_Compañia, _G_Str_cguia, _Cmb_Factura.SelectedValue.ToString(), _G_Str_IdPago))) { MessageBox.Show ( "La factura ya tiene una retención aplicada.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Error ); _Cmb_Factura.Focus(); return; } if ((_G_Enum_EstadoRetencion == TiposEstadoRetencion.EstadoRetencionNuevo) && (_Mtd_TieneRetencionEnGrid(_Cmb_Factura.SelectedValue.ToString()))) { MessageBox.Show ( "La factura ya tiene una retención aplicada.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Error ); _Cmb_Factura.Focus(); return; } //Valores _Dbl_MontoImpuesto = Frm_RC_Pago._Mtd_ObtenerImpuesto(_G_Str_Compañia, _Cmb_Factura.SelectedValue.ToString()); _Dbl_MontoPorcentaje = Frm_RC_Pago._Mtd_ObtenerPorcentajeRetencionImpuesto(_G_Str_Compañia); _Dbl_MontoMaximoImpuesto = _Dbl_MontoImpuesto * (_Dbl_MontoPorcentaje / 100); _Dbl_MontoIntroducido = Convert.ToDouble(_Txt_Monto.Tag.ToString()); _Dbl_MontoTolerancia = Frm_RC_DocumentosClientes._Mtd_ObtenerLimiteFaltante(Frm_Padre._Str_Comp); //redondeos _Dbl_MontoMaximoImpuesto = Math.Round(_Dbl_MontoMaximoImpuesto, 2); _Dbl_MontoTolerancia = Math.Round(_Dbl_MontoTolerancia, 2); if (_Dbl_MontoIntroducido > (_Dbl_MontoMaximoImpuesto + _Dbl_MontoTolerancia)) { MessageBox.Show ( "El monto de la retención es mayor al monto máximo permitido de retención de impuesto de la factura.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Error ); _Txt_Monto.Focus(); return; } //else if (_Dbl_MontoImpuesto == 0) //{ // MessageBox.Show // ( // "La factura no tiene impuesto, no se puede agregar la retención.", // "Advertencia", // MessageBoxButtons.OK, // MessageBoxIcon.Error // ); // _Txt_Monto.Focus(); // return; //} if (_G_Enum_EstadoRetencion == TiposEstadoRetencion.EstadoRetencionNuevo) { _Mtd_CargarRetencion ( _Cmb_Factura.SelectedValue.ToString(), _Str_Numeroretencion, _Dtp_Fecha.Value, _Txt_NumeroControl.Text, Convert.ToDouble(_Txt_Monto.Tag.ToString()) ); } else if (_G_Enum_EstadoRetencion == TiposEstadoRetencion.EstadoRetencionEditar) { _Mtd_ModificarRetencion ( _Cmb_Factura.SelectedValue.ToString(), _Str_Numeroretencion, _Dtp_Fecha.Value, Convert.ToDouble(_Txt_Monto.Tag.ToString()) ); } }