<?php
class Employee{
public $salary;
public $cofee;
public $pages;
function __construct($name){
$this->name=$name;
return $this->name;
}
}
class Department{
public $rank;
public $quantity;
public $salary;
public $cofee;
public $pages;
function __construct($name){
$this->name=$name;
return $this->name;
}
function getSalary(){
$multiply=1;
switch($this->rank){
case 2:
$multiply=1.25;
break;
case 3:
$multiply=1.50;
break;
}
$getSalary=$this->salary*$multiply*$this->quantity;
return $getSalary;
}
function getCofee(){
$getCofee=$this->quantity*$this->cofee;
return $getCofee;
}
function getPages(){
$getPages=$this->quantity*$this->pages;
return $getPages;
}
}
function createDepartment($data){
$department=new Department($data['name']);
$quantity=0;
$costs=0;
$pages=0;
$cofee=0;
foreach($data as $key => $workers){
if($key=="name"){
continue;
}
$department->rank=$workers['rank'];
$department->quantity=$workers['quantity'];
$department->cofee=$workers['employee']->cofee;
$department->pages=$workers['employee']->pages;
$quantity=$quantity+$department->quantity;
$department->salary=$workers['employee']->salary;
$costs=$costs+$department->getSalary();
$pages=$pages+$department->getPages();
$cofee=$cofee+$department->getCofee();
}
echo "Департамент ".$department->name;
echo " \n Работников $quantity";
echo " \n Расходы $costs";
echo "\n Кофе $cofee";
echo " \n Страниц $pages";
}
$manager=new Employee("Менеджер");
$manager->salary=500;
$manager->cofee=20;
$manager->pages=200;
$market=new Employee("Маркетолог");
$market->salary=400;
$market->cofee=15;
$market->pages=150;
$engineer=new Employee("Инженер");
$engineer->salary=200;
$engineer->cofee=5;
$engineer->pages=50;
$analyst=new Employee("Аналитик");
$analyst->salary=800;
$analyst->cofee=50;
$analyst->pages=5;
'name'=>"Закупок",
'rank'=>1,
'quantity'=>9,
'employee'=>$manager),
'rank'=>2,
'quantity'=>3,
'employee'=>$manager),
'rank'=>3,
'quantity'=>2,
'employee'=>$manager),
'rank'=>1,
'quantity'=>2,
'employee'=>$market)
);
createDepartment($department1);
PD9waHAKY2xhc3MgRW1wbG95ZWV7CgkKICAgIHB1YmxpYyAkc2FsYXJ5OwoJcHVibGljICRjb2ZlZTsKCX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