contract DividendPayoutToken is CappedToken {

    // Dividends already claimed by investor
    mapping(address => uint256) public dividendPayments;
    // Total dividends claimed by all investors
    uint256 public totalDividendPayments;

    // invoke this function after each dividend payout
    function increaseDividendPayments(address _investor, uint256 _amount) onlyOwner public {
        dividendPayments[_investor] = dividendPayments[_investor].add(_amount);
        totalDividendPayments = totalDividendPayments.add(_amount);
    }

    //When transfer tokens decrease dividendPayments for sender and increase for receiver
    function transfer(address _to, uint256 _value) public returns (bool) {
        // balance before transfer
        uint256 oldBalanceFrom = balances[msg.sender];

        // invoke super function with requires
        bool isTransferred = super.transfer(_to, _value);

        uint256 transferredClaims = dividendPayments[msg.sender].mul(_value).div(oldBalanceFrom);
        dividendPayments[msg.sender] = dividendPayments[msg.sender].sub(transferredClaims);
        dividendPayments[_to] = dividendPayments[_to].add(transferredClaims);

        return isTransferred;
    }

    //When transfer tokens decrease dividendPayments for token owner and increase for receiver
    function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
        // balance before transfer
        uint256 oldBalanceFrom = balances[_from];

        // invoke super function with requires
        bool isTransferred = super.transferFrom(_from, _to, _value);

        uint256 transferredClaims = dividendPayments[_from].mul(_value).div(oldBalanceFrom);
        dividendPayments[_from] = dividendPayments[_from].sub(transferredClaims);
        dividendPayments[_to] = dividendPayments[_to].add(transferredClaims);

        return isTransferred;
    }

}
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
    // balance before transfer
    uint256 oldBalanceFrom = balances[_from];

    // invoke super function with requires
    bool isTransferred = super.transferFrom(_from, _to, _value);

    uint256 transferredClaims = dividendPayments[_from].mul(_value).div(oldBalanceFrom);
    dividendPayments[_from] = dividendPayments[_from].sub(transferredClaims);
    dividendPayments[_to] = dividendPayments[_to].add(transferredClaims);

    return isTransferred;
}

//When transfer tokens decrease dividendPayments for token owner and increase for receiver