Guest User

Untitled

a guest
Jul 9th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.59 KB | None | 0 0
  1. <?php
  2.  
  3. // archive-ipq-co.narod.ru
  4. error_reporting(-1);
  5.  
  6. abstract class Worker
  7. {
  8.     public $ranks=[1=>1,2=>1.25,3=>1.5];
  9.     public $rank=1;
  10.     public $baseSalary;
  11.     public $coffeeRate;
  12.     public $reportRate;
  13.     public $isBoss = false;
  14.  
  15.     public function getSalary()
  16.     {
  17.         $salary = $this->baseSalary * $this->ranks[$this->rank];
  18.         if($this->isBoss)
  19.         {
  20.             return $salary*1.5;
  21.         }
  22.         else
  23.         {
  24.             return $salary;
  25.         }
  26.     }
  27.     public function getCoffee()
  28.     {
  29.         if($this->isBoss)
  30.         {
  31.             return $this->coffeeRate*2;
  32.         }
  33.         else
  34.         {
  35.             return $this->coffeeRate;
  36.         }
  37.  
  38.     }
  39.     public function getReport()
  40.     {
  41.         if($this->isBoss)
  42.         {
  43.             return 0;
  44.         }
  45.         else
  46.         {
  47.             return $this->reportRate;
  48.         }
  49.     }
  50.  
  51. }
  52.  
  53. class Manager extends Worker
  54. {
  55.     public $baseSalary = 500;
  56.     public $coffeeRate = 20;
  57.     public $reportRate = 200;
  58.  
  59. }
  60. class Marketer extends Worker
  61. {
  62.     public $baseSalary = 400;
  63.     public $coffeeRate = 15;
  64.     public $reportRate = 150;
  65. }
  66. class Engineer extends Worker
  67. {
  68.     public $baseSalary = 200;
  69.     public $coffeeRate = 5;
  70.     public $reportRate = 50;
  71. }
  72. class Analyst extends Worker
  73. {
  74.     public $baseSalary = 800;
  75.     public $coffeeRate = 50;
  76.     public $reportRate = 5;
  77. }
  78. //количество должность ранг босс
  79. class Department{
  80.     public $positions = ['man'=>'Manager','mar'=>'Marketer','eng'=>'Engineer','ana'=>'Analyst'];
  81.     public $workers = [];
  82.     public $salary = 0;
  83.     public $coffee = 0;
  84.     public $report = 0;
  85.     public $workersNumber = 0;
  86.     public function createWorkers($workerTypes)
  87.     {
  88.         foreach ($workerTypes as $workerType)
  89.         {
  90.             $title = [];
  91.             array_push($title, $workerType[0]);
  92.             $employee = new $this->positions[$workerType[1]];
  93.             $employee->rank = $workerType[2];
  94.             if ($workerType[3] == 1) {
  95.                 $employee->isBoss = true;
  96.             }
  97.             array_push($title, $employee);
  98.             array_push($this->workers, $title);
  99.         }
  100.     }
  101.     public function getDepartmentCost()
  102.     {
  103.         foreach ($this->workers as $worker)
  104.         {
  105.             $this->salary += $worker[1]->getSalary()*$worker[0];
  106.             $this->coffee += $worker[1]->getCoffee()*$worker[0];
  107.             $this->report += $worker[1]->getReport()*$worker[0];
  108.         }
  109.         return [$this->salary,$this->coffee,$this->report];
  110.     }
  111.     public function getWorkersNumber()
  112.     {
  113.         foreach ($this->workers as $workerType)
  114.         {
  115.             $this->workersNumber += $workerType[0];
  116.         }
  117.         return $this->workersNumber;
  118.     }
  119.     public function getCostPerPage()
  120.     {
  121.         $cost = $this->getDepartmentCost();
  122.         $number = $this->getWorkersNumber();
  123.         return round($cost[0]/$number,1);
  124.     }
  125. }
  126. class Company
  127. {
  128.     public $departments = [];
  129.     public function createDepartment($workers)
  130.     {
  131.         $dep = new Department();
  132.         $dep->createWorkers($workers);
  133.         array_push($this->departments,$dep);
  134.     }
  135.  
  136.     public function displayDepartmentsCosts($names)
  137.     {
  138.         $i = 0;
  139.         foreach($this->departments as $department)
  140.         {
  141.             $depWorkers = $department->getWorkersNumber();
  142.             $costs = $department->getDepartmentCost();
  143.             $costPerPage = $department->getCostPerPage();
  144.             echo '<tr><td>'.$names[$i].'</td><td>'.$depWorkers.'</td><td>'.$costs[0].'</td><td>'.$costs[1].'</td><td>'.$costs[2].'</td><td>'.$costPerPage.'</td></tr>';
  145.             $i++;
  146.         }
  147.     }
  148. }
  149.  
  150.  
  151. $suppDepWorkers = [[9,'man',1,0],[3,'man',2,0],[2,'man',3,0],[2,'mar',1,0],[1,'man',2,1]];
  152. $sellDepWorkers = [[12,'man',1,0],[6,'mar',2,0],[3,'ana',1,0],[2,'ana',2,0],[1,'mar',2,1]];
  153. $advertDepWorkers = [[15,'mar',1,0],[10,'mar',2,0],[8,'man',1,0],[2,'eng',1,0],[1,'mar',3,1]];
  154. $logDepWorkers = [[13,'man',1,0],[5,'man',2,0],[5,'eng',1,0],[1,'man',1,1]];
  155. $departments = [$suppDepWorkers,$sellDepWorkers,$advertDepWorkers,$logDepWorkers];
  156. $names = ['Поставок','Продаж','Рекламы','Логистики'];
  157. $com = new Company();
  158.  
  159. foreach ($departments as $department)
  160. {
  161.     $com->createDepartment($department);
  162. }
  163.  
  164. echo '<table border="1">';
  165. echo '<tr><th>Департамент</th><th>Сотрудники</th><th>Тугрики</th><th>Кофе</th><th>Страницы</th><th>Туг/Стр</th></tr>';
  166. $com->displayDepartmentsCosts($names);
  167. echo '</table>';
Add Comment
Please, Sign In to add comment