Groovy web console

subscribe to the feed Subscribe
to this
site

Test Tailorsoft

Published 3 weeks ago by Sebastian Montoya
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
import groovy.json.JsonSlurper 

def url_Json = new URL("https://hours.tailorsoft.co/sample.json")
def jason = new JsonSlurper().parse(url_Json)
def orders = jason.orders.items.flatten() 

println "+--------------+---------+------------+";
println "| Product      |  Orders |      Total |";
println "+--------------+---------+------------+";

jason.products.each{
    id = it.id
    Orders = 0
    orders.each{if(it.productId==id){Orders+=1}}
    price = Orders*Double.parseDouble(it.price);

    println("|"+it.name.padRight(14)+"|"+Integer.toString(Orders).padRight(9)+"|"+Double.toString(price).padLeft(12)+"|");
}

println "+--------------+---------+------------+";