Files
SIG/Bancos/PrestamoPersonal.aspx.cs

776 lines
31 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Extensiones;
using static Extensiones.ModExtensiones;
public partial class Bancos_PrestamoPersonal : ClsPaginas
{
#region "PROPIEDADES"
private int IDCtaContablePrestamo
{
get
{
return ViewState["IDCtaContablePrestamo"].ToEntero();
}
set
{
ViewState["IDCtaContablePrestamo"] = value;
}
}
private int IDCtaContableBancos
{
get
{
return ViewState["IDCtaContableBancos"].ToEntero();
}
set
{
ViewState["IDCtaContableBancos"] = value;
}
}
private int IDCtaContableBancosComplementario
{
get
{
return ViewState["IDCtaContableBancosComplementario"].ToEntero();
}
set
{
ViewState["IDCtaContableBancosComplementario"] = value;
}
}
private int IDCtaContableBancosPrestamo
{
get
{
return ViewState["IDCtaContableBancosPrestamo"].ToEntero();
}
set
{
ViewState["IDCtaContableBancosPrestamo"] = value;
}
}
private int IDCtaContableBancosPrestamoComplementario
{
get
{
return ViewState["IDCtaContableBancosPrestamoComplementario"].ToEntero();
}
set
{
ViewState["IDCtaContableBancosPrestamoComplementario"] = value;
}
}
private bool UsaComplementaria
{
get
{
return Convert.ToBoolean(ViewState["UsaComplementaria"]);
}
set
{
ViewState["UsaComplementaria"] = value;
}
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
UsaComplementaria = false;
if (UsuarioActual.CveEmpresa.Contiene(1, 119)) { UsaComplementaria = true; }
CargaTipoTransaccion();
CargaCuentas();
CargaPersonal();
CargaReporte();
TxtFechaDocumento.Text = DateTime.Now.ToShortDateString();
TxtFechaPrestamo.Text = DateTime.Now.ToShortDateString();
txtFechaI.Text = DateTime.Now.FirstDayOfMonth().ToShortDateString();
txtFechaF.Text = DateTime.Now.ToShortDateString();
TxtImporte.Attributes.Add("disabled", "disabled");
if (UsuarioActual.Empresa.Funcionalidad(281).ToEntero() == 1)
{
TxtFechaPrestamo.Enabled = false;
ImgCalendarioPrestamo.Visible = false;
TxtFechaDocumento.Enabled = false;
ImgCalendario.Visible = false;
}
}
}
#region"INFORMACION GENERAL"
protected void CargaTipoTransaccion()
{
DdlTipoTransaccion.DataSource = GlobalDTTipoTransacciones.FiltraParametros("Tipo='Ing'");
DdlTipoTransanccionPrestamo.DataSource = GlobalDTTipoTransacciones.FiltraParametros("Tipo='Egs'");
DdlTipoTransaccion.DataBind();
DdlTipoTransanccionPrestamo.DataBind();
DdlTipoTransaccion.Items.Insert(0, new ListItem("Seleccione Tipo Movimiento", "-1"));
DdlTipoTransanccionPrestamo.Items.Insert(0, new ListItem("Seleccione Tipo Movimiento", "-1"));
}
protected void CargaCuentas()
{
DdlCuenta.DataSource = get_GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa: UsuarioActual.CveEmpresa).FiltraParametros("CveTipoCuenta <> 1"); //quito las cajas chicas
DdlCuentaPrestamo.DataSource = get_GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa: UsuarioActual.CveEmpresa).FiltraParametros("CveTipoCuenta <> 1");
DdlCuenta.DataBind();
DdlCuentaPrestamo.DataBind();
DdlCuenta.Items.Insert(0, new ListItem("Seleccione Cuenta", "-1"));
DdlCuentaPrestamo.Items.Insert(0, new ListItem("Seleccione Cuenta", "-1"));
}
protected void CargaPersonal()
{
ClsRH ObjPersonal = new ClsRH();
if (ObjPersonal.GetPersonal(-1, UsuarioActual.CveEmpresa))
{
DdlFuncionarioEmpleado.DataSource = ObjPersonal.DtResultados;
DdlFuncionarioEmpleado.Items.Insert(0, new ListItem("Todos", "-1"));
DdlFuncionarioEmpleadoPago.DataSource = ObjPersonal.DtResultados;
DdlFuncionarioEmpleadoPago.Items.Insert(0, new ListItem("Seleccione", "-1"));
DdlFuncionarioEmpleadoPrestamo.DataSource = ObjPersonal.DtResultados;
DdlFuncionarioEmpleadoPrestamo.Items.Insert(0, new ListItem("Seleccione", "-1"));
}
ObjPersonal.Dispose();
DdlFuncionarioEmpleado.DataBind();
DdlFuncionarioEmpleadoPago.DataBind();
DdlFuncionarioEmpleadoPrestamo.DataBind();
}
#endregion
#region "PAGO ACREEDORES"
protected void DdlCuenta_SelectedIndexChanged(object sender, EventArgs e)
{
DataRow dr = get_GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa: UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CveCuenta = {0}", DdlCuenta.SelectedValue));
int tCveMoneda = 0;
if (dr != null)
{
tCveMoneda = dr["CveMoneda"].ToString().ToEntero();
IDCtaContableBancos = dr["IdCtaContable"].ToString().ToEntero();
IDCtaContableBancosComplementario = dr["IdCtaContableComplementaria"].ToString().ToEntero();
}
if (tCveMoneda != 1)
{
divTCPago.Visible = true;
TxtTCPago.Text = get_GlobalTipoCambio(TxtFechaDocumento.Text.ToDate()).ToString();
}
else
{
divTCPago.Visible = false;
TxtTCPago.Text = "1";
}
long Folio;
ClsBancos bancos = new ClsBancos();
Folio = bancos.GetNextFolio(DdlCuenta.SelectedValue.ToEntero(), DdlTipoTransaccion.SelectedValue.ToEntero());
bancos.Dispose();
TxtFolio.Text = Folio.ToString();
}
protected void DdlFuncionarioEmpleadoPago_SelectedIndexChanged(object sender, EventArgs e)
{
if (DdlFuncionarioEmpleadoPago.SelectedValue.ToEntero() > 0)
{
ClsMovimientos ObjMov = new ClsMovimientos();
if (ObjMov.GetPrestamosPersonalXSaldar(DdlFuncionarioEmpleadoPago.SelectedValue.ToEntero(), -1, UsuarioActual.CveEmpresa))
{
GvMovAcreedor.DataSource = ObjMov.DtResultados.FiltraParametros("CveIE > 0 AND Saldo > 0 ", "");
}
ObjMov.Dispose();
}
else
{
GvMovAcreedor.DataSource = null;
}
GvMovAcreedor.DataBind();
UpMovAcreedor.Update();
}
protected void GvMovAcreedor_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.FCCheckBox("Chk").Attributes.Add("onclick", String.Format("FnSuma(this,{0},{1});", e.Row.FCTextBox("TxtAbonar").ClientID, e.Row.DBCampo("Saldo")));
e.Row.FCTextBox("TxtAbonar").Attributes.Add("onblur", String.Format("FnCambia({0},this,{1},1,'{2}');", e.Row.FCCheckBox("Chk").ClientID, e.Row.DBCampo("Saldo"), "El Importe no debe de exceder el saldo"));
}
}
protected void BtnIEGuardar_Click(object sender, EventArgs e)
{
ClsBancos ObjIE = new ClsBancos();
ClsContabilidad ObjMov = new ClsContabilidad(ObjIE.IniciaTransacSQL());
ClsCompras ObjComp = new ClsCompras(ObjIE.IniciaTransacSQL());
string MsgError = "";
int CveIE = 0;
int CveConceptoContableBanco = 30;
int CveConceptoContablePago = 258;
int CveConceptoContableBancoComplementario = 204;
int CveConceptoContablePrestamoComplementario = 202;
int CvePlantillaPoliza = 21;
int CvePrePoliza = 0;
int CveMoneda = get_GlobalDTBancosCuentas(-1, CveEmpresa: UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveMoneda", $"CveEmpresa = {UsuarioActual.CveEmpresa} AND CveCuenta = {DdlCuenta.SelectedValue.ToEntero()}").ToEntero();
int FolioFijo = 0;
int IDPoliza = 0;
StringBuilder Msg = new StringBuilder();
//OBTIENE COMPROBANTE !!
string Comprobante = "";
List<Archivo> filesgral = Anexo.getfiles().Archivos;
string filemove = "";
foreach (Archivo fileItem in filesgral)
{
Comprobante = System.IO.Path.GetExtension(string.Format(@"{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "");
filemove = fileItem.filename;
}
// asigna a propiedades las cuentas del acreedor
AsignaCuentaPersonal(DdlFuncionarioEmpleadoPago.SelectedValue.ToEntero(), CveMoneda);
// DATOS PREPOLIZA
if (DdlTipoTransaccion.SelectedValue == "1" && UsuarioActual.CveEmpresa != 119) FolioFijo = TxtFolio.Text.ToEntero();
CvePrePoliza = ObjMov.AddPrePolizas("Bancos/IE PAGO ACRREDORES", CvePlantillaPoliza, TxtImporte.Text.Trim().ToDouble(), TxtImporte.Text.Trim().ToDouble(), CveMoneda, TxtFechaDocumento.Text.ToDate(), DdlFuncionarioEmpleadoPago.SelectedItem.Text, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, FolioFijo: FolioFijo, ReglaFolioPoliza: ObjComp.ObtenerReglaFolio(DdlTipoTransaccion.SelectedValue, null, UsuarioActual.CveEmpresa), CveTipoPoliza: ObjMov.ObtenerTipoPoliza(DdlTipoTransaccion.SelectedValue, "-1", UsuarioActual.CveEmpresa));
if (CvePrePoliza > 0)
{
decimal ImporteBanco = TxtImporte.Text.ToDecimal();
decimal ImporteMNBanco = ImporteBanco;
decimal ImporteComplementaria = 0;
decimal TC = TxtTCPago.Text.ToDecimal();
string Conc = TxtObservaciones.Text == "" ? TxtFolio.Text : TxtObservaciones.Text;
string Ref = TxtObservaciones.Text == "" ? TxtFolio.Text : TxtObservaciones.Text;
CveIE = ObjIE.AddBancos_IE(DdlCuenta.SelectedValue.ToEntero(), DdlTipoTransaccion.SelectedValue.ToEntero(), TxtFechaDocumento.Text.Trim().ToDate(), TxtFolio.Text.Trim(), DdlFuncionarioEmpleadoPago.SelectedItem.Text, ImporteBanco.ToString().ToDouble(), CveMoneda,
TC.ToString().ToDouble(), TxtObservaciones.Text.Trim(), "", ChkAbonoCuenta.Checked, false, -1, CvePrePoliza, Comprobante, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa);
if (CveMoneda != 1)
{
if (UsaComplementaria)
{
ImporteMNBanco = ImporteBanco;
ImporteComplementaria = ImporteBanco * TC - ImporteBanco;
}
else
{
ImporteMNBanco = ImporteBanco * TC;
ImporteComplementaria = 0;
}
}
if (CveIE > 0)
{
//GUARDA COMPROBANTE
if (!filemove.Equals(""))
{
filemove.FilesMove(CveIE.ToString(), string.Format(@"{0}IE", UsuarioActual.Empresa.Ruta), ConcatenarDirectorioBase: false);
}
decimal Importe;
decimal ImporteMN;
//GUARDA PREPOLIZAS DETALLE
foreach (GridViewRow gvr in GvMovAcreedor.Rows)
{
Importe = gvr.FCTextBox("TxtAbonar").Text.ToDecimal();
ImporteMN = Importe;
ImporteComplementaria = 0;
if (gvr.FCCheckBox("Chk").Checked)
{
int tCveMoneda = gvr.DataKey("CveMoneda").ToEntero();
if (tCveMoneda != 1)
{
if (UsaComplementaria)
{
ImporteMN = Importe;
ImporteComplementaria = Importe * TC - Importe;
}
else
{
ImporteMN = Importe * TC;
ImporteComplementaria = 0;
}
}
if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, true, Importe, Ref, CveConceptoContablePago, Conc, DateTime.Now, IDCtaContablePrestamo, -1, CveIE, CvePersonal: DdlFuncionarioEmpleadoPago.SelectedValue.ToEntero(), ImporteMX: ImporteMN, CveIEDevolucion: gvr.DataKey("CveIE").ToEntero(), TipoCambio: TC, TipoCambioPago: TC))
{
MsgError = "No se pudo insertar concepto de pago acreedor";
break;
}
if (tCveMoneda != 1 && UsaComplementaria)
{
if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, true, Importe, Ref, CveConceptoContablePrestamoComplementario, Conc, DateTime.Now, CveConceptoContablePrestamoComplementario, -1, CveIE, CvePersonal: DdlFuncionarioEmpleadoPago.SelectedValue.ToEntero(), ImporteMX: ImporteComplementaria, ImporteME: Importe, TipoCambio: TC, TipoCambioPago: TC))
{
MsgError = "No se pudo insertar concepto de acreedor complementaria";
}
}
}
}
if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, false, ImporteBanco, Ref, CveConceptoContableBanco, Conc, DateTime.Now, IDCtaContableBancos, -1, CveIE, CvePersonal: DdlFuncionarioEmpleadoPago.SelectedValue.ToEntero(), ImporteMX: ImporteMNBanco, ImporteME: ImporteBanco, TipoCambio: TC, TipoCambioPago: TC))
{
MsgError = "No se pudo insertar concepto de bancos";
}
if (CveMoneda != 1 && UsaComplementaria)
{
if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, false, ImporteBanco, Ref, CveConceptoContableBancoComplementario, Conc, DateTime.Now, IDCtaContableBancosPrestamo, -1, CveIE, CvePersonal: DdlFuncionarioEmpleadoPago.SelectedValue.ToEntero(), ImporteMX: ImporteComplementaria, ImporteME: ImporteBanco, TipoCambio: TC, TipoCambioPago: TC))
{
MsgError = "No se pudo insertar concepto de bancos complementaria";
}
}
}
else
{
MsgError = "No se insertó movimiento bancario";
}
}
else
{
MsgError = "No se pudo insertar la póliza";
}
// VALIDA QUE CUADRE LA PREPOLIZA
if (ObjMov.ValidacionPrePolizaCuadre(CvePrePoliza, 5))
{
if (ObjMov.ValorPolizaDescuadre > 0)
{
MsgError = ObjMov.MensajePolizaDescuadre;
ModExtensiones.GuardaLogAD($"Bancos/IE PAGO ACREEDOR | Error:{ObjMov.MensajePolizaDescuadre} Diferencia:{ObjMov.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas");
}
}
//CONTABILIZA
if (UsuarioActual.Empresa.Funcionalidad(200).Equals("1") && MsgError.Equals(""))
{
if (IDCtaContablePrestamo > 0 && IDCtaContableBancos > 0)
{
if (ObjMov.ContabilizarPrePoliza(CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.Empresa))
{
IDPoliza = ObjMov.ContaIdPoliza;
}
else
{
Alert("Ocurrio un error al contabilizar, pongase en contacto con Soporte Técnico", TipoMensaje.MsgError);
}
}
else
{
if (IDCtaContablePrestamo < 1)
{
Alert("No se puede contabilizar la Prepoliza debido a que la cuenta de Acreedor es invalida", TipoMensaje.MsgAdvertencia);
}
if (IDCtaContableBancos < 1)
{
Alert("No se puede contabilizar la Prepoliza debido a que la cuenta bancaria es invalida", TipoMensaje.MsgAdvertencia);
}
}
}
if (MsgError.Equals(""))
{
if (Msg.ToString().Equals(""))
{
Msg.Append("El Documento se guardo correctamente");
}
System.IO.FileInfo archivo = null;
if (DdlTipoTransaccion.SelectedValue.ToEntero().Contiene(2, 8, 9))
{
archivo = new System.IO.FileInfo(String.Format("{0}Formatos/Transferencia.rdlc", UsuarioActual.Empresa.Ruta));
}
else if (DdlTipoTransaccion.SelectedValue.ToEntero().Contiene(1))
{
archivo = new System.IO.FileInfo(String.Format("{0}Formatos/CHQ-{1}.rdlc", UsuarioActual.Empresa.Ruta, DdlCuenta.SelectedValue.ToEntero()));
if (!archivo.Exists)
{
archivo = new System.IO.FileInfo(String.Format(@"{0}\Empresas\Grales\Formatos\CHQ.rdlc", ModExtensiones.DirectorioBaseEmpresas));
}
}
else if (DdlTipoTransaccion.SelectedValue.ToEntero().Contiene(6) && UsuarioActual.CveEmpresa == 72)
{
archivo = new System.IO.FileInfo(String.Format("{0}Formatos/ComprobanteEgreso.rdlc", UsuarioActual.Empresa.Ruta, DdlCuenta.SelectedValue.ToEntero()));
}
//if (archivo.Length > 0)
//{
// if (archivo.Exists)
// {
// Msg.AppendFormat(@"<br/><br/> <a class=""Texto"" target='_blank' href=""/Compras/PopUpVerFactura.aspx?P={0}"">{1}</a> ", Encripta(String.Format("OP=IECHEQUE&CVEIE={0}", CveIE)), String.Format("Imprimir {0}", DdlTipoTransaccion.SelectedItem));
// }
//}
if (IDPoliza > 0)
{
Msg.AppendFormat(@"<br/><br/><a class=""Texto"" target='_blank' href=""/Contabilidad/RegPoliza.aspx?IdPoliza={0}"">Ver Póliza</a>", IDPoliza);
}
ObjIE.Commit();
}
else
{
Alert(MsgError, TipoMensaje.MsgError);
ObjIE.RollBack();
}
if (!Msg.ToString().Equals(""))
{
string AccionJS = String.Format(@"document.location.href=""{0}"";", HttpContext.Current.Request.Url.PathAndQuery);
Alert(Msg.ToString(), TipoMensaje.MsgInformacion, String.Format(@"document.location.href=""{0}"";", HttpContext.Current.Request.Url.PathAndQuery));
}
ObjIE.Dispose();
ObjMov.Dispose();
if (ObjComp != null)
ObjComp.Dispose();
}
#endregion
#region "PRESTAMO ACREEDORES"
protected void DdlCuentaPrestamo_SelectedIndexChanged(object sender, EventArgs e)
{
DataRow dr = get_GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa: UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CveCuenta = {0}", DdlCuentaPrestamo.SelectedValue));
int tCveMoneda = 0;
if (dr != null)
{
tCveMoneda = dr["CveMoneda"].ToString().ToEntero();
IDCtaContableBancosPrestamo = dr["IdCtaContable"].ToString().ToEntero();
IDCtaContableBancosPrestamoComplementario = dr["IdCtaContableComplementaria"].ToString().ToEntero();
}
if (tCveMoneda != 1)
{
divTCPrestamo.Visible = true;
TxtTCPrestamo.Text = get_GlobalTipoCambio(TxtFechaPrestamo.Text.ToDate()).ToString();
}
else
{
divTCPrestamo.Visible = false;
TxtTCPrestamo.Text = "1";
}
long Folio;
ClsBancos bancos = new ClsBancos();
Folio = bancos.GetNextFolio(DdlCuentaPrestamo.SelectedValue.ToEntero(), DdlTipoTransanccionPrestamo.SelectedValue.ToEntero());
bancos.Dispose();
TxtFolioPrestamo.Text = Folio.ToString();
// si la moneda no es peso, se pone tc
}
private void AsignaCuentaPersonal(int CvePersonal, int tCveMoneda)
{
IDCtaContablePrestamo = 0;
ClsRH ObjRH = new ClsRH();
if (CvePersonal > 0)
{
if (ObjRH.GetPersonal(CvePersonal, UsuarioActual.CveEmpresa))
{
IDCtaContablePrestamo = ObjRH.IdCtaContPrestamos;
}
}
ObjRH.Dispose();
}
protected void BtnGuardarPrestamo_Click(object sender, EventArgs e)
{
ClsBancos ObjIE = new ClsBancos();
ClsContabilidad ObjMov = new ClsContabilidad(ObjIE.IniciaTransacSQL());
ClsCompras ObjComp = new ClsCompras(ObjIE.IniciaTransacSQL());
string MsgError = "";
int CveIE = 0;
int CveConceptoContableBanco = 30;
int CveConceptoContablePrestamo = 257;
int CveConceptoContableBancoComplementario = 204;
int CveConceptoContablePrestamoComplementario = 202;
int CvePlantillaPoliza = 8;
int CvePrePoliza = 0;
int CveMoneda = get_GlobalDTBancosCuentas(-1, CveEmpresa: UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveMoneda", $"CveEmpresa = {UsuarioActual.CveEmpresa} AND CveCuenta = {DdlCuentaPrestamo.SelectedValue.ToEntero()}").ToEntero();
int FolioFijo = 0;
int IDPoliza = 0;
StringBuilder Msg = new StringBuilder();
//OBTIENE COMPROBANTE !!
string Comprobante = "";
List<Archivo> filesgral = AnexoPrestamo.getfiles().Archivos;
string filemove = "";
foreach (Archivo fileItem in filesgral)
{
Comprobante = System.IO.Path.GetExtension(string.Format(@"{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "");
filemove = fileItem.filename;
}
// asigna a propiedades las cuentas del acreedor
AsignaCuentaPersonal(DdlFuncionarioEmpleadoPrestamo.SelectedValue.ToEntero(), CveMoneda);
// DATOS PREPOLIZA
if (DdlTipoTransanccionPrestamo.SelectedValue == "1" && UsuarioActual.CveEmpresa != 119) FolioFijo = TxtFolioPrestamo.Text.ToEntero();
CvePrePoliza = ObjMov.AddPrePolizas("Bancos/PRESTAMO PERSONAL", CvePlantillaPoliza, TxtImportePrestamo.Text.Trim().ToDouble(), TxtImportePrestamo.Text.Trim().ToDouble(), CveMoneda, TxtFechaPrestamo.Text.ToDate(), DdlFuncionarioEmpleadoPrestamo.SelectedItem.Text, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, FolioFijo: FolioFijo, ReglaFolioPoliza: ObjComp.ObtenerReglaFolio(DdlTipoTransaccion.SelectedValue, null, UsuarioActual.CveEmpresa));
if (CvePrePoliza > 0)
{
decimal Importe = TxtImportePrestamo.Text.ToDecimal();
decimal ImporteMN = Importe;
decimal ImporteComplementaria = 0;
decimal TC = TxtTCPrestamo.Text.ToDecimal();
string Conc = TxtObservacionesPrestamo.Text == "" ? TxtFolioPrestamo.Text : TxtObservacionesPrestamo.Text;
string Ref = TxtObservacionesPrestamo.Text == "" ? TxtFolioPrestamo.Text : TxtObservacionesPrestamo.Text;
CveIE = ObjIE.AddBancos_IE(DdlCuentaPrestamo.SelectedValue.ToEntero(), DdlTipoTransanccionPrestamo.SelectedValue.ToEntero(), TxtFechaPrestamo.Text.Trim().ToDate(), TxtFolioPrestamo.Text.Trim(), DdlFuncionarioEmpleadoPrestamo.SelectedItem.Text, Importe.ToString().ToDouble(), CveMoneda,
TC.ToString().ToDouble(), TxtObservacionesPrestamo.Text.Trim(), "", false, false, -1, CvePrePoliza, Comprobante, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa);
if (CveMoneda != 1)
{
if (UsuarioActual.CveEmpresa.Contiene(1, 119)) { UsaComplementaria = true; }
if (UsaComplementaria)
{
ImporteMN = Importe;
ImporteComplementaria = Importe * TC - Importe;
}
else
{
ImporteMN = Importe * TC;
ImporteComplementaria = 0;
}
}
if (CveIE > 0)
{
//GUARDA COMPROBANTE
if (!filemove.Equals(""))
{
filemove.FilesMove(CveIE.ToString(), string.Format(@"{0}IE", UsuarioActual.Empresa.Ruta), ConcatenarDirectorioBase:false);
}
if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, true, Importe, Ref, CveConceptoContableBanco, Conc, DateTime.Now, IDCtaContableBancosPrestamo, -1, CveIE, CvePersonal: DdlFuncionarioEmpleadoPrestamo.SelectedValue.ToEntero(), ImporteMX: ImporteMN, TipoCambio: TC, TipoCambioPago: TC))
{
MsgError = "No se pudo insertar concepto de bancos";
}
if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, false, Importe, Ref, CveConceptoContablePrestamo, Conc, DateTime.Now, IDCtaContablePrestamo, -1, CveIE, CvePersonal: DdlFuncionarioEmpleadoPrestamo.SelectedValue.ToEntero(), ImporteMX: ImporteMN, TipoCambio: TC, TipoCambioPago: TC))
{
MsgError = "No se pudo insertar concepto de acreedor";
}
if (CveMoneda != 1 && UsaComplementaria)
{
if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, true, Importe, Ref, CveConceptoContableBancoComplementario, Conc, DateTime.Now, IDCtaContableBancosPrestamo, -1, CveIE, CvePersonal: DdlFuncionarioEmpleadoPrestamo.SelectedValue.ToEntero(), ImporteMX: ImporteComplementaria, ImporteME: Importe, TipoCambio: TC, TipoCambioPago: TC))
{
MsgError = "No se pudo insertar concepto de bancos complementaria";
}
if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, false, Importe, Ref, CveConceptoContablePrestamoComplementario, Conc, DateTime.Now, CveConceptoContablePrestamoComplementario, -1, CveIE, CvePersonal: DdlFuncionarioEmpleadoPrestamo.SelectedValue.ToEntero(), ImporteMX: ImporteComplementaria, ImporteME: Importe, TipoCambio: TC, TipoCambioPago: TC))
{
MsgError = "No se pudo insertar concepto de acreedor complementaria";
}
}
}
else
{
MsgError = "No se insertó el encabezado";
}
}
else
{
MsgError = "No se pudo insertar la póliza";
}
//VALIDA QUE CUADRE LA POLIZA
if (ObjMov.ValidacionPrePolizaCuadre(CvePrePoliza, 5))
{
if (ObjMov.ValorPolizaDescuadre > 0)
{
MsgError = ObjMov.MensajePolizaDescuadre;
ModExtensiones.GuardaLogAD($"Bancos/IE PAGO ACREEDOR | Error:{ObjMov.MensajePolizaDescuadre} Diferencia:{ObjMov.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas");
}
}
//CONTABILIZA
if (UsuarioActual.Empresa.Funcionalidad(200).Equals("1") && MsgError.Equals(""))
{
if (IDCtaContablePrestamo > 0 && IDCtaContableBancosPrestamo > 0)
{
if (ObjMov.ContabilizarPrePoliza(CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.Empresa))
{
IDPoliza = ObjMov.ContaIdPoliza;
}
else
{
Alert("Ocurrio un error al contabilizar, pongase en contacto con Soporte Técnico", TipoMensaje.MsgError);
}
}
else
{
if (IDCtaContablePrestamo < 1)
{
Alert("No se puede contabilizar la Prepoliza debido a que la cuenta de Acreedor es invalida", TipoMensaje.MsgAdvertencia);
}
if (IDCtaContableBancosPrestamo < 1)
{
Alert("No se puede contabilizar la Prepoliza debido a que la cuenta bancaria es invalida", TipoMensaje.MsgAdvertencia);
}
}
}
if (MsgError.Equals(""))
{
if (Msg.ToString().Equals(""))
{
Msg.Append("El Documento se guardo correctamente");
}
System.IO.FileInfo archivo = null;
if (DdlTipoTransanccionPrestamo.SelectedValue.ToEntero().Contiene(2, 8, 9))
{
archivo = new System.IO.FileInfo(String.Format("{0}Formatos/Transferencia.rdlc", UsuarioActual.Empresa.Ruta));
}
else if (DdlTipoTransanccionPrestamo.SelectedValue.ToEntero().Contiene(1))
{
archivo = new System.IO.FileInfo(String.Format("{0}Formatos/CHQ-{1}.rdlc", UsuarioActual.Empresa.Ruta, DdlCuentaPrestamo.SelectedValue.ToEntero()));
if (!archivo.Exists)
{
archivo = new System.IO.FileInfo(String.Format(@"{0}\Empresas\Grales\Formatos\CHQ.rdlc", ModExtensiones.DirectorioBaseEmpresas));
}
}
else if (DdlTipoTransanccionPrestamo.SelectedValue.ToEntero().Contiene(6) && UsuarioActual.CveEmpresa == 72)
{
archivo = new System.IO.FileInfo(String.Format("{0}Formatos/ComprobanteEgreso.rdlc", UsuarioActual.Empresa.Ruta, DdlCuentaPrestamo.SelectedValue.ToEntero()));
}
if (IDPoliza > 0)
{
Msg.AppendFormat(@"<br/><br/><a class=""Texto"" target='_blank' href=""/Contabilidad/RegPoliza.aspx?IdPoliza={0}"">Ver Póliza</a>", IDPoliza);
}
ObjIE.Commit();
}
else
{
Alert(MsgError, TipoMensaje.MsgError);
ObjIE.RollBack();
}
if (!Msg.ToString().Equals(""))
{
string AccionJS = String.Format(@"document.location.href=""{0}"";", HttpContext.Current.Request.Url.PathAndQuery);
Alert(Msg.ToString(), TipoMensaje.MsgInformacion, String.Format(@"document.location.href=""{0}"";", HttpContext.Current.Request.Url.PathAndQuery));
}
ObjIE.Dispose();
ObjMov.Dispose();
if (ObjComp != null)
ObjComp.Dispose();
}
#endregion
#region"AUXILIAR"
protected void CargaAuxiliar()
{
string FechaI, FechaF;
if (txtFechaI.Text != "")
FechaI = txtFechaI.Text;
else
FechaI = "-1";
if (txtFechaF.Text != "")
FechaF = txtFechaF.Text;
else
FechaF = "-1";
int CvePersonal = -1;
if (DdlFuncionarioEmpleado.SelectedValue.ToEntero() > 0) CvePersonal = DdlFuncionarioEmpleado.SelectedValue.ToEntero();
ClsBancos bancos = new ClsBancos();
if (bancos.GetPersonalPrestamoAuxiliar(CvePersonal, FechaI, FechaF, UsuarioActual.CveEmpresa))
{
GvAuxiliar.DataSource = bancos.DtResultados;
}
bancos.Dispose();
GvAuxiliar.DataBind();
UpAuxiliar.Update();
}
protected void BtnConsultarAuxiliar_Click(object sender, EventArgs e)
{
CargaAuxiliar();
}
#endregion
#region"REPORTE"
protected void CargaReporte()
{
ClsBancos bancos = new ClsBancos();
if (bancos.GetPersonalPrestamoReporte(UsuarioActual.CveEmpresa))
{
GvReporte.DataSource = bancos.DtResultados;
GvReporte.DataBind();
}
bancos.Dispose();
UpReporte.Update();
}
protected void GvReporte_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.DBCampo("CvePersonal") == "") e.Row.CssClass = "SubTotales";
}
}
#endregion
}