fork download
  1. <?php
  2.  
  3.  
  4. class Employee
  5. {
  6. public $quantity;
  7. public $position;
  8. public $boss;
  9. public $rank;
  10.  
  11. const POSITION_MANAGER = 'Manager';
  12. const POSITION_MARKETER = 'Marketer';
  13. const POSITION_ANALYST = 'Analyst';
  14. const POSITION_ENGINEER = 'Engineer';
  15.  
  16. public function __construct($position, $rank, $boss, $quantity)
  17. {
  18. $this->quantity = $quantity;
  19. $this->boss = $boss;
  20. $this->rank = $rank;
  21.  
  22. if ($position == self::POSITION_MANAGER||$position == self::POSITION_MARKETER||
  23. $position == self::POSITION_ANALYST||$position == self::POSITION_ENGINEER)
  24. {
  25. $this->position = $position;
  26. }else{
  27. echo 'Професия введена неверно.';
  28. }
  29.  
  30. }
  31.  
  32. protected function getSalary()
  33. {
  34. if ($this->rank == 1){
  35. $factor = 1;
  36. }elseif($this->rank == 2){
  37. $factor = 1.25;
  38. }elseif($this->rank == 3){
  39. $factor = 1.5;
  40. }
  41. if ($this->boss == true)
  42. {
  43. $bossFactor = 1.5;
  44. }else{
  45. $bossFactor = 1;
  46. }
  47. $salary = $this->rate * $factor * $bossFactor;
  48. return $salary;
  49. }
  50.  
  51. protected function getCoffe()
  52. {
  53. if ($this->boss == true)
  54. {
  55. $bossFactor = 2;
  56. }else{
  57. $bossFactor = 1;
  58. }
  59. $coffe = $this->coffe * $bossFactor;
  60. return $coffe;
  61. }
  62.  
  63. protected function getPages()
  64. {
  65. if ($this->boss == true)
  66. {
  67. $bossFactor = 0;
  68. }else{
  69. $bossFactor = 1;
  70. }
  71. $pages = $this->pages * $bossFactor;
  72. return $pages;
  73. }
  74. }
  75.  
  76. class Manager extends Employee
  77. {
  78. protected $rate = 500;
  79. protected $coffe = 20;
  80. protected $pages = 200;
  81.  
  82. public $rank;
  83. public $boss;
  84.  
  85. public function __construct($rank, $boss)
  86. {
  87. $this->rank = $rank;
  88. $this->boss = $boss;
  89. }
  90.  
  91. public function getSalary()
  92. {
  93. return parent::getSalary();
  94. }
  95.  
  96. public function getCoffe()
  97. {
  98. return parent::getCoffe();
  99. }
  100.  
  101. public function getPages()
  102. {
  103. return parent::getPages();
  104. }
  105. }
  106.  
  107. class Marketer extends Employee
  108. {
  109. protected $rate = 400;
  110. protected $coffe = 15;
  111. protected $pages = 150;
  112.  
  113. public $rank;
  114. public $boss;
  115.  
  116. public function __construct($rank, $boss)
  117. {
  118. $this->rank = $rank;
  119. $this->boss = $boss;
  120. }
  121.  
  122. public function getSalary()
  123. {
  124. return parent::getSalary();
  125. }
  126.  
  127. public function getCoffe()
  128. {
  129. return parent::getCoffe();
  130. }
  131.  
  132. public function getPages()
  133. {
  134. return parent::getPages();
  135. }
  136. }
  137.  
  138. class Engineer extends Employee
  139. {
  140. protected $rate = 200;
  141. protected $coffe = 5;
  142. protected $pages = 50;
  143.  
  144. public $rank;
  145. public $boss;
  146.  
  147. public function __construct($rank, $boss)
  148. {
  149. $this->rank = $rank;
  150. $this->boss = $boss;
  151. }
  152.  
  153. public function getSalary()
  154. {
  155. return parent::getSalary();
  156. }
  157.  
  158. public function getCoffe()
  159. {
  160. return parent::getCoffe();
  161. }
  162.  
  163. public function getPages()
  164. {
  165. return parent::getPages();
  166. }
  167. }
  168.  
  169. class Analyst extends Employee
  170. {
  171. protected $rate = 800;
  172. protected $coffe = 50;
  173. protected $pages = 5;
  174.  
  175. public $rank;
  176. public $boss;
  177.  
  178. public function __construct($rank, $boss)
  179. {
  180. $this->rank = $rank;
  181. $this->boss = $boss;
  182. }
  183.  
  184. public function getSalary()
  185. {
  186. return parent::getSalary();
  187. }
  188.  
  189. public function getCoffe()
  190. {
  191. return parent::getCoffe();
  192. }
  193.  
  194. public function getPages()
  195. {
  196. return parent::getPages();
  197. }
  198. }
  199.  
  200. class Department
  201. {
  202. public $departmentName;
  203. public $quantity;
  204. public $position;
  205. public $boss;
  206. public $rank;
  207.  
  208. public function __construct($employees, $departmentName)
  209. {
  210. foreach ($employees as $employee)
  211. {
  212. $this->quantity[] = $employee->quantity;
  213. $this->position[] = $employee->position;
  214. $this->boss[] = $employee->boss;
  215. $this->rank[] = $employee->rank;
  216. }
  217. $this->departmentName = $departmentName;
  218. }
  219.  
  220. public function getTotalCoffe()
  221. {
  222. $coffe = 0;
  223.  
  224. for ($x = 0; $x < count($this->rank); $x++){
  225. if ($this->position[$x] == 'Manager')
  226. {
  227. $coffe = ((new Manager($this->rank[$x], $this->boss[$x]))->getCoffe())*$this->quantity[$x] + $coffe;
  228.  
  229. }elseif ($this->position[$x] == 'Marketer')
  230. {
  231. $coffe = ((new Marketer($this->rank[$x], $this->boss[$x]))->getCoffe())*$this->quantity[$x] + $coffe;
  232.  
  233. }elseif ($this->position[$x] == 'Engineer')
  234. {
  235. $coffe = ((new Engineer($this->rank[$x], $this->boss[$x]))->getCoffe())*$this->quantity[$x] + $coffe;
  236.  
  237. }elseif ($this->position[$x] == 'Analyst')
  238. {
  239. $coffe = ((new Analyst($this->rank[$x], $this->boss[$x]))->getCoffe())*$this->quantity[$x] + $coffe;
  240. }
  241.  
  242. }
  243. return $coffe;
  244. }
  245.  
  246. public function getTotalSalary()
  247. {
  248. $salary = 0;
  249.  
  250. for ($x = 0; $x < count($this->rank); $x++){
  251. if ($this->position[$x] == 'Manager')
  252. {
  253. $salary = ((new Manager($this->rank[$x], $this->boss[$x]))->getSalary())*$this->quantity[$x] + $salary;
  254.  
  255. }elseif ($this->position[$x] == 'Marketer')
  256. {
  257. $salary = ((new Marketer($this->rank[$x], $this->boss[$x]))->getSalary())*$this->quantity[$x] + $salary;
  258.  
  259. }elseif ($this->position[$x] == 'Engineer')
  260. {
  261. $salary = ((new Engineer($this->rank[$x], $this->boss[$x]))->getSalary())*$this->quantity[$x] + $salary;
  262.  
  263. }elseif ($this->position[$x] == 'Analyst')
  264. {
  265. $salary = ((new Analyst($this->rank[$x], $this->boss[$x]))->getSalary())*$this->quantity[$x] + $salary;
  266. }
  267.  
  268. }
  269. return $salary;
  270. }
  271.  
  272. public function getTotalPages()
  273. {
  274. $pages = 0;
  275.  
  276. for ($x = 0; $x < count($this->rank); $x++){
  277. if ($this->position[$x] == 'Manager')
  278. {
  279. $pages = ((new Manager($this->rank[$x], $this->boss[$x]))->getPages())*$this->quantity[$x] + $pages;
  280.  
  281. }elseif ($this->position[$x] == 'Marketer')
  282. {
  283. $pages = ((new Marketer($this->rank[$x], $this->boss[$x]))->getPages())*$this->quantity[$x] + $pages;
  284.  
  285. }elseif ($this->position[$x] == 'Engineer')
  286. {
  287. $pages = ((new Engineer($this->rank[$x], $this->boss[$x]))->getPages())*$this->quantity[$x] + $pages;
  288.  
  289. }elseif ($this->position[$x] == 'Analyst')
  290. {
  291. $pages = ((new Analyst($this->rank[$x], $this->boss[$x]))->getPages())*$this->quantity[$x] + $pages;
  292. }
  293.  
  294. }
  295. return $pages;
  296. }
  297.  
  298. public function getPersonelAmount()
  299. {
  300. if (array_sum($this->quantity) != 0)
  301. {
  302. return array_sum($this->quantity);
  303. }else{
  304. return $this->quantity;
  305. }
  306. }
  307.  
  308. public function getSalaryPerPages()
  309. {
  310. return round($this->getTotalSalary() / $this->getTotalPages(), 2);
  311. }
  312. }
  313.  
  314. class Company
  315. {
  316. public $total = 'Всего';
  317. public $totalPersonelAmount;
  318. public $totalSalary;
  319. public $totalCoffe;
  320. public $totalDocumentation;
  321. public $totalSalaryPerPages;
  322.  
  323. public $average = 'Среднее';
  324. public $averagePersonelAmount;
  325. public $averageSalary;
  326. public $averageCoffe;
  327. public $averageDocumentation;
  328. public $averageSalaryPerPages;
  329.  
  330. public function __construct($departments)
  331. {
  332. foreach ($departments as $department)
  333. {
  334. $this->totalPersonelAmount = $department->getPersonelAmount() + $this->totalPersonelAmount;
  335. $this->totalSalary = $department->getTotalSalary() + $this->totalSalary;
  336. $this->totalCoffe = $department->getTotalCoffe() + $this->totalCoffe;
  337. $this->totalDocumentation = $department->getTotalCoffe() + $this->totalDocumentation;
  338. $this->totalSalaryPerPages = $department->getSalaryPerPages() + $this->totalSalaryPerPages;
  339. }
  340. $this->averagePersonelAmount = $this->totalPersonelAmount / count($departments);
  341. $this->averageSalary = round($this->totalSalary / count($departments), 2);
  342. $this->averageCoffe = round($this->totalCoffe / count($departments), 2);
  343. $this->averageDocumentation = round($this->totalDocumentation / count($departments), 2);
  344. $this->averageSalaryPerPages = round($this->totalSalaryPerPages / count($departments), 2);
  345.  
  346.  
  347. }
  348. }
  349.  
  350. function padRight($q, $w){
  351. return implode("", (array_merge(preg_split('//u', $q, 0, PREG_SPLIT_NO_EMPTY), array_fill(0, $w-mb_strlen($q), " "))));
  352. }
  353. function padLeft($q, $w){
  354. return implode("", (array_merge(array_fill(0, $w-mb_strlen($q), " "), preg_split('//u', $q, 0, PREG_SPLIT_NO_EMPTY))));
  355. }
  356.  
  357. $workers1 = array(
  358. new Employee ('Manager', 1, false, 9),
  359. new Employee ('Manager', 2, false, 3),
  360. new Employee ('Manager', 3, false, 2),
  361. new Employee ('Marketer', 1, false, 2),
  362. new Employee ('Manager', 2, true, 1)
  363. );
  364. $workers2 = array(
  365. new Employee ('Manager', 1, false, 12),
  366. new Employee ('Marketer', 1, false, 6),
  367. new Employee ('Analyst', 1, false, 3),
  368. new Employee ('Analyst', 2, false, 2),
  369. new Employee ('Marketer', 2, true, 1)
  370. );
  371. $workers3 = array(
  372. new Employee ('Marketer', 1, false, 15),
  373. new Employee ('Marketer', 2, false, 10),
  374. new Employee ('Manager', 1, false, 8),
  375. new Employee ('Engineer', 1, false, 2),
  376. new Employee ('Marketer', 3, true, 1)
  377. );
  378. $workers4 = array(
  379. new Employee ('Manager', 1, false, 13),
  380. new Employee ('Manager', 2, false, 5),
  381. new Employee ('Engineer', 1, false, 5),
  382. new Employee ('Manager', 1, true, 1)
  383. );
  384.  
  385. $departments = array(
  386. new Department($workers1, 'Закупок'),
  387. new Department($workers2, 'Продаж'),
  388. new Department($workers3, 'Рекламы'),
  389. new Department($workers4, 'Логистики')
  390. );
  391. $company = new Company($departments);
  392.  
  393. function printData($departments, $company, $headline)
  394. {
  395. $col1 = 20;
  396. $col2 = 8;
  397. $col3 = 12;
  398. $col4 = 12;
  399. $col5 = 12;
  400. $col6 = 12;
  401. $col7 = 50;
  402. if($headline == 0){
  403. echo padRight("Департамент", $col1) .
  404. padLeft("сотр.", $col2) .
  405. padLeft("тугр.", $col3) .
  406. padLeft("кофе", $col4) .
  407. padLeft("стр.", $col5) .
  408. padLeft("тугр./стр.", $col6) . "\n" .
  409. implode("", array_fill(0, 40, '--')) . "\n";
  410. }else{
  411. echo padLeft ('Анти-кризисная мера #'."{$headline}", $col7)."\n";
  412. echo implode("", array_fill(0, 40, '--')) . "\n";
  413. }
  414.  
  415. foreach ($departments as $department) {
  416. echo padRight($department->departmentName, $col1) .
  417. padLeft($department->getPersonelAmount(), $col2) .
  418. padLeft($department->getTotalSalary(), $col3) .
  419. padLeft($department->getTotalCoffe(), $col4) .
  420. padLeft($department->getTotalPages(), $col5) .
  421. padLeft($department->getSalaryPerPages(), $col6) . "\n" ;
  422.  
  423. } echo implode("", array_fill(0, 40, '--')) . "\n";
  424.  
  425. echo padRight($company->average, $col1) .
  426. padLeft($company->averagePersonelAmount, $col2) .
  427. padLeft($company->averageSalary, $col3) .
  428. padLeft($company->averageCoffe, $col4) .
  429. padLeft($company->averageDocumentation, $col5) .
  430. padLeft($company->averageSalaryPerPages, $col6) . "\n";
  431.  
  432. echo padRight($company->total, $col1) .
  433. padLeft($company->totalPersonelAmount, $col2) .
  434. padLeft($company->totalSalary, $col3) .
  435. padLeft($company->totalCoffe, $col4) .
  436. padLeft($company->totalDocumentation, $col5) .
  437. padLeft($company->totalSalaryPerPages, $col6)."\n\n";
  438. }
  439. printData($departments, $company, 0);
Success #stdin #stdout 0.03s 52432KB
stdin
Standard input is empty
stdout
Департамент            сотр.       тугр.        кофе        стр.  тугр./стр.
--------------------------------------------------------------------------------
Закупок                   17      9612.5         350        3100         3.1
Продаж                    24       13550         610        3325        4.08
Рекламы                   36       16300         575        5450        2.99
Логистики                 24       11375         425        3850        2.95
--------------------------------------------------------------------------------
Среднее                25.25    12709.38         490         490        3.28
Всего                    101     50837.5        1960        1960       13.12