Pendientes BDH, mejoras servicion E141, mwjoras carga PS entradas/salidas,cambios en modalidad contable, favicon signals gps
This commit is contained in:
136
Ashx/E141.ashx
136
Ashx/E141.ashx
@@ -631,6 +631,7 @@ Public Class E141 : Implements IHttpHandler
|
||||
Dim DebeTimbrar As Boolean = False
|
||||
|
||||
Dim ObjClientes As New ClsClientes()
|
||||
Dim ObjInventario As New ClsInventarios(ObjClientes.IniciaTransacSQL())
|
||||
ObjClientes.IniciaTransacSQL()
|
||||
|
||||
Try
|
||||
@@ -638,7 +639,7 @@ Public Class E141 : Implements IHttpHandler
|
||||
DebeTimbrar = CBool(JsonRequest("timbrar"))
|
||||
End If
|
||||
|
||||
ObjFactura = CreaFactura(ObjClientes, "Ing", Resp, JsonRequest, Usuario)
|
||||
ObjFactura = CreaFactura(ObjInventario, ObjClientes, "Ing", Resp, JsonRequest, Usuario)
|
||||
|
||||
If ObjFactura IsNot Nothing Then
|
||||
Resp = ObjFactura.EmitirFactura(False, Transac:=ObjClientes.IniciaTransacSQL())
|
||||
@@ -768,7 +769,7 @@ Public Class E141 : Implements IHttpHandler
|
||||
|
||||
End Function
|
||||
|
||||
Private Function CreaFactura(ObjClientes As ClsClientes, TipoDocto As String, Resp As Modelos.Factura.MMensajeFactura, JsonRequest As JObject, UsuarioActual As Usuario) As Modelos.Factura
|
||||
Private Function CreaFactura(ObjInventario As ClsInventarios, ObjClientes As ClsClientes, TipoDocto As String, Resp As Modelos.Factura.MMensajeFactura, JsonRequest As JObject, UsuarioActual As Usuario) As Modelos.Factura
|
||||
Try
|
||||
Resp.TieneError = False
|
||||
Dim Serie As String = "-1"
|
||||
@@ -867,36 +868,85 @@ Public Class E141 : Implements IHttpHandler
|
||||
End If
|
||||
|
||||
'FORMA DE PAGO
|
||||
If JsonRequest("invoice_way_to_pay") Is Nothing Then
|
||||
Resp.TieneError = False
|
||||
Resp.Mensajes.Add("Debe asignar una forma de pago")
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
If Not String.IsNullOrEmpty(JsonRequest("invoice_way_to_pay").ToString()) Then
|
||||
Dim RowFormaPago As DataRow = GlobalDTVtaFormaPago.FiltroPrimero(String.Format("ClaveFormaPagoSAT = '{0}'", JsonRequest("invoice_way_to_pay").ToString()))
|
||||
|
||||
ObjFactura.CveFormaPago33 = RowFormaPago("CveFormaPago").ToString().ToEntero()
|
||||
ObjFactura.FormaPago33 = RowFormaPago("FormaPago").ToString()
|
||||
ObjFactura.FormaPagoSAT33 = RowFormaPago("ClaveFormaPagoSAT").ToString()
|
||||
If RowFormaPago IsNot Nothing Then
|
||||
ObjFactura.CveFormaPago33 = RowFormaPago("CveFormaPago").ToString().ToEntero()
|
||||
ObjFactura.FormaPago33 = RowFormaPago("FormaPago").ToString()
|
||||
ObjFactura.FormaPagoSAT33 = RowFormaPago("ClaveFormaPagoSAT").ToString()
|
||||
Else
|
||||
Resp.TieneError = False
|
||||
Resp.Mensajes.Add("No se encontro la forma de pago")
|
||||
Return Nothing
|
||||
End If
|
||||
Else
|
||||
Resp.TieneError = False
|
||||
Resp.Mensajes.Add("Debe asignar una forma de pago")
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
'USO CFDi
|
||||
If JsonRequest("invoice_use") Is Nothing Then
|
||||
Resp.TieneError = False
|
||||
Resp.Mensajes.Add("Debe asignar un uso cfdi")
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
If Not String.IsNullOrEmpty(JsonRequest("invoice_use").ToString()) Then
|
||||
Dim RowUsoCFDi As DataRow = GlobalDTSATUsosCFDI.FiltroPrimero(String.Format("UsoCFDI = '{0}'", JsonRequest("invoice_use").ToString()))
|
||||
|
||||
ObjFactura.CveUsoCFDI = RowUsoCFDi("CveUsoCFDI").ToString().ToEntero()
|
||||
ObjFactura.UsoCFDI = RowUsoCFDi("Descripcion").ToString()
|
||||
ObjFactura.ClaveUsoCFDI = RowUsoCFDi("UsoCFDI").ToString()
|
||||
If RowUsoCFDi IsNot Nothing Then
|
||||
ObjFactura.CveUsoCFDI = RowUsoCFDi("CveUsoCFDI").ToString().ToEntero()
|
||||
ObjFactura.UsoCFDI = RowUsoCFDi("Descripcion").ToString()
|
||||
ObjFactura.ClaveUsoCFDI = RowUsoCFDi("UsoCFDI").ToString()
|
||||
Else
|
||||
Resp.TieneError = False
|
||||
Resp.Mensajes.Add("No se encontro el uso cfdi")
|
||||
Return Nothing
|
||||
End If
|
||||
Else
|
||||
Resp.TieneError = False
|
||||
Resp.Mensajes.Add("Debe asignar un uso cfdi")
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
'METODO DE PAGO
|
||||
If Not String.IsNullOrEmpty(JsonRequest("invoice_payment_method").ToString()) Then
|
||||
Dim RowMetodoPago As DataRow = GlobalDTVtaMetodoPago.FiltroPrimero(String.Format("ClaveMetodoPagoSAT = '{0}'", JsonRequest("invoice_payment_method").ToString()))
|
||||
|
||||
ObjFactura.CveMetodoPago33 = RowMetodoPago("CveMetodoPago").ToString().ToEntero()
|
||||
ObjFactura.MetodoPago33 = RowMetodoPago("MetodoPago").ToString()
|
||||
ObjFactura.ClaveMetodoPagoSAT = RowMetodoPago("ClaveMetodoPagoSAT").ToString()
|
||||
If JsonRequest("invoice_payment_method") Is Nothing Then
|
||||
Resp.TieneError = False
|
||||
Resp.Mensajes.Add("Debe asignar un método de pago")
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
End If
|
||||
If Not String.IsNullOrEmpty(JsonRequest("invoice_payment_method").ToString()) Then
|
||||
Dim RowMetodoPago As DataRow = GlobalDTVtaMetodoPago.FiltroPrimero(String.Format("ClaveMetodoPagoSAT = '{0}'", JsonRequest("invoice_payment_method").ToString()))
|
||||
If RowMetodoPago IsNot Nothing Then
|
||||
ObjFactura.CveMetodoPago33 = RowMetodoPago("CveMetodoPago").ToString().ToEntero()
|
||||
ObjFactura.MetodoPago33 = RowMetodoPago("MetodoPago").ToString()
|
||||
ObjFactura.ClaveMetodoPagoSAT = RowMetodoPago("ClaveMetodoPagoSAT").ToString()
|
||||
Else
|
||||
Resp.TieneError = False
|
||||
Resp.Mensajes.Add("No se encontro el método de pago")
|
||||
Return Nothing
|
||||
End If
|
||||
Else
|
||||
Resp.TieneError = False
|
||||
Resp.Mensajes.Add("Debe asignar un método de pago")
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
ObjFactura.CveAlmacen = GlobalDTAlmacen(CveEmpresa, CveTipoAlmacen:=1).FiltroPrimeroValor("CveAlmacen", $"CveSubProyecto={CveSubProyecto}").ToEntero()
|
||||
|
||||
|
||||
|
||||
'DETALLES
|
||||
ObjFactura.DtDetalle = CreaDTDetalle(Resp, UsuarioActual, JsonRequest)
|
||||
ObjFactura.DtDetalle = CreaDTDetalle(ObjInventario, ObjFactura, Resp, UsuarioActual, JsonRequest)
|
||||
|
||||
If Resp.TieneError Then
|
||||
Resp.Mensajes.Add("No se pudieron agregar los productos/servicios")
|
||||
@@ -912,7 +962,6 @@ Public Class E141 : Implements IHttpHandler
|
||||
'INVENTARIO
|
||||
If TipoDocto = "Ing" Then
|
||||
ObjFactura.DtInventario = ObjFactura.DtDetalle.Copy.FiltraParametros("CveTipoPS = 2")
|
||||
ObjFactura.CveAlmacen = GlobalDTAlmacen(CveEmpresa, CveTipoAlmacen:=1).FiltroPrimeroValor("CveAlmacen", $"CveSubProyecto={CveSubProyecto}").ToEntero()
|
||||
ObjFactura.GenerarSalidaAlmacen = True
|
||||
ObjFactura.GenerarPDFFactura = False
|
||||
End If
|
||||
@@ -1104,7 +1153,7 @@ Public Class E141 : Implements IHttpHandler
|
||||
Next
|
||||
Return Timbre
|
||||
End Function
|
||||
Private Function CreaDTDetalle(ByRef Retorno As Modelos.Factura.MMensajeFactura, UsuarioActual As Usuario, JsonRequest As JObject) As DataTable
|
||||
Private Function CreaDTDetalle(ByRef ObjInventarios As ClsInventarios, ObjFactura As Modelos.Factura, ByRef Retorno As Modelos.Factura.MMensajeFactura, UsuarioActual As Usuario, JsonRequest As JObject) As DataTable
|
||||
Dim TmpDT = New DataTable
|
||||
TmpDT.Columns.Add("CveVenta", GetType(Integer))
|
||||
TmpDT.Columns.Add("Consec", GetType(Integer))
|
||||
@@ -1193,30 +1242,50 @@ Public Class E141 : Implements IHttpHandler
|
||||
Dim DescuentoPorPartida As Decimal = (DescuentoTotal / ListaPS.Count)
|
||||
|
||||
Dim Consec As Integer = 1
|
||||
For Each Dr As JObject In ListaPS
|
||||
Dim Cantidad As Decimal = Dr("quantity").ToString.ToDecimal()
|
||||
For Each JsonPS As JObject In ListaPS
|
||||
Dim Cantidad As Decimal = JsonPS("quantity").ToString.ToDecimal()
|
||||
|
||||
Dim DrPS As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, Codigo:=Dr("product_sku").ToString()).FiltroPrimero("")
|
||||
Dim DrPS As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, Codigo:=JsonPS("product_sku").ToString()).FiltroPrimero("")
|
||||
|
||||
If DrPS Is Nothing Then
|
||||
Retorno.TieneError = True
|
||||
Retorno.Mensajes.Add(String.Format("No se pudo agregar el producto/servicio: {0}, no se encontró en el sistema", Dr("product_sku").ToString()))
|
||||
Retorno.Mensajes.Add(String.Format("No se pudo agregar el producto/servicio: {0}, no se encontró en el sistema", JsonPS("product_sku").ToString()))
|
||||
Exit For
|
||||
End If
|
||||
|
||||
'VALIDAR QUE SEA EL MISMO PRODUCTO
|
||||
If DrPS("Codigo").ToString() <> Dr("product_sku").ToString() Then
|
||||
If DrPS("Codigo").ToString() <> JsonPS("product_sku").ToString() Then
|
||||
Retorno.TieneError = True
|
||||
Retorno.Mensajes.Add(String.Format("No se pudo agregar el producto/servicio: {0}", Dr("PS").ToString()))
|
||||
Retorno.Mensajes.Add(String.Format("No se pudo agregar el producto/servicio: {0}", DrPS("PS").ToString()))
|
||||
Exit For
|
||||
End If
|
||||
|
||||
Dim TotalOriginal As Decimal = Dr("total_cost").ToString.ToDecimal()
|
||||
'VALIDA EXISTENCIA ANTES DE GENERAR LA FACTURA
|
||||
If ObjFactura.TipoDocto = "Ing" AndAlso DrPS("CveTipoPS").ToString() = "2" Then
|
||||
Dim Existencia As Decimal = ObjInventarios.GetExistenciasPS(DrPS("CvePS").ToString.ToEntero, DrPS("CveUnidadMedida").ToString.ToEntero, UsuarioActual.CveEmpresa, ObjFactura.CveAlmacen, CveSubProyecto:=ObjFactura.CveSubProyecto, FechaMovto:=DateTime.Today.AddDays(1).ToString("yyyy/MM/dd HH:mm"), ExcluyeAdelantado:=1, PendientePorSurtir:=1, RestringirAlmacenes:=1, ExcluyeApartados:=-1)
|
||||
|
||||
Dim PUOrginal As Decimal = Dr("cost").ToString.ToDecimal()
|
||||
If Cantidad > Existencia Then
|
||||
Retorno.TieneError = True
|
||||
Retorno.Mensajes.Add(String.Format("No hay existencia suficiente para este producto: {0}, cuenta con : {1}", DrPS("PSCodigo").ToString(), Existencia))
|
||||
Exit For
|
||||
End If
|
||||
End If
|
||||
|
||||
|
||||
Dim TotalOriginal As Decimal = JsonPS("total_cost").ToString.ToDecimal()
|
||||
|
||||
Dim PUOrginal As Decimal = JsonPS("cost").ToString.ToDecimal()
|
||||
|
||||
Dim PorcentajeIVADefault As Decimal = 0.16D
|
||||
|
||||
Dim DrSubProyecto As DataRow = GlobalDTSubProyectos(-1, JsonRequest("branch_office_id").ToEntero(), CveEmpresa:=CveEmpresa).Rows(0)
|
||||
|
||||
If DrSubProyecto IsNot Nothing Then
|
||||
PorcentajeIVADefault = DrSubProyecto("IVA").ToString().ToDecimal()
|
||||
Else
|
||||
PorcentajeIVADefault = 0.16D
|
||||
End If
|
||||
|
||||
Dim SubTotal2 As Decimal = (TotalOriginal / (1 + PorcentajeIVADefault))
|
||||
|
||||
Dim IVA As Decimal = Math.Abs(SubTotal2 - TotalOriginal)
|
||||
@@ -1227,12 +1296,12 @@ Public Class E141 : Implements IHttpHandler
|
||||
|
||||
Dim Row As DataRow = AgregarProductoServicio(Retorno, UsuarioActual, TmpDT, Consec, Cantidad, DrPS("CveUnidadMedida").ToString.ToEntero, DrPS("UnidadMedida").ToString, DrPS("CveClasificacion").ToString.ToEntero, DrPS("Clasificacion").ToString,
|
||||
DrPS("CvePS").ToString.ToEntero, DrPS("PS").ToString, "", PUCalculado, DescuentoPorPartida,
|
||||
CveSubProyecto:=JsonRequest("branch_office_id").ToEntero(), CveVentaDetalle:=-1, CveContratoDetalle:=-1, CveVentaDetalleRemision:=-1, RegeneraIEPS:=True)
|
||||
CveSubProyecto:=ObjFactura.CveSubProyecto, CveVentaDetalle:=-1, CveContratoDetalle:=-1, CveVentaDetalleRemision:=-1, RegeneraIEPS:=True)
|
||||
If Row IsNot Nothing Then
|
||||
TmpDT.Rows.Add(Row)
|
||||
Else
|
||||
Retorno.TieneError = True
|
||||
Retorno.Mensajes.Add(String.Format("No se pudo agregar el producto/servicio: {0}", Dr("PS").ToString()))
|
||||
Retorno.Mensajes.Add(String.Format("No se pudo agregar el producto/servicio: {0}", DrPS("PSCodigo").ToString()))
|
||||
Exit For
|
||||
End If
|
||||
|
||||
@@ -1408,9 +1477,10 @@ Public Class E141 : Implements IHttpHandler
|
||||
If Usuario IsNot Nothing Then
|
||||
Dim Resp As New Modelos.Factura.MMensajeFactura
|
||||
Dim ObjClientes As New ClsClientes()
|
||||
ObjClientes.IniciaTransacSQL()
|
||||
Dim ObjInventario As New ClsInventarios(ObjClientes.IniciaTransacSQL())
|
||||
|
||||
Try
|
||||
Dim ObjFactura = CreaFactura(ObjClientes, "Cot", Resp, JsonRequest, Usuario)
|
||||
Dim ObjFactura = CreaFactura(ObjInventario, ObjClientes, "Cot", Resp, JsonRequest, Usuario)
|
||||
|
||||
If ObjFactura IsNot Nothing Then
|
||||
Resp = ObjFactura.EmitirFactura(False, Transac:=ObjClientes.IniciaTransacSQL())
|
||||
@@ -1447,7 +1517,9 @@ Public Class E141 : Implements IHttpHandler
|
||||
Else
|
||||
ObjClientes.Commit()
|
||||
End If
|
||||
|
||||
ObjClientes.Dispose()
|
||||
ObjInventario.Dispose()
|
||||
Else
|
||||
TieneError = True
|
||||
RespuestaError.message = "no hay un usuario disponible"
|
||||
|
||||
Reference in New Issue
Block a user