-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 仕切書と定期請求スケジュール(Phase A〜C) (#54) #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
4da96f1
feat: 仕切書・定期請求スケジュールのコア実装 (Phase A) (#54)
strnh 29b855f
feat: 仕切書 API と請求予定データ取得 API を追加 (Phase B) (#54)
strnh 3e52ffb
feat: 仕切書の TypeScript 型・adapters・バックアップ対象拡張 (Phase C) (#54)
strnh 2d63620
Merge remote-tracking branch 'origin/main' into feature/54-settlements
strnh 5ededc9
fix: PR #56 の Copilot review 指摘に対応
strnh e685d93
fix: PR #56 の追加レビュー指摘に対応
strnh 41a5a6a
fix: settlement scheduleのIDフィルタを厳密化
strnh ed272df
fix: PR #56 の未解決レビューに対応
strnh ba6db01
fix: localの仕切書金額計算を整数化
strnh 644d54d
fix: backup復元時の終了条件を検証
strnh a0eddc8
fix: 仕切書の部分更新で既存金額を維持
strnh f1f4503
fix: backup復元時の仕切書条件を検証
strnh 964fa9f
Potential fix for pull request finding
strnh 4b20785
fix: 仕切書の関連ID検証を厳密化
strnh 1d5add9
fix: 仕切書予定同期の再生成境界を修正
strnh af3bab9
feat: 仕切書の入力UI(一覧・作成/編集・詳細)を追加 (#58)
strnh 60d357f
test: 仕切書予定バックアップ復元の値域検証に回帰テストを追加
strnh 9228f0d
fix: local仕切書の終了条件判定で空文字end_dateを未設定扱いに統一
strnh f5564f9
fix: 仕切書フォームの未選択時payload正規化とスナップショットクリア
strnh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| <?php | ||
|
|
||
| namespace App\Http\Controllers; | ||
|
|
||
| use App\Models\Settlement; | ||
| use App\Support\SettlementPricing; | ||
| use App\Support\SettlementScheduleGenerator; | ||
| use Illuminate\Http\Request; | ||
| use Illuminate\Support\Facades\DB; | ||
| use Illuminate\Validation\Rule; | ||
|
|
||
| class SettlementController extends Controller | ||
| { | ||
| public function index() | ||
| { | ||
| return Settlement::with('settlementSchedules') | ||
| ->orderByDesc('start_date') | ||
| ->orderByDesc('id') | ||
| ->get(); | ||
| } | ||
|
|
||
| public function store(Request $request) | ||
| { | ||
| $data = SettlementPricing::apply($this->validated($request)); | ||
|
|
||
| $settlement = DB::transaction(function () use ($data) { | ||
| $settlement = Settlement::create($data); | ||
| // interval_count 等の DB default を attributes に反映してから各回を生成する。 | ||
| $settlement->refresh(); | ||
| // 新規作成時は過去/未来の区別なく全回を予定データとして持つ。 | ||
| $settlement->settlementSchedules()->createMany( | ||
| SettlementScheduleGenerator::generate($settlement), | ||
| ); | ||
|
|
||
| return $settlement; | ||
| }); | ||
|
|
||
| return response()->json($settlement->load('settlementSchedules'), 201); | ||
| } | ||
|
|
||
| public function show(Settlement $settlement) | ||
| { | ||
| return $settlement->load('settlementSchedules'); | ||
| } | ||
|
|
||
| public function update(Request $request, Settlement $settlement) | ||
| { | ||
| $data = SettlementPricing::apply(array_merge( | ||
| $settlement->only(['items', 'tax_rate']), | ||
| $this->validated($request), | ||
| )); | ||
|
|
||
| DB::transaction(function () use ($settlement, $data) { | ||
| $settlement->update($data); | ||
| $settlement->refresh(); | ||
| // 過去回のスナップショットは不変。基準日(今日)以降の回だけ現在条件で作り直す。 | ||
| SettlementScheduleGenerator::sync($settlement); | ||
| }); | ||
|
|
||
| return $settlement->fresh()->load('settlementSchedules'); | ||
| } | ||
|
|
||
| public function destroy(Settlement $settlement) | ||
| { | ||
| $settlement->delete(); | ||
|
|
||
| return response()->noContent(); | ||
| } | ||
|
|
||
| private function validated(Request $request): array | ||
| { | ||
| return $request->validate([ | ||
| // settlement_number は quote_number と同じ扱い(nullable + UNIQUE)。 | ||
| // 未設定(null)は対象外=番号なし下書きは複数作成可能。 | ||
| 'settlement_number' => [ | ||
| 'nullable', 'string', 'max:100', | ||
| Rule::unique('settlements', 'settlement_number')->ignore($request->route('settlement')), | ||
| ], | ||
| 'subject' => ['nullable', 'string', 'max:255'], | ||
| // status/interval_count/billing_timing/tax_rate は DB 側が NOT NULL + default。 | ||
| // nullable だと明示的な null が DB エラー(500)になるため、未指定は default に | ||
| // 任せつつ null は 422 で弾くために sometimes を使う(値が来た時だけ検証する)。 | ||
| 'status' => ['sometimes', 'in:draft,active,ended'], | ||
|
|
||
| // 終了条件は必須: end_date か occurrences_count のいずれか(無期限は不可)。 | ||
| 'start_date' => ['required', 'date'], | ||
| 'end_date' => ['nullable', 'required_without:occurrences_count', 'date', 'after_or_equal:start_date'], | ||
| 'occurrences_count' => ['nullable', 'required_without:end_date', 'integer', 'min:1'], | ||
| 'interval_unit' => ['required', 'in:month,year'], | ||
| 'interval_count' => ['sometimes', 'integer', 'min:1'], | ||
| 'billing_day' => ['nullable', 'integer', 'between:1,31'], | ||
| 'billing_timing' => ['sometimes', 'in:advance,arrears'], | ||
|
|
||
| 'payment_terms' => ['nullable', 'string', 'max:255'], | ||
| 'tax_rate' => ['sometimes', 'integer', 'min:0', 'max:100'], | ||
| 'notes' => ['nullable', 'string'], | ||
|
|
||
| 'sender_profile_id' => ['nullable', 'integer'], | ||
| 'sender_company' => ['nullable', 'string', 'max:255'], | ||
| 'sender_zip' => ['nullable', 'string', 'max:20'], | ||
| 'sender_pref' => ['nullable', 'string', 'max:50'], | ||
| 'sender_city' => ['nullable', 'string', 'max:255'], | ||
| 'sender_address1' => ['nullable', 'string', 'max:255'], | ||
| 'sender_address2' => ['nullable', 'string', 'max:255'], | ||
| 'sender_person' => ['nullable', 'string', 'max:255'], | ||
| 'sender_tel' => ['nullable', 'string', 'max:50'], | ||
| 'sender_fax' => ['nullable', 'string', 'max:50'], | ||
| 'sender_logo_url' => ['nullable', 'string'], | ||
|
|
||
| 'customer_id' => ['nullable', 'integer'], | ||
| 'customer_name' => ['nullable', 'string', 'max:255'], | ||
| 'customer_department' => ['nullable', 'string', 'max:255'], | ||
| 'customer_person' => ['nullable', 'string', 'max:255'], | ||
| 'customer_zip' => ['nullable', 'string', 'max:20'], | ||
| 'customer_pref' => ['nullable', 'string', 'max:50'], | ||
| 'customer_city' => ['nullable', 'string', 'max:255'], | ||
| 'customer_address1' => ['nullable', 'string', 'max:255'], | ||
| 'customer_address2' => ['nullable', 'string', 'max:255'], | ||
| 'customer_tel' => ['nullable', 'string', 'max:50'], | ||
|
|
||
| 'items' => ['nullable', 'array'], | ||
| 'items.*.name' => ['nullable', 'string', 'max:255'], | ||
| 'items.*.spec' => ['nullable', 'string', 'max:255'], | ||
| 'items.*.quantity' => ['nullable', 'numeric'], | ||
| 'items.*.unit' => ['nullable', 'string', 'max:50'], | ||
| 'items.*.standard_price' => ['nullable', 'numeric'], | ||
| 'items.*.unit_price' => ['nullable', 'numeric'], | ||
| 'items.*.total' => ['nullable', 'numeric'], | ||
| ]); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <?php | ||
|
|
||
| namespace App\Http\Controllers; | ||
|
|
||
| use App\Models\SettlementSchedule; | ||
| use Illuminate\Http\Request; | ||
|
|
||
| class SettlementScheduleController extends Controller | ||
| { | ||
| /** | ||
| * 各回の請求予定データを取り出す(帳票化はしない。外部が JSON で取得する口)。 | ||
| * フィルタ: ?settlement_id= / ?from= / ?to=(from/to は billing_date に対する範囲)。 | ||
| */ | ||
| public function index(Request $request) | ||
| { | ||
| $filters = $request->validate([ | ||
| 'settlement_id' => ['nullable', 'integer'], | ||
| 'from' => ['nullable', 'date'], | ||
| 'to' => ['nullable', 'date', 'after_or_equal:from'], | ||
| ]); | ||
|
|
||
| return SettlementSchedule::query() | ||
| ->when(isset($filters['settlement_id']), fn ($query) => $query->where('settlement_id', $filters['settlement_id'])) | ||
| ->when($filters['from'] ?? null, fn ($query, $from) => $query->whereDate('billing_date', '>=', $from)) | ||
| ->when($filters['to'] ?? null, fn ($query, $to) => $query->whereDate('billing_date', '<=', $to)) | ||
| ->orderBy('billing_date') | ||
| ->orderBy('settlement_id') | ||
| ->orderBy('sequence_no') | ||
| ->get(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <?php | ||
|
|
||
| namespace App\Models; | ||
|
|
||
| use Illuminate\Database\Eloquent\Model; | ||
| use Illuminate\Database\Eloquent\Relations\HasMany; | ||
|
|
||
| class Settlement extends Model | ||
| { | ||
| protected $guarded = ['id']; | ||
|
|
||
| protected $casts = [ | ||
| 'items' => 'array', | ||
| 'start_date' => 'date:Y-m-d', | ||
| 'end_date' => 'date:Y-m-d', | ||
| 'occurrences_count' => 'integer', | ||
| 'interval_count' => 'integer', | ||
| 'billing_day' => 'integer', | ||
| 'tax_rate' => 'integer', | ||
| 'unit_subtotal' => 'integer', | ||
| 'unit_tax_amount' => 'integer', | ||
| 'unit_total_amount' => 'integer', | ||
| ]; | ||
|
|
||
| public function settlementSchedules(): HasMany | ||
| { | ||
| return $this->hasMany(SettlementSchedule::class)->orderBy('sequence_no'); | ||
| } | ||
|
Copilot marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?php | ||
|
|
||
| namespace App\Models; | ||
|
|
||
| use Illuminate\Database\Eloquent\Model; | ||
| use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
|
|
||
| class SettlementSchedule extends Model | ||
| { | ||
| protected $guarded = ['id']; | ||
|
|
||
| protected $casts = [ | ||
| 'items' => 'array', | ||
| 'sequence_no' => 'integer', | ||
| 'period_start' => 'date:Y-m-d', | ||
| 'period_end' => 'date:Y-m-d', | ||
| 'billing_date' => 'date:Y-m-d', | ||
| 'due_date' => 'date:Y-m-d', | ||
| 'subtotal' => 'integer', | ||
| 'tax_amount' => 'integer', | ||
| 'total_amount' => 'integer', | ||
| ]; | ||
|
|
||
| public function settlement(): BelongsTo | ||
| { | ||
| return $this->belongsTo(Settlement::class); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.