월별 철판단가표 만들어보기 기존 자료를 활용한 작업
철판이 입고되면 그 철판의 단가를 월별로 비교하는 루틴을 제작중인데,
연구과제가 몇가지 있다.
<div class="container">
<div class="row mt-3 mb-1 p-1 m-2">
<table class="table table-hover table-border">
<thead class=" table-secondary">
<tr>
<th class="text-center">아이템</th>
<th class="text-center">월</th>
<th class="text-center">Kg당 단가 (원)</th>
</tr>
</thead>
<tbody>
<?php
try {
$current_month = date('Y-m');
$start_month = date('Y-m', strtotime('-23 months'));
for ($i = 23; $i >= 0; $i--) {
$target_month = date('Y-m-01', strtotime("$start_month +$i months"));
$next_month = date('Y-m-01', strtotime("$target_month +1 month"));
$sqlsearch = "SELECT item, spec, steelnum, suppliercost FROM mirae8440.cost WHERE outdate >= :target_month AND outdate < :next_month";
$stmt = $pdo->prepare($sqlsearch);
$stmt->bindParam(':target_month', $target_month);
$stmt->bindParam(':next_month', $next_month);
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$item = $row['item'];
$spec = $row['spec'];
$steelnum = $row['steelnum'];
$suppliercost = $row['suppliercost'];
$temp_arr = explode('*', $spec);
$saved_weight = ($temp_arr[0] * $temp_arr[1] * $temp_arr[2] * 7.93 * (int)$steelnum) / 1000000;
$saved_weight = sprintf('%0.1f', $saved_weight);
$number = (int)str_replace(',', '', $suppliercost);
$unit_weight = $number > 0 ? number_format(floor($number / $saved_weight)) : 0;
echo "<tr>";
echo "<td class='text-center'>" . htmlspecialchars($item) . "</td>";
echo "<td class='text-center'>" . htmlspecialchars(substr($target_month, 0, 7)) . "</td>";
echo "<td class='text-center text-success'>" . htmlspecialchars($unit_weight) . "</td>";
echo "</tr>";
}
}
} catch (PDOException $Exception) {
error_log("오류: " . $Exception->getMessage());
}
?>
</tbody>
</table>
</div>
</div>
위의 코드를 활용해서 더 의미있는 자료를 만들어 내야 겠다~