Commit inicial Ventas Productivo

This commit is contained in:
JORGE LUIS CAUDILLO ESPARZA
2019-08-14 16:40:54 -07:00
commit c35cf91883
13328 changed files with 3711549 additions and 0 deletions

View File

@@ -0,0 +1,421 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using Extensiones;
using System.Data;
using Microsoft.Reporting.WebForms;
//using Extensiones;
public partial class CGame_AsignacionEmpaque : ClsPaginas
{
#region PROPIEDADES
private DataTable DtCant
{
get { return DtCant = (DataTable)ViewState["DtCant"]; }
set { ViewState["DtCant"] = value; }
}
private DataTable DtBins
{
get { return DtBins = (DataTable)ViewState["DtBins"]; }
set { ViewState["DtBins"] = value; }
}
private DataTable DtCajas
{
get { return DtCajas = (DataTable)ViewState["DtCajas"]; }
set { ViewState["DtCajas"] = value; }
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CreaDtCant();
CargaFiltros();
CargaResultado();
}
}
#region "CARGA DATOS"
protected void CreaDtCant()
{
DtCant = new DataTable();
DtCant.Columns.Add("CveOrdenProduccionDetalle");
DtCant.Columns.Add("CantRest");
}
protected void CargaFiltros()
{
ClsCGame ObjCGame = new ClsCGame();
int CveEmpresa = UsuarioActual.CveEmpresa;
if (ObjCGame.GetHuerta(CveEmpresa))
{
DdlHuerta.DataSource = ObjCGame.DtResultados;
DdlHuerta.DataBind();
}
if (ObjCGame.GetPS(CveEmpresa))
{
DdlFruto.DataSource = ObjCGame.DtResultados;
DdlFruto.DataBind();
}
if (ObjCGame.GetTipoMaduracion(-1, -1, -1, CveEmpresa))
{
DdlVariedad.DataSource = ObjCGame.DtResultados;
DdlVariedad.DataBind();
}
if (ObjCGame.GetTipoProducto(CveEmpresa))
{
DdlTipoProduccion.DataSource = ObjCGame.DtResultados;
DdlTipoProduccion.DataBind();
}
if (ObjCGame.GetTamaños(CveEmpresa))
{
DdlTamaño.DataSource = ObjCGame.DtResultados;
DdlTamaño.DataBind();
}
if (ObjCGame.GetCalidad(CveEmpresa))
{
DdlCalidad.DataSource = ObjCGame.DtResultados;
DdlCalidad.DataBind();
}
if (ObjCGame.GetTipoCaja(CveEmpresa))
{
DdlEtiqueta.DataSource = ObjCGame.DtResultados;
DdlEtiqueta.DataBind();
}
if (ObjCGame.GetTipoEmpaque(-1, -1, CveEmpresa))
{
DdlTipoEmpaque.DataSource = ObjCGame.DtResultados;
DdlTipoEmpaque.DataBind();
}
ObjCGame.Dispose();
}
protected void CargaResultado()
{
ClsCGame ObjCGame = new ClsCGame();
Double TotalCajas = 0, TotalBins = 0;
if (ObjCGame.GetProduccionResultado(-1, CveEmpresa: UsuarioActual.CveEmpresa))
{
DtCajas = ObjCGame.DtResultados.FiltraParametros("CveOrdenProduccionDetalle IS NULL AND Tipo = 1");
GvCajas.DataSource = DtCajas;
TotalCajas = ObjCGame.DtResultados.FiltraParametros("CveOrdenProduccionDetalle IS NULL AND Tipo = 1").SUM("Cantidad");
DtBins = ObjCGame.DtResultados.FiltraParametros("CveOrdenProduccionDetalle IS NULL AND Tipo = 2");
GvBins.DataSource = DtBins;
TotalBins = ObjCGame.DtResultados.FiltraParametros("CveOrdenProduccionDetalle IS NULL AND Tipo = 2").SUM("Cantidad");
ObjCGame.Dispose();
}
GvCajas.DataBind();
GvBins.DataBind();
UpDatos.Update();
LblCajas.Text = TotalCajas.FormatoNumero(0);
LblBins.Text = TotalBins.FormatoNumero(0);
UpIndicadores.Update();
}
#endregion
protected void Dividir(object sender, EventArgs e)
{
int Index = ((LinkButton)sender).CommandArgument.ToString().ToEntero();
int Cantidad = HdnCantidad.Value.ToEntero();
int CantidadPasada = GvCajas.Rows[Index].DataKey("Cantidad").ToEntero();
double PesoUnitario = GvCajas.Rows[Index].DataKey("Peso").ToDouble() / CantidadPasada;
int CantActualizada = GvCajas.Rows[Index].DataKey("Cantidad").ToEntero() - Cantidad;
double ImporteUnitario = GvCajas.Rows[Index].DataKey("ImportePreEnfriado").ToDouble() / CantidadPasada;
ClsCGame ObjCGame = new ClsCGame();
ObjCGame.IniciaTransacSQL();
bool Error = false;
if (ObjCGame.UpdateProduccionResultado(GvCajas.Rows[Index].DataKey("CveProduccionResultado").ToEntero(), GvCajas.Rows[Index].DataKey("CveProduccion").ToEntero(), GvCajas.Rows[Index].DataKey("CvePS").ToEntero(),
CantActualizada, CantActualizada * PesoUnitario, GvCajas.Rows[Index].DataKey("CveTamaño").ToEntero(), GvCajas.Rows[Index].DataKey("CveCalidad").ToEntero(), GvCajas.Rows[Index].DataKey("CveTipoCaja").ToEntero(),
Convert.ToBoolean(GvCajas.Rows[Index].DataKey("CveTipoEtiqueta")), -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, GvCajas.Rows[Index].DataKey("CveTipoEmpaque").ToEntero(), GvCajas.Rows[Index].DataKey("CveTipoMaduracion").ToEntero(), GvCajas.Rows[Index].DataKey("CveTipoProducto").ToEntero(), -1))
{
ObjCGame.UpdateProduccionResultadoImporte(GvCajas.Rows[Index].DataKey("CveProduccionResultado").ToEntero(), CantActualizada * ImporteUnitario);
if (ObjCGame.AddProduccionResultado(GvCajas.Rows[Index].DataKey("CveProduccion").ToEntero(), GvCajas.Rows[Index].DataKey("CvePS").ToEntero(),
Cantidad, Cantidad * PesoUnitario, GvCajas.Rows[Index].DataKey("CveTamaño").ToEntero(), GvCajas.Rows[Index].DataKey("CveCalidad").ToEntero(), GvCajas.Rows[Index].DataKey("CveTipoCaja").ToEntero(),
Convert.ToBoolean(GvCajas.Rows[Index].DataKey("CveTipoEtiqueta").ToEntero()), -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, GvCajas.Rows[Index].DataKey("CveTipoEmpaque").ToEntero(), GvCajas.Rows[Index].DataKey("CveTipoMaduracion").ToEntero(), GvCajas.Rows[Index].DataKey("CveTipoProducto").ToEntero(), -1) == false)
{
Error = true;
}
else
{
ObjCGame.UpdateProduccionResultadoImporte(ObjCGame.CveProduccionResultado, Cantidad * ImporteUnitario);
}
}
else
{
Error = true;
}
if (!Error) { ObjCGame.Commit(); } else { ObjCGame.RollBack(); };
ObjCGame.Dispose();
CargaResultado();
}
protected void Dividir2(object sender, EventArgs e)
{
int Index = ((LinkButton)sender).CommandArgument.ToString().ToEntero();
int Cantidad = HdnCantidad.Value.ToEntero();
int CantidadPasada = GvBins.Rows[Index].DataKey("Cantidad").ToEntero();
double PesoUnitario = GvBins.Rows[Index].DataKey("Peso").ToDouble() / CantidadPasada;
int CantActualizada = GvBins.Rows[Index].DataKey("Cantidad").ToEntero() - Cantidad;
double ImporteUnitario = GvBins.Rows[Index].DataKey("ImportePreEnfriado").ToDouble() / CantidadPasada;
ClsCGame ObjCGame = new ClsCGame();
ObjCGame.IniciaTransacSQL();
bool Error = false;
if (ObjCGame.UpdateProduccionResultado(GvBins.Rows[Index].DataKey("CveProduccionResultado").ToEntero(), GvBins.Rows[Index].DataKey("CveProduccion").ToEntero(), GvBins.Rows[Index].DataKey("CvePS").ToEntero(),
CantActualizada, CantActualizada * PesoUnitario, GvBins.Rows[Index].DataKey("CveTamaño").ToEntero(), GvBins.Rows[Index].DataKey("CveCalidad").ToEntero(), GvBins.Rows[Index].DataKey("CveTipoCaja").ToEntero(),
Convert.ToBoolean(GvBins.Rows[Index].DataKey("CveTipoEtiqueta")), -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, GvBins.Rows[Index].DataKey("CveTipoEmpaque").ToEntero(), GvBins.Rows[Index].DataKey("CveTipoMaduracion").ToEntero(), GvBins.Rows[Index].DataKey("CveTipoProducto").ToEntero(), -1))
{
ObjCGame.UpdateProduccionResultadoImporte(GvBins.Rows[Index].DataKey("CveProduccionResultado").ToEntero(), CantActualizada * ImporteUnitario);
if (ObjCGame.AddProduccionResultado(GvBins.Rows[Index].DataKey("CveProduccion").ToEntero(), GvBins.Rows[Index].DataKey("CvePS").ToEntero(),
Cantidad, Cantidad * PesoUnitario, GvBins.Rows[Index].DataKey("CveTamaño").ToEntero(), GvBins.Rows[Index].DataKey("CveCalidad").ToEntero(), GvBins.Rows[Index].DataKey("CveTipoCaja").ToEntero(),
Convert.ToBoolean(GvBins.Rows[Index].DataKey("CveTipoEtiqueta").ToEntero()), -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, GvBins.Rows[Index].DataKey("CveTipoEmpaque").ToEntero(), GvBins.Rows[Index].DataKey("CveTipoMaduracion").ToEntero(), GvBins.Rows[Index].DataKey("CveTipoProducto").ToEntero(), -1) == false)
{
Error = true;
}
else
{
ObjCGame.UpdateProduccionResultadoImporte(ObjCGame.CveProduccionResultado, Cantidad * ImporteUnitario);
}
}
else
{
Error = true;
}
if (!Error) { ObjCGame.Commit(); } else { ObjCGame.RollBack(); };
ObjCGame.Dispose();
CargaResultado();
}
protected void GvResultado_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
ClsCGame ObjCGame = new ClsCGame();
if (ObjCGame.GetOrdenProduccionDetalleCant(UsuarioActual.CveEmpresa, e.Row.DBCampo("CvePS").ToEntero(), -1))
{
DtCant = ObjCGame.DtResultados.FiltraParametros(String.Format("CantRest > 0 AND Tipo = {0} AND CveEstatus IN (1,2,3)", 1));
e.Row.FCDropDownList("DdlOrdenProduccionDetalle").DataSource = DtCant;
e.Row.FCDropDownList("DdlOrdenProduccionDetalle").Items.Insert(0, new ListItem("Seleccione", "-1"));
}
ObjCGame.Dispose();
e.Row.FCDropDownList("DdlOrdenProduccionDetalle").DataBind();
e.Row.FCLinkButton("BtnDividir").Attributes.Add("onclick", String.Format("Dividir('{0}');", e.Row.FCTextBox("TxtCantDividir").ClientID));
e.Row.FCLinkButton("BtnDividir").CommandArgument = e.Row.RowIndex.ToString();
e.Row.FCTextBox("TxtCantDividir").Attributes.Add("onkeyup", String.Format("LimitaCantidad({0},this,'{1}');", e.Row.DBCampo("Cantidad"), e.Row.FCLinkButton("BtnDividir").ClientID));
//if (e.Row.FCDropDownList("DdlOrdenProduccionDetalle").Items.Count < 2)
//{
// e.Row.Visible = false;
//}
//String Css = "Texto";
//String Liga = $"/CGame/Empaque.aspx?&CveProduccion={e.Row.DataKey("CveProduccion")}";
// e.Row.FCLabel("LblFolio").Text = "<a class=" + "" + Css + "" + " href=" + "" + Liga + "" + ">" + e.Row.FCLabel("LblFolio").Text + "</a>";
if (e.Row.DataKey("CveTipoEtiqueta").ToEntero() == 1)
{
e.Row.FCLabel("LblTipoEtiqueta").Text = "Si";
}
else
{
e.Row.FCLabel("LblTipoEtiqueta").Text = "No";
}
}
}
protected void DdlOrdenProduccionDetalle_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow GvRow = (GridViewRow)((DropDownList)sender).NamingContainer;
if (GvRow.FCDropDownList("DdlOrdenProduccionDetalle").SelectedValue != "-1")
{
ClsCGame ObjCGame = new ClsCGame();
ObjCGame.IniciaTransacSQL();
bool Error = false;
int CveOrdenProduccionDetalle = GvRow.FCDropDownList("DdlOrdenProduccionDetalle").SelectedValue.ToEntero();
double CantidadRequerida = 0.0;
if (ObjCGame.GetOrdenProduccionDetalleCant(UsuarioActual.CveEmpresa, -1, CveOrdenProduccionDetalle))
{
CantidadRequerida = ObjCGame.DtResultados.Rows[0]["CantRest"].ToString().ToDouble();
}
if (CantidadRequerida >= GvRow.DataKey("Cantidad").ToEntero())
{
CantidadRequerida = GvRow.DataKey("Cantidad").ToDouble();
//si lo que requiero es mayor, solo debo asignar lo que tiene el movimiento de resultado
if (ObjCGame.AsignaProduccionResultado(GvRow.DataKey("CveProduccionResultado").ToEntero(), CveOrdenProduccionDetalle, CantidadRequerida, false) == false)
{
Error = true;
}
}
else
{
// si el resultado es mayor, asigna la cantidad requerida y genera un nuevo movimento con la cantidad restante
if (ObjCGame.AsignaProduccionResultado(GvRow.DataKey("CveProduccionResultado").ToEntero(), CveOrdenProduccionDetalle, CantidadRequerida, true) == false)
{
Error = true;
}
}
if (!Error) { ObjCGame.Commit(); } else { ObjCGame.RollBack(); };
ObjCGame.Dispose();
CargaResultado();
}
}
protected void GvBins_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
ClsCGame ObjCGame = new ClsCGame();
if (ObjCGame.GetOrdenProduccionDetalleCant(UsuarioActual.CveEmpresa, e.Row.DBCampo("CvePS").ToEntero(), -1))
{
DtCant = ObjCGame.DtResultados.FiltraParametros(String.Format("CantRest > 0 AND Tipo = {0} AND CveEstatus IN (1,2,3)", 2));
e.Row.FCDropDownList("DdlOrdenProduccionDetalle").DataSource = DtCant;
e.Row.FCDropDownList("DdlOrdenProduccionDetalle").Items.Insert(0, new ListItem("Seleccione", "-1"));
}
ObjCGame.Dispose();
e.Row.FCDropDownList("DdlOrdenProduccionDetalle").DataBind();
e.Row.FCLinkButton("BtnDividir").Attributes.Add("onclick", String.Format("Dividir2('{0}');", e.Row.FCTextBox("TxtCantDividir").ClientID));
e.Row.FCLinkButton("BtnDividir").CommandArgument = e.Row.RowIndex.ToString();
e.Row.FCTextBox("TxtCantDividir").Attributes.Add("onkeyup", String.Format("LimitaCantidad2({0},this,'{1}');", e.Row.DBCampo("Cantidad"), e.Row.FCLinkButton("BtnDividir").ClientID));
//if (e.Row.FCDropDownList("DdlOrdenProduccionDetalle").Items.Count < 2)
//{
// e.Row.Visible = false;
//}
//String Css = "Texto";
////String Liga = $"/CGame/Empaque.aspx?&CveProduccion={e.Row.DataKey("CveProduccion")}";
//e.Row.FCLabel("LblFolio").Text = "<a class=" + "" + Css + "" + " href=" + "" + Liga + "" + ">" + e.Row.FCLabel("LblFolio").Text + "</a>";
if (e.Row.DataKey("CveTipoEtiqueta").ToEntero() == 1)
{
e.Row.FCLabel("LblTipoEtiqueta").Text = "Si";
}
else
{
e.Row.FCLabel("LblTipoEtiqueta").Text = "No";
}
}
}
protected void BtnConsultar_Click(object sender, EventArgs e)
{
int CveHuerta = DdlHuerta.SelectedValue.ToEntero();
int CveFruto = DdlFruto.SelectedValue.ToEntero();
int CveTipoProduccion = DdlTipoProduccion.SelectedValue.ToEntero();
int CveVariedad = DdlVariedad.SelectedValue.ToEntero();
int CveTipoEmpaque = DdlTipoEmpaque.SelectedValue.ToEntero();
int CveTamaño = DdlTamaño.SelectedValue.ToEntero();
int CveCalidad = DdlCalidad.SelectedValue.ToEntero();
int CveEtiqueta = DdlEtiqueta.SelectedValue.ToEntero();
Double TotalCajas = 0, TotalBins = 0;
ClsCGame ObjCGame = new ClsCGame();
if (ObjCGame.GetProduccionResultado(-1, -1, -1, UsuarioActual.CveEmpresa, -1, CveHuerta, CveFruto, CveVariedad, CveTipoProduccion, CveTamaño, CveCalidad, CveEtiqueta, CveTipoEmpaque))
{
GvCajas.DataSource = ObjCGame.DtResultados.FiltraParametros("CveOrdenProduccionDetalle IS NULL AND Tipo = 1");
TotalCajas = ObjCGame.DtResultados.FiltraParametros("CveOrdenProduccionDetalle IS NULL AND Tipo = 1").SUM("Cantidad");
GvBins.DataSource = ObjCGame.DtResultados.FiltraParametros("CveOrdenProduccionDetalle IS NULL AND Tipo = 2");
TotalBins = ObjCGame.DtResultados.FiltraParametros("CveOrdenProduccionDetalle IS NULL AND Tipo = 2").SUM("Cantidad");
ObjCGame.Dispose();
}
GvCajas.DataBind();
GvBins.DataBind();
UpDatos.Update();
LblCajas.Text = TotalCajas.FormatoNumero(0);
LblBins.Text = TotalBins.FormatoNumero(0);
UpIndicadores.Update();
}
#region "PDF"
protected void ImgImprimirPDF_Click(object sender, EventArgs e)
{
GenerarPDF("PDF");
}
protected void GenerarPDF(String Opcion)
{
if (DtCajas.Rows.Count > 0 && DtBins.Rows.Count > 0)
{
System.IO.FileInfo Imagen = new System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta));
String logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa);
List<ReportParameter> para = new List<ReportParameter>();
para.Add(new ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa));
para.Add(new ReportParameter("UsuarioImprimio", UsuarioActual.Nombre));
para.Add(new ReportParameter("FechaImpresion", DateTime.Now.ToString()));
para.Add(new ReportParameter("Huerta", DdlHuerta.SelectedItem.Text));
para.Add(new ReportParameter("Fruto", DdlFruto.SelectedItem.Text));
para.Add(new ReportParameter("Variedad", DdlVariedad.SelectedItem.Text));
para.Add(new ReportParameter("TipoProduccion", DdlTipoProduccion.SelectedItem.Text));
para.Add(new ReportParameter("Tamaño", DdlTamaño.SelectedItem.Text));
para.Add(new ReportParameter("Calidad", DdlCalidad.SelectedItem.Text));
para.Add(new ReportParameter("Etiqueta", DdlEtiqueta.SelectedItem.Text));
para.Add(new ReportParameter("TipoEmpaque", DdlTipoEmpaque.SelectedItem.Text));
para.Add(new ReportParameter("TotalCajas", LblCajas.Text));
para.Add(new ReportParameter("TotalBins", LblBins.Text));
if (Imagen.Exists)
{
para.Add(new ReportParameter("LogoPath", logouri));
}
else
{
para.Add(new ReportParameter("LogoPath", ""));
}
List<ReportDataSource> lrds = new List<ReportDataSource>();
ReportDataSource rds = new ReportDataSource();
rds.Name = "DataSet1"; rds.Value = DtCajas;
ReportDataSource rds2 = new ReportDataSource();
rds2.Name = "DataSet2"; rds2.Value = DtBins;
lrds.Add(rds);
lrds.Add(rds2);
ImprimirPDF("Empresas/Grales/Formatos/RepAsignacionEmpaque.rdlc", lrds, para, "RepAsignacionEmpaque", Opcion);
}
else
{
Alert("No hay datos consultados", ModExtensiones.TipoMensaje.MsgAdvertencia);
}
}
#endregion
}