Module:Bank value

-- implements Template:Bank value

-- dependencies: Module:ExchangeLite, Module:Addcommas local exg = require('Module:ExchangeLite') local commas = require('Module:Addcommas')._add

local p = {}

local total local tbody

--check if item exists, per Module:Exchange local function exists(item) local noErr, data = pcall( mw.loadData, 'Module:Exchange/' .. item )

if noErr then return '1' end return 0 end

local function gep(item, qty) if exists(item) then return exg.load({args = {item, 'price'}}) * tonumber(qty) else return 0 end end

local function plink(item) return ' ' .. item .. '' end

local function row(item, qty) local p = gep(item, qty) tbody  :tag('tr') :tag('td') :wikitext(plink(item)) :done :tag('td') :css('text-align','right') :wikitext(qty) :done :tag('td') :css('text-align','right') :wikitext(commas(p)) :done :done total = total + p end

p.main = function(frame) local args = frame:getParent.args total = 0 local table = mw.html.create('table') table  :addClass('wikitext') :addClass('sortable') :tag('thead') :tag('tr') :tag('th') :wikitext('Item') :done :tag('th') :wikitext('Quantity') :done :tag('th') :wikitext('Value') :done :done :done tbody = table:tag('tbody') tbody  :tag('tr') :tag('td') :attr('colspan', '2') :wikitext(' Coins') :done :tag('td') :css('text-align','right') :wikitext(commas(tonumber(args.coins))) :done :done total = total + tonumber(args.coins) local i = 1 while args[i] and args[i+1] do       row(args[i], args[i+1]) i = i + 2 end table  :tag('tfoot') :tag('tr') :addClass('sortbottom') :tag('th') :attr('colspan', '2') :wikitext('Total') :done :tag('td') :css('text-align','right') :wikitext(commas(total)) :done :done :done return table end return p