/**
  * @param array $tree
  * @param array $orders
  * @param array $params configuration parameters ordered desc (from up to down)
  * @param array $percents
  *
  * @return array
  */
 public function calc($tree, $orders, $params, $percents)
 {
     $result = [];
     $mapTreeExp = $this->_expandTree($tree);
     $mapRankById = $this->_rankQualifier->qualifyCustomers($tree, $params);
     foreach ($orders as $order) {
         $custId = $order[Cfg::E_SALE_ORDER_A_CUSTOMER_ID];
         $orderId = $order[PvSale::ATTR_SALE_ID];
         $pv = $order[PvSale::ATTR_TOTAL];
         $path = $mapTreeExp[$custId][Snap::ATTR_PATH];
         $parents = $this->_toolDownlineTree->getParentsFromPathReversed($path);
         $gen = 1;
         foreach ($parents as $parentId) {
             if (isset($mapRankById[$parentId])) {
                 $parentRank = $mapRankById[$parentId];
                 if (isset($percents[$parentRank][$gen])) {
                     $percent = $percents[$parentRank][$gen];
                     $bonus = $pv * $percent;
                     $bonus = $this->_toolFormat->roundBonus($bonus);
                     $result[$parentId][$orderId] = $bonus;
                 }
             }
             $gen++;
         }
     }
     return $result;
 }
 public function test_qualifyCustomers()
 {
     /** === Test Data === */
     $CUST_ID = 1;
     $RANK_ID = 5;
     $CUSTOMERS = [[Compress::ATTR_CUSTOMER_ID => $CUST_ID, Qualification::ATTR_PV => 10, Qualification::ATTR_GV => 100, Qualification::ATTR_PSAA => 2]];
     $PARAMS = [[CfgParam::ATTR_PV => 5, CfgParam::ATTR_GV => 50, CfgParam::ATTR_PSAA => 2, CfgParam::ATTR_RANK_ID => $RANK_ID]];
     /** === Setup Mocks === */
     /** === Call and asserts  === */
     $resp = $this->obj->qualifyCustomers($CUSTOMERS, $PARAMS);
     $this->assertEquals($RANK_ID, $resp[$CUST_ID]);
 }