626 lines
29 KiB
VB.net
626 lines
29 KiB
VB.net
Option Explicit On
|
|
Option Strict On
|
|
Imports System.Data
|
|
Imports System.IO
|
|
Imports Extensiones
|
|
Imports GemBox.Spreadsheet
|
|
|
|
Partial Class Bancos_RepComplementoPago
|
|
Inherits ClsPaginas
|
|
|
|
|
|
#Region "C A N C E L A C I O N DE C O M P L E M E N T O S"
|
|
|
|
Private Property Can_FolioFiscalCancelar As String
|
|
Get
|
|
|
|
If ViewState("Can_FolioFiscalCancelar") Is Nothing Then
|
|
ViewState("Can_FolioFiscalCancelar") = ""
|
|
End If
|
|
|
|
Return ViewState("Can_FolioFiscalCancelar").ToString
|
|
|
|
End Get
|
|
Set(value As String)
|
|
ViewState("Can_FolioFiscalCancelar") = value
|
|
End Set
|
|
End Property
|
|
|
|
|
|
Private Property Can_CveComplementoPagoCancelar As Integer
|
|
Get
|
|
|
|
If ViewState("Can_CveComplementoPagoCancelar") Is Nothing Then
|
|
ViewState("Can_CveComplementoPagoCancelar") = ""
|
|
End If
|
|
|
|
Return ViewState("Can_CveComplementoPagoCancelar").ToString.ToEntero
|
|
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("Can_CveComplementoPagoCancelar") = value
|
|
End Set
|
|
End Property
|
|
|
|
Private Property Can_CvePACCancelacion As Integer
|
|
Get
|
|
|
|
If ViewState("Can_CvePACCancelacion") Is Nothing Then
|
|
ViewState("Can_CvePACCancelacion") = ""
|
|
End If
|
|
|
|
Return ViewState("Can_CvePACCancelacion").ToString.ToEntero
|
|
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("Can_CvePACCancelacion") = value
|
|
End Set
|
|
End Property
|
|
|
|
Private Property Can_RFCReceptorCancelar As String
|
|
Get
|
|
|
|
If ViewState("Can_RFCReceptorCancelar") Is Nothing Then
|
|
ViewState("Can_RFCReceptorCancelar") = ""
|
|
End If
|
|
|
|
Return ViewState("Can_RFCReceptorCancelar").ToString
|
|
|
|
End Get
|
|
Set(value As String)
|
|
ViewState("Can_RFCReceptorCancelar") = value
|
|
End Set
|
|
End Property
|
|
|
|
|
|
|
|
#End Region
|
|
|
|
Private Sub Bancos_RepComplementoPago_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
|
|
If Not Page.IsPostBack Then
|
|
|
|
txtFechaI.Text = $"{New DateTime(Now.Year, Now.Month, 1).ToString("dd/MM/yyyy")}"
|
|
txtFechaF.Text = DateTime.Now.ToString("dd/MM/yyyy")
|
|
DdlCliente.setEsWebService(True)
|
|
|
|
DdlMotivoCancelacion.DataSource = GlobalDTMotivosCancelacionEmpresa(UsuarioActual.CveEmpresa).FiltraParametros("CveSATMotivoCancelacion = 2 or CveSATMotivoCancelacion = 3 ")
|
|
DdlMotivoCancelacion.DataBind()
|
|
DdlMotivoCancelacion.Items.Insert(0, New ListItem("Seleccione uno", "-1"))
|
|
|
|
|
|
Dim objGral As New ClsGralFolios
|
|
If objGral.GetFolios("CP", UsuarioActual.CveEmpresa) Then
|
|
If objGral.DtResultados.Rows.Count > 0 Then
|
|
BtnEmitir.Visible = True
|
|
Else
|
|
Alert("No se cuenta con folios para emitir complemento de pago", TipoMensaje.MsgAdvertencia)
|
|
End If
|
|
End If
|
|
|
|
CargaDatos()
|
|
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub BtnEmitir_Click(sender As Object, e As EventArgs) Handles BtnEmitir.Click
|
|
GeneraTimbre()
|
|
End Sub
|
|
|
|
Private Sub CargaDatos()
|
|
Dim CveCliente As Integer = If(DdlCliente.SelectedValue.ToEntero > 0, DdlCliente.SelectedValue.ToEntero, -1)
|
|
Dim Banco As New ClsBancos
|
|
LnkExcel.Visible = False
|
|
If Banco.GetComplementoPagosRep(CveCliente, txtFechaI.Text.ToDateTime, txtFechaF.Text.ToDateTime, -1, -1, DdlOpcion.SelectedValue.ToEntero, UsuarioActual.CveEmpresa, Estatus:=DdlEstatus.SelectedValue.ToEntero) Then
|
|
|
|
GvD.DataSource = Banco.DtResultados '.FiltraParametros("CveComplementoPago is null")
|
|
|
|
|
|
|
|
If Banco.DtResultados.Rows.Count > 0 Then
|
|
LnkExcel.Visible = True
|
|
End If
|
|
|
|
End If
|
|
|
|
Banco.Dispose()
|
|
If DdlOpcion.SelectedValue = "2" Then GvD.Columns(8).Visible = True Else GvD.Columns(8).Visible = False
|
|
|
|
GvD.DataBind()
|
|
UpDatos.Update()
|
|
UpAcciones.Update()
|
|
|
|
End Sub
|
|
|
|
Private Sub GeneraTimbre()
|
|
|
|
Dim Str As New StringBuilder
|
|
|
|
|
|
For Each gvr As GridViewRow In GvD.Rows
|
|
If gvr.FCCheckBox("Chk").Checked Then
|
|
Dim FechaTimbrado As DateTime = DateTime.Now
|
|
|
|
Dim UTCOffset As Integer = 0
|
|
|
|
If Now.EsHorarioVerano Then
|
|
If gvr.DataKey("UTCOffsetVerano").ToEntero() <> 0 Then
|
|
UTCOffset = gvr.DataKey("UTCOffsetVerano").ToEntero()
|
|
End If
|
|
Else
|
|
If gvr.DataKey("UTCOffsetInvierno").ToEntero() <> 0 Then
|
|
UTCOffset = gvr.DataKey("UTCOffsetInvierno").ToEntero()
|
|
End If
|
|
End If
|
|
|
|
If UTCOffset <> 0 Then
|
|
FechaTimbrado = DateTime.UtcNow.AddHours(UTCOffset)
|
|
End If
|
|
|
|
Dim Banco As New ClsBancos
|
|
Banco.IniciaTransacSQL()
|
|
Try
|
|
If Banco.GeneraTimbrePago(gvr.DataKey("CveIE").ToEntero, -1, UsuarioActual, FechaTimbrado:=FechaTimbrado) Then
|
|
If Banco.Mensaje = "" Then
|
|
Banco.Commit()
|
|
PDFReciboDePagos(-1, -1, Banco.CveComplementoPago, False)
|
|
Str.AppendFormat("Folio: <b>{0}</b> ", Banco.ComplementoSerieFolio)
|
|
Str.AppendFormat("<a class=""texto"" style='color:#337ab7' href=""/Compras/PopUpVerFactura.aspx?P={0}"" target=""_blank"">XML <i class=""fa fa-file""></i></i></a> ", Encripta(String.Format("OP=CompP&EXT=xml&SerieFolio={0}&CveComplementoPago={1}", Banco.ComplementoSerieFolio, Banco.CveComplementoPago)))
|
|
Str.AppendFormat("<a class=""texto"" style='color:#337ab7' href=""/Compras/PopUpVerFactura.aspx?P={0}"" target=""_blank"">PDF <i class=""fa fa-ad-pdf""></i></i></i></a> ", Encripta(String.Format("OP=CompP&EXT=pdf&SerieFolio={0}&CveComplementoPago={1}", Banco.ComplementoSerieFolio, Banco.CveComplementoPago)))
|
|
Str.AppendFormat("<a style='color:#337ab7' target='_blank' href='./IE.aspx?CveIE={0}'>{1}</a> {2}<br>", gvr.DataKey("CveIE"), gvr.DataKey("Folio"), gvr.DataKey("NombreCliente"))
|
|
MandaCorreo(Banco.ComplementoSerieFolio, gvr.DataKey("CobranzaCorreo"))
|
|
End If
|
|
Else
|
|
Str.AppendFormat("No se genero complemento del Folio {0} por el siguiente motivo: {1}", gvr.DataKey("Folio"), Banco.Mensaje)
|
|
Banco.RollBack()
|
|
End If
|
|
Catch ex As Exception
|
|
OnError("Ocurrió un error al generar el complemento de pago", ex)
|
|
Banco.RollBack()
|
|
End Try
|
|
Banco.Dispose()
|
|
End If
|
|
Next
|
|
CargaDatos()
|
|
Alert(Str.ToString)
|
|
End Sub
|
|
|
|
Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs)
|
|
CargaDatos()
|
|
UpDatos.Update()
|
|
End Sub
|
|
|
|
Private Sub GvD_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvD.RowDataBound
|
|
|
|
If e.Row.RowType = DataControlRowType.DataRow Then
|
|
If e.Row.DBCampo("CveVenta") = "" Then
|
|
If DdlEstatus.SelectedValue.ToEntero <> 2 Then
|
|
e.Row.BackColor = Drawing.Color.LightGray
|
|
End If
|
|
If e.Row.DBCampo("CveIE") <> "" Then
|
|
|
|
If e.Row.DBCampo("CveComplementoPago") = "" Then
|
|
e.Row.FCCheckBox("Chk").Visible = True
|
|
|
|
'VALIDACION DE FORMA DE PAGO
|
|
Dim Mensaje As String = ValidaCuentaDePagoFormaDePago(e.Row.DBCampo("CveTipoTransaccion").ToEntero(), e.Row.DBCampo("ClaveFormaPagoSAT").ToEntero(), e.Row.DBCampo("CuentaBeneficiario").ToString(), e.Row.DBCampo("CuentaOrdenante").ToString())
|
|
If Mensaje = "" Then
|
|
If e.Row.DBCampo("SinFolioFiscal").ToEntero > 0 Then
|
|
Mensaje = "El Pago contiene facturas que no tienen folio fiscal"
|
|
End If
|
|
End If
|
|
If e.Row.DBCampo("BloqueadoUtilerias") = "1" Then
|
|
Mensaje = "Bloqueado Timbrando por aplicacion"
|
|
End If
|
|
e.Row.FCLiteral("LtlMon").Text = e.Row.DBCampo("PagoAbreviaturaSAT")
|
|
|
|
If Not Mensaje.Length = 0 Then
|
|
e.Row.ForeColor = Drawing.Color.Red
|
|
e.Row.FCCheckBox("Chk").Enabled = False
|
|
e.Row.FCCheckBox("Chk").ToolTip = Mensaje
|
|
End If
|
|
|
|
Else
|
|
e.Row.FCHyperLink("HplXML").Visible = True : e.Row.FCHyperLink("HplXML").NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=CompP&EXT=xml&CveComplementoPago={0}&SerieFolio={1}&CveIE={2}", e.Row.DBCampo("CveComplementoPago"), e.Row.DBCampo("SerieFolioPago").ToString.Replace("&", "%26%"), e.Row.DBCampo("CveIE").ToString)))
|
|
e.Row.FCHyperLink("HplPDF").Visible = True : e.Row.FCHyperLink("HplPDF").NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=CompP&EXT=pdf&CveComplementoPago={0}&SerieFolio={1}&CveIE={2}", e.Row.DBCampo("CveComplementoPago"), e.Row.DBCampo("SerieFolioPago").ToString.Replace("&", "%26%"), e.Row.DBCampo("CveIE").ToString)))
|
|
e.Row.FCLinkButton("LnkSendMail").Visible = True
|
|
|
|
If DdlOpcion.SelectedValue.ToEntero = 2 Then
|
|
e.Row.FCLinkButton("LnkCancelarFolioFiscal").Visible = True
|
|
End If
|
|
|
|
End If
|
|
|
|
e.Row.Cells(1).Text = String.Format("{0} - {1}", e.Row.DBCampo("Banco"), e.Row.DBCampo("NumCuenta"))
|
|
e.Row.FCLiteral("LtlFecha").Text = e.Row.DBCampo("FechaDocumento").ToDate.ToShortDateString
|
|
e.Row.FCHyperLink("HplIE").Visible = True
|
|
e.Row.FCLabel("LblImp").Text = e.Row.DBCampo("VentasTotalPagado").FormatoNumero
|
|
|
|
e.Row.FCLabel("LblImp").ToolTip = String.Format("Importe Pagado:{0} ", e.Row.DBCampo("Importe").FormatoNumero) ' VentasTotalPagado
|
|
If e.Row.DBCampo("Importe").ToDecimal.RoundAD <> e.Row.DBCampo("VentasTotalPagado").ToDecimal.RoundAD Then
|
|
e.Row.FCLabel("LblImp").ForeColor = Drawing.Color.Red
|
|
e.Row.FCLabel("LblImp").ToolTip = String.Format("Importe Pagado:{0} Importe Pagado PUE: {1}, Ot. Ingresos {2}", e.Row.DBCampo("Importe").FormatoNumero, e.Row.DBCampo("PagadoPUE").FormatoNumero, e.Row.DBCampo("PagadoOtIngresos").FormatoNumero) ' VentasTotalPagado
|
|
'si hay una diferencia generado por el tipo de cambio o alguna situación especial, detendrá el timbrado
|
|
If Math.Abs(e.Row.DBCampo("Importe").ToDecimal - e.Row.DBCampo("VentasTotalPagado").ToDecimal) > 11 Then
|
|
' si tiene pagado PUE, habilitamos la condición porque esa puede ser la diferencia
|
|
If e.Row.DBCampo("PagadoPUE").ToDecimal > 0 OrElse e.Row.DBCampo("PagadoOtIngresos").ToDecimal > 0 Then
|
|
e.Row.FCCheckBox("Chk").Visible = True
|
|
Else
|
|
e.Row.FCCheckBox("Chk").Visible = False
|
|
End If
|
|
|
|
e.Row.FCCheckBox("Chk").ToolTip += ". Hay una inconsistencia entre lo pagado en las facturas y el importe expedido"
|
|
End If
|
|
End If
|
|
|
|
End If
|
|
Else
|
|
e.Row.FCHyperLink("HplCliente").Text = ""
|
|
e.Row.FCHyperLink("HplIE").Visible = True
|
|
e.Row.FCHyperLink("HplIE").Text = e.Row.DBCampo("MetodoPago")
|
|
e.Row.FCHyperLink("HplIE").NavigateUrl = ""
|
|
e.Row.FCHyperLink("HplIE").CssClass = ""
|
|
|
|
End If
|
|
End If
|
|
|
|
If e.Row.RowType = DataControlRowType.Header Then
|
|
If DdlOpcion.SelectedValue = "1" Then
|
|
e.Row.FCCheckBox("ChkHeader").Visible = True
|
|
Else
|
|
e.Row.FCCheckBox("ChkHeader").Visible = False
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
Protected Sub BtnSendMail_Click(sender As Object, e As System.EventArgs) Handles BtnSendMail.Click
|
|
|
|
If HdnSerieFolioPago.Value <> "-1" Then
|
|
MandaCorreo(HdnSerieFolioPago.Value, TxtParaMail.Text.Trim)
|
|
End If
|
|
|
|
End Sub
|
|
|
|
Private Sub MandaCorreo(NombreArchivo As String, Correo As String, Optional ConAlerta As Boolean = True)
|
|
Try
|
|
Dim Msg As String = ""
|
|
If NombreArchivo <> "-1" Then '
|
|
|
|
Dim ObjMail As New ClsSisMail()
|
|
Dim RutaXML As String = String.Format("{0}\XML\Pag\{1}.xml", UsuarioActual.Empresa.Ruta, NombreArchivo)
|
|
Dim RutaPDF As String = String.Format("{0}\PDF\Pag\{1}.pdf", UsuarioActual.Empresa.Ruta, NombreArchivo)
|
|
|
|
Dim Cuerpo As String = "Se hace entrega del comprobante de pago"
|
|
Dim Asunto As String = "Entrega de comprobante de pago"
|
|
|
|
If IO.File.Exists(RutaPDF) AndAlso IO.File.Exists(RutaXML) Then
|
|
|
|
Dim LSRutasMail As New List(Of ClsSisMail.ArchivoMail)
|
|
|
|
LSRutasMail.Add(New ClsSisMail.ArchivoMail With {.Ruta = RutaPDF})
|
|
LSRutasMail.Add(New ClsSisMail.ArchivoMail With {.Ruta = RutaXML})
|
|
|
|
If ObjMail.SendMail(UsuarioActual.Empresa, Correo, Asunto, Cuerpo, TxtCC.Text.Trim, LSRutasMail) Then
|
|
|
|
If ConAlerta Then
|
|
TxtCC.Text = ""
|
|
RegistraScript("$('#ModalDivMail').modal('hide');")
|
|
Alert("El correo se envió correctamente", TipoMensaje.MsgInformacion)
|
|
End If
|
|
|
|
Else
|
|
Msg = "No se pudo enviar el correo electrónico."
|
|
End If
|
|
|
|
Else
|
|
Msg = "No se pudo adjuntar el correo electrónico."
|
|
End If
|
|
|
|
End If
|
|
|
|
If ConAlerta AndAlso Msg <> "" Then
|
|
Alert(Msg, TipoMensaje.MsgError)
|
|
End If
|
|
|
|
|
|
Catch ex As Exception
|
|
OnError("Ocurrió error al mandar MAIL", ex)
|
|
|
|
End Try
|
|
End Sub
|
|
|
|
Function ValidaCuentaDePagoFormaDePago(CveTipoTransaccion As Integer, ClaveFormaPagoSAT As Integer, CuentaBeneficiario As String, CuentaPago As String) As String
|
|
Dim Mensaje As String = ""
|
|
|
|
If Not (CveTipoTransaccion > 0) Then
|
|
Mensaje = "Tipo de Transaccion o Cuenta no definidas"
|
|
End If
|
|
|
|
Select Case ClaveFormaPagoSAT.ToString
|
|
Case "1"
|
|
' no tiene restricciones
|
|
Case "2"
|
|
If CuentaPago <> "" AndAlso Not CuentaPago.Length.Contiene(11, 18) Then
|
|
Mensaje = "La cuenta ordenante no cumple con el formato esperado."
|
|
End If
|
|
|
|
If CuentaBeneficiario <> "" AndAlso Not (CuentaBeneficiario.Length.Contiene(10, 11, 15, 16, 18, 50)) Then
|
|
Mensaje = $"{Mensaje} La Cuenta Beneficiario no cumple con el formato esperado."
|
|
End If
|
|
Case "3"
|
|
If CuentaPago <> "" AndAlso Not CuentaPago.Length.Contiene(10, 16, 18) Then
|
|
Mensaje = "La cuenta ordenante no cumple con el formato esperado."
|
|
End If
|
|
If CuentaBeneficiario <> "" AndAlso Not (CuentaBeneficiario.Length.Contiene(10, 18)) Then
|
|
Mensaje = $"{Mensaje} La Cuenta Beneficiario no cumple con el formato esperado."
|
|
End If
|
|
Case "4"
|
|
If CuentaPago <> "" AndAlso Not CuentaPago.Length.Contiene(16) Then
|
|
Mensaje = "La cuenta ordenante no cumple con el formato esperado."
|
|
End If
|
|
|
|
If CuentaBeneficiario <> "" AndAlso Not (CuentaBeneficiario.Length.Contiene(10, 11, 15, 16, 18, 50)) Then
|
|
Mensaje = $"{Mensaje} La Cuenta Beneficiario no cumple con el formato esperado."
|
|
End If
|
|
|
|
Case "5"
|
|
If CuentaPago <> "" AndAlso Not CuentaPago.Length.Contiene(10, 11, 15, 16, 18, 50) Then
|
|
Mensaje = "La cuenta ordenante no cumple con el formato esperado."
|
|
End If
|
|
|
|
If CuentaBeneficiario <> "" AndAlso Not (CuentaBeneficiario.Length.Contiene(10, 11, 15, 16, 18, 50)) Then
|
|
Mensaje = $"{Mensaje} La Cuenta Beneficiario no cumple con el formato esperado."
|
|
End If
|
|
Case "6"
|
|
If CuentaPago <> "" AndAlso Not CuentaPago.Length.Contiene(10) Then
|
|
Mensaje = "La cuenta ordenante no cumple con el formato esperado."
|
|
End If
|
|
|
|
CuentaBeneficiario = ""
|
|
Case "28"
|
|
If CuentaPago <> "" AndAlso Not CuentaPago.Length.Contiene(16) Then
|
|
Mensaje = "La cuenta ordenante no cumple con el formato esperado."
|
|
End If
|
|
|
|
If CuentaBeneficiario <> "" AndAlso Not (CuentaBeneficiario.Length.Contiene(10, 11, 15, 16, 18, 50)) Then
|
|
Mensaje = $"{Mensaje} La Cuenta Beneficiario no cumple con el formato esperado."
|
|
End If
|
|
Case "29"
|
|
If CuentaPago <> "" AndAlso Not CuentaPago.Length.Contiene(15, 16) Then
|
|
Mensaje = "La cuenta ordenante no cumple con el formato esperado."
|
|
End If
|
|
|
|
If CuentaBeneficiario <> "" AndAlso Not (CuentaBeneficiario.Length.Contiene(10, 11, 15, 16, 18, 50)) Then
|
|
Mensaje = $"{Mensaje} La Cuenta Beneficiario no cumple con el formato esperado."
|
|
End If
|
|
Case Else
|
|
Mensaje = "Forma de Pago no valida, no tiene una forma de pago SAT"
|
|
End Select
|
|
Return Mensaje
|
|
End Function
|
|
|
|
Protected Sub LnkCancelaFolioFiscal(sender As Object, e As EventArgs)
|
|
|
|
Dim Gvr As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
|
|
|
|
Can_FolioFiscalCancelar = Gvr.DataKey("FolioFiscalComplemento").ToString
|
|
Can_CveComplementoPagoCancelar = Gvr.DataKey("CveComplementoPago").ToEntero
|
|
Can_CvePACCancelacion = UsuarioActual.Empresa.CvePAC
|
|
Can_RFCReceptorCancelar = Gvr.DataKey("RFC").ToString
|
|
|
|
DdlMotivoCancelacion.SelectedValueExist(-1)
|
|
|
|
RegistraScript("$('#ModalCancelacion').modal('show');")
|
|
|
|
UpModalCancelacion.Update()
|
|
|
|
End Sub
|
|
|
|
Function EstatusSATCancelado(FolioFiscal As String, RFCDe As String, RFCReceptor As String) As Boolean
|
|
|
|
Dim respuesta As Boolean = False
|
|
|
|
Dim Vigencia = Timbrado.VerificarVigenciaSAT(FolioFiscal, RFCDe, RFCReceptor, "0", True)
|
|
|
|
If Vigencia IsNot Nothing Then
|
|
If Vigencia.Estado.ToUpper = "CANCELADO" Then
|
|
respuesta = True
|
|
Else
|
|
respuesta = False
|
|
End If
|
|
Else
|
|
respuesta = False
|
|
End If
|
|
|
|
Return respuesta
|
|
End Function
|
|
|
|
|
|
Protected Sub LnkSendMail_Click(sender As Object, e As EventArgs)
|
|
Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow)
|
|
HdnSerieFolioPago.Value = gvRow.DataKey("SerieFolioPago").ToString
|
|
TxtParaMail.Text = gvRow.DataKey("CobranzaCorreo").ToString
|
|
UpSendMail.Update()
|
|
RegistraScript("$('#ModalDivMail').modal('show');")
|
|
End Sub
|
|
|
|
Protected Sub LnkExcel_Click(sender As Object, e As EventArgs)
|
|
|
|
' GvD.ExportToExcelG("ReporteComplementos", "Reporte Complementos", UsuarioActual)
|
|
'GvD.ExportToExcelx("ReporteComplementos.xlsx")
|
|
' GvD.ExportToExcel("ReporteComplementos.xlsx")
|
|
|
|
|
|
Imprimir("Excel")
|
|
|
|
|
|
|
|
End Sub
|
|
|
|
Private Sub Imprimir(Optional reporte As String = "PDF")
|
|
If GvD.Rows.Count > 0 Then
|
|
Dim StrFiltro As New StringBuilder
|
|
'If DdlProveedor.SelectedValue.ToEntero > 0 Then StrFiltro.AppendFormat("Proveedor: {0},", DdlProveedor.SelectedText)
|
|
'If ddlProducto2.SelectedValue.ToEntero > 0 Then StrFiltro.AppendFormat(" Producto/Servicio: {0},", ddlProducto2.SelectedText)
|
|
If txtFechaI.Text <> "" Then StrFiltro.AppendFormat(" Fecha Inicio: {0} ", txtFechaI.Text)
|
|
If txtFechaF.Text <> "" Then StrFiltro.AppendFormat(" Fecha Fin: {0}", txtFechaF.Text)
|
|
ExportToExcelG(GvD, "ReporteComplementos.xlsx", "Reporte complementos de pago", UsuarioActual, StrFiltro.ToString, 100, 150)
|
|
Else
|
|
Alert("Debe consultar para generar un excel", TipoMensaje.MsgAdvertencia)
|
|
End If
|
|
End Sub
|
|
|
|
Public Sub ExportToExcelG(Gv As GridView, NombreArchivoXLSx As String, Optional Titulo As String = "Reporte", Optional Usuario As Usuario = Nothing, Optional Filtros As String = "", Optional AlturaImagen As Double = 100, Optional AnchoImagen As Double = 100)
|
|
Dim sw As New StringWriter()
|
|
Dim htw As New HtmlTextWriter(sw)
|
|
Gv.RenderControl(htw)
|
|
GemBox.Spreadsheet.SpreadsheetInfo.SetLicense("ESWN-4QFD-26JF-1SZ8")
|
|
|
|
Dim excel As GemBox.Spreadsheet.ExcelFile
|
|
Dim options = GemBox.Spreadsheet.LoadOptions.HtmlDefault
|
|
Using htmlStream = New MemoryStream(options.Encoding.GetBytes(sw.ToString()))
|
|
excel = GemBox.Spreadsheet.ExcelFile.Load(htmlStream, options)
|
|
If Usuario IsNot Nothing Then
|
|
Dim TotalRowHeader As Integer = 8
|
|
Dim TotalRowFooter As Integer = 2
|
|
|
|
Dim worksheet = excel.Worksheets(0)
|
|
worksheet.Rows.InsertEmpty(0, TotalRowHeader)
|
|
Dim celdasConTexto = worksheet.GetUsedCellRange(True)
|
|
celdasConTexto.Style.Font.Name = "Calibri Light"
|
|
|
|
Dim RangoNombreEmpresa = worksheet.Cells.GetSubrangeAbsolute(1, celdasConTexto.FirstColumnIndex, 1, celdasConTexto.LastColumnIndex)
|
|
RangoNombreEmpresa.Merged = True
|
|
RangoNombreEmpresa.Value = Usuario.Empresa.Empresa
|
|
RangoNombreEmpresa.Style.Font.Size = 18 * 20
|
|
RangoNombreEmpresa.Style.Font.Name = "Calibri Light"
|
|
RangoNombreEmpresa.Style.HorizontalAlignment = GemBox.Spreadsheet.HorizontalAlignmentStyle.Center
|
|
RangoNombreEmpresa.Style.VerticalAlignment = GemBox.Spreadsheet.VerticalAlignmentStyle.Center
|
|
|
|
|
|
Dim RangoFiltros = worksheet.Cells.GetSubrangeAbsolute(6, celdasConTexto.FirstColumnIndex, 6, celdasConTexto.LastColumnIndex)
|
|
RangoFiltros.Merged = True
|
|
RangoFiltros.Value = Filtros
|
|
RangoFiltros.Style.Font.Size = 15 * 20
|
|
RangoFiltros.Style.Font.Name = "Calibri Light"
|
|
RangoFiltros.Style.HorizontalAlignment = GemBox.Spreadsheet.HorizontalAlignmentStyle.Left
|
|
RangoFiltros.Style.VerticalAlignment = GemBox.Spreadsheet.VerticalAlignmentStyle.Center
|
|
|
|
|
|
Dim RangoTitulo = worksheet.Cells.GetSubrangeAbsolute(3, celdasConTexto.FirstColumnIndex, 3, celdasConTexto.LastColumnIndex)
|
|
RangoTitulo.Merged = True
|
|
RangoTitulo.Value = Titulo
|
|
RangoTitulo.Style.Font.Size = 20 * 20
|
|
RangoTitulo.Style.Font.Name = "Calibri Light"
|
|
RangoTitulo.Style.HorizontalAlignment = GemBox.Spreadsheet.HorizontalAlignmentStyle.Center
|
|
RangoTitulo.Style.VerticalAlignment = GemBox.Spreadsheet.VerticalAlignmentStyle.Center
|
|
|
|
worksheet.Columns("C").Width = 20000
|
|
worksheet.Columns("D").Width = 4000
|
|
worksheet.Columns("E").Width = 6000
|
|
worksheet.Columns("F").Width = 6000
|
|
worksheet.Columns("G").Width = 4000
|
|
|
|
For i = celdasConTexto.FirstColumnIndex To celdasConTexto.LastColumnIndex
|
|
|
|
worksheet.Rows(8).Cells(i).Style.Font.Size = 12 * 20
|
|
worksheet.Rows(8).Cells(i).Style.HorizontalAlignment = GemBox.Spreadsheet.HorizontalAlignmentStyle.Center
|
|
worksheet.Rows(8).Cells(i).Style.VerticalAlignment = GemBox.Spreadsheet.VerticalAlignmentStyle.Center
|
|
worksheet.Rows(8).Cells(i).Style.FillPattern.SetPattern(GemBox.Spreadsheet.FillPatternStyle.Solid, GemBox.Spreadsheet.SpreadsheetColor.FromArgb(75, 119, 190), GemBox.Spreadsheet.SpreadsheetColor.FromArgb(255, 255, 255))
|
|
worksheet.Rows(8).Cells(i).Style.Font.Color = GemBox.Spreadsheet.SpreadsheetColor.FromArgb(255, 255, 255)
|
|
|
|
If i > 0 Then
|
|
Try
|
|
worksheet.Columns(i).AutoFit(1)
|
|
Catch ex As Exception
|
|
End Try
|
|
End If
|
|
Next
|
|
|
|
Dim IndexEndTable As Integer = Gv.Rows.Count + TotalRowHeader + TotalRowFooter
|
|
|
|
worksheet.Rows(IndexEndTable).Cells(2).Value = "Usuario Imprimió"
|
|
worksheet.Rows(IndexEndTable + 1).Cells(2).Value = Usuario.Nombre
|
|
|
|
worksheet.Rows(IndexEndTable).Cells(6).Value = "Fecha Impresión"
|
|
worksheet.Rows(IndexEndTable + 1).Cells(6).Value = DateTime.Now.ToString("dd/MM/yyyy")
|
|
|
|
Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", Usuario.Empresa.Ruta))
|
|
|
|
If Imagen.Exists Then
|
|
Dim Ruta As String = String.Format("{0}/Logo.png", Usuario.Empresa.Ruta)
|
|
Using sr As New StreamReader(Ruta)
|
|
Dim ms As New MemoryStream()
|
|
sr.BaseStream.CopyTo(ms)
|
|
worksheet.Pictures.Add(ms, ExcelPictureFormat.Png, "A1", AnchoImagen, AlturaImagen, LengthUnit.Pixel)
|
|
End Using
|
|
End If
|
|
End If
|
|
|
|
End Using
|
|
htw.Dispose()
|
|
|
|
excel.Save(HttpContext.Current.Response, $"{NombreArchivoXLSx}.xlsx")
|
|
|
|
End Sub
|
|
|
|
|
|
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
|
|
End Sub
|
|
|
|
|
|
Protected Sub BtnCancelarComplemento_Click(sender As Object, e As EventArgs)
|
|
|
|
|
|
Dim CveMotivoCancelacion As Integer = DdlMotivoCancelacion.SelectedValue.ToEntero
|
|
Dim CveSATMotivoCancelacion As Integer = GlobalDTMotivosCancelacionEmpresa(UsuarioActual.CveEmpresa, CveMotivoCancelacion:=CveMotivoCancelacion).FiltroPrimeroValor("CveSATMotivoCancelacion").ToEntero()
|
|
|
|
If CveMotivoCancelacion <= 0 Or CveSATMotivoCancelacion <= 0 Then
|
|
Alert("Debe de elegir un motivo de cancelación.", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
|
|
|
|
|
|
Dim ErrorProceso As Boolean = True
|
|
|
|
If Can_FolioFiscalCancelar <> "" Then
|
|
Dim ObjCancelacion As New Timbrado
|
|
Dim ObjBanco As New ClsBancos
|
|
|
|
If EstatusSATCancelado(Can_FolioFiscalCancelar, UsuarioActual.Empresa.RFC, Can_RFCReceptorCancelar) Then
|
|
|
|
If ObjBanco.UpdateComplementoPagoCancelado(Can_CveComplementoPagoCancelar, 2, UsuarioActual.CveEmpresa, Can_CvePACCancelacion, Date.Now, "", CveSATMotivoCancelacion) Then
|
|
Alert("El complemento se cancelo correctamente.")
|
|
ErrorProceso = False
|
|
End If
|
|
|
|
Else
|
|
Dim resp = ObjCancelacion.CFDICancelar(UsuarioActual.Empresa, Can_FolioFiscalCancelar, 0, Can_RFCReceptorCancelar, UsuarioActual.Empresa.RFC, Can_CvePACCancelacion, CveSATMotivoCancelacion:=CveSATMotivoCancelacion)
|
|
If resp.Verificado Then
|
|
|
|
If ObjBanco.UpdateComplementoPagoCancelado(Can_CveComplementoPagoCancelar, 2, UsuarioActual.CveEmpresa, Can_CvePACCancelacion, ObjCancelacion.CancelacionFecha, ObjCancelacion.CancelacionAcuse, CveSATMotivoCancelacion) Then
|
|
Alert("El complemento se cancelo correctamente.")
|
|
ErrorProceso = False
|
|
End If
|
|
|
|
Else
|
|
Alert("Se presento un error al cancelar el complemento.", TipoMensaje.MsgError)
|
|
ErrorProceso = True
|
|
End If
|
|
|
|
End If
|
|
|
|
ObjBanco.Dispose()
|
|
Else
|
|
ErrorProceso = False
|
|
End If
|
|
|
|
If Not ErrorProceso Then
|
|
RegistraScript("$('#ModalCancelacion').modal('hide');")
|
|
End If
|
|
|
|
|
|
End Sub
|
|
End Class
|