<?php
header("Content-Type: text/plain; charset=utf-8"); ?>
<?php
//объявление классов >>
abstract class Employee
{
public $salary;
public $coffee;
public $reports;
public $rank;
public $isDirector;
public function __construct($rank, $isDirector=0)
{
$this->rank = $rank;
$this->isDirector = $isDirector;
}
}
class Engineer extends Employee
{
public $salary = 200;
public $coffee = 5;
public $reports = 50;
}
class Marketolog extends Employee
{
public $salary = 400;
public $coffee = 15;
public $reports = 150;
}
class Manager extends Employee
{
public $salary = 500;
public $coffee = 20;
public $reports = 200;
}
class Analyst extends Employee
{
public $salary = 800;
public $coffee = 50;
public $reports = 5;
}
class Department
{
public $name;
public $workers = array(); public function __construct($name, $array)
{
$this->workers = $array;
$this->name = $name;
/* $this->count = count($this->workers);
$this->salary = $this->getSalary();
$this->coffee = $this->getCoffee();
$this->reports = $this->getReports();
$this->repSal = number_format($this->getSalaryReports(), 2); */
}
public function getCount()
{
return count($this->workers); }
public function getSalary()
{
$sumSalary = 0;
foreach ($this->workers as $worker) {
$money = $worker->salary;
if ($worker->rank == 2) {
$money = $worker->salary * 1.25;
} elseif ($worker->rank == 3) {
$money = $worker->salary * 1.5;
}
if ($worker->isDirector) {
$money *= 1.5;
}
$sumSalary += $money;
}
return $sumSalary;
}
public function getCoffee()
{
$sumCoffee = 0;
foreach ($this->workers as $worker) {
$coffee = $worker->coffee;
if ($worker->isDirector) {
$coffee = $worker->coffee * 2;
}
$sumCoffee += $coffee;
}
return $sumCoffee;
}
public function getReports()
{
$sumReports = 0;
foreach ($this->workers as $worker) {
$reports = $worker->reports;
if ($worker->isDirector) {
$reports = $worker->reports * 0;
}
$sumReports += $reports;
}
return $sumReports;
}
public function getSalaryReports()
{
return number_format(($this->getSalary() / $this->getReports()), 2); }
}
//Создание работников(объектов) внутри департамента >>
function getEmployee($array)
{
foreach ($array as $workers) {
list($rank, $class, $count, $isDirector) = (explode(', ', $workers)); for ($i = 1; $i <= $count; $i++) {
$employee = new $class($rank, $isDirector);
$employees[] = $employee;
}
}
return $employees;
}
$ma = 'Marketolog';
$me = 'Manager';
$an = 'Analyst';
$in = 'Engineer';
"1, $me, 9, 0",
"2, $me, 3, 0",
"3, $me, 2, 0",
"1, $ma, 2, 0",
"2, $me, 1, 1"
);
"1, $me, 12, 0",
"1, $ma, 6, 0",
"1, $an, 3, 0",
"2, $an, 2, 0",
"2, $ma, 1, 1"
);
"1, $ma, 15, 0",
"2, $ma, 10, 0",
"1, $me, 8, 0",
"1, $in, 2, 0",
"3, $ma, 1, 1"
);
"1, $me, 13, 0",
"2, $me, 5, 0",
"1, $in, 5, 0",
"1, $me, 1, 1"
);
$procurement = new Department('Procurement', getEmployee($procurWorkers));
$sales = new Department('Sales dp', getEmployee($saleWorkers));
$advertising = new Department('Advertising', getEmployee($adverWorkers));
$logistic = new Department('Logistic', getEmployee($logWorkers));
$procurement,
$sales,
$advertising,
$logistic
);
//Создание функций для вывода таблицы на экран и подсчет суммы по департаментам
function padRight($string, $arg)
{
if ($count <= 0) {
return $string;
}
return $string . $space;
}
function padLeft($string, $arg)
{
if ($count <= 0) {
return $string;
}
return $space . $string;
}
$text = 'Департамент сотр. тугр кофе стр. туг/стр.';
$col1 = 22;
$col2 = 11;
function getShow($array)
{
global $col1;
global $col2;
foreach ($array as $k => $str) {
if ($k == 0) {
echo padRight($str, $col1);
} else {
echo padLeft($str, $col2);
}
}
echo "\n";
}
//Вывод на экран>>
getShow($textAr);
$count = 0;
$coffee = 0;
$salary = 0;
$reports = 0;
$repSal = 0;
foreach ($departments as $department) {
echo padRight($department->name, $col1);
echo padLeft($department->getCount(), $col2);
$count += $department->getCount();
echo padLeft($department->getSalary(), $col2);
$salary += $department->getSalary();
echo padLeft($department->getCoffee(), $col2);
$coffee += $department->getCoffee();
echo padLeft($department->getReports(), $col2);
$reports += $department->getReports();
echo padLeft($department->getSalaryReports(), $col2) . "\n";
$repSal += $department->getSalaryReports();
}
$repSal /= 4;
'Всего',
$count,
$salary,
$coffee,
$reports,
$repSal
);
getShow($total);
PD9waHAKaGVhZG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DMpIHsKICAgICAgICAgICAgICAgICRtb25leSA9ICR3b3JrZXItPnNhbGFyeSAqIDEuNTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoJHdvcmtlci0+aXNEaXJlY3RvcikgewogICAgICAgICAgICAgICAgJG1vbmV5ICo9IDEuNTsKICAgICAgICAgICAgfQogICAgICAgICAgICAkc3VtU2FsYXJ5ICs9ICRtb25leTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuICRzdW1TYWxhcnk7CiAgICB9CiAgICBwdWJsaWMgZnVuY3Rpb24gZ2V0Q29mZmVlKCkKICAgIHsKICAgICAgICAkc3VtQ29mZmVlID0gMDsKICAgICAgICBmb3JlYWNoICgkdGhpcy0+d29ya2VycyBhcyAkd29ya2VyKSB7CiAgICAgICAgICAgICRjb2ZmZWUgPSAkd29ya2VyLT5jb2ZmZWU7CiAgICAgICAgICAgIGlmICgkd29ya2VyLT5pc0RpcmVjdG9yKSB7CiAgICAgICAgICAgICAgICAkY29mZmVlID0gJHdvcmtlci0+Y29mZmVlICogMjsKICAgICAgICAgICAgfQogICAgICAgICAgICAkc3VtQ29mZmVlICs9ICRjb2ZmZWU7CiAgICAgICAgfQogICAgICAgIHJldHVybiAkc3VtQ29mZmVlOwogICAgfQogICAgcHVibGljIGZ1bmN0aW9uIGdldFJlcG9ydHMoKQogICAgewogICAgICAgICRzdW1SZXBvcnRzID0gMDsKICAgICAgICBmb3JlYWNoICgkdGhpcy0+d29ya2VycyBhcyAkd29ya2VyKSB7CiAgICAgICAgICAgICRyZXBvcnRzID0gJHdvcmtlci0+cmVwb3J0czsKICAgICAgICAgICAgaWYgKCR3b3JrZXItPmlzRGlyZWN0b3IpIHsKICAgICAgICAgICAgICAgICRyZXBvcnRzID0gJHdvcmtlci0+cmVwb3J0cyAqIDA7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgJHN1bVJlcG9ydHMgKz0gJHJlcG9ydHM7CiAgICAgICAgfQogICAgICAgIHJldHVybiAkc3VtUmVwb3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