<?php
class Department
{
public $name;
public $employees = array();
public function addEmployees($quantity, $employee)
{
for($i = 0; $i < $quantity; $i++){
}
return $this->employees;
}
public function addLeader($employee){
$employee->setRank();
$employee->makeLeader();
return $this;
}
public function getTotalEmployees()
{ $total = 0;
foreach ($this->employees as $employee){
$total++;
}
return $total;
}
public function getTotalCoffee(){
$total = 0;
foreach ($this->employees as $employee) {
$total+=$employee->coffee;
}
return $total;
}
public function getTotalPapers(){
$total = 0;
foreach ($this->employees as $employee) {
$total+=$employee->papers;
}
return $total;
}
public function getTotalIncome(){
$total = 0;
foreach ($this->employees as $employee) {
$total += $employee->income;
}
}
}
abstract class Employee
{
public $rank;
public $income;
public $coffee;
public $papers;
public function __construct($rank)
{
$this->rank = $rank;
}
public function setRank()
{
$rank = $this->rank;
if($rank == 2){
$this->income *= 1.25;
}
elseif($rank == 3){
$this->income *= 1.5;
}
return $this;
}
public function makeLeader(){
$this->income *= 1.5;
$this->coffee *= 2;
$this->papers = 0;
return $this;
}
}
class Manager extends Employee
{
public $income = 500;
public $coffee = 20;
public $papers = 200;
}
class Marketer extends Employee
{
public $income = 400;
public $coffee = 15;
public $papers = 150;
}
class Engineer extends Employee
{
public $income = 200;
public $coffee = 5;
public $papers = 50;
}
class Analytics extends Employee
{
public $income = 800;
public $coffee = 50;
public $papers = 5;
}
function padLeft($text, $length){
if($cl<$length){
}
return $text;
}
function padRight($text, $length){
if($cl<$length){
}
return $text;
}
$col1 = 11;
$col2 = 11;
$col3 = 11;
$col4 = 11;
$col5 = 11;
$col6 = 13;
$col7 = 11;
$buyers = new Department;
$buyers->name = "Закупок";
$buyers->addEmployees(9, new Manager(1));
$buyers->addEmployees(3, new Manager(2));
$buyers->addEmployees(2, new Marketer(1));
$buyers->addLeader(new Manager(2));
$sellers = new Department;
$sellers->name = "Продаж";
$sellers->addEmployees(12, new Manager(1));
$sellers->addEmployees(6, new Marketer(1));
$sellers->addEmployees(3, new Analytics(1));
$sellers->addEmployees(2, new Analytics(2));
$sellers->addLeader(new Marketer(2));
$advertisers = new Department;
$advertisers->name = "Рекламы";
$advertisers->addEmployees(15, new Marketer(1));
$advertisers->addEmployees(10, new Marketer(2));
$advertisers->addEmployees(8, new Manager(1));
$advertisers->addEmployees(2, new Engineer(1));
$advertisers->addLeader(new Manager(1));
$logistics = new Department;
$logistics->name = "Логистики";
$logistics->addEmployees(13, new Manager(1));
$logistics->addEmployees(5, new Manager(2));
$logistics->addEmployees(5, new Engineer(1));
$logistics->addLeader(new Manager(1));
$departments = array($buyers, $sellers, $advertisers, $logistics);
foreach ($departments as $department) {
$totalEmp+=$department->getTotalEmployees();
$totalInc+=$department->getTotalIncome();
$totalCof+=$department->getTotalCoffee();
$totalPap+=$department->getTotalPapers();
$totalPrice+=floor($department->getTotalIncome()/$department->getTotalPapers()); }
$avPrice = floor($totalPrice / count($departments));
echo (padRight("Департамент",$col1).
padLeft("сотр.",$col2).
padLeft("тугр.",$col3).
padLeft("кофе",$col4).
padLeft("стр.",$col5).
padLeft("тугр./стр.",$col6)."\n---------------------------------------------------------------------------\n");
foreach ($departments as $department){
echo padRight($department->name,$col1).
padLeft($department->getTotalEmployees(),$col2).
padLeft($department->getTotalIncome(),$col3).
padLeft($department->getTotalCoffee(),$col4).
padLeft($department->getTotalPapers(),$col5).
padLeft
(floor($department->getTotalIncome()/$department->getTotalPapers()),$col6)."\n";}
echo (
padRight("Среднее", $col1).
padLeft($avEmp, $col2).
padLeft($avIncome, $col3).
padLeft($avCof, $col4).
padLeft($avPap, $col5).
padLeft($avPrice, $col6)."\n"
);
echo(
padRight("Всего",$col1).
padLeft($totalEmp, $col2).
padLeft($totalInc, $col3).
padLeft($totalCof, $col4).
padLeft($totalPap, $col5).
padLeft($totalPrice, $col6)
);