504 lines
18 KiB
C#
504 lines
18 KiB
C#
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI.WebControls;
|
|
using Extensiones;
|
|
using System.Data;
|
|
using static Extensiones.ModExtensiones;
|
|
using Microsoft.Reporting.WebForms;
|
|
using System;
|
|
using System.Threading;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
public partial class CGame_RepOrdenCorteDetalle : ClsPaginas
|
|
{
|
|
|
|
#region PROPIEDADES
|
|
|
|
private int CveOrdenCorte
|
|
{
|
|
get { return (ViewState["CveOrdenCorte"] == null) ? 0 : Convert.ToInt32(ViewState["CveOrdenCorte"]); }
|
|
set { ViewState["CveOrdenCorte"] = value; }
|
|
}
|
|
|
|
private int CveHuerta
|
|
{
|
|
get { return (ViewState["CveHuerta"] == null) ? 0 : Convert.ToInt32(ViewState["CveHuerta"]); }
|
|
set { ViewState["CveHuerta"] = value; }
|
|
}
|
|
|
|
#endregion
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
TxtFechaFlete.Text = DateTime.Now.ToShortDateString();
|
|
CveOrdenCorte = Request["CveOrdenCorte"] == null ? 0 : Request["CveOrdenCorte"].ToString().ToEntero();
|
|
CargaDatos();
|
|
}
|
|
}
|
|
|
|
#region CARGAS
|
|
protected void CargaDatos()
|
|
{
|
|
if (CveOrdenCorte > 0)
|
|
{
|
|
CargaEmpaque();
|
|
CargaHuerta();
|
|
ClsCGame ObjCGame = new ClsCGame();
|
|
if (ObjCGame.GetOrdenCorte(UsuarioActual.CveEmpresa, CveOrdenCorte: CveOrdenCorte))
|
|
{
|
|
if (ObjCGame.DtResultados.Rows.Count > 0)
|
|
{
|
|
DataRow dr = ObjCGame.DtResultados.Rows[0];
|
|
lblFolioOC.Text = dr["FolioOC"].ToString();
|
|
LblHuerta.Text = dr["Huerta"].ToString();
|
|
LblFecha.Text = dr["FechaEntregaOC"].ToString().ToDate().ToShortDateString();
|
|
TxtFecha.Text = dr["FechaIng"].ToString().ToDate().ToShortDateString();
|
|
lblNombreUsuario.Text = dr["Usuario"].ToString();
|
|
LblCuadro.Text = dr["Cuadro"].ToString();
|
|
LblPeso.Text = dr["Peso"].ToString();
|
|
CveHuerta = dr["CveHuerta"].ToEntero();
|
|
if (dr["Disponible"].ToEntero() == 0) { LnkGastos.Visible = false; LnkEntrada.Visible = false; }
|
|
if (ObjCGame.GetOrdenCorteDetalle(UsuarioActual.CveEmpresa, CveOrdenCorte: CveOrdenCorte))
|
|
{
|
|
GvDatos.DataSource = ObjCGame.DtResultados;
|
|
}
|
|
|
|
if (ObjCGame.GetCorte(UsuarioActual.CveEmpresa))
|
|
{
|
|
GvMP.DataSource = ObjCGame.DtResultados.FiltraParametros(String.Format("CveOrdenCorte = {0}", CveOrdenCorte));
|
|
}
|
|
|
|
if (ObjCGame.GetCorteGasto(UsuarioActual.CveEmpresa, CveOrdenCorte: CveOrdenCorte, Opcion: 1))
|
|
{
|
|
GvGastos.DataSource = ObjCGame.DtResultados;
|
|
}
|
|
if (ObjCGame.GetCorteGastoCompras(CveOrdenCorte))
|
|
{
|
|
GvOtrosGastos.DataSource = ObjCGame.DtResultados;
|
|
}
|
|
if (ObjCGame.GetFlete(UsuarioActual.CveEmpresa, CveOrdenCorte: CveOrdenCorte, TipoFlete: 1))
|
|
{
|
|
GvFleteInterno.DataSource = ObjCGame.DtResultados;
|
|
}
|
|
if (ObjCGame.GetFlete(UsuarioActual.CveEmpresa, CveOrdenCorte: CveOrdenCorte, TipoFlete: 2))
|
|
{
|
|
GvFleteExterno.DataSource = ObjCGame.DtResultados;
|
|
}
|
|
if (ObjCGame.GetCorteResumen(CveOrdenCorte))
|
|
{
|
|
if (ObjCGame.DtResultados.Rows.Count > 0)
|
|
{
|
|
LblPrimera.Text = ObjCGame.DtResultados.Rows[0]["Primera"].ToString().FormatoNumero() + " - " + ObjCGame.DtResultados.Rows[0]["PorPrimera"].ToString().FormatoNumero() + "%";
|
|
LblSegunda.Text = ObjCGame.DtResultados.Rows[0]["Segunda"].ToString().FormatoNumero() + " - " + ObjCGame.DtResultados.Rows[0]["PorSegunda"].ToString().FormatoNumero() + "%";
|
|
LblMerma.Text = ObjCGame.DtResultados.Rows[0]["Merma"].ToString().FormatoNumero() + " - " + ObjCGame.DtResultados.Rows[0]["PorMerma"].ToString().FormatoNumero() + "%";
|
|
}
|
|
}
|
|
if (ObjCGame.GetFleteHuertaEmpaque(UsuarioActual.CveEmpresa, CveOrdenCorte: CveOrdenCorte))
|
|
{
|
|
if (ObjCGame.DtResultados.FiltraParametros("CveFlete IS NULL").Rows.Count > 0)
|
|
{
|
|
if (LnkEntrada.Visible) { LnkFletes.Visible = true; }
|
|
}
|
|
}
|
|
//if (ObjCGame.GetEmpacado(CveOrdenCorte))
|
|
//{
|
|
// GvEmpacado.DataSource = ObjCGame.DtResultados;
|
|
//}
|
|
|
|
if (ObjCGame.GetLiquidacionIngresosOC(CveOrdenCorte,1))
|
|
{
|
|
GvLiquidacionIngresos.DataSource = ObjCGame.DtResultados;
|
|
}
|
|
if (ObjCGame.GetLiquidacionGastosOC(CveOrdenCorte,1))
|
|
{
|
|
GvLiquidacionGastos.DataSource = ObjCGame.DtResultados;
|
|
}
|
|
if (ObjCGame.GetLiquidacionIngresosOC(CveOrdenCorte,2))
|
|
{
|
|
GvLiquidacionIngresosBins.DataSource = ObjCGame.DtResultados;
|
|
}
|
|
if (ObjCGame.GetLiquidacionGastosOC(CveOrdenCorte,2))
|
|
{
|
|
GvLiquidacionGastosBins.DataSource = ObjCGame.DtResultados;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Alert("No se encontró la orden de corte especificada.", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
}
|
|
}
|
|
|
|
if (!LnkEntrada.Visible) { BtnAddFechaFlete.Visible = false; TxtFechaFlete.Enabled = false; DdlEmpaque.Enabled = false; }
|
|
|
|
ObjCGame.Dispose();
|
|
GvDatos.DataBind();
|
|
GvGastos.DataBind();
|
|
GvOtrosGastos.DataBind();
|
|
GvMP.DataBind();
|
|
GvFleteInterno.DataBind();
|
|
GvFleteExterno.DataBind();
|
|
//GvEmpacado.DataBind();
|
|
GvLiquidacionIngresos.DataBind();
|
|
GvLiquidacionGastos.DataBind();
|
|
GvLiquidacionGastosBins.DataBind();
|
|
GvLiquidacionIngresosBins.DataBind();
|
|
UpFletes.Update();
|
|
UpAcciones.Update();
|
|
CargaTotalGastos();
|
|
UpMP.Update();
|
|
UPDatos.Update();
|
|
UPDatosOrden.Update();
|
|
UpLiquidacion.Update();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void CargaEmpaque()
|
|
{
|
|
ClsCGame ObjCGame = new ClsCGame();
|
|
if (ObjCGame.GetEmpaques(UsuarioActual.CveEmpresa, -1, 1))
|
|
{
|
|
DdlEmpaque.DataSource = ObjCGame.DtResultados;
|
|
DdlEmpaque.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
}
|
|
ObjCGame.Dispose();
|
|
DdlEmpaque.DataBind();
|
|
}
|
|
|
|
private void CargaTotalGastos()
|
|
{
|
|
if (GvGastos.Rows.Count > 0)
|
|
{
|
|
LtlTotalOriginal.Text = GvGastos.Rows[0].Cells[3].Text.FormatoNumero();
|
|
}
|
|
|
|
UpGastos.Update();
|
|
}
|
|
|
|
protected void CargaHuerta()
|
|
{
|
|
ClsCGame ObjCort = new ClsCGame();
|
|
if (ObjCort.GetHuerta(UsuarioActual.CveEmpresa))
|
|
{
|
|
DdlHuerta.DataSource = ObjCort.DtResultados;
|
|
DdlHuerta.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
}
|
|
ObjCort.Dispose();
|
|
DdlHuerta.DataBind();
|
|
UpModalAdd.Update();
|
|
}
|
|
#endregion
|
|
|
|
#region GRIDVIEWS
|
|
|
|
protected void GvMP_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
|
|
if (e.Row.FCLabel("lblEmpaque").Text == "")
|
|
{
|
|
e.Row.FCLabel("lblEmpaque").Text = "Sin Asignar";
|
|
}
|
|
else
|
|
{
|
|
String Css = "Texto";
|
|
String Liga = $"/CGame/Empaque.aspx?&CveProduccion={e.Row.DataKey("CveProduccion")}";
|
|
e.Row.FCLabel("lblEmpaque").Text = "<a class=" + "" + Css + "" + " href=" + "" + Liga + "" + ">" + e.Row.FCLabel("lblEmpaque").Text + "</a>";
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void GvDatos_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
if (e.Row.DataKey("CveTipoEtiqueta").ToEntero() == 1)
|
|
{
|
|
e.Row.FCLabel("LblTipoEtiqueta").Text = "Si";
|
|
}
|
|
else
|
|
{
|
|
e.Row.FCLabel("LblTipoEtiqueta").Text = "No";
|
|
}
|
|
|
|
String Css = "Texto";
|
|
String Liga = $"/CGame/OrdenProduccion.aspx?&CveOrdenProduccion={e.Row.DataKey("CveOrdenProduccion")}";
|
|
e.Row.FCLabel("LblFolio").Text = "<a class=" + "" + Css + "" + " href=" + "" + Liga + "" + ">" + e.Row.FCLabel("LblFolio").Text + "</a>";
|
|
}
|
|
}
|
|
|
|
protected void GvGastos_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
if (e.Row.DBCampo("Gpo").ToString() == "Total")
|
|
{
|
|
e.Row.CssClass = "Totales";
|
|
e.Row.Cells[0].Text = e.Row.DBCampo("Gpo");
|
|
}
|
|
else if (e.Row.DBCampo("CveCorteGasto").ToEntero() == 0)
|
|
{
|
|
e.Row.CssClass = "SubTotales";
|
|
e.Row.Cells[0].Text = e.Row.DBCampo("Gpo");
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
protected void GvEmpacado_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
if (e.Row.RowIndex == 0)
|
|
{
|
|
e.Row.CssClass = "Totales";
|
|
e.Row.Cells[0].Text = "Total";
|
|
}
|
|
else if (e.Row.DBCampo("CveProduccion").ToEntero() <= 0)
|
|
{
|
|
e.Row.CssClass = "SubTotales";
|
|
e.Row.Cells[0].Text = e.Row.DBCampo("Gpo");
|
|
}
|
|
else
|
|
{
|
|
if (e.Row.DBCampo("CveTipoEtiqueta").ToEntero() == 1)
|
|
{
|
|
e.Row.FCLabel("LblTipoEtiqueta").Text = "Si";
|
|
}
|
|
else
|
|
{
|
|
e.Row.FCLabel("LblTipoEtiqueta").Text = "No";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void GvIngresos_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
if (e.Row.RowIndex == 0)
|
|
{
|
|
e.Row.CssClass = "Totales";
|
|
e.Row.Cells[0].Text = "Total";
|
|
}
|
|
else if (e.Row.DBCampo("PS").ToString() == "")
|
|
{
|
|
e.Row.CssClass = "SubTotales";
|
|
e.Row.Cells[0].Text = e.Row.DBCampo("Folio");
|
|
String Css = "Texto";
|
|
String Liga = $"/CGame/OrdenProduccion.aspx?&CveOrdenProduccion={e.Row.DBCampo("CveOrdenProduccion")}";
|
|
e.Row.Cells[0].Text = "<a class=" + "" + Css + "" + " href=" + "" + Liga + "" + ">" + e.Row.Cells[0].Text + "</a>";
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void GvLiquidacionGastos_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
if (e.Row.RowIndex == 0)
|
|
{
|
|
e.Row.CssClass = "Totales";
|
|
e.Row.Cells[0].Text = "Total";
|
|
}
|
|
else if (e.Row.DBCampo("CveCargoFijo").ToEntero() <= 0)
|
|
{
|
|
e.Row.CssClass = "SubTotales";
|
|
e.Row.Cells[0].Text = e.Row.DBCampo("Folio");
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void GvIngresosBins_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
if (e.Row.RowIndex == 0)
|
|
{
|
|
e.Row.CssClass = "Totales";
|
|
e.Row.Cells[0].Text = "Total";
|
|
}
|
|
else if (e.Row.DBCampo("PS").ToString() == "")
|
|
{
|
|
e.Row.CssClass = "SubTotales";
|
|
e.Row.Cells[0].Text = e.Row.DBCampo("Folio");
|
|
String Css = "Texto";
|
|
String Liga = $"/CGame/OrdenProduccion.aspx?&CveOrdenProduccion={e.Row.DBCampo("CveOrdenProduccion")}";
|
|
e.Row.Cells[0].Text = "<a class=" + "" + Css + "" + " href=" + "" + Liga + "" + ">" + e.Row.Cells[0].Text + "</a>";
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void GvLiquidacionGastosBins_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
if (e.Row.RowIndex == 0)
|
|
{
|
|
e.Row.CssClass = "Totales";
|
|
e.Row.Cells[0].Text = "Total";
|
|
}
|
|
else if (e.Row.DBCampo("CveCargoFijo").ToEntero() <= 0)
|
|
{
|
|
e.Row.CssClass = "SubTotales";
|
|
e.Row.Cells[0].Text = e.Row.DBCampo("Folio");
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region BTN'S
|
|
|
|
protected void LnkFletes_Click(object sender, EventArgs e)
|
|
{
|
|
Response.Redirect(String.Format("{0}{1}", "/CGame/Fletes.aspx?CveOrdenCorte=", CveOrdenCorte), true);
|
|
UpAcciones.Update();
|
|
}
|
|
|
|
protected void BtnAddFechaFlete_Click(object sender, EventArgs e)
|
|
{
|
|
if (DdlEmpaque.SelectedValue == "-1")
|
|
{
|
|
Alert("Tiene que seleccionar un empaque.", TipoMensaje.MsgAdvertencia);
|
|
return;
|
|
}
|
|
|
|
ClsCGame ObjCGame = new ClsCGame();
|
|
if (ObjCGame.AddFleteHuertaEmpaque(CveOrdenCorte, DdlEmpaque.SelectedValue.ToEntero(), TxtFechaFlete.Text.ToDate(), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa))
|
|
{
|
|
var Descripcion = "";
|
|
var Body = ObjCGame.GeneraCorreoFlete(CveOrdenCorte, UsuarioActual.CveEmpresa, UsuarioActual.Nombre, TxtFechaFlete.Text, DdlEmpaque.SelectedItem.Text);
|
|
if (ObjCGame.GetFleteHuertaEmpaque(UsuarioActual.CveEmpresa, CveOrdenCorte: CveOrdenCorte))
|
|
{
|
|
Descripcion = ObjCGame.DtResultados.Rows[0]["FolioFechaEmpaque"].ToString();
|
|
}
|
|
EnviarCorreo(CveOrdenCorte, Body, Descripcion);
|
|
Alert("La fecha del flete se asigno correctamente");
|
|
TxtFechaFlete.Text = DateTime.Now.ToShortDateString();
|
|
DdlEmpaque.SelectedIndex = 0;
|
|
LnkFletes.Visible = true;
|
|
UpAcciones.Update();
|
|
UpFletes.Update();
|
|
}
|
|
ObjCGame.Dispose();
|
|
}
|
|
|
|
protected void LnkGastos_Click(object sender, EventArgs e)
|
|
{
|
|
Response.Redirect(String.Format("{0}{1}", "/CGame/CorteGasto.aspx?CveOrdenCorte=", CveOrdenCorte), true);
|
|
UpAcciones.Update();
|
|
}
|
|
|
|
protected void LnkEntrada_Click(object sender, EventArgs e)
|
|
{
|
|
Response.Redirect(String.Format("{0}{1}", "/CGame/EntradaMateriaPrima.aspx?CveOrdenCorte=", CveOrdenCorte), true);
|
|
UpAcciones.Update();
|
|
}
|
|
|
|
protected void LnkModalGrafica_Click(object sender, EventArgs e)
|
|
{
|
|
RegistraScript("$('#DivModalGrafica').modal('show')");
|
|
ClsCGame ObjCGame = new ClsCGame();
|
|
if (ObjCGame.GetCorteResumen(CveOrdenCorte))
|
|
{
|
|
DataTable Dt = new DataTable();
|
|
Dt.Columns.Add("Texto");
|
|
Dt.Columns.Add("Valor");
|
|
|
|
DataRow Row = null;
|
|
Row = Dt.NewRow();
|
|
Row["Texto"] = "Primera";
|
|
Row["Valor"] = ObjCGame.DtResultados.Rows[0]["Primera"].ToString();
|
|
Dt.Rows.Add(Row);
|
|
|
|
DataRow Row2 = null;
|
|
Row2 = Dt.NewRow();
|
|
Row2["Texto"] = "Segunda";
|
|
Row2["Valor"] = ObjCGame.DtResultados.Rows[0]["Segunda"].ToString();
|
|
Dt.Rows.Add(Row2);
|
|
|
|
DataRow Row3 = null;
|
|
Row3 = Dt.NewRow();
|
|
Row3["Texto"] = "Merma";
|
|
Row3["Valor"] = ObjCGame.DtResultados.Rows[0]["Merma"].ToString();
|
|
Dt.Rows.Add(Row3);
|
|
|
|
|
|
var query = from s in Dt.AsEnumerable()
|
|
select new
|
|
{
|
|
Texto = s["Texto"].ToString(),
|
|
Valor = s["Valor"].ToString().ToDouble()
|
|
};
|
|
var json = Newtonsoft.Json.JsonConvert.SerializeObject(query);
|
|
RegistraScript($"CargaHistorico({json})", "22");
|
|
}
|
|
ObjCGame.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
protected void LnkEditarOC_Click(object sender, EventArgs e)
|
|
{
|
|
TxtCuadro.Text = LblCuadro.Text;
|
|
TxtPeso.Text = LblPeso.Text;
|
|
DdlHuerta.SelectedValueExist(CveHuerta);
|
|
TxtFechaCorte.Text = LblFecha.Text;
|
|
RegistraScript("$('#DivModalEditarOC').modal('show')");
|
|
UpModalAdd.Update();
|
|
}
|
|
|
|
protected void BtnEditarOC_Click(object sender, EventArgs e)
|
|
{
|
|
ClsCGame ObjCGame = new ClsCGame();
|
|
if (ObjCGame.UpdateOrdenCorte(CveOrdenCorte, DdlHuerta.SelectedValue.ToEntero(), lblFolioOC.Text, TxtFechaCorte.Text.ToDate(), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, TxtPeso.Text.ToDouble(), TxtCuadro.Text.ToEntero(), TxtObservacion.Text))
|
|
{
|
|
Alert("La orden de corte fue actualizada correctamente.");
|
|
RegistraScript("$('#DivModalEditarOC').modal('hide')");
|
|
CargaDatos();
|
|
}
|
|
ObjCGame.Dispose();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CORREO
|
|
private void MandaCorreo(String Para, String Asunto, String Body)
|
|
{
|
|
|
|
ClsSisMail Mail = new ClsSisMail();
|
|
Mail.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Body);
|
|
}
|
|
|
|
private void EnviarCorreo(int CveOrdenCorte, String Body, String Descripcion)
|
|
{
|
|
var Asunto = "SIG - Solicitud de Flete Huerta Empaque " + Descripcion;
|
|
//var Para = "julian@adsistemas.mx";
|
|
//var Para = "dany_pimi@hotmail.com";
|
|
var Para = "norberto@citrusgame.com.mx";
|
|
|
|
try
|
|
{
|
|
var Hilo = new System.Threading.Thread(() => MandaCorreo(Para, Asunto, Body));
|
|
Hilo.Start();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Alert("Ocurrio un error al mandar el mail " + ex);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
} |