902 lines
26 KiB
C#
902 lines
26 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using System.Data;
|
|
using Extensiones;
|
|
using Microsoft.Reporting.WebForms;
|
|
using System.Text;
|
|
|
|
public partial class Inventarios_EntregaAlmacenRuta : ClsPaginas
|
|
{
|
|
|
|
|
|
DataTable DTGenrarDocumentos
|
|
{
|
|
get {
|
|
|
|
if(ViewState["DTGenrarDocumentos"] == null){
|
|
ViewState["DTGenrarDocumentos"] = new DataTable();
|
|
}
|
|
return (DataTable)ViewState["DTGenrarDocumentos"];
|
|
|
|
}
|
|
set {
|
|
ViewState["DTGenrarDocumentos"] = (DataTable)value;
|
|
}
|
|
}
|
|
|
|
DataTable DTDatosConsulta
|
|
{
|
|
get
|
|
{
|
|
|
|
if (ViewState["DTDatosConsulta"] == null)
|
|
{
|
|
ViewState["DTDatosConsulta"] = new DataTable();
|
|
}
|
|
return (DataTable)ViewState["DTDatosConsulta"];
|
|
|
|
}
|
|
set
|
|
{
|
|
ViewState["DTDatosConsulta"] = (DataTable)value;
|
|
}
|
|
}
|
|
|
|
|
|
DataTable DTRecoleccion
|
|
{
|
|
get
|
|
{
|
|
if (ViewState["DTRecoleccion"] == null)
|
|
{
|
|
ViewState["DTRecoleccion"] = InitDTRecoleccion();
|
|
}
|
|
return (DataTable)ViewState["DTRecoleccion"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["DTRecoleccion"] = (DataTable)value;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool SelecionEntrega
|
|
{
|
|
get
|
|
{
|
|
if (ViewState["SelecionEntrega"] == null)
|
|
{
|
|
ViewState["SelecionEntrega"] = false;
|
|
}
|
|
return (bool) ViewState["SelecionEntrega"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["SelecionEntrega"] = (bool)value;
|
|
}
|
|
}
|
|
|
|
|
|
int CveEntregaAlmacen
|
|
{
|
|
get {
|
|
|
|
if (ViewState["CveEntregaAlmacen"] == null)
|
|
{
|
|
ViewState["CveEntregaAlmacen"] = -1;
|
|
}
|
|
return (int)ViewState["CveEntregaAlmacen"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["CveEntregaAlmacen"] = (int)value;
|
|
}
|
|
}
|
|
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
|
|
|
|
SelecionEntrega = true;
|
|
CargaCombos();
|
|
CargaDatos();
|
|
|
|
|
|
|
|
|
|
#region RECOLEECION
|
|
CargaDatosRecoleccion();
|
|
CargaModalClasificaiones();
|
|
CargaModalDdlPS();
|
|
|
|
ModalRecoleccionCargaClientes();
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|
|
|
|
protected void BtnAsignar_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
|
|
if(DdlChofer.SelectedValue.ToEntero() <= 0)
|
|
{
|
|
Alert("Debe seleccionar un chofer.", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
return;
|
|
}
|
|
|
|
if(DdlUnidadCamion.SelectedValue.ToEntero() <= 0)
|
|
{
|
|
Alert("Debe seleccionar una unidad", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
return;
|
|
}
|
|
|
|
|
|
StringBuilder SBError = new StringBuilder();
|
|
ActualizaOrdenDTGenrarDocumentos();
|
|
|
|
|
|
|
|
bool TieneError = false;
|
|
ClsGenerales ObjGeneral = new ClsGenerales();
|
|
ObjGeneral.IniciaTransacSQL();
|
|
|
|
GridViewRowCollection Grid = GvGenerarDocumentos.Rows;
|
|
|
|
|
|
string Usuario = DdlChofer.SelectedItem.Text;
|
|
|
|
|
|
|
|
|
|
int CveDireccionOrigen = -1;
|
|
foreach (GridViewRow row in Grid)
|
|
{
|
|
//int CvePaqueteriasGuias = row.DataKey("CvePaqueteriaGuia").ToEntero();
|
|
int Orden = row.DataKey("Orden").ToEntero();
|
|
|
|
//if (ObjGeneral.AsignarEntregasPorRealizar(CvePaqueteriasGuias, CvePersonal: -1, CveAsignacionEntrega: CveAsignacionEntrega, Orden: Orden))
|
|
//{
|
|
|
|
int CveDireccionDestino = row.DataKey("CveDireccionEnvio").ToEntero();
|
|
|
|
if (CveDireccionDestino <= 0)
|
|
{
|
|
SBError.AppendLine($"Factura {row.DataKey("SerieFolio")} el cliente {row.DataKey("Nombre")} no tiene una dirección de envio. ");
|
|
TieneError = true;
|
|
break;
|
|
}
|
|
int CveEntregaAlmacen = ObjGeneral.AddInvEntregaAlmacenRuta(row.DataKey("CveSubProyectoOrigen").ToEntero(), row.DataKey("CveMovimiento").ToEntero(), CveDireccionOrigen, CveDireccionDestino, DdlChofer.SelectedValue.ToEntero(), DdlUnidadCamion.SelectedValue.ToEntero(), TxtFechaEntrega.Text.ToDate(), "E",Orden,0);
|
|
CveDireccionOrigen = row.DataKey("CveDireccionEnvio").ToEntero();
|
|
|
|
if (CveEntregaAlmacen > 0)
|
|
{
|
|
DateTime MinFecha = new DateTime(1900, 01, 01);
|
|
int CveTimbre = ObjGeneral.AddGralTimbre("Tra", "-1", -1, "", MinFecha, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 0, -1, ChkEmitirCartaPorte.Checked, CveEntregaAlmacen, row.DataKey("CveSubProyectoOrigen").ToEntero());
|
|
|
|
if (CveTimbre <= 0)
|
|
{
|
|
SBError.AppendLine($"Factura {row.DataKey("SerieFolio")} error al agregar timbre. ");
|
|
|
|
TieneError = true;
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
SBError.AppendLine($"Factura {row.DataKey("SerieFolio")} error al agregar entrega alamcen. ");
|
|
TieneError = true;
|
|
break;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!TieneError)
|
|
{
|
|
|
|
foreach (GridViewRow row in Grid)
|
|
{
|
|
try
|
|
{
|
|
//MandarNotificacionCorreo(row);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
TieneError = true;
|
|
ModExtensiones.GuardaLog(ex.Message);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
if (!TieneError)
|
|
{
|
|
ObjGeneral.Commit();
|
|
Alert("Entregas asignadas correctamente");
|
|
|
|
DdlChofer.SelectedValueExist("-1");
|
|
DdlUnidadCamion.SelectedValueExist("-1");
|
|
ChkEmitirCartaPorte.Checked = false;
|
|
|
|
SelecionEntrega = false;
|
|
SeleccioanrGenrar();
|
|
|
|
CargaDatos();
|
|
UpDatos.Update();
|
|
}
|
|
else
|
|
{
|
|
ObjGeneral.RollBack();
|
|
}
|
|
ObjGeneral.Dispose();
|
|
}else
|
|
{
|
|
Alert(SBError.ToString(), ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
}
|
|
|
|
}
|
|
private void CargaDatos()
|
|
{
|
|
ClsGenerales ObjGeneral = new ClsGenerales();
|
|
if (ObjGeneral.GetInvEntregaAlmacenRuta(DdlSubProyecto.SelectedValue.ToEntero(), TxtFechaI.Text.ToDate(), TxtFechaF.Text.ToDate(), UsuarioActual.CveEmpresa, 1))
|
|
{
|
|
GvPaqueteriasGuias.DataSource = ObjGeneral.DtResultados;
|
|
DTDatosConsulta = ObjGeneral.DtResultados;
|
|
DTGenrarDocumentos = ObjGeneral.DtResultados.Clone();
|
|
|
|
}
|
|
ObjGeneral.Dispose();
|
|
GvPaqueteriasGuias.DataBind();
|
|
|
|
UpDatos.Update();
|
|
}
|
|
|
|
|
|
private void CargaCombos()
|
|
{
|
|
|
|
ClsInventarios ObjInventarios = new ClsInventarios();
|
|
|
|
if(ObjInventarios.GetCamiones(-1, UsuarioActual.CveEmpresa) && ObjInventarios.DtResultados.Rows.Count > 0){
|
|
DdlUnidadCamion.DataSource = ObjInventarios.DtResultados;
|
|
}
|
|
ObjInventarios.Dispose();
|
|
DdlUnidadCamion.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
DdlUnidadCamion.DataBind();
|
|
|
|
TxtFechaI.Text = DateTime.Now.AddDays(-1).ToShortDateString();
|
|
TxtFechaF.Text = DateTime.Now.ToShortDateString();
|
|
|
|
ClsAcarreos ObjAcar = new ClsAcarreos();
|
|
|
|
if(ObjAcar.GetChofer(-1, UsuarioActual.CveEmpresa, 1, -1) ){
|
|
DdlChofer.DataSource = ObjAcar.DtResultados;
|
|
DdlChofer.DataBind();
|
|
}
|
|
ObjAcar.Dispose();
|
|
DdlChofer.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
|
|
TxtFechaEntrega.Text = DateTime.Now.ToShortDateString();
|
|
|
|
|
|
CargarCentrosDeCosto(null, DdlSubProyecto, null, LblSubProyecto);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void CargaModalClasificaiones()
|
|
{
|
|
|
|
DdlClasificacion.DataSource = get_GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltraParametros(" Codigo = '' OR Codigo IS NULL ", Orderby: "Clasificacion");
|
|
DdlClasificacion.DataBind();
|
|
|
|
|
|
UpModalRecoleccion.Update();
|
|
}
|
|
|
|
private void CargaModalDdlPS()
|
|
{
|
|
bool EsWS = UsuarioActual.Empresa.Funcionalidad(105) == "1" | UsuarioActual.Empresa.Funcionalidad(141) == "1" ? true : false;
|
|
DdlProducto2.setEsWebService(EsWS);
|
|
if (DdlProducto2.UsaWebService)
|
|
{
|
|
DdlProducto2.ddlWS.Attributes.Add("data-cveclasificacion", DdlClasificacion.SelectedValue);
|
|
}
|
|
else if (!DdlProducto2.UsaWebService && (DataTable)DdlProducto2.DataSource == null)
|
|
{
|
|
DdlProducto2.DataSource = get_GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CveClasificacion: DdlClasificacion.SelectedValue.ToEntero()).FiltraParametros("CveTipoPS = 2");
|
|
DdlProducto2.DataBind();
|
|
}
|
|
}
|
|
|
|
|
|
protected void LnkGenerarDocumentos_Click(object sender, EventArgs e)
|
|
{
|
|
SeleccioanrGenrar();
|
|
}
|
|
|
|
|
|
private void SeleccioanrGenrar() {
|
|
|
|
if (SelecionEntrega)
|
|
{
|
|
|
|
DTGenrarDocumentos.Rows.Clear();
|
|
|
|
|
|
|
|
int CountRows = 0;
|
|
foreach (GridViewRow GvRow in GvPaqueteriasGuias.Rows)
|
|
{
|
|
|
|
CheckBox ChkAsigna = GvRow.FCCheckBox("ChkAsigna");
|
|
|
|
if (ChkAsigna.Checked)
|
|
{
|
|
|
|
int CveMovimiento = GvRow.DataKey("CveMovimiento").ToEntero();
|
|
|
|
DataRow dRow = DTGenrarDocumentos.NewRow();
|
|
DataRow dRowOrigen = DTDatosConsulta.FiltraParametros($"CveMovimiento = {CveMovimiento}").Rows[0];
|
|
|
|
int IndexColun = 0;
|
|
foreach (DataColumn dColumn in DTDatosConsulta.Columns)
|
|
{
|
|
dRow[IndexColun] = dRowOrigen[IndexColun];
|
|
IndexColun++;
|
|
}
|
|
|
|
dRow["Num"] = CountRows + 1;
|
|
DTGenrarDocumentos.Rows.Add(dRow);
|
|
CountRows++;
|
|
}
|
|
}
|
|
|
|
DTGenrarDocumentos.AcceptChanges();
|
|
|
|
|
|
|
|
|
|
SelecionEntrega = false;
|
|
LnkGenerarDocumentos.Text = "Regresar a Preselección";
|
|
LnkGenerarDocumentos.CssClass = "btn btn-default";
|
|
|
|
|
|
|
|
|
|
OcultarmostarDatosEntrega(true);
|
|
|
|
|
|
|
|
BtnConsultar.Visible = false;
|
|
|
|
UpDatos.Update();
|
|
UpFiltro.Update();
|
|
|
|
|
|
if (CountRows > 0)
|
|
{
|
|
GvGenerarDocumentos.DataSource = DTGenrarDocumentos;
|
|
GvGenerarDocumentos.DataBind();
|
|
|
|
DVGvGenerarDocumentos.Visible = true;
|
|
BtnAsignar.Visible = true;
|
|
DVGvPaqueteriasGuias.Visible = false;
|
|
|
|
RegistraScript("InitOrdenamientoGvGenerarDocumentos();");
|
|
}
|
|
else
|
|
{
|
|
Alert("No hay entregas seleccionadas", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
BtnConsultar.Visible = true;
|
|
SelecionEntrega = true;
|
|
LnkGenerarDocumentos.Text = "Preselección de Entregas";
|
|
LnkGenerarDocumentos.CssClass = "btn btn-primary";
|
|
|
|
|
|
OcultarmostarDatosEntrega(false);
|
|
|
|
BtnAsignar.Visible = false;
|
|
DVGvGenerarDocumentos.Visible = false;
|
|
DVGvPaqueteriasGuias.Visible = true;
|
|
UpDatos.Update();
|
|
UpFiltro.Update();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void OcultarmostarDatosEntrega(bool mostrar )
|
|
{
|
|
DVDatosEntrega1.Visible = mostrar;
|
|
DVDatosEntrega2.Visible = mostrar;
|
|
DVDatosEntrega3.Visible = mostrar;
|
|
DVDatosEntrega4.Visible = mostrar;
|
|
DVDatosEntrega5.Visible = mostrar;
|
|
DVDatosEntrega6.Visible = mostrar;
|
|
|
|
if (mostrar)
|
|
{
|
|
DVDatosEntrega7.Attributes.Add("class", "col-md-1");
|
|
}
|
|
else
|
|
{
|
|
DVDatosEntrega7.Attributes.Add("class", "col-md-9");
|
|
}
|
|
|
|
if (UsuarioActual.Empresa.Funcionalidad(161).ToEntero() == 1)
|
|
{
|
|
DvCartaPorte1.Visible = mostrar;
|
|
DvCartaPorte2.Visible = mostrar;
|
|
}
|
|
UpDatosEntrega.Update();
|
|
|
|
}
|
|
|
|
|
|
private void ActualizaOrdenDTGenrarDocumentos()
|
|
{
|
|
string[] OrdenMovimientos = Request.Form.GetValues("OrdenMovimientos");
|
|
|
|
int NumOrden = 1;
|
|
foreach (string CveMovimiento in OrdenMovimientos)
|
|
{
|
|
foreach(DataRow dRow in DTGenrarDocumentos.Rows)
|
|
{
|
|
if (CveMovimiento.ToEntero() == dRow["CveMovimiento"].ToString().ToEntero() )
|
|
{
|
|
dRow["Orden"] = NumOrden;
|
|
}
|
|
}
|
|
DTGenrarDocumentos.AcceptChanges();
|
|
NumOrden++;
|
|
}
|
|
|
|
|
|
DataView DTview = new DataView(DTGenrarDocumentos);
|
|
|
|
// Sort by State and ZipCode column in descending order
|
|
DTview.Sort = "Orden ASC";
|
|
|
|
GvGenerarDocumentos.DataSource = DTview;
|
|
GvGenerarDocumentos.DataBind();
|
|
UpDatos.Update();
|
|
|
|
|
|
|
|
}
|
|
|
|
protected void BtnConsultar_Click(object sender, EventArgs e)
|
|
{
|
|
if(Tab.ActiveTabIndex == 0)
|
|
{
|
|
CargaDatos();
|
|
}
|
|
else
|
|
{
|
|
CargaDatosRecoleccion();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#region RECOLECCION
|
|
|
|
|
|
private DataTable InitDTRecoleccion()
|
|
{
|
|
DataTable DT = new DataTable();
|
|
|
|
DT.Columns.Add("CveEntregaAlmacenDetalle", System.Type.GetType("System.Int32"));
|
|
DT.Columns.Add("CveEntregaAlmacen", System.Type.GetType("System.Int32"));
|
|
DT.Columns.Add("CvePS", System.Type.GetType("System.Int32"));
|
|
DT.Columns.Add("Cantidad", System.Type.GetType("System.Double"));
|
|
DT.Columns.Add("CveUnidadMedida", System.Type.GetType("System.Int32"));
|
|
DT.Columns.Add("CveUsuario",System.Type.GetType("System.Int32"));
|
|
DT.Columns.Add("FechaIng",System.Type.GetType("System.DateTime"));
|
|
DT.Columns.Add("CodigoPS", System.Type.GetType("System.String"));
|
|
DT.Columns.Add("Abreviatura", System.Type.GetType("System.String"));
|
|
|
|
return DT;
|
|
|
|
}
|
|
|
|
private void CargaDatosRecoleccion()
|
|
{
|
|
ClsGenerales ObjGeneral = new ClsGenerales();
|
|
if (ObjGeneral.GetInvEntregaAlmacenRuta(DdlSubProyecto.SelectedValue.ToEntero(), TxtFechaI.Text.ToDate(), TxtFechaF.Text.ToDate(), UsuarioActual.CveEmpresa, 2, 0))
|
|
{
|
|
GvDatosRecoleccion.DataSource = ObjGeneral.DtResultados;
|
|
}
|
|
ObjGeneral.Dispose();
|
|
GvDatosRecoleccion.DataBind();
|
|
UpDatosRecoleccion.Update();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
private void CargaDatosRecoleccionDetallePS()
|
|
{
|
|
if (CveEntregaAlmacen > 0)
|
|
{
|
|
ClsGenerales ObjGenerales = new ClsGenerales();
|
|
|
|
if (ObjGenerales.GetEntregaAlmacenRutaDetalle(CveEntregaAlmacen))
|
|
{
|
|
GvModalPSRecoleccion.DataSource = ObjGenerales.DtResultados;
|
|
}else
|
|
{
|
|
GvModalPSRecoleccion.DataSource = null;
|
|
}
|
|
ObjGenerales.Dispose();
|
|
}else
|
|
{
|
|
GvModalPSRecoleccion.DataSource = DTRecoleccion;
|
|
}
|
|
GvModalPSRecoleccion.DataBind();
|
|
UpModalRecoleccion.Update();
|
|
}
|
|
|
|
private void ModalRecoleccionCargaClientes()
|
|
{
|
|
ClsClientes ObjCliente = new ClsClientes();
|
|
if (ObjCliente.GetClientes(-1, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa, 1))
|
|
{
|
|
DdlModalRecoleccionCliente.DataSource = ObjCliente.DtResultados;
|
|
}
|
|
|
|
ObjCliente.Dispose();
|
|
DdlModalRecoleccionCliente.DataBind();
|
|
DdlModalRecoleccionCliente.Items.Insert(0, new ListItem("Seleccione uno", "-1"));
|
|
}
|
|
|
|
protected void DdlModalRecoleccionCliente_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
ModalRecoleccionCargaDirecciones();
|
|
}
|
|
|
|
private void ModalRecoleccionCargaDirecciones()
|
|
{
|
|
if(DdlModalRecoleccionCliente.SelectedValue.ToEntero() > 0)
|
|
{
|
|
ClsClientes ObjClientes = new ClsClientes();
|
|
if (ObjClientes.DireccionEnvioGet(-1, DdlModalRecoleccionCliente.SelectedValue.ToEntero(), -1))
|
|
{
|
|
DdlmodalRecoleccionDirecion.DataSource = ObjClientes.DtResultados;
|
|
}
|
|
ObjClientes.Dispose();
|
|
}
|
|
else
|
|
{
|
|
DdlmodalRecoleccionDirecion.DataSource = null;
|
|
}
|
|
|
|
DdlmodalRecoleccionDirecion.DataBind();
|
|
DdlmodalRecoleccionDirecion.Items.Insert(0, new ListItem("Seleccione una", "-1"));
|
|
|
|
UpModalRecoleccion.Update();
|
|
}
|
|
|
|
|
|
protected void LnkAgregarRecoleccion_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
if (DdlChofer.SelectedValue.ToEntero() <= 0)
|
|
{
|
|
Alert("Debe seleccionar un chofer.", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
return;
|
|
}
|
|
|
|
if (DdlUnidadCamion.SelectedValue.ToEntero() <= 0)
|
|
{
|
|
Alert("Debe seleccionar una unidad", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
return;
|
|
}
|
|
|
|
|
|
LtlModalRecoleccionTitulo.Text = "Agregar Recoleccion";
|
|
BtnModalRecoleccionGuardar.Text = "Agregar";
|
|
|
|
LimpiarModalRecoleccion();
|
|
RegistraScript("$('#DivModalRecoleccion').modal('show');");
|
|
CveEntregaAlmacen = -1;
|
|
}
|
|
|
|
protected void LnkGvDatosRecoleccionEditar_Click(object sender, EventArgs e)
|
|
{
|
|
LinkButton LnkEliminar = (LinkButton)sender;
|
|
GridViewRow GvRow = (GridViewRow)LnkEliminar.NamingContainer;
|
|
|
|
CveEntregaAlmacen = GvRow.DataKey("CveEntregaAlmacen").ToEntero();
|
|
int CveDireccionOrigen = GvRow.DataKey("CveDireccionOrigen").ToEntero();
|
|
int CveClienteEnvio = -1;
|
|
ClsClientes ObjClientes = new ClsClientes();
|
|
DataTable DtTempDirecciones = new DataTable();
|
|
|
|
if (ObjClientes.DireccionEnvioGet(CveDireccionOrigen, -1, -1))
|
|
{
|
|
CveClienteEnvio = ObjClientes.DtResultados.FiltroPrimeroValor("CveCliente").ToEntero();
|
|
|
|
if (ObjClientes.DireccionEnvioGet(-1, CveClienteEnvio, -1))
|
|
{
|
|
DdlmodalRecoleccionDirecion.DataSource = ObjClientes.DtResultados;
|
|
}
|
|
}
|
|
ObjClientes.Dispose();
|
|
|
|
DdlmodalRecoleccionDirecion.DataBind();
|
|
DdlmodalRecoleccionDirecion.Items.Add(new ListItem("Seleccione una", "-1"));
|
|
DdlmodalRecoleccionDirecion.SelectedValueExist(CveDireccionOrigen);
|
|
|
|
DdlModalRecoleccionCliente.SelectedValueExist(CveClienteEnvio);
|
|
|
|
|
|
CargaDatosRecoleccionDetallePS();
|
|
|
|
|
|
LtlModalRecoleccionTitulo.Text = "Actualizar Recolección";
|
|
BtnModalRecoleccionGuardar.Text = "Actualizar";
|
|
UpModalRecoleccion.Update();
|
|
|
|
RegistraScript("$('#DivModalRecoleccion').modal('show');");
|
|
}
|
|
|
|
private void LimpiarModalRecoleccion()
|
|
{
|
|
|
|
DdlModalRecoleccionCliente.SelectedValueExist(-1);
|
|
DdlmodalRecoleccionDirecion.SelectedValueExist(-1);
|
|
TxtModalRecoleccionCantidad.Text = "";
|
|
DdlModalRecoleccionUnidad.Items.Clear();
|
|
DdlModalRecoleccionUnidad.Items.Add(new ListItem("Seleccione una","-1"));
|
|
DdlProducto2.txtValue.Value = "";
|
|
DdlProducto2.txtText.Value = "";
|
|
|
|
DTRecoleccion.Rows.Clear();
|
|
GvModalPSRecoleccion.DataSource = DTRecoleccion;
|
|
GvModalPSRecoleccion.DataBind();
|
|
|
|
|
|
UpModalRecoleccion.Update();
|
|
}
|
|
|
|
protected void DdlProducto_ValueChanged(object sender, EventArgs e)
|
|
{
|
|
ElProductoChange();
|
|
}
|
|
|
|
private void ElProductoChange()
|
|
{
|
|
DdlModalRecoleccionUnidad.Items.Clear();
|
|
DdlModalRecoleccionUnidad.DataSource = get_GlobalDTProductosServiciosEquivalencias(DdlProducto2.SelectedValue.ToEntero(), -1, UsuarioActual.CveEmpresa);
|
|
DdlModalRecoleccionUnidad.DataBind();
|
|
UpModalRecoleccion.Update();
|
|
}
|
|
|
|
protected void BtnModalRecoleccionGuardar_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
if (DdlChofer.SelectedValue.ToEntero() <= 0)
|
|
{
|
|
Alert("Debe seleccionar un chofer.", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
return;
|
|
}
|
|
|
|
if (DdlUnidadCamion.SelectedValue.ToEntero() <= 0)
|
|
{
|
|
Alert("Debe seleccionar una unidad", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
return;
|
|
}
|
|
|
|
|
|
int CveTimbrenuevo = -1;
|
|
bool ProcesoOK = false;
|
|
|
|
|
|
|
|
|
|
int CveSubProyectoCliente = get_GlobalDTCliente(UsuarioActual.CveEmpresa, -1, DdlModalRecoleccionCliente.SelectedValue.ToEntero()).FiltroPrimeroValor("CveSubProyecto").ToEntero();
|
|
ClsGenerales ObjGenerales = new ClsGenerales();
|
|
ObjGenerales.IniciaTransacSQL();
|
|
|
|
|
|
|
|
if( CveEntregaAlmacen == -1)
|
|
{
|
|
CveEntregaAlmacen = ObjGenerales.AddInvEntregaAlmacenRuta(CveSubProyectoCliente, -1, DdlmodalRecoleccionDirecion.SelectedValue.ToEntero(), -1, DdlChofer.SelectedValue.ToEntero(), DdlUnidadCamion.SelectedValue.ToEntero(), TxtFechaEntrega.Text.ToDate(), "R", 1,0);
|
|
if (CveEntregaAlmacen > 0)
|
|
{
|
|
CveTimbrenuevo = ObjGenerales.AddGralTimbre("Tra", "-1", -1, "-1", new DateTime(1900, 01, 01), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 0, -1, ChkEmitirCartaPorte.Checked, CveEntregaAlmacen, CveSubProyectoCliente);
|
|
|
|
if (CveTimbrenuevo > 0)
|
|
{
|
|
foreach (DataRow dRow in DTRecoleccion.Rows)
|
|
{
|
|
if(ObjGenerales.AddEntregaAlmacenRutaDetalle(CveEntregaAlmacen,dRow["CvePS"].ToString().ToEntero(), dRow["Cantidad"].ToString().ToDecimal(),dRow["CveUnidadMedida"].ToString().ToEntero(), UsuarioActual.CveUsuario))
|
|
{
|
|
ProcesoOK = true;
|
|
}
|
|
else
|
|
{
|
|
|
|
ProcesoOK = false;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
if(ObjGenerales.UpdateInvEntregaAlmacenRuta(CveEntregaAlmacen,DdlmodalRecoleccionDirecion.SelectedValue.ToEntero(),-1, DdlChofer.SelectedValue.ToEntero(), DdlUnidadCamion.SelectedValue.ToEntero(),TxtFechaEntrega.Text.ToDate(), UsuarioActual.CveEmpresa))
|
|
{
|
|
ProcesoOK = true;
|
|
}
|
|
else
|
|
{
|
|
ProcesoOK = false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ProcesoOK)
|
|
{
|
|
ObjGenerales.Commit();
|
|
Alert("Recolección Guardada correctamente.");
|
|
RegistraScript("$('#DivModalRecoleccion').modal('hide');");
|
|
}
|
|
else
|
|
{
|
|
ObjGenerales.RollBack();
|
|
}
|
|
|
|
ObjGenerales.Dispose();
|
|
CargaDatosRecoleccion();
|
|
}
|
|
|
|
protected void LnkGvDatosRecoleccionEliminar_Click(object sender, EventArgs e)
|
|
{
|
|
LinkButton LnkEliminar = (LinkButton)sender;
|
|
GridViewRow GvRow = (GridViewRow)LnkEliminar.NamingContainer;
|
|
|
|
int CveEntregaAlmacenEliminar = GvRow.DataKey("CveEntregaAlmacen").ToEntero();
|
|
ClsGenerales ObjGenerales = new ClsGenerales();
|
|
if (ObjGenerales.RemoveInvEntregaAlmacenRuta(CveEntregaAlmacenEliminar, UsuarioActual.CveEmpresa))
|
|
{
|
|
Alert("Producto Eliminado correctamente.");
|
|
}
|
|
|
|
ObjGenerales.Dispose();
|
|
CargaDatosRecoleccion();
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
protected void LnkModalGvModalPSRecoleccionEliminar_Click(object sender, EventArgs e)
|
|
{
|
|
LinkButton LnkEliminar = (LinkButton)sender;
|
|
GridViewRow GvRow = (GridViewRow)LnkEliminar.NamingContainer;
|
|
|
|
if (CveEntregaAlmacen > 0)
|
|
{
|
|
|
|
|
|
int CveEntregaAlmacenDetalleEliminar = GvRow.DataKey("CveEntregaAlmacenDetalle").ToEntero();
|
|
ClsGenerales ObjGenerales = new ClsGenerales();
|
|
|
|
if (ObjGenerales.RemoveEntregaAlmacenRutaDetalle(CveEntregaAlmacenDetalleEliminar))
|
|
{
|
|
Alert("Recolección Eliminada correctamente.");
|
|
}
|
|
ObjGenerales.Dispose();
|
|
}
|
|
else
|
|
{
|
|
int DTIndex = GvRow.RowIndex;
|
|
DTRecoleccion.Rows[DTIndex].Delete();
|
|
DTRecoleccion.AcceptChanges();
|
|
|
|
}
|
|
|
|
CargaDatosRecoleccionDetallePS();
|
|
}
|
|
|
|
protected void LnkModalAgregarPS_Click(object sender, EventArgs e)
|
|
{
|
|
if(CveEntregaAlmacen > 0)
|
|
{
|
|
ClsGenerales ObjGenerales = new ClsGenerales();
|
|
|
|
if(ObjGenerales.AddEntregaAlmacenRutaDetalle(CveEntregaAlmacen,DdlProducto2.SelectedValue.ToEntero(), TxtModalRecoleccionCantidad.Text.ToEntero(), DdlModalRecoleccionUnidad.SelectedValue.ToEntero(), UsuarioActual.CveUsuario))
|
|
{
|
|
|
|
}
|
|
ObjGenerales.Dispose();
|
|
}
|
|
else
|
|
{
|
|
DataRow dRow = DTRecoleccion.NewRow() ;
|
|
|
|
dRow["CveEntregaAlmacenDetalle"] = -1;
|
|
dRow["CveEntregaAlmacen"] = CveEntregaAlmacen;
|
|
dRow["CvePS"] = DdlProducto2.SelectedValue.ToEntero();
|
|
dRow["Cantidad"] =TxtModalRecoleccionCantidad.Text.ToEntero();
|
|
dRow["CveUnidadMedida"] = DdlModalRecoleccionUnidad.SelectedValue.ToEntero();
|
|
dRow["CveUsuario"] =UsuarioActual.CveUsuario;
|
|
dRow["FechaIng"] = DateTime.Now;
|
|
dRow["CodigoPS"] = DdlProducto2.txtText.Value;
|
|
dRow["Abreviatura"] =DdlModalRecoleccionUnidad.SelectedItem.Text;
|
|
|
|
DTRecoleccion.Rows.Add(dRow);
|
|
//GvModalPSRecoleccion.DataSource = DTRecoleccion;
|
|
}
|
|
|
|
LimpiarControlesPS();
|
|
CargaDatosRecoleccionDetallePS();
|
|
|
|
}
|
|
|
|
|
|
private void LimpiarControlesPS()
|
|
{
|
|
TxtModalRecoleccionCantidad.Text = "";
|
|
DdlModalRecoleccionUnidad.Items.Clear();
|
|
DdlProducto2.txtText.Value = "";
|
|
DdlProducto2.txtValue.Value = "";
|
|
UpModalRecoleccion.Update();
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void Tab_ActiveTabChanged(object sender, EventArgs e)
|
|
{
|
|
if(Tab.ActiveTabIndex == 0)
|
|
{
|
|
SelecionEntrega = false;
|
|
SeleccioanrGenrar();
|
|
|
|
}
|
|
else
|
|
{
|
|
OcultarmostarDatosEntrega(true);
|
|
}
|
|
}
|
|
|
|
|
|
} |