<?php
class Worker
{
public function __construct($salary, $coffee, $reports, $a, $b, $c) //$a - 1 если 2 ранг, 0 если нет, $b - 1 (3 ранг), $c - 1 (если директор)
{
$salarySecond = $salary + $salary * 0.25 * $a;
$salaryThird = $salarySecond + $salarySecond * 0.5 * $b;
$salaryDir = $salaryThird + $salaryThird * 0.5 * $c;
$coffeeDir = $coffee + $coffee * $c;
$reportsDir = $reports * (1 - $c);
$this->salary = $salaryDir;
$this->coffee = $coffeeDir;
$this->reports = $reportsDir;
}
}
500,
20,
200
);
400,
15,
150
);
200,
5,
50
);
800,
50,
5
);
function doWorkers($array, $x, $a, $b, $c)
{
for ($i = 1; $i <= $x; $i++) {
list($k1, $k2, $k3) = $array; $worker = new Worker($k1, $k2, $k3, $a, $b, $c);
$workers[] = $worker;
}
return $workers;
}
$depZakupok[] = doWorkers($me, 9, 0, 0, 0);
$depZakupok[] = doWorkers($me, 3, 1, 0, 0);
$depZakupok[] = doWorkers($me, 2, 0, 1, 0);
$depZakupok[] = doWorkers($ma, 2, 0, 0, 0);
$depZakupok[] = doWorkers($ma, 1, 0, 0, 1);
$depProdaj[] = doWorkers($me, 12, 0, 0, 0);
$depProdaj[] = doWorkers($ma, 6, 0, 0, 0);
$depProdaj[] = doWorkers($an, 3, 0, 0, 0);
$depProdaj[] = doWorkers($an, 2, 1, 0, 0);
$depProdaj[] = doWorkers($ma, 1, 1, 0, 1);
$depReklamy[] = doWorkers($ma, 15, 0, 0, 0);
$depReklamy[] = doWorkers($ma, 10, 1, 0, 0);
$depReklamy[] = doWorkers($me, 8, 0, 0, 0);
$depReklamy[] = doWorkers($en, 2, 0, 0, 0);
$depReklamy[] = doWorkers($ma, 1, 0, 1, 1);
$depLogist[] = doWorkers($me, 13, 0, 0, 0);
$depLogist[] = doWorkers($me, 5, 1, 0, 0);
$depLogist[] = doWorkers($en, 5, 0, 0, 0);
$depLogist[] = doWorkers($me, 1, 0, 0, 0);
$depZakupok,
$depProdaj,
$depReklamy,
$depLogist
);
$countLogist = count($depLogist, 1) - count($depLogist); $countRek = count($depReklamy, 1) - count($depReklamy); $countProd = count($depProdaj, 1) - count($depProdaj); $countZak = count($depZakupok, 1) - count($depZakupok); $vektorCount = $countLogist + $countRek + $countProd + $countZak;
function doTotalSalaryDep($array)
{
$summary = 0;
foreach ($array as $group) {
foreach ($group as $worker) {
$summary += $worker->salary . "\n";
}
}
return $summary;
}
$zakSalary = doTotalSalaryDep($depZakupok);
$prodSalary = doTotalSalaryDep($depProdaj);
$rekSalary = doTotalSalaryDep($depReklamy);
$logSalary = doTotalSalaryDep($depLogist);
$vektorSalary = $zakSalary + $prodSalary + $rekSalary + $logSalary;
function doTotalReportsDep($array)
{
$summary = 0;
foreach ($array as $group) {
foreach ($group as $worker) {
$summary += $worker->reports;
}
}
return $summary;
}
$zakRep = doTotalReportsDep($depZakupok);
$prodRep = doTotalReportsDep($depProdaj);
$rekRep = doTotalReportsDep($depReklamy);
$logRep = doTotalReportsDep($depLogist);
$vektorRep = $zakRep + $prodRep + $rekRep + $logRep;
function doTotalCoffeeDep($array)
{
$summary = 0;
foreach ($array as $group) {
foreach ($group as $worker) {
$summary += $worker->coffee;
}
}
return $summary;
}
$zakCoffee = doTotalCoffeeDep($depZakupok);
$prodCoffee = doTotalCoffeeDep($depProdaj);
$rekCoffee = doTotalCoffeeDep($depReklamy);
$logCoffee = doTotalCoffeeDep($depLogist);
$vektorCoffee = $zakCoffee + $prodCoffee + $rekCoffee + $logCoffee;
$zakRepSal = $zakSalary / $zakRep;
$prodRepSal = $prodSalary / $prodRep;
$rekRepSal = $rekSalary / $rekRep;
$logRepSal = $logSalary / $logRep;
$vektorRepSal = $vektorSalary / $vektorRep;
$col1 = 20;
$col2 = 8;
function padRight($string, $arg)
{
if ($count <= 0) {
return $string;
}
return $string . $space;
}
function padLeft($string, $arg)
{
if ($count <= 0) {
return $string;
}
return $space . $string;
}
echo padRight('Департамент', $col1) . padLeft('сотр.', $col2) . padLeft('тугр', $col2) . padLeft('кофе', $col2) . padLeft('стр.', $col2) . padLeft('тугр./стр.', $col1) . "\n";
echo str_repeat('-', $col1 * 2 + $col2 * 4 + 5) . "\n"; echo padRight
('Деп. Закупок', $col1) . padLeft
("$countZak", $col2) . padLeft
("$zakSalary", $col2) . padLeft
("$zakCoffee", $col2) . padLeft
("$zakRep", $col2) . padLeft
(number_format($zakRepSal, 2), $col1) . "\n"; echo padRight
('Деп. Продаж', $col1) . padLeft
("$countProd", $col2) . padLeft
("$prodSalary", $col2) . padLeft
("$prodCoffee", $col2) . padLeft
("$prodRep", $col2) . padLeft
(number_format($prodRepSal, 2), $col1) . "\n"; echo padRight
('Деп. Рекламы', $col1) . padLeft
("$countRek", $col2) . padLeft
("$rekSalary", $col2) . padLeft
("$rekCoffee", $col2) . padLeft
("$rekRep", $col2) . padLeft
(number_format($rekRepSal, 2), $col1) . "\n"; echo padRight
('Деп. Логистики', $col1) . padLeft
("$countLogist", $col2) . padLeft
("$logSalary", $col2) . padLeft
("$logCoffee", $col2) . padLeft
("$logRep", $col2) . padLeft
(number_format($logRepSal, 2), $col1) . "\n"; echo str_repeat('-', $col1 * 2 + $col2 * 4 + 5) . "\n"; echo padRight
('ВСЕГО:', $col1) . padLeft
("$vektorCount", $col2) . padLeft
("$vektorSalary", $col2) . padLeft
("$vektorCoffee", $col2) . padLeft
("$vektorRep", $col2) . padLeft
(number_format($vektorRepSal, 2), $col1) . "\n";
PD9waHAKCm1iX2ludGVybmFsX2VuY29kaW5nKCJVVEYtOCIpOwoKY2xhc3MgV29ya2VyCnsKICAgIHB1YmxpYyBmdW5jdGlvbiBfX2NvbnN0cnVjdCgkc2FsYXJ5LCAkY29mZmVlLCAkcmVwb3J0cywgJGEsICRiLCAkYykgLy8kYSAtIDEg0LXRgdC70LggMiDRgNCw0L3QsywgMCDQtdGB0LvQuCDQvdC10YIsICRiIC0gMSAoMyDRgNCw0L3QsyksICRjIC0gMSAo0LXRgdC70Lgg0LTQuNGA0LXQutGC0L7RgCkKICAgIHsKICAgICAgICAkc2FsYXJ5U2Vjb25kICA9ICRzYWxhcnkgKyAkc2FsYXJ5ICogMC4yNSAqICRhOwogICAgICAgICRzYWxhcnlUaGlyZCAgID0gJHNhbGFyeVNlY29uZCArICRzYWxhcnlTZWNvbmQgKiAwLjUgKiAkYjsKICAgICAgICAkc2FsYXJ5RGlyICAgICA9ICRzYWxhcnlUaGlyZCArICRzYWxhcnlUaGlyZCAqIDAuNSAqICRjOwogICAgICAgICRjb2ZmZWVEaXIgICAgID0gJGNvZmZlZSArICRjb2ZmZWUgKiAkYzsKICAgICAgICAkcmVwb3J0c0RpciAgICA9ICRyZXBvcnRzICogKDEgLSAkYyk7CiAgICAgICAgJHRoaXMtPnNhbGFyeSAgPSAkc2FsYXJ5RGlyOwogICAgICAgICR0aGlzLT5jb2ZmZWUgID0gJGNvZmZlZURpcjsKICAgICAgICAkdGhpcy0+cmVwb3J0cyA9ICRyZXBvcnRzRGlyOwogICAgfQp9CiRtZSA9IGFycmF5KAogICAgNTAwLAogICAgMjAsCiAgICAyMDAKKTsKJG1hID0gYXJyYXkoCiAgICA0MDAsCiAgICAxNSwKICAgIDE1MAopOwokZW4gPSBhcnJheSgKICAgIDIwMCwKICAgIDUsCiAgICA1MAopOwokYW4gPSBhcnJheSgKICAgIDgwMCwKICAgIDUwLAogICAgNQopOwpmdW5jdGlvbiBkb1dvcmtlcnMoJGFycmF5LCAkeCwgJGEsICRiLCAkYykKewogICAgJHdvcmtlcnMgPSBhcnJheSgpOwogICAgZm9yICgkaSA9IDE7ICRpIDw9ICR4OyAkaSsrKSB7CiAgICAgICAgbGlzdCgkazEsICRrMiwgJGszKSA9ICRhcnJheTsKICAgICAgICAkd29ya2VyICAgID0gbmV3IFdvcmtlcigkazEsICRrMiwgJGszLCAkYSwgJGIsICRjKTsKICAgICAgICAkd29ya2Vyc1tdID0gJHdvcmtlcjsKICAgIH0KICAgIHJldHVybiAkd29ya2VyczsKfQokZGVwWmFrdXBvayAgID0gYXJyYXkoKTsKJGR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