name = $n ; } public function addEmployee( Employee $emp ) { $this -> employees[] = $emp ; } public function getEmployee( int $n ) : Employee { return $this -> employees[$n] ; } public function addEmployees( array $emp ) { foreach( $emp as $value ) { $this -> employees[] = $value ; } } public function getEmployees( ) : array { return $this -> employees ; } public function getName() : string { return $this -> name ; } public function countEmployees () : int { return count( $this -> employees ) ; } public function getOverallSalary () : float { $sum = 0 ; foreach( $this -> employees as $value ) { $sum += $value -> getSalary() ;} return $sum ; } public function getOverallCoffee () : float { $sum = 0 ; foreach( $this -> employees as $value ) { $sum += $value -> getCoffee() ;} return $sum ; } public function getOverallDocuments () : int { $sum = 0 ; foreach( $this -> employees as $value ) { $sum += $value -> getDocuments() ;} return $sum ; } public function salaryDocumentRatio () : float { return $this -> getOverallSalary() / $this -> getOverallDocuments() ; } } class Employee //завершен { private $occupation ; private $ishead ; function __construct( Occupation $occ , int $r = 1 , bool $i = false) { $this -> rank = $r ; $this -> occupation = $occ ; $this -> ishead = $i ; } public function setHead() { $this -> ishead = true ; } public function changeOccupation( Occupation $occ ) { $this -> occupation = $occ ; } public function changeRank( int $r ) { $this -> rank = $r ; } public function getSalary() : float { switch( $this -> rank ) { case 1 : $sum = $this -> occupation -> getBaseSalary() ; break ; case 2 : $sum = ( $this -> occupation -> getBaseSalary() )*1.25 ; break ; case 3 : $sum = ( $this -> occupation -> getBaseSalary() )*1.5 ; break ; } if( $this -> ishead) { $sum *= 1.5 ;} return $sum ; } public function getDocuments() : int { return ($this -> ishead) ? 0 : $this -> occupation -> getBaseDocuments() ; } public function getCoffee() : float { return ($this -> ishead) ? ($this -> occupation -> getBaseCoffee())*2 : $this -> occupation -> getBaseCoffee() ; } } class Occupation //завершен { private $name ; private $base_salary ; private $base_coffee ; private $base_documents ; function __construct( string $n , float $bs , float $bc , int $bd) { $this -> name = $n ; $this -> base_salary = $bs ; $this -> base_coffee = $bc ; $this -> base_documents = $bd ; } public function getName() : string { return $this -> name ; } public function getBaseSalary() : float { return $this -> base_salary ; } public function getBaseDocuments() : int { return $this -> base_documents ; } public function getBaseCoffee() : int { return $this -> base_coffee ; } } function createEmployees( int $n , int $r , Occupation $occ , Department $dpt ) { $i = 0 ; while ( $i < $n ) { $dpt -> addEmployee( new Employee( $occ , $r ) ) ; $i++ ; } } function createReport( Department ...$dep ) { $sum1 = 0 ; $sum2 = 0; $sum3 = 0; $sum4 = 0; $sum5 = 0; echo "" ; foreach( $dep as $value ) { echo "" ; $sum1 += $value -> countEmployees() ; $sum2 += $value -> getOverallSalary() ; $sum3 += $value -> getOverallCoffee() ; $sum4 += $value -> getOverallDocuments() ; $sum5 += number_format( $value -> salaryDocumentRatio() , 2 ) ; } echo "" ; echo "
ДепартаментСотрудникиЗарплатаКофеДокументыТугр./Докум.
" .$value -> getName() ."" .$value -> countEmployees() ."" .$value -> getOverallSalary() ."" .$value -> getOverallCoffee() ."" .$value -> getOverallDocuments() ."" .number_format( $value -> salaryDocumentRatio() , 2 ) ."
Всего$sum1$sum2$sum3$sum4$sum5
" ; } //создаем профессии и департаменты $manager = new Occupation( 'Менеджер' , 500 , 20 , 200 ) ; $market = new Occupation( 'Маркетолог' , 400 , 15 , 150 ) ; $engineer = new Occupation( 'Инженер' , 200 , 5 , 50 ) ; $analyst = new Occupation( 'Аналитик' , 800 , 50 , 5 ) ; $buy = new Department( 'Закупок' ) ; $sales = new Department( 'Продаж' ) ; $advert = new Department( 'Рекламы' ) ; $logist = new Department( 'Логистики' ) ; //заполняем департамен закупок createEmployees( 9 , 1 , $manager , $buy ) ; createEmployees( 3 , 2 , $manager , $buy ) ; createEmployees( 2 , 3 , $manager , $buy ) ; createEmployees( 2 , 1 , $market , $buy ) ; $head_buy = new Employee( $manager , 2 , true ) ; $buy -> addEmployee( $head_buy ) ; //заполняем департамент продаж createEmployees( 12 , 1 , $manager , $sales ) ; createEmployees( 6 , 1 , $market , $sales ) ; createEmployees( 3 , 1 , $analyst , $sales ) ; createEmployees( 2 , 2 , $analyst , $sales ) ; $head_sales = new Employee( $market , 2 , true ) ; $sales -> addEmployee( $head_sales ) ; //создаем департамент рекламы createEmployees( 15 , 1 , $market , $advert ) ; createEmployees( 10 , 2 , $market , $advert ) ; createEmployees( 8 , 1 , $manager , $advert ) ; createEmployees( 2 , 1 , $engineer , $advert ) ; $head_advert = new Employee( $market , 3 , true ) ; $advert -> addEmployee( $head_advert ) ; //создаем департамент логистики createEmployees( 13 , 1 , $manager , $logist ) ; createEmployees( 5 , 2 , $manager , $logist ) ; createEmployees( 5 , 1 , $engineer , $logist ) ; $head_logist = new Employee( $manager , 1 , true ) ; $logist -> addEmployee( $head_logist ) ; createReport( $logist , $advert , $sales , $buy ) ; ?>