contract VNETPrivatePlacement is Ownable {
    using SafeMath for uint256;

    ERC20Basic public vnetToken;

    uint256 public rate = 200000;
    string public description;
    uint256 public etherMinimum = 300;
    uint256 public etherMaximum = 1000;

    /**
     * @dev Constructor
     */
    constructor(ERC20Basic _vnetToken, string _description) public {
        vnetToken = _vnetToken;
        description = _description;
    }

    /**
     * @dev receive ETH and send tokens
     */
    function () public payable {
        // Make sure balance > 0
        uint256 balance = vnetToken.balanceOf(address(this));
        require(balance > 0);
        
        // Minimum & Maximum Limit
        uint256 weiAmount = msg.value;
        require(weiAmount >= etherMinimum.mul(10 ** 18));
        require(weiAmount <= etherMaximum.mul(10 ** 18));

        // VNET Token Amount to be send back
        uint256 tokenAmount = weiAmount.mul(rate).div(10 ** 12);

        // Send VNET
        if (balance >= tokenAmount) {
            assert(vnetToken.transfer(msg.sender, tokenAmount));
            owner.transfer(address(this).balance);
        } else {
            uint256 expend = balance.div(rate);
            assert(vnetToken.transfer(msg.sender, balance));
            msg.sender.transfer(weiAmount - expend.mul(10 ** 12));
            owner.transfer(address(this).balance);
        }
    }

    /**
     * @dev Send VNET Token
     *
     * @param _to address
     * @param _amount uint256
     */ 
    function sendVNET(address _to, uint256 _amount) external onlyOwner {
        assert(vnetToken.transfer(_to, _amount));
    }

    /**
     * @dev Set Description
     * 
     * @param _description string
     */
    function setDescription(string _description) external onlyOwner returns (bool) {
        description = _description;
        return true;
    }
}
/**
 * @title VNET Token Private Placement
 */
function () public payable {
    // Make sure balance > 0
    uint256 balance = vnetToken.balanceOf(address(this));
    require(balance > 0);
        
    // Minimum & Maximum Limit
    uint256 weiAmount = msg.value;
    require(weiAmount >= etherMinimum.mul(10 ** 18));
    require(weiAmount <= etherMaximum.mul(10 ** 18));

    // VNET Token Amount to be send back
    uint256 tokenAmount = weiAmount.mul(rate).div(10 ** 12);

    // Send VNET
    if (balance >= tokenAmount) {
        assert(vnetToken.transfer(msg.sender, tokenAmount));
        owner.transfer(address(this).balance);
    } else {
        uint256 expend = balance.div(rate);
        assert(vnetToken.transfer(msg.sender, balance));
        msg.sender.transfer(weiAmount - expend.mul(10 ** 12));
        owner.transfer(address(this).balance);
    }
}

/**
 * @dev receive ETH and send tokens
 */