MIF_E31211958/app/Views/Perhitungan/list.php

419 lines
23 KiB
PHP

<div class="row page-titles">
<div class="col-md-5 align-self-center">
<h4 class="text-themecolor">Data Perhitungan</h4>
</div>
<div class="col-md-7 align-self-center">
<div class="d-flex justify-content-end align-items-center">
<ol class="breadcrumb mr-3"> <!-- Menambahkan kelas mr-2 untuk margin kanan -->
<li class="breadcrumb-item"><a href="javascript:void(0)">Data Master</a></li>
<li class="breadcrumb-item active">Data Kriteria</li>
</ol>
<form id="filterForm" method="post" action="<?= base_url('perhitungan/index') ?>">
<select class="form-control custom-select" onchange="document.getElementById('filterForm').submit()"
style="width: auto; height:36px;" name="bulan">
<option value="NULL">Pilih Bulan</option>
<?php
$bulan_selected = isset($bulan_selected) ? $bulan_selected : '';
$bulan_sekarang = date("F");
$bulan = array(
"1" => "Januari",
"2" => "Februari",
"3" => "Maret",
"4" => "April",
"5" => "Mei",
"6" => "Juni",
"7" => "Juli",
"8" => "Agustus",
"9" => "September",
"10" => "Oktober",
"11" => "November",
"12" => "Desember"
);
$bulan_english = array(
"Januari" => "January",
"Februari" => "February",
"Maret" => "March",
"April" => "April",
"Mei" => "May",
"Juni" => "June",
"Juli" => "July",
"Agustus" => "August",
"September" => "September",
"Oktober" => "October",
"November" => "November",
"Desember" => "December"
);
foreach ($bulan as $num => $nama_bulan) {
$nama_bulan_english = $bulan_english[$nama_bulan];
$selected = ($nama_bulan_english == $bulan_sekarang || $num == $bulan_selected) ? 'selected' : '';
echo '<option value="' . $num . '" ' . $selected . '>' . $nama_bulan . '</option>';
}
?>
</select>
<select class="form-control custom-select" onchange="document.getElementById('filterForm').submit()"
style="width: auto; height:36px;" name="tahun">
<option value="NULL">Pilih Tahun</option>
<?php
$tahun_selected = isset($tahun_selected) ? $tahun_selected : '';
$tahun_sekarang = date("Y");
for ($i = $tahun_sekarang; $i >= 2010; $i--) {
$selected = ($i == $tahun_sekarang || $i == $tahun_selected) ? 'selected' : '';
echo '<option value="' . $i . '" ' . $selected . '>' . $i . '</option>';
}
?>
</select>
</form>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<h4 class="card-title">Tabel Kriteria</h4>
<div class="table-responsive">
<table id="myTable" class="display nowrap table table-hover table-striped table-bordered"
cellspacing="0" width="100%">
<thead>
<tr>
<?php
foreach ($kriteria as $row): ?>
<th><?= $row->kode_kriteria . ' (' . $row->tipe . ')'; ?></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<tr>
<?php
$no = 1;
foreach ($kriteria as $row): ?>
<td>
<?= $row->bobot; ?>
</td>
<?php endforeach; ?>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<h4 class="card-title">Matriks Keputusan</h4>
<div class="table-responsive">
<table id="myTable4" class="display nowrap table table-hover table-striped table-bordered"
cellspacing="0" width="100%">
<thead>
<tr>
<th>No.</th>
<th>Nama Alternatif</th>
<th>K1</th>
<th>K2</th>
<th>K3</th>
<th>K4</th>
<th>K5</th>
<th>K6</th>
<th>K7</th>
<th>K8</th>
<th>K9</th>
</tr>
</thead>
<tbody>
<?php
$no = 1;
foreach ($perhitungan as $row): ?>
<tr>
<td>
<?= $no++; ?>
</td>
<td>
<?= $row->nama_guru; ?>
</td>
<td>
<?= $row->k1; ?>
</td>
<td>
<?= $row->k2; ?>
</td>
<td>
<?= $row->k3; ?>
</td>
<td>
<?= $row->k4; ?>
</td>
<td>
<?= $row->k5; ?>
</td>
<td>
<?= $row->k6; ?>
</td>
<td>
<?= $row->k7; ?>
</td>
<td>
<?= $row->k8; ?>
</td>
<td>
<?= $row->k9; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<h4 class="card-title">Normalisasi</h4>
<h6 class="card-subtitle">Benefit = <span>X<sub>ij</sub></span><span>/ Max X<sub>ij</sub></span></h6>
<h6 class="card-subtitle">Cost = <span>Min X<sub>ij</sub></span><span>/ X<sub>ij</sub></span></h6>
<div class="table-responsive">
<table id="myTable2" class="display nowrap table table-hover table-striped table-bordered"
cellspacing="0" width="100%">
<thead>
<tr>
<th>No.</th>
<th>Nama Alternatif</th>
<th>K1</th>
<th>K2</th>
<th>K3</th>
<th>K4</th>
<th>K5</th>
<th>K6</th>
<th>K7</th>
<th>K8</th>
<th>K9</th>
</tr>
</thead>
<tbody>
<?php
$no = 1;
foreach ($perhitungan as $row): ?>
<tr>
<td><?= $no++; ?></td>
<td><?= $row->nama_guru; ?></td>
<?php
foreach ($kriteria as $k): ?>
<td>
<?php
// Check if the criterion is beneficial or a cost
if ($k->kode_kriteria == 'K1') {
if ($k->tipe == 'Benefit') {
// Benefit: xij / max(xij)
echo $row->k1 / 4;
} else {
// Cost: min(xij) / xij
echo 1 / $row->k1;
}
} elseif ($k->kode_kriteria == 'K2') {
if ($k->tipe == 'Benefit') {
// Benefit: xij / max(xij)
echo $row->k2 / 4;
} else {
// Cost: min(xij) / xij
echo 1 / $row->k2;
}
} elseif ($k->kode_kriteria == 'K3') {
if ($k->tipe == 'Benefit') {
// Benefit: xij / max(xij)
echo $row->k3 / 4;
} else {
// Cost: min(xij) / xij
echo 1 / $row->k3;
}
} elseif ($k->kode_kriteria == 'K4') {
if ($k->tipe == 'Benefit') {
// Benefit: xij / max(xij)
echo $row->k4 / 4;
} else {
// Cost: min(xij) / xij
echo 1 / $row->k4;
}
} elseif ($k->kode_kriteria == 'K5') {
if ($k->tipe == 'Benefit') {
// Benefit: xij / max(xij)
echo $row->k5 / 4;
} else {
// Cost: min(xij) / xij
echo 1 / $row->k5;
}
} elseif ($k->kode_kriteria == 'K6') {
if ($k->tipe == 'Benefit') {
// Benefit: xij / max(xij)
echo $row->k6 / 4;
} else {
// Cost: min(xij) / xij
echo 1 / $row->k6;
}
} elseif ($k->kode_kriteria == 'K7') {
if ($k->tipe == 'Benefit') {
// Benefit: xij / max(xij)
echo $row->k7 / 4;
} else {
// Cost: min(xij) / xij
echo 1 / $row->k7;
}
} elseif ($k->kode_kriteria == 'K8') {
if ($k->tipe == 'Benefit') {
// Benefit: xij / max(xij)
echo $row->k8 / 4;
} else {
// Cost: min(xij) / xij
echo 1 / $row->k8;
}
} elseif ($k->kode_kriteria == 'K9') {
if ($k->tipe == 'Benefit') {
// Benefit: xij / max(xij)
echo $row->k9 / 4;
} else {
// Cost: min(xij) / xij
echo 1 / $row->k9;
}
}
?>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<h4 class="card-title">Preferensi</h4>
<div class="table-responsive">
<table id="myTable3" class="display nowrap table table-hover table-striped table-bordered"
cellspacing="0" width="100%">
<thead>
<tr>
<th>No.</th>
<th>Nama Alternatif</th>
<th>Perhitungan</th>
<th>Hasil</th>
</tr>
</thead>
<tbody>
<?php
$no = 1;
foreach ($perhitungan as $row): ?>
<tr>
<td><?= $no++; ?></td>
<td><?= $row->nama_guru; ?></td>
<td>
<?php
// Initialize sum and formula string
$sum = 0;
$formula = "SUM (";
foreach ($kriteria as $k): ?>
<?php
// Calculate sum of product of weight and normalized value for each criterion
if ($k->kode_kriteria == 'K1') {
if ($k->tipe == 'Benefit') {
$sum += $k->bobot * ($row->k1 / 4);
$formula .= $k->bobot . " x " . ($row->k1 / 4) . ") + (";
} else {
$sum += $k->bobot * (1 / $row->k1);
$formula .= $k->bobot . " x " . (1 / $row->k1) . ") + (";
}
} elseif ($k->kode_kriteria == 'K2') {
if ($k->tipe == 'Benefit') {
$sum += $k->bobot * ($row->k2 / 4);
$formula .= $k->bobot . " x " . ($row->k2 / 4) . ") + (";
} else {
$sum += $k->bobot * (1 / $row->k2);
$formula .= $k->bobot . " x " . (1 / $row->k2) . ") + (";
}
} elseif ($k->kode_kriteria == 'K3') {
if ($k->tipe == 'Benefit') {
$sum += $k->bobot * ($row->k3 / 4);
$formula .= $k->bobot . " x " . ($row->k3 / 4) . ") + (";
} else {
$sum += $k->bobot * (1 / $row->k3);
$formula .= $k->bobot . " x " . (1 / $row->k3) . ") + (";
}
} elseif ($k->kode_kriteria == 'K4') {
if ($k->tipe == 'Benefit') {
$sum += $k->bobot * ($row->k4 / 4);
$formula .= $k->bobot . " x " . ($row->k4 / 4) . ") + (";
} else {
$sum += $k->bobot * (1 / $row->k4);
$formula .= $k->bobot . " x " . (1 / $row->k4) . ") + (";
}
} elseif ($k->kode_kriteria == 'K5') {
if ($k->tipe == 'Benefit') {
$sum += $k->bobot * ($row->k5 / 4);
$formula .= $k->bobot . " x " . ($row->k5 / 4) . ") + (";
} else {
$sum += $k->bobot * (1 / $row->k5);
$formula .= $k->bobot . " x " . (1 / $row->k5) . ") + (";
}
} elseif ($k->kode_kriteria == 'K6') {
if ($k->tipe == 'Benefit') {
$sum += $k->bobot * ($row->k6 / 4);
$formula .= $k->bobot . " x " . ($row->k6 / 4) . ") + (";
} else {
$sum += $k->bobot * (1 / $row->k6);
$formula .= $k->bobot . " x " . (1 / $row->k6) . ") + (";
}
} elseif ($k->kode_kriteria == 'K7') {
if ($k->tipe == 'Benefit') {
$sum += $k->bobot * ($row->k7 / 4);
$formula .= $k->bobot . " x " . ($row->k7 / 4) . ") + (";
} else {
$sum += $k->bobot * (1 / $row->k7);
$formula .= $k->bobot . " x " . (1 / $row->k7) . ") + (";
}
} elseif ($k->kode_kriteria == 'K8') {
if ($k->tipe == 'Benefit') {
$sum += $k->bobot * ($row->k8 / 4);
$formula .= $k->bobot . " x " . ($row->k8 / 4) . ") + (";
} else {
$sum += $k->bobot * (1 / $row->k8);
$formula .= $k->bobot . " x " . (1 / $row->k8) . ") + (";
}
} elseif ($k->kode_kriteria == 'K9') {
if ($k->tipe == 'Benefit') {
$sum += $k->bobot * ($row->k9 / 4);
$formula .= $k->bobot . " x " . ($row->k9 / 4) . " + ";
} else {
$sum += $k->bobot * (1 / $row->k9);
$formula .= $k->bobot . " x " . (1 / $row->k9) . " + ";
}
}
?>
<?php endforeach;
// Remove the last " + " from the formula string
$formula = rtrim($formula, " + ");
$formula .= ")";
echo $formula;
?>
</td>
<td>
<?= $sum; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>