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

                            Анти-кризисная мера #1
--------------------------------------------------------------------------------
Закупок                   17      9612.5         350        3100         3.1
Продаж                    24       13550         610        3325        4.08
Рекламы                   35       16100         570        5400        2.98
Логистики                 22       10975         415        3750        2.93
--------------------------------------------------------------------------------
Среднее                 24.5    12559.38      486.25     3893.75        3.27
Всего                     98     50237.5        1945       15575       13.09

                            Анти-кризисная мера #2
--------------------------------------------------------------------------------
Закупок                   17      9612.5         350        3100         3.1
Продаж                    24     15637.5         795        3470        4.51
Рекламы                   36       16300         575        5450        2.99
Логистики                 24       11375         425        3850        2.95
--------------------------------------------------------------------------------
Среднее                25.25    13231.25      536.25      3967.5        3.39
Всего                    101       52925        2145       15870       13.55

                            Анти-кризисная мера #3
--------------------------------------------------------------------------------
Закупок                   17       10550         350        3100         3.4
Продаж                    24       14300         610        3325         4.3
Рекламы                   36       16800         575        5450        3.08
Логистики                 24     12687.5         425        3850         3.3
--------------------------------------------------------------------------------
Среднее                25.25    13584.38         490     3931.25        3.52
Всего                    101     54337.5        1960       15725       14.08