Правка iban-генератора

master
Valkov Dmitry 2 years ago
parent eb7bd0067a
commit 85901209dd
  1. 2
      manifest.json
  2. 74
      popup/src/classes/Service/Generators/IbanGenerator.ts

@ -27,7 +27,7 @@
"manifest_version": 2, "manifest_version": 2,
"permissions": [ "tabs", "contextMenus", "\u003Call_urls>", "storage" ], "permissions": [ "tabs", "contextMenus", "\u003Call_urls>", "storage" ],
"short_name": "SVEAK helper", "short_name": "SVEAK helper",
"version": "1.0.0", "version": "1.0.1",
"commands": { "commands": {
"_execute_browser_action": { "_execute_browser_action": {
"suggested_key": { "suggested_key": {

@ -2,16 +2,16 @@ import { Country } from '@/classes/Enum/Country'
export class IbanGenerator { export class IbanGenerator {
generate (country: Country) { generate (country: Country) {
const t = this.getBankAccount(country) const shortBankAccount = this.getBankAccount(country)
const n = this.getNationalCheckDigit(t) const bankCode = this.getBankCode(country)
const r = this.getBankCode(country) const estonianCheckDigit = this.getEstonianCheckDigit(bankCode + shortBankAccount)
switch (country) { switch (country) {
case Country.ESTONIA: case Country.ESTONIA:
return country.toUpperCase() + this.getIbanCheckDigits(r + t + n + '141400') + r + t + n return country.toUpperCase() + this.getIbanCheckDigits(bankCode + shortBankAccount + estonianCheckDigit + '141400') + bankCode + shortBankAccount + estonianCheckDigit
case Country.LITHUANIA: case Country.LITHUANIA:
return country.toUpperCase() + this.getIbanCheckDigits(r + t + '212900') + r + t return country.toUpperCase() + this.getIbanCheckDigits(bankCode + shortBankAccount + '212900') + bankCode + shortBankAccount
default: default:
return country.toUpperCase() + this.getIbanCheckDigits(r + t + '252100') + r + t return country.toUpperCase() + this.getIbanCheckDigits(bankCode + shortBankAccount + '252100') + bankCode + shortBankAccount
} }
} }
@ -26,36 +26,50 @@ export class IbanGenerator {
return t + String(i - (o % i)).padStart(2, '0') return t + String(i - (o % i)).padStart(2, '0')
} }
getNationalCheckDigit (e: string) { /**
const t = [7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7] *
const n = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] * @param bban c 5 знака 16 символов
let r = 0 * @return одну цифру
const i = e.length */
let o = 18 getEstonianCheckDigit (bban: string) {
for (let a = i - 1; a > -1; a--) { const toCheck = bban.substring(2, 15)
n[o] = t[o] * +e[a] const weights = [7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7]
o--
}
o = 18
for (let a = i - 1; a > -1; a--) {
r -= -n[o]
o--
}
return String(r % 10 !== 0 ? 10 - r % 10 : 0) let sum = 0
for (let index = 0; index < toCheck.length; index++) {
sum += parseInt(toCheck.charAt(index), 10) * weights[index]
} }
const remainder = sum % 10
getBankCode (e: Country) { return remainder === 0 ? 0 : 10 - remainder
const t = ['16000003', '11602231', '10301612', '18900002', '15002240', '19401018', '19101152'] };
const n = ['2200', '1010', '3300', '7700', '1700', '4204']
const r = ['20900', '72900', '74000', '40100', '21200', '72300', '21700', '21400', '70440', '71800', '73000'] getBankCode (country: Country) {
switch (e) { const plBankCodes = [
'16000003', // (BNPPL Centrala) BNP PARIBAS BANK POLSKA SA Centrala
'11602231', // Bank Millennium SA Bankowy Punkt Rozlicze Nr 4
'10301612', // BH Regionalne Centrum Rozliczeń
'18900002', // HYPO Centrala
'15002240', // KBSA O. w Ełku
'19401018', // CABP F. nr 3 we Wrocławiu
'19101152'
]
const eeBankCodes = [
'2200', // Swedbank
'1010', // SEB
'3300', // Danske Bank A/S Eesti filiaal (Sampo Pank)
'7700', // LHV Pank
'1700', // Luminor
'4204' // COOP Bank
]
const ltBankCodes = ['20900', '72900', '74000', '40100', '21200', '72300', '21700', '21400', '70440', '71800', '73000']
switch (country) {
case Country.POLAND: case Country.POLAND:
return t[Math.floor(Math.random() * t.length)] return plBankCodes[Math.floor(Math.random() * plBankCodes.length)]
case Country.ESTONIA: case Country.ESTONIA:
return n[Math.floor(Math.random() * n.length)] return eeBankCodes[Math.floor(Math.random() * eeBankCodes.length)]
default: default:
return r[Math.floor(Math.random() * r.length)] return ltBankCodes[Math.floor(Math.random() * ltBankCodes.length)]
} }
} }

Loading…
Cancel
Save