nationalPT function

String nationalPT(
  1. String bban,
  2. BbanStructure structure
)

Implementation

String nationalPT(String bban, BbanStructure structure) {
  final int V0 = "0".codeUnitAt(0);
  const List<int> weights = [
    73,
    17,
    89,
    38,
    62,
    45,
    53,
    15,
    50,
    5,
    49,
    34,
    81,
    76,
    27,
    90,
    9,
    30,
    3
  ];
  final List<int> listRemainders = [
    PartType.BANK_CODE,
    PartType.BRANCH_CODE,
    PartType.ACCOUNT_NUMBER
  ]
      .map((p) => structure.extractValueMust(bban, p))
      .join("")
      .split("")
      .map((v) => v.codeUnitAt(0))
      .toList();

  int remainder = 0;

  for (int i = 0; i < listRemainders.length; ++i) {
    remainder = (remainder + (listRemainders[i] - V0) * weights[i]) % 97;
  }

  return (98 - remainder).toString().padLeft(2, "0");
}