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 * $quantity;
  47. } else {
  48. $this->salary = ($rates[$position] * $factor) * $quantity;
  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. $this->departmentName = $employee->department;
  67.  
  68. $this->personelAmount = $employee->quantity + $this->personelAmount;
  69. $this->departmentSalary = $employee->salary + $this->departmentSalary;
  70. if ($employee->boss == true) {
  71. $this->departmentCoffe = ($coffe[$employee->position] * 2) * $employee->quantity + $this->departmentCoffe;
  72. $this->departmentDocumentation = 0 + $this->departmentDocumentation;
  73. } else {
  74. $this->departmentCoffe = ($coffe[$employee->position] * $employee->quantity) + $this->departmentCoffe;
  75. $this->departmentDocumentation = ($documentation[$employee->position] * $employee->quantity) + $this->departmentDocumentation;
  76. }
  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. $this->totalPersonelAmount = $department->personelAmount + $this->totalPersonelAmount;
  102. $this->totalSalary = $department->departmentSalary + $this->totalSalary;
  103. $this->totalCoffe = $department->departmentCoffe + $this->totalCoffe;
  104. $this->totalDocumentation = $department->departmentDocumentation + $this->totalDocumentation;
  105. $this->totalSalaryPerPages = $department->salaryPerPages + $this->totalSalaryPerPages;
  106. }
  107. $this->averagePersonelAmount = $this->totalPersonelAmount / count($departments);
  108. $this->averageSalary = round($this->totalSalary / count($departments), 2);
  109. $this->averageCoffe = round($this->totalCoffe / count($departments), 2);
  110. $this->averageDocumentation = round($this->totalDocumentation / count($departments), 2);
  111. $this->averageSalaryPerPages = round($this->totalSalaryPerPages / count($departments), 2);
  112. }
  113. }
  114.  
  115. function padRight($q, $w)
  116. {
  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. {
  121. return implode("", (array_merge(array_fill(0, $w - mb_strlen($q), " "), preg_split('//u', $q, 0, PREG_SPLIT_NO_EMPTY))));
  122. }
  123.  
  124. $workers1 = array(
  125. new Employees('Закупок', 'Me', 1, false, 9, $rates),
  126. new Employees('Закупок', 'Me', 2, false, 3, $rates),
  127. new Employees('Закупок', 'Me', 3, false, 2, $rates),
  128. new Employees('Закупок', 'Ma', 1, false, 2, $rates),
  129. new Employees('Закупок', 'Me', 2, true, 1, $rates)
  130. );
  131. $workers2 = array(
  132. new Employees('Продаж', 'Me', 1, false, 12, $rates),
  133. new Employees('Продаж', 'Ma', 1, false, 6, $rates),
  134. new Employees('Продаж', 'An', 1, false, 3, $rates),
  135. new Employees('Продаж', 'An', 2, false, 2, $rates),
  136. new Employees('Продаж', 'Ma', 2, true, 1, $rates)
  137. );
  138. $workers3 = array(
  139. new Employees('Рекламы', 'Ma', 1, false, 15, $rates),
  140. new Employees('Рекламы', 'Ma', 2, false, 10, $rates),
  141. new Employees('Рекламы', 'Me', 1, false, 8, $rates),
  142. new Employees('Рекламы', 'En', 1, false, 2, $rates),
  143. new Employees('Рекламы', 'Ma', 3, true, 1, $rates)
  144. );
  145. $workers4 = array(
  146. new Employees('Логистики', 'Me', 1, false, 13, $rates),
  147. new Employees('Логистики', 'Me', 2, false, 5, $rates),
  148. new Employees('Логистики', 'En', 1, false, 5, $rates),
  149. new Employees('Логистики', 'Me', 1, true, 1, $rates)
  150. );
  151.  
  152. $departments = array(
  153. new Department($workers1, $coffe, $documentation),
  154. new Department($workers2, $coffe, $documentation),
  155. new Department($workers3, $coffe, $documentation),
  156. new Department($workers4, $coffe, $documentation)
  157. );
  158. $company = new Company($departments);
  159.  
  160. $col1 = 20;
  161. $col2 = 8;
  162. $col3 = 12;
  163. $col4 = 12;
  164. $col5 = 12;
  165. $col6 = 12;
  166.  
  167. echo padRight("Департамент", $col1) .
  168. padLeft("сотр.", $col2) .
  169. padLeft("тугр.", $col3) .
  170. padLeft("кофе", $col4) .
  171. padLeft("стр.", $col5) .
  172. padLeft("тугр./стр.", $col6) . "\n" .
  173. implode("", array_fill(0, 40, '--')) . "\n";
  174.  
  175. foreach ($departments as $department) {
  176. echo padRight($department->departmentName, $col1) .
  177. padLeft($department->personelAmount, $col2) .
  178. padLeft($department->departmentSalary, $col3) .
  179. padLeft($department->departmentCoffe, $col4) .
  180. padLeft($department->departmentDocumentation, $col5) .
  181. padLeft($department->salaryPerPages, $col6) . "\n" ;
  182.  
  183. } echo implode("", array_fill(0, 40, '--')) . "\n";
  184.  
  185. echo padRight($company->average, $col1) .
  186. padLeft($company->averagePersonelAmount, $col2) .
  187. padLeft($company->averageSalary, $col3) .
  188. padLeft($company->averageCoffe, $col4) .
  189. padLeft($company->averageDocumentation, $col5) .
  190. padLeft($company->averageSalaryPerPages, $col6) . "\n";
  191.  
  192. echo padRight($company->total, $col1) .
  193. padLeft($company->totalPersonelAmount, $col2) .
  194. padLeft($company->totalSalary, $col3) .
  195. padLeft($company->totalCoffe, $col4) .
  196. padLeft($company->totalDocumentation, $col5) .
  197. padLeft($company->totalSalaryPerPages, $col6);
  198.  
Success #stdin #stdout 0.03s 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