Module:Shop: Difference between revisions

Further fixes & support for itemCharges contents
(Remove erroneously pasted code)
(Further fixes & support for itemCharges contents)
Line 268: Line 268:
local containArray = {}
local containArray = {}
local GPTotal = 0
local GPTotal = 0
if purchase.contains.items ~= nil and not Shared.tableIsEmpty(purchase.contains.items) then
if purchase.contains ~= nil then
if not asList then
if purchase.contains.items ~= nil and not Shared.tableIsEmpty(purchase.contains.items) then
table.insert(containArray, '{| class="wikitable sortable stickyHeader"')
if not asList then
table.insert(containArray, '|- class="headerRow-0"')
table.insert(containArray, '{| class="wikitable sortable stickyHeader"')
table.insert(containArray, '! colspan="2" | Item !! Quantity !! Price')
table.insert(containArray, '|- class="headerRow-0"')
table.insert(containArray, '! colspan="2" | Item !! Quantity !! Price')
end
for i, itemLine in ipairs(purchase.contains.items) do
local item = Items.getItemByID(itemLine.id)
            local itemQty = itemLine.quantity
if asList then
table.insert(containArray, Icons.Icon({item.name, type='item', qty=itemQty}))
else
local GPVal = item.sellsFor * itemQty
GPTotal = GPTotal + GPVal
table.insert(containArray, '|-\r\n| style="min-width:25px"| ' .. Icons.Icon({item.name, type='item', notext=true, size='25'}))
table.insert(containArray, '| ' .. Icons.Icon({item.name, type='item', noicon=true}) .. '\r\n| data-sort-value="' .. itemQty .. '" style="text-align:right" | ' .. Shared.formatnum(itemQty))
table.insert(containArray, '| data-sort-value="' .. GPVal .. '"| ' .. Icons.GP(GPVal))
end
end
end
end
for i, itemLine in ipairs(purchase.contains.items) do
if purchase.contains.itemCharges ~= nil and purchase.contains.itemCharges.quantity > 0 then
local item = Items.getItemByID(itemLine.id)
        local gloveItem = Items.getItemByID(purchase.contains.itemCharges.id)
            local itemQty = itemLine.quantity
        local chargeQty = purchase.contains.itemCharges.quantity
if asList then
        if gloveItem ~= nil then
table.insert(containArray, Icons.Icon({item.name, type='item', qty=itemQty}))
            if asList then
else
                table.insert(containArray, '+'..Shared.formatnum(chargeQty)..' '..Icons.Icon({gloveItem.name, type='item'})..' Charges')
local GPVal = item.sellsFor * itemQty
            else
GPTotal = GPTotal + GPVal
                table.insert(containArray, '|-\r\n| style="min-width:25px"| ' .. Icons.Icon({gloveItem.name, type='item', notext=true, size='25'}))
table.insert(containArray, '|-\r\n| style="min-width:25px"| ' .. Icons.Icon({item.name, type='item', notext=true, size='25'}))
                table.insert(containArray, '| ' .. Icons.Icon({gloveItem.name, type='item', noicon=true}) .. ' Charges\r\n| data-sort-value="' .. chargeQty .. '" style="text-align:right" | ' .. Shared.formatnum(chargeQty))
table.insert(containArray, '| ' .. Icons.Icon({item.name, type='item', noicon=true}) .. '\r\n| data-sort-value="' .. itemQty .. '" style="text-align:right" | ' .. Shared.formatnum(itemQty))
                table.insert(containArray, '| data-sort-value="0"| ' .. Icons.GP(0))
table.insert(containArray, '| data-sort-value="' .. GPVal .. '"| ' .. Icons.GP(GPVal))
            end
end
        end
end
end
end
if purchase.itemCharges ~= nil and purchase.itemCharges.quantity > 0 then
        local gloveItem = Items.getItemByID(purchase.itemCharges.id)
        local chargeQty = purchase.itemCharges.quantity
        if gloveItem ~= nil then
            if asList then
                table.insert(containArray, '+'..Shared.formatnum(chargeQty)..' '..Icons.Icon({gloveItem.name, type='item'})..' Charges')
            else
                table.insert(containArray, '|-\r\n| style="min-width:25px"| ' .. Icons.Icon({gloveItem.name, type='item', notext=true, size='25'}))
                table.insert(containArray, '| ' .. Icons.Icon({gloveItem.name, type='item', noicon=true}) .. ' Charges\r\n| data-sort-value="' .. chargeQty .. '" style="text-align:right" | ' .. Shared.formatnum(chargeQty))
                table.insert(containArray, '| data-sort-value="0"| ' .. Icons.GP(0))
            end
        end
end
end
if not asList and not Shared.tableIsEmpty(containArray) then
if not asList and not Shared.tableIsEmpty(containArray) then
Line 623: Line 625:


for i, purchase in ipairs(purchaseArray) do
for i, purchase in ipairs(purchaseArray) do
table.insert(tableArray, p._getPurchaseTable(purchase))
table.insert(tableArray, p._getPurchaseTable(purchase.purchase))
end
end