Commit ·
eac2541
1
Parent(s): f555b1d
fix: 早朝手当を5:30〜9:00の重複時間のみに適用
Browse files全朝食シフトではなく、シフト時刻と5:30〜9:00の重複時間を算出し
その時間分のみ早朝手当を加算するよう計算ロジックを修正
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- db/repositories.py +50 -27
db/repositories.py
CHANGED
|
@@ -778,40 +778,64 @@ def get_multi_period_stats(period_ids: list[int]) -> dict:
|
|
| 778 |
|
| 779 |
settings = {r["key"]: r["value"] for r in setting_rows}
|
| 780 |
|
| 781 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 782 |
s = settings.get(f"ft_{pos}_{slot}_start", "06:00" if slot == "breakfast" else "17:00")
|
| 783 |
e = settings.get(f"ft_{pos}_{slot}_end", "11:00" if slot == "breakfast" else "22:00")
|
| 784 |
-
|
| 785 |
-
eh, em = map(int, e.split(":"))
|
| 786 |
-
return max(0.0, (eh + em / 60.0) - (sh + sm / 60.0))
|
| 787 |
|
| 788 |
-
|
| 789 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 790 |
for r in req_rows:
|
| 791 |
-
pid_r
|
| 792 |
-
eid_r
|
| 793 |
date_r = r["date"]
|
| 794 |
pat_id = r["pattern_id"]
|
|
|
|
| 795 |
if pat_id == "custom" and r["custom_start"] and r["custom_end"]:
|
| 796 |
-
sh
|
| 797 |
-
eh
|
| 798 |
-
hrs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 799 |
elif pat_id and pat_id in PATTERN_MAP:
|
| 800 |
p = PATTERN_MAP[pat_id]
|
| 801 |
-
if p.
|
| 802 |
-
|
|
|
|
|
|
|
|
|
|
| 803 |
else:
|
| 804 |
-
hrs =
|
| 805 |
else:
|
| 806 |
-
hrs = 0.0
|
|
|
|
| 807 |
if r["breakfast"]:
|
| 808 |
-
hour_map[(pid_r, eid_r, date_r, "breakfast")] = hrs
|
| 809 |
if r["dinner"]:
|
| 810 |
-
# ダブルは
|
| 811 |
if pat_id == "double":
|
| 812 |
-
hour_map[(pid_r, eid_r, date_r, "dinner")] = 0.0
|
| 813 |
else:
|
| 814 |
-
hour_map[(pid_r, eid_r, date_r, "dinner")] = hrs
|
| 815 |
|
| 816 |
# グローバル賃金設定
|
| 817 |
base_wage = int(settings.get("base_hourly_wage", "0") or 0)
|
|
@@ -832,20 +856,19 @@ def get_multi_period_stats(period_ids: list[int]) -> dict:
|
|
| 832 |
key = (pid, eid, a["date"], slot)
|
| 833 |
|
| 834 |
if key in hour_map:
|
| 835 |
-
hrs = hour_map[key]
|
| 836 |
else:
|
| 837 |
-
hrs =
|
| 838 |
|
| 839 |
# 社員は時給計算対象外(コストは 0 のまま)
|
| 840 |
if eid not in pt_ids:
|
| 841 |
cost = 0.0
|
| 842 |
else:
|
| 843 |
-
raise_amt
|
| 844 |
-
|
| 845 |
-
|
| 846 |
-
|
| 847 |
-
|
| 848 |
-
cost = hrs * hourly
|
| 849 |
|
| 850 |
if eid not in result:
|
| 851 |
result[eid] = {"shifts": 0, "hours": 0.0, "cost": 0.0, "by_period": {}}
|
|
|
|
| 778 |
|
| 779 |
settings = {r["key"]: r["value"] for r in setting_rows}
|
| 780 |
|
| 781 |
+
EARLY_START = 5.5 # 5:30
|
| 782 |
+
EARLY_END = 9.0 # 9:00
|
| 783 |
+
|
| 784 |
+
def _early_overlap(start_h: float, end_h: float) -> float:
|
| 785 |
+
"""5:30〜9:00 と重複する時間数を返す"""
|
| 786 |
+
return max(0.0, min(end_h, EARLY_END) - max(start_h, EARLY_START))
|
| 787 |
+
|
| 788 |
+
def _parse_hm(t: str) -> float:
|
| 789 |
+
h, m = map(int, t.split(":"))
|
| 790 |
+
return h + m / 60.0
|
| 791 |
+
|
| 792 |
+
def _ft_times(slot: str, pos: str) -> tuple[float, float]:
|
| 793 |
s = settings.get(f"ft_{pos}_{slot}_start", "06:00" if slot == "breakfast" else "17:00")
|
| 794 |
e = settings.get(f"ft_{pos}_{slot}_end", "11:00" if slot == "breakfast" else "22:00")
|
| 795 |
+
return _parse_hm(s), _parse_hm(e)
|
|
|
|
|
|
|
| 796 |
|
| 797 |
+
def _ft_hours_early(slot: str, pos: str) -> tuple[float, float]:
|
| 798 |
+
sh, eh = _ft_times(slot, pos)
|
| 799 |
+
return max(0.0, eh - sh), _early_overlap(sh, eh)
|
| 800 |
+
|
| 801 |
+
# (period_id, emp_id, date, slot) → (総時間, 早朝重複時間)
|
| 802 |
+
hour_map: dict[tuple, tuple[float, float]] = {}
|
| 803 |
for r in req_rows:
|
| 804 |
+
pid_r = r["period_id"]
|
| 805 |
+
eid_r = r["employee_id"]
|
| 806 |
date_r = r["date"]
|
| 807 |
pat_id = r["pattern_id"]
|
| 808 |
+
|
| 809 |
if pat_id == "custom" and r["custom_start"] and r["custom_end"]:
|
| 810 |
+
sh = _parse_hm(r["custom_start"])
|
| 811 |
+
eh = _parse_hm(r["custom_end"])
|
| 812 |
+
hrs = max(0.0, eh - sh)
|
| 813 |
+
early = _early_overlap(sh, eh)
|
| 814 |
+
elif pat_id == "double":
|
| 815 |
+
# ダブル: 朝食部(6:00-11:00) + ディナー部(17:00-23:00) = 11h
|
| 816 |
+
# 早朝重複は朝食部の 6:00-11:00 と 5:30-9:00 の重複
|
| 817 |
+
hrs = 11.0
|
| 818 |
+
early = _early_overlap(6.0, 11.0)
|
| 819 |
elif pat_id and pat_id in PATTERN_MAP:
|
| 820 |
p = PATTERN_MAP[pat_id]
|
| 821 |
+
if p.start and p.end:
|
| 822 |
+
sh = _parse_hm(p.start)
|
| 823 |
+
eh = _parse_hm(p.end)
|
| 824 |
+
hrs = max(0.0, eh - sh)
|
| 825 |
+
early = _early_overlap(sh, eh)
|
| 826 |
else:
|
| 827 |
+
hrs, early = 0.0, 0.0
|
| 828 |
else:
|
| 829 |
+
hrs, early = 0.0, 0.0
|
| 830 |
+
|
| 831 |
if r["breakfast"]:
|
| 832 |
+
hour_map[(pid_r, eid_r, date_r, "breakfast")] = (hrs, early)
|
| 833 |
if r["dinner"]:
|
| 834 |
+
# ダブルはディナー側を 0 にして重複計上を避ける
|
| 835 |
if pat_id == "double":
|
| 836 |
+
hour_map[(pid_r, eid_r, date_r, "dinner")] = (0.0, 0.0)
|
| 837 |
else:
|
| 838 |
+
hour_map[(pid_r, eid_r, date_r, "dinner")] = (hrs, early)
|
| 839 |
|
| 840 |
# グローバル賃金設定
|
| 841 |
base_wage = int(settings.get("base_hourly_wage", "0") or 0)
|
|
|
|
| 856 |
key = (pid, eid, a["date"], slot)
|
| 857 |
|
| 858 |
if key in hour_map:
|
| 859 |
+
hrs, early_hrs = hour_map[key]
|
| 860 |
else:
|
| 861 |
+
hrs, early_hrs = _ft_hours_early(slot, pos)
|
| 862 |
|
| 863 |
# 社員は時給計算対象外(コストは 0 のまま)
|
| 864 |
if eid not in pt_ids:
|
| 865 |
cost = 0.0
|
| 866 |
else:
|
| 867 |
+
raise_amt = wage_map.get(eid, 0)
|
| 868 |
+
base_rate = base_wage + raise_amt
|
| 869 |
+
normal_hrs = hrs - early_hrs
|
| 870 |
+
# 早朝時間帯(5:30〜9:00)のみ早朝手当を加算
|
| 871 |
+
cost = early_hrs * (base_rate + early_allow) + normal_hrs * base_rate
|
|
|
|
| 872 |
|
| 873 |
if eid not in result:
|
| 874 |
result[eid] = {"shifts": 0, "hours": 0.0, "cost": 0.0, "by_period": {}}
|