<?php
abstract class Employee
{
public $salary;
public $pages;
public $cofee;
public $name;
function __construct($rank)
{
$this->rank = $rank;
}
function getSalary()
{
$multiply = 1;
switch ($this->rank) {
case 2:
$multiply = 1.25;
break;
case 3:
$multiply = 1.50;
break;
}
return $this->salary * $multiply;
}
function setHead()
{
$this->salary = $this->salary * 1.50;
$this->cofee = $this->cofee * 2;
$this->pages = 0;
}
}
class Manager extends Employee
{
public $name = "Менеджер";
public $salary = 500;
public $cofee = 20;
public $pages = 200;
}
class Market extends Employee
{
public $name = "Маркетолог";
public $salary = 400;
public $cofee = 15;
public $pages = 150;
}
class Engineer extends Employee
{
public $name = "Инженер";
public $salary = 200;
public $cofee = 5;
public $pages = 50;
}
class Analyst extends Employee
{
public $name = "Аналитик";
public $salary = 800;
public $cofee = 50;
public $pages = 5;
}
class Department
{
function workers()
{
return count($this->data) - 1; }
function cofee()
{
$cofee = 0;
foreach ($this->data as $key => $worker) {
if ($key === 'name') {
continue;
}
$cofee += $worker->cofee;
}
return $cofee;
}
function costs()
{
$costs = 0;
foreach ($this->data as $key => $worker) {
if ($key === 'name') {
continue;
}
$costs += $worker->getSalary();
}
return $costs;
}
function pages()
{
$pages = 0;
foreach ($this->data as $key => $worker) {
if ($key === 'name') {
continue;
}
$pages += $worker->pages;
}
return $pages;
}
function __construct($data)
{
$this->data = $data;
$this->name = $data['name'];
}
}
function createEmployee($type, $rank, $quantity, $array)
{
for ($i = 0; $i < $quantity; $i++) {
$array[] = new $type($rank);
}
return $array;
}
function padRight($name, $col)
{
$name .= " ";
}
return $name;
}
function padLeft($name, $col)
{
$name = " " . $name;
}
return $name;
}
function createDepartment($data)
{
$department = new Department($data);
$costPerPage = round(($department->costs()) / ($department->pages()), 1);
echo padRight($department->name, 20);
echo padLeft($department->workers(), 10);
echo padLeft($department->costs(), 12);
echo padLeft($department->cofee(), 10);
echo padLeft($department->pages(), 12);
echo padLeft($costPerPage, 15);
echo "\n";
}
$department1['name'] = "Закупок";
$department1 = createEmployee('Manager', 1, 9, $department1);
$department1 = createEmployee('Manager', 2, 3, $department1);
$department1 = createEmployee('Manager', 3, 2, $department1);
$department1 = createEmployee('Market', 1, 2, $department1);
$department1['head'] = new Manager(2);
$department1['head']->setHead();
$department2['name'] = "Продаж";
$department2 = createEmployee('Manager', 1, 12, $department2);
$department2 = createEmployee('Market', 1, 6, $department2);
$department2 = createEmployee('Analyst', 1, 3, $department2);
$department2 = createEmployee('Analyst', 2, 2, $department2);
$department2['head'] = new Market(2);
$department2['head']->setHead();
$department3['name'] = "Рекламы";
$department3 = createEmployee('Market', 1, 15, $department3);
$department3 = createEmployee('Market', 2, 10, $department3);
$department3 = createEmployee('Manager', 1, 8, $department3);
$department3 = createEmployee('Engineer', 1, 2, $department3);
$department['head'] = new Market(3);
$department['head']->setHead();
echo padRight("Департамент", 30) . padLeft("Сотр.", 10) . padLeft("тугр.", 15) . padLeft("кофе", 15) . padLeft("стр.", 15) . padLeft("тугр./стр.", 25) . "\n";
createDepartment($department1);
createDepartment($department2);
createDepartment($department3);
PD9waHAKCmFic3RyYWN0IGNsYXNzIEVtcGxveWVlCnsKICAgIAogICAgcHVibGljICRzYWxhcnk7CiAgICBwdWJsaWMgJHBhZ2VzOwogICAgcHVibGljICRjb2ZlZTsKICAgIHB1YmxpYyAkbmFtZTsKICAgIAogICAgCiAgICBmdW5jdGlvbiBfX2NvbnN0cnVjdCgkcmFuaykKICAgIHsKICAgICAgICAKICAgICAgICAKICAgICAgICAkdGhpcy0+cmFuayA9ICRyYW5rOwogICAgfQogICAgCiAgICBmdW5jdGlvbiBnZXRTYWxhcnkoKQogICAgewogICAgICAgICRtdWx0aXBseSA9IDE7CiAgICAgICAgc3dpdGNoICgkdGhpcy0+cmFuaykgewogICAgICAgICAgICBjYXNlIDI6CiAgICAgICAgICAgICAgICAkbXVsdGlwbHkgPSAxLjI1OwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMzoKICAgICAgICAgICAgICAgICRtdWx0aX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wdWJsaWMgJHBhZ2VzID0gNTsKfQoKCmNsYXNzIERlcGFydG1lbnQKewogICAgZnVuY3Rpb24gd29ya2VycygpCiAgICB7CiAgICAgICAgcmV0dXJuIGNvdW50KCR0aGlzLT5kYXRhKSAtIDE7CiAgICB9CiAgICBmdW5jdGlvbiBjb2ZlZSgpCiAgICB7CiAgICAgICAgJGNvZmVlID0gMDsKICAgICAgICBmb3JlYWNoICgkdGhpcy0+ZGF0YSBhcyAka2V5ID0+ICR3b3JrZXIpIHsKICAgICAgICAgICAgaWYgKCRrZXkgPT09ICduYW1lJykgewogICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgJGNvZmVlICs9ICR3b3JrZXItPmNvZmVlOwogICAgICAgIH0KICAgICAgICByZXR1cm4gJGNvZmVlOwogICAgfQogICAgZnVuY3Rpb24gY29zdHMoKQogICAgewogICAgICAgICRjb3N0cyA9IDA7CiAgICAgICAgZm9yZWFjaCAoJHRoaXMtPmRhdGEgYXMgJGtleSA9PiAkd29ya2VyKSB7CiAgICAgICAgICAgIGlmICgka2V5ID09PSAnbmFtZScpIHsKICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgICRjb3N0cyArPSAkd29ya2VyLT5nZXRTYWxhcnkoKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuICRjb3N0czsKICAgIH0KICAgIGZ1bmN0aW9uIHBhZ2VzKCkKICAgIHsKICAgICAgICAkcGFnZXMgPSAwOwogICAgICAgIGZvcmVhY2ggKCR0aGlzLT5kYXRhIGFzICRrZXkgPT4gJHdvcmtlcikgewogICAgICAgICAgICBpZiAoJGtleSA9PT0gJ25hbWUnKSB7CiAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICAkcGFnZXMgKz0gJHdvcmtlci0+cGFnZXM7CiAgICAgICAgfQogICAgICAgIHJldHVybiAkcGFnZXM7CiAgICB9CiAgIC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