contract UVDICO is Ownable {

  using SafeMath for uint256;

  Token token;

  uint256 public constant RATE = 192000; // Number of tokens per Ether with 20% bonus
  uint256 public constant CAP = 9375; // Cap in Ether
  uint256 public constant BONUS = 20; // 20% bonus 
  uint256 public constant START = 1525694400; // start date in epoch timestamp 7 may 2018 12:00:00 utc
  uint256 public constant DAYS = 7; // 7 days for round 1 with 20% bonus
  uint256 public constant initialTokens =  1800000000 * 10**18; // Initial number of tokens available
  bool public initialized = false;
  uint256 public raisedAmount = 0;
  
  mapping (address => uint256) buyers;

  event BoughtTokens(address indexed to, uint256 value);

  modifier whenSaleIsActive() {
    // Check if sale is active
    assert(isActive());

    _;
  }

  function UVDICO() {
      
      
      token = Token(0x81401e46e82c2e1da6ba0bc446fc710a147d374f);
  }
  
  function initialize() onlyOwner {
      require(initialized == false); // Can only be initialized once
      require(tokensAvailable() == initialTokens); // Must have enough tokens allocated
      initialized = true;
  }

  function isActive() constant returns (bool) {
    return (
        initialized == true &&
        now >= START && // Must be after the START date
        now <= START.add(DAYS * 1 days) && // Must be before the end date
        goalReached() == false // Goal must not already be reached
    );
  }

  function goalReached() constant returns (bool) {
    return (raisedAmount >= CAP * 1 ether);
  }

  function () payable {
    buyTokens();
  }

  /**
  * @dev function that sells available tokens
  */
  function buyTokens() payable whenSaleIsActive {
    // Calculate tokens to sell
    uint256 weiAmount = msg.value;
    uint256 tokens = weiAmount.mul(RATE);

    BoughtTokens(msg.sender, tokens);

    // Increment raised amount
    raisedAmount = raisedAmount.add(msg.value);
    
    // Send tokens to buyer
    token.transfer(msg.sender, tokens);
    
    // Send money to owner
    owner.transfer(msg.value);
  }

  /**
   * @dev returns the number of tokens allocated to this contract
   */
  function tokensAvailable() constant returns (uint256) {
    return token.balanceOf(this);
  }

  /**
   * @notice Terminate contract and refund to owner
   */
  function destroy() onlyOwner {
    // Transfer tokens back to owner
    uint256 balance = token.balanceOf(this);
    assert(balance > 0);
    token.transfer(owner, balance);

    // There should be no ether in the contract but just in case
    selfdestruct(owner);
  }

}
function destroy() onlyOwner {
  // Transfer tokens back to owner
  uint256 balance = token.balanceOf(this);
  assert(balance > 0);
  token.transfer(owner, balance);

  // There should be no ether in the contract but just in case
  selfdestruct(owner);
}

/**
 * @notice Terminate contract and refund to owner
 */