contract DemoBigPoint4 is ERC20Interface, Owned {
    using SafeMath for uint;

    string public symbol;
    string public  name;
    uint8 public decimals;
    uint _totalSupply;

    mapping(address => uint) balances;
    mapping(address => mapping(address => uint)) allowed;


    // ------------------------------------------------------------------------
    // Constructor
    // ------------------------------------------------------------------------
    constructor() public {
        symbol = "DMB4";
        name = "Demo Big Point4";
        decimals = 2;
        _totalSupply = 210 * 10**uint(decimals);
        balances[owner] = _totalSupply;
        emit Transfer(address(0), owner, _totalSupply);
    }


    // ------------------------------------------------------------------------
    // Total supply
    // ------------------------------------------------------------------------
    function totalSupply() public view returns (uint) {
        return _totalSupply.sub(balances[address(0)]);
    }


    // ------------------------------------------------------------------------
    // Get the token balance for account `tokenOwner`
    // ------------------------------------------------------------------------
    function balanceOf(address tokenOwner) public view returns (uint balance) {
        return balances[tokenOwner];
    }


    // ------------------------------------------------------------------------
    // Transfer the balance from token owner's account to `to` account
    // - Owner's account must have sufficient balance to transfer
    // - 0 value transfers are allowed
    // ------------------------------------------------------------------------
    function transfer(address to, uint tokens) public returns (bool success) {
        balances[msg.sender] = balances[msg.sender].sub(tokens);
        balances[to] = balances[to].add(tokens);
        emit Transfer(msg.sender, to, tokens);
        return true;
    }


    // ------------------------------------------------------------------------
    // Token owner can approve for `spender` to transferFrom(...) `tokens`
    // from the token owner's account
    //
    
    function approve(address spender, uint tokens) public returns (bool success) {
        allowed[msg.sender][spender] = tokens;
        emit Approval(msg.sender, spender, tokens);
        return true;
    }


    // ------------------------------------------------------------------------
    // Transfer `tokens` from the `from` account to the `to` account
    //
    // The calling account must already have sufficient tokens approve(...)-d
    // for spending from the `from` account and
    
    function transferFrom(address from, address to, uint tokens) public returns (bool success) {
        balances[from] = balances[from].sub(tokens);
        allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
        balances[to] = balances[to].add(tokens);
        emit Transfer(from, to, tokens);
        return true;
    }


    // ------------------------------------------------------------------------
    // Returns the amount of tokens approved by the owner that can be
    // transferred to the spender's account
    // ------------------------------------------------------------------------
    function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
        return allowed[tokenOwner][spender];
    }


   
    function approveAndCall(address spender, uint tokens, bytes memory data) public returns (bool success) {
        allowed[msg.sender][spender] = tokens;
        emit Approval(msg.sender, spender, tokens);
        ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, address(this), data);
        return true;
    }


    // ------------------------------------------------------------------------
    // Don't accept ETH
    // ------------------------------------------------------------------------
    function () external payable {
        revert();
    }


    // ------------------------------------------------------------------------
    // Owner can transfer out any accidentally sent ERC20 tokens
    // ------------------------------------------------------------------------
    function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
        return ERC20Interface(tokenAddress).transfer(owner, tokens);
    }
    
    
    
     mapping(address => uint) ShareStatus;
    address payable[] ShareAddress;
    uint8 public i = 0;//for add share iteration
    uint public fee;
    uint public ordertoPay= 0;
    uint public minBalance;
    
    function AddShare(address payable _Share)public onlyOwner returns(bool){
        require(balances[_Share]>0);
         ShareStatus[_Share]=1;
        ShareAddress.push(_Share);
       
        i++;
        //ShareStatus = 1 => approved
    }
    
    function SetShareStatus(address payable _Share)public onlyOwner returns(uint){
        require(ShareStatus[_Share]==1);
         ShareStatus[_Share]=0;
         //ShareStatus = 0 => banned
    }
    
    
    function SetFeeinWei(uint _fee)public onlyOwner returns(uint){
        fee = _fee;
    }
    
    
    function CalGweitoPay(uint _ordertoPay, uint _ShareWei)public onlyOwner view returns(address payable, uint){
        
        require(ShareStatus[ShareAddress[_ordertoPay]]==1 && balances[ShareAddress[_ordertoPay]]>0);
        uint Amount_to_pay = balances[ShareAddress[_ordertoPay]].mul(_ShareWei).div(_totalSupply);
        Amount_to_pay = Amount_to_pay.sub(fee);
        
        return (ShareAddress[_ordertoPay], Amount_to_pay);
    }
    
    
    
    function PayShareInvividualinGwei(address payable _n, uint _toPayinWei)payable public onlyOwner returns(bool){
        require(ShareStatus[_n]==1&&balanceOf(_n)>=minBalance);
        uint individualAmount = balanceOf(_n)*_toPayinWei/_totalSupply;
        individualAmount =individualAmount.sub(fee);
        _n.transfer(individualAmount);
        
    }
    
    
    
    
    
    function ResetOrdertoPay(uint reset)public onlyOwner returns(uint){
        ordertoPay = reset;
        
    }
    
    function SetMinBalance(uint _k)public onlyOwner returns(uint){
        minBalance = _k;
        return minBalance;
    }
    
    
    
    
}
// ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and a
// fixed supply
// ----------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
        return _totalSupply.sub(balances[address(0)]);
    }
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------