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