Files
SIG/Inventarios/EntregasPorRealizar.aspx.cs
2020-07-14 13:31:12 -07:00

229 lines
11 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
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CargarEntregas();
CargarPersonal();
}
}
protected void BtnAsignar_Click(object sender,EventArgs e)
{
if (DdlUsuario.SelectedValue.ToEntero() > 0)
{
bool TieneError = false;
ClsGenerales ObjGeneral = new ClsGenerales();
ObjGeneral.IniciaTransacSQL();
GridViewRowCollection Grid = GvPaqueteriasGuias.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)
{
if (row.FCCheckBox("ChkAsigna").Checked)
{
int CvePaqueteriasGuias = row.DataKey("CvePaqueteriaGuia").ToEntero();
if(!ObjGeneral.AsignarEntregasPorRealizar(CvePaqueteriasGuias, CvePersonal, CveAsignacionEntrega)){
TieneError = true;
}else
{
try
{
MandarNotificacionCorreo(row);
}
catch (Exception ex)
{
TieneError = true;
ModExtensiones.GuardaLog(ex.Message);
}
//string CobranzaCorreo = row.DataKey("CobranzaCorreo");
//string CorreoEntregaAlmacen = row.DataKey("CorreoEntregaAlmacen");
//string CorreoEntregaCompras = row.DataKey("CorreoEntregaCompras");
//string CorreoVendedor = row.DataKey("Correo");
//string CorreoAdicionalNotificacionesVendedor = row.DataKey("CorreoAdicionalNotificaciones");
//string CorreosCC = string.Format("{0};{1};{2};{3}", CorreoVendedor, CorreoAdicionalNotificacionesVendedor, CobranzaCorreo, CorreoEntregaCompras);
//string LogCorreo = string.Format("{0} -- {1} --- {2}", "Tipo de entrega", CorreoEntregaAlmacen, CorreosCC);
//LogCorreo.GuardaLog();
//ClsSisMail MailCls = new ClsSisMail();
//MailCls.SendMail(ClsPaginas.EmpresaNotificaciones, CorreoVendedor, "Se enviara la compra a su dirección", "Pendiente", CorreosCC);
//MailCls = null;
}
}
}
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));
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;
}
ObjGeneral.Dispose();
GvPaqueteriasGuias.DataBind();
}
private void CargarPersonal()
{
DataTable UsuariosConRolLogistico = get_GlobalDTUsuarios(CveEmpresa: UsuarioActual.CveEmpresa).FiltraParametros("CveRol IN (1339,1386,1430)");
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>");
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:80%;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 CobranzaCorreo = row.DataKey("CobranzaCorreo");
string CorreoEntregaAlmacen = row.DataKey("CorreoEntregaAlmacen");
string CorreoEntregaCompras = row.DataKey("CorreoEntregaCompras");
string CorreoVendedor = row.DataKey("Correo");
string CorreoAdicionalNotificacionesVendedor = row.DataKey("CorreoAdicionalNotificaciones");
string Para = string.Format("{0};{1};{2};{3}", CorreoVendedor, CorreoAdicionalNotificacionesVendedor, CobranzaCorreo, CorreoEntregaCompras);
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;
}
}