Ejemplo n.º 1
0
        private void CargarDatos()
        {
            try
            {
                DataSet            dsDocumento        = new DataSet();
                SocioLineaPagDocBE SocioLineaPagDocBE = new SocioLineaPagDocBE()
                {
                    OPCION     = 4,
                    USUARIO    = General.General.GetCodigoUsuario,
                    IdLinea    = cboIdLinea.SelectedValue.ToString(),
                    IdPagadora = _IdPagadora
                };
                dsDocumento             = new SocioLineaPagDocBL().ProcesarSocioLineaPagDoc(SocioLineaPagDocBE);
                dgvDocumento.DataSource = dsDocumento.Tables[0];

                ////Plazos y Tasas
                DataSet dsPlazo = new DataSet();
                LstSocioLineaPagPlazo = new BindingList <SocioLineaPagPlazoBE>();
                SocioLineaPagPlazoBE SocioLineaPagPlazoBE = new SocioLineaPagPlazoBE()
                {
                    OPCION  = 4,
                    USUARIO = General.General.GetCodigoUsuario,
                    IdLinea = cboIdLinea.SelectedValue.ToString()
                };
                dsPlazo = new SocioLineaPagPlazoBL().ProcesarSocioLineaPagPlazo(SocioLineaPagPlazoBE);

                if (dsPlazo.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < dsPlazo.Tables[0].Rows.Count; i++)
                    {
                        SocioLineaPagPlazoBE oSocioLineaPagPlazoBE = new SocioLineaPagPlazoBE()
                        {
                            IdItem         = dsPlazo.Tables[0].Rows[i]["IdItem"].ToString(),
                            IdPagadora     = dsPlazo.Tables[0].Rows[i]["IdPagadora"].ToString(),
                            IdDocumento    = dsPlazo.Tables[0].Rows[i]["IdDocumento"].ToString(),
                            nPlazo         = Decimal.Parse(dsPlazo.Tables[0].Rows[i]["nPlazo"].ToString()),
                            nTasa          = Decimal.Parse(dsPlazo.Tables[0].Rows[i]["nTasa"].ToString()),
                            nTasaSobregiro = Decimal.Parse(dsPlazo.Tables[0].Rows[i]["nTasaSobregiro"].ToString())
                        };
                        LstSocioLineaPagPlazo.Add(oSocioLineaPagPlazoBE);
                    }
                }

                dgvDocumento_CellClick(null, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public DataSet ProcesarSocioLineaPagDoc(SocioLineaPagDocBE BE)
        {
            DataSet dsResult;

            try
            {
                cmd = db.GetStoredProcCommand("SocioLineaPagDoc_Mnt");
                db.AddInParameter(cmd, "OPCION", DbType.Int32, BE.OPCION);
                db.AddInParameter(cmd, "USUARIO", DbType.String, BE.USUARIO);
                db.AddInParameter(cmd, "IdLinea", DbType.String, BE.IdLinea);
                db.AddInParameter(cmd, "IdPagadora", DbType.String, BE.IdPagadora);
                db.AddInParameter(cmd, "IdDocumento", DbType.String, BE.IdDocumento);
                db.AddInParameter(cmd, "nFondoGarantia", DbType.Decimal, BE.nFondoGarantia);
                db.AddInParameter(cmd, "IdTipoConfirmacion", DbType.String, BE.IdTipoConfirmacion);
                db.AddInParameter(cmd, "bInteres", DbType.Boolean, BE.bInteres);
                dsResult = db.ExecuteDataSet(cmd);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(dsResult);
        }
        private void LectorXML(String file_path, int Contador)
        {
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(file_path);
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
                nsmgr.AddNamespace("tns", "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2");
                nsmgr.AddNamespace("cac", "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2");
                nsmgr.AddNamespace("cbc", "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2");

                XmlNode node    = xmlDoc.SelectSingleNode("/tns:Invoice/cbc:UBLVersionID", nsmgr); //Version
                string  Version = node.InnerText.ToString();

                string strRucSocio     = string.Empty;                                                                                                   //RUC Socio
                string strRucPagadora  = string.Empty;                                                                                                   //RUC Pagadora
                string strFechaEmision = xmlDoc.SelectSingleNode("/tns:Invoice/cbc:IssueDate", nsmgr).InnerText;                                         //Fecha de Emision
                string strNroDoc       = xmlDoc.SelectSingleNode("/tns:Invoice/cac:Signature/cbc:ID", nsmgr).InnerText;                                  //Serie y número
                string strMoneda       = xmlDoc.SelectSingleNode("/tns:Invoice/cac:LegalMonetaryTotal/cbc:PayableAmount//@currencyID", nsmgr).InnerText; //Moneda
                string strImpuesto     = xmlDoc.SelectSingleNode("/tns:Invoice/cac:TaxTotal/cbc:TaxAmount", nsmgr).InnerText;                            //Impuesto
                string strMonto        = xmlDoc.SelectSingleNode("/tns:Invoice/cac:LegalMonetaryTotal/cbc:PayableAmount", nsmgr).InnerText;              //Monto

                if (Version.Equals("2.0"))
                {
                    strRucSocio    = xmlDoc.SelectSingleNode("/tns:Invoice/cac:AccountingSupplierParty//cbc:CustomerAssignedAccountID", nsmgr).InnerText; //RUC Socio
                    strRucPagadora = xmlDoc.SelectSingleNode("/tns:Invoice/cac:AccountingCustomerParty//cbc:CustomerAssignedAccountID", nsmgr).InnerText; //RUC Pagadora
                }
                else if (Version.Equals("2.1"))
                {
                    strRucSocio    = xmlDoc.SelectSingleNode("/tns:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyIdentification/cbc:ID", nsmgr).InnerText; //RUC Socio
                    strRucPagadora = xmlDoc.SelectSingleNode("/tns:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PartyIdentification/cbc:ID", nsmgr).InnerText; //RUC Pagadora
                }
                else
                {
                    MessageBox.Show("Versión del XML no soportada - " + Version, "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (Contador == 0)
                {
                    if (!ObtenerLinea(strRucSocio, strMoneda))
                    {
                        Contador    = 1;
                        IdLinea     = string.Empty;
                        IdMoneda_tt = string.Empty;
                        txtIdSocio.Clear();
                        txtIdSocio_Dsc.Clear();
                        txtIdLinea_Dsc.Clear();
                        txtIdMoneda_tt_Dsc.Clear();
                        txtFecha.Clear();
                        txtIdTipoLinea_tt_Dsc.Clear();
                        txtCarpetaXML.Clear();
                        IdFormaDesembolso = 0;
                        MessageBox.Show("No se encontro ninguna linea del socio, por favor verifique.", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        IsError = true;
                        return;
                    }
                }

                string     IdPagadora     = string.Empty;
                string     IdPagadora_Dsc = string.Empty;
                PagadoraBE oEntityPag     = new PagadoraBE()
                {
                    OPCION = 1,
                    vcRuc  = strRucPagadora
                };
                DataSet dsPag = new PagadoraBL().ProcesarPagadora(oEntityPag);

                if (dsPag.Tables[0].Rows.Count > 0)
                {
                    IdPagadora     = dsPag.Tables[0].Rows[0]["IdPagadora"].ToString();
                    IdPagadora_Dsc = dsPag.Tables[0].Rows[0]["vcPagadora"].ToString();
                }

                DocumentoBE oEntityDoc = new DocumentoBE()
                {
                    OPCION      = 4,
                    IdDocumento = "00010"
                };
                DataSet dsDoc = new DocumentoBL().ProcesarDocumento(oEntityDoc);

                string IdDocumento_Dsc = string.Empty;
                if (dsDoc.Tables[0].Rows.Count > 0)
                {
                    IdDocumento_Dsc = dsDoc.Tables[0].Rows[0]["cAbreviatura"].ToString();
                }

                SocioLineaPagDocBE oEntityPagDoc = new SocioLineaPagDocBE();
                oEntityPagDoc.OPCION      = 1;
                oEntityPagDoc.IdLinea     = IdLinea;
                oEntityPagDoc.IdPagadora  = IdPagadora;
                oEntityPagDoc.IdDocumento = "00010"; // Factura Electronica
                DataSet dsPagDoc = new SocioLineaPagDocBL().ProcesarSocioLineaPagDoc(oEntityPagDoc);

                string IdTipoConfirmacion_Dsc = string.Empty;
                if (dsPagDoc.Tables[0].Rows.Count > 0)
                {
                    IdTipoConfirmacion_Dsc = dsPagDoc.Tables[0].Rows[0]["IdTipoConfirmacion_Dsc"].ToString();
                }

                FEXMLBE IEntity = new FEXMLBE()
                {
                    IdPagadora              = IdPagadora,
                    IdPagadora_Dsc          = IdPagadora_Dsc,
                    RUC                     = strRucPagadora,
                    IdDocumento             = "00010", // Factura Electronica
                    IdDocumento_Dsc         = IdDocumento_Dsc,
                    IdTipoConfirmacion_Dsc  = IdTipoConfirmacion_Dsc,
                    cNumDoc                 = strNroDoc,
                    nvNominal               = Convert.ToDecimal(strMonto),
                    nvNegociable            = 0,
                    Mensaje                 = string.Empty,
                    IdSocio_BeneficiarioRuc = _IdSocio_BeneficiarioRuc
                };
                LstEntityFE.Add(IEntity);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnImportar_Click(object sender, EventArgs e)
        {
            string srutaArchivo = string.Empty;

            openFileDialog1.InitialDirectory = @"C:\";
            openFileDialog1.Filter           = "Archivos de Excel (*.xls) |*.xlsx";
            openFileDialog1.FilterIndex      = 2;
            openFileDialog1.RestoreDirectory = true;
            openFileDialog1.FileName         = "";

            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                srutaArchivo = openFileDialog1.FileName;

                try
                {
                    msgHelper.Wait("Cargando registros, espere un momento ...");
                    cnExcel = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + srutaArchivo + ";Extended Properties='Excel 12.0 Xml;HDR=YES';");

                    if (cnExcel.State == ConnectionState.Closed)
                    {
                        cnExcel.Open();
                    }

                    if (!System.IO.File.Exists(srutaArchivo))
                    {
                        MessageBox.Show("No se encontró el Libro: " + srutaArchivo, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    //daExcel = new OleDbDataAdapter("Select N_Cartera, CodClasifCar, NomClasifCar, DireccionClasifCar, " + "CodDeudorCar, '0' & TipoIdentidad as TipoIdentidad, NroIdentidad, APELLIDOSYNOMBRES, DIRECCION, DISTRITO, " + _();
                    //"PROVINCIA, DEPARTAMENTO, CODPOSTAL, TELFDOM, TELFMOV, EmpLaboral, EmpDireccion, " + "EmpDistrito, TelfLab, Sexo, Fch_nacimiento, N_Operacion, Fec_Emis, Cap_Orig, Sal_Cap, " + "InteresMor, InteresComp, Honorarios, Gastos, Pagos, Deuda_Total, IIf (Moneda='S','001',IIf (Moneda='D','002',Moneda)) as Moneda , Fec_Venc, " +
                    //"Fec_Jud, Conyugue, ANombre, ADireccion, ADistrito, Atelefono, AEmpLaboral, AEmpDireccion, " + "AEmpDistrito, AEmpTelefono, Fecha_Asig, Tipo_Cart, Producto_Orig_Deuda, LoginGA, Oficina " + "From [Data$A1:AV20000] ", cnExcel);

                    OleDbDataAdapter daExcel = new OleDbDataAdapter("Select * " +
                                                                    "From [Carga$A1:Q20000] ", cnExcel);

                    DataTable dtTable = new DataTable();
                    daExcel.Fill(dtTable);

                    //Valida que no se repita el numero de documento en la carga de datos
                    foreach (DataRow row in dtTable.Rows)
                    {
                        if (!string.IsNullOrEmpty(row["RUCPAGADORA"].ToString().Trim()))
                        {
                            string IdDocumento = row["TIPODOCUMENTO"].ToString();
                            string cNumDoc     = row["NroDOCUMENTO"].ToString();
                            string RucPagadora = row["RUCPAGADORA"].ToString();

                            //Buscar en el datatable
                            DataRow[] drResult = dtTable.Select("TIPODOCUMENTO = '" + IdDocumento + "' and NroDOCUMENTO = '" + cNumDoc + "' and RUCPAGADORA = '" + RucPagadora + "'");

                            if (drResult.Length > 1)
                            {
                                MessageBox.Show("El documento " + cNumDoc + " de la pagadora " + RucPagadora + " se está duplicando en la importación de datos.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                msgHelper.Wait();
                                return;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }

                    int Contador = 0;
                    foreach (DataRow row in dtTable.Rows)
                    {
                        if (!string.IsNullOrEmpty(row["RUCPAGADORA"].ToString().Trim()))
                        {
                            if (Contador == 0)
                            {
                                if (!ObtenerLinea(row["RUCSOCIO"].ToString(), row["TIPOMONEDA"].ToString()))
                                {
                                    IdLinea     = string.Empty;
                                    IdMoneda_tt = string.Empty;
                                    txtIdSocio.Clear();
                                    txtIdSocio_Dsc.Clear();
                                    txtIdLinea_Dsc.Clear();
                                    txtIdMoneda_tt_Dsc.Clear();
                                    txtFecha.Clear();
                                    txtIdTipoLinea_tt_Dsc.Clear();
                                    txtCarpetaXML.Clear();
                                    IdFormaDesembolso = 0;
                                    MessageBox.Show("No se encontro ninguna linea del socio, por favor verifique.", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    IsError = true;
                                    return;
                                }
                            }

                            string     IdPagadora     = string.Empty;
                            string     IdPagadora_Dsc = string.Empty;
                            PagadoraBE oEntityPag     = new PagadoraBE()
                            {
                                OPCION = 1,
                                vcRuc  = row["RUCPAGADORA"].ToString().Trim()
                            };
                            DataSet dsPag = new PagadoraBL().ProcesarPagadora(oEntityPag);

                            if (dsPag.Tables[0].Rows.Count > 0)
                            {
                                IdPagadora     = dsPag.Tables[0].Rows[0]["IdPagadora"].ToString();
                                IdPagadora_Dsc = dsPag.Tables[0].Rows[0]["vcPagadora"].ToString();
                            }

                            DocumentoBE oEntityDoc = new DocumentoBE()
                            {
                                OPCION      = 4,
                                IdDocumento = row["TIPODOCUMENTO"].ToString()
                            };
                            DataSet dsDoc = new DocumentoBL().ProcesarDocumento(oEntityDoc);

                            string IdDocumento_Dsc = string.Empty;
                            if (dsDoc.Tables[0].Rows.Count > 0)
                            {
                                IdDocumento_Dsc = dsDoc.Tables[0].Rows[0]["cAbreviatura"].ToString();
                            }

                            SocioLineaPagDocBE oEntityPagDoc = new SocioLineaPagDocBE();
                            oEntityPagDoc.OPCION      = 1;
                            oEntityPagDoc.IdLinea     = IdLinea;
                            oEntityPagDoc.IdPagadora  = IdPagadora;
                            oEntityPagDoc.IdDocumento = row["TIPODOCUMENTO"].ToString();
                            DataSet dsPagDoc = new SocioLineaPagDocBL().ProcesarSocioLineaPagDoc(oEntityPagDoc);

                            string IdTipoConfirmacion_Dsc = string.Empty;
                            if (dsPagDoc.Tables[0].Rows.Count > 0)
                            {
                                IdTipoConfirmacion_Dsc = dsPagDoc.Tables[0].Rows[0]["IdTipoConfirmacion_Dsc"].ToString();
                            }

                            FEXMLBE IEntity = new FEXMLBE()
                            {
                                IdPagadora              = IdPagadora,
                                IdPagadora_Dsc          = IdPagadora_Dsc,
                                RUC                     = row["RUCPAGADORA"].ToString().Trim(),
                                IdDocumento             = row["TIPODOCUMENTO"].ToString(),
                                IdDocumento_Dsc         = IdDocumento_Dsc,
                                cNumDoc                 = row["NroDOCUMENTO"].ToString(),
                                sdVencimiento           = Convert.ToDateTime(row["FECHAPAGO"]),
                                nvNominal               = Convert.ToDecimal(row["IMPORTENETODEPAGO"]),
                                nvNegociable            = Convert.ToDecimal(row["IMPORTENETODEPAGO"]),
                                IdTipoConfirmacion_Dsc  = IdTipoConfirmacion_Dsc,
                                IdSocio_BeneficiarioRuc = _IdSocio_BeneficiarioRuc,
                                Mensaje                 = string.Empty
                            };
                            LstEntityFE.Add(IEntity);
                            Contador++;
                        }
                    }

                    dgvFEDetalle.DataSource = LstEntityFE.ToList();
                    lblnroRegistros.Text    = LstEntityFE.Count() + " registro(s)";
                    OrigenLote = 1;
                    cnExcel.Close();
                    //btnImportar.Enabled = false;
                    msgHelper.Wait();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    cnExcel.Close();
                    msgHelper.Wait();
                }
            }
        }
Ejemplo n.º 5
0
 public DataSet ProcesarSocioLineaPagDoc(SocioLineaPagDocBE BE)
 {
     return(SocioLineaPagDocDA.ProcesarSocioLineaPagDoc(BE));
 }