<!DOCTYPE html>
<html>
<head>
<title>飲食店原価率・理想売価計算アプリ</title>
<meta charset="UTF-8">
</head>
<body>
<h1>飲食店原価率・理想売価計算アプリ</h1>
<form>
<label for="material_cost">原材料費:</label>
<input type="number" id="material_cost" name="material_cost" required><br><br>
<label for="profit_margin">想定原価率(%):</label>
<input type="number" id="profit_margin" name="profit_margin" required><br><br>
<label for="current_price">現在売価:</label>
<input type="number" id="current_price" name="current_price" required><br><br>
<input type="button" onclick="calculate()" value="計算する">
</form>
<br>
<p id="result"></p>
<script>
function calculate() {
const material_cost = document.getElementById("material_cost").value;
const profit_margin = document.getElementById("profit_margin").value;
const current_price = document.getElementById("current_price").value;
const cost_ratio = (material_cost / current_price) * 100;
const difference = profit_margin - cost_ratio;
const ideal_price = (material_cost / (profit_margin / 100)) * 100;
// セキュリティ対策
if (Math.sign(cost_ratio) <= 0 || Math.sign(difference) <= 0 || Math.sign(ideal_price) <= 0) {
document.getElementById("result").innerHTML = "不正な値が入力されました。";
return;
}
let result = `原価率: ${cost_ratio.toFixed(2)}%<br>`;
result += `想定原価率との差: ${difference.toFixed(2)}%<br>`;
result += `理想売価: ${ideal_price.toFixed(2)}円`;
document.getElementById("result").innerHTML = result;
}
</script>
</body>
</html>