        <?php
    class Employee{
        public $name;
        public $rate;
        public $overtimerate;
        public $hours = array();
        public $overtime = array();
        public $normaltime = array();
        public function __construct($name,$rate) {
            $this->name = $name;
            $this->rate = $rate;
            
        }
        public function getTotalHoursWorked(){
            return array_sum($this->hours); 
        }
       
        public function getSalary(){
            $hours = $this->getTotalHoursWorked();
            
            $salary= (($this->getNormalHours()*$this->rate) + ($this->getOvertimeHours()*($this->rate*2)));
            return $salary;
        }
        public function getShortName(){
           
                   $i= mb_strlen($this->name);
                          while($this->name{$i}!=" "){
                                    $i--;
                                      if ($i<0) break;
                                                     }                                                  
                      $shortname = mb_substr($this->name, 0,$i-2 );
                        return $this->name= $shortname.".";
         }
       
     public function getNormalHours() {
          foreach ($this->hours as $key => $value) {
            
        
            if ($value <=40){
                
       $this->normaltime[$key]= $value;   }  
        else {$this->normaltime[$key]= $value -$this->getOvertimeHours() ;}
            
            
        }
        return array_sum($this->normaltime);
        
        
    }
    public function  getOvertimeHours(){           //подсчет часов сверх нормы
        foreach ($this->hours as $key => $value) {
            
        
            if ($value >40){
                
       $this->overtime[$key]= $value -40;   }  
        else {$this->overtime[$key]= 0 ;}
            
            
        }
        return array_sum($this->overtime);
    }
    
  }
          
       
       
      function padRight($string, $length){
            return $string.= str_repeat(" ", $length-mb_strlen($string));
             
      }
             function padLeft($string, $length){
$string = str_repeat(" ", $length-mb_strlen($string)) .$string;
              return $string;
        }
        
        
        
        $ivan = new Employee("Иван Иванов", 10);
        $ivan ->hours = array(46,40,40,40);
        $peter = new Employee("Петр Петров", 8);
           $ivan-> getShortName();
          $peter-> getShortName();
        $peter ->hours = array(40,10,40,50);
        $peter ->getOvertimeHours();
        $employees = array($ivan,$peter);
     
   
    
$col1 = 30;
$col2 = 10;
echo"<pre>";
  echo   padRight("Сотрудник", $col1).
            padLeft("Часы", $col2).
          padLeft("Овертайм", $col2).
            padLeft("Ставка", $col2).
            padLeft("З/п", $col2). " <br>";
  
  foreach ($employees as $employee) {
    echo padRight($employee->name, $col1) .
         padLeft($employee->getTotalHoursWorked(), $col2) .
             padLeft($employee->getOvertimeHours(), $col2) .
         padLeft($employee->rate, $col2) . 
         padLeft($employee->getSalary(), $col2) . "<br>" ;
   
   
}

        ?>
