Clipper On Line • Ver Tópico - Validar a Inscrição Municipal
Mudar para estilo Clássico
Discussão sobre a biblioteca Fivewin - O Clipper para Windows.
Postar uma resposta

Validar a Inscrição Municipal

20 Out 2015 10:55

Bom dia, alguém tem esta função mais atualizada?

Código:
//---------------------Checar a Inscricao Municipal--------------------------//

Function Mostra_ICCM // Picture Inscricao Municipal, Validacao.

    Parameters cCidade, cInscricaoMunicipal

    Local GetList := {}, Ok := .F., Base, Vpos, Valg, Vsom, Vres, Vdig1,      ;
                                    Vdig2, Vpro, P, D, N, Vbase2, Origem

    Vbase2 := Base := Origem := ""

    If Pcount() == 2 .And. GetActive() == Nil

       For i := 1 To Len( Trim( cInscricaoMunicipal ) )

           If Asc( Subs( cInscricaoMunicipal, i, 1 ) ) < 48 .Or. ;
              Asc( Subs( cInscricaoMunicipal, i, 1 ) ) > 57

              Return( cInscricaoMunicipal )

           EndIf

       Next

       If Len( Alltrim( cInscricaoMunicipal ) ) == 7

          Return( "@R PR 999/9999" )

       EndIf

       Do Case

          Case cCidade == "CAMPO GRANDE" //MT

               Return( "@R 9999999999-9" )

          Case cCidade == "BRASILIA" //DF

               Return( "@R 999.99999.999-99" )

          Case cCidade == "RIO BRANCO" //AC

               Return( "@R 99.99.9999-9" )

          Case cCidade == "MACEIO"      .Or. ;
               cCidade == "MACAPA"      .Or. ;
               cCidade == "GOIANIA"     .Or. ;
               cCidade == "SAO LUIS"    .Or. ;
               cCidade == "CUIABA"      .Or. ;
               cCidade == "TERESINA"    .Or. ;
               cCidade == "JOAO PESSOA" .Or. ;
               cCidade == "MANAUS"      .Or. ;
               cCidade == "PORTO VELHO"

               Return( "@R 99.999.999-9" )

          Case cCidade == "FORTALEZA" .Or. ;
               cCidade == "BOA VISTA" .Or. ;
               cCidade == "ARACAJU"

               Return( "@R 99999999-9" )

          Case cCidade == "BELO HORIZONTE"

               Return( "@R 999.999.999/9999" )

          Case cCidade == "BELEM"

               Return( "@R 99-999999-9" )

          Case cCidade == "RIO DE JANEIRO"

               Return( "@R 99.999.99-9" )

          Case cCidade == "BAHIA"

               Return( "@R 999999-99" )

          Case cCidade == "FLORIANOPOLIS"

               Return( "@R 999.999.999" )

          Case cCidade == "SAO PAULO"

               Return( "@R 999.999.999.999" )

          Case cCidade == "PORTO ALEGRE"

               Return( "@R 999/999999-9" )

          Case cCidade == "VITORIA"

               Return( "@R 999.999.99-9" )

          Case cCidade == "PALMAS"

               Return( "@R 99.99.999999-9" )

          Case cCidade == "RECIFE"

               Return( "@R 99.9.999.9999999-9" )

          Case cCidade == "CORITIBA" .OR. cCidade == "CURITIBA"

               Return( "@R 999.99999-99" )

          Case cCidade == "NATAL"

               Return( "@R 999.999.99-9" )

          Otherwise

               Return( Space(0) )

       EndCase

    EndIf

    oGet := GetActive()

    If ( Pcount() == 0 )

       @ oGet:Row(),oGet:Col() Say Space( 17 )

       oGet:VarPut( IIf( Trim( oGet:VarGet() ) == "ISENTO(A)", ;
                  Space(15), oGet:VarGet()+Space( 15-Len( oGet:VarGet() ) ) ) )

       oGet:Picture := "@!"

       Return( .T. )

    EndIf

    If Empty( oGet:VarGet() )

       oGet:VarPut( "ISENTO(A)" )

       oGet:Picture := "@!"

       @ oGet:Row(), oGet:Col() SAY SPACE(17)

       Return( .T. )

    EndIf

    cInscricaoMunicipal := oGet:VarGet()

    For Vpos := 1 To Len( Alltrim( cInscricaoMunicipal ) )

        If SubStr( cInscricaoMunicipal, Vpos, 1 ) $ "0123456789" .Or.  ;
           SubStr( cInscricaoMunicipal, Vpos, 1 ) == "P"         .And. ;
           cCidade == "SAO PAULO"

           Origem += SubStr( cInscricaoMunicipal, Vpos, 1 )

        EndIf

    Next

    Mascara := "99999999999999"

    If cCidade == "RIO BRANCO"

       Mascara := "@R 99.99.9999-9"
       Base    := Padr( Origem, 9, "0" )

       If Left( Base, 2 ) == "01" .And. SubStr( Base, 3, 2 ) <> "00"

          Vsom := 0

          For Vpos := 1 To 8

              Valg := Val( SubStr( Base, Vpos, 1 ) )
              Valg := Valg * ( 10 - Vpos )
              Vsom += Valg

          Next

          Vres   := Vsom % 11
          Vdig1  := Str( If( Vres < 2, 0, 11 - Vres ), 1, 0 )
          Vbase2 := Left( Base, 8 ) + Vdig1
          Ok     := ( Vbase2 == Origem )

       EndIf

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    ElseIf cCidade == "ARACAJU"

       Mascara := "@R 99.999.999-9"
       Base    := Padr( Origem, 9, "0" )

       If Left( Base, 2 ) == "24"

          Vsom := 0

          For Vpos := 1 To 8

             Valg := Val( SubStr( Base, Vpos, 1 ) )
             Valg := Valg * ( 10 - Vpos )
             Vsom += Valg

          Next

          Vpro   := Vsom*10
          Vres   := Vpro%11
          Vdig1  := If( Vres == 10, "0", Str( Vres, 1, 0 ) )
          Vbase2 := Left( Base, 8 ) + Vdig1
          Ok     := ( Vbase2 == Origem)

       EndIf

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    ElseIf cCidade == "MANAUS"

       Mascara := "@R 99.999.999-9"
       Base    := Padr( Origem, 9, "0" )
       Vsom    := 0

       For Vpos := 1 to 8

          Valg := Val( SubStr( Base, Vpos, 1 ) )
          Valg := Valg * ( 10 - Vpos )
          Vsom += Valg

       Next

       If Vsom < 11

          Vdig1 := Str( 11 - Vsom, 1, 0 )

       Else

          Vres  := Vsom%11
          Vdig1 := If( Vres < 2, "0", Str( 11 - Vres, 1, 0 ) )

       EndIf

       Vbase2 := Left( Base, 8 ) + Vdig1
       Ok     := ( Vbase2 == Origem )

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

        ElseIf cCidade == "MACAPA"

       Mascara := "@R 99.999.999-9"
       Base    := Padr( origem, 9, "0" )

       If Left( Base, 2 ) == "03"

          N := Val( Left( Base, 8 ) )

          If N >= 3000001 .And. N <= 3017000

             P := 5
             D := 0

          ElseIf N >= 3017001 .And. N <= 3019022

             P := 9
             D := 1

          ElseIf N >= 3019023

             P := 0
             D := 0

          EndIf

          Vsom := P

          For Vpos := 1 To 8

            Valg := Val( SubStr( Base, Vpos, 1 ) )
            Valg := Valg * ( 10 - Vpos )
            Vsom += Valg

          Next

          Vres  := Vsom%11
          Vdig1 := 11-Vres

          If Vdig1 == 10

             Vdig1 := 0

          ElseIf Vdig1 == 11

             Vdig1 := D

          EndIf

          Vdig1  := Str( Vdig1, 1, 0 )
          Vbase2 := Left( Base, 8 ) + Vdig1
          Ok     := ( Vbase2 == Origem )

       EndIf

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

        ElseIf cCidade == "BAHIA"

       Mascara := "@R 999999-99"
       Base    := Padr( Origem, 8, "0" )

       If Left( Base, 1) $ "0123458"

          Vsom := 0

          For Vpos := 1 To 6

              Valg := Val( SubStr( Base, Vpos, 1 ) )
              Valg := Valg * ( 8 - Vpos )
              Vsom += Valg

          Next

          Vres   := Vsom%10
          Vdig2  := Str( If( Vres == 0, 0, 10 - Vres ), 1, 0 )
          Vbase2 := Left( Base, 6 ) + Vdig2
          Vsom   := 0

          For Vpos := 1 To 7

             Valg := Val( SubStr( Vbase2, Vpos, 1 ) )
             Valg := Valg*( 9 - Vpos )
             Vsom += Valg

          Next

          Vres  := Vsom%10
          Vdig1 := Str( If( Vres == 0, 0, 10-Vres ), 1, 0 )

       Else

          vsom:=0

          For Vpos :=1 to 6

              Valg := Val( SubStr( Base, Vpos, 1 ) )
              Valg := Valg*( 8 - Vpos )
              Vsom += Valg

          Next

          Vres   := Vsom%11
          Vdig2  := Str( If( Vres < 2, 0, 11-Vres ), 1, 0 )
          Vbase2 := Left( Base, 6 ) + Vdig2
          Vsom   := 0

          For Vpos := 1 To 7

              Valg := Val( SubStr( Vbase2, Vpos, 1 ) )
              Valg := Valg*( 9 - Vpos )
              Vsom += Valg

          Next

          Vres  := Vsom%11
          Vdig1 := Str( If( Vres < 2, 0, 11-Vres ), 1, 0 )

       EndIf

       vbase2 := Left( Base, 6 ) + Vdig1 + Vdig2
       Ok     := ( Vbase2 == Origem )

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    ElseIf cCidade == "FORTALEZA"

       Mascara := "@R 99999999-9"
       base    := Padr( Origem, 9, "0" )
       vsom    := 0

       For vpos:=1 to 8

           Valg := Val( SubStr( Base, Vpos, 1 ) )
           Valg := Valg*( 10 - Vpos )
           Vsom += Valg

       Next

       Vres  := Vsom%11
       Vdig1 := 11-Vres

       if Vdig1 > 9

          Vdig1 := 0

       EndIf

       Vbase2 := Left( Base, 8 ) + Str( Vdig1, 1, 0 )
       Ok     := ( Vbase2 == Origem )

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    ElseIf cCidade == "BRASILIA"

       Mascara := "@R 999.99999.999-99"
       base    := Padr( Origem, 13, "0" )

       If Left( Base, 3 ) == "073"

          Vsom := 0
          Vmul := {4,3,2,9,8,7,6,5,4,3,2}

          For Vpos := 1 To 11

              valg := Val( SubStr( Base, Vpos, 1 ) )
              valg := Valg * vmul[vpos]
              vsom += Valg

          Next

          vres   := vsom%11
          vdig1  := If( Vres < 2, 0, 11-Vres )
          vbase2 := Left( Base, 11 ) + Str( Vdig1, 1, 0 )
          vsom   := 0
          vmul   := {5,4,3,2,9,8,7,6,5,4,3,2}

          For vpos:=1 to 12

            valg := Val( Substr( Vbase2, Vpos, 1 ) )
            valg := Valg * Vmul[Vpos]
            vsom += Valg

          Next

          vres   := Vsom%11
          vdig2  := If( Vres < 2, 0, 11-Vres )
          vbase2 += Str( Vdig2, 1, 0 )
          Ok     := ( Vbase2 == Origem )

       EndIf

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    ElseIf cCidade == "VITORIA"

       Mascara := "@R 999.999.99-9"
       base    := Padr( Origem, 9, "0" )
       vsom    := 0

       For vpos:=1 to 8

          Valg := Val( SubStr( Base, Vpos, 1 ) )
          Valg := Valg * ( 10 - Vpos )
          Vsom += Valg

       Next

       Vres   := Vsom%11
       Vdig1  := Str( If( Vres < 2, 0, 11-Vres ), 1, 0 )
       Vbase2 := Left( Base, 8) + Vdig1
       Ok     := ( Vbase2 == Origem )

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    ElseIf cCidade == "GOIANIA"

       Mascara := "@R 99.999.999-9"
       base    := Padr( Origem, 9, "0" )

       If Left( Base, 2 ) $ "10,11,15"

          Vsom := 0

          For Vpos := 1 To 8

             valg := Val( SubStr( Base, Vpos, 1 ) )
             valg := Valg * ( 10 - Vpos )
             vsom += Valg

          Next

          Vres := Vsom%11

          If vres == 0

             vdig1 := "0"

          ElseIf Vres == 1

             n     := Val(left(base,8))
             vdig1 := If( N >= 10103105 .And. N <= 10119997, "1", "0" )

          Else

             vdig1:=str(11-vres,1,0)

          EndIf

          vbase2 := Left( Base, 8 ) + Vdig1
          Ok     := ( Vbase2 == Origem )

       EndIf

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    ElseIf cCidade == "SAO LUIS"

       Mascara := "@R 99.999.999-9"
       base    := Padr( Origem, 9, "0" )

       If Left( Base, 2 ) == "12"

          Vsom := 0

          for vpos:=1 to 8
              valg:=val(substr(base,vpos,1))
              valg:=valg*(10-vpos)
              vsom+=valg
          next

          vres   := vsom%11
          vdig1  := Str( If( Vres < 2, 0, 11 - Vres ), 1, 0 )
          vbase2 := Left( Base, 8 ) + Vdig1
          Ok     := ( Vbase2 == Origem )

       EndIf

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    ElseIf cCidade == "CAMPO GRANDE"

       Mascara := "@R 9999999999-9"
       vmul    := {3,2,9,8,7,6,5,4,3,2}

       For Vpos := 1 To 10

          valg := Val( SubStr( Base, Vpos, 1 ) )
          valg := Valg * Vmul[Vpos]
          vsom += Valg

       Next

       vres   := vsom%11
       vdig1  := If( Vres < 2, 0, 11 - Vres )
       vbase2 := Left( Base, 10 ) + Str( Vdig1, 1, 0 )
       Ok     := ( Vbase2 == Origem )

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    ElseIf cCidade == "CUIABA"

       Mascara := "@R 99.999.999-9"
       base    := Padr( Origem, 9, "0" )

       If Left( Base, 2 ) == "28"

          vsom := 0

          For vpos:=1 to 8

             valg := Val( SubStr( Base, Vpos, 1 ) )
             valg := Valg*(10-vpos)
             vsom += Valg

          Next

          vres   := vsom%11
          vdig1  := Str( If( vres < 2, 0, 11-Vres ), 1, 0 )
          vbase2 := Left( Base, 8 ) + Vdig1
          Ok     := ( Vbase2 == Origem )

       EndIf

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    ElseIf cCidade == "BELO HORIZONTE"

       Mascara := "@R 999.999.999/9999"
       base    := Padr( Origem, 13, "0" )
       vbase2  := Left( Base, 3 ) + "0" + SubStr( Base, 4, 8 )
       n       := 2
       vsom    := ""

       For Vpos := 1 To 12

           valg := Val( SubStr( vbase2, vpos, 1 ) )
           n    := If( N==2, 1, 2 )
           valg := Alltrim( Str( Valg * N, 2, 0 ) )
           vsom += VAlg

       Next

       n := 0

       For Vpos := 1 To Len(Vsom)

         n += Val( SubStr( Vsom, Vpos, 1 ) )

       Next

       Vsom := N

       While Right( Str( n, 3, 0), 1 ) <> "0"

         N++

       End

       Vdig1  := Str( N-Vsom, 1, 0 )
       Vbase2 := Left( Base, 11 ) + Vdig1
       Vsom   := 0
       Vmul   := {3,2,11,10,9,8,7,6,5,4,3,2}

       For Vpos := 1 To 12

          valg := Val( SubStr( Vbase2, vpos, 1 ))
          valg := Valg * Vmul[Vpos]
          vsom += Valg

       Next

       vres   := Vsom%11
       vdig2  := If( Vres < 2, 0, 11-Vres )
       vbase2 += Str( vdig2, 1, 0 )
       Ok     := ( vbase2 == origem )

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    ElseIf cCidade == "BELEM"

       Mascara := "@R 99-999999-9"
       Base    := padr(origem,9,"0")

       If Left( base, 2 ) == "15"

          vsom := 0

          For vpos := 1 to 8

            valg := Val( Substr( Base, Vpos, 1 ) )
            valg := Valg * ( 10 - Vpos )
            vsom += Valg

          Next

          Vres   := Vsom%11
          Vdig1  := Str( If( Vres < 2, 0, 11-Vres ), 1, 0 )
          Vbase2 := Left( Base, 8 ) + Vdig1
          Ok     := ( Vbase2 == origem)

       EndIf

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    ElseIf cCidade == "JOAO PESSOA"

       Mascara := "@R 99.999.999-9"
       base    := Padr( Origem, 9, "0" )
       vsom    := 0

       For vpos:=1 to 8

          valg := Val( SubStr( Base, Vpos, 1 ) )
          valg := Valg * ( 10 - Vpos )
          vsom += Valg

       Next

       Vres   := vsom%11
       vdig1  := 11-vres

       If Vdig1 > 9

          vdig1 := 0

       EndIf

       vbase2 := Left( Base, 8 ) + Str( Vdig1, 1, 0 )
       Ok     := ( vbase2 == origem )

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    ElseIf cCidade == "RECIFE"

       Mascara := "@R 99.9.999.9999999-9"
       base    := Padr( Origem, 14, "0" )
       vsom    := 0
       vmul    := {5,4,3,2,1,9,8,7,6,5,4,3,2}

       For Vpos := 1 To 13

         valg := Val( SubStr( Base, Vpos, 1 ) )
         valg := Valg * Vmul[Vpos]
         vsom += Valg

       Next

       vres  := Vsom%11
       vdig1 := 11-Vres

       if( Vdig1 > 9, Vdig1 -= 10, )

       Vbase2 := Left( Base, 13 ) + Str( Vdig1, 1, 0 )
       Ok     := ( Vbase2 == Origem )

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    ElseIf cCidade == "TERESINA"

       Mascara := "@R 99.999.999-9"
       base    := Padr( Origem, 9, "0" )
       vsom    := 0

       For vpos := 1 to 8

          valg := Val( SubStr( Base, Vpos, 1 ) )
          valg := Valg * ( 10-Vpos )
          vsom += Valg

       Next

       Vres   := vsom%11
       Vdig1  := Str( If( Vres < 2, 0, 11-Vres ), 1, 0 )
       Vbase2 := Left( Base, 8 ) + Vdig1
       Ok     := ( Vbase2 == Origem )

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    ElseIf cCidade == "CORITIBA" .OR. cCidade == "CURITIBA"

       Mascara := "@R 999.99999-99"
       base    := Padr( Origem, 10, "0" )
       vsom    := 0
       vmul    := {3,2,7,6,5,4,3,2}

       For Vpos :=1 to 8

          valg := Val( SubStr( Base, Vpos, 1 ) )
          valg := Valg * Vmul[Vpos]
          vsom += Valg

       Next

       vres   := Vsom%11
       vdig1  := Str( If( Vres < 2, 0, 11-Vres ), 1, 0 )
       vbase2 := Left( Base, 8 ) + Vdig1
       vsom   := 0
       vmul   := {4,3,2,7,6,5,4,3,2}

       For Vpos := 1 to 9

          valg := Val( SubStr( Vbase2, Vpos, 1 ) )
          valg := Valg*Vmul[Vpos]
          vsom += Valg

       next

       vres   := Vsom%11
       vdig2  := Str( If( Vres < 2, 0, 11-Vres ), 1, 0 )
       vbase2 += Vdig2
       Ok     := ( Vbase2 == Origem )

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    ElseIf cCidade == "RIO DE JANEIRO"

       Mascara := "@R 99.999.99-9"
       base    := Padr( Origem, 8, "0" )
       vsom    := 0
       vmul    := {2,7,6,5,4,3,2}

       For Vpos := 1 to 7

         valg := Val( SubStr( Base, Vpos, 1 ) )
         valg := Valg*Vmul[vpos]
         vsom += Valg

       Next

       vres   := Vsom%11
       vdig1  := Str( If( Vres < 2, 0, 11-Vres ), 1, 0 )
       vbase2 := Left( Base, 7 ) + Vdig1
       Ok     := ( Vbase2 == Origem )

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    ElseIf cCidade == "NATAL"

       Mascara := "@R 99.999.999-9"
       base    := Padr( Origem, 9, "0" )

       If Left( Base, 2 ) == "20"

          Vsom := 0

          For Vpos := 1 to 8

              valg := Val( SubStr( Base, Vpos, 1 ) )
              valg := Valg*(10-vpos)
              vsom += Valg

          Next

          vpro   := Vsom*10
          vres   := Vpro%11
          vdig1  := Str( If( Vres > 9, 0, Vres ), 1, 0 )
          vbase2 := Left( Base, 8 ) + Vdig1
          Ok     := ( Vbase2 == Origem )

       EndIf

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    ElseIf cCidade == "MACAPA"

       Mascara := "@R 99.999.999-9"
       base    := Padr( Origem, 9, "0" )
       vbase2  := SubStr( Base, 4, 5 )
       vsom    := 0

       For Vpos := 1 to 5

           valg := Val( SubStr( vbase2, vpos, 1 ) )
           valg := valg * ( 7 - Vpos )
           vsom += valg

       Next

       vres  := vsom%11
       vdig1 := 11 - Vres

       If Vdig1 > 9

          Vdig1 -= 10

       EndIf

       vbase2 := Left( Base, 8 ) + Str( vdig1, 1, 0 )
       Ok     := ( Vbase2 == Origem )

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    ElseIf cCidade == "BOA VISTA"

       Mascara := "@R 99999999-9"
       base    := Padr( Origem, 9, "0" )

       If Left( Base, 2 ) == "24"

          vsom := 0

          For Vpos := 1 to 8

             Valg := Val( SubStr( Base, vpos, 1 ) )
             Valg := Valg * Vpos
             Vsom += Valg

          Next

          vres   := vsom%9
          vdig1  := Str( Vres, 1, 0 )
          vbase2 := Left( Base, 8 ) + Vdig1
          Ok     := ( Vbase2 == Origem )

       EndIf

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    ElseIf cCidade == "PORTO ALEGRE"

       Mascara := "@R 999/999999-9"
       base    := Padr( Origem, 10, "0" )
       n       := Val( Left( Base, 3 ) )

       If N > 0 .And. n < 468

          vsom := 0
          vmul := {2,9,8,7,6,5,4,3,2}

          For Vpos := 1 to 9

             valg := Val( SubStr( Base, Vpos, 1 ) )
             valg := Valg * Vmul[vpos]
             vsom += Valg

          Next

          vres  := vsom%11
          vdig1 := 11-vres

          If Vdig1 > 9

             Vdig1 := 0

          EndIf

          vbase2 := Left( Base, 9 ) + Str( Vdig1, 1, 0 )
          Ok     := ( Vbase2 == Origem )

       EndIf

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    ElseIf cCidade == "FLORIANOPOLIS" .OR. cCidade == "FLORIANOPOLES"

       Mascara := "@R 999.999.999"
       base    := Padr( Origem, 9, "0" )
       vsom    := 0

       For Vpos := 1 to 8

          valg := Val( SubStr( Base, Vpos, 1 ) )
          valg := Valg * ( 10 - Vpos )
          vsom += Valg

       Next

       vres   := Vsom%11
       vdig1  := If( Vres < 2, "0", Str( 11-vres, 1, 0 ))
       vbase2 := Left( Base, 8 ) + Vdig1
       Ok     := ( Vbase2 == Origem )

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    ElseIf cCidade == "ARACAJU"

       Mascara := "@R 99999999-9"
       base    := Padr( Origem, 9, "0" )
       vsom    := 0

       For Vpos := 1 to 8

          valg := Val( SubStr( Base, Vpos, 1 ) )
          valg := valg * ( 10 - vpos )
          vsom += valg

       Next

       vres  := vsom%11
       vdig1 := 11-vres

       If vdig1 > 9

          Vdig1 := 0

       EndIf

       vbase2 := Left( Base, 8 ) + Str( vdig1, 1, 0 )
       Ok     := ( Vbase2 == Origem )

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    ElseIf cCidade == "SAO PAULO"

       If Left( Origem, 1 ) == "P"

          Mascara := "@R !-99999999.9/999"
          base    := Padr( origem, 13, "0" )
          vbase2  := SubStr( Base, 2, 8 )
          vsom    := 0
          vmul    := {1,3,4,5,6,7,8,10}

          For Vpos := 1 to 8

            valg := Val( SubStr( Vbase2, Vpos, 1 ) )
            valg := Valg * Vmul[vpos]
            vsom += Valg

          Next

          Vres   := Vsom%11
          Vdig1  := Right( Str( Vres, 2, 0 ), 1 )
          Vbase2 := Left( Base, 9 ) + Vdig1 + SubStr( Base, 11, 3 )

       Else

          Mascara := "@R 999.999.999.999"
          base    := Padr( Origem, 12, "0" )
          vsom    := 0
          vmul    := {1,3,4,5,6,7,8,10}

          For Vpos := 1 To 8

             valg := Val( SubStr( Base, vpos, 1 ) )
             valg := valg * vmul[vpos]
             vsom += valg

          Next

          vres   := vsom%11
          vdig1  := Right( Str( vres, 2, 0 ), 1 )
          vbase2 := Left( Base, 8 ) + Vdig1 + SubStr( Base, 10, 2 )
          vsom   := 0
          vmul   := {3,2,10,9,8,7,6,5,4,3,2}

          For Vpos := 1 to 11

             valg := Val( SubStr( Base, vpos, 1 ) )
             valg := valg * vmul[vpos]
             vsom += valg

          Next

          vres   := vsom%11
          vdig2  := Right( Str( vres, 2, 0 ), 1 )
          vbase2 += vdig2

       EndIf

       Ok := ( vbase2 == origem )

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    ElseIf cCidade == "PALMAS"

       Mascara := "@R 99.99.999999-9"
       base    := Padr( Origem, 11, "0" )

       If SubStr( Base, 3, 2 ) $ "01,02,03,99"

          vbase2 := Left( Base, 2 ) + SubStr( Base, 5, 6 )
          vsom   := 0

          For Vpos := 1 to 8

             valg := Val( SubStr( vbase2, vpos, 1 ) )
             valg := valg * ( 10 - vpos )
             vsom += valg

          Next

          Vres   := vsom%11
          Vdig1  := Str( If( vres < 2, 0, 11 - Vres ), 1, 0 )
          Vbase2 := Left( Base, 10 ) + vdig1
          Ok     := ( vbase2 == origem )

       EndIf

       If Ok

          oGet:VarPut( vbase2 )

          oGet:Picture := Mascara

       EndIf

    Else

       Alert( "Unidade Municipal Invalida !" )

    EndIf

    If !Ok .And. LastKey() # K_UP

       If Empty( vbase2 )

          Alert( "Os D¡gitos Identificadores de Cidade e/ou Estado N„o Conferem !" )

       Else

          vbase2 := TransForm( Alltrim( vbase2 ), Mascara )

          Alert( "Inscri‡„o Inv lida! O Correto Seria " + Vbase2 )

       EndIf

       Return( .F. )

    EndIf

    If Len( Alltrim( oGet:VarGet() ) ) == 7

       oGet:VarPut( Alltrim( oGet:VarGet() ) )

       oGet:Picture := "@R PR 999/9999"

    EndIf

    @ oGet:Row(), oGet:Col() SAY Space( 17 )

Return( .T. )


Obg. abs.

Validar a Inscrição Municipal

29 Out 2018 19:35

Olá!

Imagine se cada um dos mais de cinco mil municípios adotar uma fórmula diferente...

Acho que tem que ir entrando em contato com as prefeituras na medida da necessidade. Mesmo no Google é difícil encontrar as fórmulas.
Postar uma resposta