/*
    ExchangeWay
    
    inPmMethodObj     - объект PaymentMethod
    outPmMethodObj       - объект PaymentMethod
    isActive            - признак того, что метод активный
    minAmount           - минимальная сумма обмена
    maxAmount           - минимальная сумма обмена
    formulaCalcPerc     - процент системной комиссии
*/
function ExchangeWay(inPmMethodObj, outPmMethodObj, isActive, minAmount, maxAmount, formulaCalcPerc, initValueIn, initValueOut, initValueDirection, isUseBalance, balance, rateUnits){
    this.inPmMethodObj = inPmMethodObj;
    this.outPmMethodObj = outPmMethodObj;
    this.isActive = isActive;
    this.minAmount = minAmount;
    this.maxAmount = maxAmount;
    this.formulaCalcPerc = formulaCalcPerc;
    this.initValueIn = initValueIn;
    this.initValueOut = initValueOut;
    this.initValueDirection = initValueDirection;
    this.isUseBalance = isUseBalance;
    this.balance = balance;
    this.rateUnits = rateUnits;
}

/**
 * Рассчитывает комиссию обмена (системную)
 * 
 * @param  void
 * @param  bool $calcPercByResult расчитывать процент от результата
 * @return int $id integer(4)
 */
ExchangeWay.prototype.calcCommission = function(amount, calcPercByResult){    
    // расчет комисии по формуле/коэффициенту
    var commission = 0;
    
    if(calcPercByResult == true){
        commission = amount * this.formulaCalcPerc / (1 - this.formulaCalcPerc);
    } else{
        commission = amount * this.formulaCalcPerc;
    }

    return commission;    
};


