contract PageViewRecord is SaleRecord, Pausable {
    
    using SafeMath for uint256;
    
    uint16 itemCount = 100;
    
    function setPage(uint16 _itemCount) public onlyManagers {
        itemCount = _itemCount;
    }
    
    //get
    function getPageValueCount() public view returns (uint256) {
        uint256 userSize = propertyKeys.length;
        uint256 pageCount = userSize.div(itemCount);
        if((userSize.sub(pageCount.mul(itemCount))) > 0) {
            pageCount++;
        }
        return pageCount;
    }
    function getPageItemValue(uint256 _pageIndex) public view returns (address[] memory, uint256[] memory, uint256[] memory){
        require(getPageValueCount()> _pageIndex);
        
        uint256 startIndex =_pageIndex.mul(itemCount);
        uint256 remain = propertyKeys.length - startIndex;
        uint256 loopCount = (remain >= itemCount) ? itemCount : remain;
        
        address[] memory keys = new address[](loopCount);
        uint256[] memory inputEther = new uint256[](loopCount);
        uint256[] memory outputToken = new uint256[](loopCount);

        for (uint256 i = 0 ; i < loopCount ; i++) {
            uint256 index = startIndex + i;
            address key = propertyKeys[index];
            keys[i] = key;
            
            uint256 size = propertyMember[keys[i]].length;
            for (uint256 k = 0 ; k < size ; k++) {
                inputEther[i] = inputEther[i].add(propertyMember[key][k].inputEther);
                outputToken[i] = outputToken[i].add(propertyMember[key][k].outputToken);
            }

        }
        
        return (keys, inputEther, outputToken);
    }
    
    function getPageInfoCount() public view returns (uint256) {
        uint256 infoSize = 0;
        for (uint256 i = 0 ; i < propertyKeys.length ; i++) {
            infoSize = infoSize.add(propertyMember[propertyKeys[i]].length);
        }

        uint256 pageCount = infoSize.div(itemCount);
        if((infoSize.sub(pageCount.mul(itemCount))) > 0) {
            pageCount++;
        }
        return pageCount;
    }
    function getPageItemInfo(uint256 _pageIndex) public view returns (address[] memory, uint256[] memory, uint256[] memory, uint256[] memory){
        require(getPageInfoCount()> _pageIndex);
        
        uint256 infoSize = 0;
        for (uint256 i = 0 ; i < propertyKeys.length ; i++) {
            infoSize = infoSize.add(propertyMember[propertyKeys[i]].length);
        }
        
        uint256 startIndex =_pageIndex.mul(itemCount);
        uint256 remain = infoSize - startIndex;
        uint256 loopCount = (remain >= itemCount) ? itemCount : remain;
        
        address[] memory keys = new address[](loopCount);
        uint256[] memory time = new uint256[](loopCount);
        uint256[] memory inputEther = new uint256[](loopCount);
        uint256[] memory outputToken = new uint256[](loopCount);
        
        uint256 loopIndex = 0;
        uint256 index = 0;
        for (uint256 i = 0 ; i < propertyKeys.length && loopIndex < loopCount; i++) {

            address key = propertyKeys[i];
            
            for (uint256 k = 0 ; k < propertyMember[key].length && loopIndex < loopCount ; k++) {
                if(index >=startIndex){
                    keys[loopIndex] = key;
                    time[loopIndex]        = propertyMember[key][k].time;
                    inputEther[loopIndex]  = propertyMember[key][k].inputEther;
                    outputToken[loopIndex] = propertyMember[key][k].outputToken;
                    loopIndex++;
                } else {
                    index++;
                }
            }

        }
        
        return (keys, time, inputEther, outputToken);
    }
    
    function getPageNotWithdrawCount() public view returns (uint256) {
        uint256 infoSize = 0;
        for (uint256 i = 0 ; i < propertyKeys.length ; i++) {
            for (uint256 j = 0 ; j < propertyMember[propertyKeys[i]].length ; j++) {
                if(!propertyMember[propertyKeys[i]][j].withdraw)
                    infoSize++;
            }
        }

        uint256 pageCount = infoSize.div(itemCount);
        if((infoSize.sub(pageCount.mul(itemCount))) > 0) {
            pageCount++;
        }
        return pageCount;
    }
    function getPageNotWithdrawInfo(uint256 _pageIndex) public view returns (address[] memory, uint256[] memory, uint256[] memory, uint256[] memory){
        require(getPageInfoCount()> _pageIndex);
        
        uint256 infoSize = 0;
        for (uint256 i = 0 ; i < propertyKeys.length ; i++) {
            for (uint256 j = 0 ; j < propertyMember[propertyKeys[i]].length ; j++) {
                if(!propertyMember[propertyKeys[i]][j].withdraw)
                    infoSize++;
            }
        }
        
        uint256 startIndex =_pageIndex.mul(itemCount);
        uint256 remain = infoSize - startIndex;
        uint256 loopCount = (remain >= itemCount) ? itemCount : remain;
        
        address[] memory keys = new address[](loopCount);
        uint256[] memory time = new uint256[](loopCount);
        uint256[] memory inputEther = new uint256[](loopCount);
        uint256[] memory outputToken = new uint256[](loopCount);
        
        uint256 loopIndex = 0;
        uint256 index = 0;
        for (uint256 i = 0 ; i < propertyKeys.length && loopIndex < loopCount; i++) {

            address key = propertyKeys[i];
            
            for (uint256 k = 0 ; k < propertyMember[key].length && loopIndex < loopCount ; k++) {
                if(propertyMember[key][k].withdraw)
                    continue;
                if(index >=startIndex){
                    keys[loopIndex] = key;
                    time[loopIndex]        = propertyMember[key][k].time;
                    inputEther[loopIndex]  = propertyMember[key][k].inputEther;
                    outputToken[loopIndex] = propertyMember[key][k].outputToken;
                    loopIndex++;
                } else {
                    index++;
                }
            }

        }
        
        return (keys, time, inputEther, outputToken);
    }

}
function getPageValueCount() public view returns (uint256) {
    uint256 userSize = propertyKeys.length;
    uint256 pageCount = userSize.div(itemCount);
    if((userSize.sub(pageCount.mul(itemCount))) > 0) {
        pageCount++;
    }
    return pageCount;
}

//get