fork(2) 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 $position;
  27. public $rank;
  28. public $boss;
  29. public $salary;
  30. public $quantity;
  31.  
  32. public function __construct($department, $position, $rank, $boss, $quantity, $rates)
  33. {
  34. if ($rank == 1){
  35. $factor = 1;
  36. }elseif($rank == 2){
  37. $factor = 1.25;
  38. }elseif($rank == 3){
  39. $factor = 1.5;
  40. }
  41. $this->department = $department;
  42. $this->position = $position;
  43. $this->rank = $rank;
  44. $this->boss = $boss;
  45. if ($this->boss == true){
  46. $this->salary = ($rates[$position] * $factor) * 1.5;
  47. }else{
  48. $this->salary = $rates[$position] * $factor;
  49. }
  50. $this->quantity = $quantity;
  51. }
  52. }
  53.  
  54. class Department
  55. {
  56. public $departmentName;
  57. public $personelAmount;
  58. public $departmentSalary;
  59. public $departmentCoffe;
  60. public $departmentDocumentation;
  61. public $salaryPerPages;
  62.  
  63. public function __construct($employees, $coffe, $documentation)
  64. {
  65. foreach ($employees as $employee)
  66. {
  67. $this->departmentName = $employee->department;
  68.  
  69. $this->personelAmount = $employee->quantity + $this->personelAmount;
  70. $this->departmentSalary = $employee->salary + $this->departmentSalary;
  71. if ($employee->boss == true){
  72. $this->departmentCoffe = $coffe[$employee->position] * 2 + $this->departmentCoffe;
  73. $this->departmentDocumentation = 0 + $this->departmentDocumentation;
  74. }else{
  75. $this->departmentCoffe = $coffe[$employee->position] + $this->departmentCoffe;
  76. $this->departmentDocumentation = $documentation[$employee->position] + $this->departmentDocumentation ;
  77. }
  78. }$this->salaryPerPages = round($this->departmentSalary / $this->departmentDocumentation, 2);
  79. }
  80. }
  81.  
  82. class Company
  83. {
  84. public $total = 'Всего';
  85. public $totalPersonelAmount;
  86. public $totalSalary;
  87. public $totalCoffe;
  88. public $totalDocumentation;
  89. public $totalSalaryPerPages;
  90.  
  91. public $average = 'Среднее';
  92. public $averagePersonelAmount;
  93. public $averageSalary;
  94. public $averageCoffe;
  95. public $averageDocumentation;
  96. public $averageSalaryPerPages;
  97.  
  98. public function __construct($departments)
  99. {
  100. foreach ($departments as $department)
  101. {
  102. $this->totalPersonelAmount = $department->personelAmount + $this->totalPersonelAmount;
  103. $this->totalSalary = $department->departmentSalary + $this->totalSalary;
  104. $this->totalCoffe = $department->departmentCoffe + $this->totalCoffe;
  105. $this->totalDocumentation = $department->departmentDocumentation + $this->totalDocumentation;
  106. $this->totalSalaryPerPages = $department->salaryPerPages + $this->totalSalaryPerPages;
  107. }
  108. $this->averagePersonelAmount = $this->totalPersonelAmount / count($departments);
  109. $this->averageSalary = round($this->totalSalary / count($departments), 2);
  110. $this->averageCoffe = round($this->totalCoffe / count($departments), 2);
  111. $this->averageDocumentation = round($this->totalDocumentation / count($departments), 2);
  112. $this->averageSalaryPerPages = round($this->totalSalaryPerPages / count($departments), 2);
  113. }
  114. }
  115.  
  116. function padRight($q, $w){
  117. return implode("", (array_merge(preg_split('//u', $q, 0, PREG_SPLIT_NO_EMPTY), array_fill(0, $w-mb_strlen($q), " "))));
  118. }
  119. function padLeft($q, $w){
  120. return implode("", (array_merge(array_fill(0, $w-mb_strlen($q), " "), preg_split('//u', $q, 0, PREG_SPLIT_NO_EMPTY))));
  121. }
  122.  
  123. $workers1 = array(
  124. new Employees ('Закупок', 'Me', 1, false, 9, $rates),
  125. new Employees ('Закупок', 'Me', 2, false, 3, $rates),
  126. new Employees ('Закупок', 'Me', 3, false, 2, $rates),
  127. new Employees ('Закупок', 'Ma', 1, false, 1, $rates),
  128. new Employees ('Закупок', 'Me', 2, true, 1, $rates)
  129. );
  130. $workers2 = array(
  131. new Employees ('Продаж', 'Me', 1, false, 12, $rates),
  132. new Employees ('Продаж', 'Ma', 1, false, 6, $rates),
  133. new Employees ('Продаж', 'An', 1, false, 3, $rates),
  134. new Employees ('Продаж', 'An', 2, false, 2, $rates),
  135. new Employees ('Продаж', 'Ma', 2, true, 1, $rates)
  136. );
  137. $workers3 = array(
  138. new Employees ('Рекламы', 'Ma', 1, false, 15, $rates),
  139. new Employees ('Рекламы', 'Ma', 2, false, 10, $rates),
  140. new Employees ('Рекламы', 'Me', 1, false, 8, $rates),
  141. new Employees ('Рекламы', 'En', 1, false, 2, $rates),
  142. new Employees ('Рекламы', 'Ma', 3, true, 1, $rates)
  143. );
  144. $workers4 = array(
  145. new Employees ('Логистики', 'Me', 1, false, 13, $rates),
  146. new Employees ('Логистики', 'Me', 2, false, 5, $rates),
  147. new Employees ('Логистики', 'En', 1, false, 5, $rates),
  148. new Employees ('Логистики', 'Me', 1, true, 1, $rates)
  149. );
  150.  
  151. $departments = array(
  152. new Department($workers1, $coffe, $documentation),
  153. new Department($workers2, $coffe, $documentation),
  154. new Department($workers3, $coffe, $documentation),
  155. new Department($workers4, $coffe, $documentation)
  156. );
  157. $company = new Company ($departments);
  158.  
  159. $col1 = 20;
  160. $col2 = 8;
  161. $col3 = 10;
  162. $col4 = 8;
  163. $col5 = 8;
  164. $col6 = 12;
  165.  
  166. echo padRight("Департамент", $col1) .
  167. padLeft("сотр.", $col2) .
  168. padLeft("тугр.", $col3) .
  169. padLeft("кофе", $col4) .
  170. padLeft("стр.", $col5) .
  171. padLeft("тугр./стр.", $col6) . "\n" .
  172. implode("", array_fill(0, 40, '--')) . "\n";
  173.  
  174. foreach ($departments as $department) {
  175. echo padRight($department->departmentName, $col1) .
  176. padLeft($department->personelAmount, $col2) .
  177. padLeft($department->departmentSalary, $col3) .
  178. padLeft($department->departmentCoffe, $col4) .
  179. padLeft($department->departmentDocumentation, $col5) .
  180. padLeft($department->salaryPerPages, $col6) . "\n" ;
  181.  
  182. } echo implode("", array_fill(0, 40, '--')) . "\n";
  183.  
  184. echo padRight($company->average, $col1) .
  185. padLeft($company->averagePersonelAmount, $col2) .
  186. padLeft($company->averageSalary, $col3) .
  187. padLeft($company->averageCoffe, $col4) .
  188. padLeft($company->averageDocumentation, $col5) .
  189. padLeft($company->averageSalaryPerPages, $col6) . "\n";
  190.  
  191. echo padRight($company->total, $col1) .
  192. padLeft($company->totalPersonelAmount, $col2) .
  193. padLeft($company->totalSalary, $col3) .
  194. padLeft($company->totalCoffe, $col4) .
  195. padLeft($company->totalDocumentation, $col5) .
  196. padLeft($company->totalSalaryPerPages, $col6);
  197.  
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
Департамент            сотр.     тугр.    кофе    стр.  тугр./стр.
--------------------------------------------------------------------------------
Закупок                   16    3212.5     115     750        4.28
Продаж                    24      3450     165     360        9.58
Рекламы                   36      2500      85     550        4.55
Логистики                 24      2075      85     450        4.61
--------------------------------------------------------------------------------
Среднее                   25   2809.38   112.5   527.5        5.76
Всего                    100   11237.5     450    2110       23.02