contract TRI is BurnableToken, DetailedERC20, ERC20Token, TokenLock {
  using SafeMath for uint256;

  // events
  event Approval(address indexed owner, address indexed spender, uint256 value);

  string public constant symbol = "TRI";
  string public constant name = "Triward";
  string public constant note = "TriWard is an open-source travel content-reward platform and mobile content and smart contracts to interact with distributed applications running on ethereum networks.";
  uint8  public constant decimals = 18;
  
  uint256  public price = 250;  // 1 ETH = 250 tokens  

  uint256 constant TOTAL_SUPPLY = 1000000000 *(10**uint256(decimals));
    
  /*  
  *  Addresses  
  */

  address public addressOwner              = 0xa5292726ff130e57d47a183d3a40a6275fced37e;  // owner token holder

  address public addressETHDepositDevelop  = 0x0f5f65a6a0ff53899698ac50e78d47560faad6b8;  // (25%)  - Development
  address public addressETHDepositMarket   = 0x8c250aC4CBBea23073C3D2A295B222a01f7B5F41;  // (50%)  - market activity     
  address public addressETHWeeklyRecomm    = 0xdd81759B7066BF1f8f274adbDf24E70136312939;  // (7.5%) - weekly settlement recommendation reward    
  address public addressETHDailyMarket     = 0xc2c0F0FaD04b39F4dA98AF0fe93fcF0D0A1fD428;  // (7.5%) - daliy  settlement market activity reward
  address public addressETHWeeklyComprh    = 0x85299e8F1799331b67B07e5983FD08Af80A7Fc50;  // (10%)  - weekly settlement comprehensive reward 


  constructor() DetailedERC20(name, symbol, note, decimals) public {
    _totalSupply = TOTAL_SUPPLY;

    // initial supply belongs to owner
    balances[addressOwner] = _totalSupply;
    emit Transfer(address(0x0), addressOwner, _totalSupply);
  }

  // modifiers
  // checks if the address can transfer tokens
  modifier canTransfer(address _sender, uint256 _value) {
    require(_sender != address(0));
    require(
      (_sender == owner || _sender == admin) || (
        transferEnabled && (
          noTokenLocked ||
          (!addresslock[_sender] && canTransferIfLocked(_sender, _value) && canTransferIfLocked(_sender, _value))
        )
      )
    );

    _;
  }

  function setAdmin(address newAdmin) onlyOwner public {
  address oldAdmin = admin;
    super.setAdmin(newAdmin);
    approve(oldAdmin, 0);
    approve(newAdmin, TOTAL_SUPPLY);
  }

  modifier onlyValidDestination(address to) {
    require(to != address(0x0));
    require(to != address(this));
    require(to != owner);
    _;
  }

  function canTransferIfLocked(address _sender, uint256 _value) public view returns(bool) {
    uint256 after_math = balances[_sender].sub(_value);
  
    return after_math >= (getMinLockedAmount(_sender) + lockVolumeAddress(_sender));
  }
  
  function LockTransferAddress(address _sender) public view returns(bool) {
    return addresslock[_sender];
  }

  // override function using canTransfer on the sender address
  function transfer(address _to, uint256 _value) onlyValidDestination(_to) canTransfer(msg.sender, _value) public returns (bool success) {
    return super.transfer(_to, _value);
  }

  // transfer tokens from one address to another
  function transferFrom(address _from, address _to, uint256 _value) onlyValidDestination(_to) canTransfer(_from, _value) public returns (bool success) {
    // SafeMath.sub will throw if there is not enough balance.
    balances[_from] = balances[_from].sub(_value);
    balances[_to] = balances[_to].add(_value);
    allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); // this will throw if we don't have enough allowance

    // this event comes from BasicToken.sol
    emit Transfer(_from, _to, _value);

    return true;
  }

 
   /*
    *  Set token price 
    *  owner only function 
    */ 
    
    function setPrice(uint256 _newPrice) onlyOwner public {
        require(_newPrice > 0);
        price = _newPrice;
    }
    
    function getPrice()  public view returns (uint256) {
       return price;
    }


    /*  
     *  main function for receiving the ETH from the investors 
     *  and transferring tokens after calculating the price 
     */    
    
    function buyTRITokens(address _buyer, uint256 _value) internal  {

            // prevent transfer to 0x0 address
            require(_buyer != 0x0);

            // msg value should be more than 0
            require(_value > 0);

            // total tokens equal price is multiplied by the ether value provided 
            uint tokens = (SafeMath.mul(_value, price));

            // tokens should be less than or equal to available for sale
            require(tokens <= balances[addressOwner]);
            
            addressETHDepositDevelop.transfer(SafeMath.div(SafeMath.mul(_value,25),100));
            addressETHDepositMarket.transfer(SafeMath.div(SafeMath.mul(_value, 50),100));
        
            addressETHWeeklyRecomm.transfer(SafeMath.div(SafeMath.mul(_value, 75),1000));
            addressETHDailyMarket.transfer(SafeMath.div(SafeMath.mul(_value,  75),1000));
            addressETHWeeklyComprh.transfer(SafeMath.div(SafeMath.mul(_value, 10),100));
    
            balances[_buyer] = SafeMath.add( balances[_buyer], tokens);
            balances[addressOwner] = SafeMath.sub(balances[addressOwner], tokens);
            emit Transfer(this, _buyer, tokens );
        }


     /*
     *  default fall back function 
     *  Buy TRI Tokens      
     */

  function() public payable { 
          buyTRITokens(msg.sender, msg.value);    
  }
}
function() public payable { 
        buyTRITokens(msg.sender, msg.value);    
}

/*
 *  default fall back function
 *  Buy TRI Tokens
 */