Skip to content

Instantly share code, notes, and snippets.

@VirtuosiMedia
Created April 6, 2016 21:19
Show Gist options
  • Save VirtuosiMedia/951a4716dc90c08bad1d78fa09327f1e to your computer and use it in GitHub Desktop.
Save VirtuosiMedia/951a4716dc90c08bad1d78fa09327f1e to your computer and use it in GitHub Desktop.
/**
* Gets a sorted purchase order goods list for the selected category of goods.
* @return {array} The sorted list of goods objects.
*/
getPurchaseGoods: function(){
//Get all goods that should be rendered
var trade = jg.calculate.trade;
var holding = jg.data.state.holding;
var resources = _.container(_.language.getDataSet('resources'));
var components = _.container(_.language.getDataSet('items'));
var orders = jg.data.holdings[holding].data.economic.trade.orders;
var category = jg.data.state.commercial.trade.purchaseCategory;
var goods = _.list();
if ((category === 'resources') || (category === 'all')){
resources.each(function(resource){
goods.push({
'id': resource.id,
'name': resource.name,
'description': resource.description,
'category': 'resource',
'average': trade.getAverageGoodSalesPrice(holding, resource.id),
'price': trade.getGoodOrderPrice(holding, resource.id),
'quantity': trade.getGoodOrderQuantity(holding, resource.id),
'orderType': trade.getGoodOrderType(holding, resource.id),
'action': trade.getGoodOrderAction(holding, resource.id)
});
});
}
if (category !== 'resources'){
components.each(function(component){
if ((category === component.category) || (category === 'all')){
goods.push({
'id': component.id,
'name': component.name,
'description': component.description,
'category': 'component',
'average': trade.getAverageGoodSalesPrice(holding, component.id),
'price': trade.getGoodOrderPrice(holding, component.id),
'quantity': trade.getGoodOrderQuantity(holding, component.id),
'orderType': trade.getGoodOrderType(holding, component.id),
'action': trade.getGoodOrderAction(holding, component.id)
});
}
});
}
goods.sortByKey(jg.data.state.commercial.trade.purchaseTableSort, (jg.data.state.commercial.trade.purchaseTableSortDirection === 'desc'));
return goods;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment