contract Stage is FixedRate, MultiOwners {
    using SafeMath for uint256;

    // Global
    string _stageName = "Pre-ICO";

    // Maximum possible cap in USD
    uint256 public mainCapInUSD = 1000000e2;

    // Maximum possible cap in USD
    uint256 public hardCapInUSD = mainCapInUSD;

    //  period in days
    uint256 public period = 30 days;

    // Token Price in USD
    uint256 public tokenPriceUSD = 50;

    // WEI per token
    uint256 public weiPerToken;
    
    // start and end timestamp where investments are allowed (both inclusive)
    uint256 public startTime;
    uint256 public endTime;

    // total wei received during phase one
    uint256 public totalWei;

    // Maximum possible cap in wei for phase one
    uint256 public mainCapInWei;
    // Maximum possible cap in wei
    uint256 public hardCapInWei;

    function Stage (uint256 _startTime) {
        startTime = _startTime;
        endTime = startTime.add(period);
        weiPerToken = tokenPriceUSD.mul(1 ether).div(rateETHUSD);
        mainCapInWei = mainCapInUSD.mul(1 ether).div(rateETHUSD);
        hardCapInWei = mainCapInWei;

    }

    /*
     * @dev amount calculation, depends of current period
     * @param _value ETH in wei
     * @param _at time
     */
    function calcAmountAt(uint256 _value, uint256 _at) constant returns (uint256, uint256) {
        uint256 estimate;
        uint256 odd;

        if(_value.add(totalWei) > hardCapInWei) {
            odd = _value.add(totalWei).sub(hardCapInWei);
            _value = hardCapInWei.sub(totalWei);
        } 
        estimate = _value.mul(1 ether).div(weiPerToken);
        require(_value + totalWei <= hardCapInWei);
        return (estimate, odd);
    }
}
function calcAmountAt(uint256 _value, uint256 _at) constant returns (uint256, uint256) {
        uint256 estimate;
        uint256 odd;

        if(_value.add(totalWei) > hardCapInWei) {
            odd = _value.add(totalWei).sub(hardCapInWei);
            _value = hardCapInWei.sub(totalWei);
        } 
        estimate = _value.mul(1 ether).div(weiPerToken);
        require(_value + totalWei <= hardCapInWei);
        return (estimate, odd);
    }
/*
 * @dev amount calculation, depends of current period
 * @param _value ETH in wei
 * @param _at time
 */