Codice Fiscale

« Older   Newer »
  Share  
Aaly
CAT_IMG Posted on 17/2/2011, 22:54     +1   -1




Ecco una piccola UDF fatta da me per calcolare il codice fiscale con pochi dati.
Per ora il database è contenuto in un file .ini, successivamente lo creerò in MySQL e lo metterò online.
Vi chiedo gentilmente di provarlo e farmi sapere eventuali errori. ^^

Pack completo 0.1 (Example.exe, Example.au3, FiscalCode.au3, FiscalCode.ini)
Download.

UDF -> FiscalCode v0.1
SPOILER (click to view)
CODICE
; #INDEX# =======================================================================================================================
; Title .........: FiscalCode
; AutoIt Version : 3.3.6.1
; Language ......: Italiano/English
; Description ...: Funzione con cui è possibile generare un codice fiscale
;                                   partendo dai dati anagrafici.
; Author ........: Aaly©
; ===============================================================================================================================


; #FUNCTION# ====================================================================================================================
; Name...........: __GenerateFiscalCode
; Description ...: Genera il codice fiscale con i dati inseriti.
; Syntax.........: __GenerateFiscalCode($xName, $xSurname, $xBDay, $xBMonth, $xBYear, $xSex, $xPlaceOfBirth)
; Parameters ....: $xName         - Nome.
;                  $xSurname      - Cognome.
;                  $xBDay         - Giorno di nascita. (01;02;..)
;                  $xBMonth       - Mese di nascita. (01;02;..)
;                  $xBYear        - Anno di nascita. (completo: 1990)
;                  $xSex          - Sesso. (M/F)
;                  $xPlaceOfBirth - Comune di nascita.
; Return values .: Success        - Codice fiscale completo.
;                  Failure        - 0
; Files .........: FiscalCode.ini
; Author ........: Aaly©
; Version .......: 0.1
; Type ..........: Public
; ===============================================================================================================================
Func __GenerateFiscalCode($xName, $xSurname, $xBDay, $xBMonth, $xBYear, $xSex, $xPlaceOfBirth)
       Global $CONS[22] = ["","B","C","D","F","G","H","J","K","L","M","N","P","Q","R","S","T","V","W","X","Y","Z"]
       Global $VOCA[7]  = ["","A","E","I","O","U"]
         Local $FiscalCode = "", $FiscalSurname, $FiscalName, $FiscalBday, $FiscalCom, $FiscalCar, $NameCons = 3

       $FiscalSurname = __GetSurnameCons($xSurname)
                       $FiscalCode &= $FiscalSurname[1]
                       $FiscalCode &= $FiscalSurname[2]
                       $FiscalCode &= $FiscalSurname[3] & " "

       If StringInStr($xName," ") Then $NameCons = 4
       $FiscalName    = __GetNameCons($xName, $NameCons)
               If $FiscalName[4] = "" Then
                       $FiscalCode &= $FiscalName[1]
                       $FiscalCode &= $FiscalName[2]
                       $FiscalCode &= $FiscalName[3] & " "
               Else
                       $FiscalCode &= $FiscalName[1]
                       $FiscalCode &= $FiscalName[3]
                       $FiscalCode &= $FiscalName[4] & " "
               EndIf

       $FiscalBday    = __GetBdayValue($xBDay, $xBMonth, $xBYear, $xSex)
                       $FiscalCode &= $FiscalBday[1]
                       $FiscalCode &= $FiscalBday[2]
                       $FiscalCode &= $FiscalBday[3] & " "

       $FiscalCom           = __GetCom($xPlaceOfBirth)
                       $FiscalCode &= $FiscalCom

       $FiscalCar     = __GetCar($FiscalCode)
                       $FiscalCode &= $FiscalCar

       FileDelete(@TempDir & "\FiscalCode.ini")
       Return($FiscalCode)
EndFunc


; #FUNCTION# ====================================================================================================================
; Name...........: __GetSurnameCons
; Description ...:
; Syntax.........: __GetSurnameCons($GCSurname, $GCCons = 3)
; Parameters ....: $GCSurname     - ~
;                  $GCCons = 3    - ~
; Return values .: Success        - ~
;                  Failure        - 0
; Author ........: Aaly©
; Type ..........: Private
; ===============================================================================================================================
Func __GetSurnameCons($GCSurname, $GCCons = 3)
       Local $ConsGett[20], $GCSplit, $i, $i2, $Add = 1

; Presa delle consonanti
       $GCSplit = StringSplit(StringUpper($GCSurname),"")
       For $i = 1 To $GCSplit[0] Step 1
               For $i2 = 1 To 21 Step 1
                       If $GCSplit[$i] = $CONS[$i2] Then
                               $ConsGett[$Add] = $CONS[$i2]
                               $Add += 1
                       EndIf
               Next
               If $Add = $GCCons+1 Then Return($ConsGett)
       Next

; Eccezione: Se non ci sono 3 consonanti
       If $Add < $GCCons+1 Then
               For $i = 1 To $GCSplit[0] Step 1
                       For $i2 = 1 To 6 Step 1
                               If $GCSplit[$i] = $VOCA[$i2] Then
                                       $ConsGett[$Add] = $VOCA[$i2]
                                       $Add += 1
                               EndIf
                       Next
                       If $Add = $GCCons+1 Then ExitLoop
               Next
       EndIf

       If $ConsGett[3] = "" Then $ConsGett[3] = "X"

       Return($ConsGett)
EndFunc


; #FUNCTION# ====================================================================================================================
; Name...........: __GetNameCons
; Description ...:
; Syntax.........: __GetNameCons($GCName, $GNCons = 5)
; Parameters ....: $GCName        - ~
;                  $GNCons = 5    - ~
; Return values .: Success        - ~
;                  Failure        - 0
; Author ........: Aaly©
; Type ..........: Private
; ===============================================================================================================================
Func __GetNameCons($GCName, $GNCons = 4)
       Local $ConsGett[20], $GNSplit, $i, $i2, $Add = 1
       $ConsGett[4] = ""

; Presa delle consonanti
       $GNSplit = StringSplit(StringUpper($GCName),"")
       For $i = 1 To $GNSplit[0] Step 1
               For $i2 = 1 To 21 Step 1
                       If $GNSplit[$i] = $CONS[$i2] Then
                               $ConsGett[$Add] = $CONS[$i2]
                               $Add += 1
                       EndIf
               Next
               If $Add = $GNCons+1 Then Return($ConsGett)
       Next

; Eccezione: Se non ci sono 3 consonanti
       If $Add < $GNCons+1 Then
               For $i = 1 To $GNSplit[0] Step 1
                       For $i2 = 1 To 6 Step 1
                               If $GNSplit[$i] = $VOCA[$i2] Then
                                       $ConsGett[$Add] = $VOCA[$i2]
                                       $Add += 1
                               EndIf
                       Next
                       If $Add = $GNCons+1 Then ExitLoop
               Next
       EndIf

       If $ConsGett[3] = "" Then $ConsGett[3] = "X"

       Return($ConsGett)
EndFunc


; #FUNCTION# ====================================================================================================================
; Name...........: __GetBdayValue
; Description ...:
; Syntax.........: __GetBdayValue($GBDay, $GBMonth, $GBYear, $GBSex)
; Parameters ....: $GBDay         - ~
;                  $GBMonth       - ~
;                                   $GBYear        - ~
;                                   $GBSex         - ~
; Return values .: Success        - ~
;                  Failure        - 0
; Author ........: Aaly©
; Type ..........: Private
; ===============================================================================================================================
Func __GetBdayValue($GBDay, $GBMonth, $GBYear, $GBSex)
       Local $Gett[4]

       $Gett[1] = StringMid($GBYear,3,4)

               If StringUpper($GBMonth) = "01" Then $Gett[2] = "A"
               If StringUpper($GBMonth) = "02" Then $Gett[2] = "B"
               If StringUpper($GBMonth) = "03" Then $Gett[2] = "C"
               If StringUpper($GBMonth) = "04" Then $Gett[2] = "D"
               If StringUpper($GBMonth) = "05" Then $Gett[2] = "E"
               If StringUpper($GBMonth) = "06" Then $Gett[2] = "H"
               If StringUpper($GBMonth) = "07" Then $Gett[2] = "L"
               If StringUpper($GBMonth) = "08" Then $Gett[2] = "M"
               If StringUpper($GBMonth) = "09" Then $Gett[2] = "P"
               If StringUpper($GBMonth) = "10" Then $Gett[2] = "R"
               If StringUpper($GBMonth) = "11" Then $Gett[2] = "S"
               If StringUpper($GBMonth) = "12" Then $Gett[2] = "T"

               If StringUpper($GBSex) = "M" Then
                       $Gett[3] = $GBDay
               Else
                       $Gett[3] = ($GBDay+40)
               EndIf
       Return($Gett)
EndFunc


; #FUNCTION# ====================================================================================================================
; Name...........: __GetCom
; Description ...:
; Syntax.........: __GetCom($GCPlace)
; Parameters ....: $GCPlace       - ~
;
; Return values .: Success        - ~
;                  Failure        - 0
; Author ........: Aaly©
; Type ..........: Private
; ===============================================================================================================================
Func __GetCom($GCPlace)
       Local $FirstChar, $SectionRead

       FileInstall("FiscalCode.ini",@TempDir & "\FiscalCode.ini")

       $FirstChar  = StringMid($GCPlace,1,1)
       $SectionRead = IniReadSection(@TempDir & "\FiscalCode.ini",$FirstChar)
               If @error Then
                       FileDelete(@TempDir & "\FiscalCode.ini")
                       MsgBox(48,"~ Error","Cannont find: FiscalCode.ini")
                       Exit
               EndIf

               For $i = 1 To $SectionRead[0][0] Step 1
                       If $SectionRead[$i][1] = StringUpper($GCPlace) Then ExitLoop
               Next
       Return($SectionRead[$i][0])
EndFunc


; #FUNCTION# ====================================================================================================================
; Name...........: __GetCar
; Description ...:
; Syntax.........: __GetCar($GCCode)
; Parameters ....: $GCCode        - ~
;
; Return values .: Success        - ~
;                  Failure        - 0
; Author ........: Aaly©
; Type ..........: Private
; ===============================================================================================================================
Func __GetCar($GCCode)
       Local $Replace, $i, $Split, $Mid, $Tot = 0, $Result

       $Replace = StringReplace($GCCode, " ", "")

       For $i = 0 To StringLen($Replace) Step 1
               $Mid = StringMid($Replace,$i,1)
                       $Ini = IniRead(@TempDir & "\FiscalCode.ini","CAR",$Mid,"")
                       $Split = StringSplit($Ini,"|")
               If IsInt($i/2) = 1 Then
                       $Tot += $Split[1]
;~                         MsgBox(0,"",$Mid & " : " & $i & ": pari : " & $Split[1])
               Else
                       $Tot += $Split[2]
;~                         MsgBox(0,"",$Mid & " : " & $i & ": dispari : " & $Split[2])
               EndIf
       Next

       $Result = Mod($Tot,26)
       Return(IniRead(@TempDir & "\FiscalCode.ini","CHAR",$Result,""))
EndFunc


Databse -> FiscalCode.ini
(allegato)

Download attachment
FiscalCode.ini ( Number of downloads: 248 )

 
Top
xMasteRx
CAT_IMG Posted on 17/2/2011, 23:12     +1   -1




sono il beta tester XD
bona ²
 
Top
3ad
CAT_IMG Posted on 18/2/2011, 07:46     +1   -1




Bravo ;)
 
Top
/dev/random
CAT_IMG Posted on 18/2/2011, 15:07     +1   -1




Bello! :D
 
Top
Aaly
CAT_IMG Posted on 18/2/2011, 15:26     +1   -1




Se il nome o il cognome contengono F darà errore, nel "database" nella sezione "CAR" manca l'= nella R. xD

EDIT: Qualcuno può provarlo e dirmi se funziona?

Edited by Aaly - 18/2/2011, 15:51
 
Top
4 replies since 17/2/2011, 22:54   429 views
  Share