Skip to content

Instantly share code, notes, and snippets.

@dieffrei
Created March 9, 2015 21:02
Show Gist options
  • Save dieffrei/df23775c8fc3eb1932b0 to your computer and use it in GitHub Desktop.
Save dieffrei/df23775c8fc3eb1932b0 to your computer and use it in GitHub Desktop.
$scope.getOrderMargin = function() {
var result = 0.0;
var costSUM = 0.00;
var totalValue = 0.00;
_.each($scope.sharedModel.order.OpportunityLineItems.all(), function(it) {
if (it.hasProduct() && (!it.hasSpecialPrice() && !it.hasResidualPrice())) {
totalValue = totalValue + it.getTotalValue();
costSUM = costSUM + ((it.product2.getFreightPickUpCost() + it.product2.getListCost2()) * it.Quantity)
}
});
//avoid division by zero
if (totalValue > 0) {
result = 100 * (1 - (costSUM / totalValue));
}
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment