In today's world, the speed of developments in different fields of science and technology has become much higher than before. The communications technology will also be transformed due to the increase in the number of mobile devices, expansion of the Internet of Things (IoT), and also higher required user throughput. As a result, using current conventional methods for coverage of different users in network especially in crowded places, are problematic. Therefore, we need to use various and new methods to increase the coverage area, throughput, energy efficiency and reduce the delay of the users. One of these methods, is device to device or D2D communication which allows two closely devices to communicate directly without requiring the intervention of base station. In order to transmit the message, D2D users can also benefit from their co-existence with cellular users and for this purpose, maintaining the quality of service for cellular users is important. Considering the facts that D2D communication is usually done between two devices with short distance, and replacing the batteries is costly, energy harvesting (EH) is a promising way that can be used to feed these devices. EH is a method in which users can use the energy harvester circuit to mainly harvest energy from ambient sources like the interference of the other users and from dedicated sources like base station. In this study, a cellular network is considered, where D2D communication simultaneously takes place by sharing the spectral resources of the cellular users in underlay mode and with the help of energy harvesting. Hence, there are one base station, some cellular users and D2D pairs, where the transmitter of D2D users is capable to harvest energy. Furthermore, in this system model, two timing scenarios are considered for users data transmission, namely co-existence and hybrid. Our goal is to maximize the minimum of D2D users throughput considering variables like the transmit beamforming vector at the base station, time allocation of users and energy expenditure of D2D users. This problem is solved using semi-definite relaxation (SDR) method. Finally, we compare two proposed scenarios with each other and evaluate their performance in numerical results considering different parameters like number of antennas in base station, minimum threshold of cellular user's throughput and D2D pair distance in macrocell and femtocell networks. the results shows that it is possible to have co-existence of D2D and cellular users in network and also the hybrid scenario has better performance from minimum throughput point of view. D2D Communication, Energy Harvesting, Fairness, Beamforming, Resource Allocation