---
### AIへの指示用プロンプト(計算ロジック強化版)
**【タイトル】**
サポート料金計算ツールの開発依頼(15分ブロック計算ロジック採用)
**【概要】**
以下の要件を満たす、HTML/CSS/JavaScript一体型の料金計算ツールを作成してください。サポーター3名の稼働時間を入力し、15分単位の精密な判定アルゴリズムに基づいて金額を算出します。
**【必須機能と計算ルール】**
1. **モード切り替え:**
* 「さいたま市」と「他市町村」の2つの単価設定を切り替え可能にすること。
2. **15分ブロック単位の判定ロジック(重要):**
* 出発から帰着までの時間を**15分刻みの固定ブロック**に区切って計算すること。
* **ブロック跨ぎの優先:** 1つの15分ブロックが「日中」と「早朝/夜間」の両方の時間帯に跨がる場合は、必ず**単価の高い方(早朝/夜間)を採用**すること。
* **端数の切り上げ:** 全体の時間が15分で割り切れない(余りが出た)場合、その最後の端数は**「15分間の1ブロック」として切り上げて**計算すること。
3. **1時間未満の保証ルール:**
* 合計稼働時間が60分(4ブロック)に満たない場合は、一律で**4ブロック分(1時間分)**の料金を請求する。この際も、1分でも割増時間帯が含まれれば高い方の単価を優先すること。
4. **宿泊除外設定(1人目のみ):**
* チェック時、初日の18:00以降から最終日の翌朝09:00までを計算ブロックから除外すること。
5. **実費の内訳表示:**
* 1人目:交通費、他1、他2、他3の4項目。
* 2人目・3人目:その他実費1項目。
* 表示形式:「(実費内訳:交300、他500)」のように項目名を明記すること。
6. **詳細な計算根拠の表示:**
* 各時間帯ごとに「単価(@円)」「稼働時間(h)」「小計」を表示すること。
7. **デザイン:**
* スマホ対応。ボタンや入力欄を大きくし、余計なコピーボタン等は排除して標準機能でコピーしやすい構成にすること。
**【現在のソースコード】**
<div id="st-calc-container">
<style>
#st-calc-container {
all: initial; display: flex; flex-direction: column; align-items: center; gap: 15px;
font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
background-color: #f4f7f6; padding: 20px; box-sizing: border-box; width: 100%;
}
#st-calc-container * { box-sizing: border-box; }
#st-calc-container { --st-main: #2c3e50; --st-accent: #e74c3c; --st-active: #27ae60; }
#st-calc-container .st-top-controls { width: 100%; max-width: 480px; display: flex; flex-direction: column; gap: 10px; }
#st-calc-container .st-mode-selector { display: flex; gap: 10px; width: 100%; }
#st-calc-container .st-mode-btn { flex: 1; padding: 12px; border: 2px solid #ccc; border-radius: 8px; cursor: pointer; background: white; font-weight: bold; color: #333; transition: 0.2s; }
#st-calc-container .st-mode-btn.st-active { background: var(--st-active); color: white; border-color: var(--st-active); }
#st-calc-container .st-reset-row { display: flex; justify-content: flex-end; }
#st-calc-container .st-btn-reset { padding: 6px 12px; border: 1px solid #95a5a6; border-radius: 4px; cursor: pointer; background: white; color: #95a5a6; font-size: 11px; }
#st-calc-container .st-card { background: white; padding: 20px; border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); width: 100%; max-width: 480px; margin-bottom: 10px; }
#st-calc-container h2 {
text-align: center; background-color: var(--st-main); color: #ffffff !important;
margin: -20px -20px 15px -20px !important; font-size: 1rem !important; padding: 12px !important;
border-radius: 10px 10px 0 0; display: block;
}
#st-calc-container .st-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
#st-calc-container label { flex: 1; font-size: 0.8rem; font-weight: bold; color: #555; margin: 0; }
#st-calc-container input { flex: 2.5; padding: 6px; border: 1px solid #ddd; border-radius: 4px; font-size: 0.9rem; background: white; color: black; height: 35px; }
#st-calc-container .st-row-check { justify-content: flex-start; gap: 5px; border-top: 1px dashed #eee; margin-top: 8px; padding-top: 8px; }
#st-calc-container .st-result-area { background: #fafafa; border: 1px solid #eee; border-radius: 6px; padding: 12px; margin-top: 10px; }
#st-calc-container .st-res-line { display: flex; justify-content: space-between; margin-bottom: 5px; font-size: 0.8rem; color: #333; }
#st-calc-container .st-res-subtotal { font-weight: bold; margin-left: 8px; text-align: right; min-width: 60px; }
#st-calc-container .st-unit-price { color: #888; font-size: 0.75rem; margin-right: 4px; }
#st-calc-container .st-total-line {
display: flex; flex-direction: column; align-items: flex-end; margin-top: 10px; padding-top: 10px;
border-top: 2px solid #eee; font-weight: bold;
}
#st-calc-container .st-jippi-breakdown { font-size: 0.75rem; color: #e67e22; margin-bottom: 4px; font-weight: bold; }
#st-calc-container .st-total-val { font-size: 1.2rem; color: var(--st-accent); }
#st-calc-container .st-grand-total-card { background: var(--st-main); color: white; position: sticky; bottom: 10px; z-index: 100; margin-top: 20px; }
#st-calc-container .st-grand-total-card h2 { background-color: transparent; border-bottom: 1px solid rgba(255,255,255,0.3) !important; margin: 0 0 10px 0 !important; }
#st-calc-container .st-grand-total-display { text-align: center; font-size: 1.8rem; font-weight: bold; }
</style>
<div class="st-top-controls">
<div class="st-mode-selector">
<button id="st_mode_saitama" class="st-mode-btn st-active" onclick="stSetMode('saitama')">さいたま市</button>
<button id="st_mode_others" class="st-mode-btn" onclick="stSetMode('others')">他市町村</button>
</div>
<div class="st-reset-row">
<button class="st-btn-reset" onclick="location.reload()">入力をリセット</button>
</div>
</div>
<div class="st-card">
<h2>サポート1人目</h2>
<div class="st-row"><label>出発</label><input type="datetime-local" id="st_s1"></div>
<div class="st-row"><label>帰着</label><input type="datetime-local" id="st_e1"></div>
<div class="st-row"><label>交通費</label><input type="number" id="st_f1_t" value="0"></div>
<div class="st-row"><label>他1</label><input type="number" id="st_f1_1" value="0"></div>
<div class="st-row"><label>他2</label><input type="number" id="st_f1_2" value="0"></div>
<div class="st-row"><label>他3</label><input type="number" id="st_f1_3" value="0"></div>
<div class="st-row-check"><input type="checkbox" id="st_stay1"><label for="st_stay1">宿泊設定</label></div>
<div class="st-result-area">
<div class="st-res-line"><span>早朝</span><span><span class="st-unit-price">@<span id="st_u1_e">0</span></span><span id="st_h1_early">0.00</span>h=<span class="st-res-subtotal" id="st_c1_early">0</span>円</span></div>
<div class="st-res-line"><span>日中</span><span><span class="st-unit-price">@<span id="st_u1_d">0</span></span><span id="st_h1_day">0.00</span>h=<span class="st-res-subtotal" id="st_c1_day">0</span>円</span></div>
<div class="st-res-line"><span>夜間</span><span><span class="st-unit-price">@<span id="st_u1_n">0</span></span><span id="st_h1_night">0.00</span>h=<span class="st-res-subtotal" id="st_c1_night">0</span>円</span></div>
<div class="st-total-line">
<span class="st-jippi-breakdown" id="st_break1"></span>
<span class="st-total-val">小計:<span id="st_t1">0</span>円</span>
</div>
</div>
</div>
<div class="st-card">
<h2>サポート2人目</h2>
<div class="st-row"><label>出発</label><input type="datetime-local" id="st_s2"></div>
<div class="st-row"><label>帰着</label><input type="datetime-local" id="st_e2"></div>
<div class="st-row"><label>その他</label><input type="number" id="st_f2_t" value="0"></div>
<div class="st-result-area">
<div class="st-res-line"><span>早朝</span><span><span class="st-unit-price">@<span id="st_u2_e">0</span></span><span id="st_h2_early">0.00</span>h=<span class="st-res-subtotal" id="st_c2_early">0</span>円</span></div>
<div class="st-res-line"><span>日中</span><span><span class="st-unit-price">@<span id="st_u2_d">0</span></span><span id="st_h2_day">0.00</span>h=<span class="st-res-subtotal" id="st_c2_day">0</span>円</span></div>
<div class="st-res-line"><span>夜間</span><span><span class="st-unit-price">@<span id="st_u2_n">0</span></span><span id="st_h2_night">0.00</span>h=<span class="st-res-subtotal" id="st_c2_night">0</span>円</span></div>
<div class="st-total-line">
<span class="st-jippi-breakdown" id="st_break2"></span>
<span class="st-total-val">小計:<span id="st_t2">0</span>円</span>
</div>
</div>
</div>
<div class="st-card">
<h2>サポート3人目</h2>
<div class="st-row"><label>出発</label><input type="datetime-local" id="st_s3"></div>
<div class="st-row"><label>帰着</label><input type="datetime-local" id="st_e3"></div>
<div class="st-row"><label>その他</label><input type="number" id="st_f3_t" value="0"></div>
<div class="st-result-area">
<div class="st-res-line"><span>早朝</span><span><span class="st-unit-price">@<span id="st_u3_e">0</span></span><span id="st_h3_early">0.00</span>h=<span class="st-res-subtotal" id="st_c3_early">0</span>円</span></div>
<div class="st-res-line"><span>日中</span><span><span class="st-unit-price">@<span id="st_u3_d">0</span></span><span id="st_h3_day">0.00</span>h=<span class="st-res-subtotal" id="st_c3_day">0</span>円</span></div>
<div class="st-res-line"><span>夜間</span><span><span class="st-unit-price">@<span id="st_u3_n">0</span></span><span id="st_h3_night">0.00</span>h=<span class="st-res-subtotal" id="st_c3_night">0</span>円</span></div>
<div class="st-total-line">
<span class="st-jippi-breakdown" id="st_break3"></span>
<span class="st-total-val">小計:<span id="st_t3">0</span>円</span>
</div>
</div>
</div>
<div class="st-card st-grand-total-card">
<h2 id="st_total_title">総合計金額 (さいたま市)</h2>
<div class="st-grand-total-display"><span id="st_grand_total">0</span><span>円</span></div>
</div>
<script>
(function() {
let mode = 'saitama';
window.stSetMode = function(m) {
mode = m;
document.getElementById('st_mode_saitama').classList.toggle('st-active', mode === 'saitama');
document.getElementById('st_mode_others').classList.toggle('st-active', mode === 'others');
document.getElementById('st_total_title').innerText = `総合計金額 (${mode === 'saitama' ? 'さいたま市' : '他市町村'})`;
stCalcAll();
};
function stCalcAll() {
const r1 = mode === 'saitama' ? { early: 1000, day: 800, night: 1000 } : { early: 1200, day: 1000, night: 1200 };
const rO = mode === 'saitama' ? { early: 500, day: 400, night: 500 } : { early: 600, day: 500, night: 600 };
let g = 0;
g += stCalcSingle(1, r1);
g += stCalcSingle(2, rO);
g += stCalcSingle(3, rO);
document.getElementById('st_grand_total').innerText = g.toLocaleString();
}
function stCalcSingle(n, rates) {
document.getElementById(`st_u${n}_e`).innerText = rates.early.toLocaleString();
document.getElementById(`st_u${n}_d`).innerText = rates.day.toLocaleString();
document.getElementById(`st_u${n}_n`).innerText = rates.night.toLocaleString();
const sVal = document.getElementById(`st_s${n}`).value;
const eVal = document.getElementById(`st_e${n}`).value;
if (!sVal || !eVal) return 0;
const start = new Date(sVal), end = new Date(eVal);
const totalMins = (end - start) / 60000;
if (totalMins <= 0) return 0;
let hE = 0, hD = 0, hN = 0;
const stay = (n === 1) && document.getElementById('st_stay1')?.checked;
if (totalMins < 60) {
let hasExtra = false;
for (let m = 0; m < totalMins; m++) {
let hh = new Date(start.getTime() + m * 60000).getHours();
if (hh < 8 || hh >= 20) hasExtra = true;
}
if (hasExtra) { if (start.getHours() < 12) hE = 1.0; else hN = 1.0; }
else hD = 1.0;
} else {
for (let i = 0; i < totalMins; i += 15) {
let t = new Date(start.getTime() + i * 60000);
if (stay) {
const timeM = t.getHours() * 60 + t.getMinutes();
if (t.toDateString() === start.toDateString() && timeM >= 1080) continue;
if (t.toDateString() === end.toDateString() && timeM < 540) continue;
}
let hh = t.getHours();
if (hh < 8) hE += 0.25; else if (hh >= 20) hN += 0.25; else hD += 0.25;
}
}
const cE = Math.floor(hE * rates.early), cD = Math.floor(hD * rates.day), cN = Math.floor(hN * rates.night);
let bld = [], totalJ = 0;
if (n === 1) {
const ft = Number(document.getElementById('st_f1_t').value)||0, f1 = Number(document.getElementById('st_f1_1').value)||0, f2 = Number(document.getElementById('st_f1_2').value)||0, f3 = Number(document.getElementById('st_f1_3').value)||0;
if(ft>0) bld.push(`交${ft}`); if(f1>0) bld.push(`他${f1}`); if(f2>0) bld.push(`他${f2}`); if(f3>0) bld.push(`他${f3}`);
totalJ = ft+f1+f2+f3;
} else {
const ft = Number(document.getElementById(`st_f${n}_t`).value)||0;
if(ft>0) bld.push(`他${ft}`);
totalJ = ft;
}
document.getElementById(`st_h${n}_early`).innerText = hE.toFixed(2);
document.getElementById(`st_h${n}_day`).innerText = hD.toFixed(2);
document.getElementById(`st_h${n}_night`).innerText = hN.toFixed(2);
document.getElementById(`st_c${n}_early`).innerText = cE.toLocaleString();
document.getElementById(`st_c${n}_day`).innerText = cD.toLocaleString();
document.getElementById(`st_c${n}_night`).innerText = cN.toLocaleString();
document.getElementById(`st_break${n}`).innerText = bld.length > 0 ? "(実費内訳:" + bld.join("、") + ")" : "";
const sub = cE + cD + cN + totalJ;
document.getElementById(`st_t${n}`).innerText = sub.toLocaleString();
return sub;
}
const container = document.getElementById('st-calc-container');
container.addEventListener('input', stCalcAll);
container.addEventListener('change', stCalcAll);
stCalcAll();
})();
</script>
</div>
---
### 変更のポイント(AIが理解する背景)
* **「2つの時間帯をまたがるブロックの場合は、高い方を採用する」**:
例えば、7:55〜8:10という15分ブロックがあった場合、5分間は早朝(割増)、10分間は日中ですが、この15分間全体に「早朝単価」を適用させる指示です。
* **「15で割り切れなかったブロックは切り上げ」**:
40分の稼働なら「15分×3ブロック=45分分」として計算させる、利用者にとって不利にならない(サポーターの権利を守る)ための計算ルールです。
このプロンプトを貼り付ければ、どのAIでも「15分単位の厳密な計算機」として正しくプログラムを組んでくれます。
筆者余談
わたしは、Geminiにつくってもらいました。
自分で組んでみたい人用にプロンプトをGeminiに出してもらいました。
青文字のところを、チャットに書き込めばやってくれるんじゃないかなぁ。
疲れたので、今日は寝ることにします。