Created
April 29, 2016 17:20
-
-
Save raisiqueira/7b77e1de3344786a6076997310553960 to your computer and use it in GitHub Desktop.
Cálculo de Modulo 11 em ADVPL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Função Modulo 11 para gerar Digito Verificador do Bradesco | |
* 2016 | IMEC | |
* Autor Rai Siqueira, Raphael Mendes | |
*/ | |
Static Function Modulo11(cData,nPeso,cOrig) | |
Local L, D, P := 0 | |
L := Len(cdata) | |
D := 0 | |
P := 1 | |
While L > 0 | |
P := P + 1 | |
D := D + (Val(SubStr(cData, L, 1)) * P) | |
If P = nPeso | |
P := 1 | |
EndIf | |
L := L - 1 | |
EndDo | |
If Alltrim(cOrig) == 'NN' | |
D := 11 - (mod(D,11)) | |
IF D == 11 //Se o resto for 11, o digito verificador será 0 | |
D := 0 | |
Endif | |
IF D == 10 //Se o resto for 10, o dígito verificador será P | |
D := "P" | |
Endif | |
Else | |
IF Mod(D,11) == 0 .or. Mod(D,11) == 1 .or. Mod(D,11) == 10 | |
D := 1 | |
Else | |
D := 11 - (mod(D,11)) | |
Endif | |
Endif | |
Return(D) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment