*----------------------------------------------------------------*
* CHEQUEA DIGITOS VERIFICADORES *
*----------------------------------------------------------------*
*
After-Init.
EVALUATE LNK-DV-SELECCION
WHEN 1
PERFORM VALIDAR-CUIT
WHEN 2
PERFORM VALIDAR-IIBB
WHEN 4
PERFORM VALIDAR-CBU
WHEN 3
PERFORM VALIDAR-CUIT
PERFORM VALIDAR-IIBB
WHEN 5
PERFORM VALIDAR-CUIT
PERFORM VALIDAR-CBU
WHEN 6
PERFORM VALIDAR-IIBB
PERFORM VALIDAR-CBU
WHEN 7
PERFORM VALIDAR-CUIT
PERFORM VALIDAR-IIBB
PERFORM VALIDAR-CBU
END-EVALUATE.
EXIT PROGRAM.
STOP RUN.
*----------------------------------------------------------------*
* VALIDA CUIT/CUIL *
* 0 = FALSE (CUIT NO ES VALIDO) *
* 1 = TRUE (CUIT VALIDO) *
*----------------------------------------------------------------*
*
VALIDAR-CUIT.
IF LNK-DV-CUIT NOT NUMERIC OR
LNK-DV-CUIT = 0
MOVE 0 TO LNK-DV-Validar-CUIT
EXIT PARAGRAPH.
MOVE ZEROS TO A.
MOVE 0 TO IDX.
PERFORM UNTIL IDX = 10
SET IDX UP BY 1
COMPUTE A = A +
(FUNCTION NUMVAL(LNK-DV-CUIT(IDX:1))
* IT-PESO-CUIT(IDX))
END-COMPUTE
END-PERFORM.
COMPUTE C = A / B.
COMPUTE D = B - ( A - ( B * C ) ).
IF D = 10
MOVE 9 TO V
IF V = FUNCTION NUMVAL(LNK-DV-CUIT(11:1))
MOVE 1 TO LNK-DV-Validar-CUIT
ELSE
MOVE 0 TO LNK-DV-Validar-CUIT
END-IF
EXIT PARAGRAPH.
COMPUTE D = B * C.
IF D = A
MOVE 0 TO V
IF V = FUNCTION NUMVAL(LNK-DV-CUIT(11:1))
MOVE 1 TO LNK-DV-Validar-CUIT
ELSE
MOVE 0 TO LNK-DV-Validar-CUIT
END-IF
EXIT PARAGRAPH.
COMPUTE V = B - ( A - ( B * C)).
IF V = FUNCTION NUMVAL(LNK-DV-CUIT(11:1))
MOVE 1 TO LNK-DV-Validar-CUIT
ELSE
MOVE 0 TO LNK-DV-Validar-CUIT
END-IF.
*----------------------------------------------------------------*
* VALIDA NUMERO INGRESOS BRUTOS *
*----------------------------------------------------------------*
*
VALIDAR-IIBB.
MOVE 0 TO LNK-DV-Validar-IIBB.
IF LNK-DV-IIBB(8:1) = '-' OR
LNK-DV-IIBB(4:1) = '-' AND
LNK-DV-IIBB(11:1) = '-'
CONTINUE
ELSE
MOVE 0 TO LNK-DV-Validar-IIBB
EXIT PARAGRAPH.
IF LNK-DV-IIBB(8:1) = '-'
PERFORM VALIDAR-IIBB-LOCAL
ELSE
PERFORM VALIDAR-IIBB-CONVENIO.
*
VALIDAR-IIBB-LOCAL.
MOVE 0 TO IDX A.
PERFORM UNTIL IDX = 7
SET IDX UP BY 1
MOVE LNK-DV-IIBB(IDX:1) TO NUMERO
COMPUTE A ROUNDED =
A + (NUMERO * IT-PESO-IIBB-LOCAL(IDX))
END-COMPUTE
END-PERFORM.
COMPUTE C = A / B.
COMPUTE D = C * B.
COMPUTE E = A - D.
COMPUTE F = B - E.
MOVE LNK-DV-IIBB(9:2) TO V.
IF V = F
MOVE 1 TO LNK-DV-Validar-IIBB
ELSE
MOVE 0 TO LNK-DV-Validar-IIBB.
*
VALIDAR-IIBB-CONVENIO.
MOVE 0 TO IDX A.
PERFORM UNTIL IDX = 6
SET IDX UP BY 1
MOVE LNK-DV-IIBB(IDX + 4:1) TO NUMERO
COMPUTE A ROUNDED =
A + (NUMERO * IT-PESO-IIBB-CONVENIO(IDX))
END-COMPUTE
END-PERFORM.
COMPUTE C = A / B.
COMPUTE D = C * B.
COMPUTE E = A - D.
COMPUTE F = B - E.
MOVE LNK-DV-IIBB(12:1) TO V.
IF V = F
MOVE 1 TO LNK-DV-Validar-IIBB
ELSE
MOVE 0 TO LNK-DV-Validar-IIBB.
*----------------------------------------------------------------*
* VALIDA CBU *
*----------------------------------------------------------------*
*
VALIDAR-CBU.
If LNK-DV-CBU NOT NUMERIC
MOVE 0 TO LNK-DV-Validar-CBU
EXIT PARAGRAPH
END-IF.
*
* Verifica 8º Dígito
*
MOVE 0 TO A,
MOVE 5 TO IDX-1
MOVE 8 TO IDX
PERFORM UNTIL IDX = 1
SET IDX, IDX-1 DOWN BY 1
COMPUTE A =
A +
(FUNCTION NUMVAL(LNK-DV-CBU(IDX:1))
* IT-PESO-CBU(IDX-1))
END-COMPUTE
IF IDX-1 = 1
MOVE 5 TO IDX-1
END-IF
END-PERFORM.
COMPUTE V =
FUNCTION MOD(FUNCTION MOD(10 - A, 10), 10)
END-COMPUTE.
IF FUNCTION NUMVAL(LNK-DV-CBU(8:1)) NOT = V
MOVE 0 TO LNK-DV-Validar-CBU
Exit Paragraph
END-IF.
*
* Verifica 22º Dígito
*
MOVE 0 TO A
MOVE 5 TO IDX-1
MOVE 22 TO IDX
PERFORM UNTIL IDX = 9
SET IDX, IDX-1 DOWN BY 1
COMPUTE A =
A +
(FUNCTION NUMVAL(LNK-DV-CBU(IDX:1))
* IT-PESO-CBU(IDX-1))
END-COMPUTE
IF IDX-1 = 1
MOVE 5 TO IDX-1
END-IF
END-PERFORM.
COMPUTE V =
FUNCTION MOD(FUNCTION MOD(10 - A, 10), 10)
END-COMPUTE.
IF FUNCTION NUMVAL(LNK-DV-CBU(22:1)) NOT = V
MOVE 0 TO LNK-DV-Validar-CBU
Exit Paragraph
END-IF.
MOVE 1 TO LNK-DV-Validar-CBU.