<?php
/**
* Created by PhpStorm.
* User: Саша Поляны
* Date: 07.04.2016
* Time: 16:07
*/
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){
$missingSpaces = $widthOfTableCell - $lengthOfString;
$tableCell = $string . str_repeat(" ", $missingSpaces); return $tableCell;
}
function padRight($string, $widthOfTableCell){
$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); '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";
PD9waHAKLyoqCiAqIENyZWF0ZWQgYnkgUGhwU3Rvcm0uCiAqIFVzZXI6INCh0LDRiNCwINCf0L7Qu9GP0L3RiwogKiBEYXRlOiAwNy4wNC4yMDE2CiAqIFRpbWU6IDE2OjA3CiAqLwoKZXJyb3JfcmVwb3J0aW5nKC0xKTsKbWJfaW50ZXJuYWxfZW5jb2RpbmcoJ1VURi04Jyk7CgpjbGFzcyBFbXBsb3llZXsKICAgIHB1YmxpYyAkZGVwYXJ0bWVudDsKICAgIHB1YmxpYyAkcHJvZmVzc2lvbjsKICAgIHB1YmxpYyAkY29mZmVlOwogICAgcHVibGljICRyYW5rOwogICAgcHVibGljICRib3NzOwogICAgcHVibGljICRwYWdlczsKICAgIHB1YmxpYyAkc2FsYXJ5OwogICAgcHVibGljICRyYXRlOwoKICAgIHB1YmxpYyBmdW5jdGlvbiBfX2NvbnN0cnVjdCgkZGVwYXJ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