Checks the number valiaty for the Bahia state
970125
def start(st_reg_number):
    """"""

    weights_second_digit = range(len(st_reg_number)-1, 1, -1)
    weights_first_digit = range(len(st_reg_number), 1, -1)
    second_digits = st_reg_number[-1:]
    number_state_registration = st_reg_number[0:len(st_reg_number) - 2]
    digits_state_registration = st_reg_number[-2:]
    sum_second_digit = 0
    sum_first_digit = 0

    if len(st_reg_number) != 8 and len(st_reg_number) != 9:
        return False

    if st_reg_number[-8] in ['0', '1', '2', '3', '4', '5', '8']:

        for i in weights_second_digit:

            sum_second_digit = sum_second_digit + i*int(st_reg_number[-i-1])

        second_digits_check = 10 - (sum_second_digit % 10)

        if sum_second_digit % 10 == 0 or sum_second_digit % 11 == 1:

            second_digits_check = '0'

        if str(second_digits_check) != second_digits:

            return False

        digit_two = number_state_registration + str(second_digits_check)

        for i in weights_first_digit:

            sum_first_digit = sum_first_digit + i*int(digit_two[-i+1])

        first_digits_check = 10 - (sum_first_digit % 10)

        if sum_first_digit % 10 == 0 or sum_first_digit % 10 == 1:
            first_digits_check = '0'

        digits_calculated = str(first_digits_check) + str(second_digits_check)

        return digits_calculated == digits_state_registration

    elif st_reg_number[-8] in ['6', '7', '9']:

        for i in weights_second_digit:

            sum_second_digit = sum_second_digit + i*int(st_reg_number[-i-1])

        second_digits_check = 11 - (sum_second_digit % 11)

        if sum_second_digit % 11 == 0 or sum_second_digit % 11 == 1:
            second_digits_check = '0'

        if str(second_digits_check) != second_digits:
            return False

        digit_two = number_state_registration + str(second_digits_check)

        for i in weights_first_digit:

            sum_first_digit = sum_first_digit + i*int(digit_two[-i+1])

        first_digits_check = 11 - (sum_first_digit % 11)

        if sum_first_digit % 11 == 0 or sum_first_digit % 11 == 1:
            first_digits_check = '0'
        digits_calculated = str(first_digits_check) + str(second_digits_check)
        return digits_calculated == digits_state_registration
1156436
def start(st_reg_number):
    """"""

    divisor = 11

    verificador_one = int(st_reg_number[len(st_reg_number)-4])
    verificador_two = int(st_reg_number[len(st_reg_number)-1])
    weights_first = [1, 3, 4, 5, 6, 7, 8, 10]
    weights_secund = [3, 2, 10, 9, 8, 7, 6, 5, 4, 3, 2]

    if len(st_reg_number) > 13:
        return False

    if len(st_reg_number) < 12:
        return False

    if len(st_reg_number) == 12:
        sum_total = 0
        for i in range(len(st_reg_number)-4):
            sum_total = sum_total + int(st_reg_number[i]) * weights_first[i]

        rest_division = sum_total % divisor
        digit_first = rest_division

        if rest_division == 10:
            digit_first = 0

        num = 0
        mult = 10000000000
        for i in range(len(st_reg_number)-1):
            if i == 8:
                num = num + digit_first * mult
            else:
                num = num + int(st_reg_number[i]) * mult
            mult = mult/10

        if num < 10000000000:
            new_st = str('0') + str(num)
        else:
            new_st = str(num)

        sum_total = 0
        for i in range(len(new_st)):
            sum_total = sum_total + int(new_st[i]) * weights_secund[i]

        rest_division = sum_total % divisor
        digit_secund = rest_division

        if rest_division == 10:
            digit_secund = 0

        if digit_secund == verificador_two and digit_first == verificador_one:
            return True
        else:
            return False

    else:
        if st_reg_number[0] != "P":
            return False

        sum_total = 0
        for i in range(1, 9):
            sum_total = sum_total + int(st_reg_number[i]) * weights_first[i-1]

        digit = sum_total % divisor

        if digit == 10:
            digit = 0

        return digit == int(st_reg_number[len(st_reg_number)-4])
321921
public function getCellPhoneNumber()
    {
        $mobil     = null;
        $mobilsRaw = $this->getFlexiData($this->getApiURL(),
            ['detail' => 'custom:id,mobil,kontakty(primarni,mobil)', 'relations' => 'kontakty']);
        if (is_array($mobilsRaw)) {
            $mobils = $mobilsRaw[0];
            if (array_key_exists('mobil', $mobils) && strlen(trim($mobils['mobil']))) {
                $mobil = $mobils['mobil'];
            }
            if (array_key_exists('kontakty', $mobils) && !empty($mobils['kontakty'])) {
                foreach ($mobils['kontakty'] as $kontakt) {
                    if (($kontakt['primarni'] == 'true') && strlen(trim($kontakt['mobil']))) {
                        $mobil = $kontakt['mobil'];
                        break;
                    }
                }
            }
        }
        return $mobil;
    }
277585
protected function validOrderNumber($number = null)
    {
        $number = (isset($number)) ? $number : $this->Ref;

        $existing = Estimate::get()
            ->filter(
                [
                    "ClassName" => self::class,
                    "Ref" => $number
                ]
            )->first();

        return !($existing);
    }
2679
function setStateAndCountry(&$info) {
    global $db, $messageStack;
    switch ($info['country']['iso_code_2']) {
      case 'AU':
      case 'US':
      case 'CA':
      // Paypal only accepts two character state/province codes for some countries.
      if (strlen($info['state']) > 2) {
        $sql = "SELECT zone_code FROM " . TABLE_ZONES . " WHERE zone_name = :zoneName";
        $sql = $db->bindVars($sql, ':zoneName', $info['state'], 'string');
        $state = $db->Execute($sql);
        if (!$state->EOF) {
          $info['state'] = $state->fields['zone_code'];
        } else {
          $messageStack->add_session('header', MODULE_PAYMENT_PAYPALWPP_TEXT_STATE_ERROR, 'error');
          $this->terminateEC(MODULE_PAYMENT_PAYPALWPP_TEXT_STATE_ERROR);
        }
      }
      break;
      case 'AT':
      case 'BE':
      case 'FR':
      case 'DE':
      case 'CH':
      $info['state'] = '';
      break;
      case 'GB':
      break;
      default:
      $info['state'] = '';
    }
  }
1000318
function checkNum(nums, min, max){
  if(nums == null)
    return false;

  if(nums == -1)
    return true;

  for(let i = 0; i < nums.length; i++){
    if(nums[i]<min || nums[i]>max)
      return false;
  }

  return true;
}
1270010
protected function assertChecksum($number)
    {
        $map = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 2, 4, 6, 8, 1, 3, 5, 7, 9);
        $sum = 0;
        $last = strlen($number) - 1;
        for ($i = 0; $i <= $last; $i++) {
            $sum += $map[$number[$last - $i] + ($i & 1) * 10];
        }

        return ($sum % 10 == 0);
    }
1022128
protected function gerarNossoNumero()
    {
        $convenio = $this->getConvenio();
        $numero_boleto = $this->getNumero();
        switch (strlen($convenio)) {
        case 4:
            $numero = Util::numberFormatGeral($convenio, 4) . Util::numberFormatGeral($numero_boleto, 7);
            break;
        case 6:
            if (in_array($this->getCarteira(), ['16', '18']) && $this->getVariacaoCarteira() == 17) {
                $numero = Util::numberFormatGeral($numero_boleto, 17);
            } else {
                $numero = Util::numberFormatGeral($convenio, 6) . Util::numberFormatGeral($numero_boleto, 5);
            }
            break;
        case 7:
            $numero = Util::numberFormatGeral($convenio, 7) . Util::numberFormatGeral($numero_boleto, 10);
            break;
        default:
            throw new \Exception('O código do convênio precisa ter 4, 6 ou 7 dígitos!');
        }
        return $numero;
    }
171657
public function phone_number_old_and_new($my_number = '', $my_format = NULL)
    {
        if (empty($my_number)) {
            return NULL;
        }
        try {
            $old_number = $this->phone_number_convert($my_number, 'old', $my_format);
            $new_number = $this->phone_number_convert($my_number, 'new', $my_format);
            if ($old_number != $new_number) {
                // Nếu sau khi so sánh convert số cũ và số mới khác nhau -> trả về 1 array
                $result = [
                    $old_number,
                    $new_number
                ];
                $this->_debug->info(__FUNCTION__, 'Result: ' . $result);

                return $result;
            } else {
                // Nếu không khác, trả về string
                $result = $this->format($my_number, $my_format);
                $this->_debug->info(__FUNCTION__, 'Result: ' . $result);

                return $result;
            }
        }
        catch (\Exception $e) {
            $message = 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage();
            $this->_debug->error(__FUNCTION__, $message);

            return $my_number;
        }
    }
363951
def has_next(self):
        """"""
        if self._state == PhoneNumberMatcher._NOT_READY:
            self._last_match = self._find(self._search_index)
            if self._last_match is None:
                self._state = PhoneNumberMatcher._DONE
            else:
                self._search_index = self._last_match.end
                self._state = PhoneNumberMatcher._READY
        return (self._state == PhoneNumberMatcher._READY)
395567
def start(st_reg_number):
    """"""
    divisor = 11

    if len(st_reg_number) > 9:
        return False

    if len(st_reg_number) < 9:
        return False

    sum_total = 0
    peso = 8
    for i in range(len(st_reg_number)-2):
        sum_total = sum_total + int(st_reg_number[i]) * peso
        peso = peso - 1

        rest_division = sum_total % divisor
        digit_first = divisor - rest_division

    if rest_division < 2:
        digit_first = 0

    if rest_division > 1:
        digit_first = 11 - rest_division

    num = 0
    peso = 9
    mult = 10000000
    for i in range(len(st_reg_number)-2):
        num = num + int(st_reg_number[i]) * mult
        mult = mult/10

    num = num + digit_first

    new_st = str(num)
    sum_total = 0
    peso = 9
    for i in range(len(new_st)-1):
        sum_total = sum_total + int(new_st[i]) * peso
        peso = peso - 1

    rest_division = sum_total % divisor

    if rest_division < 2:
        digit_secund = 0

    if rest_division > 1:
        digit_secund = divisor - rest_division

    if digit_secund == int(st_reg_number[len(st_reg_number)-1]) and digit_first == int(st_reg_number[len(st_reg_number)-2]):
        return True
    else:
        return False
76777
public function number() {
        $this->check_role = 'number';
        $result = is_numeric($this->value);
        $this->checkResult($result);
        return $this;
    }
1016790
def fetch_last_receipt_number(self, point_of_sales, receipt_type):
        """"""
        client = clients.get_client('wsfe', point_of_sales.owner.is_sandboxed)
        response_xml = client.service.FECompUltimoAutorizado(
            serializers.serialize_ticket(
                point_of_sales.owner.get_or_create_ticket('wsfe')
            ),
            point_of_sales.number,
            receipt_type.code,
        )
        check_response(response_xml)

        # TODO XXX: Error handling
        # (FERecuperaLastCbteResponse){
        #    PtoVta = 0
        #    CbteTipo = 0
        #    CbteNro = 0
        #    Errors =
        #       (ArrayOfErr){
        #          Err[] =
        #             (Err){
        #                Code = 601
        #                Msg = "CUIT representada no incluida en Token"
        #             },
        #       }
        #  }

        return response_xml.CbteNro
992184
protected function calculateChecksum() {
        // Forming a new number
        // If the original number is even, we take all even position
        // If the original number is odd, we take all odd position
        // 123456 = 246
        // 12345 = 135
        // Multiply by 2
        // Add up all the digit in the result (270 : 2+7+0)
        // Add up other digit not used.
        // 10 - (? Modulo 10). If result = 10, change to 0
        $last_text = $this->text;
        $this->checksumValue = array();
        for ($i = 0; $i < $this->checksum; $i++) {
            $new_text = '';
            $new_number = 0;
            $c = strlen($last_text);
            if ($c % 2 === 0) { // Even
                $starting = 1;
            } else {
                $starting = 0;
            }

            for ($j = $starting; $j < $c; $j += 2) {
                $new_text .= $last_text[$j];
            }

            $new_text = strval(intval($new_text) * 2);
            $c2 = strlen($new_text);
            for ($j = 0; $j < $c2; $j++) {
                $new_number += intval($new_text[$j]);
            }

            for ($j = ($starting === 0) ? 1 : 0; $j < $c; $j += 2) {
                $new_number += intval($last_text[$j]);
            }

            $new_number = (10 - $new_number % 10) % 10;
            $this->checksumValue[] = $new_number;
            $last_text .= $new_number;
        }
    }
1010145
function checkNumber(i) {
  if (i >= tokensLength) return 0;

  if (tokens[i].number_l) return tokens[i].number_l;

  // `10`:
  if (i < tokensLength && tokens[i].type === TokenType.DecimalNumber &&
      (!tokens[i + 1] ||
      (tokens[i + 1] && tokens[i + 1].type !== TokenType.FullStop))) {
    tokens[i].number_l = 1;
    return 1;
  }

  // `10.`:
  if (i < tokensLength &&
      tokens[i].type === TokenType.DecimalNumber &&
      tokens[i + 1] && tokens[i + 1].type === TokenType.FullStop &&
      (!tokens[i + 2] || (tokens[i + 2].type !== TokenType.DecimalNumber))) {
    tokens[i].number_l = 2;
    return 2;
  }

  // `.10`:
  if (i < tokensLength &&
      tokens[i].type === TokenType.FullStop &&
      tokens[i + 1].type === TokenType.DecimalNumber) {
    tokens[i].number_l = 2;
    return 2;
  }

  // `10.10`:
  if (i < tokensLength &&
      tokens[i].type === TokenType.DecimalNumber &&
      tokens[i + 1] && tokens[i + 1].type === TokenType.FullStop &&
      tokens[i + 2] && tokens[i + 2].type === TokenType.DecimalNumber) {
    tokens[i].number_l = 3;
    return 3;
  }

  return 0;
}
976905
protected function gerarNossoNumero()
    {
        return Util::numberFormatGeral($this->getNumero(), 11)
            . CalculoDV::bradescoNossoNumero($this->getCarteira(), $this->getNumero());
    }
349390
public function info() {
        /**
         * avatar	用户头像	String	如果没有数据的时候不会返回该数据，请做好容错	可空	https://tfsimg.alipay.com/images/partner/T1k0xiXXRnXXXXXXXX
        nick_name	用户昵称	String	如果没有数据的时候不会返回该数据，请做好容错	可空	张三
        province	省份	String	用户注册时填写的省份 如果没有数据的时候不会返回该数据，请做好容错	可空	浙江省
        city	城市	String	用户注册时填写的城市， 如果没有数据的时候不会返回该数据，请做好容错	可空	杭州
        gender	用户性别	String	M为男性，F为女性， 如果没有数据的时候不会返回该数据，请做好容错	可空	M
        user_type_value	用户类型	String	（1/2），1代表公司账户；2代表个人账户	不可空	1
        is_licence_auth	是否经过营业执照认证	String	T为通过营业执照认证，F为没有通过	不可空	T
        is_certified	是否通过实名认证	String	T是通过；F是没有实名认证	不可空	F
        is_certify_grade_a	是否A类认证	String	T表示是A类认证，F表示非A类认证，A类认证用户是指上传过身份证照片并且通过审核的支付宝用户	不可空	T
        is_student_certified	是否是学生	String	T表示是学生，F表示不是学生	不可空	T
        is_bank_auth	是否经过银行卡认证	String	T为经过银行卡认证，F为未经过银行卡认证	不可空	T
        is_mobile_auth	是否经过手机认证	String	T为经过手机认证，F为未经过手机认证	不可空	T
        alipay_user_id	当前用户的userId	String	支付宝用户的userId	不可空	2088411964574197
        user_id	已废弃，请勿使用	String	已废弃，请勿使用	不可空	已废弃，请勿使用
        user_status	用户状态（Q/T/B/W）	String	Q代表快速注册用户；T代表已认证用户；B代表被冻结账户；W代表已注册，未激活的账户	不可空	T
        is_id_auth	是否身份证认证	String	T为是身份证认证，F为非身份证认证	不可空	T
         */
        $user = (new OAuth())->info($this->get('access_token'));
        if (!is_array($user) || $user['code'] != 10000) {
            return false;
        }
        $user['username'] = $user['nick_name'];
        $user['sex'] = $user['gender'];
        $this->set($user);
        return $user;
    }