424 lines
15 KiB
C#
424 lines
15 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_EntregasPorRealizar : 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;
|
|
CargarEntregas();
|
|
CargarPersonal();
|
|
}
|
|
}
|
|
|
|
protected void BtnAsignar_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
ActualizaOrdenDTGenrarDocumentos();
|
|
|
|
|
|
if (DdlUsuario.SelectedValue.ToEntero() > 0)
|
|
{
|
|
bool TieneError = false;
|
|
ClsGenerales ObjGeneral = new ClsGenerales();
|
|
ObjGeneral.IniciaTransacSQL();
|
|
|
|
GridViewRowCollection Grid = GvGenerarDocumentos.Rows;
|
|
|
|
int CvePersonal = DdlUsuario.SelectedValue.ToEntero();
|
|
long CveAsignacionEntrega = DateTime.Now.Ticks;
|
|
string Usuario = DdlUsuario.SelectedValue.ToEntero() > 0 ? DdlUsuario.SelectedItem.Text : "Todos";
|
|
|
|
string LigaPopUpVerFactura = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", ModExtensiones.Encripta(String.Format("OP=ENTREGAS&CVEASIGNACIONENTREGA={0}&USUARIOENTREGA={1}", CveAsignacionEntrega, Usuario)));
|
|
foreach (GridViewRow row in Grid)
|
|
{
|
|
int CvePaqueteriasGuias = row.DataKey("CvePaqueteriaGuia").ToEntero();
|
|
int Orden = row.DataKey("Orden").ToEntero();
|
|
|
|
if (!ObjGeneral.AsignarEntregasPorRealizar(CvePaqueteriasGuias, CvePersonal:CvePersonal, CveAsignacionEntrega: CveAsignacionEntrega, Orden: Orden))
|
|
{
|
|
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(String.Format("Entregas asignadas correctamente <br/><br/><a style='color:#23527c' href='{0}'>Imprimir Reporte de Entregas Asignadas</a>", LigaPopUpVerFactura));
|
|
|
|
SelecionEntrega = false;
|
|
SeleccioanrGenrar();
|
|
|
|
CargarEntregas();
|
|
UpDatos.Update();
|
|
}
|
|
else
|
|
{
|
|
ObjGeneral.RollBack();
|
|
}
|
|
ObjGeneral.Dispose();
|
|
}
|
|
else
|
|
{
|
|
Alert("Seleccione a alguien del personal", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
}
|
|
}
|
|
}
|
|
private void CargarEntregas()
|
|
{
|
|
ClsGenerales ObjGeneral = new ClsGenerales();
|
|
if (ObjGeneral.GetEntregasPorRealizar(UsuarioActual.CveEmpresa))
|
|
{
|
|
GvPaqueteriasGuias.DataSource = ObjGeneral.DtResultados;
|
|
DTDatosConsulta = ObjGeneral.DtResultados;
|
|
DTGenrarDocumentos = ObjGeneral.DtResultados.Clone();
|
|
|
|
}
|
|
ObjGeneral.Dispose();
|
|
GvPaqueteriasGuias.DataBind();
|
|
}
|
|
|
|
private void CargarPersonal()
|
|
{
|
|
DataTable UsuariosConRolLogistico = get_GlobalDTUsuarios(CveEmpresa: UsuarioActual.CveEmpresa).FiltraParametros("CveRol IN (1339,1386,1430,1155)");
|
|
DdlUsuario.DataSource = UsuariosConRolLogistico;
|
|
DdlUsuario.DataBind();
|
|
DdlUsuario.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
}
|
|
|
|
//protected void LnkImprimir_Click(object sender, EventArgs e)
|
|
//{
|
|
// List<ReportParameter> RepParams = new List<ReportParameter>();
|
|
// string Usuario = DdlUsuario.SelectedValue.ToEntero() > 0 ? DdlUsuario.SelectedItem.Text : "Todos";
|
|
// RepParams.Add(new ReportParameter("Fecha", DateTime.Today.ToString()));
|
|
// RepParams.Add(new ReportParameter("AsignadoA", Usuario));
|
|
// RepParams.Add(new ReportParameter("UsuarioImprimio", UsuarioActual.Nombre));
|
|
|
|
// ImprimirPDF($"Empresas/{UsuarioActual.CveEmpresa}/Formatos/EntregasPorRealizar.rdlc", DtPaqueteriasGuias, RepParams, "Entregas por realizar", "PDF",RDSName:"DsInventarios");
|
|
//}
|
|
|
|
private string DocumentoEntregaInterna(GridViewRow row)
|
|
{
|
|
string ClienteNombre = row.DataKey("NombreComercial");
|
|
string FolioVenta = row.DataKey("SerieFolio");
|
|
string Pedido = row.DataKey("PedidoContrato");
|
|
string OrdenCompra = row.DataKey("OrdenCompra");
|
|
int CveVenta = row.DataKey("CveVenta").ToEntero();
|
|
string TipoDocto = row.DataKey("TipoDocto");
|
|
|
|
DataTable DtDetalle = new DataTable();
|
|
ClsVentas ObjVentas = new ClsVentas();
|
|
if (ObjVentas.GetVentaDetalle(CveVenta))
|
|
{
|
|
DtDetalle = ObjVentas.DtResultados;
|
|
}
|
|
ObjVentas.Dispose();
|
|
|
|
string DetalleTable = "";
|
|
foreach (DataRow dRow in DtDetalle.Rows)
|
|
{
|
|
string detalle = string.Format("<tr><td style='width:25%'>{0}</td><td style='width:25%'>{1}</td><td style='width:50%'>{2}</td></tr>", dRow["Codigo"], dRow["Cantidad"], dRow["PS"]);
|
|
DetalleTable += detalle;
|
|
}
|
|
|
|
StringBuilder strBody = new StringBuilder();
|
|
|
|
strBody.Append("<html>");
|
|
strBody.Append("<head>");
|
|
strBody.Append("<meta charset='UTF-8'>");
|
|
strBody.Append("</head>");
|
|
strBody.Append(" <body style='width:800px'>");
|
|
strBody.Append("<div>");
|
|
strBody.Append($"<img src='http://sig.adssistemas.mx/Empresas/{UsuarioActual.CveEmpresa}/Logo.png' style='width:200px'></img>");
|
|
strBody.Append("</div>");
|
|
strBody.Append(" <p style='font-family:Segoe UI Semibold;font-size:12pt;width:100%'>");
|
|
strBody.Append($" Apreciable {ClienteNombre}, su pedido ya se encuentra en camino. Le confirmamos los productos que recibirá conforme a la ");
|
|
strBody.Append($" {TipoDocto}:");
|
|
strBody.Append(" </p>");
|
|
strBody.Append($" <p style='width:100%;text-align:center;font-family:Segoe UI Semibold;font-size:12pt'>{FolioVenta} - Pedido {Pedido} - Orden de Compra {OrdenCompra}</P>");
|
|
strBody.Append(" <div style='width:100%;text-align:center'>");
|
|
strBody.Append(" <table style='width:100%;font-family:Segoe UI Semibold;font-size:12pt'>");
|
|
strBody.Append(DetalleTable);
|
|
strBody.Append(" </table>");
|
|
strBody.Append(" </div>");
|
|
strBody.Append(" <p style='font-family:Segoe UI Semibold;font-size:12pt;width:100%'>");
|
|
strBody.Append(" Solicitamos su apoyo en la verificación del pedido que está próximo a recibir y en caso de presentarse alguno de los siguientes inconvenientes favor de rechazar el paquete y comunicarse de inmediato con su Ejecutivo Comercial:");
|
|
strBody.Append(" </p>");
|
|
strBody.Append(" <p style='font-family:Segoe UI Semibold;font-size:12pt;width:100%'>");
|
|
strBody.Append(" • Empaque violado.<br/>");
|
|
strBody.Append("• Daño físico en la caja.<br/>");
|
|
strBody.Append("• Producto incompleto o distinto al solicitado.<br/>");
|
|
strBody.Append("• Alguna otra situación que se considere que compromete la integridad de la mercancía.");
|
|
strBody.Append("");
|
|
strBody.Append(" </p>");
|
|
strBody.Append(" <br/>");
|
|
strBody.Append(" <p style='font-family:Segoe UI Semibold;font-size:12pt;width:100%'>");
|
|
strBody.Append(" Gracias por realizar su pedido <br/>");
|
|
//strBody.Append(" Compuproveedores");
|
|
strBody.Append(" </p>");
|
|
strBody.Append(" <p style='font-family:Segoe UI Semibold;font-size:12pt;width:100%;text-align:center'>");
|
|
strBody.Append(" Sigue disfrutando de nuestros productos y servicios<br/>");
|
|
//strBody.Append(" <a href='https://www.compuproveedoresti.com/'>www.compuproveedores.com</a>");
|
|
strBody.Append("");
|
|
strBody.Append(" </p>");
|
|
strBody.Append(" </body>");
|
|
strBody.Append("</html>");
|
|
|
|
//List<ReportParameter> RepParams = new List<ReportParameter>();
|
|
//RepParams.Add(new ReportParameter("Cliente", ClienteNombre));
|
|
//RepParams.Add(new ReportParameter("FolioVenta", FolioVenta));
|
|
//RepParams.Add(new ReportParameter("Pedido", Pedido));
|
|
//RepParams.Add(new ReportParameter("OrdenCompra", OrdenCompra));
|
|
//return StreamPDF($"Empresas/{UsuarioActual.CveEmpresa}/Formatos/GuiaInternaAsignada.rdlc", DtDetalle, RepParams, "Notificacion de Envio", "PDF", RDSName: "DsInventarios");
|
|
return strBody.ToString();
|
|
}
|
|
|
|
private void MandarNotificacionCorreo(GridViewRow row)
|
|
{
|
|
string CorreoEntregaAlmacen = row.DataKey("CorreoEntregaAlmacen");
|
|
string CorreoEntregaCompras = row.DataKey("CorreoEntregaCompras");
|
|
string CorreoVendedor = row.DataKey("Correo");
|
|
string CorreoNotificacion = row.DataKey("CorreoNotificacion");
|
|
int CveVendedor = row.DataKey("CveVendedor").ToEntero();
|
|
string CorreoAsistente = get_GlobalDTVendedores(UsuarioActual.CveEmpresa,VendedorTipo:3).FiltroPrimeroValor("Correo",string.Format("CveSuperior = {0}", CveVendedor));
|
|
|
|
string Para = string.Format("{0};{1};{2};{3};{4}", CorreoVendedor, CorreoNotificacion, CorreoEntregaCompras,CorreoEntregaAlmacen,CorreoAsistente);
|
|
string LogCorreo = string.Format("{0} -- {1} --- {2}", "Tipo de entrega", CorreoEntregaAlmacen, Para);
|
|
LogCorreo.GuardaLog();
|
|
|
|
//byte[] ArchivoBinario = DocumentoEntregaInterna(row);
|
|
string body = DocumentoEntregaInterna(row);
|
|
|
|
ClsSisMail MailCls = new ClsSisMail();
|
|
//List<ClsSisMail.ArchivoMail> LSRutasMail = new List<ClsSisMail.ArchivoMail>();
|
|
//ClsSisMail.ArchivoMail itemMail = new ClsSisMail.ArchivoMail();
|
|
|
|
//{
|
|
// var withBlock = itemMail;
|
|
// itemMail.ArchivoBinario = ArchivoBinario;
|
|
// itemMail.NombreArchivo = "Notificacion de Envio";
|
|
//}
|
|
|
|
//LSRutasMail.Add(itemMail);
|
|
MailCls.SendMail(ClsPaginas.EmpresaNotificaciones, Para, "Entrega en camino", body, Para);
|
|
MailCls = null;
|
|
}
|
|
|
|
|
|
|
|
protected void LnkGenerarDocumentos_Click(object sender, EventArgs e)
|
|
{
|
|
SeleccioanrGenrar();
|
|
}
|
|
|
|
|
|
private void SeleccioanrGenrar() {
|
|
|
|
if (SelecionEntrega)
|
|
{
|
|
|
|
|
|
if (DdlUsuario.SelectedValue.ToEntero() <= 0)
|
|
{
|
|
Alert("Debe seleccionar entregas", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
return;
|
|
}
|
|
|
|
DTGenrarDocumentos.Rows.Clear();
|
|
|
|
|
|
|
|
int CountRows = 0;
|
|
foreach (GridViewRow GvRow in GvPaqueteriasGuias.Rows)
|
|
{
|
|
|
|
CheckBox ChkAsigna = GvRow.FCCheckBox("ChkAsigna");
|
|
|
|
if (ChkAsigna.Checked)
|
|
{
|
|
|
|
int CvePaqueteriaGuia = GvRow.DataKey("CvePaqueteriaGuia").ToEntero();
|
|
|
|
DataRow dRow = DTGenrarDocumentos.NewRow();
|
|
DataRow dRowOrigen = DTDatosConsulta.FiltraParametros($"CvePaqueteriaGuia = {CvePaqueteriaGuia}").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();
|
|
|
|
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;
|
|
}
|
|
|
|
|
|
SelecionEntrega = false;
|
|
LnkGenerarDocumentos.Text = "Regresa a selección";
|
|
|
|
BtnAsignar.Visible = true;
|
|
|
|
UpDatos.Update();
|
|
UpFiltro.Update();
|
|
}
|
|
else
|
|
{
|
|
|
|
SelecionEntrega = true;
|
|
LnkGenerarDocumentos.Text = "Generar Documentos";
|
|
BtnAsignar.Visible = true;
|
|
DVGvGenerarDocumentos.Visible = false;
|
|
DVGvPaqueteriasGuias.Visible = true;
|
|
UpDatos.Update();
|
|
UpFiltro.Update();
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void GvGenerarDocumentos_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if(e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
// e.Row.CssClass = $"{e.Row.CssClass} RowOrdenamiento";
|
|
// e.Row.Attributes.Add("onmouseup ", "alert('boton liberado')");
|
|
|
|
}
|
|
}
|
|
|
|
private void ActualizaOrdenDTGenrarDocumentos()
|
|
{
|
|
string[] OrdenCvePaqueteriaGuia = Request.Form.GetValues("OrdenCvePaqueteriaGuia");
|
|
|
|
int NumOrden = 1;
|
|
foreach (string CvePaqueteriaGuia in OrdenCvePaqueteriaGuia)
|
|
{
|
|
foreach(DataRow dRow in DTGenrarDocumentos.Rows)
|
|
{
|
|
if (CvePaqueteriaGuia.ToEntero() == dRow["CvePaqueteriaGuia"].ToString().ToEntero() )
|
|
{
|
|
dRow["Orden"] = NumOrden;
|
|
}
|
|
}
|
|
DTGenrarDocumentos.AcceptChanges();
|
|
NumOrden++;
|
|
}
|
|
|
|
GvGenerarDocumentos.DataSource = DTGenrarDocumentos;
|
|
GvGenerarDocumentos.DataBind();
|
|
UpDatos.Update();
|
|
|
|
|
|
|
|
}
|
|
} |