|
|
|
@ -108,7 +108,7 @@ const StockPage: React.FC = () => { |
|
|
|
|
newStock.stuffId = null; |
|
|
|
|
} |
|
|
|
|
if (isNaN(newStock.amount)) return; |
|
|
|
|
if (isNaN(newStock.price)) return; |
|
|
|
|
if (newStock.price === null || isNaN(newStock.price)) return; |
|
|
|
|
|
|
|
|
|
if (newStock.buyAmount !== null && isNaN(newStock.buyAmount)) { |
|
|
|
|
newStock.buyAmount = null; |
|
|
|
@ -118,6 +118,7 @@ const StockPage: React.FC = () => { |
|
|
|
|
console.log(newStock) |
|
|
|
|
|
|
|
|
|
// 購入日と消費・賞味期限の整合性チェック
|
|
|
|
|
if (newStock.expDate !== null) { |
|
|
|
|
const buy = new Date(newStock.buyDate); |
|
|
|
|
const exp = new Date(newStock.expDate); |
|
|
|
|
// 時間をリセットして純粋な“日付のみ”のタイムスタンプを取得
|
|
|
|
@ -136,6 +137,7 @@ const StockPage: React.FC = () => { |
|
|
|
|
showErrorMessage('購入日は消費・賞味期限より前の日付を設定してください.'); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const today = new Date().toISOString().substring(0, 10); |
|
|
|
|
|
|
|
|
@ -232,6 +234,7 @@ const StockPage: React.FC = () => { |
|
|
|
|
if (!editStock) return; |
|
|
|
|
|
|
|
|
|
const { stockId, amount, buyAmount, price, shop, buyDate, expDate, lastUpdate } = editStock; |
|
|
|
|
if (expDate !== null) { |
|
|
|
|
// 購入日が消費・賞味期限より未来の場合はエラー表示
|
|
|
|
|
const buy = new Date(buyDate); |
|
|
|
|
const exp = new Date(expDate); |
|
|
|
@ -250,6 +253,7 @@ const StockPage: React.FC = () => { |
|
|
|
|
showErrorMessage('購入日は消費・賞味期限より前の日付を設定してください.'); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
// Number型に変換した変数を用意
|
|
|
|
@ -368,6 +372,9 @@ const StockPage: React.FC = () => { |
|
|
|
|
</TableHead> |
|
|
|
|
<TableBody> |
|
|
|
|
{filteredStocks.map(stock => { |
|
|
|
|
let daysLeft = null; |
|
|
|
|
|
|
|
|
|
if (stock.expDate !== null) { |
|
|
|
|
const today = new Date(); |
|
|
|
|
const expDate = new Date(stock.expDate); |
|
|
|
|
// 時間をリセットして純粋な“日付のみ”のタイムスタンプを取得
|
|
|
|
@ -376,13 +383,14 @@ const StockPage: React.FC = () => { |
|
|
|
|
const expDateOnly = new Date(expDate); |
|
|
|
|
expDateOnly.setHours(0, 0, 0, 0); |
|
|
|
|
const timeDiff = expDateOnly.getTime() - todayDateOnly.getTime(); |
|
|
|
|
const daysLeft = Math.ceil(timeDiff / (1000 * 60 * 60 * 24)); |
|
|
|
|
daysLeft = Math.ceil(timeDiff / (1000 * 60 * 60 * 24)); |
|
|
|
|
|
|
|
|
|
// console.log("テーブルtoday:", today);
|
|
|
|
|
// console.log("テーブルexp:", expDate);
|
|
|
|
|
// console.log("テーブルtodayDateOnly:", todayDateOnly);
|
|
|
|
|
// console.log("テーブルexpDateOnly:", expDateOnly);
|
|
|
|
|
// console.log("日数差:", daysLeft);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<TableRow |
|
|
|
@ -393,9 +401,9 @@ const StockPage: React.FC = () => { |
|
|
|
|
<TableCell align="center" sx={{ width: '40%', fontSize: '16px' }}>{stock.stuffName}</TableCell> |
|
|
|
|
<TableCell align="center" sx={{ width: '20%', fontSize: '16px' }}>{stock.amount}</TableCell> |
|
|
|
|
<TableCell align="center" sx={{ width: '40%', fontSize: '16px' }} |
|
|
|
|
style={daysLeft <= 3 ? { color: "red", fontWeight: "bold" } : {}} |
|
|
|
|
style={daysLeft !== null && daysLeft <= 3 ? { color: "red", fontWeight: "bold" } : {}} |
|
|
|
|
> |
|
|
|
|
{formatDate(stock.expDate)} |
|
|
|
|
{stock.expDate && formatDate(stock.expDate)} |
|
|
|
|
</TableCell> |
|
|
|
|
</TableRow> |
|
|
|
|
); |
|
|
|
|