<?php
class Department
{
public $name;
public $employees = array();
public function getTotalEmployees()
{ $total = 0;
foreach ($this->employees as $employee){
$total+=$employee[3];
}
return $total;
}
public function getTotalCoffee(){
$total = 0;
foreach ($this->employees as $employee) {
$total+=$employee[1];
}
return $total;
}
public function getTotalPapers(){
$total = 0;
foreach ($this->employees as $employee) {
$total+=$employee[2];
}
return $total;
}
public function getTotalIncome(){
$total = 0;
foreach ($this->employees as $employee) {
$total = $total + $employee[0];
}
}
}
abstract class Employee
{
public $rank;
public $income;
public $coffee;
public $papers;
public $quantity = 1;
public function rank($rank)
{
if($rank == 2){
$this->income *= 1.25;
}
elseif($rank == 3){
$this->income *= 1.5;
}
return $this->income;
}
public function makeLeader($rank){
$inc = $this->rank($rank) * 1.5;
$cof = $this->coffee * 2;
$pap = 0;
$quan = $this->quantity;
return $total = [$inc,$cof,$pap,$quan];
}
public function multiple($quantity ,$rank){
$this->income = $this->rank($rank);
$inc = $this->income * $quantity;
$cof = $this->coffee * $quantity;
$pap = $this->papers * $quantity;
return $total = [$inc,$cof,$pap,$quantity];
}
}
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){
for($i = 0; $i < $length - $cl; $i++){
$text = " ".$text;
}}
return $text;
}
function padRight($text, $length){
if($cl<$length){
for($i = 0; $i < $length - $cl; $i++){
$text = $text." ";
}}
return $text;
}
$manager = new Manager;
$marketer = new Marketer;
$engineer = new Engineer;
$analytics = new Analytics;
$buyers = new Department;
$buyers->name = "Закупок";
$buyers->employees=array( $manager->multiple(9,1), //на первом месте кол-во, на втором ранг
$manager->multiple(3,2),
$manager->multiple(2,3),
$marketer->multiple(2,1),
$manager->makeLeader(2)
);
$sellers = new Department;
$sellers->name = "Продаж";
$sellers->employees = array( $manager->multiple(12,1),
$marketer->multiple(6,1),
$analytics->multiple(3,1),
$analytics->multiple(2,2),
$marketer->makeLeader(2)
);
$advertisers = new Department;
$advertisers->name = "Рекламы";
$advertisers->employees = array( $marketer->multiple(15,1),
$marketer->multiple(10,2),
$manager->multiple(8,1),
$engineer->multiple(2,1),
$marketer->makeLeader(3)
);
$logistics = new Department;
$logistics->name = "Логистики";
$logistics->employees = array( $manager->multiple(13,1),
$manager->multiple(5,2),
$engineer->multiple(5,1),
$manager->makeLeader(1)
);
$departments = array($buyers,$sellers,$advertisers,$logistics); $col1 = 10;
$col2 = 5;
$col3 = 5;
$col4 = 5;
$col5 = 5;
$col6 = 5;
$col1 = 11;
$col2 = 11;
$col3 = 11;
$col4 = 11;
$col5 = 11;
$col6 = 13;
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";
}
PD9waHAKZXJyb3JfcmVwb3J0aW5nKC0xKTsKY2xhc3MgRGVwYXJ0bWVudAp7CglwdWJsaWMgJG5hbWU7CglwdWJsaWMgJGVtcGxveWVlcyA9IGFycmF5KCk7CgoJcHVibGljIGZ1bmN0aW9uIGdldFRvdGFsRW1wbG95ZWVzKCkKCXsJJHRvdGFsID0gMDsKCQlmb3JlYWNoICgkdGhpcy0+ZW1wbG95ZWVzIGFzICRlbXBsb3llZSl7CgkJCSR0b3RhbCs9JGVtcGxveWVlWzNdOwoJCX0KCQlyZXR1cm4gJHRvdGFsOwoJfQoKCXB1YmxpYyBmdW5jdGlvbiBnZXRUb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