2017-01-26 13:27:30 +01:00
|
|
|
class BankTransactionReference
|
|
|
|
# parses a string from a bank transaction field
|
|
|
|
def self.parse(data)
|
2023-01-06 16:12:41 +01:00
|
|
|
m = /(^|[^\w.])FS(?<group>\d+)(\.(?<user>\d+))?(?<parts>([A-Za-z]+\d+(\.\d+)?)+)([^\w.]|$)/.match(data)
|
2017-01-26 13:27:30 +01:00
|
|
|
return unless m
|
|
|
|
|
|
|
|
parts = {}
|
|
|
|
m[:parts].scan(/([A-Za-z]+)(\d+(\.\d+)?)/) do |category, value|
|
|
|
|
value = value.to_f
|
|
|
|
value += parts[category] if parts[category]
|
|
|
|
parts[category] = value
|
|
|
|
end
|
|
|
|
|
2021-02-08 03:39:47 +01:00
|
|
|
ret = { group: m[:group].to_i, parts: parts }
|
|
|
|
ret[:user] = m[:user].to_i if m[:user]
|
2023-01-06 16:12:41 +01:00
|
|
|
ret
|
2017-01-26 13:27:30 +01:00
|
|
|
end
|
|
|
|
|
2019-11-11 12:09:18 +01:00
|
|
|
def self.js_code_for_user(user)
|
|
|
|
%{
|
|
|
|
function(items) {
|
|
|
|
var ret = "FS#{user.ordergroup.id}.#{user.id}";
|
|
|
|
for (var key in items) {
|
|
|
|
if (items.hasOwnProperty(key)) {
|
|
|
|
ret += key + items[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
2017-01-26 13:27:30 +01:00
|
|
|
end
|