feat: 前端分離+功能api化

1. 新增資產管理CRUD、googleOAuth登入
2. 更改原記帳controller
This commit is contained in:
2026-06-25 14:19:07 +08:00
parent 7bb931c97b
commit 85972f950c
70 changed files with 4754 additions and 1520 deletions

54
app/Models/Account.php Normal file
View File

@@ -0,0 +1,54 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Account extends Model
{
protected $fillable = [
'user_id',
'name',
'type',
'currency',
'balance',
'note',
'billing_day',
'payment_day',
];
public function user()
{
return $this->belongsTo(User::class);
}
public function holdings()
{
return $this->hasMany(InvestmentHolding::class);
}
public function expenses()
{
return $this->hasMany(Expense::class);
}
public function unpaidAmount()
{
$billingDay = $this->billing_day ?? 1;
$now = now();
// 如果今天還沒到結帳日,帳單週期是上個月結帳日到這個月結帳日
if ($now->day < $billingDay) {
$start = $now->copy()->subMonth()->setDay($billingDay);
$end = $now->copy()->setDay($billingDay)->subDay();
} else {
$start = $now->copy()->setDay($billingDay);
$end = $now->copy()->addMonth()->setDay($billingDay)->subDay();
}
return $this->expenses()
->whereBetween('date', [$start->toDateString(), $end->toDateString()])
->sum('amount');
}
}