Views: 953 (Data available since 06.02.2017)

Sometimes it may be necessary to sum up two variables in a business process during its execution, for example, if you analyze the costs and income. Let us consider the following example: how to recalculate the cost of a programmerís work.

Set the parameters and variables in a business process template:

  • Business process parameter: {=Template:integrator_USD} - programmerís work cost in USD;
  • Business process variable {=Variable:kurs_usd} - USD/EUR rate for recalculation.

Use the following code in the activity PHP code:

// Obtain current business process
$rootActivity = $this->GetRootActivity(); 
// Obtain the value of a business process variable {=Variable:kurs_usd}
$kursUSD = $rootActivity->GetVariable("kurs_usd"); 
// Obtain the value of a business process parameter {=Template:integrator_USD}
$integrator = $rootActivity->integrator_USD;
// Recalculate currency
$integrator = $integrator*$kursUSD;
// Set the value of the business process parameter {=Template:integrator_USD}
$rootActivity->integrator_USD = $integrator;
// Set the value of a business process variable {=Template:ttl}
// You can make calculations and generally do whatever you want with business process variables and parameters
$rootActivity->SetVariable("ttl",
   'The lowest price:'.number_format($min_ttl,0,',',' ')." EUR\n".
   'Profit from the minimum price:'.number_format($min_ttl_plus,0,',',' ')." EUR\n".
   'Tax:'.number_format($min_ttl*$nalog,0,',',' ')." EUR\n\n".
   'Average price:'.number_format($ttl,0,',',' ')." EUR\n".
   'Profit from the average price:'.number_format($ttl_plus,0,',',' ')." EUR\n".
   'Tax:'.number_format($ttl*$nalog,0,',',' ')." EUR\n"
);


Courses developed by «Bitrix», Inc.