<?php
class Employee
{
public $name;
public $rate;
public function __construct($name, $rate)
{
$this->name = $name;
$this->rate = $rate;
}
public function getTotalHoursWorked()
{
}
//без переработок
public function getNormalHours()
{
$normalHours = 0;
foreach($this->hours as $weeks)
{
if($weeks <= 40) {
$normalHours += $weeks;
} elseif($weeks > 40) {
$normalHours = $normalHours + 40;
}
}
return $normalHours;
}
//c переработками
public function getOvertimeHours()
{
$overtimeHours = 0;
foreach($this->hours as $weeks)
{
if($weeks > 40) {
$overtimeHours = $overtimeHours + ($weeks - 40);
}
}
return $overtimeHours;
}
public function getSalary()
{
$hours = $this->getNormalHours();
$salary = $hours * $this->rate;
$overtimeHours = $this->getOvertimeHours();
$salary = $salary + $overtimeHours*$this->rate*2;
return $salary;
}
//получаю сокращённое имя
public function getShortName()
{
$name = $this->name;
$reg = "! ([a-яёА-ЯЁ])([a-яёА-ЯЁ])+!u";
return $shortenedName;
}
}
$ivan = new Employee("Иванов Иван", 10);
$ivan->hours = array(40, 40, 40, 40);
$peter = new Employee("Петров Петр", 8);
$peter->hours = array(40, 10, 40, 50);
$employees = array($ivan, $peter); /*
foreach ($employees as $employee) {
echo "Имя: {$employee->name}\n";
echo "Ставка, тугриков в час: {$employee->rate}\n";
echo "Отработал, часов: {$employee->getTotalHoursWorked()}\n";
echo "Заработал, тугриков: {$employee->getSalary()}\n\n";
}
*/
//пишу функцию для вставки пробелов справа
function padRight($string, $length)
{
if($spaces>0)
{
$string=mb_str_pad
($string, mb_strlen($string) + $spaces, " ", STR_PAD_RIGHT
); }
return $string;
}
//пишу функцию для вставки пробелов слева
function padLeft($string, $length)
{
if($spaces>0)
{
$string=mb_str_pad
($string, mb_strlen($string) + $spaces, " ", STR_PAD_LEFT
); }
return $string;
}
//функция аналог str_pad, только для кириллицы
function mb_str_pad($str, $pad_len, $pad_str = ' ', $dir = STR_PAD_RIGHT, $encoding = NULL)
{
$padBefore = $dir === STR_PAD_BOTH || $dir === STR_PAD_LEFT;
$padAfter = $dir === STR_PAD_BOTH || $dir === STR_PAD_RIGHT;
$targetLen = $padBefore && $padAfter ? $pad_len / 2 : $pad_len;
$strToRepeatLen = mb_strlen($pad_str, $encoding); $repeatTimes = ceil($targetLen / $strToRepeatLen); $before = $padBefore ?
mb_substr($repeatedString, 0, floor($targetLen), $encoding) : ''; $after = $padAfter ?
mb_substr($repeatedString, 0, ceil($targetLen), $encoding) : ''; return $before . $str . $after;
}
$col1 = 30;
$col2 = 10;
$col3 = 10;
$col4 = 10;
echo padRight("Сотрудник", $col1) .
padLeft("Часы", $col2) .
padLeft("Овертайм", $col2) .
padLeft("Ставка", $col3) .
padLeft("З/п", $col4) . "\n";
$totalHours = $totalSalary = $totalOvertime = 0;
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";
$totalHours += $employee->getTotalHoursWorked();
$totalSalary += $employee->getSalary();
$totalOvertime += $employee->getOvertimeHours();
}
//колонка ВСЕГО
echo padRight("Всего", $col1) .
padLeft("$totalHours", $col2) .
padLeft("$totalOvertime", $col2) .
padLeft(" ", $col3) .
padLeft("$totalSalary", $col4) . "\n";
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7Cm1iX2ludGVybmFsX2VuY29kaW5nKCd1dGYtOCcpOwoKY2xhc3MgRW1wbG95ZWUKewogICAgcHVibGljICRuYW1lOwogICAgcHVibGljICRyYXRlOwogICAgcHVibGljICRob3VycyA9IGFycmF5KCk7CgogICAgcHVibGljIGZ1bmN0aW9uIF9fY29uc3RydWN0KCRuYW1lLCAkcmF0ZSkKICAgIHsKICAgICAgICAkdGhpcy0+bmFtZSA9ICRuYW1lOwogICAgICAgICR0aGlzLT5yYXRlID0gJHJhdGU7CiAgICB9CgogICAgcHVibGljIGZ1bmN0aW9uIGdldFRvdGFsSG91cnNXb3JrZWQoKQogICAgewogICAgICAgIHJldHVybiBhcnJheV9zdW0oJHRoaXMtPmhvdXJzKTsKICAgIH0KCiAgICAvL9Cx0LXQtyDQv9C10YDQtdGA0LDQsdC+0YLQvtC6CiAgICBwdWJsaWMgZnVuY3Rpb24gZ2V0Tm9ybWFsSG91cnMoKQogICAgewogICAgICAgICRub3JtYWxIb3VycyA9IDA7CiAgICAgICAgZm9yZWFjaCgkdGhpcy0+aG91cnMgYXMgJHdlZWtzKQogICAgICAgIHsKICAgICAgICAgICAgaWYoJHdlZWtzIDw9IDQwKSB7CiAgICAgICAgICAgICAgICAkbm9ybWFsSG91cnMgKz0gJHdlZWtzOwogICAgICAgICAgICB9IGVsc2VpZigkd2Vla3MgPiA0MCkgewogICAgICAgICAgICAgICAgJG5vcm1hbEhvdXJzID0gJG5vcm1hbEhvdXJzICsgNDA7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuICRub3JtYWxIb3VyczsKICAgIH0KCiAgICAvL2Mg0L/QtdGA0LXRgNCw0LHQvtGC0LrQsNC80LgKICAgIHB1YmxpYyBmdW5jdGlvbiBnZXRPdmVydGltZUhvdXJzKCkKICAgIHsKICAgICAgICAkb3ZlcnRpbWVIb3VycyA9IDA7CiAgICAgICAgZm9yZWFjaCgkdGhpcy0+aG91cnMgYXMgJHdlZWtzKQogICAgICAgIHsKICAgICAgICAgICAgaWYoJHdlZWtzID4gNDApIHsKICAgICAgICAgICAgICAgICRvdmVydGltZUhvdXJzID0gJG92ZXJ0aW1lSG91cnMgKyAoJHdlZWtzIC0gNDApOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiAkb3ZlcnRpbWVIb3VyczsKICAgIH0KCiAgICBwdWJsaWMgZnVuY3Rpb24gZ2V0U2FsYXJ5KCkKICAgIHsKICAgICAgICAkaG91cnMgPSAkdGhpcy0+Z2V0Tm9ybWFsSG91cnMoKTsKICAgICAgICAkc2FsYXJ5ID0gJGhvdXJzICogJHRoaXMtPnJhdGU7CiAgICAgICA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