Esko Logo Back to Esko Support

Page History

Choose your language for a machine translation:

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Updated by EskoConfluence integration from workflowwiki

 

Description

This article describes how to calculate a Total Price in Project Attributes by adding up Product Prices.

This solution may be used when WebCenter is used as an ordering tool. For example, customers can select products from a library to re-order them. They create a Project, and select their products from a button referring to the Product Library. Each product has a price behind it. These prices need to end up in a Total Price in the Project Attributes.

Procedure

Depending on the number of pieces ordered, the subtotal will be calculated with a simple calculation (number * price per piece). This is done automatically as soon as the user fills in the quantity. So each product will have a subtotal (Attribute: subtotal)

Now we want to have the total of all these subtotals in the Project Attributes, to reflect the total price of the order. There is a fixed cost of 15 euros per order. In case the user decides it is a rush order, the fixed cost is 380 euro.

Following JavaScript can be used to calculate this total:

Code Block
languagejs
var total = 0;
var fixedcost = 15;
var rushorder = 380;
function roundToTwo(num) {    
    return +(Math.round(num + "e+2")  + "e-2");
};
 
for (var doc=0; doc<docatt.length; doc++) {
        total += docatt[doc]['subtotal'];
	}
if (att['Rush order']=="yes") {
	att['total'] = roundToTwo(rushorder+total);
} 
else {
	att['total'] = roundToTwo(fixedcost+total);
}
Article information
Applies to

WebCenter all versions

Created29-Oct-15
Last revised 
AuthorKAMO
Case Number 
Panel
titleContents

Table of Contents
classinline-toc