888 lines
44 KiB
VB.net
888 lines
44 KiB
VB.net
Option Strict On
|
|
Imports Extensiones
|
|
Imports System.Data
|
|
Imports System.IO
|
|
Partial Class Contratos_FacturacionMasiva
|
|
Inherits ClsPaginas
|
|
|
|
#Region "Propiedades"
|
|
Private ReadOnly Property SeGuardoPrePoliza As Boolean
|
|
Get
|
|
Return CBool(ViewState("SeGuardoPrePoliza"))
|
|
End Get
|
|
End Property
|
|
Private Property DTCicloComercial As DataTable
|
|
Get
|
|
Return CType(ViewState("DTCicloComercial"), DataTable)
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("DTCicloComercial") = value
|
|
End Set
|
|
End Property
|
|
Private Property Mensaje As String
|
|
Get
|
|
Return CType(ViewState("Mensaje"), String)
|
|
End Get
|
|
Set(value As String)
|
|
ViewState("Mensaje") = value
|
|
End Set
|
|
End Property
|
|
Private Property FolioVigentes As Boolean
|
|
Get
|
|
Return CType(ViewState("FolioVigentes"), Boolean)
|
|
End Get
|
|
Set(value As Boolean)
|
|
ViewState("FolioVigentes") = value
|
|
End Set
|
|
End Property
|
|
Private Property ErrorList As List(Of String)
|
|
Get
|
|
Return CType(ViewState("ErrorList"), List(Of String))
|
|
End Get
|
|
Set(value As List(Of String))
|
|
ViewState("ErrorList") = value
|
|
End Set
|
|
End Property
|
|
Private Property DTDetalle As DataTable
|
|
Get
|
|
Return CType(ViewState("DTDetalle"), DataTable)
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("DTDetalle") = value
|
|
End Set
|
|
End Property
|
|
Private Property TmpDT As DataTable
|
|
Get
|
|
Return CType(ViewState("TmpDT"), DataTable)
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("TmpDT") = value
|
|
End Set
|
|
End Property
|
|
Private Property MensajeAlert As StringBuilder
|
|
Get
|
|
Return CType(ViewState("MensajeAlert"), StringBuilder)
|
|
End Get
|
|
Set(value As StringBuilder)
|
|
ViewState("MensajeAlert") = value
|
|
End Set
|
|
End Property
|
|
Private Property ObjFactura As Modelos.Factura
|
|
Get
|
|
Return CType(ViewState("ObjFactura"), Modelos.Factura)
|
|
End Get
|
|
Set(value As Modelos.Factura)
|
|
ViewState("ObjFactura") = value
|
|
End Set
|
|
End Property
|
|
Private Property CveCicloComercial As Integer
|
|
Get
|
|
Return ViewState("CveCicloComercial").ToString.ToEntero
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("CveCicloComercial") = value
|
|
End Set
|
|
End Property
|
|
#End Region
|
|
|
|
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
|
|
If Not IsPostBack Then
|
|
FolioVigentes = False
|
|
CargaCombos()
|
|
txtFechaI.Text = DateTime.Today.ToString("d")
|
|
txtFechaF.Text = DateTime.Today.ToString("d")
|
|
CargaDatos(-1, -1)
|
|
CreaDTVentas()
|
|
Mensaje = ""
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub CargaCombos()
|
|
DdlCliente.DataSource = GlobalDTCliente(UsuarioActual.CveEmpresa)
|
|
DdlCliente.DataBind()
|
|
DdlContrato.DataSource = GlobalDTContratos().FiltraParametros($"CveEmpresa = {UsuarioActual.CveEmpresa}")
|
|
DdlContrato.DataBind()
|
|
DdlSucursal.DataSource = GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa, 1)
|
|
DdlSucursal.DataBind()
|
|
End Sub
|
|
Private Sub CargaDatos(CveContrato As Integer, CveCliente As Integer)
|
|
ValidaFolio()
|
|
Dim ObjContratos As New ClsContratos
|
|
If ObjContratos.CicloComercialGet(CveContrato, CveCliente, -1, UsuarioActual.CveEmpresa, txtFechaI.Text.ToDateTime, txtFechaF.Text.ToDateTime, DdlSucursal.SelectedValue.ToEntero) Then
|
|
DTCicloComercial = ObjContratos.DtResultados().FiltraParametros($"FueFacturado = 0")
|
|
GvCiclosComerciales.DataSource = DTCicloComercial
|
|
End If
|
|
ObjContratos.Dispose()
|
|
GvCiclosComerciales.DataBind()
|
|
UpGv.Update()
|
|
End Sub
|
|
|
|
Private Sub ValidaFolio()
|
|
Dim ObjFolios As New ClsGralFolios
|
|
If ObjFolios.GetFolios("Ing", UsuarioActual.CveEmpresa) Then
|
|
If ObjFolios.DtResultados.Rows.Count > 0 Then
|
|
FolioVigentes = True
|
|
End If
|
|
End If
|
|
|
|
ObjFolios.Dispose()
|
|
End Sub
|
|
Protected Sub GvCiclosComerciales_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvCiclosComerciales.RowDataBound
|
|
If e.Row.RowType = DataControlRowType.DataRow Then
|
|
If Not FolioVigentes Then
|
|
e.Row.FCCheckBox("chkDis").Enabled = False
|
|
e.Row.FCCheckBox("chkDis").ToolTip = "La sucursal vinculada con este contrato no tiene folios"
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
Protected Sub btnConsultar_Click(sender As Object, e As EventArgs) Handles BtnCargaAsignados.Click
|
|
CargaDatos(DdlContrato.SelectedValue.ToEntero, DdlCliente.SelectedValue.ToEntero)
|
|
RegistraScript("$('#ex').removeClass('expand');$('#ex').addClass('collapse');$('.portlet-body').css('display', '');")
|
|
End Sub
|
|
|
|
Protected Sub ImgFacturarTodos_Click(sender As Object, e As EventArgs) Handles BtnFacturar.Click
|
|
Dim FacturadoCorrecto = True
|
|
For Each row As GridViewRow In GvCiclosComerciales.Rows
|
|
If row.FCCheckBox("chkDis").Checked Then
|
|
FacturadoCorrecto = EmitirImprimir(row.DataKey("CveCicloComercial").ToString.ToEntero)
|
|
If Not FacturadoCorrecto Then
|
|
If Mensaje = "" Then
|
|
Alert("Ocurrió un error al facturar masivamente, por favor contacte a soporte técnico", TipoMensaje.MsgAdvertencia)
|
|
Else
|
|
Alert($"{Mensaje} en el contrato {row.DataKey("NumeroContrato").ToString}", TipoMensaje.MsgAdvertencia)
|
|
End If
|
|
Exit For
|
|
End If
|
|
End If
|
|
Next
|
|
If FacturadoCorrecto Then
|
|
Alert("Los periodos se facturaron correctamente")
|
|
TxtObservaciones.Text = ""
|
|
End If
|
|
CargaDatos(DdlContrato.SelectedValue.ToEntero, DdlCliente.SelectedValue.ToEntero)
|
|
RegistraScript("$('#divAgregar').modal('hide')")
|
|
UpBodyEstatus.Update()
|
|
End Sub
|
|
|
|
Protected Sub btnFacturarAqui_Click(sender As Object, e As EventArgs)
|
|
CveCicloComercial = CType(sender, LinkButton).CommandArgument.ToEntero
|
|
CreaObjetosVenta()
|
|
|
|
If ObjFactura Is Nothing Or ObjFactura.Cliente Is Nothing Then
|
|
Alert("Ocurrió un error al procesar los datos de la Venta.", TipoMensaje.MsgError)
|
|
ObjFactura = Nothing
|
|
Exit Sub
|
|
End If
|
|
|
|
|
|
If ObjFactura.CveCliente > 0 Then
|
|
If DTDetalle.Rows.Count > 0 Then
|
|
|
|
Dim ObjVentas As New ClsVentas()
|
|
Dim ObjConta As New ClsContabilidad(ObjVentas.IniciaTransacSQL())
|
|
Dim ObjInventario As New ClsInventarios(ObjVentas.IniciaTransacSQL())
|
|
Dim ObjContr As New ClsContratos(ObjVentas.IniciaTransacSQL())
|
|
Dim ObjOS As New ClsOS(ObjVentas.IniciaTransacSQL())
|
|
Dim ObjBancos As New ClsBancos(ObjVentas.IniciaTransacSQL())
|
|
Dim ObjClientes As New ClsClientes(ObjVentas.IniciaTransacSQL())
|
|
Dim ObjContPaq As ClsContPAQi = Nothing
|
|
'Dim ObjFolios As New ClsGralFolios(ObjVentas.IniciaTransacSQL())
|
|
ErrorList = New List(Of String)
|
|
MensajeAlert = New StringBuilder
|
|
|
|
|
|
'CONTABILIDAD AUTOMATICA Y AC
|
|
If UsuarioActual.Empresa.UsaAC OrElse UsuarioActual.Empresa.Funcionalidad(200) = "1" Then
|
|
ObjContPaq = New ClsContPAQi(UsuarioActual.Empresa)
|
|
End If
|
|
|
|
|
|
'GUARDA VENTA
|
|
GuardarVenta(ObjVentas, ObjConta, ObjInventario, ObjContr, ObjFactura, TmpDT, ObjFactura.CveNCaVincular, ObjContPaq, ObjBancos, ObjOS)
|
|
|
|
If CveCicloComercial > 0 AndAlso ErrorList.Count = 0 Then
|
|
If Not ObjContr.CicloComercialUpdate(CveCicloComercial, True, UsuarioActual.CveEmpresa) Then
|
|
ErrorList.Add("No se pudo actualizar ")
|
|
End If
|
|
End If
|
|
|
|
If ObjFactura.CveVenta > 0 AndAlso ErrorList.Count = 0 AndAlso (SeGuardoPrePoliza Or ObjFactura.TipoDocto.Contiene("Ped", "Cot")) Then
|
|
ObjVentas.Commit()
|
|
If ObjContPaq IsNot Nothing Then ObjContPaq.Commit()
|
|
ViewState("CveVenta") = ObjFactura.CveVenta
|
|
|
|
|
|
Dim SeTimbro As Boolean = False
|
|
'TIMBRADO Y CASO ESPECIAL NOTA DE CREDITO
|
|
|
|
If ObjFactura.TipoDocto.Contiene("Ing", "Egs", "Ant") Then
|
|
If UsuarioActual.Empresa.TipoFacturacion = "CFDi" AndAlso UsuarioActual.Empresa.FacturaProduccion Then
|
|
|
|
Dim sw As New Diagnostics.Stopwatch
|
|
sw.Start()
|
|
|
|
'FACTURA INGRESO/EGRESO
|
|
Dim ObjTimbrado As New Timbrado
|
|
|
|
|
|
SeTimbro = ObjTimbrado.TimbrarFactura(UsuarioActual, ObjFactura)
|
|
|
|
sw.Stop()
|
|
GuardaLogTimbrado(sw.ElapsedMilliseconds.ToString, UsuarioActual.Empresa.CvePAC)
|
|
End If
|
|
|
|
|
|
'MENSAJE PRINCIPAL
|
|
MensajeAlert.AppendFormat(String.Format("<br/>La {0}: <b>{1}</b> se generó correctamente.<br/><br/>", ObjFactura.TipoDocumento, ObjFactura.SerieFolio))
|
|
|
|
|
|
If SeTimbro Then
|
|
'XML
|
|
Dim ArchivoXML = String.Format("{0}/XML/{1}/{2}.xml", UsuarioActual.Empresa.Ruta, ObjFactura.TipoDocto, ObjFactura.SerieFolio)
|
|
If File.Exists(ArchivoXML) Then
|
|
MensajeAlert.AppendFormat("<ul><li><a class=""Texto"" href=""/Compras/PopUpVerFactura.aspx?P={0}"">Descargar XML</a></li></ul>", Encripta(String.Format("OP=FactVta&CVEVENTA={0}&EXT={1}&SERIEFOLIO={2}&TIPODOCTO={3}", ObjFactura.CveVenta, "XML", ObjFactura.SerieFolio, ObjFactura.TipoDocto)))
|
|
End If
|
|
|
|
'IMPRESION
|
|
GeneraPDFFactura(False)
|
|
Else
|
|
MensajeAlert.AppendFormat("La factura no se pudo timbrar.</b> Por favor intentelo de nuevo a traves del boton Emitir o póngase en contacto con soporte técnico.")
|
|
End If
|
|
|
|
'MUESTA ALERT OK
|
|
Dim Liga = If(UsuarioActual.CveRol = 1165, "document.location.href=""/Ventas/Ventas.aspx?CveVenta=-1"";", $"document.location.href=""/Ventas/Clientes.aspx?CveCliente={ObjFactura.CveCliente}&Opt=3"";")
|
|
Alert(MensajeAlert.ToString, TipoMensaje.MsgInformacion)
|
|
|
|
ObjFactura = Nothing
|
|
Else
|
|
ObjVentas.RollBack()
|
|
If ObjContPaq IsNot Nothing Then ObjContPaq.RollBack()
|
|
|
|
For Each ErrorItem In ErrorList
|
|
Alert(ErrorItem, TipoMensaje.MsgAdvertencia)
|
|
Next
|
|
|
|
'MUESTA ALERT ERROR
|
|
Alert("Ocurrió un error al procesar los datos. Por favor rectifique y vuelta a intentar.", TipoMensaje.MsgError)
|
|
End If
|
|
|
|
ObjVentas.Dispose()
|
|
ObjConta.Dispose()
|
|
ObjInventario.Dispose()
|
|
ObjContr.Dispose()
|
|
ErrorList = Nothing
|
|
MensajeAlert = Nothing
|
|
If ObjContPaq IsNot Nothing Then ObjContPaq.Dispose()
|
|
CargaDatos(DdlContrato.SelectedValue.ToEntero, DdlCliente.SelectedValue.ToEntero)
|
|
Else
|
|
ObjVentas.RollBack()
|
|
If ObjContPaq IsNot Nothing Then ObjContPaq.RollBack()
|
|
|
|
For Each ErrorItem In ErrorList
|
|
Alert(ErrorItem, TipoMensaje.MsgAdvertencia)
|
|
Next
|
|
|
|
'MUESTA ALERT ERROR
|
|
Alert("Ocurrió un error al procesar los datos. Por favor rectifique y vuelta a intentar.", TipoMensaje.MsgError)
|
|
ObjVentas.Dispose()
|
|
ObjConta.Dispose()
|
|
ObjInventario.Dispose()
|
|
ObjContr.Dispose()
|
|
'ObjFolios.Dispose()
|
|
ErrorList = Nothing
|
|
MensajeAlert = Nothing
|
|
If ObjContPaq IsNot Nothing Then ObjContPaq.Dispose()
|
|
|
|
End If
|
|
Else
|
|
Mensaje = "Las facturas del contrato"
|
|
End If
|
|
End If
|
|
|
|
|
|
End Sub
|
|
|
|
Private Function EmitirImprimir(pCveCicloComercial As Integer) As Boolean
|
|
Dim retorno As Boolean = False
|
|
ViewState("CveCicloComercial") = pCveCicloComercial
|
|
CreaObjetosVenta()
|
|
If ObjFactura Is Nothing Or ObjFactura.Cliente Is Nothing Then
|
|
Alert("Ocurrió un error al procesar los datos de la Venta.", TipoMensaje.MsgError)
|
|
ObjFactura = Nothing
|
|
Return False
|
|
End If
|
|
|
|
|
|
If ObjFactura.CveCliente > 0 Then
|
|
If DTDetalle.Rows.Count > 0 Then
|
|
|
|
Dim ObjVentas As New ClsVentas()
|
|
Dim ObjConta As New ClsContabilidad(ObjVentas.IniciaTransacSQL())
|
|
Dim ObjInventario As New ClsInventarios(ObjVentas.IniciaTransacSQL())
|
|
Dim ObjContr As New ClsContratos(ObjVentas.IniciaTransacSQL())
|
|
Dim ObjOS As New ClsOS(ObjVentas.IniciaTransacSQL())
|
|
Dim ObjBancos As New ClsBancos(ObjVentas.IniciaTransacSQL())
|
|
Dim ObjClientes As New ClsClientes(ObjVentas.IniciaTransacSQL())
|
|
Dim ObjContPaq As ClsContPAQi = Nothing
|
|
'Dim ObjFolios As New ClsGralFolios(ObjVentas.IniciaTransacSQL())
|
|
ErrorList = New List(Of String)
|
|
MensajeAlert = New StringBuilder
|
|
|
|
|
|
'CONTABILIDAD AUTOMATICA Y AC
|
|
If UsuarioActual.Empresa.UsaAC OrElse UsuarioActual.Empresa.Funcionalidad(200) = "1" Then
|
|
ObjContPaq = New ClsContPAQi(UsuarioActual.Empresa)
|
|
End If
|
|
|
|
|
|
'GUARDA VENTA
|
|
GuardarVenta(ObjVentas, ObjConta, ObjInventario, ObjContr, ObjFactura, TmpDT, ObjFactura.CveNCaVincular, ObjContPaq, ObjBancos, ObjOS)
|
|
|
|
If pCveCicloComercial > 0 AndAlso ErrorList.Count = 0 Then
|
|
If Not ObjContr.CicloComercialUpdate(pCveCicloComercial, True, UsuarioActual.CveEmpresa) Then
|
|
ErrorList.Add("No se pudo actualizar ")
|
|
End If
|
|
End If
|
|
|
|
If ObjFactura.CveVenta > 0 AndAlso ErrorList.Count = 0 AndAlso (SeGuardoPrePoliza Or ObjFactura.TipoDocto.Contiene("Ped", "Cot")) Then
|
|
ObjVentas.Commit()
|
|
If ObjContPaq IsNot Nothing Then ObjContPaq.Commit()
|
|
ViewState("CveVenta") = ObjFactura.CveVenta
|
|
|
|
|
|
Dim SeTimbro As Boolean = False
|
|
'TIMBRADO Y CASO ESPECIAL NOTA DE CREDITO
|
|
|
|
If ObjFactura.TipoDocto.Contiene("Ing", "Egs", "Ant") Then
|
|
If UsuarioActual.Empresa.TipoFacturacion = "CFDi" AndAlso UsuarioActual.Empresa.FacturaProduccion Then
|
|
|
|
Dim sw As New Diagnostics.Stopwatch
|
|
sw.Start()
|
|
|
|
'FACTURA INGRESO/EGRESO
|
|
Dim ObjTimbrado As New Timbrado
|
|
|
|
|
|
SeTimbro = ObjTimbrado.TimbrarFactura(UsuarioActual, ObjFactura)
|
|
|
|
sw.Stop()
|
|
GuardaLogTimbrado(sw.ElapsedMilliseconds.ToString, UsuarioActual.Empresa.CvePAC)
|
|
End If
|
|
|
|
|
|
'MENSAJE PRINCIPAL
|
|
MensajeAlert.AppendFormat(String.Format("<br/>La {0}: <b>{1}</b> se generó correctamente.<br/><br/>", ObjFactura.TipoDocumento, ObjFactura.SerieFolio))
|
|
|
|
|
|
If SeTimbro Then
|
|
'XML
|
|
Dim ArchivoXML = String.Format("{0}/XML/{1}/{2}.xml", UsuarioActual.Empresa.Ruta, ObjFactura.TipoDocto, ObjFactura.SerieFolio)
|
|
If File.Exists(ArchivoXML) Then
|
|
MensajeAlert.AppendFormat("<ul><li><a class=""Texto"" href=""/Compras/PopUpVerFactura.aspx?P={0}"">Descargar XML</a></li></ul>", Encripta(String.Format("OP=FactVta&CVEVENTA={0}&EXT={1}&SERIEFOLIO={2}&TIPODOCTO={3}", ObjFactura.CveVenta, "XML", ObjFactura.SerieFolio, ObjFactura.TipoDocto)))
|
|
End If
|
|
|
|
'IMPRESION
|
|
GeneraPDFFactura(False)
|
|
Else
|
|
MensajeAlert.AppendFormat("La factura no se pudo timbrar.</b> Por favor intentelo de nuevo a traves del boton Emitir o póngase en contacto con soporte técnico.")
|
|
End If
|
|
|
|
'MUESTA ALERT OK
|
|
Dim Liga = If(UsuarioActual.CveRol = 1165, "document.location.href=""/Ventas/Ventas.aspx?CveVenta=-1"";", $"document.location.href=""/Ventas/Clientes.aspx?CveCliente={ObjFactura.CveCliente}&Opt=3"";")
|
|
retorno = True
|
|
ObjFactura = Nothing
|
|
Else
|
|
ObjVentas.RollBack()
|
|
If ObjContPaq IsNot Nothing Then ObjContPaq.RollBack()
|
|
|
|
For Each ErrorItem In ErrorList
|
|
Alert(ErrorItem, TipoMensaje.MsgAdvertencia)
|
|
Next
|
|
|
|
'MUESTA ALERT ERROR
|
|
Alert("Ocurrió un error al procesar los datos. Por favor rectifique y vuelta a intentar.", TipoMensaje.MsgError)
|
|
End If
|
|
|
|
ObjVentas.Dispose()
|
|
ObjConta.Dispose()
|
|
ObjInventario.Dispose()
|
|
ObjContr.Dispose()
|
|
ErrorList = Nothing
|
|
MensajeAlert = Nothing
|
|
If ObjContPaq IsNot Nothing Then ObjContPaq.Dispose()
|
|
Else
|
|
ObjVentas.RollBack()
|
|
If ObjContPaq IsNot Nothing Then ObjContPaq.RollBack()
|
|
|
|
For Each ErrorItem In ErrorList
|
|
Alert(ErrorItem, TipoMensaje.MsgAdvertencia)
|
|
Next
|
|
|
|
'MUESTA ALERT ERROR
|
|
Alert("Ocurrió un error al procesar los datos. Por favor rectifique y vuelta a intentar.", TipoMensaje.MsgError)
|
|
ObjVentas.Dispose()
|
|
ObjConta.Dispose()
|
|
ObjInventario.Dispose()
|
|
ObjContr.Dispose()
|
|
'ObjFolios.Dispose()
|
|
ErrorList = Nothing
|
|
MensajeAlert = Nothing
|
|
If ObjContPaq IsNot Nothing Then ObjContPaq.Dispose()
|
|
End If
|
|
Else
|
|
Mensaje = "No se pudo completar facturación por que no se encontraron partidas "
|
|
End If
|
|
End If
|
|
TmpDT.Clear()
|
|
Return retorno
|
|
End Function
|
|
|
|
|
|
Private Sub CreaDTVentas()
|
|
TmpDT = New DataTable
|
|
TmpDT.Columns.Add("CveVenta", GetType(Integer))
|
|
TmpDT.Columns.Add("Consec", GetType(Integer))
|
|
TmpDT.Columns.Add("Cantidad", GetType(Double))
|
|
TmpDT.Columns.Add("Codigo", GetType(String))
|
|
TmpDT.Columns.Add("CveUM", GetType(Integer))
|
|
TmpDT.Columns.Add("UM", GetType(String))
|
|
TmpDT.Columns.Add("CveClasificacion", GetType(Integer))
|
|
TmpDT.Columns.Add("Clasificacion", GetType(String))
|
|
TmpDT.Columns.Add("CvePS", GetType(Integer))
|
|
TmpDT.Columns.Add("PS", GetType(String))
|
|
TmpDT.Columns.Add("CodigoPS", GetType(String))
|
|
TmpDT.Columns.Add("CveTipoInvPS", GetType(Integer))
|
|
TmpDT.Columns.Add("Serie", GetType(String))
|
|
TmpDT.Columns.Add("Obs", GetType(String))
|
|
TmpDT.Columns.Add("TiempoEntrega", GetType(String))
|
|
TmpDT.Columns.Add("PU", GetType(Double))
|
|
TmpDT.Columns.Add("IVA", GetType(Double))
|
|
TmpDT.Columns.Add("IEPS", GetType(Double))
|
|
TmpDT.Columns.Add("Descuento", GetType(Double))
|
|
TmpDT.Columns.Add("TipoDescuento", GetType(Integer))
|
|
TmpDT.Columns.Add("Total", GetType(Double))
|
|
TmpDT.Columns.Add("CveProyecto", GetType(Integer))
|
|
TmpDT.Columns.Add("Proyecto", GetType(String))
|
|
TmpDT.Columns.Add("CveSubProyecto", GetType(Integer))
|
|
TmpDT.Columns.Add("SubProyecto", GetType(String))
|
|
TmpDT.Columns.Add("CvePresupuestoIngreso", GetType(Integer))
|
|
TmpDT.Columns.Add("CveContratoDetalle", GetType(Integer))
|
|
TmpDT.Columns.Add("CveVentaDetalle", GetType(Integer))
|
|
End Sub
|
|
Private Sub CreaObjetosVenta(Optional VistaPrevia As Boolean = False)
|
|
Dim ObjFolios As New ClsGralFolios()
|
|
Dim Folio As String = ""
|
|
Dim Serie As String = ""
|
|
Dim CveProyecto As String = ""
|
|
Dim CveSubProyecto As String = ""
|
|
Dim Proyecto As String = ""
|
|
Dim SubProyecto As String = ""
|
|
|
|
|
|
|
|
ObjFactura = New Modelos.Factura
|
|
Dim objContratos As New ClsContratos
|
|
Dim DR As DataRow = DTCicloComercial.FiltroPrimero($"CveCicloComercial = {CveCicloComercial}")
|
|
|
|
ObjFactura.CveUsuario = UsuarioActual.CveUsuario
|
|
ObjFactura.CveEmpresa = UsuarioActual.CveEmpresa
|
|
ObjFactura.TipoCambio = 20
|
|
ObjFactura.ConvertirPesos = False
|
|
ObjFactura.CveMoneda = DR("CveMoneda").ToString.ToEntero
|
|
ObjFactura.Moneda = GlobalDTMonedas.FiltroPrimeroValor("Moneda", $"CveMoneda = {ObjFactura.CveMoneda} ")
|
|
ObjFactura.MonedaSAT = GlobalDTMonedas.FiltroPrimeroValor("AbreviaturaSAT", $"CveMoneda = {DR("CveMoneda").ToString.ToEntero}")
|
|
ObjFactura.TipoDocto = "Ing"
|
|
ObjFactura.RefDocto = ""
|
|
ObjFactura.Folio = Folio.ToEntero
|
|
'ObjFactura.Folio = If(ExFolioFactura, FolioXML.ToEntero, -1)
|
|
ObjFactura.Serie = Serie
|
|
ObjFactura.CveMesa = -1
|
|
ObjFactura.Fecha = DR("FechaVenc").ToString.ToDate
|
|
ObjFactura.CvePrePoliza = -1
|
|
ObjFactura.CveMetodoPago = 1
|
|
ObjFactura.MetodoPago = "Efectivo"
|
|
ObjFactura.FechaPago = DateTime.Today
|
|
ObjFactura.MotivoDescuento = ""
|
|
ObjFactura.Observaciones = ""
|
|
ObjFactura.FechaEjecucion = DateTime.Today
|
|
ObjFactura.ClaveMetodoPagoSAT = GlobalDTMetodosPago.FiltroPrimeroValor("ClaveSAT", $"CveMetodoPago = {1}")
|
|
ObjFactura.UsuarioCreo = UsuarioActual.Usuario
|
|
ObjFactura.CveCondicionEntrega = -1
|
|
ObjFactura.CondicionEntrega = ""
|
|
ObjFactura.NumeroCuenta = ""
|
|
'ObjFactura.CveSucursal = GlobalDTSubProyectos.FiltroPrimeroValor("CveSucursal", $"CveEmpresa = {UsuarioActual.CveEmpresa}").ToEntero
|
|
'ObjFactura.Cliente.NumCtaPago = TxtNumCtaPago.Text.Trim
|
|
ObjFactura.CondicionesPago = 0
|
|
ObjFactura.FormaPago = 0
|
|
'ObjFactura.SerieFolio = String.Format("{0}-{1}", LblSerie.Text, TxtFolio.Text)
|
|
ObjFactura.PedidoContrato = ""
|
|
ObjFactura.NumeroContrato = DR("NumeroContrato").ToString
|
|
ObjFactura.DescripcionContrato = DR("DescripcionContrato").ToString
|
|
ObjFactura.CveCorte = -1
|
|
ObjFactura.TipoDocumento = "Factura"
|
|
ObjFactura.Alfa1 = ""
|
|
ObjFactura.Alfa2 = ""
|
|
ObjFactura.Alfa3 = ""
|
|
'Totales, Y se llena TmpDTImpuestos
|
|
ObjFactura.Descuento = 0
|
|
ObjFactura.Amortizacion = 0
|
|
ObjFactura.CveContrato = DR("CveContrato").ToString.ToEntero
|
|
ObjFactura.RetIVA = 0
|
|
ObjFactura.RetISR = 0
|
|
ObjFactura.IEPS = 0
|
|
CveProyecto = DR("CveProyecto").ToString
|
|
Proyecto = DR("ProyectoContrato").ToString
|
|
CveSubProyecto = DR("CveSubProyecto").ToString
|
|
SubProyecto = DR("SubProyectoContrato").ToString
|
|
ObjFactura.IVA = GlobalDTSubProyectos(-1, CveSubProyecto.ToEntero, UsuarioActual.CveEmpresa, 1).FiltroPrimeroValor("IVA").ToDecimal
|
|
|
|
|
|
If ObjFolios.GetFolios("Ing", UsuarioActual.CveEmpresa) Then
|
|
Dim DT As DataTable = ObjFolios.DtResultados.FiltraParametros(String.Format($" Estado = 'Activo' AND CveSubProyecto = {CveSubProyecto} "))
|
|
If DT.Rows.Count > 0 Then
|
|
Serie = DT.Rows(0)("Serie").ToString
|
|
Folio = DT.Rows(0)("FActual").ToString
|
|
End If
|
|
DT.Dispose()
|
|
End If
|
|
ObjFolios.Dispose()
|
|
|
|
If objContratos.GetContratosDetalle(DR("CveContrato").ToString.ToEntero) Then
|
|
DTDetalle = objContratos.DtResultados
|
|
Else
|
|
DTDetalle = Nothing
|
|
End If
|
|
|
|
objContratos.Dispose()
|
|
Dim DtR As DataRow
|
|
ObjFactura.SubTotal = SUM(DTDetalle, "PU").ToDecimal
|
|
ObjFactura.IVA = ObjFactura.IVA * ObjFactura.SubTotal
|
|
ObjFactura.Total = ObjFactura.SubTotal + ObjFactura.IVA
|
|
ObjFactura.Serie = Serie
|
|
ObjFactura.Folio = Folio.ToEntero
|
|
|
|
For Each row As DataRow In DTDetalle.Rows
|
|
DtR = TmpDT.NewRow
|
|
DtR("CveVenta") = -1
|
|
DtR("Codigo") = row("Codigo")
|
|
DtR("Consec") = TmpDT.Rows.Count + 1
|
|
DtR("Cantidad") = row("CantidadContratada")
|
|
DtR("CveUM") = row("CveUM")
|
|
DtR("UM") = row("UM")
|
|
DtR("CveClasificacion") = row("CveClasificacion")
|
|
DtR("Clasificacion") = row("Clasificacion")
|
|
DtR("CvePS") = row("CvePS")
|
|
DtR("PS") = row("PS")
|
|
DtR("CodigoPS") = row("CodigoPS")
|
|
DtR("Obs") = ""
|
|
DtR("PU") = row("PU")
|
|
DtR("Descuento") = 0
|
|
DtR("TipoDescuento") = 0
|
|
DtR("Total") = row("Total")
|
|
DtR("CveProyecto") = CveProyecto
|
|
DtR("Proyecto") = Proyecto
|
|
DtR("CveSubProyecto") = CveSubProyecto
|
|
DtR("IVA") = If(row("IVA").ToString.ToDouble = -1, GlobalDTSubProyectos(-1, CveSubProyecto.ToEntero, UsuarioActual.CveEmpresa, 1).FiltroPrimeroValor("IVA").ToDouble, row("IVA").ToString.ToDouble)
|
|
DtR("SubProyecto") = SubProyecto
|
|
DtR("CveVentaDetalle") = 0
|
|
DtR("CveContratoDetalle") = row("CveContratoDetalle")
|
|
TmpDT.Rows.Add(DtR)
|
|
Next
|
|
|
|
|
|
'DETALLES
|
|
ObjFactura.DtDetalle = TmpDT
|
|
|
|
'CLIENTE
|
|
ObjFactura.CveCliente = DR("CveCliente").ToString.ToEntero
|
|
ObjFactura.SetCliente()
|
|
|
|
|
|
|
|
End Sub
|
|
|
|
Private Sub GuardarVenta(ObjVentas As ClsVentas, ObjConta As ClsContabilidad, ObjInventario As ClsInventarios, ObjContr As ClsContratos, factura As Modelos.Factura, TmpDTDetalle As DataTable, CveNCaVincular As Integer, objContPaqi As ClsContPAQi, Optional ObjBancos As ClsBancos = Nothing, Optional ObjOS As ClsOS = Nothing)
|
|
|
|
Dim Msgok As New StringBuilder
|
|
Dim CveAlmacenTraspasoOrigen As Integer = -1
|
|
Dim CveAlmacenTraspasoDestino As Integer = -1
|
|
Dim EsDevolucionVenta = -1
|
|
Dim CveSubProyecto = TmpDTDetalle.Rows(0)("CveSubProyecto").ToString.ToEntero
|
|
|
|
|
|
factura.CvePrePoliza = ObjConta.AddPrePolizas("Ventas/GuardarVenta", factura.CvePlantillaPoliza, factura.Total, factura.Total, factura.CveMoneda, factura.Fecha, factura.Cliente.Nombre, factura.CveUsuario, factura.CveEmpresa)
|
|
If Not ObjVentas.AddVenta(factura.TipoDocto, factura.Folio, factura.CveCliente, factura.CveClienteSucursal, factura.SubTotalTC, factura.DescuentoTC,
|
|
factura.AmortizacionTC, factura.IVATC, factura.RetIVATC, factura.RetISRTC,
|
|
factura.TotalTC, factura.CveMoneda, factura.TipoCambio, factura.CveMetodoPago, factura.CondicionesPago, factura.FormaPago, factura.FechaPago, factura.Fecha, factura.MotivoDescuento,
|
|
factura.Observaciones, factura.FechaEjecucion, factura.CveVendedor, factura.Alfa1, factura.Alfa2,
|
|
factura.Alfa3, factura.Num1, factura.Num2, factura.Num3,
|
|
factura.Fech1, factura.Fech2, factura.Fech3, factura.CveCorte, factura.CveMesa, factura.NumeroPersonas, factura.CvePrePoliza, factura.CveUsuario, factura.CveEmpresa,
|
|
AtencionA:=factura.AtencionA, TelefonoGenerico:="", CveContrato:=factura.CveContrato, CveVentaPadre:=factura.CveVentaPadre, Det_FechaOrdenCompra:=factura.Det_FechaOrdenCompra, Det_OrdenCompra:=factura.Det_OrdenCompra, otros:=factura.Otros,
|
|
Entrega:="", Vigencia:=MinFecha,
|
|
CveAlmacenTraspasoDestino:=CveAlmacenTraspasoDestino, CveAlmacenTraspasoOrigen:=CveAlmacenTraspasoOrigen, CveDireccionEnvio:=-1, CveOC:=-1, IEPS:=factura.IEPSTC, Serie:=factura.Serie, CveCondicionEntrega:=-1,
|
|
PedidoContrato:="", CveSubProyecto:=CveSubProyecto, CveSubProyectoCobranza:=CveSubProyecto, CveSubProyectoEjecucion:=CveSubProyecto) Then
|
|
ErrorList.Add("Ocurrió un error al Generar la Venta.<br />Revise su factura y cualquier detalle comuníquese a Soporte Técnico")
|
|
End If
|
|
|
|
|
|
If ErrorList.Count = 0 AndAlso ObjVentas.CveVenta > 0 Then
|
|
|
|
factura.CveVenta = ObjVentas.CveVenta
|
|
factura.Serie = ObjVentas.Serie
|
|
factura.Folio = ObjVentas.Folio
|
|
ViewState("VentaFolio") = ObjVentas.SerieFolio
|
|
|
|
'Se agregan los PS
|
|
For Each Row As DataRow In TmpDTDetalle.Rows
|
|
If Not ObjVentas.AddVentaDetalle(ObjVentas.CveVenta, Row("CvePS").ToString.ToEntero, Row("Cantidad").ToString.ToDouble, Row("CveUM").ToString.ToEntero,
|
|
Row("PU").ToString.ToDouble(If(ObjFactura.ConvertirPesos, factura.TipoCambio, 1)), Row("IVA").ToString.ToDouble(If(ObjFactura.ConvertirPesos, factura.TipoCambio, 1)), Math.Round((Row("PU").ToString.ToDouble(If(ObjFactura.ConvertirPesos, factura.TipoCambio, 1)) * (1 + Row("IVA").ToString.ToDouble(If(ObjFactura.ConvertirPesos, factura.TipoCambio, 1)))), 3),
|
|
TxtObservaciones.Text, 0, 0, Row("CveSubProyecto").ToString.ToEntero, -1,
|
|
TiempoEntrega:="", CveVentaDetallePadre:=-1, CveContratoDetalle:=Row("CveContratoDetalle").ToString.ToEntero, CvePromocionDetalle:=-1, IEPS:=0) Then
|
|
ErrorList.Add("Ocurrió un error al agregar un Producto o Servicio a la Factura.<br />Revise su factura y cualquier detalle comuníquese a Soporte Técnico")
|
|
Exit For
|
|
Else
|
|
Dim TmpDr As DataRow = TmpDT.Select($"Consec = {Row("Consec").ToString}")(0)
|
|
TmpDr("CveVentaDetalle") = ObjVentas.CveVentaDetalle
|
|
End If
|
|
Next
|
|
|
|
GuardarContratoAvanceEstimaciones(ObjVentas, factura, ErrorList, 1)
|
|
|
|
If ErrorList.Count = 0 Then
|
|
'prepoliza
|
|
GuardarVentaPrePolizas(ObjConta, factura, TmpDTDetalle, CveNCaVincular, objContPaqi, ObjBancos, ObjVentas)
|
|
End If
|
|
|
|
End If
|
|
End Sub
|
|
Private Sub GuardarVentaPrePolizas(ObjConta As ClsContabilidad, factura As Modelos.Factura, TmpDTDetalleMovimientos As DataTable, CveNCaVincular As Integer, objContPaqi As ClsContPAQi, Optional ObjBancos As ClsBancos = Nothing, ByRef Optional ObjVentas As ClsVentas = Nothing)
|
|
|
|
Dim CveIE As Integer = -1
|
|
Dim DT As DataTable = Nothing
|
|
|
|
|
|
Dim CveConceptoAfectacion As Integer = 1 'Cliente
|
|
Dim CveConceptoAntCli As Integer = 3 'Anticipo Cliente
|
|
Dim CveConceptoVenta As Integer = 4 'Venta
|
|
Dim CveConceptoCanAnt As Integer = 11 'Cancelacion Anticipos
|
|
Dim CveConceptoDSV As Integer = 12 ' DSV
|
|
Dim CveConceptoIVA As Integer = 13 'IVA Trasladado
|
|
Dim CveConceptoRetIVA As Integer = 8 'Ret IVA
|
|
Dim CveConceptoRetISR As Integer = 9 'Ret ISR
|
|
'P R E P O L I Z A S
|
|
If factura.CvePrePoliza > 0 Then
|
|
|
|
If ProcesoPrepolizas(ObjConta, factura, CveIE, TmpDTDetalleMovimientos, objContPaqi, 1, ObjBancos, ObjVentas) Then
|
|
ErrorList.Add("Ocurrió un error al agregar los Movimientos de la prepoliza.<br />Revise su factura y cualquier detalle comuníquese a Soporte Técnico")
|
|
End If
|
|
|
|
Else
|
|
ErrorList.Add("Ocurrió un error al agregar los Movimientos de la prepoliza.<br />Revise su factura y cualquier detalle comuníquese a Soporte Técnico")
|
|
End If
|
|
End Sub
|
|
|
|
Private Function ProcesoPrepolizas(ObjConta As ClsContabilidad, ObjFactura As Modelos.Factura, CveIE As Integer, TmpDTDetalle As DataTable, objContPaqi As ClsContPAQi, Optional ValorMultiplicador As Integer = 1, ByRef Optional ObjBancos As ClsBancos = Nothing, ByRef Optional ObjVentas As ClsVentas = Nothing) As Boolean
|
|
|
|
Dim DT As DataTable
|
|
Dim CvePlantilaPoliza As Integer
|
|
Dim PorcentajeAmortizacion As Decimal = 0
|
|
Dim sumaAmorticaciones As Decimal = 0
|
|
Dim ivaTrasladado As Decimal = 0
|
|
Dim retIvaTrasladado As Decimal = 0
|
|
Dim retIsrTrasladado As Decimal = 0
|
|
Dim ErrorPrepoliza As Boolean = False
|
|
Dim alertaContabilizacion As String = "Se enviaron correctamente las siguientes pólizas:<br><br>"
|
|
Dim idCuentaContabilizacion As Integer = 1
|
|
Dim tipoCambio As Decimal
|
|
Dim CuentasContablesInvalidas As New StringBuilder
|
|
|
|
If ObjFactura.TipoDocto = "Ing" Or ObjFactura.TipoDocto = "Ant" Or ObjFactura.TipoDocto = "Com" Then
|
|
CvePlantilaPoliza = 4
|
|
ElseIf ObjFactura.TipoDocto.Contiene("Egs", "Dev") Then
|
|
CvePlantilaPoliza = 7
|
|
ElseIf ObjFactura.TipoDocto = "Rem" Then
|
|
CvePlantilaPoliza = 4
|
|
End If
|
|
|
|
If ObjFactura.CveMoneda = 2 Then
|
|
tipoCambio = GlobalTipoCambio(ObjFactura.Fecha).ToString.ToDecimal
|
|
Else
|
|
tipoCambio = 1
|
|
End If
|
|
|
|
Dim ConceptoContable As Integer
|
|
Dim TipoMovimiento As Boolean
|
|
Dim importeMovimiento As Decimal
|
|
Dim FechaMovimiento As Date = Date.Today
|
|
Dim IdCtaContable As Integer
|
|
Dim IdCtaContableCliente As Integer
|
|
Dim Concepto As String = ViewState("VentaFolio").ToString
|
|
Dim Referencia As String = ViewState("VentaFolio").ToString
|
|
Dim Fecha = ObjFactura.Fecha
|
|
|
|
Dim importeMX As Decimal
|
|
Dim Multiplicador As Integer
|
|
'Dim CveIEPago As Integer
|
|
' Dim FolioIE As Long
|
|
|
|
If ObjConta.GetPlantillaConceptos(ObjFactura.CveEmpresa, CvePlantilaPoliza) Then
|
|
For Each Row As DataRow In ObjConta.DtResultados.Rows
|
|
|
|
ConceptoContable = Row("CveConcepto").ToString.ToEntero
|
|
TipoMovimiento = If(Row("TipoMovto").ToString = "True", True, False)
|
|
importeMovimiento = 0
|
|
IdCtaContable = 0
|
|
Multiplicador = (Row("Multiplicador").ToString.ToEntero)
|
|
Concepto = ObjConta.ObtenerConceptoEmpresa(UsuarioActual.CveEmpresa, ConceptoContable, ObjFactura.Cliente.Nombre, $"{ObjFactura.Serie}-{ObjFactura.Folio}", "")
|
|
|
|
Select Case ConceptoContable
|
|
Case 1 'Cliente
|
|
If ObjFactura.TipoDocto <> "Egs" Then
|
|
importeMovimiento = (ObjFactura.Total) * ValorMultiplicador
|
|
importeMX = importeMovimiento * tipoCambio * Multiplicador
|
|
FechaMovimiento = ObjFactura.FechaPago
|
|
If tipoCambio > 1 Then Concepto += $" TC:{tipoCambio} ${importeMovimiento.FormatoNumero(2)}"
|
|
|
|
If tipoCambio = 1 Then
|
|
IdCtaContable = ObjFactura.Cliente.IdCtaContClientes
|
|
Else
|
|
IdCtaContable = ObjFactura.Cliente.IdCtaContComplementaria
|
|
If importeMovimiento <> 0 AndAlso IdCtaContable > 0 Then
|
|
importeMX = importeMovimiento
|
|
If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, TipoMovimiento, 0, Referencia, ConceptoContable, Concepto, FechaMovimiento, IdCtaContable, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=ObjFactura.CveCliente, CveIE:=CveIE, ImporteMX:=importeMovimiento * tipoCambio - importeMovimiento, ImporteME:=If(tipoCambio = 1, 0, importeMovimiento)) Then
|
|
ErrorPrepoliza = True
|
|
End If
|
|
End If
|
|
|
|
IdCtaContable = ObjFactura.Cliente.IdCtaContMonedaExtranjera
|
|
End If
|
|
IdCtaContableCliente = IdCtaContable
|
|
End If
|
|
|
|
Case 4 'Venta Clasificacion
|
|
|
|
If ObjFactura.TipoDocto <> "Ant" Then
|
|
DT = TmpDTDetalle.FiltraParametros($"CvePS <> {0}", "", {"CveClasificacion", "CveSubProyecto"})
|
|
If DT.Rows.Count > 0 Then
|
|
'Se agrega movimiento separado por la cuenta de ventas (ER)
|
|
For Each Row2 As DataRow In DT.Rows
|
|
importeMovimiento = (TmpDTDetalle.SUM("Total", String.Format("CveClasificacion = {0} AND CveSubProyecto = {1}", Row2("CveClasificacion"), Row2("CveSubProyecto"))).ToString.ToDecimal) * ValorMultiplicador
|
|
importeMX = importeMovimiento * tipoCambio * Multiplicador
|
|
FechaMovimiento = ObjFactura.FechaPago
|
|
Concepto = $"{ViewState("VentaFolio").ToString} {If(Row2("CveClasificacion").ToString.ToEntero > 0, GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Clasificacion", $"CveClasificacion = {Row2("CveClasificacion").ToString}"), "")} - {If(Row2("CveSubProyecto").ToString.ToEntero > 0, GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa).FiltroPrimeroValor("SubProyecto", $"CveSubProyecto = {Row2("CveSubProyecto").ToString}"), "Sin SubProyecto Asignado")}"
|
|
If tipoCambio > 1 Then Concepto += $" TC:{tipoCambio} ${importeMovimiento.FormatoNumero(2)}"
|
|
IdCtaContable = GlobalDTClasificaciones(ObjFactura.CveEmpresa).FiltroPrimeroValor("IdCuentaIngresos", String.Format("CveClasificacion = {0}", Row2("CveClasificacion"))).ToEntero
|
|
If importeMovimiento <> 0 Then
|
|
|
|
If IdCtaContable <= 0 Then
|
|
CuentasContablesInvalidas.Append("<br>" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", ConceptoContable))("ConceptoContable").ToString + GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Clasificacion", $"CveClasificacion = {Row2("CveClasificacion").ToString}"))
|
|
idCuentaContabilizacion = 0
|
|
End If
|
|
|
|
If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, ConceptoContable, Concepto, ObjFactura.Fecha, IdCtaContable, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=ObjFactura.CveCliente, CveIE:=CveIE, CveClasificacion:=Row2("CveClasificacion").ToString.ToEntero, CveSubProyecto:=Row2("CveSubProyecto").ToString.ToEntero, ImporteMX:=importeMX, ImporteME:=If(tipoCambio = 1, 0, importeMovimiento)) Then
|
|
ErrorPrepoliza = True
|
|
Else
|
|
ViewState("SeGuardoPrePoliza") = True
|
|
End If
|
|
End If
|
|
Next
|
|
End If
|
|
End If
|
|
importeMovimiento = 0
|
|
|
|
|
|
|
|
Case 13 'Iva por Trasladar
|
|
importeMovimiento = ObjFactura.IVA * ValorMultiplicador
|
|
importeMX = Math.Round(importeMovimiento, 2) * tipoCambio * Multiplicador
|
|
FechaMovimiento = ObjFactura.FechaPago
|
|
IdCtaContable = UsuarioActual.Empresa.IdCuentaIVAxTrasladar
|
|
If tipoCambio > 1 Then Concepto += $" TC:{tipoCambio} ${importeMovimiento.FormatoNumero(2)}"
|
|
|
|
|
|
|
|
End Select
|
|
|
|
If importeMovimiento <> 0 Then
|
|
|
|
If IdCtaContable <= 0 Then
|
|
CuentasContablesInvalidas.Append("<br>" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", ConceptoContable))("ConceptoContable").ToString)
|
|
idCuentaContabilizacion = 0
|
|
End If
|
|
|
|
If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, ConceptoContable, Concepto, FechaMovimiento, IdCtaContable, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=ObjFactura.CveCliente, CveIE:=CveIE, ImporteMX:=importeMX, ImporteME:=If(tipoCambio = 1, 0, importeMovimiento)) Then
|
|
ErrorPrepoliza = True
|
|
Else
|
|
ViewState("SeGuardoPrePoliza") = True
|
|
End If
|
|
|
|
End If
|
|
|
|
Next
|
|
|
|
End If
|
|
|
|
Return ErrorPrepoliza
|
|
End Function
|
|
|
|
Private Sub GeneraPDFFactura(EnviaCorreo As Boolean)
|
|
|
|
|
|
'If Not ImprimeAlert Then
|
|
Dim Archivo As New System.IO.FileInfo(String.Format("{0}Formatos/Factura.rdlc", UsuarioActual.Empresa.Ruta))
|
|
Dim Archivo2 As New System.IO.FileInfo(String.Format("{0}Formatos/Remision.rdlc", UsuarioActual.Empresa.Ruta))
|
|
|
|
'CASO NORMAL NEW
|
|
If Archivo.Exists Or Archivo2.Exists Then
|
|
MensajeAlert.AppendFormat("<ul><li><a class=""Texto"" href=""/Compras/PopUpVerFactura.aspx?P={0}"">Descargar PDF</a></li></ul><br/>", Encripta(String.Format("OP=VTA&CVEVENTA={0}", ObjFactura.CveVenta)))
|
|
Else
|
|
MensajeAlert.Append("Ocurrió un error al generar el PDF. Por favor vuelva a entrar a la factura para imprimir el PDF. ")
|
|
End If
|
|
|
|
|
|
Dim pdf As Byte() = Nothing
|
|
|
|
'GUARDA PDF
|
|
Dim LocalSerieFolio As String = String.Empty
|
|
Dim LocalTipoDocto As String = String.Empty
|
|
|
|
|
|
'TIMBRADO NUEVO
|
|
Try
|
|
pdf = PdfFactura(ObjFactura)
|
|
' File.WriteAllBytes(String.Format("{0}PDF/{1}/{2}.pdf", UsuarioActual.Empresa.Ruta, ObjFactura.TipoDocto, ObjFactura.SerieFolio), pdf)
|
|
Catch ex As Exception
|
|
Alert("Ocurrió un error al generar el PDF", TipoMensaje.MsgAdvertencia)
|
|
End Try
|
|
|
|
LocalSerieFolio = ObjFactura.SerieFolio
|
|
LocalTipoDocto = ObjFactura.TipoDocto
|
|
'End If
|
|
|
|
End Sub
|
|
|
|
Private Sub GuardarContratoAvanceEstimaciones(ObjVentas As ClsVentas, factura As Modelos.Factura, ErrorList As List(Of String), Multiplicador As Integer, Optional CrearAvance As Boolean = False)
|
|
|
|
If factura.CveContrato > 0 Then
|
|
Dim ObjContratos As New ClsContratos(ObjVentas.IniciaTransacSQL())
|
|
Dim CveEstimacion As Integer = -1
|
|
|
|
If ObjContratos.AddEstimaciones(factura.CveContrato, factura.Fecha, -1, factura.CveVenta, "-1", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then
|
|
CveEstimacion = ObjContratos.DtResultados(0)("CveEstimacion").ToString.ToEntero
|
|
|
|
For Each row As DataRow In TmpDT.Rows
|
|
If Not ObjContratos.AddContratosAvance(row("CveContratoDetalle").ToString.ToEntero, row("Cantidad").ToString.ToEntero * Multiplicador, factura.Fecha, UsuarioActual.CveUsuario, CveEstimacion:=CveEstimacion) Then
|
|
ErrorList.Add("Ocurrió un error al agregar los avances")
|
|
End If
|
|
Next
|
|
|
|
Else
|
|
ErrorList.Add("Ocurrió un error al agregar las estimaciones")
|
|
End If
|
|
End If
|
|
|
|
End Sub
|
|
|
|
End Class
|