<?php
class Employee
{
public $salary;
public $cofee;
public $pages;
public function __construct($salary, $cofee, $pages)
{
$this->salary = $salary;
$this->cofee = $cofee;
$this->pages = $pages;
}
}
$me = new Employee(500, 20, 200);
$ma = new Employee(400, 15, 150);
$in = new Employee(200, 5, 50);
$an = new Employee(800, 50, 5);
class Department
{
public $name;
public $meEmployees = array(0, 0, 0); //array(lvl1,lvl2,lvl3) public $maEmployees = array(0, 0, 0); public $inEmployees = array(0, 0, 0); public $anEmployees = array(0, 0, 0); public $head = array("" => 0); //array(type=>lvl) }
$purch = new Department;
$purch->name = "Закупок";
$purch->meEmployees[0] = 9;
$purch->meEmployees[1] = 3;
$purch->meEmployees[2] = 2;
$purch->maEmployees[0] = 2;
"me" => 2
);
$sale = new Department;
$sale->name = "Продаж";
$sale->meEmployees[0] = 12;
$sale->maEmployees[0] = 6;
$sale->anEmployees[0] = 3;
$sale->anEmployees[1] = 12;
"ma" => 2
);
$advert = new Department;
$advert->name = "Рекламы";
$advert->maEmployees[0] = 15;
$advert->maEmployees[1] = 10;
$advert->meEmployees[0] = 8;
$advert->inEmployees[0] = 2;
"ma" => 3
);
$logist = new Department;
$logist->name = "Логистики";
$logist->meEmployees[0] = 13;
$logist->meEmployees[1] = 5;
$logist->meEmployees[0] = 5;
"me" => 1
);
function drawTable($array)
{
//ПОИСК МАКСИМАЛЬНОЙ ШИРИНЫ ЯЧЕЙКИ
$maxWidth = 0;
$cells = 0;
foreach ($array as $key => $value) {
$cells = $cells < count($value) ?
count($value) : $cells; foreach ($value as $word)
}
//ОТРИСОВКА ТАБЛИЦЫ
drawLine($maxWidth, $cells);
foreach ($array as $key => $value) {
echo "|";
foreach ($value as $word) {
echo $word . "|";
}
echo "\n";
drawLine($maxWidth, $cells);
}
}
function drawLine($maxWidth, $cells)
{
echo "+";
for ($i = 1; $i <= $cells; $i++)
echo "\n";
}
"Департамент",
"сотр.",
"з/п",
"кофе",
"стр.",
"постр.з/п"
);
$table[1] = countDep($purch, $me, $ma, $in, $an);
$table[2] = countDep($sale, $me, $ma, $in, $an);
$table[3] = countDep($advert, $me, $ma, $in, $an);
$table[4] = countDep($logist, $me, $ma, $in, $an);
function countDep($obj, $me, $ma, $in, $an)
{
$result[0] = $obj->name;
$sum = 0;
$sumCofee = 0;
$sumPages = 0;
for ($typeEmplCounter = 1; $typeEmplCounter <= 4; $typeEmplCounter++) {
switch ($typeEmplCounter) {
case "1":
$typeEmpl = 'meEmployees';
$emplCl = $me;
break;
case "2":
$typeEmpl = 'maEmployees';
$emplCl = $ma;
break;
case "3":
$typeEmpl = 'inEmployees';
$emplCl = $in;
break;
case "4":
$typeEmpl = 'anEmployees';
$emplCl = $an;
break;
}
foreach ($obj->$typeEmpl as $key => $empl) {
$k = $key > 0 ? ($key > 1 ? 1.5 : 1.25) : 1; // :3 УЧЁТ ЛЕВЕЛА :3
$sum += $k * $empl * $emplCl->salary;
$sumCofee += $empl * $emplCl->cofee;
$sumPages += $empl * $emplCl->pages;
}
}
$result[2] = $sum;
$result[3] = $sumCofee;
$result[4] = $sumPages;
$result[5] = round($sum / $sumPages, 2); return $result;
}
//ПОКА ЧТО БЕЗ УЧЕТА НАЧАЛЬНИКОВ ОТДЕЛА И ГРАФ "СРЕДНЕГО"-"ВСЕГО"
drawTable($table);
PD9waHAKbWJfaW50ZXJuYWxfZW5jb2RpbmcoJ3V0Zi04Jyk7CmNsYXNzIEVtcGxveWVlCnsKICAgIHB1YmxpYyAkc2FsYXJ5OwogICAgcHVibGljICRjb2ZlZTsKICAgIHB1YmxpYyAkcGFnZXM7CiAgICAKICAgIHB1YmxpYyBmdW5jdGlvbiBfX2NvbnN0cnVjdCgkc2FsYXJ5LCAkY29mZWUsICRwYWdlcykKICAgIHsKICAgICAgICAkdGhpcy0+c2FsYXJ5ID0gJHNhbGFyeTsKICAgICAgICAkdGhpcy0+Y29mZWUgID0gJGNvZmVlOwogICAgICAgICR0aGlzLT5wYWdlcyAgPSAkcGFnZXM7CiAgICB9Cn0KCiRtZSA9IG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dGFibGVbMl0gPSBjb3VudERlcCgkc2FsZSwgJG1lLCAkbWEsICRpbiwgJGFuKTsKJHRhYmxlWzNdID0gY291bnREZXAoJGFkdmVydCwgJG1lLCAkbWEsICRpbiwgJGFuKTsKJHRhYmxlWzRdID0gY291bnREZXAoJGxvZ2lzdCwgJG1lLCAkbWEsICRpbiwgJGFuKTsKCmZ1bmN0aW9uIGNvdW50RGVwKCRvYmosICRtZSwgJG1hLCAkaW4sICRhbikKewogICAgJHJlc3VsdFswXSA9ICRvYmotPm5hbWU7CiAgICAkcmVzdWx0WzFdID0gYXJyYXlfc3VtKCRvYmotPm1lRW1wbG95ZWVzKSArIGFycmF5X3N1bSgkb2JqLT5tYUVtcGxveWVlcykgKyBhcnJheV9zdW0oJG9iai0+aW5FbXBsb3llZXMpICsgYXJyYXlfc3VtKCRvYmotPmFuRW1wbG95ZWVzKTsKICAgIAogICAgJHN1bSAgICAgID0gMDsKICAgICRzdW1Db2ZlZSA9IDA7CiAgICAkc3VtUGFnZXMgPSAwOwogICAgZm9yICgkdHlwZUVtcGxDb3VudGVyID0gMTsgJHR5cGVFbXBsQ291bnRlciA8PSA0OyAkdHlwZUVtcGxDb3VudGVyKyspIHsKICAgICAgICBzd2l0Y2ggKCR0eXBlRW1wbENvdW50ZXIpIHsKICAgICAgICAgICAgY2FzZSAiMSI6CiAgICAgICAgICAgICAgICAkdHlwZUVtcGwgPSAnbWVFbXBsb3llZXMnOwogICAgICAgICAgICAgICAgJGVtcGxDbCAgID0gJG1lOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgIjIiOgogICAgICAgICAgICAgICAgJHR5cGVFbXBsID0gJ21hRW1wbG95ZWVzJzsKICAgICAgICAgICAgICAgICRlbXBsQ2wgICA9ICRtYTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlICIzIjoKICAgICAgICAgICAgICAgICR0eXBlRW1wbCA9ICdpbkVtcGxveWVlcyc7CiAgICAgICAgICAgICAgICAkZW1wbENsICAgPSAkaW47CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgY2FzZSAiNCI6CiAgICAgICAgICAgICAgICAkdHlwZUVtcGwgPSAnYW5FbXBsb3llZXMnOwogICAgICAgICAgICAgICAgJGVtcGxDbCAgID0gJGFuOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfQogICAgICAgIGZvcmVhY2ggKCRvYmotPiR0eXBlRW1wbCBhcyAka2V5ID0+ICRlbXBsKSB7CiAgICAgICAgICAgICRrID0gJGtleSA+IDAgPyAoJGtleSA+IDEgPyAxLjUgOiAxLjI1KSA6IDE7IC8vICA6MyDQo9Cn0IHQoiDQm9CV0JLQldCb0JAgOjMKICAgICAgICAgICAgJHN1bSArPSAkayAqICRlbXBsICogJGVtcGxDbC0+c2FsYXJ5OwogICAgICAgICAgICAkc3VtQ29mZWUgKz0gJGVtcGwgKiAkZW1wbENsLT5jb2ZlZTsKICAgICAgICAgICAgJHN1bVBhZ2VzICs9ICRlbXBsICogJGVtcGxDbC0+cGFnZXM7CiAgICAgICAgfQogICAgICAgIAogICAgfQogICAgCiAgICAkcmVzdWx0WzJdID0gJHN1bTsKICAgICRyZXN1bHRbM10gPSAkc3VtQ29mZWU7CiAgICAkcmVzdWx0WzRdID0gJHN1bVBhZ2VzOwogICAgJHJlc3VsdFs1XSA9IHJvdW5kKCRzdW0gLyAkc3VtUGFnZXMsIDIpOwogICAgcmV0dXJuICRyZXN1bHQ7Cn0KCi8v0J/QntCa0JAg0KfQotCeINCR0JXQlyDQo9Cn0JXQotCQINCd0JDQp9CQ0JvQrNCd0JjQmtCe0JIg0J7QotCU0JXQm9CQINCYINCT0KDQkNCkICLQodCg0JXQlNCd0JXQk9CeIi0i0JLQodCV0JPQniIKZHJhd1RhYmxlKCR0YWJsZSk7