<?php
/**
 * Created by PhpStorm.
 * User: Саша Поляны
 * Date: 07.04.2016
 * Time: 16:07
 */

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

class Employee{
    public $department;
    public $profession;
    public $coffee;
    public $rank;
    public $boss;
    public $pages;
    public $salary;
    public $rate;

    public function __construct($department, $profession, $coffee, $boss, $rank, $pages, $basicSalary)
    {
        $this->department = $department;
        $this->profession = $profession;
        $this->coffee = $coffee;
        $this->rank = $rank;
        $this->boss = $boss;
        $this->pages = $pages;
        $this->basicSalary = $basicSalary;
    }

    public function getRate()
    {
        if ($this->boss == true) {
            $bossRank = 1.5;
        } else {
            $bossRank = 1;
        }
        if ($this->rank == 1) {
            $this->rate = 1;
        } elseif ($this->rank == 2) {
            $this->rate = 1.25;
        } elseif ($this->rank == 3) {
            $this->rate = 1.5;
        }
        $this->rate *= $bossRank;
        return $this->rate;
    }
    public function getSalary()
    {
        $this->salary = $this->basicSalary * $this->getRate();
        return $this->salary;
    }
    public function getPages()
    {
        $pages = $this->pages;
        return $pages;
    }
    public function getCoffee()
    {
        $coffee = $this->coffee;
        return $coffee;
    }
}
function padLeft($string, $widthOfTableCell){
    $lengthOfString = mb_strlen($string);
    $missingSpaces = $widthOfTableCell - $lengthOfString;
    $tableCell = $string . str_repeat(" ", $missingSpaces);
    return $tableCell;
}
function padRight($string, $widthOfTableCell){
    $lengthOfString = mb_strlen($string);
    $missingSpaces = $widthOfTableCell - $lengthOfString;
    $tableCell = str_repeat(" ", $missingSpaces) . $string;
    return $tableCell;
}
$col1 = 15;
$col2 = $col3 = $col4 = $col5 = $col6 = 12;

$employeesPurchaseDepartment = [];
for ($i = 1; $i <= 9; $i++) {
    $employeesPurchaseDepartment[] = new Employee('Закупки', 'Me', 20, false, 1, 200, 500);
}
for ($i = 1; $i <= 3; $i++) {
    $employeesPurchaseDepartment[] = new Employee('Закупки', 'Me', 20, false, 2, 200, 500);
}
for ($i = 1; $i <= 2; $i++) {
    $employeesPurchaseDepartment[] = new Employee('Закупки', 'Me', 20, false, 3, 200, 500);
}
for ($i = 1; $i <= 2; $i++) {
    $employeesPurchaseDepartment[] = new Employee('Закупки', 'Ma', 15, false, 2, 150, 400);
}
for ($i = 1; $i <= 1; $i++) {
    $employeesPurchaseDepartment[] = new Employee('Закупки', 'Me', 20, true, 2, 200, 500);
}

function getIndex($employees)
{
    $salary = 0;
    $pages = 0;
    $coffee = 0;
    $department = 0;
    $employeesNumber = 0;
    $index = [];
    for ($i = 0; $i < count($employees); $i++) {
        $salary += $employees[$i]->getSalary();
        $pages += $employees[$i]->getPages();
        $coffee += $employees[$i]->getCoffee();
    }
    $department = $employees[$i - 1]->department;
    $employeesNumber = count($employees);
    $index = array(
    'salary' => $salary,
    'pages' => $pages,
    'coffee' => $coffee,
    'department' => $department,
    'employeesNumber' => $employeesNumber
    );
    return $index;
}
$purchaseDepartment = getIndex($employeesPurchaseDepartment);

// Заголовок таблицы
echo padLeft("Департамент", $col1) .
    padRight("сотр.", $col2) .
    padRight("тугр.", $col3) .
    padRight("кофе", $col4) .
    padRight("стр.", $col5) .
    padRight("тугр./стр.", $col6) ."\n";

// Сама таблица
echo padLeft($purchaseDepartment['department'], $col1) .
    padRight($purchaseDepartment['employeesNumber'], $col2) .
    padRight($purchaseDepartment['salary'], $col3) .
    padRight($purchaseDepartment['coffee'], $col4) .
    padRight($purchaseDepartment['pages'], $col5) .
    padRight(0, $col6) . "\n";