diff --git a/Ventas/Ventas.aspx.vb b/Ventas/Ventas.aspx.vb
index a2e9b6c87..fe6236592 100644
--- a/Ventas/Ventas.aspx.vb
+++ b/Ventas/Ventas.aspx.vb
@@ -5703,6 +5703,7 @@ Partial Class Ventas
VentaActual.PorcentajeIVA = DbRowVenta("PorcentajeIVA").ToString.ToDecimal
VentaActual.UsuarioActual = UsuarioActual
VentaActual.CveSubProyecto = DbRowVenta("CveSubProyecto").ToString.ToEntero
+ VentaActual.CveUsoCFDI = DbRowVenta("CveUsoCFDI").ToString.ToEntero
HdnAmortizacion.Value = LblAmort.Text.ToDouble.ToString()
HdnSubTotalDescuestos.Value = (TxtSubTotal.Text.Replace(",", "").ToDouble - LblDescuentos.Text.Replace(",", "").ToDouble - LblAmortizacion.Text.Trim.Replace(",", "").ToDouble - TxtRetISR.Text.Replace(",", "").ToDouble).FormatoNumero(2)
@@ -17525,6 +17526,123 @@ Partial Class Ventas
End If
End If
End Sub
+
+ Private Function GenerarNC(ImporteTotal As Decimal, CveVendedor As Integer, ByRef Venta As Venta, GvRowAnticipo As GridViewRow, ByRef ObjVentas As ClsVentas) As Modelos.Factura.MMensajeFactura
+ Dim Retorno As Modelos.Factura.MMensajeFactura = Nothing
+ Dim SbAlert As New StringBuilder()
+
+ Try
+ Dim ObjNC = Modelos.Factura.CrearVentaNueva(UsuarioActual, Venta.CveSubProyecto, Venta.CveCliente, Venta.CveMoneda, "Egs")
+ ObjNC.CveMoneda = Venta.CveMoneda
+ If ObjNC.CveMoneda = 2 Then
+ ObjNC.TipoCambio = GlobalTipoCambio(Now).ToString().ToDecimal()
+ Else
+ ObjNC.TipoCambio = 1
+ End If
+
+ Dim Total As Decimal = ImporteTotal
+ Dim subTotal As Decimal = (Total / (1D + Venta.PorcentajeIVA))
+ 'Dim IVA = (subTotal * Factura.PorcentajeIVA).RoundSQL(2)
+ Dim PU As Decimal = subTotal
+ Dim Cantidad As Decimal = 1D
+ Dim Descuento As Decimal = 0
+ Dim Obs = ""
+
+ Dim CvePSAnticipo As Integer = 1
+ Dim DatarowPS = GlobalDTPS(UsuarioActual.CveEmpresa, SATClavePS:="84111506").FiltroPrimero("CodigoPS LIKE '%ANTICIPO%' OR CodigoPS LIKE '%anticipo%' OR CodigoPS LIKE '%Anticipo%'")
+ If DatarowPS IsNot Nothing Then
+ CvePSAnticipo = DatarowPS("CvePS").ToString().ToEntero()
+ End If
+
+ ObjNC.AgregarPS(CvePSAnticipo, Cantidad, PU, Descuento, Obs, CveSubProyecto:=Venta.CveSubProyecto, PorcentajeIVA:=Venta.PorcentajeIVA)
+ ObjNC.CalculaTotales()
+
+ Dim DtVentasNC = New DataTable
+ DtVentasNC.Columns.Add("CveVenta", GetType(Integer))
+ DtVentasNC.Columns.Add("Importe", GetType(Decimal))
+ DtVentasNC.Columns.Add("FolioFiscal", GetType(String))
+ DtVentasNC.Columns.Add(New DataColumn With {.ColumnName = "TC", .DataType = GetType(Decimal), .DefaultValue = 1})
+ DtVentasNC.Columns.Add(New DataColumn With {.ColumnName = "TCCambioValuacion", .DataType = GetType(Decimal), .DefaultValue = 1})
+ DtVentasNC.Columns.Add(New DataColumn With {.ColumnName = "CveEstatusFactura", .DataType = GetType(Integer), .DefaultValue = -1})
+ DtVentasNC.Columns.Add(New DataColumn With {.ColumnName = "Folio", .DataType = GetType(String), .DefaultValue = ""})
+
+ DtVentasNC.Rows.Add(Venta.CveVenta, Total, "")
+
+ ObjNC.DtVentasNC = DtVentasNC
+
+ Dim DtVentasRelacionadas As New DataTable()
+ DtVentasRelacionadas.Columns.Add("CveVenta", GetType(Integer))
+ DtVentasRelacionadas.Rows.Add(Venta.CveVenta)
+
+ ObjNC.DtVentasRelacionadas = DtVentasRelacionadas
+
+ Dim DtAnticipos As New DataTable()
+ DtAnticipos.Columns.Add("CveVenta", GetType(Integer))
+ DtAnticipos.Columns.Add("Importe", GetType(Decimal))
+ DtAnticipos.Columns.Add("CveConceptoContable", GetType(Integer))
+ DtAnticipos.Columns.Add("CveIE", GetType(Integer))
+ DtAnticipos.Columns.Add("FolioFiscal", GetType(String))
+ DtAnticipos.Columns.Add("Descuentos", GetType(Decimal))
+ DtAnticipos.Columns.Add("TotalAnticipo", GetType(Decimal))
+ DtAnticipos.Columns.Add("SubTotalAnticipo", GetType(Decimal))
+ DtAnticipos.Columns.Add("CveMoneda", GetType(Decimal))
+ DtAnticipos.Columns.Add("Fecha", GetType(DateTime))
+ DtAnticipos.Columns.Add("TipoCambioPago", GetType(Decimal))
+ DtAnticipos.Columns.Add("Folio", GetType(String))
+ DtAnticipos.Columns.Add("Tipo", GetType(String))
+
+ If GvRowAnticipo IsNot Nothing Then
+ Dim CveVenta = GvRowAnticipo.DataKey("CveVenta").ToEntero()
+ Dim Importe = GvRowAnticipo.FCTextBox(String.Format("TxtAnticipo{0}", GvRowAnticipo.RowIndex)).Text.ToDecimal()
+ Dim CveConceptoContable = GvRowAnticipo.DataKey("CveConceptoContable").ToEntero()
+ Dim CveIE = GvRowAnticipo.DataKey("CveIE").ToEntero()
+
+ Dim FolioFiscal = GvRowAnticipo.DataKey("FolioFiscal")
+ Dim Descuentos As Decimal = GvRowAnticipo.DataKey("Descuentos").ToDecimal()
+ Dim TotalAnticipo As Decimal = GvRowAnticipo.DataKey("TotalAnticipo").ToDecimal()
+ Dim SubTotalAnticipo As Decimal = GvRowAnticipo.DataKey("SubTotalAnticipo").ToDecimal()
+ Dim CveMoneda As Integer = GvRowAnticipo.DataKey("CveMoneda").ToEntero()
+ Dim Fecha As DateTime = GvRowAnticipo.DataKey("Fecha").ToDateTime()
+ Dim TipoCambioPago As Decimal = GvRowAnticipo.DataKey("TipoCambioPago").ToDecimal()
+ Dim Folio = GvRowAnticipo.DataKey("Folio")
+ Dim Tipo = GvRowAnticipo.DataKey("Tipo")
+
+
+ DtAnticipos.Rows.Add(CveVenta, Importe, CveConceptoContable, CveIE, FolioFiscal, Descuentos, TotalAnticipo, SubTotalAnticipo, CveMoneda, Fecha, TipoCambioPago, Folio, Tipo)
+ End If
+
+ ObjNC.EsNCAmortizacion = True
+ ObjNC.CveTipoAmortizacionAnticipo = 2
+ ObjNC.DtAnticiposAplicados = DtAnticipos
+
+ ObjNC.CveFormaPago = 21 'Aplicación de anticipos
+ ObjNC.CveMetodoPago = 1
+ ObjNC.CveUsoCFDI = Venta.CveUsoCFDI
+ ObjNC.CveVendedor = CveVendedor
+ ObjNC.CveTipoRelacion = 7
+
+ ObjNC.PreparaTimbre()
+ AjustarTimbreNC(ObjNC)
+
+ Retorno = ObjNC.EmitirFactura(False, Transac:=ObjVentas.IniciaTransacSQL(), Modulo:="Cobranza/GuardarVenta", MostrarURL:=True)
+ Retorno.Factura = ObjNC
+
+ If Retorno IsNot Nothing AndAlso Retorno.CveVenta > 0 Then
+ For Each msg In Retorno.Mensajes
+ SbAlert.AppendFormat("{0}
", msg)
+ Next
+
+ SbAlert.AppendFormat("