Correciones en facturacion masiva
This commit is contained in:
@@ -202,22 +202,35 @@ Partial Class Contratos_FacturacionMasiva
|
||||
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
|
||||
EjecutarFacturacion()
|
||||
Protected Sub ImgFacturarTodos_Click(sender As Object, e As EventArgs) Handles ImgFacturarTodos.Click
|
||||
EjecutarFacturacion(FacturarTodos:=True)
|
||||
Dim CveContrato As Integer = If(DdlContrato.SelectedValue.ToEntero <= 0, -1, DdlContrato.SelectedValue.ToEntero)
|
||||
Dim CveCliente As Integer = If(DdlCliente.SelectedValue.ToEntero <= 0, -1, DdlCliente.SelectedValue.ToEntero)
|
||||
|
||||
CargaDatos(CveContrato, CveCliente)
|
||||
End Sub
|
||||
|
||||
Protected Sub btnFacturarAqui_Click(sender As Object, e As EventArgs) Handles BtnFacturar.Click
|
||||
EjecutarFacturacion(FacturarTodos:=False)
|
||||
|
||||
Dim CveContrato As Integer = If(DdlContrato.SelectedValue.ToEntero <= 0, -1, DdlContrato.SelectedValue.ToEntero)
|
||||
Dim CveCliente As Integer = If(DdlCliente.SelectedValue.ToEntero <= 0, -1, DdlCliente.SelectedValue.ToEntero)
|
||||
|
||||
CargaDatos(CveContrato, CveCliente)
|
||||
RegistraScript("$('#divAgregar').modal('hide')")
|
||||
UpBodyEstatus.Update()
|
||||
End Sub
|
||||
|
||||
Private Sub EjecutarFacturacion()
|
||||
Private Sub EjecutarFacturacion(Optional FacturarTodos As Boolean = False)
|
||||
Dim FacturadoCorrecto = True
|
||||
Dim sb As New StringBuilder()
|
||||
|
||||
For Each row As GridViewRow In GvCiclosComerciales.Rows
|
||||
If row.FCCheckBox("chkDis").Checked Then
|
||||
If FacturarTodos OrElse row.FCCheckBox("chkDis").Checked Then
|
||||
|
||||
Dim Resp = EmitirImprimir(row.DataKey("CveCicloComercial").ToString.ToEntero)
|
||||
|
||||
For Each Msg In Resp.Mensajes
|
||||
sb.AppendFormat("{0}</br></br>", Msg)
|
||||
Next
|
||||
sb.AppendFormat("{0}</br></br>", Resp.Mensaje)
|
||||
|
||||
If Not FacturadoCorrecto Then
|
||||
If Mensaje = "" Then
|
||||
@@ -234,155 +247,75 @@ Partial Class Contratos_FacturacionMasiva
|
||||
Else
|
||||
Alert("No se generaron facturas", TipoMensaje.MsgAdvertencia)
|
||||
End If
|
||||
|
||||
Dim CveContrato As Integer = If(DdlContrato.SelectedValue.ToEntero <= 0, -1, DdlContrato.SelectedValue.ToEntero)
|
||||
Dim CveCliente As Integer = If(DdlCliente.SelectedValue.ToEntero <= 0, -1, DdlCliente.SelectedValue.ToEntero)
|
||||
|
||||
CargaDatos(CveContrato, CveCliente)
|
||||
RegistraScript("$('#divAgregar').modal('hide')")
|
||||
UpBodyEstatus.Update()
|
||||
End Sub
|
||||
|
||||
Protected Sub btnFacturarAqui_Click(sender As Object, e As EventArgs)
|
||||
EjecutarFacturacion()
|
||||
End Sub
|
||||
|
||||
Private Function EmitirImprimir(pCveCicloComercial As Integer) As Modelos.Factura.MMensajeFactura
|
||||
Dim Resp As New Modelos.Factura.MMensajeFactura
|
||||
|
||||
Private Function EmitirImprimir(pCveCicloComercial As Integer) As MMensajeFacturacion
|
||||
Dim Retorno As New MMensajeFacturacion
|
||||
|
||||
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 Resp
|
||||
Return Retorno
|
||||
End If
|
||||
|
||||
|
||||
If ObjFactura.CveCliente > 0 Then
|
||||
If ObjFactura.DtDetalle.Rows.Count > 0 Then
|
||||
Dim TieneError As Boolean = False
|
||||
Dim RespFactura As Modelos.Factura.MMensajeFactura = Nothing
|
||||
|
||||
Try
|
||||
RespFactura = ObjFactura.EmitirFactura(Timbrar:=False)
|
||||
|
||||
If RespFactura IsNot Nothing AndAlso RespFactura.CveVenta <= 0 OrElse RespFactura.TieneError Then
|
||||
TieneError = True
|
||||
End If
|
||||
Catch ex As Exception
|
||||
TieneError = True
|
||||
OnError("Ocurrió un error al generar la factura", ex)
|
||||
End Try
|
||||
|
||||
If Not TieneError AndAlso RespFactura.CveVenta > 0 Then
|
||||
Retorno.CveVenta = RespFactura.CveVenta
|
||||
Retorno.SerieFolio = RespFactura.SerieFolio
|
||||
Retorno.SeTimbro = ObjFactura.TimbrarFactura()
|
||||
End If
|
||||
|
||||
Dim SbMensajes As New StringBuilder
|
||||
|
||||
If Not TieneError Then
|
||||
SbMensajes.AppendFormat("La factura <a class=""Texto"" target='_blank' href=""/Ventas/Ventas.aspx?CveVenta={0}"">{1}</a> se guardo correctamente.", Retorno.CveVenta, Retorno.SerieFolio)
|
||||
|
||||
If Not Retorno.SeTimbro Then
|
||||
SbMensajes.AppendFormat("<br/> La factura no se pudo timbrar.")
|
||||
End If
|
||||
Else
|
||||
SbMensajes.Append("Ocurrió un error al generar la factura.")
|
||||
If RespFactura IsNot Nothing Then
|
||||
For Each msg As String In RespFactura.Mensajes
|
||||
SbMensajes.Append(msg)
|
||||
Next
|
||||
End If
|
||||
End If
|
||||
|
||||
Retorno.Mensaje = SbMensajes.ToString()
|
||||
|
||||
Resp = ObjFactura.EmitirFactura()
|
||||
|
||||
'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 "
|
||||
Retorno.Mensaje = "No se pudo completar facturación por que no se encontraron partidas "
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
If ObjFactura IsNot Nothing Then
|
||||
ObjFactura.Dispose()
|
||||
End If
|
||||
|
||||
TmpDT.Clear()
|
||||
Return Resp
|
||||
Return Retorno
|
||||
End Function
|
||||
|
||||
|
||||
@@ -500,13 +433,13 @@ Partial Class Contratos_FacturacionMasiva
|
||||
ObjFactura.Folio = -1
|
||||
ObjFactura.Serie = "-1"
|
||||
ObjFactura.CveMesa = -1
|
||||
ObjFactura.Fecha = DR("FechaVenc").ToString.ToDate
|
||||
ObjFactura.Fecha = DR("FechaVenc").ToString.ToDate 'If(DR("FechaVenc").ToString.ToDate > Now, Now, DR("FechaVenc").ToString.ToDate)
|
||||
ObjFactura.CvePrePoliza = -1
|
||||
ObjFactura.CveMetodoPago = 1
|
||||
ObjFactura.MetodoPago = "Efectivo"
|
||||
ObjFactura.FechaPago = DateTime.Today
|
||||
ObjFactura.MotivoDescuento = ""
|
||||
ObjFactura.Observaciones = TxtObservaciones.Text + " " + DR("Observaciones").ToString
|
||||
ObjFactura.Observaciones = If(String.IsNullOrEmpty(TxtObservaciones.Text), "", TxtObservaciones.Text + " ") + DR("Observaciones").ToString
|
||||
ObjFactura.FechaEjecucion = DateTime.Today
|
||||
'ObjFactura.ClaveMetodoPagoSAT = GlobalDTMetodosPago.FiltroPrimeroValor("ClaveSAT", $"CveMetodoPago = {1}")
|
||||
ObjFactura.UsuarioCreo = UsuarioActual.Usuario
|
||||
@@ -638,7 +571,10 @@ Partial Class Contratos_FacturacionMasiva
|
||||
ObjFactura.SetSubProyecto(Me)
|
||||
|
||||
ObjFactura.Timbre = PreParaTimbre(ObjFactura)
|
||||
|
||||
ObjFactura.FemsaFactura = New Modelos.FemsaFactura() With {
|
||||
.AplicaFEMSA = False,
|
||||
.FEMSA_Version = 1
|
||||
}
|
||||
End Sub
|
||||
|
||||
Private Function PreParaTimbre(Obj As Modelos.Factura) As CFDITimbre
|
||||
@@ -764,372 +700,11 @@ Partial Class Contratos_FacturacionMasiva
|
||||
Return Timbre
|
||||
End Function
|
||||
|
||||
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("Contratos/FacturacionMasiva", 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, CveFormaPago33:=factura.CveFormaPago33,
|
||||
CveMetodoPago33:=factura.CveMetodoPago33, CveUsoCFDI:=factura.CveUsoCFDI) 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
|
||||
Dim Observacion As String = Row("Observacion").ToString
|
||||
If TxtObservaciones.Text.Trim <> "" Then
|
||||
Observacion = $"{Observacion} {TxtObservaciones.Text}"
|
||||
End If
|
||||
|
||||
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(factura.ConvertirPesos, factura.TipoCambio, 1)), Math.Round((Row("Total").ToString.ToDouble(If(factura.ConvertirPesos, factura.TipoCambio, 1)) * (1 + Row("IVA").ToString.ToDouble(If(factura.ConvertirPesos, factura.TipoCambio, 1)))), 6),
|
||||
Observacion, 0, 0, Row("CveSubProyecto").ToString.ToEntero, -1,
|
||||
TiempoEntrega:="", CveVentaDetallePadre:=-1, CveContratoDetalle:=Row("CveContratoDetalle").ToString.ToEntero, CvePromocionDetalle:=-1, IEPS:=Row("ImporteIEPS").ToString.ToDouble,
|
||||
ImporteRetIVA:=Row("ImporteRetIVA").ToString.ToDouble, ImporteRetISR:=Row("ImporteRetISR").ToString.ToDouble,
|
||||
PorcentajeIEPS:=Row("PorcentajeIEPS").ToString.ToDouble, PorcentajeRetIVA:=Row("PorcentajeRetIVA").ToString.ToDouble, PorcentajeRetISR:=Row("PorcentajeRetISR").ToString.ToDouble) 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 CveCuenta 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
|
||||
CveCuenta = 0
|
||||
Multiplicador = (Row("Multiplicador").ToString.ToEntero)
|
||||
Concepto = ObjConta.ObtenerConceptoEmpresa(UsuarioActual.CveEmpresa, ConceptoContable, ObjFactura.Cliente.Nombre, $"{ObjFactura.Serie}-{ObjFactura.Folio}", "")
|
||||
|
||||
Dim PorcentajeImpuesto As Decimal = 0
|
||||
|
||||
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 8 'Ret IVA por Trasladar
|
||||
If Not ObjFactura.TipoDocto.Contiene("Rem") Then
|
||||
importeMovimiento = ObjFactura.RetIVA * ValorMultiplicador
|
||||
importeMX = Math.Round(importeMovimiento, 2) * tipoCambio * Multiplicador
|
||||
FechaMovimiento = ObjFactura.FechaPago
|
||||
If tipoCambio > 1 Then Concepto += $" TC:{tipoCambio} ${importeMovimiento.FormatoNumero(2)}"
|
||||
|
||||
'Contabilidad ContPAQ
|
||||
If IdCtaContRetIVA > 0 Then
|
||||
IdCtaContable = IdCtaContRetIVA
|
||||
Else
|
||||
If ObjConta.GetRetCuenta(ConceptoContable, ObjFactura.CveEmpresa) Then
|
||||
If ObjConta.DtResultados.Rows.Count > 0 Then
|
||||
IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
'Contabilidad SIG
|
||||
If CveCuentaRetIVA > 0 Then
|
||||
CveCuenta = CveCuentaRetIVA
|
||||
Else
|
||||
If ObjConta.GetRetCuenta(ConceptoContable, ObjFactura.CveEmpresa) Then
|
||||
If ObjConta.DtResultados.Rows.Count > 0 Then
|
||||
CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
Case 9 'Ret ISR por Trasladar
|
||||
If Not ObjFactura.TipoDocto.Contiene("Rem") Then
|
||||
importeMovimiento = ObjFactura.RetISR * ValorMultiplicador
|
||||
importeMX = Math.Round(importeMovimiento, 2) * tipoCambio * Multiplicador
|
||||
FechaMovimiento = ObjFactura.FechaPago
|
||||
If tipoCambio > 1 Then Concepto += $" TC:{tipoCambio} ${importeMovimiento.FormatoNumero(2)}"
|
||||
|
||||
'Contabilidad ContPAQ
|
||||
If IdCtaContRetISR > 0 Then
|
||||
IdCtaContable = IdCtaContRetISR
|
||||
Else
|
||||
If ObjConta.GetRetCuenta(ConceptoContable, ObjFactura.CveEmpresa) Then
|
||||
If ObjConta.DtResultados.Rows.Count > 0 Then
|
||||
IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacion").ToString.ToEntero
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
'Contabilidad SIG
|
||||
If CveCuentaRetISR > 0 Then
|
||||
CveCuenta = CveCuentaRetISR
|
||||
Else
|
||||
If ObjConta.GetRetCuenta(ConceptoContable, ObjFactura.CveEmpresa) Then
|
||||
If ObjConta.DtResultados.Rows.Count > 0 Then
|
||||
CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacionSIG").ToString.ToEntero
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
|
||||
|
||||
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)}"
|
||||
PorcentajeImpuesto = TmpDTDetalle.MAX("PorcentajeIVA").ToDecimal
|
||||
|
||||
Case 38 'IEPS por Trasladar
|
||||
If Not ObjFactura.TipoDocto.Contiene("Rem") Then
|
||||
importeMovimiento = ObjFactura.IEPS * ValorMultiplicador
|
||||
importeMX = Math.Round(importeMovimiento * tipoCambio * Multiplicador, 2)
|
||||
FechaMovimiento = ObjFactura.Fecha
|
||||
If tipoCambio > 1 Then Concepto += $" TC:{tipoCambio} ${importeMovimiento.FormatoNumero(2)}"
|
||||
If importeMovimiento > 0 AndAlso ObjConta.GetRetCuenta(ConceptoContable, ObjFactura.CveEmpresa) Then
|
||||
If ObjConta.DtResultados.Rows.Count > 0 Then
|
||||
IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaIEPSxTrasladar").ToString.ToEntero
|
||||
CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaIEPSxTrasladarSIG").ToString.ToEntero
|
||||
End If
|
||||
End If
|
||||
PorcentajeImpuesto = TmpDTDetalle.MAX("PorcentajeIEPS").ToDecimal
|
||||
End If
|
||||
|
||||
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), PorcentajeImpuesto:=PorcentajeImpuesto) 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}&PAG=1", 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
|
||||
Public Class MMensajeFacturacion
|
||||
Public Property CveVenta As Integer = -1
|
||||
Public Property SerieFolio As String = ""
|
||||
Public Property Mensaje As String = ""
|
||||
Public Property SeTimbro As Boolean = False
|
||||
End Class
|
||||
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user