feat: add quick-create functionality for client categories in the schedule form

This commit is contained in:
I-Fun
2026-04-04 22:40:20 +07:00
parent 15c8d3ae7c
commit 79f2f22e5d
8 changed files with 320 additions and 131 deletions

View File

@@ -88,21 +88,17 @@ class BrandContractController extends Controller
{
$categoryId = $request->integer('category_id');
$clientId = $request->integer('client_id');
$dateStr = $request->input('date');
if (! $categoryId) {
if (! $categoryId || empty($dateStr)) {
return response()->json(null);
}
// Collect the category and its parent chain (so blocking a parent also blocks children)
$category = ClientCategory::find($categoryId);
$checkIds = [$categoryId];
if ($category?->parent_id) {
$checkIds[] = $category->parent_id;
}
$date = $dateStr ? \Carbon\Carbon::parse($dateStr) : today();
$contract = BrandContract::with(['client', 'category'])
->active()
->whereIn('category_id', $checkIds)
->active($date)
->where('category_id', $categoryId)
->first();
if (! $contract) {