<?php

class Employee
{
    public $salary;
    public $coffee;
    public $pages;
    public $rank;

    public function __construct($profession, $rank = 1)
    {
        switch ($profession) {
            case 'manager':
                $this->salary = 500 * $rank;
                $this->pages = 200;
                $this->coffee = 20;
                $this->rank = $rank;
                break;
            case 'engineer':
                $this->salary = 200 * $rank;
                $this->pages = 50;
                $this->coffee = 5;
                $this->rank = $rank;
                break;
            case 'analyst':
                $this->salary = 800 * $rank;
                $this->pages = 5;
                $this->coffee = 50;
                $this->rank = $rank;
                break;
            case 'marketer':
                $this->salary = 400 * $rank;
                $this->pages = 150;
                $this->coffee = 15;
                $this->rank = $rank;
                break;
            default: exit("Profession \"$profession\" not found.");
        }
    }
}

class Report
{
    public $departmentName;
    public $salary;
    public $coffee;
    public $pages;
    public $employeeCount;
}

class Department
{
    public $employees;
    public $name;

    public function __construct(array $employees, $name)
    {
        $this->employees = $employees;
        $this->name = $name;
    }

    public function getReport()
    {
        $report = new Report;
        foreach ($this->employees as $employee) {
            $report->salary += $employee[0]->salary * $employee[1];
            $report->coffee += $employee[0]->coffee * $employee[1];
            $report->pages += $employee[0]->pages * $employee[1];
            $report->employeeCount += $employee[1];
        }
        $report->departmentName = $this->name;
        return $report;
    }
}

$manager1 = new Employee('manager', 1);
$manager2 = new Employee('manager', 1.25);
$manager3 = new Employee('manager', 1.5);
$marketer1 = new Employee('marketer', 1);
$marketer2 = new Employee('marketer', 1.25);
$analyst1 = new Employee('analyst', 1);
$analyst2 = new Employee('analyst', 1.25);
$engineer1 = new Employee('engineer', 1);

$procurement = new Department(array(
    array($manager1, 9),
    array($manager2, 3),
    array($manager3, 2),
    array($marketer1, 2),
), 'Закупок');

$selling = new Department(array(
    array($manager1, 12),
    array($marketer1, 6),
    array($analyst1, 3),
    array($analyst2, 2),
), 'Продаж');

$advertisement = new Department(array(
    array($marketer1, 15),
    array($marketer2, 10),
    array($manager1, 8),
    array($engineer1, 2),
), 'Рекламы');

$logistics = new Department(array(
    array($manager1, 13),
    array($manager2, 5),
    array($engineer1, 5),
), 'Логистики');

foreach (array($procurement, $selling, $advertisement, $logistics) as $department) {
    $summary[] = $department->getReport();
}

echo "Департамент:\t\tсотр.\t\tтугр.\t\tкофе\t\tстр.\t\tтугр./стр.\n";
echo "--------------------------------------------------------------------------------------\n";
foreach ($summary as $report) {
    echo "$report->departmentName\t\t\t\t$report->employeeCount\t\t$report->salary\t\t$report->coffee\t\t$report->pages\t\t";
    echo round($report->salary / $report->pages, 1);
    echo "\n";
}
