contract DMPNGCrowdsale is Ownable {
  using SafeMath for uint256;

  // The token being sold
  ERC20 public token;

  // Address where funds are collected
  address public wallet;

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

  // Amount of wei raised
  uint256 public weiRaised;

  
  event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount);

  
  function DMPNGCrowdsale(uint256 _rate, address _wallet, ERC20 _token) public {
    require(_rate > 0);
    require(_wallet != address(0));
    require(_token != address(0));

    rate = _rate;
    wallet = _wallet;
    token = _token;
}

  

  // -----------------------------------------
  // Crowdsale external interface
  // -----------------------------------------

  function allocateRemainingTokens() onlyOwner public {    
    uint256 remaining = token.balanceOf(this);
    token.transfer(owner, remaining);
  }
  
  function () external payable {
    buyTokens(msg.sender);
  }

  
  function buyTokens(address _beneficiary) public payable {

    uint256 weiAmount = msg.value;
    _preValidatePurchase(_beneficiary, weiAmount);

    // calculate token amount to be created
    uint256 tokens = _getTokenAmount(weiAmount);

    // update state
    weiRaised = weiRaised.add(weiAmount);

    _processPurchase(_beneficiary, tokens);
    emit TokenPurchase(
      msg.sender,
      _beneficiary,
      weiAmount,
      tokens
    );   

    _forwardFunds();
   
  }

  // -----------------------------------------
  // Internal interface (extensible)
  // -----------------------------------------

  
  function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) pure internal {
    require(_beneficiary != address(0));
    require(_weiAmount != 0);
  }  
  

  
  function _deliverTokens(address _beneficiary, uint256 _tokenAmount) internal {
    token.transfer(_beneficiary, _tokenAmount);
  }

  
  function _processPurchase(address _beneficiary, uint256 _tokenAmount) internal {
    _deliverTokens(_beneficiary, _tokenAmount);
  }   

  
  function _getTokenAmount(uint256 _weiAmount) internal view returns (uint256) {

    uint256 tokensIssued = _weiAmount.mul(rate);
    
    if( 10 * (10 ** 18) < tokensIssued && 100 * (10 ** 18) > tokensIssued ) tokensIssued = tokensIssued + (1 * (10 ** 18));
    else if( 100 * (10 ** 18) <= tokensIssued ) tokensIssued = tokensIssued + (15 * (10 ** 18));
   

    return tokensIssued;
   
  }
  
  function _forwardFunds() internal {
    wallet.transfer(msg.value);
  }

}
function allocateRemainingTokens() onlyOwner public {    
  uint256 remaining = token.balanceOf(this);
  token.transfer(owner, remaining);
}

// -----------------------------------------
// Crowdsale external interface
// -----------------------------------------