Commit inicial Ventas Productivo
This commit is contained in:
385
Ventas/ReporteDetalle.aspx.cs
Normal file
385
Ventas/ReporteDetalle.aspx.cs
Normal file
@@ -0,0 +1,385 @@
|
||||
using System;
|
||||
using Stimulsoft.Report;
|
||||
using Stimulsoft.Report.Dictionary;
|
||||
using Stimulsoft.Report.MobileDesign;
|
||||
using System.Data;
|
||||
using Extensiones;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
|
||||
public partial class Ventas_ReporteDetalle : ClsPaginas
|
||||
{
|
||||
#region P R O P I E D A D E S
|
||||
private StiReport report;
|
||||
private StiReport Reporte
|
||||
{
|
||||
get { return report; }
|
||||
set { report = value; }
|
||||
}
|
||||
|
||||
public DataTable DtReportes1
|
||||
{
|
||||
get { return (DataTable)ViewState["DtReportes1"]; }
|
||||
set { ViewState["DtReportes1"] = value; }
|
||||
}
|
||||
private string Directorio1
|
||||
{
|
||||
get { return UsuarioActual.get_Sesion("Directorio1"); }
|
||||
set { UsuarioActual.set_Sesion("Directorio1", value); }
|
||||
}
|
||||
public int CveReporte
|
||||
{
|
||||
get { return Session["CveReporte"] != null ? Session["CveReporte"].ToString().ToEntero() : -1; }
|
||||
set { Session["CveReporte"] = value; }
|
||||
}
|
||||
public int CveEmpresa
|
||||
{
|
||||
get { return UsuarioActual.get_Sesion("CveEmpresa") != null ? UsuarioActual.get_Sesion("CveEmpresa").ToEntero() : -1; }
|
||||
set { UsuarioActual.set_Sesion("CveEmpresa", value.ToString()); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region F U N C I O N E S
|
||||
private Hashtable Parametros(string cadena)
|
||||
{
|
||||
Hashtable URLParametros = new Hashtable();
|
||||
string[] p1 = cadena.Split('&');
|
||||
string[] p2;
|
||||
foreach (string tmp in p1)
|
||||
{
|
||||
p2 = tmp.Split('=');
|
||||
URLParametros.Add(p2[0].ToString().ToUpper(), p2[1]);
|
||||
}
|
||||
return URLParametros;
|
||||
}
|
||||
private Hashtable getProcedimientos()
|
||||
{
|
||||
Hashtable StoreProcedures = new Hashtable();
|
||||
StringBuilder spVentas = new StringBuilder();
|
||||
StringBuilder spCompras = new StringBuilder();
|
||||
spVentas.Append("EXEC [dbo].[PA_StiReportsVentasGet]");
|
||||
spVentas.AppendFormat("@CveEmpresa = {0} ,", UsuarioActual.CveEmpresa);
|
||||
spVentas.AppendFormat("@Top = {0}", 30);
|
||||
|
||||
spCompras.Append("EXEC [dbo].[PA_StiReportsComprasGet]");
|
||||
spCompras.AppendFormat("@CveEmpresa = {0} ,", UsuarioActual.CveEmpresa);
|
||||
spCompras.AppendFormat("@Top = {0}", 30);
|
||||
|
||||
StoreProcedures.Add("Ventas", spVentas.ToString());
|
||||
StoreProcedures.Add("Compras", spCompras.ToString());
|
||||
return StoreProcedures;
|
||||
}
|
||||
private DataTable DtFacturaDefault1()
|
||||
{
|
||||
DataTable dt = new DataTable();
|
||||
dt.TableName = "Datos";
|
||||
dt.Columns.Add("Cantidad", typeof(Double));
|
||||
dt.Columns.Add("UM", typeof(String));
|
||||
dt.Columns.Add("PS", typeof(String));
|
||||
dt.Columns.Add("PU", typeof(Double));
|
||||
dt.Columns.Add("Total", typeof(Double));
|
||||
|
||||
dt.Rows.Add(1, "Kilos", "Harina", 100000, 200000);
|
||||
dt.Rows.Add(1, "Kilos", "Arroz", 1000, 2000);
|
||||
dt.AcceptChanges();
|
||||
|
||||
return dt;
|
||||
}
|
||||
|
||||
private DataTable DtImpuestos()
|
||||
{
|
||||
DataTable dt = new DataTable();
|
||||
dt.TableName = "Deduccion";
|
||||
dt.Columns.Add("CveImpuestoLocal", typeof(Int32));
|
||||
dt.Columns.Add("ImpuestoLocal", typeof(String));
|
||||
dt.Columns.Add("Porcentaje", typeof(Double));
|
||||
dt.Columns.Add("Importe", typeof(Double));
|
||||
dt.Columns.Add("TipoImpuesto", typeof(Int32));
|
||||
dt.Columns.Add("IdCtaContable", typeof(Int32));
|
||||
dt.Columns.Add("Orden", typeof(Int32));
|
||||
|
||||
dt.Rows.Add(1, "Subtotal", 1.5, (DtFacturaDefault1().SUM("PU") * DtFacturaDefault1().SUM("Cantidad")) * 0.16 , 1,1,1);
|
||||
dt.Rows.Add(2, "IVA", 1.5, ((DtFacturaDefault1().SUM("PU") * DtFacturaDefault1().SUM("Cantidad")) * 0.16) * 0.16, 1, 1, 2);
|
||||
dt.Rows.Add(3, "Total", 1.5, (DtFacturaDefault1().SUM("PU") * DtFacturaDefault1().SUM("Cantidad")) * 0.16 + ((DtFacturaDefault1().SUM("PU") * DtFacturaDefault1().SUM("Cantidad")) * 0.16) * 0.16, 1, 1, 3);
|
||||
dt.AcceptChanges();
|
||||
|
||||
return dt;
|
||||
}
|
||||
#endregion
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsPostBack)
|
||||
{
|
||||
//Cambia el idioma a español
|
||||
SmdDesigner.GlobalizationFile = "Localization/es.xml";
|
||||
//Se utiliza cuando se crea un formato de factura
|
||||
if (Request["Op"] != null && !Request["Op"].ToString().Equals(""))
|
||||
{
|
||||
Hashtable UrlParametros = Parametros(ModExtensiones.Decripta(Request["Op"].ToString()));
|
||||
if (Request["Mod"] != null && Request["Mod"].ToString().Equals("Editar"))
|
||||
{
|
||||
Directorio1 = AppDomain.CurrentDomain.BaseDirectory + string.Format(@"Empresas\{0}\Formatos\Factura.mrt", UrlParametros["CVEEMPRESA"].ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
Directorio1 = AppDomain.CurrentDomain.BaseDirectory + @"Empresas\Grales\Formatos\Factura.mrt";
|
||||
}
|
||||
CargaFactura(Directorio1, UrlParametros);
|
||||
SmdDesigner.Report = Reporte;
|
||||
}
|
||||
//Se utiliza cuando se crea o edita un reporte personalizado
|
||||
if (Request["P"] != null && !Request["P"].ToString().Equals(""))
|
||||
{
|
||||
Hashtable UrlParametros = Parametros(ModExtensiones.Decripta(Request["P"].ToString()));
|
||||
string Tipo = UrlParametros["T"].ToString();
|
||||
CveReporte = UrlParametros["CVEREPORTE"].ToString().ToEntero();
|
||||
int CveEmpresaRef = UrlParametros["E"].ToString().ToEntero();
|
||||
ClsStiReports ObjReportes = new ClsStiReports();
|
||||
if (ObjReportes.GetReportes(UsuarioActual.CveEmpresa, UsuarioActual.CveUsuario, Tipo))
|
||||
{
|
||||
DtReportes1 = ObjReportes.DtResultados;
|
||||
}
|
||||
if (UsuarioActual.CveEmpresa == CveEmpresaRef)
|
||||
{
|
||||
if (CveReporte > 0)
|
||||
{
|
||||
Directorio1 = string.Format("{0}{1}", UsuarioActual.Empresa.Ruta, DtReportes1.FiltroPrimeroValor("Directorio1", string.Format("CveReporte = {0}", CveReporte)));
|
||||
CargaReporte(Directorio1);
|
||||
SmdDesigner.Report = Reporte;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#region C A R G A R E P O R T E S
|
||||
private void CargaReporte(string Directorio1)
|
||||
{
|
||||
FileInfo File = new FileInfo(Directorio1);
|
||||
if (File.Exists && Directorio1.Contains(String.Format(@"Empresas\{0}\", UsuarioActual.CveEmpresa)))
|
||||
{
|
||||
Reporte = new StiReport();
|
||||
Reporte.Load(Directorio1);
|
||||
Reporte.Dictionary.Synchronize();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Carga el formato de factura por defecto
|
||||
/// </summary>
|
||||
/// <param name="Directorio1"></param>
|
||||
private void CargaFactura(string Directorio1, Hashtable UrlParametros)
|
||||
{
|
||||
FileInfo File = new FileInfo(Directorio1);
|
||||
if (File.Exists)
|
||||
{
|
||||
Reporte = new StiReport();
|
||||
Reporte.Load(Directorio1);
|
||||
Reporte.Dictionary.DataSources.Clear();
|
||||
DataSet ds = new DataSet();
|
||||
ds.Tables.Add(DtFacturaDefault1());
|
||||
ds.Tables.Add(DtImpuestos());
|
||||
Reporte.RegData(ds);
|
||||
//Agregar valores a los parametros
|
||||
Reporte.Dictionary.Variables["Empresa"].Value = UrlParametros["EMPRESA"].ToString();
|
||||
Reporte.Dictionary.Variables["Tipo"].Value = "Ingreso";
|
||||
Reporte.Dictionary.Variables["RFC"].Value = UrlParametros["RFC"].ToString();
|
||||
Reporte.Dictionary.Variables["ClienteNombre"].Value = "Benito Juarez";
|
||||
Reporte.Dictionary.Variables["ClienteDireccion"].Value = UrlParametros["DOMICILIO"].ToString();
|
||||
Reporte.Dictionary.Variables["DomicilioExpedicion"].Value = UrlParametros["DOMICILIO"].ToString();
|
||||
double SubtTotal = ((DtFacturaDefault1().SUM("PU") * DtFacturaDefault1().SUM("Cantidad")) * 0.16);
|
||||
double IVA = SubtTotal * 0.16;
|
||||
double Total = SubtTotal + IVA;
|
||||
Reporte.Dictionary.Variables["ImporteLetra"].Value = Total.Texto2Letras();
|
||||
Reporte.Dictionary.Variables["SubTotal"].Value = SubtTotal.ToString();
|
||||
Reporte.Dictionary.Variables["IVA"].Value = IVA.ToString();
|
||||
Reporte.Dictionary.Variables["Total"].Value = Total.ToString();
|
||||
Reporte.Dictionary.Variables["QR"].Value = "lajgkfjsldasdhjsakd229312974tedghjbsadskuuhdkjsad";
|
||||
Reporte.Dictionary.Synchronize();
|
||||
}
|
||||
else
|
||||
{
|
||||
RegistraScript("alert('No hay un formato de factura predefinido,favor de comunicar a soporte tecnico')");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
protected void SmdDesigner_CreateReport(object sender, StiMobileDesigner.StiCreateReportEventArgs e)
|
||||
{
|
||||
|
||||
if (Request["P"] != null && !Request["P"].ToString().Equals(""))
|
||||
{
|
||||
Hashtable UrlParametros = Parametros(ModExtensiones.Decripta(Request["P"].ToString()));
|
||||
//int CveReporte = UrlParametros["CVEREPORTE"].ToString().ToEntero();
|
||||
|
||||
//Obtiene los datos ingresados en el catalogo de reportes
|
||||
string Nombre = UrlParametros["N"] != null ? UrlParametros["N"].ToString() : "Reporte" + UrlParametros["T"].ToString();
|
||||
string Alias = UrlParametros["ALIAS"] != null ? UrlParametros["ALIAS"].ToString() : Nombre;
|
||||
string Descripcion = UrlParametros["ALIAS"] != null ? UrlParametros["ALIAS"].ToString() : "";
|
||||
string Autor = UrlParametros["AUTOR"] != null ? UrlParametros["AUTOR"].ToString() : UsuarioActual.Nombre;
|
||||
|
||||
e.Report.ReportAuthor = Autor;
|
||||
e.Report.ReportFile = Nombre + ".mrt";
|
||||
e.Report.ReportName = Nombre;
|
||||
e.Report.ReportAlias = Alias;
|
||||
e.Report.ReportDescription = Descripcion;
|
||||
e.Report.ReportCacheMode = StiReportCacheMode.On;
|
||||
|
||||
//Checa si ya hay datasource registrados en el reporte
|
||||
if (e.Report.Dictionary.DataSources.Count == 0)
|
||||
{
|
||||
Hashtable Procedimientos = this.getProcedimientos();
|
||||
//Limpia los las conexiones a la base de datos
|
||||
//e.Report.Dictionary.Databases.Clear();
|
||||
//e.Report.Dictionary.DataSources.Clear();
|
||||
|
||||
//Conexiones a la base de datos
|
||||
string Conexion = System.Configuration.ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString;
|
||||
string DBName = !UsuarioActual.Empresa.NombreCorto.Equals("") ? UsuarioActual.Empresa.NombreCorto : "Datos";
|
||||
StiSqlDatabase DataBase = new StiSqlDatabase(DBName, Conexion);
|
||||
StringBuilder Procedimiento = new StringBuilder();
|
||||
StiSqlSource SqlSource = null;
|
||||
string ViewName = "";
|
||||
//Categoria del reporte (ejem: Ventas,Compras etc)
|
||||
string Tipo = UrlParametros["T"].ToString();
|
||||
|
||||
switch (Tipo)
|
||||
{
|
||||
case "Vta":
|
||||
ViewName = "Ventas";
|
||||
SqlSource = new StiSqlSource(DBName, ViewName, ViewName);
|
||||
Procedimiento.Append(Procedimientos["Ventas"].ToString());
|
||||
break;
|
||||
case "Com":
|
||||
ViewName = "Compras";
|
||||
SqlSource = new StiSqlSource(DBName, ViewName, ViewName);
|
||||
Procedimiento.Append(Procedimientos["Compras"].ToString());
|
||||
break;
|
||||
default://Agrega todos los datasources disponibles
|
||||
e.Report.Dictionary.Databases.Add(DataBase);
|
||||
foreach (string PA in Procedimientos.Values)
|
||||
{
|
||||
ViewName = Procedimientos.Keys.OfType<String>().FirstOrDefault(s => Procedimientos[s].Equals(PA));
|
||||
SqlSource = new StiSqlSource(DBName, ViewName, ViewName, PA);
|
||||
e.Report.Dictionary.DataSources.Add(SqlSource);
|
||||
e.Report.Dictionary.Synchronize();
|
||||
SqlSource.SynchronizeColumns();
|
||||
}
|
||||
break;
|
||||
}
|
||||
//Agrega un solo data source
|
||||
if (SqlSource != null && !Tipo.Equals("-1"))
|
||||
{
|
||||
SqlSource.Type = StiSqlSourceType.Table;
|
||||
SqlSource.SqlCommand = Procedimiento.ToString();
|
||||
e.Report.Dictionary.Databases.Add(DataBase);
|
||||
e.Report.Dictionary.DataSources.Add(SqlSource);
|
||||
e.Report.Dictionary.Synchronize();
|
||||
SqlSource.SynchronizeColumns();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void MandaAviso()
|
||||
{
|
||||
const string ScriptKey = "ScriptKey";
|
||||
if (!ClientScript.IsStartupScriptRegistered(this.GetType(), ScriptKey))
|
||||
{
|
||||
StringBuilder fn = new StringBuilder();
|
||||
fn.Append("MandaAviso();");
|
||||
ClientScript.RegisterStartupScript(this.GetType(),ScriptKey, fn.ToString(), true);
|
||||
}
|
||||
}
|
||||
|
||||
protected void SmdDesigner_SaveReport(object sender, StiMobileDesigner.StiSaveReportEventArgs e)
|
||||
{
|
||||
Reporte = e.Report;
|
||||
//Guarda formato de factura
|
||||
if (Request["Op"] != null && !Request["Op"].ToString().Equals(""))
|
||||
{
|
||||
Hashtable UrlParametros = Parametros(ModExtensiones.Decripta(Request["Op"].ToString()));
|
||||
CveEmpresa = UrlParametros["CVEEMPRESA"].ToString().ToEntero();
|
||||
string DirBase = AppDomain.CurrentDomain.BaseDirectory + string.Format(@"Empresas\{0}\Formatos\", CveEmpresa);
|
||||
if (!System.IO.Directory.Exists(DirBase))
|
||||
{
|
||||
System.IO.Directory.CreateDirectory(DirBase);
|
||||
}
|
||||
Directorio1 = string.Format(@"{0}Factura.mrt", DirBase);
|
||||
Reporte.Save(Directorio1);
|
||||
}
|
||||
//Guarda reportes Personalizados
|
||||
if (Request["P"] != null && !Request["P"].ToString().Equals(""))
|
||||
{
|
||||
FileInfo File = null;
|
||||
ClsStiReports ObjReportes = new ClsStiReports();
|
||||
Hashtable UrlParametros = Parametros(ModExtensiones.Decripta(Request["P"].ToString()));
|
||||
string Tipo = UrlParametros["T"].ToString();
|
||||
CveReporte = CveReporte > 0 ? CveReporte : UrlParametros["CVEREPORTE"].ToString().ToEntero();
|
||||
|
||||
//Checa si el reporte es nuevo o se esta editando uno existente
|
||||
if (CveReporte > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ObjReportes.GetReportes(UsuarioActual.CveEmpresa, UsuarioActual.CveUsuario, Tipo))
|
||||
{
|
||||
DtReportes1 = ObjReportes.DtResultados;
|
||||
}
|
||||
Directorio1 = string.Format("{0}{1}", UsuarioActual.Empresa.Ruta, DtReportes1.FiltroPrimeroValor("Directorio1", string.Format("CveReporte = {0}", CveReporte)));
|
||||
File = new FileInfo(Directorio1);
|
||||
if (File.Exists)
|
||||
{
|
||||
Reporte.Save(Directorio1);
|
||||
SmdDesigner.Report.WriteToReportRenderingMessages("Se ha guardado el reporte Exitosamente");
|
||||
SmdDesigner.Page.Alert("Se ha guardado el reporte Exitosamente", ModExtensiones.TipoMensaje.MsgInformacion);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
else//Entra si el reporte es nuevo
|
||||
{
|
||||
//Checa si la empresa contiene la carpeta Personalizados que es donde se guardara el reporte
|
||||
if (!System.IO.Directory.Exists(string.Format(@"{0}Personalizados\", UsuarioActual.Empresa.Ruta)))
|
||||
{
|
||||
System.IO.Directory.CreateDirectory(string.Format(@"{0}Personalizados\", UsuarioActual.Empresa.Ruta));
|
||||
}
|
||||
Directorio1 = string.Format(@"{0}Personalizados\{1}", UsuarioActual.Empresa.Ruta, Reporte.ReportFile);
|
||||
File = new FileInfo(Directorio1);
|
||||
//Si el Reporte es nuevo y el archivo no existe
|
||||
if (CveReporte <= 0 && !File.Exists)
|
||||
{
|
||||
try
|
||||
{
|
||||
string dbPath = string.Format(@"Personalizados\{0}", Reporte.ReportFile);
|
||||
Reporte.Save(Directorio1);
|
||||
this.CveReporte = ObjReportes.AddReporte(Reporte.ReportName, Tipo, dbPath, UsuarioActual.CveEmpresa, UsuarioActual.CveUsuario);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
//Si el reporte nuevo ya se guardo y se quieren guardar modificaciones nuevas
|
||||
else if (CveReporte <= 0 && File.Exists)
|
||||
{
|
||||
Reporte.Save(Directorio1);
|
||||
}
|
||||
}
|
||||
ObjReportes.Dispose();
|
||||
}
|
||||
}
|
||||
protected void SmdDesigner_Exit(object sender, StiMobileDesigner.StiExitEventArgs e)
|
||||
{
|
||||
if (CveReporte > 0)
|
||||
{
|
||||
Response.Redirect(string.Format("/Ventas/Reportes.aspx?CveReporte={0}", CveReporte));
|
||||
}
|
||||
else
|
||||
{
|
||||
Response.Redirect("/Ventas/Reportes.aspx");
|
||||
}
|
||||
this.CveReporte = -1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user