<?php

error_reporting(-1);
mb_internal_encoding('utf-8');

class Company
{
	private $departments = array();
	
	public function setDepartments($departments)
	{
		$this->departments = $departments;
	}
	
}

class Department
{
	private $employees = array();
	
	public function setEmployees($employees)
	{
		$this->employees = $employees;
	}
	
	public function getEmployees()
	{
		return $this->employees;
	}
	
	public function getTotalSalary()
	{
		$totalSalary = 0;
		
		foreach($this->employees as $employee) {
			$totalSalary += $employee->getSalary();
		}
		return $totalSalary;
	}
	
	public function getTotalCoffeeConsumption()
	{
		$totalCoffeeConsumption = 0;
		
		foreach($this->employees as $employee) {
			$totalCoffeeConsumption += $employee->getCoffeeConsumption();
		}
		return $totalCoffeeConsumption;
	}
	
	public function getTotalProduction()
	{
		$totalProduction = 0;
		
		foreach($this->employees as $employee) {
			$totalProduction += $employee->getProduction();
		}
		return $totalProduction;
	}
}

abstract class Employee
{
	protected $baseRate;
	protected $rank;
	protected $isBoss;
	
	abstract protected function getBaseCoffeeConsumption();
	abstract protected function getBaseRate();
	abstract protected function getBaseProduction();
	
	public function __construct($rank, $isBoss = false)
	{
		$this->rank = $rank;
		$this->isBoss = $isBoss;
	}
	
	public function getSalary()
	{
		$salary = 0;
		
		if($this->rank == 1) {
			$salary = $this->getBaseRate();
		} elseif($this->rank == 2) {
			$salary = $this->getBaseRate() * 1.25;
		} elseif($this->rank == 3) {
			$salary = $this->getBaseRate() * 1.5;
		}
		
		if($this->isBoss) {
			$salary *= 1.5;
		}
		
		return $salary;
	}
	
	public function getCoffeeConsumption()
	{
		$coffee = $this->getBaseCoffeeConsumption();
		
		if($this->isBoss) {
			$coffee *= 2;
		}
		
		return $coffee;
	}
	
	public function getProduction()
	{
		$production = $this->getBaseProduction();
		
		if($this->isBoss) {
			$production = 0;
		}
		return $production;
	}
}

class Manager extends Employee
{
	protected function getBaseCoffeeConsumption()
	{
		return 20;
	}
	
	protected function getBaseRate()
	{
		return 500;
	}
	
	protected function getBaseProduction()
	{
		return 200;
	}
}

class Engineer extends Employee
{
	protected function getBaseCoffeeConsumption()
	{
		return 5;
	}
	
	protected function getBaseRate()
	{
		return 200;
	}
	
	protected function getBaseProduction()
	{
		return 50;
	}
	
}

class Analyst extends Employee
{
	protected function getBaseCoffeeConsumption()
	{
		return 50;
	}
	
	protected function getBaseRate()
	{
		return 800;
	}
	
	protected function getBaseProduction()
	{
		return 5;
	}
}

class Marketer extends Employee
{
	protected function getBaseCoffeeConsumption()
	{
		return 15;
	}
	
	protected function getBaseRate()
	{
		return 400;
	}
	
	protected function getBaseProduction()
	{
		return 150;
	}
}

$col1 = 20;
$col2 = 8;
$col3 = 8;
$col4 = 8;
$col5 = 8;
$col6 = 8;

function padRight($string, $length)
{
	$padding = $length - mb_strlen($string);
	$string .= str_repeat(" ", $padding);
	return $string;
}

function padLeft($string, $length) 
{
	$padding = $length - mb_strlen($string)+2;
	$string = str_repeat(" ", $padding) . $string;
	return $string;
}

$procurement = new Department;
$emps = array();
for($i = 0; $i < 9; $i++) {
	$emps[] = new Manager(1);
}
for($i = 0; $i < 3; $i++) {
	$emps[] = new Manager(2);
}
for($i = 0; $i < 2; $i++) {
	$emps[] = new Manager(3);
}
for($i = 0; $i < 2; $i++) {
	$emps[] = new Marketer(1);
}
$emps[] = new Manager(2, true);
$procurement->setEmployees($emps);
echo "Всего сотрудников: " . count($procurement->getEmployees()) . "\n";
echo "Всего выдано зп: " . $procurement->getTotalSalary() . "\n";
echo "Всего выпито кофе: " . $procurement->getTotalCoffeeConsumption() . "\n";
echo "Всего произведено страниц отчетов: " . $procurement->getTotalProduction() . "\n"; 



echo padRight('Департамент', $col1) . 
padLeft('сотр.', $col2) . 
padLeft('тугр.', $col3) . 
padLeft('кофе', $col4) . 
padLeft('стр.', $col5) .
padLeft('тугр/стр', $col6) . '\n\n';