the sum is calculated:
1 * a1 + 2 * a2 + 3 * a3 + 4 * a4 + 5 * a5 + 6 * a6 + 7 * a7 + 8 * a8,
where a1 is the first digit, a2 is the second, and so on.
• the balance under module 11 of the amount is calculated
• if the remainder is other than 10, it is defined as the ninth digit
• if the remainder is 10, the amount is calculated
3 * a1 + 4 * a2 + 5 * a3 + 6 * a4 + 7 * a5 + 8 * a6 + 9 * a7 + 10 * a8,
where a1 is the first digit, a2 is the second, and so on
• the balance under module 11 of the new amount is calculated
• if the remainder is other than 10, it is defined as the ninth digit, and if it is ten - for
the ninth digit is set to "0"
According to your example, 83102340 = 8 + 6 + 3 + 0 + 10 + 18 + 28 + 0 = 73
if the last 9th digit is 0, it is considered valid.
It is a question of checking the validity of the UIC under the Bulgarian legislation.
I did it very easily with PHP, but I'm a beginner with DELPHI.
I found this, but I can't embed it in MVD
Function IsDN(dn:String;var code:integer):Boolean;
var
L,i:integer;
v,vs,vm:Longint;
begin
Result:=False;
dn:=TrimAll_t(dn);
L:=Length(dn);
if L<>10 then begin
Result:=False;
code:=1;
Exit;
end;
if dn='9999999999' then begin
Result:=True;
Exit;
end;
vs:=0;
v:=0;
For i:=1 to L do begin
if not (dn[i] in ['0'..'9']) then begin
{if there are # characters from a number}
code:=2;
Exit;
end;
v:=StrToIntDef(dn[i],0);
case i of
1:vs:=vs+v*4;
2:vs:=vs+v*3;
3:vs:=vs+v*2;
4:vs:=vs+v*7;
5:vs:=vs+v*6;
6:vs:=vs+v*5;
7:vs:=vs+v*4;
8:vs:=vs+v*3;
9:vs:=vs+v*2;
end;{case i}
end;{For i:=1 to L do begin}
if vs=0 then begin
code:=3;
exit;
end;
vm:=vs mod 11;
case vm of
0:begin{the last number in the DN must be 0}
if v<>0 then begin
code:=4;
exit;
end;
end;
1:begin{wrong DN}
code:=5;
Exit;
end;
2..10:
begin
if v<>(11-vm) then begin
code:=6;
exit;
end;
end;
end;{case vm}
Result:=True;
end;