diff --git a/App_Code/ClsCompras.vb b/App_Code/ClsCompras.vb index b06d1b586..c04c98792 100644 --- a/App_Code/ClsCompras.vb +++ b/App_Code/ClsCompras.vb @@ -199,7 +199,8 @@ Public Class ClsCompras Optional CveOC As Integer = -1, Optional CveCajaChica As Integer = -1, Optional CvePersonal As Integer = -1, Optional NumeroReembolso As String = "-1", Optional CveProveedorSucursal As Integer = -1, Optional AplicoPromocion As Boolean = False, Optional PorcentajeIVA As Decimal = 0, Optional CveMetodoPago As Integer = -1, Optional CveRetIVAConcepto As Integer = -1, Optional CveConceptoContableAlmacen As Integer = -1, Optional CveRetISRConcepto As Integer = -1, Optional NoDeducible As Integer = 0, Optional CveTipoCompra As Integer = -1, Optional TotalOriginal As Decimal = 0, Optional CveTipoConcepto As Integer = 1, Optional CveFactura As Integer = -1, - Optional CveContrato As Integer = -1, Optional EsImportacion As Boolean = False, Optional CveSubProyecto As Integer = -1, Optional DoctosRelacionados As String = "-1", Optional CveFolioGarantia As Integer = -1) As Boolean + Optional CveContrato As Integer = -1, Optional EsImportacion As Boolean = False, Optional CveSubProyecto As Integer = -1, Optional DoctosRelacionados As String = "-1", Optional CveFolioGarantia As Integer = -1, + Optional CveCompraRelacionada As Integer = -1) As Boolean Dim Retorno As Boolean = False @@ -255,6 +256,7 @@ Public Class ClsCompras .Add("@CveSubProyecto", SqlDbType.Int).Value = CveSubProyecto .Add("@DoctosRelacionados", SqlDbType.VarChar).Value = DoctosRelacionados .Add("@CveFolioGarantia", SqlDbType.Int).Value = CveFolioGarantia + .Add("@CveCompraRelacionada", SqlDbType.Int).Value = CveCompraRelacionada End With Try diff --git a/App_Code/Modelos.vb b/App_Code/Modelos.vb index 1b88ed2c4..419794e5b 100644 --- a/App_Code/Modelos.vb +++ b/App_Code/Modelos.vb @@ -1488,7 +1488,8 @@ Namespace Modelos Optional CveSubProyecto As Integer = -1, Optional SubProyecto As String = "", Optional PorcentajeIVA As Decimal = -1, Optional CuentaPredial As String = "", Optional CveVentaDetallePadre As Integer = -1, - Optional CveVentaDetalleRemision As Integer = -1, Optional CveViajePasajero As Integer = -1, Optional RedondearTotal As Boolean = True) As Boolean + Optional CveVentaDetalleRemision As Integer = -1, Optional CveViajePasajero As Integer = -1, Optional RedondearTotal As Boolean = True, + Optional CvePromocionDetalle As Integer = -1) As Boolean If Not CvePS > 0 Then Alert("Ocurrió un error al cargar la información del producto a agregar. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgError) @@ -1651,7 +1652,6 @@ Namespace Modelos Row("IEPS") = Row("ImporteIEPS") Row("Descuento") = (Descuento).RoundSQL(NumeroDecimales) Row("TipoDescuento") = -1 - Row("CvePromocionDetalle") = -1 If RedondearTotal Then Row("Total") = (Cantidad * PU).RoundSQL(NumeroDecimales) @@ -1678,6 +1678,7 @@ Namespace Modelos Row("CveVentaDetallePedido2") = -1 Row("CuentaPredial") = CuentaPredial Row("EsCargo") = 0 + Row("CvePromocionDetalle") = CvePromocionDetalle If Me.DtDetalle.Columns.Contains("CveMarca") Then Row("CveMarca") = DrPS("CveMarca") @@ -2258,7 +2259,7 @@ Namespace Modelos Row("PU").ToString.ToDecimal(If(factura.ConvertirPesos, factura.TipoCambio, 1)), Row("ImporteIVA").ToString.ToDecimal(If(factura.ConvertirPesos, factura.TipoCambio, 1)), Math.Round((Row("Total").ToString.ToDecimal(If(factura.ConvertirPesos, factura.TipoCambio, 1)) * (1 + Row("PorcentajeIVA").ToString.ToDecimal(If(factura.ConvertirPesos, factura.TipoCambio, 1)))), 6), Row("Obs").ToString, Row("Descuento").ToString.ToDecimal(If(factura.ConvertirPesos, factura.TipoCambio, 1)), Row("TipoDescuento").ToString.ToEntero, Row("CveSubProyecto").ToString.ToEntero, Row("CvePresupuestoIngreso").ToString.ToEntero, TiempoEntrega:=Row("TiempoEntrega").ToString, CveVentaDetallePadre:=Row("CveVentaDetalle").ToString.ToEntero, CveContratoDetalle:=Row("CveContratoDetalle").ToString.ToEntero, - CvePromocionDetalle:=If(DtPromociones IsNot Nothing, DtPromociones.FiltroPrimeroValor("CvePromocionDetalle", $"CvePS={Row("CvePS").ToString}").ToEntero, -1), + CvePromocionDetalle:=Row("CvePromocionDetalle").ToString.ToEntero, IEPS:=Row("ImporteIEPS").ToString.ToDecimal, CveMovimientoDetallePedido:=Row("CveMovimientoDetallePedido").ToString.ToEntero, ImporteRetIVA:=Row("ImporteRetIVA").ToString.ToDecimal, ImporteRetISR:=Row("ImporteRetISR").ToString.ToDecimal, PorcentajeIEPS:=Row("PorcentajeIEPS").ToString.ToDecimal, PorcentajeRetIVA:=Row("PorcentajeRetIVA").ToString.ToDouble, PorcentajeRetISR:=Row("PorcentajeRetISR").ToString.ToDecimal, CuentaPredial:=Row("CuentaPredial").ToString, diff --git a/Ashx/E141.ashx b/Ashx/E141.ashx index ca85d2adb..42d378a46 100644 --- a/Ashx/E141.ashx +++ b/Ashx/E141.ashx @@ -832,13 +832,13 @@ Public Class E141 : Implements IHttpHandler, System.Web.SessionState.IRequiresSe If ObjFactura.TipoDocto = "Cot" Then If ObjClientes.GetClientes(CveCliente, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa, -1, TipoCliente:=-1) Then If ObjClientes.DtResultados.Rows.Count > 0 Then - ObjFactura.CveFormaPago = ObjClientes.CveFormaPago33 - ObjFactura.FormaPago = ClsPaginas.GlobalDTVtaFormaPago.FiltroPrimeroValor("FormaPago", String.Format("CveFormaPago = {0}", ObjClientes.CveFormaPago33)) - ObjFactura.ClaveFormaPagoSAT = ClsPaginas.GlobalDTVtaFormaPago.FiltroPrimeroValor("ClaveFormaPagoSAT", String.Format("CveFormaPago = {0}", ObjClientes.CveFormaPago33)) + ObjFactura.CveFormaPago = ObjClientes.CveFormaPago + ObjFactura.FormaPago = ClsPaginas.GlobalDTVtaFormaPago.FiltroPrimeroValor("FormaPago", String.Format("CveFormaPago = {0}", ObjClientes.CveFormaPago)) + ObjFactura.ClaveFormaPagoSAT = ClsPaginas.GlobalDTVtaFormaPago.FiltroPrimeroValor("ClaveFormaPagoSAT", String.Format("CveFormaPago = {0}", ObjClientes.CveFormaPago)) - ObjFactura.CveMetodoPago = ObjClientes.CveMetodoPago33 - ObjFactura.MetodoPago = ClsPaginas.GlobalDTVtaMetodoPago.FiltroPrimeroValor("MetodoPago", String.Format("CveMetodoPago = {0}", ObjClientes.CveMetodoPago33)) - ObjFactura.ClaveMetodoPagoSAT = ClsPaginas.GlobalDTVtaMetodoPago.FiltroPrimeroValor("ClaveMetodoPagoSAT", String.Format("CveMetodoPago = {0}", ObjClientes.CveMetodoPago33)) + ObjFactura.CveMetodoPago = ObjClientes.CveMetodoPago + ObjFactura.MetodoPago = ClsPaginas.GlobalDTVtaMetodoPago.FiltroPrimeroValor("MetodoPago", String.Format("CveMetodoPago = {0}", ObjClientes.CveMetodoPago)) + ObjFactura.ClaveMetodoPagoSAT = ClsPaginas.GlobalDTVtaMetodoPago.FiltroPrimeroValor("ClaveMetodoPagoSAT", String.Format("CveMetodoPago = {0}", ObjClientes.CveMetodoPago)) ObjFactura.CveUsoCFDI = ObjClientes.CveUsoCFDI ObjFactura.UsoCFDI = ClsPaginas.GlobalDTSATUsosCFDI.FiltroPrimeroValor("Descripcion", String.Format("CveUsoCFDI = {0}", ObjClientes.CveUsoCFDI)) diff --git a/Ashx/E194.ashx b/Ashx/E194.ashx index d5604d293..ffceffa11 100644 --- a/Ashx/E194.ashx +++ b/Ashx/E194.ashx @@ -326,13 +326,13 @@ Public Class E194 : Implements IHttpHandler, System.Web.SessionState.IRequiresSe Dim ObjCliente As New ClsClientes If ObjCliente.GetClientes(CveCliente, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa, -1, TipoCliente:=-1) Then If ObjCliente.DtResultados.Rows.Count > 0 Then - ObjFactura.CveFormaPago = ObjCliente.CveFormaPago33 - ObjFactura.FormaPago = ClsPaginas.GlobalDTVtaFormaPago.FiltroPrimeroValor("FormaPago", String.Format("CveFormaPago = {0}", ObjCliente.CveFormaPago33)) - ObjFactura.ClaveFormaPagoSAT = ClsPaginas.GlobalDTVtaFormaPago.FiltroPrimeroValor("ClaveFormaPagoSAT", String.Format("CveFormaPago = {0}", ObjCliente.CveFormaPago33)) + ObjFactura.CveFormaPago = ObjCliente.CveFormaPago + ObjFactura.FormaPago = ClsPaginas.GlobalDTVtaFormaPago.FiltroPrimeroValor("FormaPago", String.Format("CveFormaPago = {0}", ObjCliente.CveFormaPago)) + ObjFactura.ClaveFormaPagoSAT = ClsPaginas.GlobalDTVtaFormaPago.FiltroPrimeroValor("ClaveFormaPagoSAT", String.Format("CveFormaPago = {0}", ObjCliente.CveFormaPago)) - ObjFactura.CveMetodoPago = ObjCliente.CveMetodoPago33 - ObjFactura.MetodoPago = ClsPaginas.GlobalDTVtaMetodoPago.FiltroPrimeroValor("MetodoPago", String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago33)) - ObjFactura.ClaveMetodoPagoSAT = ClsPaginas.GlobalDTVtaMetodoPago.FiltroPrimeroValor("ClaveMetodoPagoSAT", String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago33)) + ObjFactura.CveMetodoPago = ObjCliente.CveMetodoPago + ObjFactura.MetodoPago = ClsPaginas.GlobalDTVtaMetodoPago.FiltroPrimeroValor("MetodoPago", String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago)) + ObjFactura.ClaveMetodoPagoSAT = ClsPaginas.GlobalDTVtaMetodoPago.FiltroPrimeroValor("ClaveMetodoPagoSAT", String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago)) ObjFactura.CveUsoCFDI = ObjCliente.CveUsoCFDI ObjFactura.UsoCFDI = ClsPaginas.GlobalDTSATUsosCFDI.FiltroPrimeroValor("Descripcion", String.Format("CveUsoCFDI = {0}", ObjCliente.CveUsoCFDI)) diff --git a/Ashx/SIGFacturacion.ashx b/Ashx/SIGFacturacion.ashx index baabe5df8..f13ce480c 100644 --- a/Ashx/SIGFacturacion.ashx +++ b/Ashx/SIGFacturacion.ashx @@ -314,13 +314,13 @@ Public Class SIGFacturacion : Implements IHttpHandler, IRequiresSessionState Dim ObjCliente As New ClsClientes If ObjCliente.GetClientes(CveCliente, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa, -1, TipoCliente:=-1) Then If ObjCliente.DtResultados.Rows.Count > 0 Then - ObjFactura.CveFormaPago = ObjCliente.CveFormaPago33 - ObjFactura.FormaPago = ClsPaginas.GlobalDTVtaFormaPago.FiltroPrimeroValor("FormaPago", String.Format("CveFormaPago = {0}", ObjCliente.CveFormaPago33)) - ObjFactura.ClaveFormaPagoSAT = ClsPaginas.GlobalDTVtaFormaPago.FiltroPrimeroValor("ClaveFormaPagoSAT", String.Format("CveFormaPago = {0}", ObjCliente.CveFormaPago33)) + ObjFactura.CveFormaPago = ObjCliente.CveFormaPago + ObjFactura.FormaPago = ClsPaginas.GlobalDTVtaFormaPago.FiltroPrimeroValor("FormaPago", String.Format("CveFormaPago = {0}", ObjCliente.CveFormaPago)) + ObjFactura.ClaveFormaPagoSAT = ClsPaginas.GlobalDTVtaFormaPago.FiltroPrimeroValor("ClaveFormaPagoSAT", String.Format("CveFormaPago = {0}", ObjCliente.CveFormaPago)) - ObjFactura.CveMetodoPago = ObjCliente.CveMetodoPago33 - ObjFactura.MetodoPago = ClsPaginas.GlobalDTVtaMetodoPago.FiltroPrimeroValor("MetodoPago", String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago33)) - ObjFactura.ClaveMetodoPagoSAT = ClsPaginas.GlobalDTVtaMetodoPago.FiltroPrimeroValor("ClaveMetodoPagoSAT", String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago33)) + ObjFactura.CveMetodoPago = ObjCliente.CveMetodoPago + ObjFactura.MetodoPago = ClsPaginas.GlobalDTVtaMetodoPago.FiltroPrimeroValor("MetodoPago", String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago)) + ObjFactura.ClaveMetodoPagoSAT = ClsPaginas.GlobalDTVtaMetodoPago.FiltroPrimeroValor("ClaveMetodoPagoSAT", String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago)) ObjFactura.CveUsoCFDI = ObjCliente.CveUsoCFDI ObjFactura.UsoCFDI = ClsPaginas.GlobalDTSATUsosCFDI.FiltroPrimeroValor("Descripcion", String.Format("CveUsoCFDI = {0}", ObjCliente.CveUsoCFDI)) diff --git a/Bancos/IE.aspx b/Bancos/IE.aspx index 37fce5bfc..12275d7f1 100644 --- a/Bancos/IE.aspx +++ b/Bancos/IE.aspx @@ -26,9 +26,7 @@ -
  • - Póliza -
  • +
  • @@ -62,7 +60,12 @@
  • Envíar Comprobante Mail
  • - +
  • + Ver Póliza +
  • +
  • + Imprimir Póliza +
  • diff --git a/Bancos/IE.aspx.vb b/Bancos/IE.aspx.vb index b419b6dd1..8cec942a6 100644 --- a/Bancos/IE.aspx.vb +++ b/Bancos/IE.aspx.vb @@ -863,6 +863,8 @@ Partial Class Bancos_IE ViewState("CvePrePoliza") = ObjIE.DtResultados.Rows(0)("CvePrePoliza").ToString.ToEntero HpLPrePoliza.NavigateUrl = String.Format("/Contabilidad/RegPrePolizas.aspx?CvePrePoliza={0}", ViewState("CvePrePoliza")) HpLPrePoliza.Visible = True + LnkDescargaPoliza.Visible = True + LnkDescargaPoliza.NavigateUrl = $"/Compras/PopUpVerFactura.aspx?P={Encripta(String.Format("OP=PREPO&CvePrePoliza={0}", ViewState("CvePrePoliza")))}" TxtFechaDocumento.Text = ObjIE.FechaDocumento.ToShortDateString TxtFolio.Text = ObjIE.Folio LblBeneficiario.Text = ObjIE.PagueseA diff --git a/Bancos/PagoAcreedor.aspx b/Bancos/PagoAcreedor.aspx index eeca92ae5..bf3356817 100644 --- a/Bancos/PagoAcreedor.aspx +++ b/Bancos/PagoAcreedor.aspx @@ -28,7 +28,8 @@
    - + @@ -71,6 +72,12 @@ + + + +
    @@ -155,7 +162,8 @@
    - + @@ -201,6 +209,12 @@ + + + +
    diff --git a/Bancos/PagoAcreedor.aspx.cs b/Bancos/PagoAcreedor.aspx.cs index 2605d9662..9643bbd97 100644 --- a/Bancos/PagoAcreedor.aspx.cs +++ b/Bancos/PagoAcreedor.aspx.cs @@ -12,7 +12,7 @@ public partial class Bancos_PagoAcreedor : ClsPaginas { #region "PROPIEDADES" - + private int CveMonedaCuentaPago { get @@ -36,7 +36,7 @@ public partial class Bancos_PagoAcreedor : ClsPaginas protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) - { + { CveMonedaCuentaPago = 0; rowComisiones.Visible = true; @@ -53,18 +53,21 @@ public partial class Bancos_PagoAcreedor : ClsPaginas CargarCentrosDeCosto(null, null, null, LblSubProyecto); LblSubProyecto2.Text = LblSubProyecto.Text; + ValidaFechaDocumentoDiasPosterioresPrestamo(); + ValidaFechaDocumentoDiasPosteriores(); + } } private void CargaSubproyectos() { - DdlSubProyecto.DataSource = get_GlobalDTSubProyectos( UsuarioActual.CveEmpresa); + DdlSubProyecto.DataSource = get_GlobalDTSubProyectos(UsuarioActual.CveEmpresa); DdlSubProyecto.DataBind(); DdlSubProyecto.Items.Insert(0, new ListItem("Seleccione", "-1")); - DdlSubProyectoPago.DataSource = get_GlobalDTSubProyectos( UsuarioActual.CveEmpresa); + DdlSubProyectoPago.DataSource = get_GlobalDTSubProyectos(UsuarioActual.CveEmpresa); DdlSubProyectoPago.DataBind(); DdlSubProyectoPago.Items.Insert(0, new ListItem("Seleccione", "-1")); @@ -116,7 +119,7 @@ public partial class Bancos_PagoAcreedor : ClsPaginas CveMonedaCuentaPago = 0; if (dr != null) { - CveMonedaCuentaPago = dr["CveMoneda"].ToString().ToEntero(); + CveMonedaCuentaPago = dr["CveMoneda"].ToString().ToEntero(); } if (CveMonedaCuentaPago != 1) @@ -144,8 +147,8 @@ public partial class Bancos_PagoAcreedor : ClsPaginas bancos.Dispose(); TxtFolio.Text = Folio.ToString(); - - TxtDDImporte.Attributes.Add("onblur",$"validaDeudoresDiversos({CveMonedaCuentaPago});FormatoMoneda(this);"); + + TxtDDImporte.Attributes.Add("onblur", $"validaDeudoresDiversos({CveMonedaCuentaPago});FormatoMoneda(this);"); UpDatos.Update(); } @@ -231,7 +234,7 @@ public partial class Bancos_PagoAcreedor : ClsPaginas { decimal ImporteBanco = TxtImporte.Text.ToDecimal(); decimal ImporteMNBanco = ImporteBanco; - decimal ImporteComplementaria = 0; + decimal ImporteComplementaria = 0; decimal TCPago = TxtTCPago.Text.ToDecimal(); string Conc = TxtObservaciones.Text == "" ? TxtFolio.Text : TxtObservaciones.Text; string Ref = TxtObservaciones.Text == "" ? TxtFolio.Text : TxtObservaciones.Text; @@ -243,14 +246,14 @@ public partial class Bancos_PagoAcreedor : ClsPaginas if (CveIE > 0) { - + decimal Importe; decimal ImporteMN; decimal ImporteComision; decimal ImporteComisionMN; decimal AcumImporteMN = 0; decimal ImporteBancosMN, ImporteAcreedorMN; - bool TipoMovtoComision = false; + bool TipoMovtoComision = false; int CveConceptoDiferenciaCambiaria = 0; //GUARDA PREPOLIZAS DETALLE @@ -262,7 +265,7 @@ public partial class Bancos_PagoAcreedor : ClsPaginas ImporteAcreedorMN = Importe; ImporteBancosMN = Importe; ImporteComisionMN = ImporteComision; - ImporteComplementaria = 0; + ImporteComplementaria = 0; if (gvr.FCTextBox("TxtComision").Text.ToDecimal() < 0) { @@ -273,7 +276,7 @@ public partial class Bancos_PagoAcreedor : ClsPaginas else { TipoMovtoComision = false; - } + } if (gvr.FCCheckBox("Chk").Checked) { @@ -308,7 +311,7 @@ public partial class Bancos_PagoAcreedor : ClsPaginas } else if (CveMonedaPago == 2 && tCveMoneda == 2) { - + //ImporteComisionMN = ImporteComision; //ImporteMN = Importe; //ImporteComplementaria = (Importe * TC - Importe).RoundSQL(); @@ -318,48 +321,48 @@ public partial class Bancos_PagoAcreedor : ClsPaginas //ImporteComplementaria = ImporteComplementaria.RoundSQL(); ImporteComisionMN = ImporteComisionMN.RoundSQL(); ImporteComision = ImporteComision.RoundSQL(); - AcumImporteMN += ImporteMN; - - if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, false, Importe, ImporteMN, CveConceptoContablePago, Ref, Conc, CveIE: CveIE, CveProveedor: DdlProveedores.SelectedValue.ToEntero(), CveIEDevolucion: gvr.DataKey("CveIE").ToEntero(), TipoCambio: TC, TipoCambioPago: TCPago, CveSubProyecto: DdlSubProyectoPago.SelectedValue.ToEntero())) + AcumImporteMN += ImporteMN; + + if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, false, Importe, ImporteMN, CveConceptoContablePago, Ref, Conc, CveIE: CveIE, CveProveedor: DdlProveedores.SelectedValue.ToEntero(), CveIEDevolucion: gvr.DataKey("CveIE").ToEntero(), TipoCambio: TC, TipoCambioPago: TCPago, CveSubProyecto: DdlSubProyectoPago.SelectedValue.ToEntero())) { MsgError = "No se pudo insertar concepto de pago acreedor"; break; - } - + } + if (tCveMoneda > 1 && MsgError == "") { ImporteComplementaria = (Importe * TC - Importe).RoundSQL(); - if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, false, Importe, ImporteComplementaria, CveConceptoContablePrestamoComplementario, Ref, Conc, CveIE: CveIE, CveProveedor: DdlProveedores.SelectedValue.ToEntero(), CveIEDevolucion: gvr.DataKey("CveIE").ToEntero(), ImporteME: Importe, TipoCambio: TC, TipoCambioPago: TCPago, CveSubProyecto: DdlSubProyecto.SelectedValue.ToEntero())) + if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, false, Importe, ImporteComplementaria, CveConceptoContablePrestamoComplementario, Ref, Conc, CveIE: CveIE, CveProveedor: DdlProveedores.SelectedValue.ToEntero(), CveIEDevolucion: gvr.DataKey("CveIE").ToEntero(), ImporteME: Importe, TipoCambio: TC, TipoCambioPago: TCPago, CveSubProyecto: DdlSubProyecto.SelectedValue.ToEntero())) MsgError = "No se pudo insertar concepto de acreedor complementaria"; } - if (ImporteBancosMN != ImporteAcreedorMN && MsgError == "") - { - bool TipoMovto = false; + if (ImporteBancosMN != ImporteAcreedorMN && MsgError == "") + { + bool TipoMovto = false; if (TCPago > TC) { CveConceptoDiferenciaCambiaria = 65; - TipoMovto = false; + TipoMovto = false; } else if (TCPago < TC) { CveConceptoDiferenciaCambiaria = 64; TipoMovto = true; } - Importe = ((Importe * TCPago) - (Importe * TC)).Abs(); + Importe = ((Importe * TCPago) - (Importe * TC)).Abs(); - if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovto, Importe, Importe, CveConceptoDiferenciaCambiaria, Ref, Conc, CveIE: CveIE, CveProveedor: DdlProveedores.SelectedValue.ToEntero(), ImporteME: Importe, CveIEDevolucion: gvr.DataKey("CveIE").ToEntero(), TipoCambio: TC, TipoCambioPago: TCPago, CveSubProyecto: DdlSubProyectoPago.SelectedValue.ToEntero())) + if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovto, Importe, Importe, CveConceptoDiferenciaCambiaria, Ref, Conc, CveIE: CveIE, CveProveedor: DdlProveedores.SelectedValue.ToEntero(), ImporteME: Importe, CveIEDevolucion: gvr.DataKey("CveIE").ToEntero(), TipoCambio: TC, TipoCambioPago: TCPago, CveSubProyecto: DdlSubProyectoPago.SelectedValue.ToEntero())) MsgError = "No se pudo insertar concepto de diferencia cambiaria"; } - - if (ImporteComision != 0 && MsgError == "" && DdlOtrosPagos.SelectedValue == "2" ) + + if (ImporteComision != 0 && MsgError == "" && DdlOtrosPagos.SelectedValue == "2") { - + ImporteComisionMN = (ImporteComision * TCPago).RoundSQL(); int tTipoConceptoOtro = 255; //if (DdlOtrosPagos.SelectedValue == "3") tTipoConceptoOtro = 43; //deudores diversos - if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovtoComision, ImporteComision, ImporteComisionMN, tTipoConceptoOtro, Ref, Conc, CveIE: CveIE, CveProveedor: DdlProveedores.SelectedValue.ToEntero(),CveIEDevolucion: gvr.DataKey("CveIE").ToEntero(), TipoCambio: TC, TipoCambioPago: TCPago, CveSubProyecto: DdlSubProyectoPago.SelectedValue.ToEntero())) + if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovtoComision, ImporteComision, ImporteComisionMN, tTipoConceptoOtro, Ref, Conc, CveIE: CveIE, CveProveedor: DdlProveedores.SelectedValue.ToEntero(), CveIEDevolucion: gvr.DataKey("CveIE").ToEntero(), TipoCambio: TC, TipoCambioPago: TCPago, CveSubProyecto: DdlSubProyectoPago.SelectedValue.ToEntero())) { MsgError = "No se pudo insertar concepto de pago acreedor"; break; @@ -389,30 +392,30 @@ public partial class Bancos_PagoAcreedor : ClsPaginas //CveMonedaPago ImporteComision = ImporteComision.RoundSQL(); - ImporteComisionMN = (ImporteComision * TCPago).RoundSQL() ; + ImporteComisionMN = (ImporteComision * TCPago).RoundSQL(); ImporteComisionMN = (ImporteComision * TCPago).RoundSQL(); - + int tTipoConceptoOtro = 43; //deudores diversos if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovtoComision, ImporteComision, ImporteComisionMN, tTipoConceptoOtro, Ref, Conc, CveIE: CveIE, CveProveedor: DdlProveedores.SelectedValue.ToEntero(), TipoCambio: TCPago, TipoCambioPago: TCPago, CveSubProyecto: DdlSubProyectoPago.SelectedValue.ToEntero())) { - MsgError = "No se pudo insertar concepto de pago acreedor"; + MsgError = "No se pudo insertar concepto de pago acreedor"; } } if (CveMonedaPago != 1) - { - ImporteComplementaria = (ImporteBanco * TCPago - ImporteBanco).RoundSQL(); + { + ImporteComplementaria = (ImporteBanco * TCPago - ImporteBanco).RoundSQL(); } - if (MsgError == "" && !ObjMov.AddPrePolizasDetalle(CvePrePoliza, true, ImporteBanco, ImporteBanco, 30, Ref, Conc, CveIE: CveIE, CveProveedor: DdlProveedores.SelectedValue.ToEntero(),ImporteME: ImporteBanco, TipoCambio: TCPago, TipoCambioPago: TCPago, CveSubProyecto: DdlSubProyectoPago.SelectedValue.ToEntero())) MsgError = "No se pudo insertar concepto de bancos"; - + if (MsgError == "" && !ObjMov.AddPrePolizasDetalle(CvePrePoliza, true, ImporteBanco, ImporteBanco, 30, Ref, Conc, CveIE: CveIE, CveProveedor: DdlProveedores.SelectedValue.ToEntero(), ImporteME: ImporteBanco, TipoCambio: TCPago, TipoCambioPago: TCPago, CveSubProyecto: DdlSubProyectoPago.SelectedValue.ToEntero())) MsgError = "No se pudo insertar concepto de bancos"; + //movimiento de ajuste por sino se aplicó en el proceso anterior - if (MsgError == "" && CveMonedaPago != 1 ) + if (MsgError == "" && CveMonedaPago != 1) { - if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, true, ImporteBanco, ImporteComplementaria, 204, Ref, Conc, CveIE: CveIE, CveProveedor: DdlProveedores.SelectedValue.ToEntero(), ImporteME: ImporteBanco, TipoCambio: TCPago, TipoCambioPago: TCPago, CveSubProyecto: DdlSubProyectoPago.SelectedValue.ToEntero())) MsgError = "No se pudo insertar concepto de bancos complementaria"; - } + if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, true, ImporteBanco, ImporteComplementaria, 204, Ref, Conc, CveIE: CveIE, CveProveedor: DdlProveedores.SelectedValue.ToEntero(), ImporteME: ImporteBanco, TipoCambio: TCPago, TipoCambioPago: TCPago, CveSubProyecto: DdlSubProyectoPago.SelectedValue.ToEntero())) MsgError = "No se pudo insertar concepto de bancos complementaria"; + } } else @@ -426,15 +429,15 @@ public partial class Bancos_PagoAcreedor : ClsPaginas } //VALIDA QUE CUADRE LA PREPOLIZA - Usuario UA = UsuarioActual; - if (MsgError == "" && ObjMov.ValidacionesPrePoliza(CvePrePoliza, ref UA,Opcion:5)) + Usuario UA = UsuarioActual; + if (MsgError == "" && ObjMov.ValidacionesPrePoliza(CvePrePoliza, ref UA, Opcion: 5)) { if (ObjMov.ValorPolizaDescuadre > 0) { MsgError = ObjMov.MensajePolizaDescuadre; ModExtensiones.GuardaLogAD($"Bancos/IE PAGO ACREEDOR | Error:{ObjMov.MensajePolizaDescuadre} Diferencia:{ObjMov.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas"); } - } + } if (MsgError.Equals("")) { @@ -445,10 +448,10 @@ public partial class Bancos_PagoAcreedor : ClsPaginas } //GUARDA COMPROBANTE - if (!filemove.Equals("")) - { - filemove.FilesMove(CveIE.ToString(), string.Format(@"{0}IE", UsuarioActual.Empresa.Ruta), ConcatenarDirectorioBase: false); - } + if (!filemove.Equals("")) + { + filemove.FilesMove(CveIE.ToString(), string.Format(@"{0}IE", UsuarioActual.Empresa.Ruta), ConcatenarDirectorioBase: false); + } System.IO.FileInfo archivo = null; if (DdlTipoTransaccion.SelectedValue.ToEntero().Contiene(2, 8, 9)) @@ -481,10 +484,10 @@ public partial class Bancos_PagoAcreedor : ClsPaginas //{ // Msg.AppendFormat(@"

    Ver Póliza", IDPoliza); //} - + Msg.AppendFormat(@"Ver Póliza
    ", CvePrePoliza); Msg.AppendFormat($"Imprimir"); - + } else { @@ -542,8 +545,8 @@ public partial class Bancos_PagoAcreedor : ClsPaginas } private void AsignaCuentaProveedor(int CveProveedor) - { - + { + } protected void BtnGuardarPrestamo_Click(object sender, EventArgs e) @@ -597,8 +600,8 @@ public partial class Bancos_PagoAcreedor : ClsPaginas if (CveMoneda != 1) { - ImporteMN = Importe; - ImporteComplementaria = Importe * TC - Importe; + ImporteMN = Importe; + ImporteComplementaria = Importe * TC - Importe; } @@ -611,7 +614,7 @@ public partial class Bancos_PagoAcreedor : ClsPaginas filemove.FilesMove(CveIE.ToString(), string.Format(@"{0}IE", UsuarioActual.Empresa.Ruta), ConcatenarDirectorioBase: false); } - if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, false, Importe, ImporteMN,CveConceptoContableBanco, Ref, Conc, CveIE: CveIE, CveProveedor: DdlProveedorPrestamo.SelectedValue.ToEntero(), TipoCambio: TC, TipoCambioPago: TC, CveSubProyecto: DdlSubProyecto.SelectedValue.ToEntero())) + if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, false, Importe, ImporteMN, CveConceptoContableBanco, Ref, Conc, CveIE: CveIE, CveProveedor: DdlProveedorPrestamo.SelectedValue.ToEntero(), TipoCambio: TC, TipoCambioPago: TC, CveSubProyecto: DdlSubProyecto.SelectedValue.ToEntero())) { MsgError = "No se pudo insertar concepto de bancos"; } @@ -619,23 +622,23 @@ public partial class Bancos_PagoAcreedor : ClsPaginas if (CveMoneda != 1) { - if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, true, Importe, ImporteMN, CveConceptoContablePrestamo, Ref, Conc, CveIE: CveIE, CveProveedor: DdlProveedorPrestamo.SelectedValue.ToEntero(), TipoCambio: TC, TipoCambioPago: TC, CveSubProyecto: DdlSubProyecto.SelectedValue.ToEntero())) + if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, true, Importe, ImporteMN, CveConceptoContablePrestamo, Ref, Conc, CveIE: CveIE, CveProveedor: DdlProveedorPrestamo.SelectedValue.ToEntero(), TipoCambio: TC, TipoCambioPago: TC, CveSubProyecto: DdlSubProyecto.SelectedValue.ToEntero())) { MsgError = "No se pudo insertar concepto de acreedor"; - } - if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, false, Importe, ImporteComplementaria, CveConceptoContableBancoComplementario, Ref, Conc, CveIE: CveIE, CveProveedor: DdlProveedorPrestamo.SelectedValue.ToEntero(), ImporteME: Importe, TipoCambio: TC, TipoCambioPago: TC, CveSubProyecto: DdlSubProyecto.SelectedValue.ToEntero())) + } + if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, false, Importe, ImporteComplementaria, CveConceptoContableBancoComplementario, Ref, Conc, CveIE: CveIE, CveProveedor: DdlProveedorPrestamo.SelectedValue.ToEntero(), ImporteME: Importe, TipoCambio: TC, TipoCambioPago: TC, CveSubProyecto: DdlSubProyecto.SelectedValue.ToEntero())) { MsgError = "No se pudo insertar concepto de bancos complementaria"; } - if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, true, Importe, ImporteComplementaria, CveConceptoContablePrestamoComplementario, Ref, Conc, CveIE: CveIE, CveProveedor: DdlProveedorPrestamo.SelectedValue.ToEntero(), ImporteME: Importe, TipoCambio: TC, TipoCambioPago: TC, CveSubProyecto: DdlSubProyecto.SelectedValue.ToEntero())) + if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, true, Importe, ImporteComplementaria, CveConceptoContablePrestamoComplementario, Ref, Conc, CveIE: CveIE, CveProveedor: DdlProveedorPrestamo.SelectedValue.ToEntero(), ImporteME: Importe, TipoCambio: TC, TipoCambioPago: TC, CveSubProyecto: DdlSubProyecto.SelectedValue.ToEntero())) { MsgError = "No se pudo insertar concepto de acreedor complementaria"; } - + } else { - if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, true, Importe, ImporteMN, CveConceptoContablePrestamo, Ref, Conc, CveIE: CveIE, CveProveedor: DdlProveedorPrestamo.SelectedValue.ToEntero(), TipoCambio: TC, TipoCambioPago: TC, CveSubProyecto: DdlSubProyecto.SelectedValue.ToEntero())) + if (!ObjMov.AddPrePolizasDetalle(CvePrePoliza, true, Importe, ImporteMN, CveConceptoContablePrestamo, Ref, Conc, CveIE: CveIE, CveProveedor: DdlProveedorPrestamo.SelectedValue.ToEntero(), TipoCambio: TC, TipoCambioPago: TC, CveSubProyecto: DdlSubProyecto.SelectedValue.ToEntero())) { MsgError = "No se pudo insertar concepto de acreedor"; } @@ -653,14 +656,14 @@ public partial class Bancos_PagoAcreedor : ClsPaginas //VALIDA QUE CUADRE LA POLIZA Usuario UA = UsuarioActual; - if (MsgError == "" && ObjMov.ValidacionesPrePoliza(CvePrePoliza, ref UA, Opcion: 5)) + if (MsgError == "" && ObjMov.ValidacionesPrePoliza(CvePrePoliza, ref UA, Opcion: 5)) { if (ObjMov.ValorPolizaDescuadre > 0) { MsgError = ObjMov.MensajePolizaDescuadre; ModExtensiones.GuardaLogAD($"Bancos/IE PAGO ACREEDOR | Error:{ObjMov.MensajePolizaDescuadre} Diferencia:{ObjMov.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas"); } - } + } if (MsgError.Equals("")) { @@ -808,7 +811,7 @@ public partial class Bancos_PagoAcreedor : ClsPaginas divDD.Visible = false; if (DdlOtrosPagos.SelectedValue == "2") { - TxtOtrosImportes.Visible = true; + TxtOtrosImportes.Visible = true; TxtTotal.Visible = true; GvMovAcreedor.Columns[8].Visible = true; TxtOtrosImportes.Text = ""; @@ -818,14 +821,14 @@ public partial class Bancos_PagoAcreedor : ClsPaginas else { if (DdlOtrosPagos.SelectedValue == "3") - { + { TxtDDImporte.Text = ""; divDD.Visible = true; RegistraScript($"$get('TxtImporte').value = FormatoNumero(SumaValores({CveMonedaCuentaPago}), 2);"); - } + } TxtOtrosImportes.Visible = false; TxtTotal.Visible = false; - GvMovAcreedor.Columns[8].Visible = false; + GvMovAcreedor.Columns[8].Visible = false; } UpDatos.Update(); UpMovAcreedor.Update(); @@ -835,4 +838,93 @@ public partial class Bancos_PagoAcreedor : ClsPaginas { CargaReporte(); } + + + + + protected void DdlTipoTransaccion_SelectedIndexChanged(object sender, EventArgs e) + { + ValidaFechaDocumentoDiasPosteriores(); + } + + protected void RVTxtFechaDocumento_Init(object sender, EventArgs e) + { + RVTxtFechaDocumento.MaximumValue = NowADS().AddDays(2).ToShortDateString(); + RVTxtFechaDocumento.MinimumValue = NowADS().AddMonths(-38).ToShortDateString(); + Calendario.EndDate = NowADS().AddDays(2); + } + + private void ValidaFechaDocumentoDiasPosteriores() + { + RVTxtFechaDocumento.MaximumValue = NowADS().AddDays(3).ToShortDateString(); + RVTxtFechaDocumento.ErrorMessage = "ERROR:
    La fecha del documento no puede ser superior a 3 días de la fecha actual"; + + Calendario.EndDate = NowADS().AddDays(3); + + // Equivalente a: If DdlTipoMovto.SelectedValue.Contiene("1", "16") Then + // Suponiendo que "Contiene" verifique si SelectedValue es "1" o "16" + if (DdlTipoTransaccion.SelectedValue == "1" || DdlTipoTransaccion.SelectedValue == "16") + { + // cheques, 3 meses + RVTxtFechaDocumento.MaximumValue = NowADS().AddMonths(3).ToShortDateString(); + RVTxtFechaDocumento.ErrorMessage = "ERROR:
    La fecha del documento no puede ser superior a 3 meses de la fecha actual"; + Calendario.EndDate = NowADS().AddMonths(3); + } + + // transfer, 3 semanas + if (DdlTipoTransaccion.SelectedValue == "2") + { + RVTxtFechaDocumento.MaximumValue = NowADS().AddDays(21).ToShortDateString(); + RVTxtFechaDocumento.ErrorMessage = "ERROR:
    La fecha del documento no puede ser superior a 3 semanas de la fecha actual"; + Calendario.EndDate = NowADS().AddDays(21); + } + + UpDatos.Update(); + //UpGuardar.Update(); + } + + + + + protected void DdlTipoTransanccionPrestamo_SelectedIndexChanged(object sender, EventArgs e) + { + ValidaFechaDocumentoDiasPosterioresPrestamo(); + } + protected void RVTxtFechaPrestamo_Init(object sender, EventArgs e) + { + RVTxtFechaPrestamo.MaximumValue = NowADS().AddDays(2).ToShortDateString(); + RVTxtFechaPrestamo.MinimumValue = NowADS().AddMonths(-38).ToShortDateString(); + CalendarioPrestamo.EndDate = NowADS().AddDays(2); + + } + + private void ValidaFechaDocumentoDiasPosterioresPrestamo() + { + RVTxtFechaPrestamo.MaximumValue = NowADS().AddDays(3).ToShortDateString(); + RVTxtFechaPrestamo.ErrorMessage = "ERROR:
    La fecha del documento no puede ser superior a 3 días de la fecha actual"; + + CalendarioPrestamo.EndDate = NowADS().AddDays(3); + + // Equivalente a: If DdlTipoMovto.SelectedValue.Contiene("1", "16") Then + // Suponiendo que "Contiene" verifique si SelectedValue es "1" o "16" + if (DdlTipoTransanccionPrestamo.SelectedValue == "1" || DdlTipoTransanccionPrestamo.SelectedValue == "16") + { + // cheques, 3 meses + RVTxtFechaPrestamo.MaximumValue = NowADS().AddMonths(3).ToShortDateString(); + RVTxtFechaPrestamo.ErrorMessage = "ERROR:
    La fecha del documento no puede ser superior a 3 meses de la fecha actual"; + CalendarioPrestamo.EndDate = NowADS().AddMonths(3); + } + + // transfer, 3 semanas + if (DdlTipoTransanccionPrestamo.SelectedValue == "2") + { + RVTxtFechaPrestamo.MaximumValue = NowADS().AddDays(21).ToShortDateString(); + RVTxtFechaPrestamo.ErrorMessage = "ERROR:
    La fecha del documento no puede ser superior a 3 semanas de la fecha actual"; + CalendarioPrestamo.EndDate = NowADS().AddDays(21); + } + + UpPrestamo.Update(); + + } + } diff --git a/Bancos/PagoDeudor.aspx b/Bancos/PagoDeudor.aspx index 09e008c7e..09be4eddd 100644 --- a/Bancos/PagoDeudor.aspx +++ b/Bancos/PagoDeudor.aspx @@ -42,7 +42,8 @@
    - + @@ -95,6 +96,12 @@ + + + +
    @@ -209,7 +216,8 @@
    - + @@ -263,6 +271,12 @@ + + + +
    diff --git a/Bancos/PagoDeudor.aspx.cs b/Bancos/PagoDeudor.aspx.cs index e2af4114e..10ebf8179 100644 --- a/Bancos/PagoDeudor.aspx.cs +++ b/Bancos/PagoDeudor.aspx.cs @@ -56,6 +56,9 @@ public partial class Bancos_PagoDeudor : ClsPaginas TxtImporte.Attributes.Add("disabled", "disabled"); CargarCentrosDeCosto(null, null, null, LblSubProyecto); LblSubProyecto2.Text = LblSubProyecto.Text; + + ValidaFechaDocumentoDiasPosterioresPrestamo(); + ValidaFechaDocumentoDiasPosteriores(); } } @@ -372,6 +375,48 @@ public partial class Bancos_PagoDeudor : ClsPaginas if (ObjComp != null) ObjComp.Dispose(); } + + protected void DdlTipoTransaccionPrestamo_SelectedIndexChanged(object sender, EventArgs e) + { + ValidaFechaDocumentoDiasPosterioresPrestamo(); + } + protected void RVTxtFechaPrestamo_Init(object sender, EventArgs e) + { + RVTxtFechaPrestamo.MaximumValue = NowADS().AddDays(2).ToShortDateString(); + RVTxtFechaPrestamo.MinimumValue = NowADS().AddMonths(-38).ToShortDateString(); + CalendarioPrestamo.EndDate = NowADS().AddDays(2); + + } + + private void ValidaFechaDocumentoDiasPosterioresPrestamo() + { + RVTxtFechaPrestamo.MaximumValue = NowADS().AddDays(3).ToShortDateString(); + RVTxtFechaPrestamo.ErrorMessage = "ERROR:
    La fecha del documento no puede ser superior a 3 días de la fecha actual"; + + CalendarioPrestamo.EndDate = NowADS().AddDays(3); + + // Equivalente a: If DdlTipoMovto.SelectedValue.Contiene("1", "16") Then + // Suponiendo que "Contiene" verifique si SelectedValue es "1" o "16" + if (DdlTipoTransaccionPrestamo.SelectedValue == "1" || DdlTipoTransaccionPrestamo.SelectedValue == "16") + { + // cheques, 3 meses + RVTxtFechaPrestamo.MaximumValue = NowADS().AddMonths(3).ToShortDateString(); + RVTxtFechaPrestamo.ErrorMessage = "ERROR:
    La fecha del documento no puede ser superior a 3 meses de la fecha actual"; + CalendarioPrestamo.EndDate = NowADS().AddMonths(3); + } + + // transfer, 3 semanas + if (DdlTipoTransaccionPrestamo.SelectedValue == "2") + { + RVTxtFechaPrestamo.MaximumValue = NowADS().AddDays(21).ToShortDateString(); + RVTxtFechaPrestamo.ErrorMessage = "ERROR:
    La fecha del documento no puede ser superior a 3 semanas de la fecha actual"; + CalendarioPrestamo.EndDate = NowADS().AddDays(21); + } + + UpPrestamo.Update(); + //UpGuardar.Update(); + } + #endregion #region "PAGO DEUDORES" @@ -830,4 +875,52 @@ public partial class Bancos_PagoDeudor : ClsPaginas TxtFechaDocumento.Attributes.Remove("onchange"); DivImporteME.Visible = false; } + + + + protected void DdlTipoTransaccion_SelectedIndexChanged(object sender, EventArgs e) + { + ValidaFechaDocumentoDiasPosteriores(); + } + + protected void RVTxtFechaDocumento_Init(object sender, EventArgs e) + { + RVTxtFechaDocumento.MaximumValue = NowADS().AddDays(2).ToShortDateString(); + RVTxtFechaDocumento.MinimumValue = NowADS().AddMonths(-38).ToShortDateString(); + Calendario.EndDate = NowADS().AddDays(2); + } + + private void ValidaFechaDocumentoDiasPosteriores() + { + RVTxtFechaDocumento.MaximumValue = NowADS().AddDays(3).ToShortDateString(); + RVTxtFechaDocumento.ErrorMessage = "ERROR:
    La fecha del documento no puede ser superior a 3 días de la fecha actual"; + + Calendario.EndDate = NowADS().AddDays(3); + + // Equivalente a: If DdlTipoMovto.SelectedValue.Contiene("1", "16") Then + // Suponiendo que "Contiene" verifique si SelectedValue es "1" o "16" + if (DdlTipoTransaccion.SelectedValue == "1" || DdlTipoTransaccion.SelectedValue == "16") + { + // cheques, 3 meses + RVTxtFechaDocumento.MaximumValue = NowADS().AddMonths(3).ToShortDateString(); + RVTxtFechaDocumento.ErrorMessage = "ERROR:
    La fecha del documento no puede ser superior a 3 meses de la fecha actual"; + Calendario.EndDate = NowADS().AddMonths(3); + } + + // transfer, 3 semanas + if (DdlTipoTransaccion.SelectedValue == "2") + { + RVTxtFechaDocumento.MaximumValue = NowADS().AddDays(21).ToShortDateString(); + RVTxtFechaDocumento.ErrorMessage = "ERROR:
    La fecha del documento no puede ser superior a 3 semanas de la fecha actual"; + Calendario.EndDate = NowADS().AddDays(21); + } + + UpMovDeudor.Update(); + //UpGuardar.Update(); + } + + + + + } \ No newline at end of file diff --git a/Bancos/ProveedoresAbonar.aspx b/Bancos/ProveedoresAbonar.aspx index c2daed3a9..8c5c7ab04 100644 --- a/Bancos/ProveedoresAbonar.aspx +++ b/Bancos/ProveedoresAbonar.aspx @@ -105,15 +105,16 @@ - + + - - + <%-- + --%> @@ -341,8 +342,7 @@ - - + diff --git a/Bancos/ProveedoresAbonar.aspx.vb b/Bancos/ProveedoresAbonar.aspx.vb index 288fe1d16..e96b2a9b0 100644 --- a/Bancos/ProveedoresAbonar.aspx.vb +++ b/Bancos/ProveedoresAbonar.aspx.vb @@ -2,6 +2,11 @@ Option Strict On Imports System.Data +Imports System.Data.SqlClient +Imports ClsPaginas +Imports System.IO +Imports System.Xml +Imports DocumentFormat.OpenXml.ExtendedProperties Imports Extensiones Imports Microsoft.Reporting.WebForms Partial Class Bancos_ProveedoresAbonar @@ -220,6 +225,31 @@ Partial Class Bancos_ProveedoresAbonar End Set End Property + Private Property CveTipoProveedor As Integer + Get + If ViewState("CveTipoProveedor") Is Nothing Then + ViewState("CveTipoProveedor") = -1 + End If + Return ViewState("CveTipoProveedor").ToString.ToEntero + + End Get + Set(value As Integer) + ViewState("CveTipoProveedor") = value + End Set + End Property + Private Property CveTipoConceptoProveedor As Integer + Get + If ViewState("CveTipoConceptoProveedor") Is Nothing Then + ViewState("CveTipoConceptoProveedor") = -1 + End If + Return ViewState("CveTipoConceptoProveedor").ToString.ToEntero + + End Get + Set(value As Integer) + ViewState("CveTipoConceptoProveedor") = value + End Set + End Property + #End Region @@ -344,7 +374,6 @@ Partial Class Bancos_ProveedoresAbonar If UsuarioActual.TienePermisoProceso(361) Then 'GvCxP.Columns(11).Visible = True chkaplicaDescuento.Visible = True - chkaplicaDescuentoMasivo.Visible = True End If @@ -452,6 +481,9 @@ Partial Class Bancos_ProveedoresAbonar End If End If + CveTipoProveedor = ObjProveedor.CveTipoProveedor + CveTipoConceptoProveedor = ObjProveedor.CveTipoProveedor + CargaDatos() '(tCveProveedor, CveMoneda, FechaI, FechaF, CveUsuarioRegistro, CveUsuarioProgramo, Serie) CargaCuentasDepositos() @@ -608,14 +640,16 @@ Partial Class Bancos_ProveedoresAbonar Dim ValFechaDocumento As Boolean = False Dim FoliosFechasValFechaDocumento As New StringBuilder + Dim sbRNC As New StringBuilder FoliosFechasValFechaDocumento.AppendLine("Se seleccionaron facturas con fecha de mes superior al mes del pago:
    ") + Dim sbDescuentos As New StringBuilder + For Each gvRowVal As GridViewRow In GvCxP.Rows If gvRowVal.FCCheckBox("Chk").Checked Then - Dim FechaFactura As Date = gvRowVal.DataKey("Fecha").ToDate Dim FechaDocumento As Date = TxtFechaDocumento.Text.ToDate @@ -634,9 +668,11 @@ Partial Class Bancos_ProveedoresAbonar ValFechaDocumento = True End If End If + End If Next + If ValFechaDocumento Then Alert(FoliosFechasValFechaDocumento.ToString, TipoMensaje.MsgAdvertencia) Exit Sub @@ -893,6 +929,69 @@ Partial Class Bancos_ProveedoresAbonar If MsgError = "" AndAlso gvr.DataKey("ImporteProgramo").ToDouble > 0 Then ObjComp.ProgramarCompra(gvr.DataKey("CveCompra").ToEntero, 0, UsuarioActual.CveUsuario, -1) End If + + + 'INICIO Descuento Remision Nota de credito + Dim descuentoParts As String() = gvr.FCTextBox("TxtDescuento").Text.Split("+"c) + Dim Descuento As Decimal = 0 + Dim TotalTemp As Decimal = gvr.DataKey("Saldo").ToDecimal + + If descuentoParts.Length = 0 Then + Descuento = 0 + Else + + For i As Integer = 0 To descuentoParts.Length - 1 + Dim descuentoPart As Decimal = descuentoParts(i).Trim().ToDecimal + If descuentoPart > 0 Then + Descuento = Descuento + ((TotalTemp - Descuento) * (descuentoPart / 100)) + Else + Continue For + End If + Next + + End If + + If Descuento > 0 Then + + Dim PorcentajeIVA As Decimal = gvr.DataKey("PorcentajeIVA").ToDecimal + Dim serieFolioArray As String() = gvr.DataKey("SerieFolio").ToString.Split("-"c) + Dim SerieRNC As String = "" + Dim FolioRNC As String = "" + + Dim SerieFolioRNC As String = serieFolioArray(0) + If serieFolioArray.Length = 2 Then + SerieRNC = serieFolioArray(0) + FolioRNC = serieFolioArray(1) + SerieFolioRNC = $"{FolioRNC}-D-{SerieRNC = serieFolioArray(0)}" + + Else + FolioRNC = serieFolioArray(0) + End If + + Descuento = Descuento.RoundSQL(2) + If PorcentajeIVA > 0 Then + Descuento = (Descuento) / (1 + PorcentajeIVA) + End If + + Dim CveCompraRNC As Integer = GeneraRNC(Descuento.RoundSQL(2), ObjComp.IniciaTransacSQL, gvr.DataKey("CveCompra").ToEntero, CompraActual, ObjMov, CvePrePoliza, CveProveedor, HplProveedor.Text, TxtFechaDocumento.Text.ToDate, + $"Remisión Nota de Crédito pago {gvr.DataKey("SerieFolio").ToString}", gvr.DataKey("CveMoneda").ToEntero, TxtTC.Text.ToDecimal, SerieRNC, FolioRNC, PorcentajeIVA:=PorcentajeIVA, + CveSubProyecto:=gvr.DataKey("CveSubProyecto").ToEntero) + + If CveCompraRNC > 0 Then + + sbRNC.AppendLine($" {SerieFolioRNC}
    ") + + Else + 'TieneError = True + MsgError = $"Error al Generar Remisión de Nota de Crédito de factura {gvr.DataKey("SerieFolio").ToString}" + Exit For + End If + End If + + 'FIN Descuento Remision Nota de credito + + + End If Next @@ -1057,6 +1156,11 @@ Partial Class Bancos_ProveedoresAbonar Msg.AppendFormat("Ver Póliza   ", CvePrePoliza) End If + + If sbRNC.Length > 0 Then + Msg.AppendFormat($"
    Remisiones de Nota de Crédito Generadas y Aplicadas
    {sbRNC.ToString}") + End If + Dim Mensaje As String = String.Format("El Documento se generó correctamente.

    {0} ", Msg.ToString) 'LIMPIA @@ -1714,8 +1818,9 @@ Partial Class Bancos_ProveedoresAbonar Private Sub RVTxtFechaDocumento_Init(sender As Object, e As EventArgs) Handles RVTxtFechaDocumento.Init RVTxtFechaDocumento.MaximumValue = NowADS().AddDays(2).ToShortDateString - RVTxtFechaDocumentoMenor.MinimumValue = NowADS().AddMonths(-38).ToShortDateString - RVTxtFechaDocumentoMenor.MaximumValue = NowADS().AddDays(2).ToShortDateString + RVTxtFechaDocumento.MinimumValue = NowADS().AddMonths(-38).ToShortDateString + 'RVTxtFechaDocumentoMenor.MinimumValue = NowADS().AddMonths(-38).ToShortDateString + 'RVTxtFechaDocumentoMenor.MaximumValue = NowADS().AddDays(2).ToShortDateString Calendario.EndDate = NowADS().AddDays(2) End Sub @@ -1724,7 +1829,7 @@ Partial Class Bancos_ProveedoresAbonar RVTxtFechaDocumento.MaximumValue = NowADS().AddDays(3).ToShortDateString - RVTxtFechaDocumentoMenor.MaximumValue = NowADS().AddDays(3).ToShortDateString + 'RVTxtFechaDocumentoMenor.MaximumValue = NowADS().AddDays(3).ToShortDateString RVTxtFechaDocumento.ErrorMessage = "ERROR:
    La fecha del documento no puede ser superior a 3 días de la fecha actual" Calendario.EndDate = NowADS().AddDays(3) @@ -1749,16 +1854,11 @@ Partial Class Bancos_ProveedoresAbonar Protected Sub chkaplicaDescuento_CheckedChanged(sender As Object, e As EventArgs) GvCxP.Columns(11).Visible = chkaplicaDescuento.Checked + TxtDescuenoMasivo.Visible = chkaplicaDescuento.Checked UPCompras.Update() End Sub - Protected Sub chkaplicaDescuentoMasivo_CheckedChanged(sender As Object, e As EventArgs) - - GvCxP.Columns(11).Visible = chkaplicaDescuentoMasivo.Checked - TxtDescuenoMasivo.Visible = chkaplicaDescuentoMasivo.Checked - UPCompras.Update() - End Sub Private Sub tmpValida() @@ -1832,5 +1932,2185 @@ Partial Class Bancos_ProveedoresAbonar Dim url As String = String.Format("/Bancos/ProveedoresAbonar.aspx?CveProveedor={0}&FechaI={1}&FechaF={2}&CveUsuarioProgramo={3}&TipoPago={4}&CveUsuarioRegistro={5}&CveUsuarioResponsable={6}&CveClasificacion={7}&CveMoneda={8}&CveEstatus={9}&CveProveedorSucursal={10}&CveAplicaNC={11}&CodigoProgramacion={12}&CveSubProyecto={13}", DdlProveedores.SelectedValue, Request("FechaI").ToString(), Request("FechaF").ToString(), Request("CveUsuarioProgramo").ToString(), -1, Request("CveUsuarioRegistro").ToString(), Request("CveUsuarioResponsable").ToString(), Request("CveClasificacion").ToString(), Request("CveMoneda").ToString(), Request("CveEstatus").ToString(), Request("CveProveedorSucursal").ToString(), Request("CveAplicaNC").ToString(), Request("CodigoProgramacion").ToString(), Request("CveSubProyecto").ToString()) Response.Redirect(url) End Sub + + + Public Function GeneraRNC(ImporteRNC As Decimal, ByRef sqltransaccion As SqlTransaction, CveCompraAmortizada As Integer, ByRef CompraActual As Compra, ByRef ObjConta As ClsContabilidad, CvePrePoliza As Integer, + CveProveedor As Integer, NombreProveedor As String, Fecha As Date, Descripcion As String, CveMoneda As Integer, TipoCambio As Decimal, Serie As String, Folio As String, Optional EsDRMN As Boolean = False, + Optional TmpListadoPS As DataTable = Nothing, Optional PorcentajeIVA As Decimal = 0, Optional CveSubProyecto As Integer = -1) As Integer + Dim CveCompraRNC As Integer = -1 + Dim respuesta As Boolean = True + 'Dim PorcentajeIVA As Decimal = TmpDT.MAX("IVAPorcentaje").ToDecimal + + Dim CvePS_RNC As Integer = UsuarioActual.Empresa.Funcionalidad(580).ToEntero + Dim PSRow As DataRow = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CvePS:=CvePS_RNC).FiltroPrimero("") + Dim CveSubProyectoPrincipal As Integer = CveSubProyecto 'AsignarSubProyectoPrincipal() + Dim SubProyecto As String = "" + + If Not CvePS_RNC > 0 Then + Alert("No esta definido el producto de Remisión de Nota de Crédito.", TipoMensaje.MsgAdvertencia) + Return -1 + End If + + If Not CveSubProyectoPrincipal > 0 Then + Alert("No esta definido el Sub Proyecto.", TipoMensaje.MsgAdvertencia) + Return -1 + End If + + SubProyecto = GlobalDTSubProyectos(UsuarioActual.CveEmpresa, CveSubProyecto:=CveSubProyectoPrincipal).FiltroPrimeroValor("SubProyecto") + + If PSRow IsNot Nothing Then + + Dim CompraRNC As New ClsCompraManagerCompras(UsuarioActual) With { + .TipoDocto = "RNC", + .CveProveedor = CveProveedor, + .CveTipoProveedor = CveTipoProveedor, + .CveTipoConceptoProveedor = CveTipoConceptoProveedor, + .Descripcion = Descripcion, + .NombreProveedor = NombreProveedor, + .Fecha = Fecha, + .CveMoneda = CveMoneda, + .TipoCambio = If(CveMoneda = 1, 1, TipoCambio), + .Serie = $"D-{Serie}", + .Folio = Folio, + .CveCompraAmortizacion = CveCompraAmortizada, + .CveCompraRelacionada = CveCompraAmortizada + } + + 'Dim CveTipoPS As Integer = PSRow("CveTipoPS").ToString.ToEntero + 'If PSRow("CvePSCargo").ToString <> "" Then + ' CveTipoPS = 2 + 'End If + + Dim CveClasificacion As Integer = PSRow("CveClasificacion").ToString.ToEntero + Dim Clasificacion As String = PSRow("Clasificacion").ToString + Dim PS As String = PSRow("PSCodigo").ToString + Dim CveUM As Integer = PSRow("CveUnidadMedida").ToString.ToEntero + Dim UM As String = PSRow("UnidadMedida").ToString + Dim IVARNC As Decimal = (ImporteRNC * PorcentajeIVA) + + CompraRNC.ConfiguraRegistroRapido(CvePS_RNC, CveUM, UM, CveClasificacion, Clasificacion, PS, CveSubProyectoPrincipal, SubProyecto, ImporteRNC, IVARNC, (ImporteRNC + IVARNC), PorcentajeIVA) + + If CompraRNC.AddCompra(sqltransaccion) Then + Dim tImporteRNC = ImporteRNC + IVARNC ' le agrego el importe del iva + Dim Pago As New CompraPago + Pago.ImportePago = tImporteRNC + Pago.CveMonedaPago = CompraActual.CveMoneda + Pago.CveCompraAmortizacion = CompraRNC.CveCompra + Pago.Referencia = CompraRNC.SerieFolio + Pago.TCPago = CompraActual.TC + Pago.AplicaAcreditable = False + Pago.TipoPago = "RNC" + Pago.Fecha = CompraActual.Fecha 'toma la misma fecha de la provisión en el pago de NC + CveCompraRNC = CompraRNC.CveCompra + respuesta = Not AplicaPrePolizaPagoCompra(CompraActual, Pago, CvePrePoliza, ObjConta) + Else + respuesta = False + End If + + 'If respuesta AndAlso ImporteRNCProntoPago > 0 Then + + ' Dim CompraRNCProntoPago As New ClsCompraManagerCompras(UsuarioActual) With { + ' .TipoDocto = "RNC", + ' .CveProveedor = CveProveedor, + ' .CveTipoProveedor = CveTipoProveedor, + ' .CveTipoConceptoProveedor = CveTipoConcepto, + ' .Descripcion = Descripcion, + ' .NombreProveedor = NombreProveedor, + ' .Fecha = Fecha, + ' .CveMoneda = CveMoneda, + ' .TipoCambio = If(CveMoneda = 1, 1, TipoCambio), + ' .Serie = $"PP-{Serie}", + ' .Folio = $"{Folio}", + ' .CveCompraAmortizacion = CveCompraRegistrada + ' } + ' Dim IVARNCProntoPago As Decimal = (ImporteRNCProntoPago * PorcentajeIVA).RoundSQL(2) + + ' CompraRNCProntoPago.ConfiguraRegistroRapido(CvePS_RNC, CveUM, UM, CveClasificacion, Clasificacion, PS, CveSubProyectoPrincipal, SubProyecto, ImporteRNCProntoPago, (ImporteRNCProntoPago + IVARNCProntoPago), IVARNCProntoPago, PorcentajeIVA) + ' If CompraRNCProntoPago.AddCompra(sqltransaccion) Then + ' Dim tImporteRNCProntoPago = ImporteRNCProntoPago + IVARNCProntoPago ' le agrego el importe del iva + ' Dim Pago As New CompraPago + ' Pago.ImportePago = tImporteRNCProntoPago + ' Pago.CveMonedaPago = CompraActual.CveMoneda + ' Pago.CveCompraAmortizacion = CompraRNCProntoPago.CveCompra + ' Pago.Referencia = CompraRNCProntoPago.SerieFolio + ' Pago.TCPago = CompraActual.TC + ' Pago.AplicaAcreditable = False + ' Pago.TipoPago = "RNC" + ' Pago.Fecha = CompraActual.Fecha 'toma la misma fecha de la provisión en el pago de NC + ' respuesta = Not AplicaPrePolizaPagoCompra(CompraActual, Pago, CvePrePoliza, ObjConta) + ' Else + ' respuesta = False + ' End If + 'End If + End If + + Return If(respuesta, CveCompraRNC, -1) + + End Function + + +End Class + + + + + +Public Class MMensajeDevolucion + Public Property CveMovimiento As Integer + Public Property TieneError As Boolean + Public Property DebeRealizarDevolucion As Boolean + Public Property Total As Decimal +End Class + + + +Public Class ClsCompraManagerCompras + + Enum EnumCargaCompra + DesdeXML + DesdeArchivo + SinXML + End Enum + Public Enum EnumCFDIVersion + v32 + v33 + v40 + End Enum + Public Enum EnumTipoCompra + SinDefinir = -1 + Gasto_con_almacen = 10 + Activo_Fijo = 1 + 'Costo_Indirecto = 2 + Almacen = 3 + Almacen_con_costo_indirecto = 8 + Costo_Indirecto = 4 + Importación = 5 + NC_Con_Productos = 6 + Apoyo_Logístico = 9 + NC_Por_Devolución = 11 + Garantia = 12 + End Enum + + + Public Enum EnumModalidadAccionPS + Agregar + Actualizar + End Enum + + Public Property CveCompra As Integer = -1 + Public Property CveProveedor As Integer + Public Property CveTipoConceptoProveedor As Integer + Public Property CveMoneda As Integer + Public Property Fecha As Date + Public ReadOnly Property SerieFolio As String + Get + If Serie.Length > 0 Then + Return $"{Serie}-{Folio}" + Else + Return $"{Folio}" + End If + End Get + End Property + + Public Property Serie As String = "" + Public Property Folio As String = "" + Public Property FolioSecundario As String = "" + Public Property Descripcion As String = "" + Public Property CFDIVersion As EnumCFDIVersion = EnumCFDIVersion.v40 + Public Property ProveedorNombre As String = "" + Public Property EsImportacion As Boolean = False + Public Property TC As Decimal = 1 + Public Property SubTotal As Decimal = 0D + Public Property SubTotal2 As Decimal = 0D + Public Property Descuento As Decimal = 0D + Public Property Total As Decimal = 0D + Public Property Moneda As String = "" + Public Property TipoComprobante As String + Public Property TipoDocto As String = "Fac" + Public Property TipoCambio As Decimal = 1 + Public Property CompraNoDeducible As Integer = 0 + Public Property IVA As Decimal = 0D + Public Property IVADeducible As Decimal = 0D + Public Property IVANoDeducible As Decimal = 0 + Public Property IEPS As Decimal = 0D + Public Property RetIVA As Decimal = 0D + Public Property RetISR As Decimal = 0D + Public Property PorcentajeIVA As Decimal = 0 + Public Property PorcentajeISR As Decimal = 0 + Public Property CveRetIVAConcepto As Integer = -1 + Public Property CveRetISRConcepto As Integer = -1 + Public Property CveSubProyecto As Integer = -1 + Public Property UsuarioActual As Usuario + Public ReadOnly Property ConceptoPrePolizaIVA As ClsPaginas.ConceptosRetenciones + Get + Dim Ret As New ClsPaginas.ConceptosRetenciones + If EsImportacion Then + Ret.CveConceptoAcreditable = 288 + Ret.CveConceptoxAcreditar = 287 + Else + Ret.CveConceptoAcreditable = 19 + Ret.CveConceptoxAcreditar = 14 + End If + Return Ret + End Get + End Property + Public ReadOnly Property ConceptoPrePolizaRetIVA As ClsPaginas.ConceptosRetenciones + Get + Dim Ret As New ClsPaginas.ConceptosRetenciones + Dim Funcionalidad, FuncionalidadxAcred As Integer + If CveRetIVAConcepto = 1 Then + Funcionalidad = 308 : FuncionalidadxAcred = 307 + Ret.CveConceptoAcreditable = 22 + Ret.CveConceptoxAcreditar = 15 + ElseIf CveRetIVAConcepto = 2 Then + Funcionalidad = 310 : FuncionalidadxAcred = 309 + Ret.CveConceptoAcreditable = 184 + Ret.CveConceptoxAcreditar = 183 + ElseIf CveRetIVAConcepto = 3 Then + Funcionalidad = 312 : FuncionalidadxAcred = 311 + Ret.CveConceptoAcreditable = 186 + Ret.CveConceptoxAcreditar = 185 + ElseIf CveRetIVAConcepto = 4 Then + Funcionalidad = 314 : FuncionalidadxAcred = 313 + Ret.CveConceptoAcreditable = 249 + Ret.CveConceptoxAcreditar = 248 + ElseIf CveRetIVAConcepto = 5 Then + Funcionalidad = 578 : FuncionalidadxAcred = 578 + Ret.CveConceptoAcreditable = 286 + Ret.CveConceptoxAcreditar = 285 + ElseIf CveRetIVAConcepto = 6 Then + Funcionalidad = 578 : FuncionalidadxAcred = 578 + Ret.CveConceptoAcreditable = 333 + Ret.CveConceptoxAcreditar = 334 + End If + Return Ret + End Get + End Property + Public ReadOnly Property ConceptoPrePolizaRetISR As ClsPaginas.ConceptosRetenciones + Get + Dim Ret As New ClsPaginas.ConceptosRetenciones + Dim Funcionalidad, FuncionalidadxAcred As Integer + If CveRetISRConcepto = 1 Then + Funcionalidad = 316 : FuncionalidadxAcred = 315 + Ret.CveConceptoAcreditable = 23 + Ret.CveConceptoxAcreditar = 16 + ElseIf CveRetISRConcepto = 2 Then + Funcionalidad = 318 : FuncionalidadxAcred = 317 + Ret.CveConceptoAcreditable = 244 + Ret.CveConceptoxAcreditar = 243 + ElseIf CveRetISRConcepto = 3 Then + Funcionalidad = 349 : FuncionalidadxAcred = 348 + Ret.CveConceptoAcreditable = 328 + Ret.CveConceptoxAcreditar = 327 + End If + Return Ret + End Get + End Property + + Public Property CveMetodoPago As Integer + Public Property MetodoPago As String + Public Property DocumentosRelacionadosUUIDSList As List(Of String) = New List(Of String) + Public ReadOnly Property DocumentosRelacionadosUUIDSString As String + Get + Return GeneraStringDoctosRelacionados() + End Get + End Property + + Public Property DocumentosRelacionadosAnticiposUUIDList As List(Of String) = New List(Of String) + Public Property TieneAnticiposXML As Boolean = False + Public Property EmisorRFC As String + Public Property ReceptorRFC As String + Public Property UUID As String = "" + Public Property TotalRetenciones As Decimal = 0D + Public Property RetencionIVA As Decimal = 0D + Public Property RetencionISR As Decimal = 0D + Public Property SumaTotalRetenciones As Decimal = 0D + Public Property TotalTraslados As Decimal = 0D + Public Property TrasladoIVA As Decimal = 0D + Public Property TrasladoIEPS As Decimal = 0D + Public Property SumaTotalTraslados As Decimal = 0D + Public Property OtrosImpuestos As Decimal = 0D + Private Property OtrosImpuestosRetenciones As Decimal = 0D + Public Property Amortizacion As Decimal = 0D + Public Property FechaPago As Date 'FIX ME corregir usando fecha interna calculada por los dias de credito del proveedor + Public Property AplicaNotaCredito As Boolean = False + Public Property XMlStr As String + Public Property XMLCargaExistosa As Boolean = True + Public Property Observaciones As String = "" + Public Property CveEstatusFactura As Integer = 1 + Public Property CvePrePoliza As Integer = -1 + Public Property Redondeo As Decimal = 0 + Public Property IdPoliza As Integer = -1 + Public Property CveCajaChica As Integer = -1 + Public Property CvePersonal As Integer = -1 + Public Property NumeroReembolso As String = "" + Public Property CveProveedorSucursal As Integer = -1 + Public Property AplicoPromocion As Boolean = False + Public Property CveConceptoContableAlmacen As Integer = -1 + Public Property NoDeducible As Integer = 0 + Public Property CveTipoCompra As Integer = -1 + Public Property TotalOriginal As Decimal = 0D + Public Property CveTipoConcepto As Integer = 1 'FIX ME Esto tiene que ver con el CveTipoProveedor 1 y 3 es CveTipoConcepto 1 y 2 es CveTipoConcepto 2 + Public Property CveSubProyectoPrincipal As Integer = -1 + Public Property CveFactura As Integer = -1 + Public Property CveFolioGarantia As Integer = -1 + Public Property TmpDT As DataTable = New DataTable + Public Property SubTotalConceptos As Decimal = 0D + + Private Errores As StringBuilder = New StringBuilder + + Public ReadOnly Property MensajeError As String + Get + Return Errores.ToString() + End Get + End Property + + Public Property CompraSaldo As Decimal = 0D + Public Property SubTotalOriginal As Decimal = 0D + Public Property SubTotal2Original As Double = 0D + Public Property IVAOriginal As Decimal = 0D + Public Property RetIVAOriginal As Decimal = 0D + Public Property RetISROriginal As Decimal = 0D + Public Property Proyecto As String = "" + Public Property CveProyecto As Integer = -1 + Public Property SubProyecto As String = "" + Public Property TipoCompra As EnumTipoCompra = EnumTipoCompra.SinDefinir + Private Property DTTiposGastos() As DataTable + Public Property CveTipoProveedor As Integer = -1 + Public Property IEPSGasto As Boolean = False + Public Property OtrosImpuestosGasto As Boolean = False + Public Property OCVinculada As Boolean = False + Public Property NumNoDed As Integer = 0 + Public Property CveTipoPoliza As Integer = -1 + Public Property NombreProveedor As Object + Public Property CveCreditoDetalle As Integer = -1 + Public Property CveIE As Integer = -1 + Public Property CveCompraAmortizacion As Integer = -1 + Public Property CveCompraRelacionada As Integer = -1 + + + Public Sub New(UsuarioActual As Usuario) + + Errores = New StringBuilder + + Me.UsuarioActual = UsuarioActual + + End Sub + + Public Sub New(XmlFuente As String, OpcionCarga As EnumCargaCompra, DTTiposGastos As DataTable, UsuarioActual As Usuario) + + Errores = New StringBuilder + Me.DTTiposGastos = DTTiposGastos + Me.UsuarioActual = UsuarioActual + + If OpcionCarga = EnumCargaCompra.SinXML Then + + Else + If OpcionCarga = EnumCargaCompra.DesdeArchivo Then + CargaDesdeArchivo(XmlFuente) + Else + CargaDesdeString(XmlFuente) + End If + End If + End Sub + +#Region "C A R G A S D E F U E N T E S " + + Private Sub CargaDesdeArchivo(XmlFuenteRuta As String) + + Dim XMLDoc As New XmlDocument + + If IO.File.Exists(XmlFuenteRuta) Then + XMlStr = File.ReadAllText(XmlFuenteRuta).Replace("<br>", "").Replace("<", "").Replace("o;?", "") + Try + XMLDoc.LoadXml(XMlStr) + XMLCargaExistosa = True + Catch ex As Exception + Try + Dim oReader As New StreamReader(XmlFuenteRuta, Encoding.GetEncoding("ISO-8859-1")) + XMLDoc.Load(oReader) + oReader.Dispose() + XMLCargaExistosa = True + Catch ex2 As Exception + GuardaLog("Error al intentar leer el XML del SAT. Error:" & ex2.ToString()) + Errores.AppendLine("Error al intentar leer el XML. Error:" & ex2.ToString()) + XMLCargaExistosa = False + End Try + End Try + End If + + If XMLCargaExistosa Then + CargaComprobanteXML(XMLDoc) + End If + + End Sub + Private Sub CargaDesdeString(XmlFuente As String) + XMlStr = XmlFuente.Replace("<br>", "").Replace("<", "").Replace("o;?", "") + Dim XMLDoc As New XmlDocument + Try + XMLDoc.LoadXml(XMlStr) + XMLCargaExistosa = True + Catch ex As Exception + GuardaLog("Error al intentar leer . Error:" & ex.ToString()) + Errores.AppendLine("Error al intentar leer el XML. Error:" & ex.ToString()) + XMLCargaExistosa = False + End Try + + If XMLCargaExistosa Then + CargaComprobanteXML(XMLDoc) + End If + + End Sub + Private Sub CargaComprobanteXML(XMLDoc As XmlDocument) + Dim nodo As XmlNode = XMLDoc.DocumentElement + + Serie = ValorXML(nodo, "serie") + + Dim StrCFDIVerion As String = ValorXML(nodo, "version") + + If StrCFDIVerion = "3.2" Then + CFDIVersion = EnumCFDIVersion.v32 + ElseIf StrCFDIVerion = "3.3" Then + CFDIVersion = EnumCFDIVersion.v33 + ElseIf StrCFDIVerion = "4.0" Then + CFDIVersion = EnumCFDIVersion.v40 + Else + GuardaLog($"CFDI Versión {StrCFDIVerion} no soportada") + Errores.AppendLine($"CFDI Versión {StrCFDIVerion} no soportada") + XMLCargaExistosa = False + Exit Sub + End If + + Folio = ValorXML(nodo, "folio") + Fecha = ValorXML(nodo, "fecha").ToDate + SubTotal = ValorXML(nodo, "subTotal").ToDecimal + Total = ValorXML(nodo, "total").ToDecimal + Descuento = ValorXML(nodo, "descuento").ToDecimal + Moneda = ValorXML(nodo, "Moneda") + + CveMoneda = ClsPaginas.GlobalDTMonedas().FiltroPrimeroValor("CveMoneda", $" AbreviaturaSAT = '{Moneda}' ").ToEntero + If Not CveMoneda > 0 Then + GuardaLog($"Moneda {Moneda} no se obtuvo la clabe") + Errores.AppendLine($"Moneda {Moneda} no se obtuvo la clabe") + XMLCargaExistosa = False + Exit Sub + End If + + TipoComprobante = ValorXML(nodo, "tipoDeComprobante") + TipoCambio = ValorXML(nodo, "TipoCambio", "1").ToDecimal + + If CFDIVersion = EnumCFDIVersion.v33 Or CFDIVersion = EnumCFDIVersion.v40 Then + Dim drm As DataRow = ClsPaginas.GlobalDTVtaMetodoPago.FiltroPrimero(String.Format("ClaveMetodoPagoSAT = '{0}'", ValorXML(nodo, "MetodoPago"))) + If drm IsNot Nothing Then + CveMetodoPago = drm("CveMetodoPago").ToString.ToEntero + MetodoPago = drm("MetodoPagoSAT").ToString + End If + End If + + Dim namespaces As New XmlNamespaceManager(XMLDoc.NameTable) + Dim Prefijo As String = If(XMLDoc.DocumentElement.Prefix = "", "cfd", XMLDoc.DocumentElement.Prefix) + Dim cfdVer As String = "" + + If CFDIVersion = EnumCFDIVersion.v32 Then + Prefijo = "cfd" + cfdVer = "http://www.sat.gob.mx/cfd/2" + ElseIf CFDIVersion = EnumCFDIVersion.v33 Then + cfdVer = "http://www.sat.gob.mx/cfd/3" + Else ' se considera que es la version 4.0 + cfdVer = "http://www.sat.gob.mx/cfd/4" + End If + namespaces.AddNamespace(Prefijo, cfdVer) + namespaces.AddNamespace("aerolineas", "http://www.sat.gob.mx/aerolineas") + namespaces.AddNamespace("tfd", "http://www.sat.gob.mx/TimbreFiscalDigital") + namespaces.AddNamespace("implocal", "http://www.sat.gob.mx/implocal") + namespaces.AddNamespace("registrofiscal", "http://www.sat.gob.mx/registrofiscal") + + If TipoComprobante.ToUpper = "E" AndAlso (CFDIVersion = EnumCFDIVersion.v33 OrElse CFDIVersion = EnumCFDIVersion.v40) Then + Dim UUIDS As String = "" + + Dim UUIDSLista As New List(Of String) + Dim nodeCFDIRelacionados As XmlNode + nodeCFDIRelacionados = XMLDoc.SelectSingleNode(String.Format("//{0}:CfdiRelacionados", Prefijo), namespaces) + + If nodeCFDIRelacionados IsNot Nothing Then + For Each CFDIRelacionados As XmlNode In nodeCFDIRelacionados + UUIDSLista.Add("" & CFDIRelacionados.Attributes("UUID").Value.ToString & "") + Next + End If + DocumentosRelacionadosUUIDSList = UUIDSLista + + End If + + Dim node As XmlNode + node = XMLDoc.SelectSingleNode(String.Format("//{0}:Emisor", Prefijo), namespaces) + + If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then + EmisorRFC = ValorXML(node, "RFC") + End If + + node = XMLDoc.SelectSingleNode(String.Format("//{0}:Receptor", Prefijo), namespaces) + + If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then + ReceptorRFC = ValorXML(node, "RFC") + End If + + If UsuarioActual.CveEmpresa.Contiene(119, 7) Then + node = XMLDoc.SelectSingleNode(String.Format("//{0}:CfdiRelacionados", Prefijo), namespaces) + If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then + If ValorXML(node, "TipoRelacion").ToString.Contiene("07") Then + Dim nodeDocumentosRelacionados As XmlNodeList = XMLDoc.SelectNodes(String.Format("//{0}:CfdiRelacionado", Prefijo), namespaces) + For Each documento As XmlNode In nodeDocumentosRelacionados + If documento.Attributes("UUID").Value <> "" Then + DocumentosRelacionadosAnticiposUUIDList.Add(documento.Attributes("UUID").Value) + End If + TieneAnticiposXML = True + Next + End If + End If + End If + + node = XMLDoc.SelectSingleNode(String.Format("//{0}:Impuestos", Prefijo), namespaces) + If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then + Dim nodeRetenciones As XmlNodeList = XMLDoc.SelectNodes(String.Format("//{0}:Comprobante/{0}:Impuestos/{0}:Retenciones/{0}:Retencion", Prefijo), namespaces) + + TotalRetenciones = ValorXML(node, "totalImpuestosRetenidos", "0").ToDecimal + + If CFDIVersion = EnumCFDIVersion.v33 OrElse CFDIVersion = EnumCFDIVersion.v40 Then + + For Each retencion As XmlNode In nodeRetenciones + If retencion.Attributes("Impuesto").Value = "002" Then RetencionIVA += retencion.Attributes("Importe").Value.ToDecimal + If retencion.Attributes("Impuesto").Value = "001" Then RetencionISR += retencion.Attributes("Importe").Value.ToDecimal + Next + + Else + + For Each retencion As XmlNode In nodeRetenciones + If retencion.Attributes("impuesto").Value = "IVA" Then RetencionIVA += retencion.Attributes("importe").Value.ToDecimal + If retencion.Attributes("impuesto").Value = "ISR" Then RetencionISR += retencion.Attributes("importe").Value.ToDecimal + Next + End If + SumaTotalRetenciones += RetencionIVA + SumaTotalRetenciones += RetencionISR + + TotalTraslados = ValorXML(node, "totalImpuestosTrasladados", "0").ToDecimal + Dim nodeTraslados As XmlNodeList = XMLDoc.SelectNodes(String.Format("//{0}:Comprobante/{0}:Impuestos/{0}:Traslados/{0}:Traslado", Prefijo), namespaces) + + If CFDIVersion = EnumCFDIVersion.v33 OrElse CFDIVersion = EnumCFDIVersion.v40 Then + + For Each traslado As XmlNode In nodeTraslados + + If traslado.Attributes("Importe") IsNot Nothing Then + If traslado.Attributes("Impuesto").Value = "002" Then TrasladoIVA += traslado.Attributes("Importe").Value.ToDecimal + If traslado.Attributes("Impuesto").Value = "003" Then TrasladoIEPS += traslado.Attributes("Importe").Value.ToDecimal + End If + Next + Else + + For Each traslado As XmlNode In nodeTraslados + If traslado.Attributes("Importe") IsNot Nothing Then + If traslado.Attributes("impuesto").Value = "IVA" Then TrasladoIVA += traslado.Attributes("importe").Value.ToDecimal + + If traslado.Attributes("impuesto").Value = "IEPS" Then TrasladoIEPS += traslado.Attributes("importe").Value.ToDecimal + End If + Next + End If + + SumaTotalTraslados += TrasladoIVA + SumaTotalTraslados += TrasladoIEPS + End If + + Dim nodeComp As XmlNode = XMLDoc.SelectSingleNode(String.Format("//{0}:Complemento", Prefijo), namespaces) + If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then + + Dim nodeTFD As XmlNode = nodeComp.SelectSingleNode(String.Format("//{0}:TimbreFiscalDigital", "tfd"), namespaces) + + UUID = ValorXML(nodeTFD, "UUID", "") + + Dim nodeRF As XmlNode = nodeComp.SelectSingleNode(String.Format("//{0}:CFDIRegistroFiscal ", "registrofiscal"), namespaces) + If nodeRF IsNot Nothing Then + Folio = ValorXML(nodeRF, "folio").TrimStart("0"c) + End If + + node = node.SelectSingleNode(String.Format("//{0}:ImpuestosLocales", "implocal"), namespaces) + + If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then + OtrosImpuestos = ValorXML(node, "TotaldeTraslados", "0").ToDecimal + '2022.06.04-- se quitan los datos de retenciones de impuestos locales, generan conflicto. RMF + 'OtrosImpuestosRetenciones = ValorXML(node, "TotaldeRetenciones", "0").ToDecimal + End If + End If + + + If XMLCargaExistosa Then + If Not ValidateUUID(UUID) Then + GuardaLog($"UUID Invalido {UUID} .") + Errores.AppendLine($"UUID Invalido {UUID} .") + XMLCargaExistosa = False + End If + End If + + +#Region "DETALLES" + + Dim ObjeFacturas As New ClsCompras + Dim AjustaUltimoConcepto As Boolean = False + + Dim nodeconceptos As XmlNode = XMLDoc.SelectSingleNode(String.Format("//{0}:Conceptos", Prefijo), namespaces) + Dim XML As String = Replace(nodeconceptos.OuterXml, "", "") 'salto de linea html + XML = XML.Replace("<br>", "") + XML = XML.Replace("<", "") + + XML = XML.Replace("&", "") 'adicional, si hay otros + + If ObjeFacturas.GetFacturasComparacionXML(StrCFDIVerion, XML, UsuarioActual.CveEmpresa) Then + TmpDT = ObjeFacturas.DtResultados + TmpDT.Columns.Add("CveSATPSActualizado") + SubTotalConceptos = TmpDT.SUMD("Total").RoundSQL + + If Not TmpDT.Columns.Contains("Amortizacion") Then TmpDT.Columns.Add("Amortizacion", GetType(Decimal)) + + If Not TmpDT.Columns.Contains("AplicaLote") Then TmpDT.Columns.Add("AplicaLote", GetType(Boolean)) + + If Not TmpDT.Columns.Contains("AplicaCaducidad") Then TmpDT.Columns.Add("AplicaCaducidad", GetType(Boolean)) + + If Not TmpDT.Columns.Contains("Lote") Then TmpDT.Columns.Add("Lote", GetType(String)) + + If Not TmpDT.Columns.Contains("FechaCaducidad") Then TmpDT.Columns.Add("FechaCaducidad", GetType(Date)) + + 'VALIDA QUE EL XML SI VIENE CON EL CODIGO SAT 01010101 + Dim ProductosCodigoSATNoPermitidos As New StringBuilder("") + For Each drr As DataRow In TmpDT.FiltraParametros("ClaveProdServ = '01010101'").Rows + ProductosCodigoSATNoPermitidos.AppendFormat("{0}
    ", drr("PS")) + Next + + If ProductosCodigoSATNoPermitidos.ToString.Length > 0 Then + Errores.AppendLine($"El comprobante contiene productos con código SAT '01010101', revise los productos:

    {ProductosCodigoSATNoPermitidos.ToString}") + End If + Else + GuardaLog($"Error al cargar detalles GetFacturasComparacionXML.") + Errores.AppendLine($"Error al cargar detalles GetFacturasComparacionXML.") + XMLCargaExistosa = False + End If + + ObjeFacturas.Dispose() + + If CFDIVersion = EnumCFDIVersion.v33 OrElse CFDIVersion = EnumCFDIVersion.v40 Then + If Not TmpDT.Columns.Contains("Amortizacion") Then + TmpDT.Columns.Add("Amortizacion", GetType(Decimal)) + End If + TmpDT.AcceptChanges() + ValidacionesTotalesXml() + End If + + Me.PorcentajeIVA = TmpDT.MAX("IVAPorcentaje").ToDecimal + +#End Region + End Sub + +#End Region + + Public Function ConfiguraRegistroRapidoReembolso(CvePS As Integer, CveSubProyecto As Integer, CveCajaChica As Integer, CvePersonal As Integer, CveRetIVAConcepto As Integer, CveRetISRConcepto As Integer, NumeroReembolso As String) As Boolean + + Dim respuesta As Boolean = True + Me.CveSubProyecto = CveSubProyecto + Me.CveSubProyectoPrincipal = CveSubProyecto + Me.CveCajaChica = CveCajaChica + Me.CvePersonal = CvePersonal + Me.CveRetIVAConcepto = CveRetIVAConcepto + Me.CveRetISRConcepto = CveRetISRConcepto + Me.CveTipoPoliza = 3 + Me.NumeroReembolso = NumeroReembolso + + Dim dRowSubProyecto As DataRow = GlobalDTSubProyectos(UsuarioActual.CveEmpresa, CveSubProyecto:=CveSubProyecto).FiltroPrimero("") + + If dRowSubProyecto IsNot Nothing Then + Me.Proyecto = dRowSubProyecto("Proyecto").ToString + Me.CveProyecto = (dRowSubProyecto("CveProyecto").ToString).ToEntero + Me.SubProyecto = dRowSubProyecto("SubProyecto").ToString + Else + Errores.AppendLine($"Error al cargar el Sub Proyecto CveSubProyecto: {CveSubProyecto}") + Return False + End If + + Dim DTIndex As DataTable = TmpDT.FiltraParametros("", DistinctColumns:={"Consec"}) + + For Each dRowIndex As DataRow In DTIndex.Rows + If Not UpdatePSReembolso(dRowIndex("Consec").ToString.ToEntero, CvePS) Then + respuesta = False + End If + Next + + If respuesta AndAlso IEPS > 0 Then + If Not AgregaIEPSReembolso(CvePS:=CvePS) Then + respuesta = False + Else + IEPS = 0 + End If + End If + + If Not AjustesValidacion() Then + respuesta = False + End If + + Return respuesta + + End Function + Public Function ConfiguraRegistroRapido(CvePS As Integer, CveUM As Integer, UM As String, CveClasificacion As Integer, Clasificacion As String, PS As String, CveSubProyecto As Integer, SubProyecto As String, + SubTotal As Decimal, IVA As Decimal, Total As Decimal, PorcentajeIVA As Decimal) As Boolean + + Dim respuesta As Boolean = True + Me.CveSubProyecto = CveSubProyecto + Me.CveSubProyectoPrincipal = CveSubProyecto + Me.CveCajaChica = -1 + Me.CvePersonal = -1 + Me.CveRetIVAConcepto = -1 + Me.CveRetISRConcepto = -1 + Me.CveTipoPoliza = 3 + Me.NumeroReembolso = "" + Me.SubTotal = SubTotal + Me.IVA = IVA + Me.Total = Total + Me.PorcentajeIVA = PorcentajeIVA + + Dim dRowSubProyecto As DataRow = GlobalDTSubProyectos(UsuarioActual.CveEmpresa, CveSubProyecto:=CveSubProyecto).FiltroPrimero("") + + If dRowSubProyecto IsNot Nothing Then + Me.Proyecto = dRowSubProyecto("Proyecto").ToString + Me.CveProyecto = (dRowSubProyecto("CveProyecto").ToString).ToEntero + Me.SubProyecto = dRowSubProyecto("SubProyecto").ToString + Else + Errores.AppendLine($"Error al cargar el Sub Proyecto CveSubProyecto: {CveSubProyecto}") + Return False + End If + + CreaDTCompras() + AddPS(1, CveUM, UM, CveClasificacion, Clasificacion, CvePS, PS, 1, CveSubProyecto.ToString, SubProyecto, "", "-1", "", SubTotal, Total, 0, 0, 0, 0, 0, 0, PorcentajeIVA:=PorcentajeIVA) + + 'If respuesta AndAlso IEPS > 0 Then + ' If Not AgregaIEPSReembolso(CvePS:=CvePS) Then + ' respuesta = False + ' Else + ' IEPS = 0 + ' End If + 'End If + + 'If Not AjustesValidacion() Then + ' respuesta = False + 'End If + + Return respuesta + + End Function + + + Private Sub CreaDTCompras() + + TmpDT = New DataTable + TmpDT.Columns.Add("Consec", GetType(Integer)) + TmpDT.Columns.Add("Cantidad", GetType(Decimal)) + 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("CveClasificacionActualizar", GetType(Integer)) + TmpDT.Columns.Add("CvePS", GetType(Integer)) + TmpDT.Columns.Add("PS", GetType(String)) + TmpDT.Columns.Add("Obs", GetType(String)) + TmpDT.Columns.Add("PU", GetType(Decimal)) + TmpDT.Columns.Add("IVA", GetType(Decimal)) + TmpDT.Columns.Add("IVAPorcentaje", GetType(Decimal)) + TmpDT.Columns.Add("RetIVA", GetType(Decimal)) + TmpDT.Columns.Add("RetIVAPorcentaje", GetType(Decimal)) + TmpDT.Columns.Add("RetISR", GetType(Decimal)) + TmpDT.Columns.Add("RetISRPorcentaje", GetType(Decimal)) + TmpDT.Columns.Add("IEPSPS", GetType(Double)) + TmpDT.Columns.Add("IEPSPSPorcentaje", GetType(Double)) + TmpDT.Columns.Add("IEPSPSIVA", GetType(Double)) + TmpDT.Columns.Add("IEPSPSIVAPorcentaje", GetType(Double)) + TmpDT.Columns.Add("Descuento", GetType(Decimal)) + TmpDT.Columns.Add("OtrosGastos", GetType(Decimal)) + TmpDT.Columns.Add("Total", GetType(Decimal)) + TmpDT.Columns.Add("AsientoContableCompras", GetType(Integer)) + TmpDT.Columns.Add("Proyecto", GetType(String)) + TmpDT.Columns.Add("CveProyecto", GetType(Integer)) + TmpDT.Columns.Add("CveSubProyecto", GetType(Integer)) + TmpDT.Columns.Add("CveContrato", GetType(Integer)) + TmpDT.Columns.Add("SubProyecto", GetType(String)) + 'TmpDT.Columns.Add("CveEq", GetType(Integer)) + TmpDT.Columns.Add("CveAlmacen", GetType(Integer)) + TmpDT.Columns.Add("CvePersonal", GetType(String)) + TmpDT.Columns.Add("Referencia", GetType(String)) + + 'AC + TmpDT.Columns.Add("CveTipoGastoAC", GetType(Integer)) + TmpDT.Columns.Add("CvePresupuestoEgreso", GetType(Integer)) + TmpDT.Columns.Add("CveProgramaOperativo", GetType(Integer)) + TmpDT.Columns.Add("CveUnidadAdministrativa", GetType(Integer)) + TmpDT.Columns.Add("CveFuenteFinanciamiento", GetType(Integer)) + TmpDT.Columns.Add("CveClasificacionOG", GetType(Integer)) + + TmpDT.Columns.Add("IdCuentaComprometido", GetType(Integer)) + TmpDT.Columns.Add("IdCuentaPorEjercer", GetType(Integer)) + TmpDT.Columns.Add("IdCuentaDevengado", GetType(Integer)) + TmpDT.Columns.Add("IdCuentaMatriz", GetType(Integer)) + + 'INVENTARIO SERIE/LOTE + TmpDT.Columns.Add("CveMetodoInventario", GetType(Integer)) + + TmpDT.Columns.Add("CveConcepto", GetType(Integer)) + + 'AF + TmpDT.Columns.Add("CveActivoFijo", GetType(Integer)) + TmpDT.Columns.Add("CodAF", GetType(String)) + TmpDT.Columns.Add("TipoAF", GetType(Integer)) + TmpDT.Columns.Add("AFMedida", GetType(Integer)) + TmpDT.Columns.Add("AFTipoMantenimiento", GetType(Integer)) + + 'PS + TmpDT.Columns.Add("CveTipoPS", GetType(Integer)) + TmpDT.Columns.Add("CodigoPS", GetType(String)) + TmpDT.Columns.Add("PSDescripcion", GetType(String)) + 'CAMPO ESPECIAL PARA GLUYAS - LEE EL DEL XML - A GLUYAS LE INTERESA EL CODIGO DEL PROVEEDOR + TmpDT.Columns.Add("PSCodigo", GetType(String)) + + + 'OC + TmpDT.Columns.Add("CveOrdenCompraDetalle", GetType(Integer)) + TmpDT.Columns.Add("ProductoOC", GetType(String)) + TmpDT.Columns.Add("CantidadF", GetType(Double)) + + 'Consignaciones + TmpDT.Columns.Add("CveAlmacenConsignacion", GetType(Integer)) + TmpDT.Columns.Add("NoConsignacion", GetType(Integer)) + TmpDT.Columns.Add("CveConsignacion", GetType(Integer)) + TmpDT.Columns.Add("HdnPS", GetType(String)) + TmpDT.Columns.Add("HdnCvePS", GetType(String)) + TmpDT.Columns.Add("HdnClasificacion", GetType(String)) + TmpDT.Columns.Add("HdnCveClasificacion", GetType(String)) + TmpDT.Columns.Add("HdnCveAlmacen", GetType(String)) + + 'Fletes y Servicios + TmpDT.Columns.Add("AplicaCostoIndirecto", GetType(Integer)) + TmpDT.Columns.Add("CostoIndirectoAlmacen", GetType(Decimal)) + TmpDT.Columns.Add("CveCompraDetalle", GetType(Integer)) + + TmpDT.Columns.Add("EntregaDirecta", GetType(Integer)) + + 'SAT + TmpDT.Columns.Add("CveSATPS", GetType(Integer)) + TmpDT.Columns.Add("SATClaveProductoServicio", GetType(String)) + TmpDT.Columns.Add("CveUnidadMedidaSAT", GetType(Integer)) + TmpDT.Columns.Add("SATClaveUnidadMedida", GetType(String)) + TmpDT.Columns.Add("CveSATPSActualizado", GetType(Integer)) + + + 'Tipo de Gasto + TmpDT.Columns.Add("CveTipoGasto", GetType(Integer)) + TmpDT.Columns.Add("TipoGasto", GetType(String)) + + TmpDT.Columns.Add("ImporteSinImpuestos", GetType(Double)) + TmpDT.Columns.Add("ImporteConImpuestos", GetType(Double)) + TmpDT.Columns.Add("NoDeducible", GetType(Boolean)) + + TmpDT.Columns.Add("DifPSSat", GetType(Integer)) + + + TmpDT.Columns.Add("CveContratoDetalle", GetType(Integer)) + TmpDT.Columns.Add("CveCultivoCuadroDetalle", GetType(Integer)) + TmpDT.Columns.Add("TemporadaCuadro", GetType(String)) + + TmpDT.Columns.Add("NoIdentificacion", GetType(String)) + + TmpDT.Columns.Add("AplicaLote", GetType(Boolean)) + TmpDT.Columns.Add("AplicaCaducidad", GetType(Boolean)) + + TmpDT.Columns.Add("Lote", GetType(String)) + TmpDT.Columns.Add("FechaCaducidad", GetType(Date)) + + + TmpDT.AcceptChanges() + + + End Sub + Private Function AjustesValidacion() As Boolean + Dim respuesta As Boolean = True + 'VALIDA IMPORTES + If Not ValidaTotalesGuardar() Then + respuesta = False + End If + + If Not AjustaCombustibles() Then + respuesta = False + End If + + If Not AjustaIVA() Then + respuesta = False + End If + + If Not AjustaRetIVA() Then + respuesta = False + End If + + If Not AjustaRetISR() Then + respuesta = False + End If + + Return respuesta + + End Function + + Private Function ValidaTotalesGuardar() As Boolean + Dim EsValido As Boolean = True + + 'VALIDA IMPORTES + 'VALIDA TOTAL CON LOS IMPORTES TOTALES + Dim TempSubTotal, TempDescuentos, TempIVA, TempSubTotal2, TempRetIVA, TempRetISR, TempTotal, DifTotales, TempIEPS As Decimal + + Dim Amortizacion As Decimal = 0 + Dim TieneAmortizacion As Boolean = False + If DocumentosRelacionadosAnticiposUUIDList IsNot Nothing AndAlso DocumentosRelacionadosAnticiposUUIDList.Count > 0 Then 'Fix me + ' AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 Then + 'TieneAmortizacion = True + End If + + 'If CveCompra < 0 AndAlso Not TieneAmortizacion Then + ' LblAmortizacion.Text = "0.00" + 'End If + + 'If UsuarioActual.CveEmpresa = 119 AndAlso TieneAmortizacion Then + ' Amortizacion = LblAmortizacion.Text.Trim.ToDecimal + ' TxtSubTotal.Text = (TxtSubTotal.Text.ToDouble + Amortizacion).ToString + 'End If + + + TempSubTotal = SubTotal + SubTotalOriginal = SubTotal + SubTotal2Original = SubTotal2 + TempDescuentos = Descuento + Amortizacion + TempSubTotal2 = TempSubTotal - TempDescuentos + TempIVA = IVA + TempIEPS = IEPS + TempRetIVA = RetIVA + TempRetISR = RetISR + TempTotal = Math.Round(TempSubTotal2 + TempIVA + TempIEPS - TempRetIVA - TempRetISR + OtrosImpuestos - Amortizacion, 2) + DifTotales = Total - TempTotal + Dim DiferenciaPermitida As Decimal = 0.6D + + If Math.Abs(DifTotales) > DiferenciaPermitida Then + Errores.AppendLine($"Los importes de los conceptos (Productos/Servicios) no cuadran con el total. Por favor verifique y vuelva a intentar.[{Math.Abs(DifTotales) - DiferenciaPermitida}]") + EsValido = False + ElseIf DifTotales <> 0 Then + SubTotal2 = (SubTotal2 + DifTotales) + SubTotal = (SubTotal + DifTotales) + SubTotalOriginal = SubTotal + SubTotal2Original = SubTotal2 + End If + + Dim DiferenciaSubtotales As Decimal = 0 + If CveCompra > 0 Or CveFactura > 0 Or OCVinculada Then + + If SubTotalOriginal = Nothing Then + SubTotalOriginal = 0 + End If + + If SubTotal2Original = Nothing Then + SubTotal2Original = 0 + End If + + DiferenciaSubtotales = SubTotal2Original.ToString.ToDecimal - TmpDT.SUM("Total").ToString.ToDecimal + '[IPP] PARCHE: Factura TELMEX para APH 12/ENERO/2018 + If CveFactura = 286290 Then + DiferenciaSubtotales += Descuento + End If + If Math.Abs(DiferenciaSubtotales) > 1 And Not CompraNoDeducible = 1 Then 'EsNoDeducible + Errores.AppendLine("Los importes de los conceptos (Productos/Servicios) no cuadran con el total. Por favor verifique y vuelva a intentar.") + EsValido = False + Else + AjustaImporteUltimoConcepto(DiferenciaSubtotales) + End If + Else + DiferenciaSubtotales = (SubTotal2 - TmpDT.SUMD("Total")).ToString.ToDecimal + If Math.Abs(DiferenciaSubtotales) > 1 Then + Errores.AppendLine("Los importes de los conceptos (Productos/Servicios) no cuadran con el total. Por favor verifique y vuelva a intentar.") + EsValido = False + Else + AjustaImporteUltimoConcepto(DiferenciaSubtotales) + End If + End If + + Return EsValido + End Function + + + + Private Function AjustaCombustibles() As Boolean + + Dim Respuesta As Boolean = False + + Dim IVADetalles As Decimal = TmpDT.SUMD("IVA", " IVA > 0 ") + Dim DiferenciaIVas As Decimal = IVA - IVADetalles + + + If Not TmpDT.Columns.Contains("AplicaIEPS") Then + TmpDT.Columns.Add(New DataColumn("AplicaIEPS", GetType(Boolean))) + End If + + If Not TmpDT.Columns.Contains("IEPSGrabaIVA") Then + TmpDT.Columns.Add(New DataColumn("IEPSGrabaIVA", GetType(Boolean))) + End If + + For Each dRow As DataRow In TmpDT.Rows + Dim DttPS As DataTable = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=dRow("CvePS").ToString.ToEntero) + If DttPS IsNot Nothing AndAlso DttPS.Rows.Count > 0 Then + Dim DrPS As DataRow = DttPS.Rows(0) + dRow("AplicaIEPS") = Boolean.Parse(DrPS("AplicaIEPS").ToString) + dRow("IEPSGrabaIVA") = Boolean.Parse(DrPS("IEPSGrabaIVA").ToString) + Else + dRow("AplicaIEPS") = False + dRow("IEPSGrabaIVA") = False + End If + Next + + Dim DTConsulta As New DataTable + DTConsulta = TmpDT.FiltraParametros(" AplicaIEPS = 'True' AND IEPSGrabaIVA = 'False' AND IVA > 0 ") + + If DTConsulta.Rows.Count > 0 Then + + Dim IndiceContador As Integer = 0 + Dim IndiceUltimo As Integer = 0 + Dim CantidadRegistroConIVA As Decimal + + For Each dRow As DataRow In TmpDT.Rows + If Boolean.Parse(dRow("AplicaIEPS").ToString) And Boolean.Parse(dRow("IEPSGrabaIVA").ToString) = False And dRow("IVA").ToString.ToDecimal > 0 Then + IndiceUltimo = IndiceContador + CantidadRegistroConIVA = CantidadRegistroConIVA + 1 + End If + IndiceContador = IndiceContador + 1 + Next + + IVADetalles = TmpDT.SUMD("IVA", " IVA > 0 ") + DiferenciaIVas = IVA - IVADetalles + + If Math.Abs(DiferenciaIVas) > 0.01D Then + + If (TmpDT.Rows(IndiceUltimo)("IVA").ToString.ToDecimal + DiferenciaIVas) < 0 Then + + Dim AjusteteDividido As Decimal = Math.Abs(DiferenciaIVas) / CantidadRegistroConIVA + + For Each dRow As DataRow In TmpDT.Rows + If Boolean.Parse(dRow("AplicaIEPS").ToString) And Boolean.Parse(dRow("IEPSGrabaIVA").ToString) = False And dRow("IVA").ToString.ToDecimal > 0 Then + dRow("IVA") = dRow("IVA").ToString.ToDecimal - AjusteteDividido + End If + Next + Else + TmpDT.Rows(IndiceUltimo)("IVA") = TmpDT.Rows(IndiceUltimo)("IVA").ToString.ToDecimal + DiferenciaIVas + End If + TmpDT.AcceptChanges() + End If + + End If + + 'Revalidacion de ajuste + IVADetalles = TmpDT.SUMD("IVA", " IVA > 0 ") + DiferenciaIVas = IVA - IVADetalles + + If Math.Abs(DiferenciaIVas) > 0.01D Then + Respuesta = False + If IVADetalles > 0 Then + + For Each dRow As DataRow In TmpDT.Rows + If dRow("IVA").ToString.ToDecimal > 0 Then + dRow("IVA") = dRow("IVA").ToString.ToDecimal + DiferenciaIVas + TmpDT.AcceptChanges() + Respuesta = True + Exit For + End If + Next + Else + Alert("Los productos especificados en el listado no tienen asignado impuesto IVA, favor de realizar la corrección en el producto que aplique el impuesto.", TipoMensaje.MsgAdvertencia) + Respuesta = False + End If + Else + Respuesta = True + End If + + If Respuesta Then + + Dim IEPSPSDetalles As Decimal = TmpDT.SUMD("IEPSPS", " IEPSPS > 0 ") + Dim DiferenciaIEPSPS As Decimal = IEPS - IEPSPSDetalles + + Dim DTConsultaIEPSPS As New DataTable + DTConsultaIEPSPS = TmpDT.FiltraParametros(" AplicaIEPS = 'True'") + Dim IndiceContador As Integer = 0 + Dim IndicePrimero As Integer = 0 + + For Each dRow As DataRow In TmpDT.Rows + If Boolean.Parse(dRow("AplicaIEPS").ToString) And dRow("IEPSPS").ToString.ToDecimal > 0 Then + IndicePrimero = IndiceContador + Exit For + End If + IndiceContador = IndiceContador + 1 + Next + If DiferenciaIEPSPS.RoundSQL(2) <> 0 Then + + TmpDT.Rows(IndicePrimero)("IEPSPS") = TmpDT.Rows(IndicePrimero)("IEPSPS").ToString.ToDecimal + DiferenciaIEPSPS + TmpDT.AcceptChanges() + End If + + For Each dRow As DataRow In TmpDT.Rows + If dRow("IEPSPSPorcentaje").ToString.ToDecimal > 0 AndAlso dRow("IEPSPS").ToString.ToDecimal = 0 Then + dRow("IEPSPSPorcentaje") = 0 + End If + Next + TmpDT.AcceptChanges() + End If + + Return Respuesta + + End Function + + + Private Function AjustaIVA() As Boolean + + Dim Respuesta As Boolean = False + + Dim IVADetalles As Decimal = TmpDT.SUMD("IVA", " IVA > 0 ") + Dim DiferenciaIVas As Decimal = IVA - IVADetalles + + If Math.Abs(DiferenciaIVas) > 0 Then + If Math.Abs(DiferenciaIVas) <= 0.05 Then + + Dim DTConsulta As New DataTable + DTConsulta = TmpDT.FiltraParametros(" IVA > 0 ") + + If DTConsulta.Rows.Count > 0 Then + + Dim IndiceContador As Integer = 0 + Dim IndiceUltimo As Integer = 0 + Dim CantidadRegistroConIVA As Decimal + + For Each dRow As DataRow In TmpDT.Rows + If dRow("IVA").ToString.ToDecimal > 0 Then + IndiceUltimo = IndiceContador + CantidadRegistroConIVA = CantidadRegistroConIVA + 1 + End If + IndiceContador = IndiceContador + 1 + Next + + IVADetalles = TmpDT.SUMD("IVA", " IVA > 0 ") + DiferenciaIVas = IVA - IVADetalles + + If Math.Abs(DiferenciaIVas) > 0.0D Then + + If (TmpDT.Rows(IndiceUltimo)("IVA").ToString.ToDecimal + DiferenciaIVas) < 0 Then + + Dim AjusteteDividido As Decimal = Math.Abs(DiferenciaIVas) / CantidadRegistroConIVA + + For Each dRow As DataRow In TmpDT.Rows + dRow("IVA") = dRow("IVA").ToString.ToDecimal - AjusteteDividido + Next + Else + TmpDT.Rows(IndiceUltimo)("IVA") = TmpDT.Rows(IndiceUltimo)("IVA").ToString.ToDecimal + DiferenciaIVas + End If + TmpDT.AcceptChanges() + End If + End If + + 'Revalidacion de ajuste + IVADetalles = TmpDT.SUMD("IVA", " IVA > 0 ") + DiferenciaIVas = IVA - IVADetalles + + If Math.Abs(DiferenciaIVas) > 0.01D Then + Respuesta = False + If IVADetalles > 0 Then + + For Each dRow As DataRow In TmpDT.Rows + If dRow("IVA").ToString.ToDecimal > 0 Then + dRow("IVA") = dRow("IVA").ToString.ToDecimal + DiferenciaIVas + TmpDT.AcceptChanges() + Respuesta = True + Exit For + End If + Next + + Else + Errores.AppendLine("Los productos especificados en el listado no tienen asignado impuesto IVA, favor de realizar la corrección en el producto que aplique el impuesto.") + Respuesta = False + End If + Else + Respuesta = True + End If + + Else + Errores.AppendLine($"existe una diferencia de {DiferenciaIVas} entre el IVA de la compra y los detalles.") + Respuesta = False + End If + Else + Respuesta = True + End If + + Return Respuesta + + End Function + + Private Function AjustaRetIVA() As Boolean + + Dim Respuesta As Boolean = False + + Dim RetIVADetalles As Decimal = TmpDT.SUMD("RetIVA", " RetIVA > 0 ") + Dim DiferenciaRetIVA As Decimal = RetIVA - RetIVADetalles + + If Math.Abs(DiferenciaRetIVA) > 0 Then + If Math.Abs(DiferenciaRetIVA) <= 0.05 Then + + Dim DTConsulta As New DataTable + DTConsulta = TmpDT.FiltraParametros(" RetIVA > 0 ") + + If DTConsulta.Rows.Count > 0 Then + + Dim IndiceContador As Integer = 0 + Dim IndiceUltimo As Integer = 0 + Dim CantidadRegistroConRetIVA As Decimal + + For Each dRow As DataRow In TmpDT.Rows + If dRow("RetIVA").ToString.ToDecimal > 0 Then + IndiceUltimo = IndiceContador + CantidadRegistroConRetIVA = CantidadRegistroConRetIVA + 1 + End If + IndiceContador = IndiceContador + 1 + Next + + RetIVADetalles = TmpDT.SUMD("RetIVA", " RetIVA > 0 ") + DiferenciaRetIVA = RetIVA - RetIVADetalles + + If Math.Abs(DiferenciaRetIVA) > 0.0D Then + + If (TmpDT.Rows(IndiceUltimo)("RetIVA").ToString.ToDecimal + DiferenciaRetIVA) < 0 Then + + Dim AjusteteDividido As Decimal = Math.Abs(DiferenciaRetIVA) / CantidadRegistroConRetIVA + + For Each dRow As DataRow In TmpDT.Rows + dRow("RetIVA") = dRow("RetIVA").ToString.ToDecimal - AjusteteDividido + Next + + Else + TmpDT.Rows(IndiceUltimo)("RetIVA") = TmpDT.Rows(IndiceUltimo)("RetIVA").ToString.ToDecimal + DiferenciaRetIVA + End If + + TmpDT.AcceptChanges() + + End If + + End If + + 'Revalidacion de ajuste + RetIVADetalles = TmpDT.SUMD("RetIVA", " RetIVA > 0 ") + DiferenciaRetIVA = RetIVA - RetIVADetalles + + If Math.Abs(DiferenciaRetIVA) > 0.01D Then + Respuesta = False + If RetIVADetalles > 0 Then + + For Each dRow As DataRow In TmpDT.Rows + If dRow("RetIVA").ToString.ToDecimal > 0 Then + dRow("RetIVA") = dRow("RetIVA").ToString.ToDecimal + DiferenciaRetIVA + TmpDT.AcceptChanges() + Respuesta = True + Exit For + End If + Next + + Else + Errores.AppendLine("Los productos especificados en el listado no tienen asignado impuesto RetIVA, favor de realizar la corrección en el producto que aplique el impuesto.") + Respuesta = False + End If + Else + Respuesta = True + End If + + Else + Errores.AppendLine($"existe una diferencia de {DiferenciaRetIVA} entre el RetIVA de la compra y los detalles.") + End If + Else + Respuesta = True + + End If + + Return Respuesta + + End Function + + Private Function AjustaRetISR() As Boolean + + Dim Respuesta As Boolean = False + + Dim RetISRDetalles As Decimal = TmpDT.SUMD("RetISR", " RetISR > 0 ") + Dim DiferenciaRetISR As Decimal = RetISR - RetISRDetalles + + If Math.Abs(DiferenciaRetISR) > 0 Then + If Math.Abs(DiferenciaRetISR) <= 0.05 Then + + Dim DTConsulta As New DataTable + DTConsulta = TmpDT.FiltraParametros(" RetISR > 0 ") + + If DTConsulta.Rows.Count > 0 Then + + Dim IndiceContador As Integer = 0 + Dim IndiceUltimo As Integer = 0 + Dim CantidadRegistroConRetISR As Decimal + + For Each dRow As DataRow In TmpDT.Rows + If dRow("RetISR").ToString.ToDecimal > 0 Then + IndiceUltimo = IndiceContador + CantidadRegistroConRetISR = CantidadRegistroConRetISR + 1 + End If + IndiceContador = IndiceContador + 1 + Next + + RetISRDetalles = TmpDT.SUMD("RetISR", " RetISR > 0 ") + DiferenciaRetISR = RetISR - RetISRDetalles + + If Math.Abs(DiferenciaRetISR) > 0.0D Then + + If (TmpDT.Rows(IndiceUltimo)("RetISR").ToString.ToDecimal + DiferenciaRetISR) < 0 Then + + Dim AjusteteDividido As Decimal = Math.Abs(DiferenciaRetISR) / CantidadRegistroConRetISR + + For Each dRow As DataRow In TmpDT.Rows + dRow("RetISR") = dRow("RetISR").ToString.ToDecimal - AjusteteDividido + Next + + Else + TmpDT.Rows(IndiceUltimo)("RetISR") = TmpDT.Rows(IndiceUltimo)("RetISR").ToString.ToDecimal + DiferenciaRetISR + End If + + TmpDT.AcceptChanges() + + End If + + End If + + 'Revalidacion de ajuste + RetISRDetalles = TmpDT.SUMD("RetISR", " RetISR > 0 ") + DiferenciaRetISR = RetISR - RetISRDetalles + + If Math.Abs(DiferenciaRetISR) > 0.01D Then + Respuesta = False + If RetISRDetalles > 0 Then + + For Each dRow As DataRow In TmpDT.Rows + If dRow("RetISR").ToString.ToDecimal > 0 Then + dRow("RetISR") = dRow("RetISR").ToString.ToDecimal + DiferenciaRetISR + TmpDT.AcceptChanges() + Respuesta = True + Exit For + End If + Next + + Else + Errores.AppendLine("Los productos especificados en el listado no tienen asignado impuesto RetISR, favor de realizar la corrección en el producto que aplique el impuesto.") + Respuesta = False + End If + Else + Respuesta = True + End If + + Else + Errores.AppendLine($"existe una diferencia de {DiferenciaRetISR} entre el RetISR de la compra y los detalles.") + Respuesta = False + End If + Else + Respuesta = True + End If + + Return Respuesta + + End Function + + Private Function AgregaIEPSReembolso(CvePS As Integer) As Boolean + + Dim respuesta As Boolean = True + + If IEPSGasto Or OtrosImpuestosGasto Then + + 'AGREGA IEPS COMO CONCEPTO + If IEPSGasto Then + AgregarConceptoIEPS(TrasladoIEPS, CvePS) + For Each Dr As DataRow In TmpDT.Rows + Dr("IEPSPS") = 0 + Dr("IEPSPSPorcentaje") = 0 + Next + TmpDT.AcceptChanges() + End If + 'AGREGA OTROS IMPUESTOS COMO CONCEPTO + If OtrosImpuestosGasto Then + AgregarConceptoIEPS(OtrosImpuestos, CvePS) + End If + Else + respuesta = False + Errores.AppendLine("Debe seleccionar al menos un impuesto. ") + End If + CalculaTotales() + + Return respuesta + + End Function + + + Private Sub AgregarConceptoIEPS(IEPS As Decimal, CvePS1 As Integer) + Dim SubTotalR As Decimal = TmpDT.SUM("Total").ToString.ToDecimal + + Dim PSS As DataTable = GlobalDTPS(UsuarioActual.CveEmpresa).FiltraParametros(String.Format("CvePS = {0} ", CvePS1), "PS") + Dim PSS2 As DataTable = TmpDT.FiltraParametros(String.Format("CvePS = {0} ", CvePS1), "PS") + + If PSS.Rows.Count > 0 Or PSS2.Rows.Count > 0 Then + Dim CveUM As Integer = 0 + Dim UM As String = "" + Dim CveClasificacion As Integer = 0 + Dim Clasificacion As String = "" + Dim CvePS As Integer = 0 + Dim PS As String = "" + Dim CveTipoPS As Integer = 0 + + If PSS.Rows.Count > 0 Then + CveUM = PSS.Rows(0)("CveUM").ToString.ToEntero + UM = PSS.Rows(0)("UnidadMedida").ToString + CveClasificacion = PSS.Rows(0)("CveClasificacion").ToString.ToEntero + Clasificacion = PSS.Rows(0)("Clasificacion").ToString + CvePS = PSS.Rows(0)("CvePS").ToString.ToEntero + PS = PSS.Rows(0)("PS").ToString + CveTipoPS = PSS.Rows(0)("CveTipoPS").ToString.ToEntero + End If + + Dim Cantidad As Decimal = 1 + Dim CveSubProyectoContrato As String = "-1" + Dim CveProyecto As String = "-1" + Dim SubProyecto As String = "SE" + Dim Proyecto As String = "SE" + Dim Obs As String = "" + Dim PU As Decimal = IEPS + Dim Total As Decimal = Cantidad * PU + Dim IVA As Decimal = 0 + Dim Descuento As Decimal = 0 + + If PSS2.Rows.Count > 0 Then + CveUM = PSS2.Rows(0)("CveUM").ToString.ToEntero + UM = PSS2.Rows(0)("UM").ToString + CveClasificacion = PSS2.Rows(0)("CveClasificacion").ToString.ToEntero + Clasificacion = PSS2.Rows(0)("Clasificacion").ToString + CvePS = PSS2.Rows(0)("CvePS").ToString.ToEntero + PS = PSS2.Rows(0)("PS").ToString + CveTipoPS = PSS2.Rows(0)("CveTipoPS").ToString.ToEntero + + CveSubProyectoContrato = PSS2.Rows(0)("CveSubProyecto").ToString + CveProyecto = PSS2.Rows(0)("CveProyecto").ToString + SubProyecto = PSS2.Rows(0)("SubProyecto").ToString + Proyecto = PSS2.Rows(0)("Proyecto").ToString + Obs = PSS2.Rows(0)("Obs").ToString + + Dim CveTipoGasto As Integer = PSS2.Rows(0)("CveTipoGasto").ToString.ToEntero + Dim TipoGasto As String = PSS2.Rows(0)("TipoGasto").ToString + + AddPS(Cantidad, CveUM, UM, CveClasificacion, Clasificacion, CvePS, PS, CveTipoPS, CveSubProyectoContrato, SubProyecto, Proyecto, CveProyecto, Obs, PU, Total, IVA, 0, 0, 0, 0, Descuento, TCalculaTotales:=False, CveTipoGasto:=CveTipoGasto, + TipoGasto:=TipoGasto, ModalidadAccionPS:=EnumModalidadAccionPS.Agregar) + + Else + AddPS(Cantidad, CveUM, UM, CveClasificacion, Clasificacion, CvePS, PS, CveTipoPS, CveSubProyectoContrato, SubProyecto, Proyecto, CveProyecto, Obs, PU, Total, IVA, 0, 0, 0, 0, Descuento, TCalculaTotales:=False) + End If + End If + + Dim SubTotalIEPS As Decimal = TmpDT.SUMD("Total") + + Me.SubTotal = Math.Round(SubTotalIEPS, 2) + Me.SubTotalConceptos = Math.Round(SubTotalIEPS, 2) + + PSS.Dispose() + End Sub + + Private Function AddPS(Cantidad As Decimal, CveUM As Integer, UM As String, CveClasificacion As Integer, Clasificacion As String, CvePS As Integer, PS As String, CveTipoPS As Integer, CveSubProyectoContrato As String, SubProyecto As String, Proyecto As String, CveProyecto As String, + Obs As String, PU As Decimal, Total As Decimal, IVA As Decimal, RetIVA As Decimal, RetISR As Decimal, IEPSPS As Decimal, IEPSPSIVA As Decimal, Descuento As Decimal, Optional CveOrdenCompraDetalle As Integer = -1, Optional TCalculaTotales As Boolean = True, + Optional PSCodigo As String = "-", Optional PSDescripcion As String = "-", Optional CantidadF As Double = -1, Optional EntregaDirecta As Integer = -1, Optional OtrosGastos As Decimal = 0, + Optional CveSATPS As Integer = -1, Optional CargaXml As Boolean = False, Optional CveTipoGasto As Integer = -1, Optional TipoGasto As String = "", Optional PorcentajeIVA As Decimal = 0, + Optional PorcentajeIEPS As Decimal = 0, Optional PorcentajeRetIVA As Decimal = 0, Optional PorcentajeRetISR As Decimal = 0, Optional NoDeducible As Boolean = False, Optional CveContratoDetalle As Integer = -1, Optional CveCultivoCuadroDetalle As Integer = -1, + Optional CveSATPSActualizado As Boolean = False, Optional TemporadaCuadro As String = "", Optional ModalidadAccionPS As EnumModalidadAccionPS = EnumModalidadAccionPS.Agregar, Optional Con As Integer = -1, + Optional CveProgramaOperativo As Integer = -1, Optional CveUnidadAdministrativa As Integer = -1, Optional CveFuenteFinanciamiento As Integer = -1, Optional CveTipoGastoAC As Integer = -1, Optional CveClasificacionOG As Integer = -1) As Integer + + Dim Row As DataRow = Nothing + + Row = TmpDT.NewRow() + Dim Retorno As Integer = 0 + Dim CveContrato As Integer = -1 + Dim CveSubProyecto As Integer = -1 + Dim Valores As String() + + ''CONTRATOS + If CveSubProyectoContrato.Contains("|"c) Then + Valores = CveSubProyectoContrato.Split("|"c) + CveContrato = Valores(1).ToEntero + CveSubProyecto = Valores(0).ToEntero + Else + CveSubProyecto = CveSubProyectoContrato.ToEntero + End If + + 'DR PS + Dim DrPS As DataRow = Nothing + If CvePS > 0 Then + DrPS = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePS).Rows(0) + End If + + If DrPS IsNot Nothing Then + Row("PSCodigo") = If(PSCodigo = "", DrPS("PSCodigo").ToString, PSCodigo) + Row("CveMetodoInventario") = DrPS("Inv_CveMetodoInventario").ToString.ToEntero + + If CveTipoCompra = EnumTipoCompra.Garantia AndAlso DrPS("AplicaSerie").ToString = "True" Then + Row("CveMetodoInventario") = "1" + End If + + Else + Row("PSCodigo") = PSCodigo + Row("CveMetodoInventario") = 0 + End If + + If ModalidadAccionPS = EnumModalidadAccionPS.Actualizar Then + Row("Consec") = Con + Else + Row("Consec") = TmpDT.Rows.Count + 1 + End If + + If (CFDIVersion = EnumCFDIVersion.v33 Or CFDIVersion = EnumCFDIVersion.v40) And CveSATPS > 0 Then + Dim DrPSSAT As DataRow = Nothing + If CargaXml Then + DrPSSAT = GlobalDTPSATPS("-1", CveSATPS.ToString).FiltroPrimero("") + Else + DrPSSAT = GlobalDTPSATPS("-1", CveSATPS.ToString).FiltroPrimero("") + End If + If DrPSSAT IsNot Nothing Then + Row("SATClaveProductoServicio") = DrPSSAT("SATClaveProductoServicio").ToString + Row("CveSATPS") = DrPSSAT("CveSATPS").ToString + If CveSATPSActualizado Then + Row("CveSATPSActualizado") = 1 + Else + Row("CveSATPSActualizado") = 0 + End If + End If + End If + + Try + If (DrPS("CvePSCargo").ToString <> "") Then 'si es un producto de usado. que se registre contablemente como alamcen(como producto) + CveTipoPS = 2 + End If + Catch ex As Exception + + End Try + + Dim DecimalesPermitidos As Integer = 6 + + Row("CveConcepto") = TmpDT.Rows.Count + 1 + Row("Cantidad") = Math.Round(Cantidad, DecimalesPermitidos) + Row("CantidadF") = If(CantidadF = -1, Math.Round(Cantidad, DecimalesPermitidos), Math.Round(CantidadF, DecimalesPermitidos)) + Row("CveUM") = CveUM + Row("UM") = UM + Row("CveClasificacion") = CveClasificacion + Row("CveClasificacionActualizar") = CveClasificacion + Row("Clasificacion") = Clasificacion + Row("CvePS") = CvePS + Row("PS") = PS + Row("CveTipoPS") = CveTipoPS + + Row("PSDescripcion") = PSDescripcion + Row("CveSubProyecto") = CveSubProyecto.ToEntero + Row("CveProyecto") = CveProyecto.ToEntero + Row("CveContrato") = CveContrato.ToEntero + Row("SubProyecto") = If(SubProyecto = "Seleccione", "Sin Sub Proyecto", SubProyecto) + Row("Proyecto") = If(Proyecto = "Seleccione", "Sin Proyecto", Proyecto) + Row("CveActivoFijo") = -1 + Row("Obs") = Obs + Row("CveActivoFijo") = -1 + Row("CodAF") = "-1" + Row("TipoAF") = -1 + Row("CveOrdenCompraDetalle") = CveOrdenCompraDetalle + Row("EntregaDirecta") = EntregaDirecta + + Row("NoDeducible") = NoDeducible + + + Total = Math.Round(PU, DecimalesPermitidos) * Cantidad - Descuento + Row("PU") = Math.Round(PU, DecimalesPermitidos) + If CargaXml And (CFDIVersion = EnumCFDIVersion.v33 Or CFDIVersion = EnumCFDIVersion.v40) Then + + If CveFactura > 0 And IVA = 0 Then + Row("IVA") = 0 + Row("IVAPorcentaje") = 0 + Else + Row("IVA") = Math.Round(IVA, DecimalesPermitidos) + Row("IVAPorcentaje") = PorcentajeIVA + End If + + Row("RetIVA") = Math.Round(RetIVA, DecimalesPermitidos) + Row("RetIVAPorcentaje") = PorcentajeRetIVA + Row("RetISR") = Math.Round(RetISR, DecimalesPermitidos) + Row("RetISRPorcentaje") = PorcentajeRetISR + Row("IEPSPS") = Math.Round(IEPSPS, DecimalesPermitidos) + Row("IEPSPSPorcentaje") = PorcentajeIEPS + Else + 'If DdlIVA.SelectedValue.ToDouble = 0 Then Row("IVA") = 0 Else Row("IVA") = Math.Round(IVA * Total, DecimalesPermitidos) + + If CveFactura > 0 And IVA = 0 Then + Row("IVA") = 0 + Row("IVAPorcentaje") = 0 + Else + Row("IVA") = (PorcentajeIVA * Total).RoundSQL + Row("IVAPorcentaje") = PorcentajeIVA + End If + + Row("RetIVA") = (PorcentajeRetIVA * Total).RoundSQL + Row("RetIVAPorcentaje") = PorcentajeRetIVA + Row("RetISR") = (PorcentajeRetISR * Total).RoundSQL + Row("RetISRPorcentaje") = PorcentajeRetISR + Row("IEPSPS") = (PorcentajeIEPS * Total).RoundSQL + Row("IEPSPSPorcentaje") = PorcentajeIEPS + End If + + Row("ImporteConImpuestos") = (Row("Cantidad").ToString.ToDecimal * Row("PU").ToString.ToDecimal) + Row("IVA").ToString.ToDecimal + Row("IEPSPS").ToString.ToDecimal - (Row("RetIVA").ToString.ToDecimal + Row("RetISR").ToString.ToDecimal) + Row("ImporteSinImpuestos") = Row("Cantidad").ToString.ToDecimal * Row("PU").ToString.ToDecimal + + Row("IEPSPSIVA") = Math.Round(IEPSPSIVA * Total, DecimalesPermitidos) + Row("IEPSPSIVAPorcentaje") = IEPSPSIVA + Row("Descuento") = Math.Round(Descuento, DecimalesPermitidos) + Row("OtrosGastos") = Math.Round(OtrosGastos, DecimalesPermitidos) + Row("Total") = Math.Round(Total, DecimalesPermitidos) + + Row("CveTipoGasto") = CveTipoGasto + Row("TipoGasto") = If(CveTipoGasto > 0, TipoGasto, "") + + Row("CveContratoDetalle") = CveContratoDetalle + + Row("CveCultivoCuadroDetalle") = CveCultivoCuadroDetalle + Row("TemporadaCuadro") = TemporadaCuadro + + If UsuarioActual.Empresa.UsaAC Then + Row("CveProgramaOperativo") = CveProgramaOperativo + Row("CveUnidadAdministrativa") = CveUnidadAdministrativa + Row("CveFuenteFinanciamiento") = CveFuenteFinanciamiento + Row("CveTipoGastoAC") = CveTipoGastoAC + Row("CveClasificacionOG") = CveClasificacionOG + End If + 'Esta parte es para validar cuando la factura tenga ieps en o se asignara el ieps como una partida ya no se considere + If (CveFactura > 0 Or CveCompra > 0) And IEPS = 0 Then + Row("IEPSPS") = 0 + Row("IEPSPSPorcentaje") = 0 + End If + TmpDT.Rows.Add(Row) + TmpDT.Rows.IndexOf(Row) + + If TCalculaTotales Then + CalculaTotales(True) + End If + + Return Retorno + End Function + + Private Sub CalculaTotales(Optional CalculaIVA As Boolean = False, Optional EsNoDeducible As Boolean = False) + 'VARIABLES DE CALCULO + Dim LocalSubTotal, LocalDescuentos, LocalAmortizacion, LocalIVA, LocalSubTotal2, LocalRetIVA, LocalRetISR, LocalIEPSPS, LocalTotal, LocalSubTotalIVA, LocalSubTotalIEPSIVA As Decimal + + 'HACEMOS CALCULOS + LocalSubTotalIVA = TmpDT.SUMD("IVA") + LocalSubTotalIEPSIVA = TmpDT.SUMD("IEPSPSIVA") + LocalSubTotal = (TmpDT.SUMD("Total") + TmpDT.SUMD("Descuento")).RoundSQL(8) + LocalRetIVA = TmpDT.SUMD("RetIVA") + LocalRetISR = TmpDT.SUMD("RetISR") + LocalIEPSPS = TmpDT.SUMD("IEPSPS") + + If CveCompra > 0 AndAlso CveFactura > 0 Then + LocalIVA = IVA + Else + LocalIVA = If(TmpDT.SUM("IVA") > 0, LocalSubTotalIVA + LocalSubTotalIEPSIVA, 0) + End If + + LocalDescuentos = TmpDT.SUMD("Descuento") + + If Not CveCompra > 0 Then + LocalAmortizacion = Me.Amortizacion + End If + + 'RETENCIONES + Dim Retenciones As Decimal = 0 + Retenciones = LocalRetIVA + Retenciones += LocalRetISR + + + LocalSubTotal2 = LocalSubTotal - LocalDescuentos + LocalTotal = LocalSubTotal2 + LocalIVA + LocalIEPSPS - Retenciones + + 'ASIGNAMOS VALORES A VISTA + If CveCompra > 0 Or CveFactura > 0 Or Me.OCVinculada Then + SubTotal = LocalSubTotal + SubTotal2 = LocalSubTotal2 + Descuento = LocalDescuentos + + If EsNoDeducible Then + IVA = LocalIVA + RetIVA = LocalRetIVA + RetISR = LocalRetISR + IEPS = LocalIEPSPS + End If + + Total = LocalTotal + Else + SubTotal = LocalSubTotal + SubTotal2 = LocalSubTotal2 + IVA = LocalIVA + Descuento = LocalDescuentos + RetIVA = LocalRetIVA + RetISR = LocalRetISR + IEPS = LocalIEPSPS + Total = LocalTotal + 'VALORES PROPIEDAD + CompraSaldo = LocalTotal + + End If + Me.NumNoDed = TmpDT.COUNT("CvePS", "NoDeducible = True ") + + End Sub + + Private Function UpdatePSReembolso(Index As Integer, CvePS As Integer) As Boolean + + Dim Respuesta As Boolean = True + + Dim DrPS As DataRow = Nothing + Try + DrPS = TmpDT.Select($"Consec = {Index}")(0) + If DrPS Is Nothing Then + Errores.AppendLine($"No se encontrol el producto con index {Index}") + Return False + End If + Catch ex As Exception + Errores.AppendLine($"No se encontrol el producto con index {Index}") + Return False + End Try + + 'DATOS GENERALES + DrPS("Obs") = "" + DrPS("Proyecto") = Proyecto + DrPS("CveProyecto") = CveProyecto + DrPS("SubProyecto") = SubProyecto + DrPS("CveSubProyecto") = CveSubProyecto + DrPS("CveContratoDetalle") = -1 + + 'IMPORTES - [CANTIDAD Y PRECIO] + Dim Cantidad As Double = DrPS("Cantidad").ToString.ToDouble + Dim PU As Double = DrPS("PU").ToString.ToDouble + Dim Descuento As Double = DrPS("Descuento").ToString.ToDouble + Dim Total As Double = (Cantidad * PU) - Descuento + DrPS("NoDeducible") = NoDeducible + + Dim PSRow As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePS).FiltroPrimero("") + If PSRow IsNot Nothing Then + Dim CveTipoPS As Integer = PSRow("CveTipoPS").ToString.ToEntero + If PSRow("CvePSCargo").ToString <> "" Then 'si es un producto de usado. que se registre contablemente como alamcen(como producto) + CveTipoPS = 2 + End If + + DrPS("CveClasificacion") = PSRow("CveClasificacion").ToString + DrPS("Clasificacion") = PSRow("Clasificacion").ToString + DrPS("CvePS") = CvePS + DrPS("PS") = PSRow("PS").ToString + DrPS("CveTipoPS") = CveTipoPS + DrPS("CveSATPS") = PSRow("CveSATPS").ToString.ToEntero + DrPS("SATClaveProductoServicio") = PSRow("SATClaveProductoServicio").ToString + DrPS("CveSATPSActualizado") = 0 + + DrPS("CveUM") = PSRow("CveUnidadMedida").ToString.ToEntero + DrPS("UM") = PSRow("UnidadMedida").ToString + + Dim DrTipoGasto As DataRow = Me.DTTiposGastos.FiltroPrimero("") + + DrPS("CveTipoGasto") = DrTipoGasto("CveTipoGasto") + DrPS("TipoGasto") = DrTipoGasto("TipoGasto") + + If UsuarioActual.Empresa.Funcionalidad(562).ToEntero > 0 Then + DrPS("AplicaCostoIndirecto") = "0" + End If + + DrPS("CveCultivoCuadroDetalle") = -1 + DrPS("TemporadaCuadro") = "" + + Else + Errores.AppendLine($"No se encontrol el producto con CvePS {CvePS}") + Respuesta = False + End If + TmpDT.AcceptChanges() + Return Respuesta + End Function + + Private Sub ValidacionesTotalesXml() + + If Not TmpDT.Columns.Contains("Amortizacion") Then + TmpDT.Columns.Add("Amortizacion", GetType(Decimal)) + End If + + Dim Msg As String = "" + Dim SubtotalTemp As Decimal = TmpDT.SUMD("Total") + Math.Round(TmpDT.SUM("Descuento") + Math.Round(TmpDT.SUM("Amortizacion")), 2) + Dim DescuentosTemp As Decimal = TmpDT.SUMD("Descuento") + Dim Subtotal2Temp As Decimal = TmpDT.SUMD("Total") + Dim IVATemp As Decimal = TmpDT.SUMD("IVA") + Dim IEPSTemp As Decimal = TmpDT.SUMD("IEPSPS") + Dim RetIVATemp As Decimal = TmpDT.SUMD("RetIVA") + Dim RetISRTemp As Decimal = TmpDT.SUMD("RetISR") + Dim TotalTemp As Decimal = Subtotal2Temp - RetIVATemp - RetISRTemp + Math.Round(IVATemp, 6) + IEPSTemp + OtrosImpuestos - OtrosImpuestosRetenciones + + If Math.Abs(Math.Round(DescuentosTemp, 6) - Math.Round(Descuento, 6)) > 0.01 Then + Msg &= String.Format("- Los descuentos del detalle no coinciden con el descuento general
    ") + End If + + If Math.Abs(Math.Round(IVATemp, 6) - Math.Round(TrasladoIVA, 6)) > 0.01 Then + Msg &= String.Format("- Los IVAS del detalle no coinciden con el IVA general
    ") + End If + + If Math.Abs(Math.Round(IEPSTemp, 6) - Math.Round(TrasladoIEPS, 6)) > 0.01 Then + Msg &= String.Format("- Los IEPS del detalle no coinciden con el IEPS general
    ") + End If + + If Math.Abs(Math.Round(RetIVATemp, 6) - Math.Round(RetencionIVA, 6)) > 0.01 Then + Msg &= String.Format("- Los RetIVA del detalle no coinciden con el RetIVA general
    ") + End If + + If Math.Abs(Math.Round(RetISRTemp, 6) - Math.Round(RetencionISR, 6)) > 0.01 Then + Msg &= String.Format("- Las RetISR del detalle no coinciden con el RetIVA general
    ") + End If + + If Math.Abs(Math.Round(TotalTemp, 2) - Math.Round(Total, 2)) > 0.01 Then + Msg &= String.Format("- El total generado por los detalles no coincide con el total general
    ({0}-{1})", Math.Round(TotalTemp, 2), Math.Round(Total, 2)) + End If + + If Msg <> "" Then + Errores.AppendLine($" El comprobante XML presenta las siguientes inconsistencias:{Msg}. ") + Else + + DescuentosTemp = Descuento + IVATemp = TrasladoIVA + TotalTemp = Total + RetIVATemp = RetencionIVA + RetISRTemp = RetencionISR + IEPSTemp = TrasladoIEPS + End If + + Me.SubTotal = SubtotalTemp + Me.Descuento = DescuentosTemp + Me.SubTotal2 = Subtotal2Temp + Me.IVA = IVATemp + Me.Total = TotalTemp + Me.RetIVA = RetIVATemp + Me.RetISR = RetISRTemp + Me.IEPS = IEPSTemp + CompraSaldo = TotalTemp + + AsignaValoresOriginales(SubtotalTemp, Subtotal2Temp, IVATemp, RetIVATemp, RetISRTemp, Total) + + End Sub + + Private Sub AsignaValoresOriginales(SubTotal As Decimal, SubTotal2 As Double, IVA As Decimal, RetIVA As Decimal, RetISR As Decimal, Total As Decimal) + SubTotalOriginal = SubTotal + SubTotal2Original = SubTotal2 + IVAOriginal = IVA + RetIVAOriginal = RetIVA + RetISROriginal = RetISR + TotalOriginal = Total + End Sub + + Private Sub AjustaImporteUltimoConcepto(ImporteAjuste As Decimal, Optional EsCarga As Boolean = False) + + If ImporteAjuste = 0 Then Exit Sub + + Dim Amortizacion As Decimal = 0 + + If TmpDT.Rows.Count > 0 Then ' si hay movimientos y si esta afectando al total, que se haga el ajuste + Dim Indice As Integer = If(TmpDT.Rows(TmpDT.Rows.Count - 1)("CvePS").ToString = UsuarioActual.Empresa.Funcionalidad(112).ToString, TmpDT.Rows.Count - 2, TmpDT.Rows.Count - 1) + Dim tPU As Decimal + + If TmpDT.Rows(Indice)("Cantidad").ToString.ToDecimal > 0 Then + tPU = ImporteAjuste / TmpDT.Rows(Indice)("Cantidad").ToString.ToDecimal + Else + tPU = 0 + End If + + If TmpDT.Rows(Indice)("PU").ToString.ToDecimal + tPU < 0 Then 'si es negativo, que tome el dato anterior + Indice = Indice - 1 + If TmpDT.Rows(Indice)("Cantidad").ToString.ToDecimal > 0 Then + tPU = ImporteAjuste / TmpDT.Rows(Indice)("Cantidad").ToString.ToDecimal + Else + tPU = 0 + End If + End If + + TmpDT.Rows(Indice)("PU") = TmpDT.Rows(Indice)("PU").ToString.ToDecimal + tPU + TmpDT.Rows(Indice)("Total") = TmpDT.Rows(Indice)("Total").ToString.ToDecimal + ImporteAjuste + TmpDT.Rows(Indice)("IEPSPS") = (TmpDT.Rows(Indice)("Total").ToString.ToDecimal() * TmpDT.Rows(Indice)("IEPSPSPorcentaje").ToString.ToDecimal()).RoundAD(2) + TmpDT.Rows(Indice)("IVA") = (TmpDT.Rows(Indice)("PU").ToString.ToDecimal * TmpDT.Rows(Indice)("Cantidad").ToString.ToDecimal - TmpDT.Rows(Indice)("Descuento").ToString.ToDecimal) * TmpDT.Rows(Indice)("IVAPorcentaje").ToString.ToDecimal + TmpDT.AcceptChanges() + End If + + SubTotal = TmpDT.SUMD("Total") + If Not EsCarga Then + Descuento = TmpDT.SUMD("Descuento") + End If + + SubTotalConceptos = SubTotal + + End Sub + + Public Function ValidateUUID(ByVal uuid As String) As Boolean + Dim pattern As String = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$" + Dim regex As New Regex(pattern) + Return regex.IsMatch(uuid) + End Function + Private Function GeneraStringDoctosRelacionados() As String + + Dim DoctosRelacionados As String = "-1" + Dim listaUUIDSRelacionados As New List(Of String) + + If DocumentosRelacionadosUUIDSList.Count > 0 Then + For Each s As String In DocumentosRelacionadosUUIDSList + If s.Trim.Length > 0 Then + listaUUIDSRelacionados.Add(s.Trim) + End If + Next + End If + + If listaUUIDSRelacionados.Count > 0 Then + DoctosRelacionados = String.Join(",", listaUUIDSRelacionados.ToArray()) + End If + + Return DoctosRelacionados + End Function + Private Function ValorXML(n As XmlNode, Campo As String, Optional Retorno As String = "") As String + Dim o As XmlNode = n.Attributes.Cast(Of XmlAttribute)().SingleOrDefault(Function(a) String.Compare(a.Name, Campo, True) = 0) + If o Is Nothing Then + Return Retorno + Else + Return o.Value + End If + End Function + + Public Function AddCompra(Optional ByRef transacccion As SqlTransaction = Nothing) As Boolean + + If Not AjustesValidacion() Then Return False + + Dim respuesta As Boolean = True + Dim ObjCompras As ClsCompras + + If transacccion IsNot Nothing Then + ObjCompras = New ClsCompras(transacccion) + Else + ObjCompras = New ClsCompras + End If + Dim ObjConta As New ClsContabilidad(ObjCompras.IniciaTransacSQL()) + + If Not AddPrePolizaCabecera(ObjConta) Then + respuesta = False + End If + + If respuesta AndAlso ObjCompras.AddCompra(Me.TipoDocto, Me.Descripcion, Me.Serie, Me.Folio, Me.FolioSecundario, Me.CveProveedor, Me.SubTotal, Me.Descuento, + Me.Amortizacion, Me.IVA, Me.RetIVA, Me.RetISR, Me.IEPS, Me.OtrosImpuestos, + Me.Redondeo, Me.Total, Me.Fecha, Me.CveMoneda, Me.TipoCambio, If(Me.FechaPago = Nothing, Me.Fecha, Me.FechaPago), Me.AplicaNotaCredito, Me.Observaciones, Me.CveEstatusFactura, + Me.CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, Me.IdPoliza, CveCajaChica:=Me.CveCajaChica, CvePersonal:=Me.CvePersonal, NumeroReembolso:=Me.NumeroReembolso, CveProveedorSucursal:=Me.CveProveedorSucursal, + AplicoPromocion:=Me.AplicoPromocion, PorcentajeIVA:=Me.PorcentajeIVA, CveMetodoPago:=Me.CveMetodoPago, CveRetIVAConcepto:=Me.CveRetIVAConcepto, + CveConceptoContableAlmacen:=Me.CveConceptoContableAlmacen, + CveRetISRConcepto:=Me.CveRetISRConcepto, NoDeducible:=Me.NoDeducible, CveTipoCompra:=Me.CveTipoCompra, TotalOriginal:=Me.TotalOriginal, CveTipoConcepto:=Me.CveTipoConcepto, + EsImportacion:=Me.EsImportacion, CveFactura:=Me.CveFactura, CveSubProyecto:=Me.CveSubProyectoPrincipal, DoctosRelacionados:=Me.DocumentosRelacionadosUUIDSString, CveFolioGarantia:=Me.CveFolioGarantia, + CveCompraRelacionada:=CveCompraRelacionada) Then + Me.CveCompra = ObjCompras.CveCompra + Else + respuesta = False + End If + + If respuesta AndAlso Me.CveCompra > 0 Then + + For Each Row As DataRow In Me.TmpDT.Rows + + Dim TipoRecepcion As Integer = -1 + Dim Referencia As String = "" + Dim EsNoDeducible As Boolean = False + Dim CveAF As Integer = If(Row("CveActivoFijo").ToString.ToEntero > 0 AndAlso Row("TipoAF").ToString.ToEntero = 1, Row("CveActivoFijo").ToString.ToEntero, -1) + Dim CveAFC As Integer = If(Row("CveActivoFijo").ToString.ToEntero > 0 AndAlso Row("TipoAF").ToString.ToEntero = 2, Row("CveActivoFijo").ToString.ToEntero, -1) + + If Not ObjCompras.AddCompraDetalle(Me.CveCompra, Row("CveUM").ToString.ToEntero, Row("CvePS").ToString.ToEntero, Row("CveSubProyecto").ToString.ToEntero, -1, CveAF, + Row("Cantidad").ToString.ToDecimal, Row("PU").ToString.ToDecimal, Row("IVA").ToString.ToDecimal, Row("Total").ToString.ToDecimal, Row("Descuento").ToString.ToDecimal, + Row("Obs").ToString, Row("CveOrdenCompraDetalle").ToString.ToEntero, TipoRecepcion, Row("CveContrato").ToString.ToEntero, Row("CvePresupuestoEgreso").ToString.ToEntero, + AplicaCostoIndirecto:=Row("AplicaCostoIndirecto").ToString.ToEntero, EstatusAlmacen:=Row("EntregaDirecta").ToString.ToEntero, CvePersonal:=CvePersonal, + CveTipoGasto:=Row("CveTipoGasto").ToString.ToEntero, AF_Medida:=Row("AFMedida").ToString.ToEntero, AF_TipoMantenimiento:=Row("AFTipoMantenimiento").ToString.ToEntero, Referencia:=Referencia, OtrosGastos:=Row("OtrosGastos").ToString.ToDecimal, + RetIVA:=Row("RetIVA").ToString.ToDecimal, RetISR:=Row("RetISR").ToString.ToDecimal, IEPSPS:=Row("IEPSPS").ToString.ToDecimal.RoundSQL, IEPSPSIVA:=Row("IEPSPSIVA").ToString.ToDecimal, + IVAPorcentaje:=Row("IVAPorcentaje").ToString.ToDecimal, RetIVAPorcentaje:=Row("RetIVAPorcentaje").ToString.ToDecimal, RetISRPorcentaje:=Row("RetISRPorcentaje").ToString.ToDecimal, + IEPSPSPorcentaje:=Row("IEPSPSPorcentaje").ToString.ToDecimal, IEPSPSIVAPorcentaje:=Row("IEPSPSIVAPorcentaje").ToString.ToDecimal, NoDeducible:=If((Row("NoDeducible").ToString().ToUpper().Contiene("TRUE", "1")) AndAlso EsNoDeducible, True, False), + CveContratoDetalle:=Row("CveContratoDetalle").ToString.ToEntero, CveCultivoCuadroDetalle:=Row("CveCultivoCuadroDetalle").ToString.ToEntero, CveActivoFijoCompra:=CveAFC) Then + + respuesta = False + Exit For + End If + Next + End If + + If respuesta Then + If Not AddPrePolizaDetalles(ObjConta) Then respuesta = False + End If + + If respuesta AndAlso ObjConta.ValidacionesPrePoliza(CvePrePoliza, UsuarioActual, 4) Then + If ObjConta.ValorPolizaDescuadre > 0 Then + Errores.AppendLine($"eFacturas/Compras-Guardar | Error{ObjConta.MensajePolizaDescuadre} Diferencia{ObjConta.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}.") + GuardaLogAD($"eFacturas/Compras-Guardar | Error{ObjConta.MensajePolizaDescuadre} Diferencia{ObjConta.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas") + respuesta = False + End If + End If + + If respuesta AndAlso Me.CveFactura > 0 Then + If Not ObjCompras.UpdateCompraFactura(Me.CveCompra, Me.CveFactura, Me.Serie, Me.Folio) Then respuesta = False + End If + + If transacccion Is Nothing Then 'SINO VIENE DE UNA TRANSACCIÓN + If respuesta Then + ObjCompras.Commit() + Else + ObjCompras.RollBack() + End If + ObjCompras.Dispose() + ObjConta.Dispose() + End If + + Return respuesta + End Function + + Private Function AddPrePolizaCabecera(ByRef ObjConta As ClsContabilidad) As Boolean + + Dim respuesta As Boolean = False + + Dim ConceptoPoliza As String = String.Format("{0} - {1} - {2}", NombreProveedor, SerieFolio, "") + Dim Modulo As String = "eFacturas/Registrar" + + If Me.TipoDocto = "RNC" Then + ConceptoPoliza = String.Format("{0} - {1} - {2}", NombreProveedor, SerieFolio, "") + Modulo = "Compras/RNC" + End If + + Me.CvePrePoliza = ObjConta.AddPrePolizas(Modulo, 1, Me.Total, Me.Total, Me.CveMoneda, Me.Fecha, ConceptoPoliza, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 0, "", CveTipoPoliza:=Me.CveTipoPoliza) + respuesta = If(Me.CvePrePoliza > 0, True, False) + + Return respuesta + End Function + + Private Function AddPrePolizaDetalles(ByRef ObjConta As ClsContabilidad, Optional ES_RNC As Boolean = False) As Boolean + Dim respuesta As Boolean = True + Dim Concepto As String = $"{Me.NombreProveedor} {Me.SerieFolio}" + Dim Referencia As String = Me.SerieFolio + + If TipoDocto = "RNC" Then + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Me.Total, Me.Total, 370, Referencia, Concepto, CveCompra:=CveCompra, CveCompraAmortizacion:=Me.CveCompraAmortizacion, CveProveedor:=Me.CveProveedor, ImporteME:=If(TipoCambio = 1, 0, Me.Total), TipoCambio:=TipoCambio, + CveClasificacion:=-1, CveSubProyecto:=Me.CveSubProyecto, Contabilizable:=True) Then + respuesta = False + + End If + + If respuesta Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Me.Total, Me.Total, 372, Referencia, Concepto, CveCompra:=CveCompra, CveCompraAmortizacion:=Me.CveCompraAmortizacion, CveProveedor:=Me.CveProveedor, ImporteME:=If(TipoCambio = 1, 0, Me.Total), TipoCambio:=TipoCambio, + CveClasificacion:=-1, CveSubProyecto:=Me.CveSubProyecto, Contabilizable:=True) Then + respuesta = False + + End If + End If + + Else + + Dim importeMovimiento As Decimal + Dim importeMN As Decimal + + + '6 + For Each RowDetalle As DataRow In TmpDT.FiltraParametros("ISNULL(TipoAF,0) <> 2", "", {"CveClasificacion", "CveSubProyecto"}).Rows + + importeMovimiento = TmpDT.SUMD("Total", $" CveClasificacion = {RowDetalle("CveClasificacion").ToString} AND CveSubProyecto = {RowDetalle("CveSubProyecto").ToString}") + importeMN = (importeMovimiento * Me.TipoCambio).RoundSQL + + If importeMN <> 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMovimiento, importeMN, 6, Referencia, Concepto, CveCompra:=CveCompra, CveProveedor:=Me.CveProveedor, CveIE:=Me.CveIE, CvePersonal:=CvePersonal, CveCreditoDetalle:=Me.CveCreditoDetalle, ImporteME:=If(TipoCambio = 1, 0, importeMovimiento), TipoCambio:=TipoCambio, + CveClasificacion:=RowDetalle("CveClasificacion").ToString().ToEntero(), CveSubProyecto:=RowDetalle("CveSubProyecto").ToString().ToEntero(), Contabilizable:=True) Then + respuesta = False + Exit For + End If + End If + Next + '14 + If respuesta AndAlso Me.IVA > 0 Then + importeMovimiento = Me.IVA + importeMN = (importeMovimiento * Me.TipoCambio).RoundSQL + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMovimiento, importeMN, 14, Referencia, Concepto, CveCompra:=CveCompra, CveSubProyecto:=Me.CveSubProyectoPrincipal, CveProveedor:=Me.CveProveedor, CveIE:=Me.CveIE, CvePersonal:=CvePersonal, CveCreditoDetalle:=CveCreditoDetalle, ImporteME:=If(Me.TipoCambio = 1, 0, importeMovimiento), TipoCambio:=Me.TipoCambio, PorcentajeImpuesto:=Me.PorcentajeIVA, Contabilizable:=True) Then + respuesta = False + End If + End If + '25 + If respuesta AndAlso Me.IEPS > 0 Then + importeMovimiento = Me.IEPS + importeMN = (importeMovimiento * Me.TipoCambio).RoundSQL + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMovimiento, importeMN, 25, Referencia, Concepto, CveCompra:=CveCompra, CveSubProyecto:=Me.CveSubProyectoPrincipal, CveProveedor:=Me.CveProveedor, CveIE:=Me.CveIE, CvePersonal:=CvePersonal, CveCreditoDetalle:=CveCreditoDetalle, ImporteME:=If(Me.TipoCambio = 1, 0, importeMovimiento), TipoCambio:=Me.TipoCambio, PorcentajeImpuesto:=0, Contabilizable:=True) Then + respuesta = False + End If + End If + ' + If respuesta AndAlso Me.RetIVA > 0 Then + importeMovimiento = Me.RetIVA + importeMN = (importeMovimiento * Me.TipoCambio).RoundSQL + Dim ret As ConceptosRetenciones = ConceptoPrePolizaRetIVA + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importeMovimiento, importeMN, ret.CveConceptoxAcreditar, Referencia, Concepto, CveCompra:=CveCompra, CveSubProyecto:=Me.CveSubProyectoPrincipal, CveProveedor:=Me.CveProveedor, CveIE:=Me.CveIE, CvePersonal:=CvePersonal, CveCreditoDetalle:=CveCreditoDetalle, ImporteME:=If(Me.TipoCambio = 1, 0, importeMovimiento), TipoCambio:=Me.TipoCambio, PorcentajeImpuesto:=0, Contabilizable:=True) Then + respuesta = False + End If + End If + ' + If respuesta AndAlso Me.RetISR > 0 Then + importeMovimiento = Me.RetISR + importeMN = (importeMovimiento * Me.TipoCambio).RoundSQL + Dim ret As ConceptosRetenciones = ConceptoPrePolizaRetISR + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importeMovimiento, importeMN, ret.CveConceptoxAcreditar, Referencia, Concepto, CveCompra:=CveCompra, CveSubProyecto:=Me.CveSubProyectoPrincipal, CveProveedor:=Me.CveProveedor, CveIE:=Me.CveIE, CvePersonal:=CvePersonal, CveCreditoDetalle:=CveCreditoDetalle, ImporteME:=If(Me.TipoCambio = 1, 0, importeMovimiento), TipoCambio:=Me.TipoCambio, PorcentajeImpuesto:=0, Contabilizable:=True) Then + respuesta = False + End If + End If + '5 + If respuesta Then + importeMovimiento = Me.Total + importeMN = (importeMovimiento * Me.TipoCambio).RoundSQL + Dim ConPreP As ConceptosTipoSaldo = ObtenerCveConceptoPrePoliza(1, Me.CveMoneda, False, Me.CveTipoConceptoProveedor) + Dim ImporteME As Decimal = importeMovimiento + Dim UsaComplementaria As Boolean = True + If Me.CveMoneda > 1 Then ImporteME = importeMovimiento + + If UsuarioActual.CveEmpresa.Contiene(13, 83) Then 'caso excepcional de complementarias + UsaComplementaria = False + importeMN = importeMovimiento * Me.TipoCambio + Else + importeMN = importeMovimiento + End If + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importeMovimiento, importeMN, ConPreP.CveConcepto, Referencia, Concepto, CveCompra:=CveCompra, CveSubProyecto:=Me.CveSubProyectoPrincipal, CveProveedor:=Me.CveProveedor, CveIE:=Me.CveIE, CvePersonal:=CvePersonal, CveCreditoDetalle:=CveCreditoDetalle, ImporteME:=If(Me.TipoCambio = 1, 0, importeMovimiento), TipoCambio:=Me.TipoCambio, PorcentajeImpuesto:=0, Contabilizable:=True) Then + respuesta = False + End If + If respuesta AndAlso Me.CveMoneda > 1 AndAlso UsaComplementaria Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importeMovimiento, (importeMovimiento * Me.TipoCambio - importeMovimiento).RoundSQL, ConPreP.CveConceptoComplementario, Referencia, Concepto, CveCompra:=Me.CveCompra, CveProveedor:=Me.CveProveedor, CveIE:=Me.CveIE, CvePersonal:=Me.CvePersonal, CveCompraAmortizacion:=Me.CveCompraAmortizacion, TipoCambio:=Me.TipoCambio, TipoCambioPago:=1, ImporteME:=ImporteME, CveSubProyecto:=Me.CveSubProyecto) Then + respuesta = False + End If + End If + End If + End If + + Return respuesta + + End Function + End Class diff --git a/Bancos/Transferencias.aspx b/Bancos/Transferencias.aspx index 2ea396687..652eb1306 100644 --- a/Bancos/Transferencias.aspx +++ b/Bancos/Transferencias.aspx @@ -82,6 +82,13 @@ + + + + + + diff --git a/Bancos/Transferencias.aspx.vb b/Bancos/Transferencias.aspx.vb index 2094cb900..5541134c4 100644 --- a/Bancos/Transferencias.aspx.vb +++ b/Bancos/Transferencias.aspx.vb @@ -78,6 +78,7 @@ Partial Class Bancos_Transferencias DdlTipoMovto_SelectedIndexChanged(Nothing, Nothing) + End If End Sub @@ -616,6 +617,9 @@ Partial Class Bancos_Transferencias RFVTxtPaguese.Visible = True End If End If + + ValidaFechaDocumentoDiasPosteriores() + UPPDatos.Update() End Sub @@ -662,4 +666,36 @@ Partial Class Bancos_Transferencias DdlCajaChica.Items.Insert(0, New ListItem("Seleccione", "-1")) End Sub + + Private Sub RVTxtFechaDocumento_Init(sender As Object, e As EventArgs) Handles RVTxtFechaDocumento.Init + RVTxtFechaDocumento.MaximumValue = NowADS().AddDays(2).ToShortDateString + RVTxtFechaDocumento.MinimumValue = NowADS().AddMonths(-38).ToShortDateString + Calendario.EndDate = NowADS().AddDays(2) + + End Sub + + Private Sub ValidaFechaDocumentoDiasPosteriores() + + + RVTxtFechaDocumento.MaximumValue = NowADS().AddDays(3).ToShortDateString + RVTxtFechaDocumento.ErrorMessage = "ERROR:
    La fecha del documento no puede ser superior a 3 días de la fecha actual" + + Calendario.EndDate = NowADS().AddDays(3) + + If DdlTipoMovto.SelectedValue.Contiene("1", "16") Then 'cheques, 3meses + RVTxtFechaDocumento.MaximumValue = NowADS().AddMonths(3).ToShortDateString + RVTxtFechaDocumento.ErrorMessage = "ERROR:
    La fecha del documento no puede ser superior a 3 meses de la fecha actual" + Calendario.EndDate = NowADS().AddMonths(3) + End If + If DdlTipoMovto.SelectedValue = "2" Then 'transfer, 3semanas + RVTxtFechaDocumento.MaximumValue = NowADS().AddDays(21).ToShortDateString + RVTxtFechaDocumento.ErrorMessage = "ERROR:
    La fecha del documento no puede ser superior a 3 semanas de la fecha actual" + Calendario.EndDate = NowADS().AddDays(21) + End If + + UPPDatos.Update() + 'UpGuardar.Update() + + End Sub + End Class diff --git a/Contratos/FacturacionMasiva.aspx.vb b/Contratos/FacturacionMasiva.aspx.vb index ef7e16b69..695118973 100644 --- a/Contratos/FacturacionMasiva.aspx.vb +++ b/Contratos/FacturacionMasiva.aspx.vb @@ -539,13 +539,13 @@ Partial Class Contratos_FacturacionMasiva 'Dim ObjCliente As New ClsClientes() 'If ObjCliente.GetClientes(DR("CveCliente").ToString.ToEntero, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa, -1, TipoCliente:=-1) Then ' If ObjCliente.DtResultados.Rows.Count > 0 Then - ' ObjFactura.CveFormaPago33 = ObjCliente.CveFormaPago33 - ' ObjFactura.FormaPago33 = GlobalDTVtaFormaPago.FiltroPrimeroValor("FormaPago", $"CveFormaPago = {ObjCliente.CveFormaPago33}") - ' ObjFactura.FormaPagoSAT33 = GlobalDTVtaFormaPago.FiltroPrimeroValor("ClaveFormaPagoSAT", $"CveFormaPago = {ObjCliente.CveFormaPago33}") + ' ObjFactura.CveFormaPago = ObjCliente.CveFormaPago + ' ObjFactura.FormaPago33 = GlobalDTVtaFormaPago.FiltroPrimeroValor("FormaPago", $"CveFormaPago = {ObjCliente.CveFormaPago}") + ' ObjFactura.FormaPagoSAT33 = GlobalDTVtaFormaPago.FiltroPrimeroValor("ClaveFormaPagoSAT", $"CveFormaPago = {ObjCliente.CveFormaPago}") - ' ObjFactura.CveMetodoPago33 = ObjCliente.CveMetodoPago33 - ' ObjFactura.MetodoPago33 = GlobalDTVtaMetodoPago.FiltroPrimeroValor("MetodoPago", $"CveMetodoPago = {ObjCliente.CveMetodoPago33}") - ' ObjFactura.ClaveMetodoPagoSAT = GlobalDTVtaMetodoPago.FiltroPrimeroValor("ClaveMetodoPagoSAT", $"CveMetodoPago = {ObjCliente.CveMetodoPago33}") + ' ObjFactura.CveMetodoPago = ObjCliente.CveMetodoPago + ' ObjFactura.MetodoPago33 = GlobalDTVtaMetodoPago.FiltroPrimeroValor("MetodoPago", $"CveMetodoPago = {ObjCliente.CveMetodoPago}") + ' ObjFactura.ClaveMetodoPagoSAT = GlobalDTVtaMetodoPago.FiltroPrimeroValor("ClaveMetodoPagoSAT", $"CveMetodoPago = {ObjCliente.CveMetodoPago}") ' ObjFactura.CveUsoCFDI = ObjCliente.CveUsoCFDI ' ObjFactura.UsoCFDI = GlobalDTSATUsosCFDI.FiltroPrimeroValor("Descripcion", $"CveUsoCFDI = {ObjCliente.CveUsoCFDI}") diff --git a/General/SaldosIniciales.aspx.vb b/General/SaldosIniciales.aspx.vb index 160061279..6f44e2d57 100644 --- a/General/SaldosIniciales.aspx.vb +++ b/General/SaldosIniciales.aspx.vb @@ -2176,1009 +2176,11 @@ Partial Class General_SaldosIniciales 'C L I E N T E S - F A C T U R A S ElseIf RblFormato.SelectedValue = "4" Then -#Region "C L I E N T E S - F A C T U R A S" - - Dim NoEncontrados As Integer = 0 - Dim Encontrados As Integer = 0 - Dim StrRFCNoencontrados As New StringBuilder - Dim drr As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimero("AplicaParaVenta = 1") - If drr Is Nothing Then - Alert("No existen productos para venta. favor de crear uno e intentar de nuevo", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - Dim ObjVentas As New ClsVentas - Dim ObjConta As New ClsContabilidad(ObjVentas.IniciaTransacSQL()) - Dim ObjIE As New ClsBancos(ObjVentas.IniciaTransacSQL()) - Dim ErrorVentas As Boolean = False - Dim CveVenta As Integer - Dim DtClientes As New DataTable - 'Dim ExisteVenta As Boolean = False - 'Dim Contador As Integer = 0 - DtClientes = GlobalDTCliente(UsuarioActual.CveEmpresa, Estatus:=-1) - Dim CvePS As Integer = drr("CvePS").ToString().ToEntero() - Dim CveUnidadMedida As Integer = drr("CveUnidadMedida").ToString().ToEntero() - Dim CveClasificacion As Integer = drr("CveClasificacion").ToString().ToEntero() - - If Not CvePS > 0 Then Alert(String.Format("No se encontró el Producto Servicio"), TipoMensaje.MsgError) : ErrorVentas = True - ' If Not CveSucursal > 0 Then Alert("No se encontró la sucursal.", TipoMensaje.MsgError) : ErrorVentas = True - If Not CveUnidadMedida > 0 Then Alert(String.Format("No se encontró la Unidad de Medida."), TipoMensaje.MsgError) : ErrorVentas = True - Dim dtsubp As DataTable = GlobalDTSubProyectos(UsuarioActual.CveEmpresa) - - 'For Each drt As DataRow In dt.FiltraParametros("RFC <> ''", DistinctColumns:={"RFC"}).Rows - ' Dim RFC As String = drt("RFC").ToString().Trim.Replace("-", "").Replace(" ", "") - ' Dim CveCliente As Integer = DtClientes.FiltroPrimeroValor("CveCliente", $"RFC = '{RFC}'").ToString().ToEntero() - ' If CveCliente <= 0 Then - ' Dim OBJ As New ClsClientes - ' OBJ.AgregarClienteNoFrecuente(RFC, RFC, "", "", "", "", "", 26, RFC, "", "", "", -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, "", -1, -1) - ' OBJ.Dispose() - ' End If - 'Next - 'GlobalDTCliente(UsuarioActual.CveEmpresa) = Nothing - 'DtClientes = GlobalDTCliente(UsuarioActual.CveEmpresa, Estatus:=-1) - Dim CountRow As Integer = 1 - For Each Row As DataRow In dt.FiltraParametros("RFC <> ''").Rows - Dim Sucursal As String = dtsubp.FiltroPrimeroValor("CveSubProyecto", $"SubProyecto = '{Row("Sucursal").ToString()}'") - Dim TipoDocto As String = Row("Tipo Documento").ToString().Trim - Dim RFC As String = Row("RFC").ToString().Trim.Replace("-", "").Replace(" ", "") - Dim Serie As String = Row("Serie").ToString().Trim - Dim Folio As Integer = Row("Folio").ToString().ToEntero() - Dim Fecha As Date = Row("Fecha").ToString().ToDate - Dim FechaVencimiento As Date = Row("Fecha Vencimiento").ToString().ToDate - Dim ImpuestoLocal As Decimal = If(dt.Columns.Contains("ImpuestoLocal"), Row("ImpuestoLocal").ToString().ToDecimal, 0D) - Dim Amortizacion As Decimal = If(dt.Columns.Contains("Amort.Ant"), Row("Amort.Ant").ToString().ToDecimal, 0) - Dim SubTotal As Decimal = Row("SubTotal").ToString().ToDecimal - Dim IVA As Decimal = Row("IVA").ToString().ToDecimal - Dim Total As Decimal = Row("Total").ToString().ToDecimal - Dim Saldo As Decimal = Row("Saldo").ToString().ToDecimal - Dim CveCliente As Integer = DtClientes.FiltroPrimeroValor("CveCliente", $"RFC = '{RFC}'").ToString().ToEntero() - Dim RetIVA As Decimal = Row("Ret IVA").ToString().ToDecimal - Dim RetISR As Decimal = Row("Ret ISR").ToString().ToDecimal - Dim Moneda As String = Row("Moneda").ToString() - Dim TipoCambio As String = Row("Tipo Cambio").ToString() - Dim CveMoneda As Integer = 1 - Dim Vendedor As String = If(dt.Columns.Contains("Vendedor"), Row("Vendedor").ToString(), "") - Dim CveVendedor As Integer = 0 - - Dim IEPS As Decimal = 0 - - If RblFormato.SelectedValue = "17" Then - IEPS = Row("IEPS").ToString().ToDecimal - End If - - Dim CveClienteSucursal As Integer = 0 'Row("CveClienteSucursal").ToString().ToEntero() - Dim FolioFiscal As String = If(dt.Columns.Contains("Folio Fiscal"), Row("Folio Fiscal").ToString(), "") - Dim PorcentajeIVA As Decimal = If(dt.Columns.Contains("PorcentajeIVA"), Round(Row("PorcentajeIVA").ToString().ToDecimal, 4), 0) - Dim PorcentajeRetIVA As Decimal = If(dt.Columns.Contains("PorcentajeRetIVA"), Round(Row("PorcentajeRetIVA").ToString().ToDecimal, 4), 0) - Dim PorcentajeRetISR As Decimal = If(dt.Columns.Contains("PorcentajeRetISR"), Round(Row("PorcentajeRetISR").ToString().ToDecimal, 4), 0) - Dim PedidoContrato As String = If(dt.Columns.Contains("Pedido"), Row("Pedido").ToString(), "") - - GuardaLog(Sucursal + "-" + Row("Folio").ToString()) - 'Temporalmente SE BORRARA - Dim Transaccion As String = "" ' Row("Transaccion2").ToString() - Dim Folio2 As String = "" ' Row("Folio2").ToString() - Dim CodCliente As String = "" 'Row("CodCliente2").ToString() - - Dim IEPSDetalle As Decimal = 0 - Dim CantidadDetalle As Decimal = 0 - Dim PUDetalle As Decimal = 0 - Dim IVADetalle As Decimal = 0 - Dim PorcentajeIEPS As Decimal = 0 - - If IEPS > 0 Then - PorcentajeIEPS = If(dt.Columns.Contains("PorcentajeIEPS"), Round(Row("PorcentajeIEPS").ToString().ToDecimal, 4), 0) - End If - - If RblFormato.SelectedValue = "17" Then - - Dim CodigoDetalle As String = Row("Codigo").ToString - If CodigoDetalle.Trim.Length > 0 Then - Dim DrDetalles As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimero($"Codigo = '{CodigoDetalle}'") - - If DrDetalles IsNot Nothing Then - CvePS = DrDetalles("CvePS").ToString().ToEntero() - CveUnidadMedida = DrDetalles("CveUnidadMedida").ToString().ToEntero() - CveClasificacion = DrDetalles("CveClasificacion").ToString().ToEntero() - Else - Alert($"El código del producto no se encontro, error en registro {CountRow}") - ErrorVentas = True - End If - Else - Alert($"El código es requerido, error en registro {CountRow}") - ErrorVentas = True - End If - - IEPSDetalle = Row("IEPS").ToString.ToDecimal - CantidadDetalle = Row("Cantidad").ToString.ToDecimal - PUDetalle = Row("PU").ToString.ToDecimal - IVADetalle = Row("IVA").ToString.ToDecimal - - If CantidadDetalle = 0 Then - Alert($"No se especifico la cantidad, error en registro {CountRow}") - ErrorVentas = True - End If - - End If - - If dt.Columns.Contains("Cliente Sucursal") AndAlso Row("Cliente Sucursal").ToString() <> "" Then - - Dim ObjCliente As New ClsClientes - If ObjCliente.GetSucursales(CveCliente) Then - If ObjCliente.DtResultados.Rows.Count > 0 Then - CveClienteSucursal = ObjCliente.DtResultados.FiltroPrimeroValor("CveClienteSucursal", "SucursalCliente = '" & Row("Cliente Sucursal").ToString().Trim & "'").ToEntero - End If - End If - - ObjCliente.Dispose() - End If - - - 'If Not CveCliente > 0 Then Alert(String.Format("No se encontró el cliente con el RFC: {0}", {RFC}), TipoMensaje.MsgError) : ErrorVentas = True : RFC.GuardaLog : Exit For - TipoDocto = IIf(TipoDocto.ToUpper.Contiene("INGRESO", "INGRESOS", "ING", "FACTURA", "FACTURAS"), "Ing", IIf(TipoDocto.ToUpper.Contiene("EGRESO", "EGRESOS", "EGS"), "Egs", IIf(TipoDocto.ToUpper.Contiene("ANTICIPO", "ANTICIPOS", "ANT"), "Ant", "Rem"))).ToString() - 'PrePóliza - Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("Venta/SaldoInicial", 1, Total, Total, 1, Fecha, String.Format("{0}-{1}", Serie, Folio), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - - If Vendedor <> "" Then - CveVendedor = GlobalDTVendedores(UsuarioActual.CveEmpresa, VendedorTipo:=-1).FiltroPrimeroValor("CveVendedor", $"Vendedor = '{Vendedor}'").ToString().ToEntero() - If Not CveVendedor > 0 Then CveVendedor = 0 - Else - CveVendedor = 0 - End If - - 'Moneda - If Moneda.ToUpper.Contiene("PESOS", "PESO", "MXN") Then - CveMoneda = 1 - TipoCambio = "1" - ElseIf Moneda.ToUpper.Contiene("DÓLAR", "DÓLARES", "DOLARES", "USD") Then - CveMoneda = 2 - - If TipoCambio.Trim.ToDecimal < 10 Then - - If UsuarioActual.CveEmpresa.Contiene(13, 83) Then - TipoCambio = GlobalTipoCambio(Fecha.AddDays(-1)).ToString() - Else - TipoCambio = GlobalTipoCambio(Fecha).ToString() - End If - - End If - - End If - - 'Si no se especifica TC, se manda como pesos. - If TipoCambio = "" Then TipoCambio = "1" - - If Not CveClienteSucursal > 0 Then CveClienteSucursal = -1 - - If FechaVencimiento = "".ToDate Or FechaVencimiento < "1900/01/01".ToDate Then - FechaVencimiento = Fecha - End If - - - 'Venta - If CveCliente > 0 Then - - - If TipoDocto.Contiene("Ing", "Egs", "Rem", "Ant") Then - GuardaLog(Serie & "-" & Folio) - If Not ObjVentas.AddVenta(TipoDocto, Folio, CveCliente.ToEntero(), CveClienteSucursal, SubTotal, 0, Amortizacion, IVA, RetIVA, RetISR, Total, CveMoneda, TipoCambio.ToDecimal, - 0, 0, 0, FechaVencimiento, Fecha, "", "", Fecha, CveVendedor, Folio2, "", "", 0, 0, 0, "-1".ToDate, "-1".ToDate, "-1".ToDate, -1, 0, CvePrePoliza, - UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, Serie:=Serie, CveSubProyecto:=Sucursal.ToEntero(), CveSubProyectoEjecucion:=Sucursal.ToEntero(), - CveSubProyectoCobranza:=Sucursal.ToEntero(), IEPS:=IEPS, ObservacionesAlmacen:=Transaccion, Entrega:=CodCliente, ImpuestoLocal:=ImpuestoLocal, - PedidoContrato:=PedidoContrato, CveMetodoPago33:=3) Then - ErrorVentas = True - Exit For - End If - CveVenta = ObjVentas.CveVenta - - If RblFormato.SelectedValue = "17" Then - - Dim TotalDetalles As Decimal = SubTotal - If PUDetalle > 0 Then - TotalDetalles = (CantidadDetalle * PUDetalle) + IVA - RetIVA - RetISR + IEPSDetalle - End If - - If Math.Abs(TotalDetalles - Total) > 0.01 Then - ErrorVentas = True - Alert($"Registro {CountRow} El total no councide con el calculo de los detalles, total: {Total.ToString("###,###,###.00")} calculo detatalles: {TotalDetalles.ToString("###,###,###.00")}", TipoMensaje.MsgAdvertencia) - Exit For - End If - - If Not ObjVentas.AddVentaDetalle(CveVenta, CvePS, CantidadDetalle, CveUnidadMedida, PUDetalle, IVADetalle, TotalDetalles, "Saldo Inicial", 0, 0, Sucursal.ToEntero(), 0, - PorcentajeIVA:=PorcentajeIVA, PorcentajeRetIVA:=PorcentajeRetIVA, ImporteRetIVA:=RetIVA, IEPS:=IEPSDetalle, PorcentajeRetISR:=PorcentajeRetISR, PorcentajeIEPS:=PorcentajeIEPS) Then - ErrorVentas = True - Exit For - End If - - Else - If Not ObjVentas.AddVentaDetalle(CveVenta, CvePS, 1, CveUnidadMedida, SubTotal, IVA, SubTotal * PorcentajeIVA, "Saldo Inicial", 0, 0, Sucursal.ToEntero(), 0, PorcentajeIVA:=PorcentajeIVA, PorcentajeRetIVA:=PorcentajeRetIVA, ImporteRetIVA:=RetIVA, IEPS:=0) Then - ErrorVentas = True - Exit For - End If - End If - - Dim ConceptoContable As Integer = 1 - Dim ConceptoContablePago As Integer = 2 - If TipoDocto = "Egs" Then - ConceptoContable = 12 - ConceptoContablePago = 91 - End If - - If FolioFiscal <> "" Then - If Not ObjVentas.UpdateVentaFolioFiscal(FolioFiscal, CveVenta, UsuarioActual.CveEmpresa) Then - ErrorVentas = True - Exit For - End If - End If - - Dim UsaComplementaria As Boolean = False - - If UsuarioActual.CveEmpresa.Contiene(119, 158) Then UsaComplementaria = True - - 'PrePólizaDetalle - Dim tCveConcepto As Integer = 4 - If TipoDocto = "Ant" Then tCveConcepto = 3 - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, SubTotal, SubTotal, tCveConcepto, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, CveClasificacion:=CveClasificacion, CveSubProyecto:=Sucursal.ToEntero(), PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Total, ConceptoContable, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For - - If IVA > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IVA, IVA, 13, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - If IEPS > 0 Then - 'AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, Folio, 38, String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteMX:=IEPS) - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, IEPS, 38, Folio.ToString, String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For - - End If - - If RetIVA > 0 Then - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetISR, RetISR, 8, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeRetISR, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - If RetISR > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetISR, RetISR, 9, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeRetISR, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - If ImpuestoLocal > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImpuestoLocal, ImpuestoLocal, 27, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - - If UsaComplementaria Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total * TipoCambio.ToDecimal - Total, Total * TipoCambio.ToDecimal - Total, 203, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteME:=Total, TipoCambio:=TipoCambio.ToDecimal, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - 'Saldo - If Saldo < Total Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total - Saldo, Total - Saldo, ConceptoContablePago, Folio.ToString(), Folio.ToString(), CveVenta:=CveVenta, CveCliente:=CveCliente, CveVentaAmortizacion:=CveVenta, Contabilizable:=False) Then ErrorVentas = True : Exit For - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total - Saldo, Total - Saldo, 95, Folio.ToString(), Folio.ToString(), CveVenta:=CveVenta, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - - - Else - 'ANTICIPOS - Dim CveIE As Integer = ObjIE.AddBancos_IE(1, 1, Fecha, Folio.ToString(), "", Total, 1, - 1, "Anticipo Cliente", "", False, False, -1, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Total, 30, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total, Total, 66, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For - - End If - Encontrados = Encontrados + 1 - - Else - NoEncontrados = NoEncontrados + 1 - StrRFCNoencontrados.AppendFormat("{0}
    ", RFC) - ErrorVentas = True - Exit For - End If - - CountRow = CountRow + 1 - Next - If Not ErrorVentas Then - Alert(String.Format("Se agregaron: {0} Ventas correctamente. {1} no encontrados
    {2} ", Encontrados, NoEncontrados, StrRFCNoencontrados), TipoMensaje.MsgInformacion) - ObjVentas.Commit() - TxtExcel.Text = "" - UpDatos.Update() - Else - Alert(String.Format("Error al registrar : {0} Ventas correctamente. {1} no encontrados
    {2} ", Encontrados, NoEncontrados, StrRFCNoencontrados), TipoMensaje.MsgError) - ObjVentas.RollBack() - End If - ObjVentas.Dispose() - - + RegistraVentas(dt, False) ElseIf RblFormato.SelectedValue = "17" Then - Dim NoEncontrados As Integer = 0 - Dim VentasAgregadas As Integer = 0 - Dim Encontrados As Integer = 0 - Dim StrRFCNoencontrados As New StringBuilder - Dim drr As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimero("AplicaParaVenta = 1") - If drr Is Nothing Then - Alert("No existen productos para venta. favor de crear uno e intentar de nuevo", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - Dim ObjVentas As New ClsVentas - Dim ObjConta As New ClsContabilidad(ObjVentas.IniciaTransacSQL()) - Dim ObjIE As New ClsBancos(ObjVentas.IniciaTransacSQL()) - Dim ErrorVentas As Boolean = False - Dim CveVenta As Integer - Dim CvePrePoliza As Integer - Dim DtClientes As New DataTable - 'Dim ExisteVenta As Boolean = False - 'Dim Contador As Integer = 0 - DtClientes = GlobalDTCliente(UsuarioActual.CveEmpresa, Estatus:=-1) - Dim CvePS As Integer = drr("CvePS").ToString().ToEntero() - Dim CveUnidadMedida As Integer = drr("CveUnidadMedida").ToString().ToEntero() - Dim CveClasificacion As Integer = drr("CveClasificacion").ToString().ToEntero() - - If Not CvePS > 0 Then Alert(String.Format("No se encontró el Producto Servicio"), TipoMensaje.MsgError) : ErrorVentas = True - ' If Not CveSucursal > 0 Then Alert("No se encontró la sucursal.", TipoMensaje.MsgError) : ErrorVentas = True - If Not CveUnidadMedida > 0 Then Alert(String.Format("No se encontró la Unidad de Medida."), TipoMensaje.MsgError) : ErrorVentas = True - Dim dtsubp As DataTable = GlobalDTSubProyectos(UsuarioActual.CveEmpresa) - - 'For Each drt As DataRow In dt.FiltraParametros("RFC <> ''", DistinctColumns:={"RFC"}).Rows - ' Dim RFC As String = drt("RFC").ToString().Trim.Replace("-", "").Replace(" ", "") - ' Dim CveCliente As Integer = DtClientes.FiltroPrimeroValor("CveCliente", $"RFC = '{RFC}'").ToString().ToEntero() - ' If CveCliente <= 0 Then - ' Dim OBJ As New ClsClientes - ' OBJ.AgregarClienteNoFrecuente(RFC, RFC, "", "", "", "", "", 26, RFC, "", "", "", -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, "", -1, -1) - ' OBJ.Dispose() - ' End If - 'Next - 'GlobalDTCliente(UsuarioActual.CveEmpresa) = Nothing - 'DtClientes = GlobalDTCliente(UsuarioActual.CveEmpresa, Estatus:=-1) - Dim CountRow As Integer = 1 - Dim LastSerieFolioTipoDoc As String = String.Empty - Dim EsDetalle As Boolean = False - - If UsuarioActual.CveEmpresa = 189 Then - - Dim DTFoliosFiscales As DataTable = dt.FiltraParametros("[Folio Fiscal] <> ''", "", {"Folio Fiscal"}) - - For Each drFolioFiscal As DataRow In DTFoliosFiscales.Rows - Dim FolioFiscalActual As String = drFolioFiscal("Folio Fiscal").ToString - Dim DRVentaActual As DataRow = dt.FiltroPrimero($"[Folio Fiscal] = '{FolioFiscalActual}'") - - Dim Sucursal As String = dtsubp.FiltroPrimeroValor("CveSubProyecto", $"SubProyecto = '{DRVentaActual("Sucursal").ToString()}'") - Dim TipoDocto As String = DRVentaActual("Tipo Documento").ToString().Trim - Dim RFC As String = DRVentaActual("RFC").ToString().Trim.Replace("-", "").Replace(" ", "") - Dim Serie As String = DRVentaActual("Serie").ToString().Trim - Dim Folio As Integer = DRVentaActual("Folio").ToString().ToEntero() - Dim Fecha As Date = DRVentaActual("Fecha").ToString().ToDate - Dim FechaVencimiento As Date = DRVentaActual("Fecha Vencimiento").ToString().ToDate - Dim ImpuestoLocal As Decimal = If(dt.Columns.Contains("ImpuestoLocal"), DRVentaActual("ImpuestoLocal").ToString().ToDecimal, 0D) - Dim Amortizacion As Decimal = If(dt.Columns.Contains("Amort.Ant"), DRVentaActual("Amort.Ant").ToString().ToDecimal, 0) - Dim CveCliente As Integer = DtClientes.FiltroPrimeroValor("CveCliente", $"RFC = '{RFC}'").ToString().ToEntero() - - If LastSerieFolioTipoDoc = $"{Serie}{Folio}{TipoDocto}" AndAlso UsuarioActual.CveEmpresa = 189 Then - EsDetalle = True - Else - LastSerieFolioTipoDoc = $"{Serie}{Folio}{TipoDocto}" - EsDetalle = False - End If - - Dim SubTotal As Decimal = 0 - Dim IVA As Decimal = 0 - Dim Total As Decimal = 0 - Dim Saldo As Decimal = 0 - Dim RetIVA As Decimal = 0 - Dim RetISR As Decimal = 0 - Dim IEPS As Decimal = 0 - - SubTotal = DRVentaActual("SubTotal").ToString().ToDecimal - IVA = DRVentaActual("IVA").ToString().ToDecimal - Total = DRVentaActual("Total").ToString().ToDecimal - Saldo = DRVentaActual("Saldo").ToString().ToDecimal - RetIVA = DRVentaActual("Ret IVA").ToString().ToDecimal - RetISR = DRVentaActual("Ret ISR").ToString().ToDecimal - IEPS = DRVentaActual("IEPS").ToString().ToDecimal - - Dim Moneda As String = DRVentaActual("Moneda").ToString() - Dim TipoCambio As String = DRVentaActual("Tipo Cambio").ToString() - Dim CveMoneda As Integer = 1 - Dim Vendedor As String = If(dt.Columns.Contains("Vendedor"), DRVentaActual("Vendedor").ToString(), "") - Dim CveVendedor As Integer = 0 - - Dim CveClienteSucursal As Integer = 0 'Row("CveClienteSucursal").ToString().ToEntero() - 'Dim FolioFiscal As String = If(dt.Columns.Contains("Folio Fiscal"), DRVentaActual("Folio Fiscal").ToString(), "") - Dim PorcentajeIVA As Decimal = If(dt.Columns.Contains("PorcentajeIVA"), Round(DRVentaActual("PorcentajeIVA").ToString().ToDecimal, 2), 0) - Dim PorcentajeRetIVA As Decimal = If(dt.Columns.Contains("PorcentajeRetIVA"), Round(DRVentaActual("PorcentajeRetIVA").ToString().ToDecimal, 4), 0) - Dim PorcentajeRetISR As Decimal = If(dt.Columns.Contains("PorcentajeRetISR"), Round(DRVentaActual("PorcentajeRetISR").ToString().ToDecimal, 4), 0) - Dim PedidoContrato As String = If(dt.Columns.Contains("Pedido"), DRVentaActual("Pedido").ToString(), "") - - GuardaLog(Sucursal + "-" + DRVentaActual("Folio").ToString()) - 'Temporalmente SE BORRARA - Dim Transaccion As String = "" ' Row("Transaccion2").ToString() - Dim Folio2 As String = "" ' Row("Folio2").ToString() - Dim CodCliente As String = "" 'Row("CodCliente2").ToString() - - TipoDocto = IIf(TipoDocto.ToUpper.Contiene("INGRESO", "INGRESOS", "ING", "FACTURA", "FACTURAS"), "Ing", IIf(TipoDocto.ToUpper.Contiene("EGRESO", "EGRESOS", "EGS"), "Egs", "Rem")).ToString() - - 'Dim CantidadDetalle As Decimal = 0 - 'Dim PUDetalle As Decimal = 0 - 'Dim IVADetalle As Decimal = 0 - Dim PorcentajeIEPS As Decimal = 0 - - - Dim TotalDetalles As Decimal = 0 - For Each dRowDetalle As DataRow In dt.FiltraParametros($"[Folio Fiscal]='{FolioFiscalActual}'").Rows - Dim CantidadDetalle As Decimal = dRowDetalle("Cantidad").ToString.ToDecimal 'digo PU IVADetalle - Dim PuDetalle As Decimal = dRowDetalle("PU").ToString.ToDecimal - Dim IVADetalle As Decimal = dRowDetalle("IVADetalle").ToString.ToDecimal - Dim IEPSDetalle As Decimal = dRowDetalle("IEPS").ToString.ToDecimal - TotalDetalles += (CantidadDetalle * PuDetalle) + IVADetalle + IEPSDetalle - Next - - - If IEPS > 0 Then - PorcentajeIEPS = If(dt.Columns.Contains("PorcentajeIEPS"), Round(DRVentaActual("PorcentajeIEPS").ToString().ToDecimal, 4), 0) - End If - - If Math.Abs(TotalDetalles - Total) > 0.01 Then - ErrorVentas = True - Alert($"Registro {CountRow} El total no coincide con el acumulado de los detalles, total: {Total.ToString("###,###,###.00")} detatalle: {TotalDetalles.ToString("###,###,###.00")}", TipoMensaje.MsgAdvertencia) - Exit For - End If - - If Vendedor <> "" Then - CveVendedor = GlobalDTVendedores(UsuarioActual.CveEmpresa, VendedorTipo:=-1).FiltroPrimeroValor("CveVendedor", $"Vendedor = '{Vendedor}'").ToString().ToEntero() - If Not CveVendedor > 0 Then CveVendedor = 0 - Else - CveVendedor = 0 - End If - - If Moneda.ToUpper.Contiene("PESOS", "PESO", "MXN") Then - CveMoneda = 1 - TipoCambio = "1" - ElseIf Moneda.ToUpper.Contiene("DÓLAR", "DÓLARES", "DOLARES", "USD") Then - CveMoneda = 2 - - If TipoCambio.Trim.ToDecimal < 10 Then - - If UsuarioActual.CveEmpresa.Contiene(13, 83) Then - TipoCambio = GlobalTipoCambio(Fecha.AddDays(-1)).ToString() - Else - TipoCambio = GlobalTipoCambio(Fecha).ToString() - End If - - End If - - End If - - If TipoCambio = "" Then TipoCambio = "1" - - If Not CveClienteSucursal > 0 Then CveClienteSucursal = -1 - - If FechaVencimiento = "".ToDate Or FechaVencimiento < "1900/01/01".ToDate Then - FechaVencimiento = Fecha - End If - - If Not ErrorVentas Then - CvePrePoliza = ObjConta.AddPrePolizas("Venta/SaldoInicial", 1, Total, Total, CveMoneda, Fecha, String.Format("{0}-{1}", Serie, Folio), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - If Not CvePrePoliza > 0 Then - ErrorVentas = True - End If - End If - Dim VentayaRegistrada As Boolean = False - If Not ErrorVentas Then - 'Venta - If CveCliente > 0 Then - - If TipoDocto.Contiene("Ing", "Egs", "Rem") Then - GuardaLog(Serie & "-" & Folio) - CveVenta = 0 - Dim contador As Integer = 0 - 'verificar si existe la venta, si existe obtener el cveventa y limpiar su contenido para carga de lo nuevo. - If ObjVentas.GetVentas(UsuarioActual.CveEmpresa, TipoDocto, Serie, Folio, "-1", -1, -1, -1, -1, "2000-01-01", Now.ToShortDateString, FolioFiscalActual, CveUsuarioConsulta:=100) Then - If ObjVentas.DtResultados.Rows.Count > 0 Then - contador = 1 - CveVenta = ObjVentas.DtResultados.FiltroPrimeroValor("CveVenta").ToEntero - VentayaRegistrada = True - VentasAgregadas += 1 - 'limpieza de las partidas - If ObjVentas.GetVentaDetalle(CveVenta) Then - For Each dr As DataRow In ObjVentas.DtResultados.Rows - ObjVentas.RemoveVentasDetalle(CveVenta, dr("CveVentaDetalle").ToString.ToEntero) - Next - End If - - End If - End If - If Not EsDetalle AndAlso CveVenta = 0 Then - If Not ObjVentas.AddVenta(TipoDocto, Folio, CveCliente.ToEntero(), CveClienteSucursal, SubTotal, 0, Amortizacion, IVA, RetIVA, RetISR, Total, CveMoneda, TipoCambio.ToDecimal, - 0, 0, 0, FechaVencimiento, Fecha, "", "", Fecha, CveVendedor, Folio2, "", "", 0, 0, 0, "-1".ToDate, "-1".ToDate, "-1".ToDate, -1, 0, CvePrePoliza, - UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, Serie:=Serie, CveSubProyecto:=Sucursal.ToEntero(), CveSubProyectoEjecucion:=Sucursal.ToEntero(), - CveSubProyectoCobranza:=Sucursal.ToEntero(), IEPS:=IEPS, ObservacionesAlmacen:=Transaccion, Entrega:=CodCliente, ImpuestoLocal:=ImpuestoLocal, - PedidoContrato:=PedidoContrato, CveMetodoPago33:=3) Then - ErrorVentas = True - Exit For - Else - VentasAgregadas += 1 - End If - CveVenta = ObjVentas.CveVenta - End If - - For Each dRowDetalle As DataRow In dt.FiltraParametros($"[Folio Fiscal]='{FolioFiscalActual}'").Rows - - Dim CantidadDetalle As Decimal = dRowDetalle("Cantidad").ToString.ToDecimal 'digo PU IVADetalle - Dim PuDetalle As Decimal = dRowDetalle("PU").ToString.ToDecimal - Dim IVADetalle As Decimal = dRowDetalle("IVADetalle").ToString.ToDecimal - Dim IEPSDetalle As Decimal = dRowDetalle("IEPS").ToString.ToDecimal - Dim PorcentajeIEPSDetalle = dRowDetalle("PorcentajeIEPS").ToString.ToDecimal - - Dim CodigoDetalle As String = dRowDetalle("Codigo").ToString - If CodigoDetalle.Trim.Length > 0 Then - Dim DrDetalles As DataRow = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa).FiltroPrimero($"Codigo = '{CodigoDetalle}'") - - If DrDetalles IsNot Nothing Then - CvePS = DrDetalles("CvePS").ToString().ToEntero() - CveUnidadMedida = DrDetalles("CveUnidadMedida").ToString().ToEntero() - CveClasificacion = DrDetalles("CveClasificacion").ToString().ToEntero() - Else - Alert($"El código del producto no se encontro, error en registro {CountRow}") - ErrorVentas = True - End If - Else - Alert($"El código es requerido, error en registro {CountRow}") - ErrorVentas = True - End If - - If Not ErrorVentas Then - If Not ObjVentas.AddVentaDetalle(CveVenta, CvePS, CantidadDetalle, CveUnidadMedida, PuDetalle, IVADetalle, TotalDetalles, "Saldo Inicial", 0, 0, Sucursal.ToEntero(), 0, - PorcentajeIVA:=PorcentajeIVA, PorcentajeRetIVA:=PorcentajeRetIVA, ImporteRetIVA:=0, IEPS:=IEPSDetalle, PorcentajeRetISR:=0, PorcentajeIEPS:=PorcentajeIEPSDetalle, - EstatusAlmacen:=2) Then - ErrorVentas = True - Exit For - End If - End If - - Next - - If Not VentayaRegistrada Then - Dim ConceptoContable As Integer = 1 - Dim ConceptoContablePago As Integer = 2 - If TipoDocto = "Egs" Then - ConceptoContable = 12 - ConceptoContablePago = 91 - End If - - If FolioFiscalActual <> "" Then - If Not ObjVentas.UpdateVentaFolioFiscal(FolioFiscalActual, CveVenta, UsuarioActual.CveEmpresa) Then - ErrorVentas = True - Exit For - End If - End If - - Dim UsaComplementaria As Boolean = False - - If UsuarioActual.CveEmpresa.Contiene(119, 158) Then UsaComplementaria = True - - 'PrePólizaDetalle - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, SubTotal, SubTotal, 4, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, CveClasificacion:=CveClasificacion, CveSubProyecto:=Sucursal.ToEntero(), PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Total, ConceptoContable, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For - - If IVA > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IVA, IVA, 13, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - If IEPS > 0 Then - 'AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, Folio, 38, String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteMX:=IEPS) - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, IEPS, 38, Folio.ToString, String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For - - End If - - If RetIVA > 0 Then - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetISR, RetISR, 8, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeRetISR, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - If RetISR > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetISR, RetISR, 9, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeRetISR, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - If ImpuestoLocal > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImpuestoLocal, ImpuestoLocal, 27, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - If UsaComplementaria Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total * TipoCambio.ToDecimal - Total, Total * TipoCambio.ToDecimal - Total, 203, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteME:=Total, TipoCambio:=TipoCambio.ToDecimal, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - 'Saldo - If Saldo < Total Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total - Saldo, Total - Saldo, ConceptoContablePago, Folio.ToString(), Folio.ToString(), CveVenta:=CveVenta, CveCliente:=CveCliente, CveVentaAmortizacion:=CveVenta, Contabilizable:=False) Then ErrorVentas = True : Exit For - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total - Saldo, Total - Saldo, 95, Folio.ToString(), Folio.ToString(), CveVenta:=CveVenta, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - End If - - If Not ErrorVentas Then - VentasAgregadas += VentasAgregadas - End If - - Else - - 'ANTICIPOS - Dim CveIE As Integer = ObjIE.AddBancos_IE(1, 1, Fecha, Folio.ToString(), "", Total, 1, 1, "Anticipo Cliente", "", False, False, -1, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Total, 30, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total, Total, 66, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For - - End If - - '_______________________________________________________________ - - Else - NoEncontrados = NoEncontrados + 1 - StrRFCNoencontrados.AppendFormat("{0}
    ", RFC) - 'ErrorVentas = True - 'Exit For - End If - End If - - - Next - Else - For Each Row As DataRow In dt.FiltraParametros("RFC <> ''").Rows - - Dim Sucursal As String = dtsubp.FiltroPrimeroValor("CveSubProyecto", $"SubProyecto = '{Row("Sucursal").ToString()}'") - Dim TipoDocto As String = Row("Tipo Documento").ToString().Trim - Dim RFC As String = Row("RFC").ToString().Trim.Replace("-", "").Replace(" ", "") - Dim Serie As String = Row("Serie").ToString().Trim - Dim Folio As Integer = Row("Folio").ToString().ToEntero() - Dim Fecha As Date = Row("Fecha").ToString().ToDate - Dim FechaVencimiento As Date = Row("Fecha Vencimiento").ToString().ToDate - Dim ImpuestoLocal As Decimal = If(dt.Columns.Contains("ImpuestoLocal"), Row("ImpuestoLocal").ToString().ToDecimal, 0D) - Dim Amortizacion As Decimal = If(dt.Columns.Contains("Amort.Ant"), Row("Amort.Ant").ToString().ToDecimal, 0) - Dim CveCliente As Integer = DtClientes.FiltroPrimeroValor("CveCliente", $"RFC = '{RFC}'").ToString().ToEntero() - - If LastSerieFolioTipoDoc = $"{Serie}{Folio}{TipoDocto}" AndAlso UsuarioActual.CveEmpresa = 189 Then - EsDetalle = True - Else - LastSerieFolioTipoDoc = $"{Serie}{Folio}{TipoDocto}" - EsDetalle = False - End If - - Dim SubTotal As Decimal = 0 - Dim IVA As Decimal = 0 - Dim Total As Decimal = 0 - Dim Saldo As Decimal = 0 - Dim RetIVA As Decimal = 0 - Dim RetISR As Decimal = 0 - Dim IEPS As Decimal = 0 - - If UsuarioActual.CveEmpresa = 189 AndAlso Not EsDetalle Then - - For Each item As DataRow In dt.FiltraParametros($"RFC <> '' AND Folio = '{Row("Folio").ToString()}' AND Serie = '{Row("Serie").ToString()}' AND [Tipo Documento] = '{Row("Tipo Documento").ToString()}' ").Rows - SubTotal += item("SubTotal").ToString().ToDecimal - IVA += item("IVA").ToString().ToDecimal - Total += item("Total").ToString().ToDecimal - Saldo += item("Saldo").ToString().ToDecimal - RetIVA += item("Ret IVA").ToString().ToDecimal - RetISR += item("Ret ISR").ToString().ToDecimal - IEPS += item("IEPS").ToString().ToDecimal - Next - - Else - SubTotal = Row("SubTotal").ToString().ToDecimal - IVA = Row("IVA").ToString().ToDecimal - Total = Row("Total").ToString().ToDecimal - Saldo = Row("Saldo").ToString().ToDecimal - RetIVA = Row("Ret IVA").ToString().ToDecimal - RetISR = Row("Ret ISR").ToString().ToDecimal - IEPS = Row("IEPS").ToString().ToDecimal - End If - - Dim Moneda As String = Row("Moneda").ToString() - Dim TipoCambio As String = Row("Tipo Cambio").ToString() - Dim CveMoneda As Integer = 1 - Dim Vendedor As String = If(dt.Columns.Contains("Vendedor"), Row("Vendedor").ToString(), "") - Dim CveVendedor As Integer = 0 - - Dim CveClienteSucursal As Integer = 0 'Row("CveClienteSucursal").ToString().ToEntero() - Dim FolioFiscal As String = If(dt.Columns.Contains("Folio Fiscal"), Row("Folio Fiscal").ToString(), "") - Dim PorcentajeIVA As Decimal = If(dt.Columns.Contains("PorcentajeIVA"), Round(Row("PorcentajeIVA").ToString().ToDecimal, 2), 0) - Dim PorcentajeRetIVA As Decimal = If(dt.Columns.Contains("PorcentajeRetIVA"), Round(Row("PorcentajeRetIVA").ToString().ToDecimal, 4), 0) - Dim PorcentajeRetISR As Decimal = If(dt.Columns.Contains("PorcentajeRetISR"), Round(Row("PorcentajeRetISR").ToString().ToDecimal, 4), 0) - Dim PedidoContrato As String = If(dt.Columns.Contains("Pedido"), Row("Pedido").ToString(), "") - - GuardaLog(Sucursal + "-" + Row("Folio").ToString()) - 'Temporalmente SE BORRARA - Dim Transaccion As String = "" ' Row("Transaccion2").ToString() - Dim Folio2 As String = "" ' Row("Folio2").ToString() - Dim CodCliente As String = "" 'Row("CodCliente2").ToString() - - Dim IEPSDetalle As Decimal = 0 - Dim CantidadDetalle As Decimal = 0 - Dim PUDetalle As Decimal = 0 - Dim IVADetalle As Decimal = 0 - Dim PorcentajeIEPS As Decimal = 0 - - If IEPS > 0 Then - PorcentajeIEPS = If(dt.Columns.Contains("PorcentajeIEPS"), Round(Row("PorcentajeIEPS").ToString().ToDecimal, 4), 0) - End If - - If RblFormato.SelectedValue = "17" Then - - Dim CodigoDetalle As String = Row("Codigo").ToString - If CodigoDetalle.Trim.Length > 0 Then - Dim DrDetalles As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimero($"Codigo = '{CodigoDetalle}'") - - If DrDetalles IsNot Nothing Then - CvePS = DrDetalles("CvePS").ToString().ToEntero() - CveUnidadMedida = DrDetalles("CveUnidadMedida").ToString().ToEntero() - CveClasificacion = DrDetalles("CveClasificacion").ToString().ToEntero() - Else - Alert($"El código del producto no se encontro, error en registro {CountRow}") - ErrorVentas = True - End If - Else - Alert($"El código es requerido, error en registro {CountRow}") - ErrorVentas = True - End If - - IEPSDetalle = Row("IEPS").ToString.ToDecimal - CantidadDetalle = Row("Cantidad").ToString.ToDecimal - PUDetalle = Row("PU").ToString.ToDecimal - IVADetalle = Row("IVA").ToString.ToDecimal - - If CantidadDetalle = 0 Then - Alert($"No se especifico la cantidad, error en registro {CountRow}") - ErrorVentas = True - End If - - End If - - If dt.Columns.Contains("Cliente Sucursal") AndAlso Row("Cliente Sucursal").ToString() <> "" Then - - Dim ObjCliente As New ClsClientes - If ObjCliente.GetSucursales(CveCliente) Then - If ObjCliente.DtResultados.Rows.Count > 0 Then - CveClienteSucursal = ObjCliente.DtResultados.FiltroPrimeroValor("CveClienteSucursal", "SucursalCliente = '" & Row("Cliente Sucursal").ToString().Trim & "'").ToEntero - End If - End If - - ObjCliente.Dispose() - End If - - - 'If Not CveCliente > 0 Then Alert(String.Format("No se encontró el cliente con el RFC: {0}", {RFC}), TipoMensaje.MsgError) : ErrorVentas = True : RFC.GuardaLog : Exit For - TipoDocto = IIf(TipoDocto.ToUpper.Contiene("INGRESO", "INGRESOS", "ING", "FACTURA", "FACTURAS"), "Ing", IIf(TipoDocto.ToUpper.Contiene("EGRESO", "EGRESOS", "EGS"), "Egs", "Rem")).ToString() - 'PrePóliza - If Not EsDetalle Then - CvePrePoliza = ObjConta.AddPrePolizas("Venta/SaldoInicial", 1, Total, Total, 1, Fecha, String.Format("{0}-{1}", Serie, Folio), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - End If - - If Vendedor <> "" Then - CveVendedor = GlobalDTVendedores(UsuarioActual.CveEmpresa, VendedorTipo:=-1).FiltroPrimeroValor("CveVendedor", $"Vendedor = '{Vendedor}'").ToString().ToEntero() - If Not CveVendedor > 0 Then CveVendedor = 0 - Else - CveVendedor = 0 - End If - - 'Moneda - If Moneda.ToUpper.Contiene("PESOS", "PESO", "MXN") Then - CveMoneda = 1 - TipoCambio = "1" - ElseIf Moneda.ToUpper.Contiene("DÓLAR", "DÓLARES", "DOLARES", "USD") Then - CveMoneda = 2 - - If TipoCambio.Trim.ToDecimal < 10 Then - - If UsuarioActual.CveEmpresa.Contiene(13, 83) Then - TipoCambio = GlobalTipoCambio(Fecha.AddDays(-1)).ToString() - Else - TipoCambio = GlobalTipoCambio(Fecha).ToString() - End If - - End If - - End If - - 'Si no se especifica TC, se manda como pesos. - If TipoCambio = "" Then TipoCambio = "1" - - If Not CveClienteSucursal > 0 Then CveClienteSucursal = -1 - - If FechaVencimiento = "".ToDate Or FechaVencimiento < "1900/01/01".ToDate Then - FechaVencimiento = Fecha - End If - - - 'Venta - If CveCliente > 0 Then - - If TipoDocto.Contiene("Ing", "Egs", "Rem") Then - GuardaLog(Serie & "-" & Folio) - If Not EsDetalle Then - If Not ObjVentas.AddVenta(TipoDocto, Folio, CveCliente.ToEntero(), CveClienteSucursal, SubTotal, 0, Amortizacion, IVA, RetIVA, RetISR, Total, CveMoneda, TipoCambio.ToDecimal, - 0, 0, 0, FechaVencimiento, Fecha, "", "", Fecha, CveVendedor, Folio2, "", "", 0, 0, 0, "-1".ToDate, "-1".ToDate, "-1".ToDate, -1, 0, CvePrePoliza, - UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, Serie:=Serie, CveSubProyecto:=Sucursal.ToEntero(), CveSubProyectoEjecucion:=Sucursal.ToEntero(), - CveSubProyectoCobranza:=Sucursal.ToEntero(), IEPS:=IEPS, ObservacionesAlmacen:=Transaccion, Entrega:=CodCliente, ImpuestoLocal:=ImpuestoLocal, - PedidoContrato:=PedidoContrato, CveMetodoPago33:=3) Then - ErrorVentas = True - Exit For - Else - VentasAgregadas += 1 - End If - CveVenta = ObjVentas.CveVenta - End If - - If Not EsDetalle Then - SubTotal = Row("SubTotal").ToString().ToDecimal - IVA = Row("IVA").ToString().ToDecimal - Total = Row("Total").ToString().ToDecimal - Saldo = Row("Saldo").ToString().ToDecimal - RetIVA = Row("Ret IVA").ToString().ToDecimal - RetISR = Row("Ret ISR").ToString().ToDecimal - IEPS = Row("IEPS").ToString().ToDecimal - End If - - If RblFormato.SelectedValue = "17" Then - - Dim TotalDetalles As Decimal = SubTotal - If PUDetalle > 0 Then - TotalDetalles = (CantidadDetalle * PUDetalle) + IVA - RetIVA - RetISR + IEPSDetalle - End If - - If Math.Abs(TotalDetalles - Total) > 0.01 Then - ErrorVentas = True - Alert($"Registro {CountRow} El total no coincide con el acumulado de los detalles, total: {Total.ToString("###,###,###.00")} detatalle: {TotalDetalles.ToString("###,###,###.00")}", TipoMensaje.MsgAdvertencia) - Exit For - End If - - If Not ObjVentas.AddVentaDetalle(CveVenta, CvePS, CantidadDetalle, CveUnidadMedida, PUDetalle, IVADetalle, TotalDetalles, "Saldo Inicial", 0, 0, Sucursal.ToEntero(), 0, - PorcentajeIVA:=PorcentajeIVA, PorcentajeRetIVA:=PorcentajeRetIVA, ImporteRetIVA:=RetIVA, IEPS:=IEPSDetalle, PorcentajeRetISR:=PorcentajeRetISR, PorcentajeIEPS:=PorcentajeIEPS) Then - ErrorVentas = True - Exit For - End If - - Else - If Not ObjVentas.AddVentaDetalle(CveVenta, CvePS, 1, CveUnidadMedida, SubTotal, IVA, SubTotal * PorcentajeIVA, "Saldo Inicial", 0, 0, Sucursal.ToEntero(), 0, PorcentajeIVA:=PorcentajeIVA, PorcentajeRetIVA:=PorcentajeRetIVA, ImporteRetIVA:=RetIVA, IEPS:=0) Then - ErrorVentas = True - Exit For - End If - End If - - - - Dim ConceptoContable As Integer = 1 - Dim ConceptoContablePago As Integer = 2 - If TipoDocto = "Egs" Then - ConceptoContable = 12 - ConceptoContablePago = 91 - End If - - If FolioFiscal <> "" Then - If Not ObjVentas.UpdateVentaFolioFiscal(FolioFiscal, CveVenta, UsuarioActual.CveEmpresa) Then - ErrorVentas = True - Exit For - End If - End If - - Dim UsaComplementaria As Boolean = False - - If UsuarioActual.CveEmpresa.Contiene(119, 158) Then UsaComplementaria = True - - If Not EsDetalle Then - - SubTotal = 0 - IVA = 0 - Total = 0 - Saldo = 0 - RetIVA = 0 - RetISR = 0 - For Each item As DataRow In dt.FiltraParametros($"RFC <> '' AND Folio = '{Row("Folio").ToString()}' AND Serie = '{Row("Serie").ToString()}' AND [Tipo Documento] = '{Row("Tipo Documento").ToString()}' ").Rows - SubTotal += item("SubTotal").ToString().ToDecimal - IVA += item("IVA").ToString().ToDecimal - Total += item("Total").ToString().ToDecimal - Saldo += item("Saldo").ToString().ToDecimal - RetIVA += item("Ret IVA").ToString().ToDecimal - RetISR += item("Ret ISR").ToString().ToDecimal - IEPS += item("IEPS").ToString().ToDecimal - Next - - 'PrePólizaDetalle - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, SubTotal, SubTotal, 4, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, CveClasificacion:=CveClasificacion, CveSubProyecto:=Sucursal.ToEntero(), PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Total, ConceptoContable, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For - - If IVA > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IVA, IVA, 13, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - If IEPS > 0 Then - 'AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, Folio, 38, String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteMX:=IEPS) - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, IEPS, 38, Folio.ToString, String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For - - End If - - If RetIVA > 0 Then - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetISR, RetISR, 8, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeRetISR, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - If RetISR > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetISR, RetISR, 9, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeRetISR, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - If ImpuestoLocal > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImpuestoLocal, ImpuestoLocal, 27, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - - If UsaComplementaria Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total * TipoCambio.ToDecimal - Total, Total * TipoCambio.ToDecimal - Total, 203, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteME:=Total, TipoCambio:=TipoCambio.ToDecimal, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - 'Saldo - If Saldo < Total Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total - Saldo, Total - Saldo, ConceptoContablePago, Folio.ToString(), Folio.ToString(), CveVenta:=CveVenta, CveCliente:=CveCliente, CveVentaAmortizacion:=CveVenta, Contabilizable:=False) Then ErrorVentas = True : Exit For - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total - Saldo, Total - Saldo, 95, Folio.ToString(), Folio.ToString(), CveVenta:=CveVenta, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - End If - - Else - - If Not EsDetalle Then - - SubTotal = 0 - IVA = 0 - Total = 0 - Saldo = 0 - RetIVA = 0 - RetISR = 0 - For Each item As DataRow In dt.FiltraParametros($"RFC <> '' AND Folio = '{Row("Folio").ToString()}' AND Serie = '{Row("Serie").ToString()}' AND [Tipo Documento] = '{Row("Tipo Documento").ToString()}' ").Rows - SubTotal += item("SubTotal").ToString().ToDecimal - IVA += item("IVA").ToString().ToDecimal - Total += item("Total").ToString().ToDecimal - Saldo += item("Saldo").ToString().ToDecimal - RetIVA += item("Ret IVA").ToString().ToDecimal - RetISR += item("Ret ISR").ToString().ToDecimal - IEPS += item("IEPS").ToString().ToDecimal - Next - - 'ANTICIPOS - Dim CveIE As Integer = ObjIE.AddBancos_IE(1, 1, Fecha, Folio.ToString(), "", Total, 1, - 1, "Anticipo Cliente", "", False, False, -1, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Total, 30, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total, Total, 66, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - End If - Encontrados = Encontrados + 1 - - Else - NoEncontrados = NoEncontrados + 1 - StrRFCNoencontrados.AppendFormat("{0}
    ", RFC) - 'ErrorVentas = True - 'Exit For - End If - - CountRow = CountRow + 1 - Next - End If - - '********************************************************************************************************************************************************************************** - - If Not ErrorVentas Then - - If UsuarioActual.CveEmpresa = 189 Then - Alert(String.Format("Se agregaron: {0} Ventas correctamente. {1} no encontrados
    {2} ", VentasAgregadas, NoEncontrados, StrRFCNoencontrados), TipoMensaje.MsgInformacion) - Else - Alert(String.Format("Se agregaron: {0} Ventas correctamente. {1} no encontrados
    {2} ", Encontrados, NoEncontrados, StrRFCNoencontrados), TipoMensaje.MsgInformacion) - End If - - - ObjVentas.Commit() - TxtExcel.Text = "" - UpDatos.Update() - Else - Alert(String.Format("Error al registrar : {0} Ventas correctamente. {1} no encontrados
    {2} ", Encontrados, NoEncontrados, StrRFCNoencontrados), TipoMensaje.MsgError) - ObjVentas.RollBack() - End If - ObjVentas.Dispose() -#End Region + RegistraVentas(dt, True) ' R H - P E R S O N A L ElseIf RblFormato.SelectedValue = "6" Then @@ -3762,6 +2764,658 @@ Partial Class General_SaldosIniciales End If End If + End Sub + + Private Sub RegistraVentas(dt As DataTable, OpcionDetallada As Boolean) + + If Not OpcionDetallada Then + + Dim NoEncontrados As Integer = 0 + Dim Encontrados As Integer = 0 + Dim StrRFCNoencontrados As New StringBuilder + Dim drr As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimero("AplicaParaVenta = 1") + If drr Is Nothing Then + Alert("No existen productos para venta. favor de crear uno e intentar de nuevo", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + Dim ObjVentas As New ClsVentas + Dim ObjConta As New ClsContabilidad(ObjVentas.IniciaTransacSQL()) + Dim ObjIE As New ClsBancos(ObjVentas.IniciaTransacSQL()) + Dim ObjInv As New ClsInventarios(ObjVentas.IniciaTransacSQL()) + Dim ErrorVentas As Boolean = False + Dim CveVenta As Integer + Dim DtClientes As New DataTable + 'Dim ExisteVenta As Boolean = False + 'Dim Contador As Integer = 0 + DtClientes = GlobalDTCliente(UsuarioActual.CveEmpresa, Estatus:=-1) + Dim CvePS As Integer = drr("CvePS").ToString().ToEntero() + Dim CveUnidadMedida As Integer = drr("CveUnidadMedida").ToString().ToEntero() + Dim CveClasificacion As Integer = drr("CveClasificacion").ToString().ToEntero() + + If Not CvePS > 0 Then Alert(String.Format("No se encontró el Producto Servicio"), TipoMensaje.MsgError) : ErrorVentas = True + ' If Not CveSucursal > 0 Then Alert("No se encontró la sucursal.", TipoMensaje.MsgError) : ErrorVentas = True + If Not CveUnidadMedida > 0 Then Alert(String.Format("No se encontró la Unidad de Medida."), TipoMensaje.MsgError) : ErrorVentas = True + Dim dtsubp As DataTable = GlobalDTSubProyectos(UsuarioActual.CveEmpresa) + + Dim CountRow As Integer = 1 + For Each Row As DataRow In dt.FiltraParametros("RFC <> ''").Rows + Dim Sucursal As String = dtsubp.FiltroPrimeroValor("CveSubProyecto", $"SubProyecto = '{Row("Sucursal").ToString()}'") + Dim TipoDocto As String = Row("Tipo Documento").ToString().Trim + Dim RFC As String = Row("RFC").ToString().Trim.Replace("-", "").Replace(" ", "") + Dim Serie As String = Row("Serie").ToString().Trim + Dim Folio As Integer = Row("Folio").ToString().ToEntero() + Dim Fecha As Date = Row("Fecha").ToString().ToDate + Dim FechaVencimiento As Date = Row("Fecha Vencimiento").ToString().ToDate + Dim ImpuestoLocal As Decimal = If(dt.Columns.Contains("ImpuestoLocal"), Row("ImpuestoLocal").ToString().ToDecimal, 0D) + Dim Amortizacion As Decimal = If(dt.Columns.Contains("Amort.Ant"), Row("Amort.Ant").ToString().ToDecimal, 0) + Dim SubTotal As Decimal = Row("SubTotal").ToString().ToDecimal + Dim IVA As Decimal = Row("IVA").ToString().ToDecimal + Dim Total As Decimal = Row("Total").ToString().ToDecimal + Dim Saldo As Decimal = Row("Saldo").ToString().ToDecimal + Dim CveCliente As Integer = DtClientes.FiltroPrimeroValor("CveCliente", $"RFC = '{RFC}'").ToString().ToEntero() + Dim RetIVA As Decimal = Row("Ret IVA").ToString().ToDecimal + Dim RetISR As Decimal = Row("Ret ISR").ToString().ToDecimal + Dim Moneda As String = Row("Moneda").ToString() + Dim TipoCambio As String = Row("Tipo Cambio").ToString() + Dim CveMoneda As Integer = 1 + Dim Vendedor As String = If(dt.Columns.Contains("Vendedor"), Row("Vendedor").ToString(), "") + Dim CveVendedor As Integer = 0 + + Dim IEPS As Decimal = 0 + + If RblFormato.SelectedValue = "17" Then + IEPS = Row("IEPS").ToString().ToDecimal + End If + + Dim CveClienteSucursal As Integer = 0 'Row("CveClienteSucursal").ToString().ToEntero() + Dim FolioFiscal As String = If(dt.Columns.Contains("Folio Fiscal"), Row("Folio Fiscal").ToString(), "") + Dim PorcentajeIVA As Decimal = If(dt.Columns.Contains("PorcentajeIVA"), Round(Row("PorcentajeIVA").ToString().ToDecimal, 4), 0) + Dim PorcentajeRetIVA As Decimal = If(dt.Columns.Contains("PorcentajeRetIVA"), Round(Row("PorcentajeRetIVA").ToString().ToDecimal, 4), 0) + Dim PorcentajeRetISR As Decimal = If(dt.Columns.Contains("PorcentajeRetISR"), Round(Row("PorcentajeRetISR").ToString().ToDecimal, 4), 0) + Dim PedidoContrato As String = If(dt.Columns.Contains("Pedido"), Row("Pedido").ToString(), "") + + GuardaLog(Sucursal + "-" + Row("Folio").ToString()) + 'Temporalmente SE BORRARA + Dim Transaccion As String = "" ' Row("Transaccion2").ToString() + Dim Folio2 As String = "" ' Row("Folio2").ToString() + Dim CodCliente As String = "" 'Row("CodCliente2").ToString() + + Dim IEPSDetalle As Decimal = 0 + Dim CantidadDetalle As Decimal = 0 + Dim PUDetalle As Decimal = 0 + Dim IVADetalle As Decimal = 0 + Dim PorcentajeIEPS As Decimal = 0 + + If IEPS > 0 Then + PorcentajeIEPS = If(dt.Columns.Contains("PorcentajeIEPS"), Round(Row("PorcentajeIEPS").ToString().ToDecimal, 4), 0) + End If + + If RblFormato.SelectedValue = "17" Then + + Dim CodigoDetalle As String = Row("Codigo").ToString + If CodigoDetalle.Trim.Length > 0 Then + Dim DrDetalles As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimero($"Codigo = '{CodigoDetalle}'") + + If DrDetalles IsNot Nothing Then + CvePS = DrDetalles("CvePS").ToString().ToEntero() + CveUnidadMedida = DrDetalles("CveUnidadMedida").ToString().ToEntero() + CveClasificacion = DrDetalles("CveClasificacion").ToString().ToEntero() + Else + Alert($"El código del producto no se encontro, error en registro {CountRow}") + ErrorVentas = True + End If + Else + Alert($"El código es requerido, error en registro {CountRow}") + ErrorVentas = True + End If + + IEPSDetalle = Row("IEPS").ToString.ToDecimal + CantidadDetalle = Row("Cantidad").ToString.ToDecimal + PUDetalle = Row("PU").ToString.ToDecimal + IVADetalle = Row("IVA").ToString.ToDecimal + + If CantidadDetalle = 0 Then + Alert($"No se especifico la cantidad, error en registro {CountRow}") + ErrorVentas = True + End If + + End If + + If dt.Columns.Contains("Cliente Sucursal") AndAlso Row("Cliente Sucursal").ToString() <> "" Then + + Dim ObjCliente As New ClsClientes + If ObjCliente.GetSucursales(CveCliente) Then + If ObjCliente.DtResultados.Rows.Count > 0 Then + CveClienteSucursal = ObjCliente.DtResultados.FiltroPrimeroValor("CveClienteSucursal", "SucursalCliente = '" & Row("Cliente Sucursal").ToString().Trim & "'").ToEntero + End If + End If + + ObjCliente.Dispose() + End If + + + 'If Not CveCliente > 0 Then Alert(String.Format("No se encontró el cliente con el RFC: {0}", {RFC}), TipoMensaje.MsgError) : ErrorVentas = True : RFC.GuardaLog : Exit For + TipoDocto = IIf(TipoDocto.ToUpper.Contiene("INGRESO", "INGRESOS", "ING", "FACTURA", "FACTURAS"), "Ing", IIf(TipoDocto.ToUpper.Contiene("EGRESO", "EGRESOS", "EGS"), "Egs", IIf(TipoDocto.ToUpper.Contiene("ANTICIPO", "ANTICIPOS", "ANT"), "Ant", "Rem"))).ToString() + 'PrePóliza + Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("Venta/SaldoInicial", 1, Total, Total, 1, Fecha, String.Format("{0}-{1}", Serie, Folio), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + + If Vendedor <> "" Then + CveVendedor = GlobalDTVendedores(UsuarioActual.CveEmpresa, VendedorTipo:=-1).FiltroPrimeroValor("CveVendedor", $"Vendedor = '{Vendedor}'").ToString().ToEntero() + If Not CveVendedor > 0 Then CveVendedor = 0 + Else + CveVendedor = 0 + End If + + 'Moneda + If Moneda.ToUpper.Contiene("PESOS", "PESO", "MXN") Then + CveMoneda = 1 + TipoCambio = "1" + ElseIf Moneda.ToUpper.Contiene("DÓLAR", "DÓLARES", "DOLARES", "USD") Then + CveMoneda = 2 + + If TipoCambio.Trim.ToDecimal < 10 Then + + If UsuarioActual.CveEmpresa.Contiene(13, 83) Then + TipoCambio = GlobalTipoCambio(Fecha.AddDays(-1)).ToString() + Else + TipoCambio = GlobalTipoCambio(Fecha).ToString() + End If + + End If + + End If + + 'Si no se especifica TC, se manda como pesos. + If TipoCambio = "" Then TipoCambio = "1" + + If Not CveClienteSucursal > 0 Then CveClienteSucursal = -1 + + If FechaVencimiento = "".ToDate Or FechaVencimiento < "1900/01/01".ToDate Then + FechaVencimiento = Fecha + End If + + + 'Venta + If CveCliente > 0 Then + + + If TipoDocto.Contiene("Ing", "Egs", "Rem", "Ant") Then + GuardaLog(Serie & "-" & Folio) + If Not ObjVentas.AddVenta(TipoDocto, Folio, CveCliente.ToEntero(), CveClienteSucursal, SubTotal, 0, Amortizacion, IVA, RetIVA, RetISR, Total, CveMoneda, TipoCambio.ToDecimal, + 0, 0, 0, FechaVencimiento, Fecha, "", "", Fecha, CveVendedor, Folio2, "", "", 0, 0, 0, "-1".ToDate, "-1".ToDate, "-1".ToDate, -1, 0, CvePrePoliza, + UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, Serie:=Serie, CveSubProyecto:=Sucursal.ToEntero(), CveSubProyectoEjecucion:=Sucursal.ToEntero(), + CveSubProyectoCobranza:=Sucursal.ToEntero(), IEPS:=IEPS, ObservacionesAlmacen:=Transaccion, Entrega:=CodCliente, ImpuestoLocal:=ImpuestoLocal, + PedidoContrato:=PedidoContrato, CveMetodoPago33:=3) Then + ErrorVentas = True + Exit For + End If + CveVenta = ObjVentas.CveVenta + + If Not ErrorVentas Then + If Not ObjInv.ActualizarEsDevolucionVenta(CveVenta, 2) Then + ErrorVentas = True + Exit For + End If + End If + + If RblFormato.SelectedValue = "17" Then + + Dim TotalDetalles As Decimal = SubTotal + If PUDetalle > 0 Then + TotalDetalles = (CantidadDetalle * PUDetalle) + IVA - RetIVA - RetISR + IEPSDetalle + End If + + If Math.Abs(TotalDetalles - Total) > 0.01 Then + ErrorVentas = True + Alert($"Registro {CountRow} El total no coincide con el calculo de los detalles, total: {Total.ToString("###,###,###.00")} calculo detatalles: {TotalDetalles.ToString("###,###,###.00")}", TipoMensaje.MsgAdvertencia) + Exit For + End If + + If Not ObjVentas.AddVentaDetalle(CveVenta, CvePS, CantidadDetalle, CveUnidadMedida, PUDetalle, IVADetalle, TotalDetalles, "Saldo Inicial", 0, 0, Sucursal.ToEntero(), 0, + PorcentajeIVA:=PorcentajeIVA, PorcentajeRetIVA:=PorcentajeRetIVA, ImporteRetIVA:=RetIVA, IEPS:=IEPSDetalle, PorcentajeRetISR:=PorcentajeRetISR, PorcentajeIEPS:=PorcentajeIEPS) Then + ErrorVentas = True + Exit For + End If + + Else + If Not ObjVentas.AddVentaDetalle(CveVenta, CvePS, 1, CveUnidadMedida, SubTotal, IVA, SubTotal * PorcentajeIVA, "Saldo Inicial", 0, 0, Sucursal.ToEntero(), 0, PorcentajeIVA:=PorcentajeIVA, PorcentajeRetIVA:=PorcentajeRetIVA, ImporteRetIVA:=RetIVA, IEPS:=0) Then + ErrorVentas = True + Exit For + End If + End If + + Dim ConceptoContable As Integer = 1 + Dim ConceptoContablePago As Integer = 2 + If TipoDocto = "Egs" Then + ConceptoContable = 12 + ConceptoContablePago = 91 + End If + + If FolioFiscal <> "" Then + If Not ObjVentas.UpdateVentaFolioFiscal(FolioFiscal, CveVenta, UsuarioActual.CveEmpresa) Then + ErrorVentas = True + Exit For + End If + End If + + Dim UsaComplementaria As Boolean = False + + If UsuarioActual.CveEmpresa.Contiene(119, 158) Then UsaComplementaria = True + + 'PrePólizaDetalle + Dim tCveConcepto As Integer = 4 + If TipoDocto = "Ant" Then tCveConcepto = 3 + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, SubTotal, SubTotal, tCveConcepto, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, CveClasificacion:=CveClasificacion, CveSubProyecto:=Sucursal.ToEntero(), PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Total, ConceptoContable, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For + + If IVA > 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IVA, IVA, 13, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For + End If + + If IEPS > 0 Then + 'AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, Folio, 38, String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteMX:=IEPS) + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, IEPS, 38, Folio.ToString, String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For + + End If + + If RetIVA > 0 Then + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetISR, RetISR, 8, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeRetISR, Contabilizable:=False) Then ErrorVentas = True : Exit For + End If + + If RetISR > 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetISR, RetISR, 9, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeRetISR, Contabilizable:=False) Then ErrorVentas = True : Exit For + End If + + If ImpuestoLocal > 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImpuestoLocal, ImpuestoLocal, 27, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For + End If + + If UsaComplementaria Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total * TipoCambio.ToDecimal - Total, Total * TipoCambio.ToDecimal - Total, 203, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteME:=Total, TipoCambio:=TipoCambio.ToDecimal, Contabilizable:=False) Then ErrorVentas = True : Exit For + End If + + 'Saldo + If Saldo < Total Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total - Saldo, Total - Saldo, ConceptoContablePago, Folio.ToString(), Folio.ToString(), CveVenta:=CveVenta, CveCliente:=CveCliente, CveVentaAmortizacion:=CveVenta, Contabilizable:=False) Then ErrorVentas = True : Exit For + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total - Saldo, Total - Saldo, 95, Folio.ToString(), Folio.ToString(), CveVenta:=CveVenta, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For + End If + + Else + 'ANTICIPOS + Dim CveIE As Integer = ObjIE.AddBancos_IE(1, 1, Fecha, Folio.ToString(), "", Total, 1, + 1, "Anticipo Cliente", "", False, False, -1, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Total, 30, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total, Total, 66, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For + + End If + Encontrados = Encontrados + 1 + + Else + NoEncontrados = NoEncontrados + 1 + StrRFCNoencontrados.AppendFormat("{0}
    ", RFC) + ErrorVentas = True + Exit For + End If + + CountRow = CountRow + 1 + Next + If Not ErrorVentas Then + Alert(String.Format("Se agregaron: {0} Ventas correctamente. {1} no encontrados
    {2} ", Encontrados, NoEncontrados, StrRFCNoencontrados), TipoMensaje.MsgInformacion) + ObjVentas.Commit() + TxtExcel.Text = "" + UpDatos.Update() + Else + Alert(String.Format("Error al registrar : {0} Ventas correctamente. {1} no encontrados
    {2} ", Encontrados, NoEncontrados, StrRFCNoencontrados), TipoMensaje.MsgError) + ObjVentas.RollBack() + End If + ObjVentas.Dispose() + + Else + + Dim NoEncontrados As Integer = 0 + Dim VentasAgregadas As Integer = 0 + Dim Encontrados As Integer = 0 + Dim StrRFCNoencontrados As New StringBuilder + Dim drr As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimero("AplicaParaVenta = 1") + If drr Is Nothing Then + Alert("No existen productos para venta. favor de crear uno e intentar de nuevo", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + Dim ObjVentas As New ClsVentas + Dim ObjConta As New ClsContabilidad(ObjVentas.IniciaTransacSQL()) + Dim ObjIE As New ClsBancos(ObjVentas.IniciaTransacSQL()) + Dim ObjInv As New ClsInventarios(ObjVentas.IniciaTransacSQL()) + Dim ErrorVentas As Boolean = False + Dim CveVenta As Integer + Dim CvePrePoliza As Integer + Dim DtClientes As New DataTable + 'Dim ExisteVenta As Boolean = False + 'Dim Contador As Integer = 0 + DtClientes = GlobalDTCliente(UsuarioActual.CveEmpresa, Estatus:=-1) + Dim CvePS As Integer = drr("CvePS").ToString().ToEntero() + Dim CveUnidadMedida As Integer = drr("CveUnidadMedida").ToString().ToEntero() + Dim CveClasificacion As Integer = drr("CveClasificacion").ToString().ToEntero() + + If Not CvePS > 0 Then Alert(String.Format("No se encontró el Producto Servicio"), TipoMensaje.MsgError) : ErrorVentas = True + ' If Not CveSucursal > 0 Then Alert("No se encontró la sucursal.", TipoMensaje.MsgError) : ErrorVentas = True + If Not CveUnidadMedida > 0 Then Alert(String.Format("No se encontró la Unidad de Medida."), TipoMensaje.MsgError) : ErrorVentas = True + Dim dtsubp As DataTable = GlobalDTSubProyectos(UsuarioActual.CveEmpresa) + + Dim CountRow As Integer = 1 + Dim LastSerieFolioTipoDoc As String = String.Empty + Dim EsDetalle As Boolean = False + + + + Dim DTFoliosFiscales As DataTable = dt.FiltraParametros("[Folio Fiscal] <> ''", "", {"Folio Fiscal"}) + + For Each drFolioFiscal As DataRow In DTFoliosFiscales.Rows + Dim FolioFiscalActual As String = drFolioFiscal("Folio Fiscal").ToString + Dim DRVentaActual As DataRow = dt.FiltroPrimero($"[Folio Fiscal] = '{FolioFiscalActual}'") + + Dim Sucursal As String = dtsubp.FiltroPrimeroValor("CveSubProyecto", $"SubProyecto = '{DRVentaActual("Sucursal").ToString()}'") + Dim TipoDocto As String = DRVentaActual("Tipo Documento").ToString().Trim + Dim RFC As String = DRVentaActual("RFC").ToString().Trim.Replace("-", "").Replace(" ", "") + Dim Serie As String = DRVentaActual("Serie").ToString().Trim + Dim Folio As Integer = DRVentaActual("Folio").ToString().ToEntero() + Dim Fecha As Date = DRVentaActual("Fecha").ToString().ToDate + Dim FechaVencimiento As Date = DRVentaActual("Fecha Vencimiento").ToString().ToDate + Dim ImpuestoLocal As Decimal = If(dt.Columns.Contains("ImpuestoLocal"), DRVentaActual("ImpuestoLocal").ToString().ToDecimal, 0D) + Dim Amortizacion As Decimal = If(dt.Columns.Contains("Amort.Ant"), DRVentaActual("Amort.Ant").ToString().ToDecimal, 0) + Dim CveCliente As Integer = DtClientes.FiltroPrimeroValor("CveCliente", $"RFC = '{RFC}'").ToString().ToEntero() + + If LastSerieFolioTipoDoc = $"{Serie}{Folio}{TipoDocto}" AndAlso UsuarioActual.CveEmpresa = 189 Then + EsDetalle = True + Else + LastSerieFolioTipoDoc = $"{Serie}{Folio}{TipoDocto}" + EsDetalle = False + End If + + Dim SubTotal As Decimal = 0 + Dim IVA As Decimal = 0 + Dim Total As Decimal = 0 + Dim Saldo As Decimal = 0 + Dim RetIVA As Decimal = 0 + Dim RetISR As Decimal = 0 + Dim IEPS As Decimal = 0 + + SubTotal = DRVentaActual("SubTotal").ToString().ToDecimal + IVA = DRVentaActual("IVA").ToString().ToDecimal + Total = DRVentaActual("Total").ToString().ToDecimal + Saldo = DRVentaActual("Saldo").ToString().ToDecimal + RetIVA = DRVentaActual("Ret IVA").ToString().ToDecimal + RetISR = DRVentaActual("Ret ISR").ToString().ToDecimal + IEPS = DRVentaActual("IEPS").ToString().ToDecimal + + Dim Moneda As String = DRVentaActual("Moneda").ToString() + Dim TipoCambio As String = DRVentaActual("Tipo Cambio").ToString() + Dim CveMoneda As Integer = 1 + Dim Vendedor As String = If(dt.Columns.Contains("Vendedor"), DRVentaActual("Vendedor").ToString(), "") + Dim CveVendedor As Integer = 0 + + Dim CveClienteSucursal As Integer = 0 'Row("CveClienteSucursal").ToString().ToEntero() + 'Dim FolioFiscal As String = If(dt.Columns.Contains("Folio Fiscal"), DRVentaActual("Folio Fiscal").ToString(), "") + Dim PorcentajeIVA As Decimal = If(dt.Columns.Contains("PorcentajeIVA"), Round(DRVentaActual("PorcentajeIVA").ToString().ToDecimal, 2), 0) + Dim PorcentajeRetIVA As Decimal = If(dt.Columns.Contains("PorcentajeRetIVA"), Round(DRVentaActual("PorcentajeRetIVA").ToString().ToDecimal, 4), 0) + Dim PorcentajeRetISR As Decimal = If(dt.Columns.Contains("PorcentajeRetISR"), Round(DRVentaActual("PorcentajeRetISR").ToString().ToDecimal, 4), 0) + Dim PedidoContrato As String = If(dt.Columns.Contains("Pedido"), DRVentaActual("Pedido").ToString(), "") + + GuardaLog(Sucursal + "-" + DRVentaActual("Folio").ToString()) + 'Temporalmente SE BORRARA + Dim Transaccion As String = "" ' Row("Transaccion2").ToString() + Dim Folio2 As String = "" ' Row("Folio2").ToString() + Dim CodCliente As String = "" 'Row("CodCliente2").ToString() + + TipoDocto = IIf(TipoDocto.ToUpper.Contiene("INGRESO", "INGRESOS", "ING", "FACTURA", "FACTURAS"), "Ing", IIf(TipoDocto.ToUpper.Contiene("EGRESO", "EGRESOS", "EGS"), "Egs", "Rem")).ToString() + + 'Dim CantidadDetalle As Decimal = 0 + 'Dim PUDetalle As Decimal = 0 + 'Dim IVADetalle As Decimal = 0 + Dim PorcentajeIEPS As Decimal = 0 + + + Dim TotalDetalles As Decimal = 0 + For Each dRowDetalle As DataRow In dt.FiltraParametros($"[Folio Fiscal]='{FolioFiscalActual}'").Rows + Dim CantidadDetalle As Decimal = dRowDetalle("Cantidad").ToString.ToDecimal 'digo PU IVADetalle + Dim PuDetalle As Decimal = dRowDetalle("PU").ToString.ToDecimal + Dim IVADetalle As Decimal = dRowDetalle("IVADetalle").ToString.ToDecimal + Dim IEPSDetalle As Decimal = dRowDetalle("IEPS").ToString.ToDecimal + TotalDetalles += (CantidadDetalle * PuDetalle) + IVADetalle + IEPSDetalle + Next + + + If IEPS > 0 Then + PorcentajeIEPS = If(dt.Columns.Contains("PorcentajeIEPS"), Round(DRVentaActual("PorcentajeIEPS").ToString().ToDecimal, 4), 0) + End If + + If Math.Abs(TotalDetalles - Total) > 0.01 Then + ErrorVentas = True + Alert($"Registro {CountRow} El total no coincide con el acumulado de los detalles, total: {Total.ToString("###,###,###.00")} detatalle: {TotalDetalles.ToString("###,###,###.00")}", TipoMensaje.MsgAdvertencia) + Exit For + End If + + If Vendedor <> "" Then + CveVendedor = GlobalDTVendedores(UsuarioActual.CveEmpresa, VendedorTipo:=-1).FiltroPrimeroValor("CveVendedor", $"Vendedor = '{Vendedor}'").ToString().ToEntero() + If Not CveVendedor > 0 Then CveVendedor = 0 + Else + CveVendedor = 0 + End If + + If Moneda.ToUpper.Contiene("PESOS", "PESO", "MXN") Then + CveMoneda = 1 + TipoCambio = "1" + ElseIf Moneda.ToUpper.Contiene("DÓLAR", "DÓLARES", "DOLARES", "USD") Then + CveMoneda = 2 + + If TipoCambio.Trim.ToDecimal < 10 Then + + If UsuarioActual.CveEmpresa.Contiene(13, 83) Then + TipoCambio = GlobalTipoCambio(Fecha.AddDays(-1)).ToString() + Else + TipoCambio = GlobalTipoCambio(Fecha).ToString() + End If + + End If + + End If + + If TipoCambio = "" Then TipoCambio = "1" + + If Not CveClienteSucursal > 0 Then CveClienteSucursal = -1 + + If FechaVencimiento = "".ToDate Or FechaVencimiento < "1900/01/01".ToDate Then + FechaVencimiento = Fecha + End If + + If Not ErrorVentas Then + CvePrePoliza = ObjConta.AddPrePolizas("Venta/SaldoInicial", 1, Total, Total, CveMoneda, Fecha, String.Format("{0}-{1}", Serie, Folio), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + If Not CvePrePoliza > 0 Then + ErrorVentas = True + End If + End If + Dim VentayaRegistrada As Boolean = False + If Not ErrorVentas Then + 'Venta + If CveCliente > 0 Then + + If TipoDocto.Contiene("Ing", "Egs", "Rem") Then + GuardaLog(Serie & "-" & Folio) + CveVenta = 0 + Dim contador As Integer = 0 + 'verificar si existe la venta, si existe obtener el cveventa y limpiar su contenido para carga de lo nuevo. + If ObjVentas.GetVentas(UsuarioActual.CveEmpresa, TipoDocto, Serie, Folio, "-1", -1, -1, -1, -1, "2000-01-01", Now.ToShortDateString, FolioFiscalActual, CveUsuarioConsulta:=100) Then + If ObjVentas.DtResultados.Rows.Count > 0 Then + contador = 1 + CveVenta = ObjVentas.DtResultados.FiltroPrimeroValor("CveVenta").ToEntero + VentayaRegistrada = True + VentasAgregadas += 1 + 'limpieza de las partidas + If ObjVentas.GetVentaDetalle(CveVenta) Then + For Each dr As DataRow In ObjVentas.DtResultados.Rows + ObjVentas.RemoveVentasDetalle(CveVenta, dr("CveVentaDetalle").ToString.ToEntero) + Next + End If + + End If + End If + If Not EsDetalle AndAlso CveVenta = 0 Then + If Not ObjVentas.AddVenta(TipoDocto, Folio, CveCliente.ToEntero(), CveClienteSucursal, SubTotal, 0, Amortizacion, IVA, RetIVA, RetISR, Total, CveMoneda, TipoCambio.ToDecimal, + 0, 0, 0, FechaVencimiento, Fecha, "", "", Fecha, CveVendedor, Folio2, "", "", 0, 0, 0, "-1".ToDate, "-1".ToDate, "-1".ToDate, -1, 0, CvePrePoliza, + UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, Serie:=Serie, CveSubProyecto:=Sucursal.ToEntero(), CveSubProyectoEjecucion:=Sucursal.ToEntero(), + CveSubProyectoCobranza:=Sucursal.ToEntero(), IEPS:=IEPS, ObservacionesAlmacen:=Transaccion, Entrega:=CodCliente, ImpuestoLocal:=ImpuestoLocal, + PedidoContrato:=PedidoContrato, CveMetodoPago33:=3) Then + ErrorVentas = True + Exit For + Else + VentasAgregadas += 1 + End If + CveVenta = ObjVentas.CveVenta + End If + + If Not ErrorVentas Then + If Not ObjInv.ActualizarEsDevolucionVenta(CveVenta, 2) Then + ErrorVentas = True + Exit For + End If + End If + + For Each dRowDetalle As DataRow In dt.FiltraParametros($"[Folio Fiscal]='{FolioFiscalActual}'").Rows + + Dim CantidadDetalle As Decimal = dRowDetalle("Cantidad").ToString.ToDecimal 'digo PU IVADetalle + Dim PuDetalle As Decimal = dRowDetalle("PU").ToString.ToDecimal + Dim IVADetalle As Decimal = dRowDetalle("IVADetalle").ToString.ToDecimal + Dim IEPSDetalle As Decimal = dRowDetalle("IEPS").ToString.ToDecimal + Dim PorcentajeIEPSDetalle = dRowDetalle("PorcentajeIEPS").ToString.ToDecimal + + Dim CodigoDetalle As String = dRowDetalle("Codigo").ToString + If CodigoDetalle.Trim.Length > 0 Then + Dim DrDetalles As DataRow = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa).FiltroPrimero($"Codigo = '{CodigoDetalle}'") + + If DrDetalles IsNot Nothing Then + CvePS = DrDetalles("CvePS").ToString().ToEntero() + CveUnidadMedida = DrDetalles("CveUnidadMedida").ToString().ToEntero() + CveClasificacion = DrDetalles("CveClasificacion").ToString().ToEntero() + Else + Alert($"El código del producto no se encontro, error en registro {CountRow}") + ErrorVentas = True + End If + Else + Alert($"El código es requerido, error en registro {CountRow}") + ErrorVentas = True + End If + + If Not ErrorVentas Then + If Not ObjVentas.AddVentaDetalle(CveVenta, CvePS, CantidadDetalle, CveUnidadMedida, PuDetalle, IVADetalle, TotalDetalles, "Saldo Inicial", 0, 0, Sucursal.ToEntero(), 0, + PorcentajeIVA:=PorcentajeIVA, PorcentajeRetIVA:=PorcentajeRetIVA, ImporteRetIVA:=0, IEPS:=IEPSDetalle, PorcentajeRetISR:=0, PorcentajeIEPS:=PorcentajeIEPSDetalle, + EstatusAlmacen:=1) Then + ErrorVentas = True + Exit For + End If + End If + + Next + + If Not VentayaRegistrada Then + Dim ConceptoContable As Integer = 1 + Dim ConceptoContablePago As Integer = 2 + If TipoDocto = "Egs" Then + ConceptoContable = 12 + ConceptoContablePago = 91 + End If + + If FolioFiscalActual <> "" Then + If Not ObjVentas.UpdateVentaFolioFiscal(FolioFiscalActual, CveVenta, UsuarioActual.CveEmpresa) Then + ErrorVentas = True + Exit For + End If + End If + + Dim UsaComplementaria As Boolean = False + + If UsuarioActual.CveEmpresa.Contiene(119, 158) Then UsaComplementaria = True + + 'PrePólizaDetalle + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, SubTotal, SubTotal, 4, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, CveClasificacion:=CveClasificacion, CveSubProyecto:=Sucursal.ToEntero(), PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Total, ConceptoContable, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For + + If IVA > 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IVA, IVA, 13, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For + End If + + If IEPS > 0 Then + 'AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, Folio, 38, String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteMX:=IEPS) + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, IEPS, 38, Folio.ToString, String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For + + End If + + If RetIVA > 0 Then + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetISR, RetISR, 8, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeRetISR, Contabilizable:=False) Then ErrorVentas = True : Exit For + End If + + If RetISR > 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetISR, RetISR, 9, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeRetISR, Contabilizable:=False) Then ErrorVentas = True : Exit For + End If + + If ImpuestoLocal > 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImpuestoLocal, ImpuestoLocal, 27, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For + End If + + If UsaComplementaria Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total * TipoCambio.ToDecimal - Total, Total * TipoCambio.ToDecimal - Total, 203, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteME:=Total, TipoCambio:=TipoCambio.ToDecimal, Contabilizable:=False) Then ErrorVentas = True : Exit For + End If + + 'Saldo + If Saldo < Total Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total - Saldo, Total - Saldo, ConceptoContablePago, Folio.ToString(), Folio.ToString(), CveVenta:=CveVenta, CveCliente:=CveCliente, CveVentaAmortizacion:=CveVenta, Contabilizable:=False) Then ErrorVentas = True : Exit For + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total - Saldo, Total - Saldo, 95, Folio.ToString(), Folio.ToString(), CveVenta:=CveVenta, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For + End If + End If + + If Not ErrorVentas Then + VentasAgregadas += VentasAgregadas + End If + + Else + + 'ANTICIPOS + Dim CveIE As Integer = ObjIE.AddBancos_IE(1, 1, Fecha, Folio.ToString(), "", Total, 1, 1, "Anticipo Cliente", "", False, False, -1, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Total, 30, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total, Total, 66, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For + + End If + + '_______________________________________________________________ + + Else + NoEncontrados = NoEncontrados + 1 + StrRFCNoencontrados.AppendFormat("{0}
    ", RFC) + 'ErrorVentas = True + 'Exit For + End If + End If + + Next + + '********************************************************************************************************************************************************************************** + + If Not ErrorVentas Then + ObjVentas.Commit() + + Alert(String.Format("Se agregaron: {0} Ventas correctamente. {1} no encontrados
    {2} ", VentasAgregadas, NoEncontrados, StrRFCNoencontrados), TipoMensaje.MsgInformacion) + TxtExcel.Text = "" + UpDatos.Update() + Else + Alert(String.Format("Error al registrar : {0} Ventas correctamente. {1} no encontrados
    {2} ", Encontrados, NoEncontrados, StrRFCNoencontrados), TipoMensaje.MsgError) + ObjVentas.RollBack() + End If + ObjVentas.Dispose() + End If + + End Sub diff --git a/Inventarios/RecepcionDevolucion.aspx.vb b/Inventarios/RecepcionDevolucion.aspx.vb index 591c7dd84..ac903a206 100644 --- a/Inventarios/RecepcionDevolucion.aspx.vb +++ b/Inventarios/RecepcionDevolucion.aspx.vb @@ -372,29 +372,29 @@ Partial Class Inventarios_RecepcionDevolucion Dim ObjCliente As New ClsClientes If ObjCliente.GetClientes(CveCliente, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa, -1, TipoCliente:=-1) Then If ObjCliente.DtResultados.Rows.Count > 0 Then - Me.ObjRemisionNC.CveFormaPago = ObjCliente.CveFormaPago33 - 'Me.ObjRemisionNC.FormaPago33 = GlobalDTVtaFormaPago.FiltroPrimeroValor("FormaPago", String.Format("CveFormaPago = {0}", ObjCliente.CveFormaPago33)) - 'Me.ObjRemisionNC.FormaPagoSAT33 = GlobalDTVtaFormaPago.FiltroPrimeroValor("ClaveFormaPagoSAT", String.Format("CveFormaPago = {0}", ObjCliente.CveFormaPago33)) + Me.ObjRemisionNC.CveFormaPago = ObjCliente.CveFormaPago + 'Me.ObjRemisionNC.FormaPago33 = GlobalDTVtaFormaPago.FiltroPrimeroValor("FormaPago", String.Format("CveFormaPago = {0}", ObjCliente.CveFormaPago)) + 'Me.ObjRemisionNC.FormaPagoSAT33 = GlobalDTVtaFormaPago.FiltroPrimeroValor("ClaveFormaPagoSAT", String.Format("CveFormaPago = {0}", ObjCliente.CveFormaPago)) - Me.ObjRemisionNC.CveMetodoPago = ObjCliente.CveMetodoPago33 - 'Me.ObjRemisionNC.MetodoPago33 = GlobalDTVtaMetodoPago.FiltroPrimeroValor("MetodoPago", String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago33)) - 'Me.ObjRemisionNC.ClaveMetodoPagoSAT = GlobalDTVtaMetodoPago.FiltroPrimeroValor("ClaveMetodoPagoSAT", String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago33)) + Me.ObjRemisionNC.CveMetodoPago = ObjCliente.CveMetodoPago + 'Me.ObjRemisionNC.MetodoPago33 = GlobalDTVtaMetodoPago.FiltroPrimeroValor("MetodoPago", String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago)) + 'Me.ObjRemisionNC.ClaveMetodoPagoSAT = GlobalDTVtaMetodoPago.FiltroPrimeroValor("ClaveMetodoPagoSAT", String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago)) Me.ObjRemisionNC.CveUsoCFDI = ObjCliente.CveUsoCFDI 'Me.ObjRemisionNC.UsoCFDI = GlobalDTSATUsosCFDI.FiltroPrimeroValor("Descripcion", String.Format("CveUsoCFDI = {0}", ObjCliente.CveUsoCFDI)) 'Me.ObjRemisionNC.ClaveUsoCFDI = GlobalDTSATUsosCFDI.FiltroPrimeroValor("UsoCFDI", String.Format("CveUsoCFDI = {0}", ObjCliente.CveUsoCFDI)) - Me.ObjRemisionNC.CveMetodoPago = ObjCliente.CveMetodoPago33 + Me.ObjRemisionNC.CveMetodoPago = ObjCliente.CveMetodoPago - If GlobalDTVtaMetodoPago.FiltraParametros(String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago33)).Rows.Count > 0 Then - Me.ObjRemisionNC.MetodoPago = GlobalDTVtaMetodoPago.FiltraParametros(String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago33)).Rows(0)("MetodoPago").ToString + If GlobalDTVtaMetodoPago.FiltraParametros(String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago)).Rows.Count > 0 Then + Me.ObjRemisionNC.MetodoPago = GlobalDTVtaMetodoPago.FiltraParametros(String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago)).Rows(0)("MetodoPago").ToString Else Me.ObjRemisionNC.CveMetodoPago = 1 Me.ObjRemisionNC.MetodoPago = "Efectivo" End If If UsuarioActual.CveEmpresa = 119 Then - Me.ObjRemisionNC.CveFormaPago = 20 'POR DEFINIR AND (@CveMetodoPago33 = 3 AND @CveFormaPago33 <> 20) + Me.ObjRemisionNC.CveFormaPago = 20 'POR DEFINIR AND (@CveMetodoPago = 3 AND @CveFormaPago33 <> 20) If Me.ObjRemisionNC.CveMetodoPago = 3 Then Me.ObjRemisionNC.CveFormaPago = 20 End If diff --git a/Inventarios/RecepcionUsados.aspx.vb b/Inventarios/RecepcionUsados.aspx.vb index a1a33d492..8e300748a 100644 --- a/Inventarios/RecepcionUsados.aspx.vb +++ b/Inventarios/RecepcionUsados.aspx.vb @@ -2455,22 +2455,22 @@ Partial Class Inventarios_RecepcionUsados Dim ObjCliente As New ClsClientes If ObjCliente.GetClientes(CveCliente, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa, -1, TipoCliente:=-1) Then If ObjCliente.DtResultados.Rows.Count > 0 Then - Me.ObjRemisionNC.CveFormaPago = ObjCliente.CveFormaPago33 - 'Me.ObjRemisionNC.FormaPago33 = GlobalDTVtaFormaPago.FiltroPrimeroValor("FormaPago", String.Format("CveFormaPago = {0}", ObjCliente.CveFormaPago33)) - 'Me.ObjRemisionNC.FormaPagoSAT33 = GlobalDTVtaFormaPago.FiltroPrimeroValor("ClaveFormaPagoSAT", String.Format("CveFormaPago = {0}", ObjCliente.CveFormaPago33)) + Me.ObjRemisionNC.CveFormaPago = ObjCliente.CveFormaPago + 'Me.ObjRemisionNC.FormaPago33 = GlobalDTVtaFormaPago.FiltroPrimeroValor("FormaPago", String.Format("CveFormaPago = {0}", ObjCliente.CveFormaPago)) + 'Me.ObjRemisionNC.FormaPagoSAT33 = GlobalDTVtaFormaPago.FiltroPrimeroValor("ClaveFormaPagoSAT", String.Format("CveFormaPago = {0}", ObjCliente.CveFormaPago)) - Me.ObjRemisionNC.CveMetodoPago = ObjCliente.CveMetodoPago33 - 'Me.ObjRemisionNC.MetodoPago33 = GlobalDTVtaMetodoPago.FiltroPrimeroValor("MetodoPago", String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago33)) - 'Me.ObjRemisionNC.ClaveMetodoPagoSAT = GlobalDTVtaMetodoPago.FiltroPrimeroValor("ClaveMetodoPagoSAT", String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago33)) + Me.ObjRemisionNC.CveMetodoPago = ObjCliente.CveMetodoPago + 'Me.ObjRemisionNC.MetodoPago33 = GlobalDTVtaMetodoPago.FiltroPrimeroValor("MetodoPago", String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago)) + 'Me.ObjRemisionNC.ClaveMetodoPagoSAT = GlobalDTVtaMetodoPago.FiltroPrimeroValor("ClaveMetodoPagoSAT", String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago)) Me.ObjRemisionNC.CveUsoCFDI = ObjCliente.CveUsoCFDI 'Me.ObjRemisionNC.UsoCFDI = GlobalDTSATUsosCFDI.FiltroPrimeroValor("Descripcion", String.Format("CveUsoCFDI = {0}", ObjCliente.CveUsoCFDI)) 'me.ObjRemisionNC.ClaveUsoCFDI = GlobalDTSATUsosCFDI.FiltroPrimeroValor("UsoCFDI", String.Format("CveUsoCFDI = {0}", ObjCliente.CveUsoCFDI)) - Me.ObjRemisionNC.CveMetodoPago = ObjCliente.CveMetodoPago33 + Me.ObjRemisionNC.CveMetodoPago = ObjCliente.CveMetodoPago 'If GlobalDTMetodosPago IsNot Nothing Then - ' Dim DtMetodoPago As DataTable = GlobalDTMetodosPago.FiltraParametros(String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago33)) + ' Dim DtMetodoPago As DataTable = GlobalDTMetodosPago.FiltraParametros(String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago)) ' If DtMetodoPago IsNot Nothing Then diff --git a/Inventarios/Remanufactura.aspx.vb b/Inventarios/Remanufactura.aspx.vb index e3d85837c..8d374924d 100644 --- a/Inventarios/Remanufactura.aspx.vb +++ b/Inventarios/Remanufactura.aspx.vb @@ -466,13 +466,13 @@ Partial Class Inventarios_Remanufactura 'If ObjCliente.GetClientes(DdlCliente.SelectedValue.ToEntero, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa, -1, TipoCliente:=-1) Then ' If ObjCliente.DtResultados.Rows.Count > 0 Then - ' ObjFactura.CveFormaPago33 = ObjCliente.CveFormaPago33 - ' ObjFactura.FormaPago33 = GlobalDTVtaFormaPago.FiltroPrimeroValor("FormaPago", $"CveFormaPago = {ObjCliente.CveFormaPago33}") - ' ObjFactura.FormaPagoSAT33 = GlobalDTVtaFormaPago.FiltroPrimeroValor("ClaveFormaPagoSAT", $"CveFormaPago = {ObjCliente.CveFormaPago33}") + ' ObjFactura.CveFormaPago = ObjCliente.CveFormaPago + ' ObjFactura.FormaPago33 = GlobalDTVtaFormaPago.FiltroPrimeroValor("FormaPago", $"CveFormaPago = {ObjCliente.CveFormaPago}") + ' ObjFactura.FormaPagoSAT33 = GlobalDTVtaFormaPago.FiltroPrimeroValor("ClaveFormaPagoSAT", $"CveFormaPago = {ObjCliente.CveFormaPago}") - ' ObjFactura.CveMetodoPago33 = ObjCliente.CveMetodoPago33 - ' ObjFactura.MetodoPago33 = GlobalDTVtaMetodoPago.FiltroPrimeroValor("MetodoPago", $"CveMetodoPago = {ObjCliente.CveMetodoPago33}") - ' ObjFactura.ClaveMetodoPagoSAT = GlobalDTVtaMetodoPago.FiltroPrimeroValor("ClaveMetodoPagoSAT", $"CveMetodoPago = {ObjCliente.CveMetodoPago33}") + ' ObjFactura.CveMetodoPago = ObjCliente.CveMetodoPago + ' ObjFactura.MetodoPago33 = GlobalDTVtaMetodoPago.FiltroPrimeroValor("MetodoPago", $"CveMetodoPago = {ObjCliente.CveMetodoPago}") + ' ObjFactura.ClaveMetodoPagoSAT = GlobalDTVtaMetodoPago.FiltroPrimeroValor("ClaveMetodoPagoSAT", $"CveMetodoPago = {ObjCliente.CveMetodoPago}") ' ObjFactura.CveUsoCFDI = ObjCliente.CveUsoCFDI ' ObjFactura.UsoCFDI = GlobalDTSATUsosCFDI.FiltroPrimeroValor("Descripcion", $"CveUsoCFDI = {ObjCliente.CveUsoCFDI}") @@ -620,7 +620,7 @@ Partial Class Inventarios_Remanufactura 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.CveFormaPago, - CveMetodoPago33:=factura.CveMetodoPago, CveUsoCFDI:=factura.CveUsoCFDI) Then + CveMetodoPago:=factura.CveMetodoPago, CveUsoCFDI:=factura.CveUsoCFDI) Then ErrorList.Add("Ocurrió un error al Generar la Venta.
    Revise su factura y cualquier detalle comuníquese a Soporte Técnico") End If diff --git a/PortalCliente/PortalCliente.aspx.vb b/PortalCliente/PortalCliente.aspx.vb index d0fd34a97..0dfc8214a 100644 --- a/PortalCliente/PortalCliente.aspx.vb +++ b/PortalCliente/PortalCliente.aspx.vb @@ -3038,21 +3038,21 @@ Partial Class Ventas_PortalCliente 'Dim ObjCliente As New ClsClientes 'If ObjCliente.GetClientes(CveCliente, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa, -1, TipoCliente:=-1) Then ' If ObjCliente.DtResultados.Rows.Count > 0 Then - ' ObjFactura.CveFormaPago33 = ObjCliente.CveFormaPago33 - ' ObjFactura.FormaPago33 = GlobalDTVtaFormaPago.FiltroPrimeroValor("FormaPago", $"CveFormaPago = {ObjCliente.CveFormaPago33}") - ' ObjFactura.FormaPagoSAT33 = GlobalDTVtaFormaPago.FiltroPrimeroValor("ClaveFormaPagoSAT", $"CveFormaPago = {ObjCliente.CveFormaPago33}") + ' ObjFactura.CveFormaPago = ObjCliente.CveFormaPago + ' ObjFactura.FormaPago33 = GlobalDTVtaFormaPago.FiltroPrimeroValor("FormaPago", $"CveFormaPago = {ObjCliente.CveFormaPago}") + ' ObjFactura.FormaPagoSAT33 = GlobalDTVtaFormaPago.FiltroPrimeroValor("ClaveFormaPagoSAT", $"CveFormaPago = {ObjCliente.CveFormaPago}") - ' ObjFactura.CveMetodoPago33 = ObjCliente.CveMetodoPago33 - ' ObjFactura.MetodoPago33 = GlobalDTVtaMetodoPago.FiltroPrimeroValor("MetodoPago", $"CveMetodoPago = {ObjCliente.CveMetodoPago33}") - ' ObjFactura.ClaveMetodoPagoSAT = GlobalDTVtaMetodoPago.FiltroPrimeroValor("ClaveMetodoPagoSAT", $"CveMetodoPago = {ObjCliente.CveMetodoPago33}") + ' ObjFactura.CveMetodoPago = ObjCliente.CveMetodoPago + ' ObjFactura.MetodoPago33 = GlobalDTVtaMetodoPago.FiltroPrimeroValor("MetodoPago", $"CveMetodoPago = {ObjCliente.CveMetodoPago}") + ' ObjFactura.ClaveMetodoPagoSAT = GlobalDTVtaMetodoPago.FiltroPrimeroValor("ClaveMetodoPagoSAT", $"CveMetodoPago = {ObjCliente.CveMetodoPago}") ' ObjFactura.CveUsoCFDI = ObjCliente.CveUsoCFDI ' ObjFactura.UsoCFDI = GlobalDTSATUsosCFDI.FiltroPrimeroValor("Descripcion", $"CveUsoCFDI = {ObjCliente.CveUsoCFDI}") ' ObjFactura.ClaveUsoCFDI = GlobalDTSATUsosCFDI.FiltroPrimeroValor("UsoCFDI", $"CveUsoCFDI = {ObjCliente.CveUsoCFDI}") - ' ObjFactura.CveMetodoPago33 = ObjCliente.CveMetodoPago33 - ' If GlobalDTMetodosPago.FiltraParametros($"CveMetodoPago33 = {ObjCliente.CveMetodoPago33}").Rows.Count > 0 Then - ' ObjFactura.MetodoPago = GlobalDTMetodosPago.FiltraParametros($"CveMetodoPago33 = {ObjCliente.CveMetodoPago33}").Rows(0)("MetodoPago").ToString + ' ObjFactura.CveMetodoPago = ObjCliente.CveMetodoPago + ' If GlobalDTMetodosPago.FiltraParametros($"CveMetodoPago = {ObjCliente.CveMetodoPago}").Rows.Count > 0 Then + ' ObjFactura.MetodoPago = GlobalDTMetodosPago.FiltraParametros($"CveMetodoPago = {ObjCliente.CveMetodoPago}").Rows(0)("MetodoPago").ToString ' Else ' ObjFactura.CveMetodoPago = 1 ' ObjFactura.MetodoPago = "Efectivo" @@ -3459,7 +3459,7 @@ Partial Class Ventas_PortalCliente AtencionA:=factura.AtencionA, CveContrato:=factura.CveContrato, Det_FechaOrdenCompra:=factura.Det_FechaOrdenCompra, Det_OrdenCompra:=factura.Det_OrdenCompra, otros:=factura.Otros, CveAlmacenTraspasoDestino:=CveAlmacenTraspasoDestino, CveAlmacenTraspasoOrigen:=CveAlmacenTraspasoOrigen, IEPS:=factura.IEPSTC, Serie:=factura.Serie, CveSubProyecto:=factura.CveSubProyecto, CveSubProyectoCobranza:=factura.CveSubProyectoCobranza, CveSubProyectoEjecucion:=factura.CveSubProyectoEjecucion, CveFormaPago33:=factura.CveFormaPago, - CveMetodoPago33:=factura.CveMetodoPago, CveUsoCFDI:=factura.CveUsoCFDI, CveTipoRelacion:=factura.CveTipoRelacion, ImpuestoLocal:=TotalImpuestoLocal, + CveMetodoPago:=factura.CveMetodoPago, CveUsoCFDI:=factura.CveUsoCFDI, CveTipoRelacion:=factura.CveTipoRelacion, ImpuestoLocal:=TotalImpuestoLocal, CveVentaRelacion:=(If(factura.CveVentaRelacion.ToEntero > 0, factura.CveVentaRelacion, -1)), ImporteRelacion:=(If(factura.ImporteRelacion <> Nothing, factura.ImporteRelacion, -1)), CveTipoAmortizacionAnticipo:=factura.CveTipoAmortizacionAnticipo) Then diff --git a/Sistemas/Empresa.aspx b/Sistemas/Empresa.aspx index f6b0d3717..bc5697216 100644 --- a/Sistemas/Empresa.aspx +++ b/Sistemas/Empresa.aspx @@ -1426,7 +1426,7 @@ diff --git a/Ventas/Clientes.aspx.vb b/Ventas/Clientes.aspx.vb index 4a7558dfc..28daf19eb 100644 --- a/Ventas/Clientes.aspx.vb +++ b/Ventas/Clientes.aspx.vb @@ -922,7 +922,7 @@ Partial Class Clientes LnkPersonaFisica.Visible = True End If - InicializaDevolverDinero() + 'InicializaDevolverDinero() TxtFechaICredito.Text = NowADS().AddYears(-2).ToShortDateString() TxtFechaFCredito.Text = NowADS().ToShortDateString() @@ -1632,7 +1632,7 @@ Partial Class Clientes DdlUsoCFDI.SelectedValueExist(ObjClientes.CveUsoCFDI.ToString()) DdlMetodoPago33.SelectedValueExist(ObjClientes.CveMetodoPago.ToString()) - 'DdlFormaPago33.SelectedValueExist(ObjClientes.CveFormaPago33.ToString()) + 'DdlFormaPago33.SelectedValueExist(ObjClientes.CveFormaPago.ToString()) CargaFormaDePago(ObjClientes.CveFormaPago) If ObjClientes.CveRegimenFiscal > 0 Then DdlRegimenFiscal.SelectedValueExist(ObjClientes.CveRegimenFiscal) @@ -1956,12 +1956,8 @@ Partial Class Clientes DtClientesAnticipo = Nothing GVAnticiposHistorial.DataSource = Nothing DtAnticipoHistorial = Nothing - End If + End If ObjMovtos.Dispose() - - 'If UsuarioActual.Empresa.Funcionalidad(185) = "1" AndAlso UsuarioActual.TienePermisoProceso(379) Then - ' GVAnticipos.Columns(7).Visible = True - 'End If GVAnticipos.DataBind() GVAnticiposHistorial.DataBind() @@ -2279,7 +2275,7 @@ Partial Class Clientes Cuerpo = Cuerpo.Replace("{""NombreEmpresa""}", UsuarioActual.Empresa.Empresa) Cuerpo = Cuerpo.Replace("{""NombreCliente""}", LtlCliente.Text.Trim) Cuerpo = Cuerpo.Replace("{""TipoDocumento""}", TipoComprobante) - Cuerpo = Cuerpo.Replace("{""FolioFactura""}", HdnSerieFolio.Value.ToString()) + Cuerpo = Cuerpo.Replace("{""SerieFolio""}", HdnSerieFolio.Value.ToString()) If Dr IsNot Nothing Then Cuerpo = Cuerpo.Replace("{""FechaFactura""}", Dr("Fecha").ToString().ToDate().ToShortDateString()) @@ -2297,7 +2293,7 @@ Partial Class Clientes Asunto = Asunto.Replace("{""NombreEmpresa""}", UsuarioActual.Empresa.Empresa) Asunto = Asunto.Replace("{""NombreCliente""}", LtlCliente.Text.Trim) Asunto = Asunto.Replace("{""TipoDocumento""}", TipoComprobante) - Asunto = Asunto.Replace("{""FolioFactura""}", HdnSerieFolio.Value.ToString()) + Asunto = Asunto.Replace("{""SerieFolio""}", HdnSerieFolio.Value.ToString()) If Dr IsNot Nothing Then Asunto = Asunto.Replace("{""FechaFactura""}", Dr("Fecha").ToString().ToDate().ToShortDateString()) @@ -2318,7 +2314,7 @@ Partial Class Clientes Cuerpo = Cuerpo.Replace("{""NombreEmpresa""}", UsuarioActual.Empresa.Empresa) Cuerpo = Cuerpo.Replace("{""NombreCliente""}", LtlCliente.Text.Trim) Cuerpo = Cuerpo.Replace("{""TipoDocumento""}", TipoComprobante) - Cuerpo = Cuerpo.Replace("{""FolioFactura""}", HdnSerieFolio.Value.ToString()) + Cuerpo = Cuerpo.Replace("{""SerieFolio""}", HdnSerieFolio.Value.ToString()) If Dr IsNot Nothing Then Cuerpo = Cuerpo.Replace("{""FechaFactura""}", Dr("Fecha").ToString().ToDate().ToShortDateString()) Cuerpo = Cuerpo.Replace("{""ImporteFactura""}", Dr("Total").ToString().FormatoNumero()) @@ -2335,7 +2331,7 @@ Partial Class Clientes Asunto = Asunto.Replace("{""NombreEmpresa""}", UsuarioActual.Empresa.Empresa) Asunto = Asunto.Replace("{""NombreCliente""}", LtlCliente.Text.Trim) Asunto = Asunto.Replace("{""TipoDocumento""}", TipoComprobante) - Asunto = Asunto.Replace("{""FolioFactura""}", HdnSerieFolio.Value.ToString()) + Asunto = Asunto.Replace("{""SerieFolio""}", HdnSerieFolio.Value.ToString()) If Dr IsNot Nothing Then Asunto = Asunto.Replace("{""FechaFactura""}", Dr("Fecha").ToString().ToDate().ToShortDateString()) Asunto = Asunto.Replace("{""ImporteFactura""}", Dr("Total").ToString().FormatoNumero()) @@ -2696,7 +2692,7 @@ Partial Class Clientes If Not ObjClientes.AddSucursal(CveClienteNuevo, Row("SucursalCliente").ToString(), UsuarioActual.CveUsuario, Row("CiudadSucursal").ToString(), Row("ColoniaSucursal").ToString(), Row("CPSucursal").ToString(), Row("DireccionSucursal").ToString(), Row("EstadoSucursal").ToString(), Row("LocalidadSucursal").ToString(), Row("PaisSucursal").ToString(), Row("NumExtSucursal").ToString(), Row("NumIntSucursal").ToString(), Row("TelefonoSucursal").ToString(), Row("CorreoSucursal").ToString(), Row("CorreoCotiziacionSucursal").ToString(), Row("ContactoSucursal").ToString(), Row("CveVendedorSucursal").ToString().ToEntero(), Row("NumCuenta").ToString(), Row("CveMetodoPago").ToString().ToEntero(), Row("LimiteCredito").ToString().ToDecimal(), Row("CveResponsableCobranza").ToString().ToEntero(), - Row("CveUsoCFDI").ToString().ToEntero(), Row("CveFormaPago33").ToString().ToEntero(), Row("CveMetodoPago33").ToString().ToEntero(), LT:=Row("LT").ToString(), LG:=Row("LG").ToString(), CveAlmacenAsignado:=CveAlmacenAsignadoSucursal) Then + Row("CveUsoCFDI").ToString().ToEntero(), Row("CveFormaPago33").ToString().ToEntero(), Row("CveMetodoPago").ToString().ToEntero(), LT:=Row("LT").ToString(), LG:=Row("LG").ToString(), CveAlmacenAsignado:=CveAlmacenAsignadoSucursal) Then ErrorProceso = True Exit For End If @@ -3348,7 +3344,7 @@ Partial Class Clientes DdlResponsableSucursal.SelectedValueExist(ObjCliente.DtResultados.Rows(0)("CveResponsableCobranza").ToString()) DdlSucursalUsoCFDI.SelectedValueExist(ObjCliente.DtResultados.Rows(0)("CveUsoCFDI").ToString()) - DdlSucursalMetodoPago33.SelectedValueExist(ObjCliente.DtResultados.Rows(0)("CveMetodoPago33").ToString()) + DdlSucursalMetodoPago33.SelectedValueExist(ObjCliente.DtResultados.Rows(0)("CveMetodoPago").ToString()) DdlSucursalFormaPago33.SelectedValueExist(ObjCliente.DtResultados.Rows(0)("CveFormaPago33").ToString()) txtLg.Text = ObjCliente.DtResultados.Rows(0)("LG").ToString() @@ -5647,7 +5643,7 @@ Partial Class Clientes TempDTSucursales.Columns.Add("CveAlmacenAsignado", Type.GetType("System.Int32")) TempDTSucursales.Columns.Add("CveUsoCFDI", Type.GetType("System.Int32")) TempDTSucursales.Columns.Add("CveFormaPago33", Type.GetType("System.Int32")) - TempDTSucursales.Columns.Add("CveMetodoPago33", Type.GetType("System.Int32")) + TempDTSucursales.Columns.Add("CveMetodoPago", Type.GetType("System.Int32")) TempDTSucursales.Columns.Add("Correo", Type.GetType("System.String")) TempDTSucursales.Columns.Add("CorreoCotizacion", Type.GetType("System.String")) TempDTSucursales.Columns.Add("LimiteCredito", Type.GetType("System.Decimal")) @@ -5688,7 +5684,7 @@ Partial Class Clientes RowSucursal("CveUsoCFDI") = DdlSucursalUsoCFDI.SelectedValue.ToEntero() RowSucursal("CveFormaPago33") = DdlSucursalFormaPago33.SelectedValue.ToEntero() - RowSucursal("CveMetodoPago33") = DdlSucursalMetodoPago33.SelectedValue.ToEntero() + RowSucursal("CveMetodoPago") = DdlSucursalMetodoPago33.SelectedValue.ToEntero() RowSucursal("LimiteCredito") = TxtLimiteCreditoSucursal.Text.ToDecimal RowSucursal("CveResponsableCobranza") = DdlResponsableSucursal.SelectedValue.ToEntero @@ -5742,7 +5738,7 @@ Partial Class Clientes Cuerpo = Cuerpo.Replace("{""NombreEmpresa""}", UsuarioActual.Empresa.Empresa) Cuerpo = Cuerpo.Replace("{""NombreCliente""}", LtlCliente.Text.Trim) Cuerpo = Cuerpo.Replace("{""TipoDocumento""}", TipoComprobante) - Cuerpo = Cuerpo.Replace("{""FolioFactura""}", HdnSerieFolio2.Value.ToString()) + Cuerpo = Cuerpo.Replace("{""SerieFolio""}", HdnSerieFolio2.Value.ToString()) If Dr IsNot Nothing Then Cuerpo = Cuerpo.Replace("{""FechaFactura""}", Dr("Fecha").ToString().ToDate().ToShortDateString()) Cuerpo = Cuerpo.Replace("{""ImporteFactura""}", Dr("Total").ToString().FormatoNumero()) @@ -5760,7 +5756,7 @@ Partial Class Clientes Asunto = Asunto.Replace("{""NombreEmpresa""}", UsuarioActual.Empresa.Empresa) Asunto = Asunto.Replace("{""NombreCliente""}", LtlCliente.Text.Trim) Asunto = Asunto.Replace("{""TipoDocumento""}", TipoComprobante) - Asunto = Asunto.Replace("{""FolioFactura""}", HdnSerieFolio2.Value.ToString()) + Cuerpo = Cuerpo.Replace("{""SerieFolio""}", HdnSerieFolio2.Value.ToString()) If Dr IsNot Nothing Then Asunto = Asunto.Replace("{""FechaFactura""}", Dr("Fecha").ToString().ToDate().ToShortDateString()) Asunto = Asunto.Replace("{""ImporteFactura""}", Dr("Total").ToString().FormatoNumero()) @@ -5780,7 +5776,7 @@ Partial Class Clientes Cuerpo = Cuerpo.Replace("{""NombreEmpresa""}", UsuarioActual.Empresa.Empresa) Cuerpo = Cuerpo.Replace("{""NombreCliente""}", LtlCliente.Text.Trim) Cuerpo = Cuerpo.Replace("{""TipoDocumento""}", TipoComprobante) - Cuerpo = Cuerpo.Replace("{""FolioFactura""}", HdnSerieFolio2.Value.ToString()) + Cuerpo = Cuerpo.Replace("{""SerieFolio""}", HdnSerieFolio2.Value.ToString()) If Dr IsNot Nothing Then Cuerpo = Cuerpo.Replace("{""FechaFactura""}", Dr("Fecha").ToString().ToDate().ToShortDateString()) Cuerpo = Cuerpo.Replace("{""ImporteFactura""}", Dr("Total").ToString().FormatoNumero()) @@ -5793,13 +5789,12 @@ Partial Class Clientes End If End If - If UsuarioActual.Empresa.AsuntoPlantillaMailVenta.Trim.Length > 0 Then Asunto = UsuarioActual.Empresa.AsuntoPlantillaMailVenta Asunto = Asunto.Replace("{""NombreEmpresa""}", UsuarioActual.Empresa.Empresa) Asunto = Asunto.Replace("{""NombreCliente""}", LtlCliente.Text.Trim) Asunto = Asunto.Replace("{""TipoDocumento""}", TipoComprobante) - Asunto = Asunto.Replace("{""FolioFactura""}", HdnSerieFolio2.Value.ToString()) + Asunto = Asunto.Replace("{""SerieFolio""}", HdnSerieFolio2.Value.ToString()) If Dr IsNot Nothing Then Asunto = Asunto.Replace("{""FechaFactura""}", Dr("Fecha").ToString().ToDate().ToShortDateString()) Asunto = Asunto.Replace("{""ImporteFactura""}", Dr("Total").ToString().FormatoNumero()) @@ -8087,7 +8082,7 @@ Partial Class Clientes #Region " DEVOLVER DINERO ANT/NC " Private Sub InicializaDevolverDinero() If UsuarioActual.TienePermisoProceso(247) Then - GVAnticipos.Columns(6).Visible = True + GVAnticipos.Columns(7).Visible = True End If End Sub #End Region @@ -10778,6 +10773,7 @@ Partial Class Clientes TxtDevRedondeo.Text = "" DdlCuentaDeposito.DataSource = GlobalDTCuentasDepositosClientes(UsuarioActual.CveEmpresa, CveCliente:=CveCliente) DdlCuentaDeposito.DataBind() + GVAnticipos.Columns(7).Visible = True 'Dim Dep As New ClsGenerales 'If Dep.GetCuentasDepositos(CveCliente:=CveCliente, CveEmpresa:=UsuarioActual.CveEmpresa) Then ' DdlCuentaDeposito.DataSource = Dep.DtResultados diff --git a/Ventas/ClientesAbonar.aspx b/Ventas/ClientesAbonar.aspx index 349c86a99..bae240e5f 100644 --- a/Ventas/ClientesAbonar.aspx +++ b/Ventas/ClientesAbonar.aspx @@ -205,10 +205,14 @@
    Anticipo:
    -
    +
    -
    +
    Sucursal:
    +
    + + +
    @@ -831,7 +835,7 @@ var chkPesosBancos = $get("ChkPagarPesos"); var chkDolaresBancos = $get("ChkPagarDolares"); - + debugger; if (t.checked) { txt.value = FormatoNumero(importe, 2); @@ -853,8 +857,15 @@ } } - function SumaValores(pagoMultiple, monedaPago) { + function FnRecalcula(pagoMultiple,monedaPago) + { + var Suma = SumaValores(pagoMultiple, monedaPago); + $get('TxtImporte').value = FormatoNumero(Suma, 2); + $('#LtlTotalMXN').text(FormatoNumero(Suma, 2)) + } + function SumaValores(pagoMultiple, monedaPago) { + var Importe = 0; var Comision = 0.00; var topLevelElem = document.getElementById("form1"); @@ -945,7 +956,7 @@ $get('TxtAnticipo').value = 0.00 } else { - Importe = Importe + ToDouble($get('TxtAnticipo').value); + Importe = Importe + ToDouble($get('TxtAnticipo').value); } } if ($get('TxtPrestamoImporte') != null) { diff --git a/Ventas/ClientesAbonar.aspx.vb b/Ventas/ClientesAbonar.aspx.vb index 6a927a74e..47fed9063 100644 --- a/Ventas/ClientesAbonar.aspx.vb +++ b/Ventas/ClientesAbonar.aspx.vb @@ -4,6 +4,7 @@ Imports System.Data Imports ADSTimbrado Imports Extensiones +Imports Org.BouncyCastle.Ocsp Partial Class Ventas_ClientesAbonar Inherits ClsPaginas @@ -343,6 +344,13 @@ Partial Class Ventas_ClientesAbonar DtPrestamos = CargaPrestamos(1) End If + If UsuarioActual.Empresa.Funcionalidad(382) = "1" Then 'GDIaz + divAnticipo.Visible = True + TxtAnticipo.Attributes.Add("onKeyUp", "FnRecalcula(0,1);") + DivAntSubProyecto.Visible = True + DivAntSubProyectoTexto.visible = True + CargarCentrosDeCosto(Nothing, DdlSubProyectos, Nothing, Nothing, AplicaTodos:="") + End If CargaDatos(tCveMoneda) Else Alert("El Cliente Solicitado no existe, por favor revise su búsqueda.", TipoMensaje.MsgAdvertencia) @@ -758,7 +766,8 @@ Partial Class Ventas_ClientesAbonar Dim MsgError As String = "" Dim NCGeneradas As New List(Of RespuestaNotaCredrito) Dim ListaFacturasGenerarNC As New List(Of Modelos.Factura) - + Dim ObjFacturaAnt As Modelos.Factura = Nothing + Dim RespAnt As Modelos.Factura.MMensajeFactura = Nothing Dim ImporteSeleccionado As Decimal = 0 '02-05-2018 MANDAMOS CANCELAR EL COMPLEMENTO A SUSTITUIR @@ -1176,12 +1185,79 @@ Partial Class Ventas_ClientesAbonar End If End If + If UsuarioActual.Empresa.Funcionalidad(382) = "1" AndAlso TxtAnticipo.Text.ToDecimal > 0 AndAlso MsgError = "" Then '' si es empresa GDiaz + 'generar un anticipo y registrarle el pago. + + Dim tCveMoneda As Integer = 1 + Dim tCveFormaPago As Integer = GlobalDTTipoTransacciones().FiltroPrimeroValor("CveFormaPago", $"CveTipoTransaccion={DdlTipoTransaccion.SelectedValue}").ToEntero + Dim tCvePS As Integer + Dim tCveUM As Integer = 0 + Dim tCveSub As Integer = DdlSubProyectos.SelectedValue.ToEntero + ObjFacturaAnt = Modelos.Factura.CrearVentaNueva(UsuarioActual, tCveSub, CveCliente, tCveMoneda, "Ant") + ObjFacturaAnt.CveMoneda = tCveMoneda + ObjFacturaAnt.CveFormaPago = tCveFormaPago + ObjFacturaAnt.CveMetodoPago = 1 + ObjFacturaAnt.ClaveMetodoPagoSAT = "PUE" + ObjFacturaAnt.ClaveFormaPagoSAT = GlobalDTVtaFormaPago.FiltroPrimeroValor("ClaveFormaPagoSAT", $"CveFormaPago = {ObjFacturaAnt.CveFormaPago}") + ObjFacturaAnt.ClaveUsoCFDISAT = GlobalDTSATUsosCFDI.FiltroPrimeroValor("UsoCFDI", $"CveUsoCFDI = {ObjFacturaAnt.CveUsoCFDI}") + + Dim drPS As DataRow = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CodigoSATPS:="84111506").FiltroPrimero("PSCodigo LIKE '%ANTICIPO%' OR PSCodigo LIKE '%anticipo%' OR PSCodigo LIKE '%Anticipo%'") + Dim tPorIVA As Decimal = GlobalDTSubProyectos(UsuarioActual.CveEmpresa, CveSubProyecto:=tCveSub).FiltroPrimeroValor("IVA").ToDecimal + Dim tPU As Decimal = (TxtAnticipo.Text.ToDecimal / (1 + tPorIVA)).RoundSQL(6) + If drPS IsNot Nothing Then + tCvePS = drPS("CvePS").ToString.ToEntero + tCveUM = drPS("CveUnidadMedida").ToString.ToEntero + End If + ObjFacturaAnt.AgregarPS(tCvePS, 1, tPU, 0, "", CveUM:=tCveUM, CveSubProyecto:=tCveSub, PorcentajeIVA:=tPorIVA) + ObjFacturaAnt.CalculaTotales() + RespAnt = ObjFacturaAnt.EmitirFactura(False, Transac:=ObjMov.IniciaTransacSQL(), Modulo:="Ventas/ClientesAbonarAnt", MostrarURL:=True) + RespAnt.Factura = ObjFacturaAnt + + If RespAnt IsNot Nothing AndAlso RespAnt.Factura IsNot Nothing Then + + Dim VentaActual As New Venta(UsuarioActual) + VentaActual.CveVenta = RespAnt.Factura.CveVenta + VentaActual.Fecha = RespAnt.Factura.Fecha + VentaActual.CveCliente = CveCliente + VentaActual.CveMoneda = tCveMoneda + VentaActual.TipoDocto = "Ant" + VentaActual.SerieFolio = RespAnt.Factura.SerieFolio + VentaActual.ClienteNombre = NombreComercial + VentaActual.TC = 1 + VentaActual.Total = TxtAnticipo.Text.ToDecimal + VentaActual.IVA = (tPorIVA * tPU).RoundSQL(2) + + VentaActual.PorcentajeIVA = tPorIVA + VentaActual.CveSubProyecto = tCveSub + 'Importe de pago + Dim Pago As New VentaPago + Pago.TipoPago = "XXX" + Pago.Fecha = TxtFechaDocumento.Text.ToDate + Pago.CveIE = CveIE + Pago.CveMonedaPago = tCveMoneda + Pago.ImportePago = TxtAnticipo.Text.ToDecimal + Pago.ImportePagoVenta = TxtAnticipo.Text.ToDecimal + Pago.Referencia = TxtFolio.Text + Pago.TipoPago = "XXX" + 'If RblTipoPago.SelectedValue = "3" Then + ' Pago.TipoPago = "I" + ' Pago.FechaDocumentoRelacionado = FechaIngreso + ' Pago.CveClientePago = CveCliente + 'End If + 'MsgError = RespAnt.Mensajes.ToString + If MsgError = "" AndAlso AplicaPrePolizaPagoVenta(VentaActual, Pago, CvePrePoliza, ObjMov) Then + MsgError = "No se pudo insertar la póliza" + End If + End If + End If + If MsgError = "" AndAlso Not ObjMov.ValidacionesPrePoliza(CvePrePoliza, UsuarioActual, Opcion:=3) Then MsgError = ObjMov.MensajePolizaDescuadre & " La diferencia es de: " & ObjMov.ValorDiferencia 'If ObjMov.ValorPolizaDescuadre > 0 Then ' MsgError = ObjMov.MensajePolizaDescuadre & " La diferencia es de: " & ObjMov.ValorDiferencia 'End If End If + Else MsgError = "No se pudo insertar la póliza" End If @@ -1326,6 +1402,25 @@ Partial Class Ventas_ClientesAbonar End If Next + If ObjFacturaAnt IsNot Nothing Then + Dim MsgTimbrado As String = "" + Try + ObjFacturaAnt.PreparaTimbre() + MsgTimbrado = TimbrarFactura(ObjFacturaAnt, True) + StrMsg.AppendFormat("

    Anticipo generado correctamente.
    Folio: {1}
    ", ObjFacturaAnt.CveVenta, ObjFacturaAnt.SerieFolio) + + If Not String.IsNullOrEmpty(MsgTimbrado) Then + Dim StrEr As String = $"
    Comprobante no emitido :
    {MsgTimbrado}
    Por favor inténtelo de nuevo a través del botón 'Emitir' en ventas.
    " + StrMsg.AppendFormat("
    {0}
    ", StrEr) + End If + + Catch ex As Exception + GuardaLogAD(ex.ToString()) + StrMsg.AppendFormat("
    {0}
    ", MsgTimbrado) + End Try + + End If + If ChkComplementoPago.Checked Then Dim TextoComplementoPago As String = EmitirComplementoPago(CveIE, CveVentasPago, SeriesPago) StrMsg.AppendFormat("

    {0}", TextoComplementoPago) @@ -1352,6 +1447,26 @@ Partial Class Ventas_ClientesAbonar End Sub + Private Function TimbrarFactura(ByRef ObjFactura As Modelos.Factura, ByRef SeTimbro As Boolean) As String + Dim MsgErrorTimbrado As String = "" + + Dim ObjTimbrado As New Timbrado + Try + SeTimbro = ObjTimbrado.TimbrarFactura(UsuarioActual, ObjFactura) + Dim FolioFiscalFactura As String = ObjTimbrado.UUID + MsgErrorTimbrado = ObjTimbrado.MensajeErrorCFDI + ObjTimbrado = Nothing + + Catch ex As Exception + OnError("Ocurrió un error al generar el timbrado", ex) + End Try + + If Not String.IsNullOrEmpty(MsgErrorTimbrado) Then + GuardaLogAD(MsgErrorTimbrado, Archivo:="LogTimbrado") + End If + + Return MsgErrorTimbrado + End Function Private Function RegistraAmortizacionAnticipo(ByRef ObjMov As ClsContabilidad, CvePrePoliza As Integer, CveIE As Integer, Importe As Decimal, tipoCambioPago As Decimal, CveVenta As Integer, ReferenciaVenta As String, ReferenciaPago As String) As String Dim MsgError As String = "" If CveMonedaPago = 2 Then diff --git a/Ventas/PV.aspx.vb b/Ventas/PV.aspx.vb index c2834f001..0b8f90818 100644 --- a/Ventas/PV.aspx.vb +++ b/Ventas/PV.aspx.vb @@ -2681,11 +2681,11 @@ Partial Class PV CveMetodoPagoCliente = ObjCliente.DtResultados.Rows(0)("CveMetodoPago").ToString.ToEntero DdlUsoCFDI.SelectedValueExist(ObjCliente.CveUsoCFDI.ToString) 'DdlMetodoPago.SelectedValueExist(ObjCliente.CveMetodoPago.ToString) - DdlMetodoPago33.SelectedValueExist(ObjCliente.CveMetodoPago33.ToString) + DdlMetodoPago33.SelectedValueExist(ObjCliente.CveMetodoPago.ToString) 'DdlMetodoPago33.SelectedValueExist(ObjCliente.DtResultados.Rows(0)("CveMetodoPago33").ToString) DdlMetodoPago33_SelectedIndexChanged(DdlMetodoPago33, EventArgs.Empty) - DdlFormaPago33.SelectedValueExist(ObjCliente.CveFormaPago33.ToString) + DdlFormaPago33.SelectedValueExist(ObjCliente.CveFormaPago.ToString) 'DdlFormaPago33.SelectedValueExist(ObjCliente.DtResultados.Rows(0)("CveFormaPago33").ToString) DdlUsoCFDI.SelectedValueExist(ObjCliente.DtResultados.Rows(0)("CveUsoCFDI").ToString) 'SI ES RFC GENERICO NO TIENE OBLIGACIONES FISCALES @@ -2906,8 +2906,8 @@ Partial Class PV 'CveMetodoPagoCliente = ObjCliente.CveMetodoPago DdlMetodoPago.SelectedValueExist(CveMetodoPagoCliente.ToString) - DdlFormaPago33.SelectedValueExist(ObjCliente.CveFormaPago33) - DdlMetodoPago33.SelectedValueExist(ObjCliente.CveMetodoPago33) + DdlFormaPago33.SelectedValueExist(ObjCliente.CveFormaPago) + DdlMetodoPago33.SelectedValueExist(ObjCliente.CveMetodoPago) DdlUsoCFDI.SelectedValueExist(ObjCliente.CveUsoCFDI) 'SI ES RFC GENERICO NO TIENE OBLIGACIONES FISCALES If LblRFC.Text.Contiene("XAXX010101000", "XEXX010101000") Then diff --git a/Ventas/PVCobranza.aspx.vb b/Ventas/PVCobranza.aspx.vb index f224d9383..1fb39977d 100644 --- a/Ventas/PVCobranza.aspx.vb +++ b/Ventas/PVCobranza.aspx.vb @@ -1139,7 +1139,7 @@ Partial Class Ventas_PVCobranza For Each Dr As DataRow In ObjFactura.DtRemisionesPS.Rows ObjFactura.AgregarPS(Dr("CvePS").ToString().ToEntero(), Dr("Cantidad").ToString().ToDecimal(), Dr("PU").ToString().ToDecimal(), Dr("Descuento").ToString().ToDecimal, Dr("Obs").ToString(), CveUM:=Dr("CveUM").ToString().ToEntero(), CveProyecto:=Dr("CveProyecto").ToString().ToEntero(), CveSubProyecto:=Dr("CveSubProyecto").ToString().ToEntero(), CveVentaDetallePadre:=Dr("CveVentaDetalle").ToString().ToEntero(), CveVentaDetalleRemision:=Dr("CveVentaDetalle").ToString().ToEntero(), - PorcentajeIVA:=Dr("PorcentajeIVA").ToString().ToDecimal()) + PorcentajeIVA:=Dr("PorcentajeIVA").ToString().ToDecimal(), CvePromocionDetalle:=Dr("CvePromocionDetalle").ToString.ToEntero) Next If Not ValidateString(ObservacionesAlmacen.ToLower(), "parcial") Then @@ -1148,14 +1148,12 @@ Partial Class Ventas_PVCobranza ObjFactura.CveAlmacen = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveAlmacen", $"CveTipoAlmacen = 1 AND CveSubProyecto = {VentaRemision.CveSubProyecto}", "Orden").ToString().ToEntero() End If - ObjFactura.CalculaTotales() ObjFactura.PreparaTimbre() If HdnTipoAmortizacion.Value = "4" Then - DtAnticipos.Columns.Add("CveVenta", GetType(Integer)) DtAnticipos.Columns.Add("Importe", GetType(Decimal)) DtAnticipos.Columns.Add("CveConceptoContable", GetType(Integer)) diff --git a/asmx/WSApp.asmx b/asmx/WSApp.asmx index 46e2559b7..8fd815f70 100644 --- a/asmx/WSApp.asmx +++ b/asmx/WSApp.asmx @@ -644,21 +644,21 @@ Public Class WSApp Dim ObjCliente As New ClsClientes If ObjCliente.GetClientes(CveCliente, "-1", "-1", "-1", "-1", "-1", "-1", -1, CveEmpresa, -1, TipoCliente:=-1) Then If ObjCliente.DtResultados.Rows.Count > 0 Then - ObjFactura.CveFormaPago = ObjCliente.CveFormaPago33 - ObjFactura.FormaPago = ClsPaginas.GlobalDTVtaFormaPago.FiltroPrimeroValor("FormaPago", $"CveFormaPago = {ObjCliente.CveFormaPago33}") - ObjFactura.ClaveFormaPagoSAT = ClsPaginas.GlobalDTVtaFormaPago.FiltroPrimeroValor("ClaveFormaPagoSAT", $"CveFormaPago = {ObjCliente.CveFormaPago33}") + ObjFactura.CveFormaPago = ObjCliente.CveFormaPago + ObjFactura.FormaPago = ClsPaginas.GlobalDTVtaFormaPago.FiltroPrimeroValor("FormaPago", $"CveFormaPago = {ObjCliente.CveFormaPago}") + ObjFactura.ClaveFormaPagoSAT = ClsPaginas.GlobalDTVtaFormaPago.FiltroPrimeroValor("ClaveFormaPagoSAT", $"CveFormaPago = {ObjCliente.CveFormaPago}") - ObjFactura.CveMetodoPago = ObjCliente.CveMetodoPago33 - ObjFactura.MetodoPago = ClsPaginas.GlobalDTVtaMetodoPago.FiltroPrimeroValor("MetodoPago", $"CveMetodoPago = {ObjCliente.CveMetodoPago33}") - ObjFactura.ClaveMetodoPagoSAT = ClsPaginas.GlobalDTVtaMetodoPago.FiltroPrimeroValor("ClaveMetodoPagoSAT", $"CveMetodoPago = {ObjCliente.CveMetodoPago33}") + ObjFactura.CveMetodoPago = ObjCliente.CveMetodoPago + ObjFactura.MetodoPago = ClsPaginas.GlobalDTVtaMetodoPago.FiltroPrimeroValor("MetodoPago", $"CveMetodoPago = {ObjCliente.CveMetodoPago}") + ObjFactura.ClaveMetodoPagoSAT = ClsPaginas.GlobalDTVtaMetodoPago.FiltroPrimeroValor("ClaveMetodoPagoSAT", $"CveMetodoPago = {ObjCliente.CveMetodoPago}") ObjFactura.CveUsoCFDI = ObjCliente.CveUsoCFDI ObjFactura.UsoCFDI = ClsPaginas.GlobalDTSATUsosCFDI.FiltroPrimeroValor("Descripcion", $"CveUsoCFDI = {ObjCliente.CveUsoCFDI}") ObjFactura.ClaveUsoCFDISAT = ClsPaginas.GlobalDTSATUsosCFDI.FiltroPrimeroValor("UsoCFDI", $"CveUsoCFDI = {ObjCliente.CveUsoCFDI}") - ObjFactura.CveMetodoPago = ObjCliente.CveMetodoPago33 - If ClsPaginas.GlobalDTVtaMetodoPago.FiltraParametros($"CveMetodoPago = {ObjCliente.CveMetodoPago33}").Rows.Count > 0 Then - ObjFactura.MetodoPago = ClsPaginas.GlobalDTVtaMetodoPago.FiltraParametros($"CveMetodoPago = {ObjCliente.CveMetodoPago33}").Rows(0)("MetodoPago").ToString + ObjFactura.CveMetodoPago = ObjCliente.CveMetodoPago + If ClsPaginas.GlobalDTVtaMetodoPago.FiltraParametros($"CveMetodoPago = {ObjCliente.CveMetodoPago}").Rows.Count > 0 Then + ObjFactura.MetodoPago = ClsPaginas.GlobalDTVtaMetodoPago.FiltraParametros($"CveMetodoPago = {ObjCliente.CveMetodoPago}").Rows(0)("MetodoPago").ToString Else ObjFactura.CveMetodoPago = 1 ObjFactura.MetodoPago = "Efectivo" diff --git a/asmx/WSSIGApp.asmx b/asmx/WSSIGApp.asmx index 05547cdfb..c357054be 100644 --- a/asmx/WSSIGApp.asmx +++ b/asmx/WSSIGApp.asmx @@ -1942,13 +1942,13 @@ Public Class WSSIGApp Dim ObjCliente As New ClsClientes If ObjCliente.GetClientes(CveCliente, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa, -1, TipoCliente:=-1) Then If ObjCliente.DtResultados.Rows.Count > 0 Then - ObjFactura.CveFormaPago = ObjCliente.CveFormaPago33 - ObjFactura.FormaPago = GlobalDTVtaFormaPago.FiltroPrimeroValor("FormaPago", $"CveFormaPago = {ObjCliente.CveFormaPago33}") - ObjFactura.ClaveFormaPagoSAT = GlobalDTVtaFormaPago.FiltroPrimeroValor("ClaveFormaPagoSAT", $"CveFormaPago = {ObjCliente.CveFormaPago33}") + ObjFactura.CveFormaPago = ObjCliente.CveFormaPago + ObjFactura.FormaPago = GlobalDTVtaFormaPago.FiltroPrimeroValor("FormaPago", $"CveFormaPago = {ObjCliente.CveFormaPago}") + ObjFactura.ClaveFormaPagoSAT = GlobalDTVtaFormaPago.FiltroPrimeroValor("ClaveFormaPagoSAT", $"CveFormaPago = {ObjCliente.CveFormaPago}") - ObjFactura.CveMetodoPago = ObjCliente.CveMetodoPago33 - ObjFactura.MetodoPago = GlobalDTVtaMetodoPago.FiltroPrimeroValor("MetodoPago", $"CveMetodoPago = {ObjCliente.CveMetodoPago33}") - ObjFactura.ClaveMetodoPagoSAT = GlobalDTVtaMetodoPago.FiltroPrimeroValor("ClaveMetodoPagoSAT", $"CveMetodoPago = {ObjCliente.CveMetodoPago33}") + ObjFactura.CveMetodoPago = ObjCliente.CveMetodoPago + ObjFactura.MetodoPago = GlobalDTVtaMetodoPago.FiltroPrimeroValor("MetodoPago", $"CveMetodoPago = {ObjCliente.CveMetodoPago}") + ObjFactura.ClaveMetodoPagoSAT = GlobalDTVtaMetodoPago.FiltroPrimeroValor("ClaveMetodoPagoSAT", $"CveMetodoPago = {ObjCliente.CveMetodoPago}") ObjFactura.CveUsoCFDI = ObjCliente.CveUsoCFDI ObjFactura.UsoCFDI = GlobalDTSATUsosCFDI.FiltroPrimeroValor("Descripcion", $"CveUsoCFDI = {ObjCliente.CveUsoCFDI}")