<?php
class Employee{
public $department;
public $profession;
public $coffee;
public $boss;
public $rank;
public $pages;
public $basicSalary;
public $rate;
public $salary;
public function __construct($department, $profession, $boss, $rank)
{
$this->department = $department;
$this->profession = $profession;
$this->rank = $rank;
$this->boss = $boss;
}
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;
}
public function getCoffeeByProfession($coffeeByProfession){
foreach ($coffeeByProfession as $professionName => $coffeeNumber) {
if ($this->profession == $professionName) {
if ($this->boss == true) {
$this->coffee = $coffeeNumber * 2;
break;
} else {
$this->coffee = $coffeeNumber;
break;
}
}
}
return $this->coffee;
}
public function getBasicSalaryByProfession($basicSalaryByProfession){
foreach ($basicSalaryByProfession as $professionName => $salaryAmount) {
if ($this->profession == $professionName) {
$this->basicSalary = $salaryAmount;
break;
}
}
return $this->basicSalary;
}
public function getPagesByProfession($pagesByProfession){
foreach ($pagesByProfession as $professionName => $pagesNumber) {
if ($this->profession == $professionName) {
if ($this->boss == true) {
$this->pages = 0;
break;
} else {
$this->pages = $pagesNumber;
break;
}
}
}
return $this->pages;
}
}
function padRight($string, $widthOfTableCell){
$missingSpaces = $widthOfTableCell - $lengthOfString;
$tableCell = $string . str_repeat(" ", $missingSpaces); return $tableCell;
}
function padLeft($string, $widthOfTableCell){
$missingSpaces = $widthOfTableCell - $lengthOfString;
$tableCell = str_repeat(" ", $missingSpaces) . $string; return $tableCell;
}
$col1 = 15;
$col2 = $col3 = $col4 = $col5 = $col6 = 12;
$basicSalaryByProfession = array( 'Me' => 500,
'Ma' => 400,
'En' => 200,
'An' => 800
);
$coffeeByProfession = array( 'Me' => 20,
'Ma' => 15,
'En' => 5,
'An' => 50
);
$pagesByProfession = array( 'Me' => 200,
'Ma' => 150,
'En' => 50,
'An' => 5
);
$employeesPurchaseDepartment = [];
$number = 9;
for ($i = 0; $i < $number; $i++) {
$employeesPurchaseDepartment[$i] = new Employee('Закупки', 'Me', false, 1);
$employeesPurchaseDepartment[$i]->coffee = $employeesPurchaseDepartment[$i]->getCoffeeByProfession($coffeeByProfession);
$employeesPurchaseDepartment[$i]->basicSalary = $employeesPurchaseDepartment[$i]->getBasicSalaryByProfession($basicSalaryByProfession);
$employeesPurchaseDepartment[$i]->pages = $employeesPurchaseDepartment[$i]->getPagesByProfession($pagesByProfession);
}
$number = $i + 3;
for ($i; $i < $number; $i++) {
$employeesPurchaseDepartment[$i] = new Employee('Закупки', 'Me', false, 2);
$employeesPurchaseDepartment[$i]->coffee = $employeesPurchaseDepartment[$i]->getCoffeeByProfession($coffeeByProfession);
$employeesPurchaseDepartment[$i]->basicSalary = $employeesPurchaseDepartment[$i]->getBasicSalaryByProfession($basicSalaryByProfession);
$employeesPurchaseDepartment[$i]->pages = $employeesPurchaseDepartment[$i]->getPagesByProfession($pagesByProfession);
}
$number = $i + 2;
for ($i; $i < $number; $i++) {
$employeesPurchaseDepartment[$i] = new Employee('Закупки', 'Me', false, 3);
$employeesPurchaseDepartment[$i]->coffee = $employeesPurchaseDepartment[$i]->getCoffeeByProfession($coffeeByProfession);
$employeesPurchaseDepartment[$i]->basicSalary = $employeesPurchaseDepartment[$i]->getBasicSalaryByProfession($basicSalaryByProfession);
$employeesPurchaseDepartment[$i]->pages = $employeesPurchaseDepartment[$i]->getPagesByProfession($pagesByProfession);
}
$number = $i + 2;
for ($i; $i < $number; $i++) {
$employeesPurchaseDepartment[$i] = new Employee('Закупки', 'Ma', false, 1);
$employeesPurchaseDepartment[$i]->coffee = $employeesPurchaseDepartment[$i]->getCoffeeByProfession($coffeeByProfession);
$employeesPurchaseDepartment[$i]->basicSalary = $employeesPurchaseDepartment[$i]->getBasicSalaryByProfession($basicSalaryByProfession);
$employeesPurchaseDepartment[$i]->pages = $employeesPurchaseDepartment[$i]->getPagesByProfession($pagesByProfession);
}
$number = $i + 1;
for ($i; $i < $number; $i++) {
$employeesPurchaseDepartment[$i] = new Employee('Закупки', 'Me', true, 2);
$employeesPurchaseDepartment[$i]->coffee = $employeesPurchaseDepartment[$i]->getCoffeeByProfession($coffeeByProfession);
$employeesPurchaseDepartment[$i]->basicSalary = $employeesPurchaseDepartment[$i]->getBasicSalaryByProfession($basicSalaryByProfession);
$employeesPurchaseDepartment[$i]->pages = $employeesPurchaseDepartment[$i]->getPagesByProfession($pagesByProfession);
}
function getIndex($employees)
{
$salary = 0;
$pages = 0;
$coffee = 0;
$department = 0;
$employeesNumber = 0;
$index = [];
$i = 0;
$department = $employees[$i]->department;
for ($i; $i < count($employees); $i++) { $salary += $employees[$i]->getSalary();
$pages += $employees[$i]->getPages();
$coffee += $employees[$i]->getCoffee();
}
$employeesNumber = count($employees); 'salary' => $salary,
'pages' => $pages,
'coffee' => $coffee,
'department' => $department,
'employeesNumber' => $employeesNumber
);
return $index;
}
$purchaseDepartment = getIndex($employeesPurchaseDepartment);
// Заголовок таблицы
echo padRight("Департамент", $col1) .
padLeft("сотр.", $col2) .
padLeft("тугр.", $col3) .
padLeft("кофе", $col4) .
padLeft("стр.", $col5) .
padLeft("тугр./стр.", $col6) ."\n";
// Сама таблица
echo padRight($purchaseDepartment['department'], $col1) .
padLeft($purchaseDepartment['employeesNumber'], $col2) .
padLeft($purchaseDepartment['salary'], $col3) .
padLeft($purchaseDepartment['coffee'], $col4) .
padLeft($purchaseDepartment['pages'], $col5) .
padLeft(0, $col6) . "\n";