<?php

mb_internal_encoding("UTF-8");

class Employee
{
    public $name;
    public $rate;
    public $hours = array();
    
    public function getTotalHoursWorked()
    {
        return array_sum($this->hours);
    }
    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 = '.';
        $z       = preg_replace($pattern, $replace, $this->name);
        return $z;
        
    }
    public function getOverTimeHours()
    {
        $overtime = 0;
        foreach ($this->hours as $hours) {
            if ($hours >= 40) {
                
                $overtime += $hours - 40;
                
            }
        }
        return $overtime;
    }
    
    
    
    
}
$ivan = new Employee("Иванов Иван", 10);

$ivan->hours = array(
    40,
    40,
    40,
    40
);

$peter = new Employee("Петров Петр", 8);

$peter->hours   = array(
    40,
    10,
    40,
    50
);
$mikhail        = new Employee("Михайлов Михаил", 12);
$mikhail->hours = array(
    40,
    40,
    60,
    40
);

$employees = array(
    $ivan,
    $peter,
    $mikhail
);
$col1      = 30;
$col2      = 8;
$col3      = 8;
$col4      = 8;
function padRight($string, $arg)
{
    $count = $arg - mb_strlen($string);
    if ($count <= 0) {
        return $string;
    }
    $space = str_repeat(' ', $count);
    return $string . $space;
}
function padLeft($string, $arg)
{
    $count = $arg - mb_strlen($string);
    if ($count <= 0) {
        return $string;
    }
    $space = str_repeat(' ', $count);
    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";