<?php
class Employee
{
public $name;
public $rate;
public function getTotalHoursWorked()
{
}
public function getSalary()
{
$hours = $this->getTotalHoursWorked();
$overHours = $this->getOverTimeHours();
$salary = $hours * $this->rate + $overHours * $this->rate;
return $salary;
}
public function __construct($name, $rate)
{
$this->name = $name;
$this->rate = $rate;
}
public function getShortName()
{
$pattern = "/[а-яё]+$/u";
$replace = '.';
return $z;
}
public function getOverTimeHours()
{
$overtime = 0;
foreach ($this->hours as $hours) {
if ($hours >= 40) {
$overtime += $hours - 40;
}
}
return $overtime;
}
}
$ivan = new Employee("Иванов Иван", 10);
40,
40,
40,
40
);
$peter = new Employee("Петров Петр", 8);
40,
10,
40,
50
);
$mikhail = new Employee("Михайлов Михаил", 12);
40,
40,
60,
40
);
$ivan,
$peter,
$mikhail
);
$col1 = 30;
$col2 = 8;
$col3 = 8;
$col4 = 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("Ставка", $col3) . padLeft("З/п", $col4) . "\n\n";
$totalHrs = 0;
$totalRate = 0;
$totalSlr = 0;
$totalOverHrs = 0;
foreach ($employees as $employee) {
$totalHrs += $employee->getTotalHoursWorked();
$totalRate += $employee->rate;
$totalSlr += $employee->getSalary();
$totalOverHrs += $employee->getOverTimeHours();
}
foreach ($employees as $employee) {
echo padRight($employee->getShortName(), $col1) . padLeft($employee->getTotalHoursWorked(), $col2) . padLeft($employee->getOverTimeHours(), $col2) . padLeft($employee->rate, $col3) . padLeft($employee->getSalary(), $col4) . "\n";
}
echo padRight('Всего : ', $col1) . padLeft($totalHrs, $col2) . padLeft($totalOverHrs, $col2) . padLeft($totalRate, $col3) . padLeft($totalSlr, $col4) . "\n";
PD9waHAKCm1iX2ludGVybmFsX2VuY29kaW5nKCJVVEYtOCIpOwoKY2xhc3MgRW1wbG95ZWUKewogICAgcHVibGljICRuYW1lOwogICAgcHVibGljICRyYXRlOwogICAgcHVibGljICRob3VycyA9IGFycmF5KCk7CiAgICAKICAgIHB1YmxpYyBmdW5jdGlvbiBnZXRUb3RhbEhvdXJzV29ya2VkKCkKICAgIHsKICAgICAgICByZXR1cm4gYXJyYXlfc3VtKCR0aGlzLT5ob3Vycyk7CiAgICB9CiAgICBwdWJsaWMgZnVuY3Rpb24gZ2V0U2FsYXJ5KCkKICAgIHsKICAgICAgICAkaG91cnMgICAgID0gJHRoaXMtPmdldFRvdGFsSG91cnNXb3JrZWQoKTsKICAgICAgICAkb3ZlckhvdXJzID0gJHRoaXMtPmdldE92ZXJUaW1lSG91cnMoKTsKICAgICAgICAkc2FsYXJ5ICAgID0gJGhvdXJzICogJHRoaXMtPnJhdGUgKyAkb3ZlckhvdXJzICogJHRoaXMtPnJhdGU7CiAgICAgICAgcmV0dXJuICRzYWxhcnk7CiAgICB9CiAgICBwdWJsaWMgZnVuY3Rpb24gX19jb25zdHJ1Y3QoJG5hbWUsICRyYXRlKQogICAgewogICAgICAgIAogICAgICAgICR0aGlzLT5uYW1lID0gJG5hbWU7CiAgICAgICAgJHRoaXMtPnJhdGUgPSAkcmF0ZTsKICAgIH0KICAgIAogICAgcHVibGljIGZ1bmN0aW9uIGdldFNob3J0TmFtZSgpCiAgICB7CiAgICAgICAgCiAgICAgICAgJHBhdHRlcm4gPSAiL1vQsC3Rj9GRXSskL3UiOwogICAgICAgICRyZXBsYWNlID0gJy4nOwogICAgICAgICR6ICAgICAgID0gcHJlZ19yZXBsYWNlKCRwYXR0ZXJuLCAkcmVwbGFjZSwgJHRoaXMtPm5hbWUpOwogICAgICAgIHJldHVybiAkejsKICAgICAgICAKICAgIH0KICAgIHB1YmxpYyBmdW5jdGlvbiBnZXRPdmVyVGltZUhvdXJzKCkKICAgIHsKICAgICAgICAkb3ZlcnRpbWUgPSAwOwogICAgICAgIGZvcmVhY2ggKCR0aGlzLT5ob3VycyBhcyAkaG91cnMpIHsKICAgICAgICAgICAgaWYgKCRob3VycyA+PSA0MCkgewogICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAkb3ZlcnRpbWUgKz0gJGhvdXJzIC0gNDA7CiAgICAgICAgICAgICAgICAKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gJG92ZXJ0aW1lOwogICAgfQogICAgCiAgICAKICAgIAogICAgCn0KJGl2YW4gPSBuZXcgRW1wbG95ZWUoItCY0LLQsNC90L7QsiDQmNCy0LDQvSIsIDEwKTsKCiRpdmFuLT5ob3VycyA9IGFycmF5KAogICAgNDAsCiAgICA0MCwKICAgIDQwLAogICAgNDAKKTsKCiRwZXRlciA9IG5ldyBFbXBsb3llZSgi0J/QtdGC0YDQvtCyINCf0LXRgtGAIiwgOCk7CgokcGV0ZXItPmhvdXJzICAgPSBhcnJheSgKICAgIDQwLAogICAgMTAsCiAgICA0MCwKICAgIDUwCik7CiRtaWtoYWlsICAgICAgICA9IG5ldyBFbXBsb3llZSgi0JzQuNGF0LDQudC70L7QsiDQnNC40YXQsNC40LsiLCAxMik7CiRtaWtoYWlsLT5ob3VycyA9IGFycmF5KAogICAgNDAsCiAgICA0MCwKICAgIDYwLAogICAgNDAKKTsKCiRlbXBsb3llZXMgPSBhcnJheSgKICAgICRpdmFuLAogICAgJHBldGVyLAogICAgJG1pa2hhaWwKKTsKJGNvbDEgICAgICA9IDMwOwokY29sMiAgICAgID0gODsKJGNvbDMgICAgICA9IDg7CiRjb2w0ICAgICAgPSA4OwpmdW5jdGlvbiBwYWRSaWdodCgkc3RyaW5nLCAkYXJnKQp7CiAgICAkY291bnQgPSAkYXJnIC0gbWJfc3RybGVuKCRzdHJpbmcpOwogICAgaWYgKCRjb3VudCA8PSAwKSB7CiAgICAgICAgcmV0dXJuICRzdHJpbmc7CiAgICB9CiAgICAkc3BhY2UgPSBzdHJfcmVwZWF0KCcgJywgJGNvdW50KTsKICAgIHJldHVybiAkc3RyaW5nIC4gJ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