Changes
This commit is contained in:
@@ -98,13 +98,24 @@ public function storeContract(ClientCase $clientCase, Request $request)
|
||||
|
||||
\DB::transaction(function() use ($request, $clientCase){
|
||||
|
||||
//Create contract
|
||||
$clientCase->contracts()->create([
|
||||
// Create contract
|
||||
$contract = $clientCase->contracts()->create([
|
||||
'reference' => $request->input('reference'),
|
||||
'start_date' => date('Y-m-d', strtotime($request->input('start_date'))),
|
||||
'type_id' => $request->input('type_id')
|
||||
'type_id' => $request->input('type_id'),
|
||||
'description' => $request->input('description'),
|
||||
]);
|
||||
|
||||
// Optionally create/update related account amounts
|
||||
$initial = $request->input('initial_amount');
|
||||
$balance = $request->input('balance_amount');
|
||||
if (!is_null($initial) || !is_null($balance)) {
|
||||
$contract->account()->create([
|
||||
'initial_amount' => $initial ?? 0,
|
||||
'balance_amount' => $balance ?? 0,
|
||||
]);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return to_route('clientCase.show', $clientCase);
|
||||
@@ -117,9 +128,25 @@ public function updateContract(ClientCase $clientCase, String $uuid, Request $re
|
||||
\DB::transaction(function() use ($request, $contract){
|
||||
$contract->update([
|
||||
'reference' => $request->input('reference'),
|
||||
'type_id' => $request->input('type_id')
|
||||
'type_id' => $request->input('type_id'),
|
||||
'description' => $request->input('description'),
|
||||
'start_date' => $request->filled('start_date') ? date('Y-m-d', strtotime($request->input('start_date'))) : $contract->start_date,
|
||||
]);
|
||||
|
||||
$initial = $request->input('initial_amount');
|
||||
$balance = $request->input('balance_amount');
|
||||
if (!is_null($initial) || !is_null($balance)) {
|
||||
$accountData = [
|
||||
'initial_amount' => $initial ?? 0,
|
||||
'balance_amount' => $balance ?? 0,
|
||||
];
|
||||
if ($contract->account) {
|
||||
$contract->account->update($accountData);
|
||||
} else {
|
||||
$contract->account()->create($accountData);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return to_route('clientCase.show', $clientCase);
|
||||
@@ -132,11 +159,28 @@ public function storeActivity(ClientCase $clientCase, Request $request) {
|
||||
'amount' => 'nullable|decimal:0,4',
|
||||
'note' => 'nullable|string',
|
||||
'action_id' => 'exists:\App\Models\Action,id',
|
||||
'decision_id' => 'exists:\App\Models\Decision,id'
|
||||
'decision_id' => 'exists:\App\Models\Decision,id',
|
||||
'contract_uuid' => 'nullable|uuid',
|
||||
]);
|
||||
|
||||
//Create activity
|
||||
$row = $clientCase->activities()->create($attributes);
|
||||
// Map contract_uuid to contract_id within the same client case, if provided
|
||||
$contractId = null;
|
||||
if (!empty($attributes['contract_uuid'])) {
|
||||
$contract = $clientCase->contracts()->where('uuid', $attributes['contract_uuid'])->firstOrFail('id');
|
||||
if ($contract) {
|
||||
$contractId = $contract->id;
|
||||
}
|
||||
}
|
||||
|
||||
// Create activity
|
||||
$row = $clientCase->activities()->create([
|
||||
'due_date' => $attributes['due_date'] ?? null,
|
||||
'amount' => $attributes['amount'] ?? null,
|
||||
'note' => $attributes['note'] ?? null,
|
||||
'action_id' => $attributes['action_id'],
|
||||
'decision_id' => $attributes['decision_id'],
|
||||
'contract_id' => $contractId,
|
||||
]);
|
||||
/*foreach ($activity->decision->events as $e) {
|
||||
$class = '\\App\\Events\\' . $e->name;
|
||||
event(new $class($clientCase));
|
||||
@@ -296,9 +340,9 @@ public function show(ClientCase $clientCase)
|
||||
'client' => $case->client()->with('person', fn($q) => $q->with(['addresses', 'phones']))->firstOrFail(),
|
||||
'client_case' => $case,
|
||||
'contracts' => $case->contracts()
|
||||
->with(['type'])
|
||||
->with(['type', 'account', 'objects'])
|
||||
->orderByDesc('created_at')->get(),
|
||||
'activities' => $case->activities()->with(['action', 'decision'])
|
||||
'activities' => $case->activities()->with(['action', 'decision', 'contract:id,uuid,reference'])
|
||||
->orderByDesc('created_at')
|
||||
->paginate(20, ['*'], 'activities'),
|
||||
'documents' => $case->documents()->orderByDesc('created_at')->get(),
|
||||
|
||||
Reference in New Issue
Block a user