420 lines
12 KiB
C#
420 lines
12 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;
|
|
}
|
|
}
|
|
|
|
|
|
bool SelecionEntrega
|
|
{
|
|
get
|
|
{
|
|
if (ViewState["SelecionEntrega"] == null)
|
|
{
|
|
ViewState["SelecionEntrega"] = false;
|
|
}
|
|
return (bool) ViewState["SelecionEntrega"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["SelecionEntrega"] = (bool)value;
|
|
}
|
|
}
|
|
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
|
|
|
|
|
|
SelecionEntrega = true;
|
|
|
|
CargaCombos();
|
|
CargaDatos();
|
|
|
|
}
|
|
}
|
|
|
|
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);
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
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";
|
|
|
|
DVDatosEntrega1.Visible = true;
|
|
DVDatosEntrega2.Visible = true;
|
|
DVDatosEntrega3.Visible = true;
|
|
DVDatosEntrega4.Visible = true;
|
|
DVDatosEntrega5.Visible = true;
|
|
DVDatosEntrega6.Visible = true;
|
|
|
|
DVDatosEntrega7.Attributes.Add("class", "col-md-1");
|
|
|
|
if (UsuarioActual.Empresa.Funcionalidad(161).ToEntero() == 1)
|
|
{
|
|
DvCartaPorte1.Visible = true;
|
|
DvCartaPorte2.Visible = 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";
|
|
DVDatosEntrega7.Attributes.Add("class", "col-md-9");
|
|
|
|
DVDatosEntrega1.Visible = false;
|
|
DVDatosEntrega2.Visible = false;
|
|
DVDatosEntrega3.Visible = false;
|
|
DVDatosEntrega4.Visible = false;
|
|
DVDatosEntrega5.Visible = false;
|
|
DVDatosEntrega6.Visible = false;
|
|
|
|
if (UsuarioActual.Empresa.Funcionalidad(161).ToEntero() == 1)
|
|
{
|
|
DvCartaPorte1.Visible = false;
|
|
DvCartaPorte2.Visible = false;
|
|
}
|
|
|
|
BtnAsignar.Visible = false;
|
|
DVGvGenerarDocumentos.Visible = false;
|
|
DVGvPaqueteriasGuias.Visible = true;
|
|
UpDatos.Update();
|
|
UpFiltro.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)
|
|
{
|
|
CargaDatos();
|
|
}
|
|
} |