Multiple product calculation

From All n One's bxp software Wixi

Jump to: navigation, search

1 Description

    This demo will use the example of two newspapers with different prices based on the day of the week.
    If a sales rep goes to the client the client will be able to select the newspaper issues that he/she wants. The code will also calculate the weekly cost of the combination
    of the issues that the client wants to purchase.


2 Create the Variables

var tempCost = 0;

var int_times=new Array();

int_times[0]=0;

int_times[1]=0;

int_times[2]=0;

int_times[3]=0;

int_times[4]=0;

int_times[5]=0;


var int_star=new Array();

int_star[0]=0;

int_star[1]=0;

int_star[2]=0;

int_star[3]=0;

int_star[4]=0;

int_star[5]=0;


       This creates two arrays for the two newspapers with the ability to store the price for six days
       e.g. if the client want the Times only on a Monday, the array will look like this
       
       int_times[0]=1.90; And the rest of the array will be all set to zero

3 Getting the selected values from the Drop down lists

var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Times Monday issue

var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Times Tuesday issue

var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Times Wednesday issue

var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Times Thursday issue

var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Times Friday issue

var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Times Saturday issue

var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Star Monday issue

var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Star Tuesday issue

var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Star Wednesday issue

var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Star Thursday issue

var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Star Friday issue

var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Star sat



     This is getting the values that are associated with the the drop down lists in the campaign 
     To adapt this to a new campaign where it says 'strCDA_X_field_0_X ' simply swap the 'X' for the numbers associated fields in your campaign

4 Calculating the Cost of the combinations of the products selected

var temp_Times=int_times[0]+int_times[1]+int_times[2]+int_times[3]+int_times[4]+int_times[5];

        Adds up the values of the selected issues that the client wants for the Times newspaper


var temp_Star=int_star[0]+int_star[1]+int_star[2]+int_star[3]+int_star[4]+int_star[5];

      Adds up the values of the selected issues that the client wants for the Star newspaper

tempCost=temp_Times+temp_Star;

     Combines the value of the times and the star to get a total cost

tempCost=tempCost.toFixed(2);

      This line rounds the value to two decimal places to avoid a total value of 1.569541 and rounds it to 1.57

document.getElementById('strCDA_X_field_0_X').value=tempCost;

       This line then adds the total amount to the pre-selected field that you want the total price to be inserted into.
      To adapt this to a new campaign where it says 'strCDA_X_field_0_X ' simply swap the 'X' for the numbers associated fields in your campaign