Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <meta charset="utf-8"/>
- <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
- </head>
- <body>
- <?php
- class Table {
- public $columns=0;
- public $table = array();
- public $tableBody;
- public $id=0;
- public $columnNames = array();
- public function __construct($columns, $names)
- {
- $this->columns = $columns;
- if(isset($names)) {
- $this->columnNames = $names;
- }
- else {
- for($i=1;$i<=$this->columns;$i++) {
- $this->columnNames['column' . $i] = 'column' . $i;
- }
- }
- }
- public function addCell($item) {
- $columnsTotal = $this->columns;
- $id = count($this->table['items'])+1;
- $this->table['items'][] = $item;
- }
- public function renderTable() {
- echo "<table class='table'>";
- echo "<thead>";
- echo "<tr>";
- foreach($this->columnNames as $key=>$value) {
- echo "<th>{$value}</th>";
- }
- echo "</tr>";
- echo "</thead>";
- echo "<tbody>";
- foreach($this->table['items'] as $key => $value) {
- echo "<tr>";
- foreach($value as $cell) {
- echo "<td> {$cell} </td>";
- }
- echo "</tr>";
- }
- echo "</tbody>";
- echo "</table>";
- }
- }
- class Worker {
- public $firstName;
- public $lastName;
- public $middleName;
- public $hourRate;
- public $hours = array();
- public function __construct($firstName,
- $lastName,
- $middleName,
- $hourRate)
- {
- $this->firstName = $firstName;
- $this->lastName = $lastName;
- $this->middleName = $middleName;
- $this->hourRate = $hourRate;
- }
- public function getTotalHours() {
- return array_sum($this->hours);
- }
- public function getOverTimePay() {
- $needOverPay = 0;
- foreach($this->hours as $hoursPerWeek) {
- if($hoursPerWeek>40) {
- $payedTime = $hoursPerWeek - 40;
- $overTimePay = $payedTime * $hourRate;
- $needOverPay = $needOverPay + $overTimePay;
- return $needOverPay;
- }
- }
- }
- public function getOverTimeHours() {
- foreach($this->hours as $hoursPerWeek) {
- if($hoursPerWeek>40) {
- $overTime = $hoursPerWeek - 40;
- }
- else {
- $overTime = 0;
- }
- return $overTime;
- var_dump($overTime);
- }
- }
- public function getFullName() {
- $fullName = $this->firstName . " " . $this->lastName . " ". $this->middleName;
- return $fullName;
- }
- public function getShortName() {
- $shortName = $this->lastName . ' ' . iconv_substr($this->firstName, 0, 2) . '.';
- return $shortName;
- }
- public function getSalary() {
- $totalHours = $this->getTotalHours();
- $salary = $totalHours * $this->hourRate + $this->getOverTimePay();
- return $salary;
- }
- public function getInfo() {
- return array($this->getShortName(),
- $this->hourRate . ' руб в час',
- $this->getSalary() . ' руб',
- $this->getOverTimeHours() . ' ч',
- $this->getTotalHours() . ' ч');
- }
- }
- class Control {
- public $totalSalary = 0;
- public $totalOverTime = 0;
- public $totalHours = 0;
- public function workersTotalData($workers) {
- foreach($workers as $worker) {
- $this->totalSalary = $this->totalSalary + $worker->getSalary();
- $this->totalOverTime = $this->totalOverTime + $worker->getOverTimeHours();
- $this->totalHours = $this->totalHours + $worker->getTotalHours();
- }
- return array('totalSalary'=>$this->totalSalary,
- 'totalOverTime'=>$this->totalOverTime,
- 'totalHours'=>$this->totalHours);
- }
- }
- $ivan = new Worker("Иван", "Иванов", "Иванович", 12);
- $ivan->hours = array(100, 40, 40, 40);
- $tagil = new Worker("Тагил", "Алексеев", "Рафисович", 15);
- $tagil->hours = array(100, 40, 40, 40);
- $gamaz = new Worker("Гамаз", "Тугрев", "Тугрикович", 25);
- $gamaz->hours = array(120, 40, 40, 40);
- $workers = array($ivan, $tagil, $gamaz);
- $columnNames = array('column1' => 'Сотрудник',
- 'сolumn2'=>'Ставка',
- 'column3'=>'ЗП',
- 'column4' => 'Овертайм',
- 'column5' =>'Всего часов');
- $result = new Table($columns=5, $columnNames);
- foreach($workers as $worker) {
- $result->AddCell($worker->getInfo());
- }
- $report = new Control();
- $report->workersTotalData($workers);
- $result->AddCell(array('Всего', '-',
- $report->totalSalary . ' руб',
- $report->totalOverTime . ' ч',
- $report->totalHours . ' ч'));
- $result->renderTable();
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement