<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */
class Pruefziffer_13 implements IPruefziffer
{
  public static function check($pKtoNr, $pBlz, $pGewichtung = array(), $pPruefZifferStelle = 9)
  {
    $ktoNr = str_pad($pKtoNr, 10, '0', STR_PAD_LEFT);

    $grundNummer = substr($ktoNr, 1, 7);
    if (Pruefziffer_00::check($grundNummer, $pBlz, $pGewichtung, $pPruefZifferStelle)) {
      return true;
    } else {
      if (substr_compare($ktoNr, '00', 1, 2) == 0) {
        $ktoNr = str_pad(substr($ktoNr, 2, 8), 10, '0', STR_PAD_RIGHT);
      }
      $grundNummer = substr($ktoNr, 1, 7);

      return Pruefziffer_00::check($grundNummer, $pBlz, $pGewichtung, $pPruefZifferStelle);
    }
  }
}