Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // archive-ipq-co.narod.ru
- error_reporting(-1);
- abstract class Worker
- {
- public $ranks=[1=>1,2=>1.25,3=>1.5];
- public $rank=1;
- public $baseSalary;
- public $coffeeRate;
- public $reportRate;
- public $isBoss = false;
- public function getSalary()
- {
- $salary = $this->baseSalary * $this->ranks[$this->rank];
- if($this->isBoss)
- {
- return $salary*1.5;
- }
- else
- {
- return $salary;
- }
- }
- public function getCoffee()
- {
- if($this->isBoss)
- {
- return $this->coffeeRate*2;
- }
- else
- {
- return $this->coffeeRate;
- }
- }
- public function getReport()
- {
- if($this->isBoss)
- {
- return 0;
- }
- else
- {
- return $this->reportRate;
- }
- }
- }
- class Manager extends Worker
- {
- public $baseSalary = 500;
- public $coffeeRate = 20;
- public $reportRate = 200;
- }
- class Marketer extends Worker
- {
- public $baseSalary = 400;
- public $coffeeRate = 15;
- public $reportRate = 150;
- }
- class Engineer extends Worker
- {
- public $baseSalary = 200;
- public $coffeeRate = 5;
- public $reportRate = 50;
- }
- class Analyst extends Worker
- {
- public $baseSalary = 800;
- public $coffeeRate = 50;
- public $reportRate = 5;
- }
- //количество должность ранг босс
- class Department{
- public $positions = ['man'=>'Manager','mar'=>'Marketer','eng'=>'Engineer','ana'=>'Analyst'];
- public $workers = [];
- public $salary = 0;
- public $coffee = 0;
- public $report = 0;
- public $workersNumber = 0;
- public function createWorkers($workerTypes)
- {
- foreach ($workerTypes as $workerType)
- {
- $title = [];
- array_push($title, $workerType[0]);
- $employee = new $this->positions[$workerType[1]];
- $employee->rank = $workerType[2];
- if ($workerType[3] == 1) {
- $employee->isBoss = true;
- }
- array_push($title, $employee);
- array_push($this->workers, $title);
- }
- }
- public function getDepartmentCost()
- {
- foreach ($this->workers as $worker)
- {
- $this->salary += $worker[1]->getSalary()*$worker[0];
- $this->coffee += $worker[1]->getCoffee()*$worker[0];
- $this->report += $worker[1]->getReport()*$worker[0];
- }
- return [$this->salary,$this->coffee,$this->report];
- }
- public function getWorkersNumber()
- {
- foreach ($this->workers as $workerType)
- {
- $this->workersNumber += $workerType[0];
- }
- return $this->workersNumber;
- }
- public function getCostPerPage()
- {
- $cost = $this->getDepartmentCost();
- $number = $this->getWorkersNumber();
- return round($cost[0]/$number,1);
- }
- }
- class Company
- {
- public $departments = [];
- public function createDepartment($workers)
- {
- $dep = new Department();
- $dep->createWorkers($workers);
- array_push($this->departments,$dep);
- }
- public function displayDepartmentsCosts($names)
- {
- $i = 0;
- foreach($this->departments as $department)
- {
- $depWorkers = $department->getWorkersNumber();
- $costs = $department->getDepartmentCost();
- $costPerPage = $department->getCostPerPage();
- 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>';
- $i++;
- }
- }
- }
- $suppDepWorkers = [[9,'man',1,0],[3,'man',2,0],[2,'man',3,0],[2,'mar',1,0],[1,'man',2,1]];
- $sellDepWorkers = [[12,'man',1,0],[6,'mar',2,0],[3,'ana',1,0],[2,'ana',2,0],[1,'mar',2,1]];
- $advertDepWorkers = [[15,'mar',1,0],[10,'mar',2,0],[8,'man',1,0],[2,'eng',1,0],[1,'mar',3,1]];
- $logDepWorkers = [[13,'man',1,0],[5,'man',2,0],[5,'eng',1,0],[1,'man',1,1]];
- $departments = [$suppDepWorkers,$sellDepWorkers,$advertDepWorkers,$logDepWorkers];
- $names = ['Поставок','Продаж','Рекламы','Логистики'];
- $com = new Company();
- foreach ($departments as $department)
- {
- $com->createDepartment($department);
- }
- echo '<table border="1">';
- echo '<tr><th>Департамент</th><th>Сотрудники</th><th>Тугрики</th><th>Кофе</th><th>Страницы</th><th>Туг/Стр</th></tr>';
- $com->displayDepartmentsCosts($names);
- echo '</table>';
Add Comment
Please, Sign In to add comment