contract VIUBI {
    using SafeMath for uint256;

    address public receiver1;
    address public receiver2;
    IERC20 public token;
    uint256 public value1;
    uint256 public value2;
    uint256 public nextDistributionDate;
    uint256 public distributionInterval;

    event Distribution(
        uint256 nextDistributionDate,
        uint256 paidAt,
        uint256 timesPaid,
        address receiver1,
        uint256 value1,
        address receiver2,
        uint256 value2
    );

    constructor(
        IERC20 _token,
        address _receiver1,
        address _receiver2,
        uint256 _value1,
        uint256 _value2,
        uint256 _distributionStartDate,
        uint256 _distributionInterval
    ) public {
        token = _token;
        receiver1 = _receiver1;
        receiver2 = _receiver2;
        value1 = _value1;
        value2 = _value2;
        nextDistributionDate = _distributionStartDate;
        distributionInterval = _distributionInterval;
    }

    /**
     * @dev Calculate number of intervals available for payout
     */
    function getAvailableDistributionIntervals() public view returns (uint256) {
        if (now < nextDistributionDate) {
            return 0;
        } else {
            return
                (now.sub(nextDistributionDate)).div(distributionInterval).add(
                    1
                );
        }
    }

    /**
     * @dev Perform specific amount of token distributions to receivers addresses
     */
    function distribute() public returns (bool) {
        uint256 times = getAvailableDistributionIntervals();
        require(times != 0);
        require(
            now >=
                nextDistributionDate.add(distributionInterval.mul(times.sub(1)))
        );

        uint256 payoutAmount1 = value1.mul(times);
        uint256 payoutAmount2 = value2.mul(times);

        token.transfer(receiver1, payoutAmount1);
        token.transfer(receiver2, payoutAmount2);

        nextDistributionDate = nextDistributionDate.add(
            distributionInterval.mul(times)
        );

        emit Distribution(
            nextDistributionDate,
            now,
            times,
            receiver1,
            payoutAmount1,
            receiver2,
            payoutAmount2
        );

        return true;
    }
}
function distribute() public returns (bool) {
    uint256 times = getAvailableDistributionIntervals();
    require(times != 0);
    require(
        now >=
            nextDistributionDate.add(distributionInterval.mul(times.sub(1)))
    );

    uint256 payoutAmount1 = value1.mul(times);
    uint256 payoutAmount2 = value2.mul(times);

    token.transfer(receiver1, payoutAmount1);
    token.transfer(receiver2, payoutAmount2);

    nextDistributionDate = nextDistributionDate.add(
        distributionInterval.mul(times)
    );

    emit Distribution(
        nextDistributionDate,
        now,
        times,
        receiver1,
        payoutAmount1,
        receiver2,
        payoutAmount2
    );

    return true;
}

/**
 * @dev Perform specific amount of token distributions to receivers addresses
 */