contract PatentCoinPreICO is Ownable {
    using SafeMath for uint256;

    // Limit of tokens
    uint256 public constant hardCap = 6150000 * (10 ** 6);

    // How many token units a buyer gets per wei
    uint256 public constant rate = 1080;

    // Address where funds are collected
    address public wallet;

    // Amount sold tokens
    uint256 public tokenRaised;

    // Amount of raised money in wei
    uint256 public weiRaised;

    // The token being sold
    Token public token;

    // Date start preICO - 03/25/2018 @ 00:00 (UTC)
    uint256 public constant dateStart = 1521936000;

    // Date end preICO - 05/25/2018 @ 23:59 (UTC)
    uint256 public constant dateEnd = 1527292740;

    /**
     * PatentCoinPreICO constructor
     */
    function PatentCoinPreICO(address _wallet, address _token) public {
        require(_wallet != address(0));
        require(_token != address(0));
        wallet = _wallet;
        token = Token(_token);
    }

    /**
     * event for token purchase logging
     * @param purchaser who paid for the tokens
     * @param beneficiary who got the tokens
     * @param value weis paid for purchase
     * @param amount amount of tokens purchased
     */
    event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount);

    // Fallback function can be used to buy tokens
    function() external payable {
        buyTokens(msg.sender);
    }

    // Low level token purchase function
    function buyTokens(address beneficiary) public payable {
        require(beneficiary != address(0));
        require(msg.value != 0);
        require(now > dateStart);
        require(now <= dateEnd);

        uint256 weiAmount = msg.value;

        // calculate token amount to be created
        uint256 tokens = weiAmount.div(10 ** 12).mul(rate);

        // update state
        require(token.mint(beneficiary, tokens));
        tokenRaised = tokenRaised.add(tokens);
        require(tokenRaised <= hardCap);
        TokenPurchase(msg.sender, beneficiary, weiAmount, tokens);
        weiRaised = weiRaised.add(weiAmount);
        forwardFunds();
    }

    // Send ether to the fund collection wallet
    // override to create custom fund forwarding mechanisms
    function forwardFunds() internal {
        wallet.transfer(msg.value);
    }
}
function forwardFunds() internal {
    wallet.transfer(msg.value);
}

// Send ether to the fund collection wallet
// override to create custom fund forwarding mechanisms