<?php
class Employee
{
public $name;
public $rate;
public function __construct($name, $rate)
{
$this->name = $name;
$this->rate = $rate;
}
public function getTotalHoursWorked()
{
}
public function getNormalHours()
{
$normal = 0;
foreach ($this->hours as $week) {
if ($week <= 40) {
$normal = $week + $normal;
} else {
$normal = 40 + $normal;
}
}
return $normal;
}
public function getOvertimeHours()
{
$overtime = 0;
foreach ($this->hours as $week) {
if ($week > 40) {
$overtime = ($week - 40) + $overtime;
} else {
$overtime = $overtime + 0;
}
}
return $overtime;
}
public function getSalary()
{
$hours = $this->getNormalHours();
$overtime = $this->getOvertimeHours();
$salary = $hours * $this->rate + 2 * $this->rate * $overtime;
return $salary;
}
public function getShortName()
{
$firstletter = mb_substr($this->name, 0, 1) . "."; $reg = '/[а-яА-Яё]+\s/u';
$shortname = preg_replace($reg, "", $this->name) . " " . $firstletter; return $shortname;
}
}
$ivan = new Employee('Иван Иванов', 10);
40,
40,
40,
40
);
$peter = new Employee('Пётр Петров', 8); //с другими именами всё работает
40,
10,
40,
50
);
$ivan,
$peter
);
$col1 = 30;
$col2 = 8;
$col3 = 8;
$col4 = 8;
function padRight($string, $length)
{
$string = $string . " ";
}
return $string;
}
function padLeft($string, $length)
{
$string = " " . $string;
}
return $string;
}
//заголовок таблицы
echo padRight("Сотрудник", $col1) . padLeft("Ставка", $col2) . padLeft("Часы", $col3) . padLeft("Овертайм", 10) . padLeft("З/П", $col4) . "\n\n";
//сама таблица
$hours = 0;
$salary = 0;
$overtime = 0;
foreach ($employees as $employee) {
echo padRight($employee->getShortName(), $col1) . padLeft($employee->rate, $col2) . padLeft($employee->getTotalHoursWorked(), $col3) . padLeft($employee->getOverTimeHours(), 10) . padLeft($employee->getSalary(), $col4) . "\n";
$hours = $hours + $employee->getTotalHoursWorked();
$salary = $salary + $employee->getSalary();
$overtime = $overtime + $employee->getOverTimeHours();
}
echo padRight("Всего", 30) . padLeft("", $col2) . padLeft($hours, $col2) . padLeft($overtime, 10) . padLeft($salary, $col2);
PD9waHAKbWJfaW50ZXJuYWxfZW5jb2RpbmcoJ3V0Zi04Jyk7CmNsYXNzIEVtcGxveWVlCnsKICAgIHB1YmxpYyAkbmFtZTsKICAgIHB1YmxpYyAkcmF0ZTsKICAgIHB1YmxpYyAkaG91cnMgPSBhcnJheSgpOwogICAgcHVibGljIGZ1bmN0aW9uIF9fY29uc3RydWN0KCRuYW1lLCAkcmF0ZSkKICAgIHsKICAgICAgICAkdGhpcy0+bmFtZSA9ICRuYW1lOwogICAgICAgICR0aGlzLT5yYXRlID0gJHJhdGU7CiAgICB9CiAgICBwdWJsaWMgZnVuY3Rpb24gZ2V0VG90YWxIb3Vyc1dvcmtlZCgpCiAgICB7CiAgICAgICAgcmV0dXJuIGFycmF5X3N1bSgkdGhpcy0+aG91cnMpOwogICAgfQogICAgcHVibGljIGZ1bmN0aW9uIGdldE5vcm1hbEhvdXJzKCkKICAgIHsKICAgICAgICAkbm9ybWFsID0gMDsKICAgICAgICBmb3JlYWNoICgkdGhpcy0+aG91cnMgYXMgJHdlZWspIHsKICAgICAgICAgICAgaWYgKCR3ZWVrIDw9IDQwKSB7CiAgICAgICAgICAgICAgICAkbm9ybWFsID0gJHdlZWsgKyAkbm9ybWFsOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgJG5vcm1hbCA9IDQwICsgJG5vcm1hbDsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gJG5vcm1hbDsKICAgIH0KICAgIHB1YmxpYyBmdW5jdGlvbiBnZXRPdmVydGltZUhvdXJzKCkKICAgIHsKICAgICAgICAkb3ZlcnRpbWUgPSAwOwogICAgICAgIGZvcmVhY2ggKCR0aGlzLT5ob3VycyBhcyAkd2VlaykgewogICAgICAgICAgICBpZiAoJHdlZWsgPiA0MCkgewogICAgICAgICAgICAgICAgJG92ZXJ0aW1lID0gKCR3ZWVrIC0gNDApICsgJG92ZXJ0aW1lOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgJG92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