Module:NHFurnitureCargoQuery

local p = {} local cargo = mw.ext.cargo local getArgs = require('Module:Arguments').getArgs local currency = require("Module:Currency") local availability = require("Module:Availability") local formatnum = require("Module:Formatnum") local sentenceCase = require('Module:SentenceCase').firstToUpper

function p.main(frame) local args        = getArgs(frame) local where       = args['where'] or '' local showVariants = args['show-variants'] or '' local groupBy     = args['group by'] or '' local currency2   = args['show-second-currency'] or '' local limit       = args['limit'] or '' local orderBy     = args['order by'] or '' local offset      = args['offset'] or '' local noImage     = args['no image'] or '' return p.outputFurnitureCargo(where, showVariants, groupBy, currency2, limit, orderBy, offset, noImage) end

function p.outputFurnitureCargo(where, showVariants, groupBy, currency2, limit, orderBy, offset, noImage) local function isEmpty(s) return s == nil or s == '' end local print = '' local disableImage = '' local tables = 'nh_furniture,nh_furniture_variation' local fields = "nh_furniture._pageName=pagename,nh_furniture.en_name=name,nh_furniture.catalog_num=catalognum,nh_furniture_variation.variation=variation,nh_furniture_variation.pattern=pattern,nh_furniture_variation.image=image,nh_furniture.buy1_price=buy1price,nh_furniture.buy1_currency=buy1currency,nh_furniture.buy2_price=buy2price,nh_furniture.buy2_currency=buy2currency,nh_furniture.sell=sell,nh_furniture.availability1=availability1,nh_furniture.availability2=availability2,nh_furniture.availability3=availability3,nh_furniture.theme1=theme1,nh_furniture.theme2=theme2,nh_furniture.function1=function1,nh_furniture.function2=function2,nh_furniture.customizable=customizable,nh_furniture.length=length,nh_furniture.width=width" local args = { join = 'nh_furniture_variation.en_name = nh_furniture.en_name', where = where, groupBy = groupBy, orderBy = orderBy, limit = limit, offset = offset, default = '' }   if not isEmpty(noImage) then disableImage = "yes" end local results = cargo.query( tables, fields, args ) for r = 1, #results do   	local toAppend = '' toAppend = toAppend .. "| data-sort-value=\"" .. results[r].catalognum .. "\" | " if not isEmpty(results[r].catalognum) then toAppend = toAppend .. formatnum.formatNum(results[r].catalognum,"en") else toAppend = toAppend .. "-"   	end toAppend = toAppend .. "\n" toAppend = toAppend .. "| " .. sentenceCase(results[r].name) .. "" if not isEmpty(showVariants) and not isEmpty(results[r].variation) then toAppend = toAppend .. " (".. results[r].variation   		if not isEmpty(results[r].pattern) then    			toAppend = toAppend .. " - " .. results[r].pattern    		end    		toAppend = toAppend .. ")" end toAppend = toAppend .. "\n" toAppend = toAppend .. "| \n" toAppend = toAppend .. "| data-sort-value=\"" .. results[r].buy1price .. "\" | " if not isEmpty(results[r].buy1price) then toAppend = toAppend .. currency.outputCurrency(results[r].buy1currency,results[r].buy1price, , , , , '', disableImage) if not isEmpty(currency2) and not isEmpty(results[r].buy2price) then toAppend = toAppend .. " " .. currency.outputCurrency(results[r].buy2currency,results[r].buy2price, , , , , '', disableImage) end else toAppend = toAppend .. "Not for sale" end toAppend = toAppend .. "\n" toAppend = toAppend .. "| data-sort-value=\"" .. results[r].sell .. "\" | " if not isEmpty(results[r].sell) then toAppend = toAppend .. currency.outputCurrency("Bells",results[r].sell, , , , , '', disableImage) else toAppend = toAppend .. "Cannot be sold" end toAppend = toAppend .. "\n" toAppend = toAppend .. "| " .. availability.outputAvailability(results[r].availability1, , , , , , , '', disableImage) if not isEmpty(results[r].availability2) then toAppend = toAppend .. " " .. availability.outputAvailability(results[r].availability2, , , , , , , '', disableImage) end if not isEmpty(results[r].availability3) then toAppend = toAppend .. " " .. availability.outputAvailability(results[r].availability3) end toAppend = toAppend .. "\n" toAppend = toAppend .. "| "   	if not isEmpty(results[r].theme1) then toAppend = toAppend .. results[r].theme1 if not isEmpty(results[r].theme2) then toAppend = toAppend .. " / " .. results[r].theme2 end else toAppend = toAppend .. "-"   	end toAppend = toAppend .. "\n" toAppend = toAppend .. "| "   	if not isEmpty(results[r].function1) then toAppend = toAppend .. results[r].function1 if not isEmpty(results[r].function2) then toAppend = toAppend .. " / " .. results[r].function2 end else toAppend = toAppend .. "-"   	end toAppend = toAppend .. "\n" toAppend = toAppend .. "| "   	if not isEmpty(results[r].customizable) and results[r].customizable == 1 then toAppend = toAppend .. "Yes" else toAppend = toAppend .. "No" end toAppend = toAppend .. "\n" if not isEmpty(disableImage) then toAppend = toAppend .. "| " .. formatnum.formatNum(results[r].length, "en", 1) .. "×" .. formatnum.formatNum(results[r].width, "en", 1) .. "\n" else toAppend = toAppend .. "| \n" end print = print .. toAppend .. "|-\n" end return print end

return p