renew and other crud functionality
This commit is contained in:
@@ -9,8 +9,11 @@ class BuildingController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$buildings = Building::with('owner')->latest()->paginate(15);
|
||||
return Inertia::render('Buildings/Index', ['buildings' => $buildings]);
|
||||
$buildings = Building::with('owner')
|
||||
->when($request->search, fn($q) => $q->where('building_name', 'like', "%{$request->search}%"))
|
||||
->latest()
|
||||
->paginate(15);
|
||||
return Inertia::render('Buildings/Index', ['buildings' => $buildings]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Contract;
|
||||
use App\Models\Unit;
|
||||
use App\Models\Owner;
|
||||
use App\Models\Subunit;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
@@ -31,4 +34,75 @@ class OwnerContractController extends Controller
|
||||
$ownerContract->delete();
|
||||
return redirect()->route('owner-contracts.index');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// app/Http/Controllers/OwnerContractController.php - add these methods
|
||||
public function create()
|
||||
{
|
||||
$units = Unit::with('building')->get();
|
||||
$owners = Owner::all();
|
||||
$subunits = Subunit::all();
|
||||
|
||||
return Inertia::render('OwnerContracts/Create', [
|
||||
'units' => $units,
|
||||
'owners' => $owners,
|
||||
'subunits' => $subunits
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'unit_id' => 'required|exists:units,id',
|
||||
'person_id' => 'required|exists:owners,id',
|
||||
'contract_type' => 'required',
|
||||
'contract_number' => 'required|unique:contracts',
|
||||
'ejari_no' => 'required',
|
||||
'start_date' => 'required|date',
|
||||
'end_date' => 'required|date',
|
||||
'duration_months' => 'required|integer',
|
||||
'total_amount' => 'required|numeric',
|
||||
'status' => 'required',
|
||||
'notes' => 'nullable',
|
||||
'subunit_ids' => 'nullable|array',
|
||||
'payments' => 'required|array'
|
||||
]);
|
||||
|
||||
$contract = Contract::create($validated);
|
||||
|
||||
if ($request->subunit_ids) {
|
||||
$contract->subunits()->attach($request->subunit_ids);
|
||||
}
|
||||
|
||||
foreach ($request->payments as $payment) {
|
||||
$contract->payments()->create($payment);
|
||||
}
|
||||
|
||||
return redirect()->route('owner-contracts.index');
|
||||
}
|
||||
|
||||
public function renew(Contract $ownerContract)
|
||||
{
|
||||
$units = Unit::with('building')->get();
|
||||
$owners = Owner::all();
|
||||
$subunits = Subunit::all();
|
||||
|
||||
$renewData = [
|
||||
'unit_id' => $ownerContract->unit_id,
|
||||
'person_id' => $ownerContract->person_id,
|
||||
'ejari_no' => $ownerContract->ejari_no,
|
||||
'duration_months' => $ownerContract->duration_months,
|
||||
'total_amount' => $ownerContract->total_amount,
|
||||
'start_date' => $ownerContract->end_date->addDay()->format('Y-m-d'),
|
||||
'subunit_ids' => $ownerContract->subunits->pluck('id')->toArray()
|
||||
];
|
||||
|
||||
return Inertia::render('OwnerContracts/Create', [
|
||||
'units' => $units,
|
||||
'owners' => $owners,
|
||||
'subunits' => $subunits,
|
||||
'renewData' => $renewData
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,16 @@ use Inertia\Inertia;
|
||||
|
||||
class OwnerController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$owners = Owner::latest()->paginate(15);
|
||||
return Inertia::render('Owners/Index', ['owners' => $owners]);
|
||||
}
|
||||
public function index(Request $request)
|
||||
{
|
||||
$owners = Owner::when($request->search, fn($q) =>
|
||||
$q->where('name', 'like', "%{$request->search}%")
|
||||
->orWhere('phone', 'like', "%{$request->search}%")
|
||||
)
|
||||
->latest()
|
||||
->paginate(15);
|
||||
return Inertia::render('Owners/Index', ['owners' => $owners]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
|
||||
@@ -6,14 +6,19 @@ use Inertia\Inertia;
|
||||
|
||||
class PaymentController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$payments = Payment::with('contract.unit.building', 'contract.person')
|
||||
->when($request->status, fn($q) => $q->where('status', $request->status))
|
||||
->when($request->type, fn($q) => $q->where('payment_type', $request->type))
|
||||
->latest()
|
||||
->paginate(20);
|
||||
public function index(Request $request)
|
||||
{
|
||||
$payments = Payment::with('contract.unit.building', 'contract.person')
|
||||
->when($request->search, fn($q) =>
|
||||
$q->whereHas('contract', fn($q2) =>
|
||||
$q2->where('contract_number', 'like', "%{$request->search}%")
|
||||
)
|
||||
)
|
||||
->when($request->status, fn($q) => $q->where('status', $request->status))
|
||||
->when($request->type, fn($q) => $q->where('payment_type', $request->type))
|
||||
->latest()
|
||||
->paginate(20);
|
||||
|
||||
return Inertia::render('Payments/Index', ['payments' => $payments]);
|
||||
}
|
||||
return Inertia::render('Payments/Index', ['payments' => $payments]);
|
||||
}
|
||||
}
|
||||
@@ -7,12 +7,18 @@ use Inertia\Inertia;
|
||||
|
||||
class SubunitController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$subunits = Subunit::with('unit.building')->latest()->paginate(15);
|
||||
return Inertia::render('Subunits/Index', ['subunits' => $subunits]);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$subunits = Subunit::with('unit.building')
|
||||
->when($request->search, fn($q) =>
|
||||
$q->whereHas('unit.building', fn($q2) =>
|
||||
$q2->where('building_name', 'like', "%{$request->search}%")
|
||||
)
|
||||
)
|
||||
->latest()
|
||||
->paginate(15);
|
||||
return Inertia::render('Subunits/Index', ['subunits' => $subunits]);
|
||||
}
|
||||
public function create()
|
||||
{
|
||||
$units = Unit::with('building')->get();
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Contract;
|
||||
use App\Models\Unit;
|
||||
use App\Models\Tenant;
|
||||
use App\Models\Subunit;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
@@ -22,7 +25,7 @@ class TenantContractController extends Controller
|
||||
|
||||
public function show(Contract $tenantContract)
|
||||
{
|
||||
$tenantContract->load(['unit.building.owner', 'person', 'payments', 'subunits']);
|
||||
$tenantContract->load(['unit.building.tenant', 'person', 'payments', 'subunits']);
|
||||
return Inertia::render('TenantContracts/Show', ['contract' => $tenantContract]);
|
||||
}
|
||||
|
||||
@@ -31,4 +34,73 @@ class TenantContractController extends Controller
|
||||
$tenantContract->delete();
|
||||
return redirect()->route('tenant-contracts.index');
|
||||
}
|
||||
|
||||
// app/Http/Controllers/tenantContractController.php - add these methods
|
||||
public function create()
|
||||
{
|
||||
$units = Unit::with('building')->get();
|
||||
$tenants = Tenant::all();
|
||||
$subunits = Subunit::all();
|
||||
|
||||
return Inertia::render('TenantContracts/Create', [
|
||||
'units' => $units,
|
||||
'tenants' => $tenants,
|
||||
'subunits' => $subunits
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'unit_id' => 'required|exists:units,id',
|
||||
'person_id' => 'required|exists:tenants,id',
|
||||
'contract_type' => 'required',
|
||||
'contract_number' => 'required|unique:contracts',
|
||||
'ejari_no' => 'required',
|
||||
'start_date' => 'required|date',
|
||||
'end_date' => 'required|date',
|
||||
'duration_months' => 'required|integer',
|
||||
'total_amount' => 'required|numeric',
|
||||
'status' => 'required',
|
||||
'notes' => 'nullable',
|
||||
'subunit_ids' => 'nullable|array',
|
||||
'payments' => 'required|array'
|
||||
]);
|
||||
|
||||
$contract = Contract::create($validated);
|
||||
|
||||
if ($request->subunit_ids) {
|
||||
$contract->subunits()->attach($request->subunit_ids);
|
||||
}
|
||||
|
||||
foreach ($request->payments as $payment) {
|
||||
$contract->payments()->create($payment);
|
||||
}
|
||||
|
||||
return redirect()->route('tenant-contracts.index');
|
||||
}
|
||||
|
||||
public function renew(Contract $tenantContract)
|
||||
{
|
||||
$units = Unit::with('building')->get();
|
||||
$tenants = Tenant::all();
|
||||
$subunits = Subunit::all();
|
||||
|
||||
$renewData = [
|
||||
'unit_id' => $tenantContract->unit_id,
|
||||
'person_id' => $tenantContract->person_id,
|
||||
'ejari_no' => $tenantContract->ejari_no,
|
||||
'duration_months' => $tenantContract->duration_months,
|
||||
'total_amount' => $tenantContract->total_amount,
|
||||
'start_date' => $tenantContract->end_date->addDay()->format('Y-m-d'),
|
||||
'subunit_ids' => $tenantContract->subunits->pluck('id')->toArray()
|
||||
];
|
||||
|
||||
return Inertia::render('TenantContracts/Create', [
|
||||
'units' => $units,
|
||||
'tenants' => $tenants,
|
||||
'subunits' => $subunits,
|
||||
'renewData' => $renewData
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -6,12 +6,16 @@ use Inertia\Inertia;
|
||||
|
||||
class TenantController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$tenants = Tenant::latest()->paginate(15);
|
||||
return Inertia::render('Tenants/Index', ['tenants' => $tenants]);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$tenants = Tenant::when($request->search, fn($q) =>
|
||||
$q->where('name', 'like', "%{$request->search}%")
|
||||
->orWhere('phone', 'like', "%{$request->search}%")
|
||||
)
|
||||
->latest()
|
||||
->paginate(15);
|
||||
return Inertia::render('Tenants/Index', ['tenants' => $tenants]);
|
||||
}
|
||||
public function create()
|
||||
{
|
||||
return Inertia::render('Tenants/Create');
|
||||
|
||||
@@ -7,11 +7,18 @@ use Inertia\Inertia;
|
||||
|
||||
class UnitController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$units = Unit::with('building')->latest()->paginate(15);
|
||||
return Inertia::render('Units/Index', ['units' => $units]);
|
||||
}
|
||||
public function index(Request $request)
|
||||
{
|
||||
$units = Unit::with('building')
|
||||
->when($request->search, fn($q) =>
|
||||
$q->whereHas('building', fn($q2) =>
|
||||
$q2->where('building_name', 'like', "%{$request->search}%")
|
||||
)
|
||||
)
|
||||
->latest()
|
||||
->paginate(15);
|
||||
return Inertia::render('Units/Index', ['units' => $units]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user