Пример #1
0
        public void ProcessRequest(HttpContext context)
        {
            string sPath           = string.Empty;
            string sNoContrato     = oWeb.GetData("NumContrato");
            string sFileName       = string.Empty;
            string pCodComprobante = oWeb.GetData("pCodComprobante");
            DBConn oConn           = new DBConn();

            if (oConn.Open())
            {
                cComprobanteImpuesto oComprobanteImpuesto = new cComprobanteImpuesto(ref oConn);
                oComprobanteImpuesto.CodComprobante = pCodComprobante;
                DataTable dtComprobante = oComprobanteImpuesto.Get();

                if (dtComprobante != null)
                {
                    if (dtComprobante.Rows.Count > 0)
                    {
                        sFileName = dtComprobante.Rows[0]["nom_comprobante"].ToString();
                    }
                }
                dtComprobante = null;
            }

            System.Web.HttpResponse oResponse = System.Web.HttpContext.Current.Response;

            //sPath = System.Web.HttpContext.Current.Server.MapPath("ComprobantesSII/") + sNoContrato + "/" + sFileName;
            sPath = System.Web.HttpContext.Current.Server.MapPath("rps_licenciatariosmattel/") + sFileName;
            oResponse.AppendHeader("Content-Disposition", "attachment; filename=" + sFileName);

            // Write the file to the Response
            const int bufferLength = 10000;

            byte[] buffer   = new Byte[bufferLength];
            int    length   = 0;
            Stream download = null;

            try
            {
                download = new FileStream(sPath, FileMode.Open, FileAccess.Read);
                do
                {
                    if (oResponse.IsClientConnected)
                    {
                        length = download.Read(buffer, 0, bufferLength);
                        oResponse.OutputStream.Write(buffer, 0, length);
                        buffer = new Byte[bufferLength];
                    }
                    else
                    {
                        length = -1;
                    }
                }while (length > 0);
                oResponse.Flush();
                oResponse.End();
            }
            finally
            {
                if (download != null)
                {
                    download.Close();
                }
            }
        }
        protected DataTable getResumenContratos()
        {
            ResumenContrato oResumenContrato = new ResumenContrato();

            oResumenContrato.getMakeTable();

            DBConn oConn = new DBConn();

            if (oConn.Open())
            {
                cContratos oContratos = new cContratos(ref oConn);
                oContratos.Aprobado = true;
                //oContratos.AnoTermino = cmbox_ano.SelectedValue;
                DataTable dtContrato = oContratos.GetForResumen();
                if (dtContrato != null)
                {
                    foreach (DataRow oRow in dtContrato.Rows)
                    {
                        oResumenContrato.Licenciatario = oRow["licenciatario"].ToString();
                        oResumenContrato.NoContrato    = oRow["no_contrato"].ToString();
                        oResumenContrato.Inicio        = DateTime.Parse(oRow["fech_inicio"].ToString()).ToString("dd/MM/yyyy");
                        oResumenContrato.Final         = DateTime.Parse(oRow["fech_termino"].ToString()).ToString("dd/MM/yyyy");
                        oResumenContrato.PorVencer     = string.Empty;

                        string sMesPeriodo   = string.Empty;
                        string sFechaPeriodo = string.Empty;

                        string sNumFactura      = string.Empty;
                        string sFechFactura     = string.Empty;
                        string sFechComprobante = string.Empty;

                        cReporteVenta oReporteVenta = new cReporteVenta(ref oConn);
                        oReporteVenta.InMesReporte = sMeses;
                        oReporteVenta.AnoReporte   = cmbox_ano.SelectedValue;
                        oReporteVenta.NumContrato  = oRow["num_contrato"].ToString();
                        oReporteVenta.OrderMes     = true;
                        DataTable dtReporteVenta = oReporteVenta.GetResumenContrato();
                        if (dtReporteVenta != null)
                        {
                            sNumFactura      = string.Empty;
                            sFechFactura     = string.Empty;
                            sFechComprobante = string.Empty;

                            oResumenContrato.MesFechaUno  = null;
                            oResumenContrato.MesFechaDos  = null;
                            oResumenContrato.MesFechaTres = null;
                            if (dtReporteVenta.Rows.Count > 0)
                            {
                                foreach (DataRow oRowVenta in dtReporteVenta.Rows)
                                {
                                    sMesPeriodo   = (string.IsNullOrEmpty(sMesPeriodo) ? oRowVenta["mes_reporte"].ToString() : sMesPeriodo + ',' + oRowVenta["mes_reporte"].ToString());
                                    sFechaPeriodo = (string.IsNullOrEmpty(sFechaPeriodo) ? oRowVenta["fecha_reporte"].ToString() : sFechaPeriodo + ',' + oRowVenta["fecha_reporte"].ToString());
                                }

                                string[] sMes           = sMeses.Split(',');
                                string[] sMesArrPeriodo = sMesPeriodo.Split(',');
                                string[] sFechPeriodo   = sFechaPeriodo.Split(',');

                                oResumenContrato.MesFechaUno  = string.Empty;
                                oResumenContrato.MesFechaDos  = string.Empty;
                                oResumenContrato.MesFechaTres = string.Empty;

                                for (int i = 0; i < sMesArrPeriodo.Length; i++)
                                {
                                    if (sMes[0].ToString() == sMesArrPeriodo[i].ToString())
                                    {
                                        oResumenContrato.MesFechaUno = DateTime.Parse(sFechPeriodo[i]).ToString("dd/MM/yyyy");
                                    }
                                    if (sMes[1].ToString() == sMesArrPeriodo[i].ToString())
                                    {
                                        oResumenContrato.MesFechaDos = DateTime.Parse(sFechPeriodo[i]).ToString("dd/MM/yyyy");
                                    }
                                    if (sMes[2].ToString() == sMesArrPeriodo[i].ToString())
                                    {
                                        oResumenContrato.MesFechaTres = DateTime.Parse(sFechPeriodo[i]).ToString("dd/MM/yyyy");
                                    }
                                }

                                cFactura oFactura = new cFactura(ref oConn);
                                oFactura.NumContrato = oRow["num_contrato"].ToString();
                                oFactura.Periodo     = cmbox_periodo.SelectedValue + "/" + cmbox_ano.SelectedValue;
                                DataTable dtFactura = oFactura.Get();
                                if (dtFactura != null)
                                {
                                    if (dtFactura.Rows.Count > 0)
                                    {
                                        sNumFactura  = dtFactura.Rows[0]["num_invoice"].ToString();
                                        sFechFactura = DateTime.Parse(dtFactura.Rows[0]["date_invoce"].ToString()).ToString("dd/MM/yyyy");

                                        if (!string.IsNullOrEmpty(dtFactura.Rows[0]["cod_comprobante"].ToString()))
                                        {
                                            cComprobanteImpuesto oComprobanteImpuesto = new cComprobanteImpuesto(ref oConn);
                                            oComprobanteImpuesto.CodComprobante = dtFactura.Rows[0]["cod_comprobante"].ToString();
                                            DataTable dtComprobante = oComprobanteImpuesto.Get();
                                            if (dtComprobante != null)
                                            {
                                                if (dtComprobante.Rows.Count > 0)
                                                {
                                                    sFechComprobante = DateTime.Parse(dtComprobante.Rows[0]["fecha_declaracion"].ToString()).ToString("dd/MM/yyyy");
                                                }
                                            }
                                            dtComprobante = null;
                                        }
                                    }
                                }
                                dtFactura = null;
                            }
                            dtReporteVenta = null;
                        }

                        oResumenContrato.NumInvoce       = sNumFactura;
                        oResumenContrato.FechFactura     = sFechFactura;
                        oResumenContrato.FechComprobante = sFechComprobante;

                        oResumenContrato.AddRow();
                    }
                }
                dtContrato = null;
            }
            oConn.Close();
            DataTable dtResumenContrato = oResumenContrato.Get();

            return(dtResumenContrato);
        }
Пример #3
0
        protected void btnGuardar_Click(object sender, EventArgs e)
        {
            string FileName        = string.Empty;
            string FilePath        = string.Empty;
            string sNoContrato     = string.Empty;
            string sPeriodo        = ddlmesventa.Items[ddlmesventa.SelectedIndex].Text.ToUpper();
            string pCodComprobante = string.Empty;

            try
            {
                DBConn oConn = new DBConn();
                if (oConn.Open())
                {
                    cContratos oContrato = new cContratos(ref oConn);
                    oContrato.NumContrato = cmbox_contrato.SelectedValue;
                    DataTable tbContrato = oContrato.Get();
                    if (tbContrato != null)
                    {
                        if (tbContrato.Rows.Count > 0)
                        {
                            sNoContrato = tbContrato.Rows[0]["no_contrato"].ToString();
                        }
                    }
                    tbContrato = null;
                }
                oConn.Close();

                if (chkbox_declaracion.Checked)
                {
                    bool bExito = false;
                    if (RadUpload1.UploadedFiles.Count > 0)
                    {
                        oConn = new DBConn();
                        if (oConn.Open())
                        {
                            foreach (UploadedFile ofile in RadUpload1.UploadedFiles)
                            {
                                //string FileName = ofile.GetName();
                                FileName = cmbox_contrato.SelectedValue + "_" + ddlmesventa.Items[ddlmesventa.SelectedIndex].Text.Replace("/", "_") + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf";
                                //FilePath = FilePath + FileName;
                                //FilePath = Server.MapPath("rps_licenciatariosmattel/") + cmbox_contrato.Items[cmbox_contrato.SelectedIndex].Text + "\\" + FileName;
                                //if (!Directory.Exists(Server.MapPath("rps_licenciatariosmattel/") + cmbox_contrato.Items[cmbox_contrato.SelectedIndex].Text + "\\"))
                                //  Directory.CreateDirectory(Server.MapPath("rps_licenciatariosmattel/") + cmbox_contrato.Items[cmbox_contrato.SelectedIndex].Text + "\\");

                                FilePath = Server.MapPath("rps_licenciatariosmattel/") + "\\" + FileName;
                                if (!Directory.Exists(Server.MapPath("rps_licenciatariosmattel/") + "\\"))
                                {
                                    Directory.CreateDirectory(Server.MapPath("rps_licenciatariosmattel/") + "\\");
                                }

                                ofile.SaveAs(FilePath);

                                cComprobanteImpuesto oComprobanteImpuesto = new cComprobanteImpuesto(ref oConn);
                                oComprobanteImpuesto.NumContrato        = cmbox_contrato.SelectedValue;
                                oComprobanteImpuesto.Periodo            = ddlmesventa.Items[ddlmesventa.SelectedIndex].Text;
                                oComprobanteImpuesto.NomComprobante     = FileName;
                                oComprobanteImpuesto.DeclaraMovimiento  = "S";
                                oComprobanteImpuesto.RepositorioArchivo = "L";
                                oComprobanteImpuesto.Accion             = "CREAR";
                                oComprobanteImpuesto.Put();

                                cFactura oFactura = new cFactura(ref oConn);
                                oFactura.CodFactura     = ddlmesventa.SelectedValue;
                                oFactura.CodComprobante = oComprobanteImpuesto.CodComprobante;
                                oFactura.Accion         = "EDITAR";
                                oFactura.Put();

                                if (string.IsNullOrEmpty(oComprobanteImpuesto.Error))
                                {
                                    pCodComprobante = oComprobanteImpuesto.CodComprobante;
                                    bExito          = true;
                                }
                            }
                            oConn.Close();
                        }
                    }

                    if (bExito)
                    {
                        oConn = new DBConn();
                        if (oConn.Open())
                        {
                            cLogEventos oLogEventos = new cLogEventos(ref oConn);
                            oLogEventos.AccionLog           = "SUBIR ARCHIVO COMPROBANTE DE IMPUESTO";
                            oLogEventos.CodCanal            = "2";
                            oLogEventos.CodFlujo            = "3";
                            oLogEventos.NomFlujo            = "COMPROBANTE DE IMPUESTO";
                            oLogEventos.ArchLog             = FileName;
                            oLogEventos.NumContrato         = cmbox_contrato.SelectedValue;
                            oLogEventos.NoContrato          = sNoContrato;
                            oLogEventos.PeriodoLog          = sPeriodo;
                            oLogEventos.RutDeudor           = oUsuario.RutLicenciatario;
                            oLogEventos.CodUser             = oUsuario.CodUsuario;
                            oLogEventos.RutUser             = oUsuario.RutUsuario;
                            oLogEventos.NomUser             = oUsuario.Nombres;
                            oLogEventos.ObsLog              = "Se a cargado el archivo de comprobante de impuesto con éxito.";
                            oLogEventos.IpLog               = oWeb.GetIpUsuario();
                            oLogEventos.IndReporsitorioArch = "L";
                            oLogEventos.Accion              = "CREAR";
                            oLogEventos.Put();
                        }
                        oConn.Close();

                        StringBuilder js = new StringBuilder();
                        js.Append("function LgRespuesta() {");
                        js.Append(" window.radalert('El comprobante pago de impuesto a sido cargado con éxito.', 330, 210); ");
                        js.Append(" Sys.Application.remove_load(LgRespuesta); ");
                        js.Append("};");
                        js.Append("Sys.Application.add_load(LgRespuesta);");
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "radalert", js.ToString(), true);

                        chkbox_declaracion.Checked = false;
                        ddlmesventa.Items.Clear();
                        cmbox_contrato.Items.Clear();
                        loadContrato();
                    }
                }
                else
                {
                    oConn = new DBConn();
                    if (oConn.Open())
                    {
                        cComprobanteImpuesto oComprobanteImpuesto = new cComprobanteImpuesto(ref oConn);
                        oComprobanteImpuesto.NumContrato       = cmbox_contrato.SelectedValue;
                        oComprobanteImpuesto.Periodo           = ddlmesventa.Items[ddlmesventa.SelectedIndex].Text;
                        oComprobanteImpuesto.NomComprobante    = string.Empty;
                        oComprobanteImpuesto.DeclaraMovimiento = "N";
                        oComprobanteImpuesto.Accion            = "CREAR";
                        oComprobanteImpuesto.Put();

                        cFactura oFactura = new cFactura(ref oConn);
                        oFactura.CodFactura     = ddlmesventa.SelectedValue;
                        oFactura.CodComprobante = oComprobanteImpuesto.CodComprobante;
                        oFactura.Accion         = "EDITAR";
                        oFactura.Put();

                        chkbox_declaracion.Checked = false;
                        ddlmesventa.Items.Clear();
                        cmbox_contrato.Items.Clear();
                        loadContrato();

                        oConn = new DBConn();
                        if (oConn.Open())
                        {
                            cLogEventos oLogEventos = new cLogEventos(ref oConn);
                            oLogEventos.AccionLog   = "SE DECLARA EL PERIODO SIN MOVIMIENTOS";
                            oLogEventos.CodCanal    = "2";
                            oLogEventos.CodFlujo    = "3";
                            oLogEventos.NomFlujo    = "COMPROBANTE DE IMPUESTO";
                            oLogEventos.NumContrato = cmbox_contrato.SelectedValue;
                            oLogEventos.NoContrato  = sNoContrato;
                            oLogEventos.PeriodoLog  = sPeriodo + " / " + ViewState["ano_reporte"].ToString();
                            oLogEventos.RutDeudor   = oUsuario.RutLicenciatario;
                            oLogEventos.CodUser     = oUsuario.CodUsuario;
                            oLogEventos.RutUser     = oUsuario.RutUsuario;
                            oLogEventos.NomUser     = oUsuario.Nombres;
                            oLogEventos.ObsLog      = "Se a declarado el periodo sin movimientos con éxito.";
                            oLogEventos.IpLog       = oWeb.GetIpUsuario();
                            oLogEventos.Accion      = "CREAR";
                            oLogEventos.Put();
                        }
                        oConn.Close();

                        StringBuilder js = new StringBuilder();
                        js.Append("function LgRespuesta() {");
                        js.Append(" window.radalert('Se ha declarado el periodo sin movimientos con éxito.', 330, 210); ");
                        js.Append(" Sys.Application.remove_load(LgRespuesta); ");
                        js.Append("};");
                        js.Append("Sys.Application.add_load(LgRespuesta);");
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "radalert", js.ToString(), true);
                    }
                    oConn.Close();
                }
            }
            catch (Exception Ex)
            {
                DBConn oConn = new DBConn();
                if (oConn.Open())
                {
                    cLogEventos oLogEventos = new cLogEventos(ref oConn);
                    oLogEventos.AccionLog   = "ERROR SUBIR ARCHIVO COMPROBANTE DE IMPUESTO";
                    oLogEventos.CodCanal    = "2";
                    oLogEventos.CodFlujo    = "3";
                    oLogEventos.NomFlujo    = "COMPROBANTE DE IMPUESTO";
                    oLogEventos.PeriodoLog  = sPeriodo;
                    oLogEventos.RutDeudor   = oUsuario.RutLicenciatario;
                    oLogEventos.CodUser     = oUsuario.CodUsuario;
                    oLogEventos.RutUser     = oUsuario.RutUsuario;
                    oLogEventos.NomUser     = oUsuario.Nombres;
                    oLogEventos.ObsErrorLog = Ex.Message + " / " + Ex.Source;
                    oLogEventos.IpLog       = oWeb.GetIpUsuario();
                    oLogEventos.Accion      = "CREAR";
                    oLogEventos.Put();
                }
                oConn.Close();

                Session["Error"] = "Error en la carga de archivo de comprobante de impuesto. Por favor comuniquese con el administrador.";
                Response.Redirect("error_ingreso_venta.aspx?sTypeError=2", true);
            }
        }