Namespace Modelo190
    Public Class DatosModelo190
        Public Property Declarante As RegistroDeclarante
        Public Property Perceptores As List(Of RegistroPerceptor)
    End Class

    Public Class RegistroDeclarante
        Public Property TipoRegistro As String = "1" ' 1
        Public Property ModeloDeclaracion As String = "190" ' 2-4
        Public Property Ejercicio As String = "" ' 5-8
        Public Property NifDeclarante As String = "" ' 9-17
        Public Property ApeNombreRsoDeclarante As String = "" '18-57
        Public Property TipodeSoporte As String = "T" '58
        Public Property PerConQuienRelacionarseTlf As String = "" ' 59-67
        Public Property PerConQuienRelacionarseNom As String = "" ' 68-107
        Public Property NumIdenDecla As String = "" ' 108-120
        Public Property DeclComploSust As String = "" ' 121-122
        Public Property NumIdenDeclaAnt As String = "" ' 123-135
        Public Property NumTotaldePercepciones As String = "" ' 136-144
        Public Property ImpTotPercepcionesSigno As String = "" ' 145
        'Public Property ImpTotPercepciones As String = "" ' 146-160 146-158 parte entera 159-160 parte decimal
        Public Property ImpTotPercepcionesParEnt As String = "" '146-158
        Public Property ImpTotPercepcionesParDec As String = "" '159-160
        Public Property ImpTotRetencionesParEnt As String = "" '161-173
        Public Property ImpTotRetencionesParDec As String = "" '174-175
        'Public Property ImpTotRetenciones As String = "" ' 161-175 161-173 parte entera 174-175 parte decimal
        Public Property CorreoElectronicoPerConQuienRelacionarse As String = "" ' 176-225
        Public Property Blancos As String = " ".PadRight(262, " ") '226-487
        Public Property SelloElectronico As String = " ".PadRight(13, " ") '488-500



    End Class
    Public Class RegistroPerceptor
        Public Property TipoRegistro As String
        Public Property ModeloDeclaracion As String = "190"
        Public Property Ejercicio As String = "" ' 5-8
        Public Property NifDeclarante As String = "" ' 9-17
        Public Property NifPerceptor As String = "" ' 18-26
        Public Property NifRepresentateLegal As String = "" ' 27-35
        Public Property ApeNombreRsoPerceptor As String = "" '36-75
        Public Property CodigoProvincial As String = "41" '76-77
        Public Property ClavePercepcion As String = "" '78
        Public Property SubClave As String = "" '79-80
        Public Property PerDineNoIncaLabSigno As String = "" '81
        Public Property PerDineNoIncaLabPerint As Double = 0
        Public Property PerDineNoIncaLabPerintParEnt As String = "" '82-92
        Public Property PerDineNoIncaLabPerintParDec As String = "" '93-94
        Public Property PerDineNoIncaLabRetPra As Double = 0
        Public Property PerDineNoIncaLabRetPraParEnt As String = "" '95-105
        Public Property PerDineNoIncaLabRetPraParDec As String = "" '106-107
        Public Property PerEspNoIncaLabSigno As String = "" '108
        Public Property PerEspNoIncaLabPerint As Double = 0
        Public Property PerEspNoIncaLabPerintParEnt As String = "" '109-119
        Public Property PerEspNoIncaLabPerintParDec As String = "" '120-121
        Public Property PerEspNoIncaLabRetPra As Double = 0 '122-132
        Public Property PerEspNoIncaLabRetPraParEnt As String = "" '122-132
        Public Property PerEspNoIncaLabRetPraParDec As String = "" '133-134
        Public Property PerEspNoIncaLabRetRep As Double = 0
        Public Property PerEspNoIncaLabRetRepParEnt As String = "" '135-145
        Public Property PerEspNoIncaLabRetRepParDec As String = "" '146-147
        Public Property EjercicioDevengo As String = "0000" '148-151
        Public Property CeutaOMelilla As String = "" '152
        Public Property AñoNacimiento As String = "" '153-156
        Public Property SituacionFamilia As String = "" '157
        Public Property NifConyuge As String = "" '158-166
        Public Property Discapacidad As String = "" '167
        Public Property ContratoRelacion As String = "" '168
        Public Property Guion As String = "" '169
        Public Property MovilidadGeografica As String = "" '170
        Public Property ReduccionesAplicable As String = "" '171-181 parte entera 182-183 parte decimal
        Public Property GastosDeducibles As Double = 0
        Public Property GastosDeduciblesEnt As String = "" '184-194 parte entera
        Public Property GastosDeduciblesDec As String = "" ' 195-196 parte decimal
        Public Property PensionCompensatoria As Double = 0
        Public Property PensionCompensatoriaEnt As String = "" '197-207 parte entera
        Public Property PensionCompensatoriaDec As String = "" '208-209 parte decimal
        Public Property AnualidadporAlimentos As Double = 0
        Public Property AnualidadporAlimentosEnt As String = "" '210-220 parte entera 
        Public Property AnualidadporAlimentosDec As String = "" '221-222 parte decimal
        Public Property HijosyOtrosDecendientes As String = "" '223-228
        Public Property HijosyOtrosDecendientesConDiscapacidad As String = "" '229-240
        Public Property Ascendientes As String = "" '241-244
        Public Property AscendientesConDiscapacidad As String = "" '245-250
        Public Property Com3PrimerosHijos As String = "" '251-253
        Public Property ComuPresVivHab As String = "" '254
        Public Property PerDineDerIncaLabSigno As String = "" '255
        Public Property PerDineIncaLabPerint As Double = 0
        Public Property PerDineIncaLabPerintParEnt As String = "" '256-266
        Public Property PerDineIncaLabPerintParDec As String = "" '267-268
        Public Property PerDineIncaLabRetPra As Double = 0
        Public Property PerDineIncaLabRetPraParEnt As String = "" '269-279
        Public Property PerDineIncaLabRetPraParDec As String = "" '280-281
        Public Property PerEspDerIncaLabSigno As String = "" '282
        Public Property PerEspIncaLabPerint As Double = 0
        Public Property PerEspIncaLabPerintParEnt As String = "" '283-293
        Public Property PerEspIncaLabPerintParDec As String = "" '294-295
        Public Property PerEspIncaLabRetPra As Double = 0
        Public Property PerEspIncaLabRetPraParEnt As String = "" '296-306
        Public Property PerEspIncaLabRetPraParDec As String = "" '307-308
        Public Property PerEspIncaLabRetRep As Double = 0
        Public Property PerEspIncaLabRetRepParEnt As String = "" '309-319
        Public Property PerEspIncaLabRetRepParDec As String = "" '320-321
        Public Property PerTitularConvivencia As String = "0" '322
        Public Property RetEIngrEstEnDipuForPaisVascoYNavarra As String = "0".PadRight(66, "0") ' 323-387
        Public Property TotalPercepcionesIntegras As Double = 0
        Public Property TotalRetencionesIntegras As Double = 0
        Public Property Blancos As String = " ".PadRight(112, " ") '388-500

    End Class
    Public Class Utilidades
        Public Shared Sub GeneraFichero(Datos As DatosModelo190, Fichero As String)
            Try


                '       Dim fs As New IO.FileStream(Fichero, IO.FileMode.CreateNew)
                '        Dim sw As New IO.StreamWriter(fs, System.Text.Encoding.GetEncoding("iso-8859-1"))
                Dim sw As New IO.StreamWriter(Fichero, False, System.Text.Encoding.GetEncoding("iso-8859-1"))
                Dim RegDeclarante As String
                RegDeclarante = Datos.Declarante.TipoRegistro.PadLeft(1, " ")
                RegDeclarante &= Datos.Declarante.ModeloDeclaracion.PadRight(3, " ")
                RegDeclarante &= Datos.Declarante.Ejercicio.PadLeft(4, "0")
                RegDeclarante &= Datos.Declarante.NifDeclarante.PadLeft(9, "0")
                RegDeclarante &= Datos.Declarante.ApeNombreRsoDeclarante.Replace(",", "").PadRight(40, " ")
                RegDeclarante &= Datos.Declarante.TipodeSoporte.PadLeft(1, " ")
                RegDeclarante &= Datos.Declarante.PerConQuienRelacionarseTlf.PadLeft(9, "0")
                RegDeclarante &= Datos.Declarante.PerConQuienRelacionarseNom.PadRight(40, " ")
                RegDeclarante &= Datos.Declarante.NumIdenDecla.PadLeft(13, "0")
                RegDeclarante &= Datos.Declarante.DeclComploSust.PadRight(2, " ")
                RegDeclarante &= Datos.Declarante.NumIdenDeclaAnt.PadLeft(13, "0")
                RegDeclarante &= Datos.Declarante.NumTotaldePercepciones.PadLeft(9, "0")
                RegDeclarante &= Datos.Declarante.ImpTotPercepcionesSigno.PadLeft(1, " ")
                RegDeclarante &= Datos.Declarante.ImpTotPercepcionesParEnt.PadLeft(13, "0")  '146-158
                RegDeclarante &= Datos.Declarante.ImpTotPercepcionesParDec.PadLeft(2, "0") '159-160
                RegDeclarante &= Datos.Declarante.ImpTotRetencionesParEnt.PadLeft(13, "0") '161-173
                RegDeclarante &= Datos.Declarante.ImpTotRetencionesParDec.PadLeft(2, "0") '174-175
                RegDeclarante &= Datos.Declarante.CorreoElectronicoPerConQuienRelacionarse.PadRight(50, " ")
                RegDeclarante &= Datos.Declarante.Blancos.PadRight(262, " ")
                RegDeclarante &= Datos.Declarante.SelloElectronico.PadRight(13, " ")
                sw.WriteLine(RegDeclarante)
                For Each p In Datos.Perceptores
                    If p.NifPerceptor = "27289008Z" Then
                        Dim parate = 12
                    End If
                    Dim RegPerceptor As String
                    RegPerceptor = p.TipoRegistro.PadLeft(1, " ")
                    RegPerceptor &= p.ModeloDeclaracion.PadRight(3, " ")
                    RegPerceptor &= p.Ejercicio.PadLeft(4, "0")
                    RegPerceptor &= p.NifDeclarante.PadLeft(9, "0")
                    RegPerceptor &= p.NifPerceptor.PadLeft(9, "0")
                    RegPerceptor &= p.NifRepresentateLegal.PadLeft(9, " ")
                    RegPerceptor &= p.ApeNombreRsoPerceptor.Replace(",", " ").Replace("Á", "A").Replace("É", "E").Replace("Í", "I").Replace("Ó", "O").Replace("Ú", "U").Replace("Ü", "U").Replace("Ñ", "N").Replace("  ", " ").PadRight(40, " ").Substring(0, 40)
                    RegPerceptor &= p.CodigoProvincial.PadLeft(2, "00")
                    RegPerceptor &= p.ClavePercepcion.PadLeft(1, " ")
                    RegPerceptor &= p.SubClave.PadLeft(2, "00")
                    RegPerceptor &= p.PerDineNoIncaLabSigno.PadLeft(1, " ")
                    RegPerceptor &= p.PerDineNoIncaLabPerintParEnt.PadLeft(11, "0")
                    RegPerceptor &= p.PerDineNoIncaLabPerintParDec.PadLeft(2, "0")
                    RegPerceptor &= p.PerDineNoIncaLabRetPraParEnt.PadLeft(11, "0") '95-105
                    RegPerceptor &= p.PerDineNoIncaLabRetPraParDec.PadLeft(2, "0") '106-107
                    RegPerceptor &= p.PerEspNoIncaLabSigno.PadLeft(1, " ")
                    RegPerceptor &= p.PerEspNoIncaLabPerintParEnt.PadLeft(11, "0") '109-119
                    RegPerceptor &= p.PerEspNoIncaLabPerintParDec.PadLeft(2, "0") '120-121
                    RegPerceptor &= p.PerEspNoIncaLabRetPraParEnt.PadLeft(11, "0") '122-132
                    RegPerceptor &= p.PerEspNoIncaLabRetPraParDec.PadLeft(2, "0") '133-134
                    RegPerceptor &= p.PerEspNoIncaLabRetRepParEnt.PadLeft(11, "0") '135-145
                    RegPerceptor &= p.PerEspNoIncaLabRetRepParDec.PadLeft(2, "0") '146-147
                    RegPerceptor &= p.EjercicioDevengo.PadLeft(4, "0") '148-151
                    RegPerceptor &= p.CeutaOMelilla.PadLeft(1, "0") '152-152
                    RegPerceptor &= p.AñoNacimiento.PadLeft(4, "0") '153-156
                    RegPerceptor &= p.SituacionFamilia.PadLeft(1, "0") '157-157
                    RegPerceptor &= p.NifConyuge.PadLeft(9, " ") '158-166
                    RegPerceptor &= p.Discapacidad.PadLeft(1, "0") '167-167
                    RegPerceptor &= p.ContratoRelacion.PadLeft(1, "0") '168-168
                    RegPerceptor &= p.Guion.PadLeft(1, "0") '169-169
                    RegPerceptor &= p.MovilidadGeografica.PadLeft(1, "0") '170-170
                    RegPerceptor &= p.ReduccionesAplicable.PadLeft(13, "0") '171-183
                    RegPerceptor &= p.GastosDeduciblesEnt.PadLeft(11, "0")  '184-194 parte entera
                    RegPerceptor &= p.GastosDeduciblesDec.PadLeft(2, "0") ' 195-196 parte decimal
                    RegPerceptor &= p.PensionCompensatoriaEnt.PadLeft(11, "0") '197-207 parte entera
                    RegPerceptor &= p.PensionCompensatoriaDec.PadLeft(2, "0") '208-209 parte decimal
                    RegPerceptor &= p.AnualidadporAlimentosEnt.PadLeft(11, "0") '210-220 parte entera 
                    RegPerceptor &= p.AnualidadporAlimentosDec.PadLeft(2, "0") '221-222 parte decimal
                    RegPerceptor &= p.HijosyOtrosDecendientes.PadLeft(6, "0")
                    RegPerceptor &= p.HijosyOtrosDecendientesConDiscapacidad.PadLeft(12, "0")
                    RegPerceptor &= p.Ascendientes.PadLeft(4, "0")
                    RegPerceptor &= p.AscendientesConDiscapacidad.PadLeft(6, "0")
                    RegPerceptor &= p.Com3PrimerosHijos.PadLeft(3, "0")
                    RegPerceptor &= p.ComuPresVivHab.PadLeft(1, "0")
                    RegPerceptor &= p.PerDineDerIncaLabSigno.PadLeft(1, " ")
                    RegPerceptor &= p.PerDineIncaLabPerintParEnt.PadLeft(11, "0")  '256-266
                    RegPerceptor &= p.PerDineIncaLabPerintParDec.PadLeft(2, "0") '267-268
                    RegPerceptor &= p.PerDineIncaLabRetPraParEnt.PadLeft(11, "0") '269-279
                    RegPerceptor &= p.PerDineIncaLabRetPraParDec.PadLeft(2, "0")  '280-281
                    RegPerceptor &= p.PerEspDerIncaLabSigno.PadLeft(1, " ")
                    RegPerceptor &= p.PerEspIncaLabPerintParEnt.PadLeft(11, "0") '283-293
                    RegPerceptor &= p.PerEspIncaLabPerintParDec.PadLeft(2, "0") '294-295
                    RegPerceptor &= p.PerEspIncaLabRetPraParEnt.PadLeft(11, "0") '296-306
                    RegPerceptor &= p.PerEspIncaLabRetPraParDec.PadLeft(2, "0") '307-308
                    RegPerceptor &= p.PerEspIncaLabRetRepParEnt.PadLeft(11, "0") '309-319
                    RegPerceptor &= p.PerEspIncaLabRetRepParDec.PadLeft(2, "0") '320-321
                    RegPerceptor &= p.PerTitularConvivencia.PadLeft(1, "0") '322
                    RegPerceptor &= p.RetEIngrEstEnDipuForPaisVascoYNavarra.PadLeft(66, "0") ' 323-388
                    RegPerceptor &= p.Blancos.PadRight(112, " ") '389-500

                    sw.WriteLine(RegPerceptor)
                Next
                sw.Close()
                'fs.Close()
            Catch ex As Exception
                Throw New Exception(ex.Message, ex)
            End Try
        End Sub
    End Class

End Namespace