fork download
  1. <?php
  2. class Department
  3. {
  4. public $name;
  5. public $employees = array();
  6.  
  7. public function getTotalEmployees()
  8. { $total = 0;
  9. foreach ($this->employees as $employee){
  10. $total+=$employee[3];
  11. }
  12. return $total;
  13. }
  14.  
  15. public function getTotalCoffee(){
  16. $total = 0;
  17. foreach ($this->employees as $employee) {
  18. $total+=$employee[1];
  19. }
  20. return $total;
  21. }
  22.  
  23. public function getTotalPapers(){
  24. $total = 0;
  25. foreach ($this->employees as $employee) {
  26. $total+=$employee[2];
  27. }
  28. return $total;
  29. }
  30.  
  31. public function getTotalIncome(){
  32. $total = 0;
  33. foreach ($this->employees as $employee) {
  34. $total = $total + $employee[0];
  35. }
  36. return floor($total);
  37. }
  38.  
  39. }
  40.  
  41. abstract class Employee
  42. {
  43. public $rank;
  44. public $income;
  45. public $coffee;
  46. public $papers;
  47. public $quantity = 1;
  48.  
  49. public function rank($rank)
  50. {
  51. if($rank == 2){
  52. $this->income *= 1.25;
  53. }
  54. elseif($rank == 3){
  55. $this->income *= 1.5;
  56. }
  57. return $this->income;
  58. }
  59. public function makeLeader($rank){
  60. $total = array();
  61. $inc = $this->rank($rank) * 1.5;
  62. $cof = $this->coffee * 2;
  63. $pap = 0;
  64. $quan = $this->quantity;
  65. return $total = [$inc,$cof,$pap,$quan];
  66. }
  67. public function multiple($quantity ,$rank){
  68. $this->income = $this->rank($rank);
  69. $total = array();
  70.  
  71. $inc = $this->income * $quantity;
  72. $cof = $this->coffee * $quantity;
  73. $pap = $this->papers * $quantity;
  74. return $total = [$inc,$cof,$pap,$quantity];
  75. }
  76. }
  77.  
  78. class Manager extends Employee
  79. {
  80. public $income = 500;
  81. public $coffee = 20;
  82. public $papers = 200;
  83. }
  84. class Marketer extends Employee
  85. {
  86. public $income = 400;
  87. public $coffee = 15;
  88. public $papers = 150;
  89. }
  90. class Engineer extends Employee
  91. {
  92. public $income = 200;
  93. public $coffee = 5;
  94. public $papers = 50;
  95. }
  96. class Analytics extends Employee
  97. {
  98. public $income = 800;
  99. public $coffee = 50;
  100. public $papers = 5;
  101. }
  102.  
  103. function padLeft($text, $length){
  104. $cl = mb_strlen($text);
  105. if($cl<$length){
  106. for($i = 0; $i < $length - $cl; $i++){
  107. $text = " ".$text;
  108. }}
  109. return $text;
  110. }
  111. function padRight($text, $length){
  112. $cl = mb_strlen($text);
  113. if($cl<$length){
  114. for($i = 0; $i < $length - $cl; $i++){
  115. $text = $text." ";
  116. }}
  117. return $text;
  118. }
  119.  
  120. $manager = new Manager;
  121. $marketer = new Marketer;
  122. $engineer = new Engineer;
  123. $analytics = new Analytics;
  124.  
  125. $buyers = new Department;
  126. $buyers->name = "Закупок";
  127. $buyers->employees=array(
  128. $manager->multiple(9,1), //на первом месте кол-во, на втором ранг
  129. $manager->multiple(3,2),
  130. $manager->multiple(2,3),
  131. $marketer->multiple(2,1),
  132. $manager->makeLeader(2)
  133. );
  134.  
  135. $sellers = new Department;
  136. $sellers->name = "Продаж";
  137. $sellers->employees = array(
  138. $manager->multiple(12,1),
  139. $marketer->multiple(6,1),
  140. $analytics->multiple(3,1),
  141. $analytics->multiple(2,2),
  142. $marketer->makeLeader(2)
  143. );
  144.  
  145. $advertisers = new Department;
  146. $advertisers->name = "Рекламы";
  147. $advertisers->employees = array(
  148. $marketer->multiple(15,1),
  149. $marketer->multiple(10,2),
  150. $manager->multiple(8,1),
  151. $engineer->multiple(2,1),
  152. $marketer->makeLeader(3)
  153. );
  154.  
  155. $logistics = new Department;
  156. $logistics->name = "Логистики";
  157. $logistics->employees = array(
  158. $manager->multiple(13,1),
  159. $manager->multiple(5,2),
  160. $engineer->multiple(5,1),
  161. $manager->makeLeader(1)
  162. );
  163. $departments = array($buyers,$sellers,$advertisers,$logistics);
  164. $col1 = 10;
  165. $col2 = 5;
  166. $col3 = 5;
  167. $col4 = 5;
  168. $col5 = 5;
  169. $col6 = 5;
  170.  
  171. $col1 = 11;
  172. $col2 = 11;
  173. $col3 = 11;
  174. $col4 = 11;
  175. $col5 = 11;
  176. $col6 = 13;
  177.  
  178. echo (padRight("Департамент",$col1).
  179. padLeft("сотр.",$col2).
  180. padLeft("тугр.",$col3).
  181. padLeft("кофе",$col4).
  182. padLeft("стр.",$col5).
  183. padLeft("тугр./стр.",$col6)."\n---------------------------------------------------------------------------\n");
  184.  
  185. foreach ($departments as $department){
  186. echo padRight($department->name,$col1).
  187. padLeft($department->getTotalEmployees(),$col2).
  188. padLeft($department->getTotalIncome(),$col3).
  189. padLeft($department->getTotalCoffee(),$col4).
  190. padLeft($department->getTotalPapers(),$col5).
  191. padLeft(floor($department->getTotalIncome()/$department->getTotalPapers()),$col6)."\n";
  192.  
  193. }
Success #stdin #stdout 0.02s 24400KB
stdin
Standard input is empty
stdout
Департамент      сотр.      тугр.       кофе       стр.   тугр./стр.
---------------------------------------------------------------------------
Закупок             17      10807        350       3100            3
Продаж              24      21612        610       3325            6
Рекламы             36      24931        575       5450            4
Логистики           24      25755        425       3850            6