Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Calculates shipping cost to ship X grams with EMS.
- * @param {Range} range Range or cell containing the shipping weights.
- * @param {Number} firstCost Cost of first interval. (Default 20.91)
- * @param {Number} additionalCost Cost of additional intervals. (Default 6.31)
- * @param {Number} interval Interval size. (Default 500)
- * @return Shipping cost in USD.
- * @customfunction
- */
- function EMS_SHIPPING(range, firstCost, additionalCost, interval) {
- firstCost = Number(firstCost);
- if(isNaN(firstCost)) {
- firstCost = 20.91;
- }
- additionalCost = Number(additionalCost);
- if(isNaN(additionalCost)) {
- additionalCost = 6.31;
- }
- interval = Number(interval);
- if(isNaN(interval)) {
- interval = 500;
- }
- var totalWeight = 0;
- if(typeof range == 'number') {
- totalWeight = range;
- } else {
- for(var i = 0; i < range.length; i++) {
- totalWeight += parseFloat(range[i]);
- }
- }
- var totalCost = 0;
- var doneFirst = false;
- while(totalWeight > 0) {
- if(!doneFirst)
- totalCost += firstCost;
- else
- totalCost += additionalCost;
- totalWeight -= interval;
- doneFirst = true;
- }
- return totalCost;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement