Merge branch 'master' into Development
This commit is contained in:
@@ -2,12 +2,8 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Account;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class AccountController extends Controller
|
||||
{
|
||||
//
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -13,8 +13,10 @@ class ActivityNotificationController extends Controller
|
||||
*/
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'activity_id' => ['required', 'integer', 'exists:activities,id'],
|
||||
$data = $request->validate([
|
||||
'activity_id' => ['sometimes', 'integer', 'exists:activities,id'],
|
||||
'activity_ids' => ['sometimes', 'array', 'min:1'],
|
||||
'activity_ids.*' => ['integer', 'exists:activities,id'],
|
||||
]);
|
||||
|
||||
$userId = optional($request->user())->id;
|
||||
@@ -22,20 +24,30 @@ public function __invoke(Request $request)
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$activity = Activity::query()->select(['id', 'due_date'])->findOrFail($request->integer('activity_id'));
|
||||
$due = optional($activity->due_date) ? date('Y-m-d', strtotime($activity->due_date)) : now()->toDateString();
|
||||
$ids = [];
|
||||
if (!empty($data['activity_id'])) {
|
||||
$ids[] = $data['activity_id'];
|
||||
}
|
||||
if (!empty($data['activity_ids'])) {
|
||||
$ids = array_merge($ids, $data['activity_ids']);
|
||||
}
|
||||
$ids = array_unique($ids);
|
||||
|
||||
ActivityNotificationRead::query()->updateOrCreate(
|
||||
[
|
||||
'user_id' => $userId,
|
||||
'activity_id' => $activity->id,
|
||||
'due_date' => $due,
|
||||
],
|
||||
[
|
||||
'read_at' => now(),
|
||||
]
|
||||
);
|
||||
$activities = Activity::query()->select(['id', 'due_date'])->whereIn('id', $ids)->get();
|
||||
foreach ($activities as $activity) {
|
||||
$due = optional($activity->due_date) ? date('Y-m-d', strtotime($activity->due_date)) : now()->toDateString();
|
||||
ActivityNotificationRead::query()->updateOrCreate(
|
||||
[
|
||||
'user_id' => $userId,
|
||||
'activity_id' => $activity->id,
|
||||
'due_date' => $due,
|
||||
],
|
||||
[
|
||||
'read_at' => now(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
return response()->json(['status' => 'ok']);
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public function index(Request $request): Response
|
||||
->get(['id', 'profile_id', 'sname', 'phone_number']);
|
||||
$templates = \App\Models\SmsTemplate::query()
|
||||
->orderBy('name')
|
||||
->get(['id', 'name']);
|
||||
->get(['id', 'name', 'content']);
|
||||
$segments = \App\Models\Segment::query()
|
||||
->where('active', true)
|
||||
->orderBy('name')
|
||||
@@ -98,6 +98,10 @@ public function show(Package $package, SmsService $sms): Response
|
||||
'start_date' => (string) ($c->start_date ?? ''),
|
||||
'end_date' => (string) ($c->end_date ?? ''),
|
||||
];
|
||||
// Include contract.meta as flattened key-value pairs
|
||||
if (is_array($c->meta) && ! empty($c->meta)) {
|
||||
$vars['contract']['meta'] = $this->flattenMeta($c->meta);
|
||||
}
|
||||
if ($c->account) {
|
||||
$initialRaw = (string) $c->account->initial_amount;
|
||||
$balanceRaw = (string) $c->account->balance_amount;
|
||||
@@ -121,7 +125,7 @@ public function show(Package $package, SmsService $sms): Response
|
||||
if (! $rendered) {
|
||||
$body = isset($payload['body']) ? trim((string) $payload['body']) : '';
|
||||
if ($body !== '') {
|
||||
$rendered = $body;
|
||||
$rendered = $sms->renderContent($body, $vars);
|
||||
} elseif (! empty($payload['template_id'])) {
|
||||
$tpl = \App\Models\SmsTemplate::find((int) $payload['template_id']);
|
||||
if ($tpl) {
|
||||
@@ -157,6 +161,10 @@ public function show(Package $package, SmsService $sms): Response
|
||||
'start_date' => (string) ($c->start_date ?? ''),
|
||||
'end_date' => (string) ($c->end_date ?? ''),
|
||||
];
|
||||
// Include contract.meta as flattened key-value pairs
|
||||
if (is_array($c->meta) && ! empty($c->meta)) {
|
||||
$vars['contract']['meta'] = $this->flattenMeta($c->meta);
|
||||
}
|
||||
if ($c->account) {
|
||||
$initialRaw = (string) $c->account->initial_amount;
|
||||
$balanceRaw = (string) $c->account->balance_amount;
|
||||
@@ -175,7 +183,7 @@ public function show(Package $package, SmsService $sms): Response
|
||||
if ($body !== '') {
|
||||
$preview = [
|
||||
'source' => 'body',
|
||||
'content' => $body,
|
||||
'content' => $sms->renderContent($body, $vars),
|
||||
];
|
||||
} elseif (! empty($payload['template_id'])) {
|
||||
/** @var SmsTemplate|null $tpl */
|
||||
@@ -300,30 +308,39 @@ public function destroy(Package $package): RedirectResponse
|
||||
public function contracts(Request $request, PhoneSelector $selector): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'segment_id' => ['required', 'integer', 'exists:segments,id'],
|
||||
'segment_id' => ['nullable', 'integer', 'exists:segments,id'],
|
||||
'q' => ['nullable', 'string'],
|
||||
'per_page' => ['nullable', 'integer', 'min:1', 'max:100'],
|
||||
'client_id' => ['nullable', 'integer', 'exists:clients,id'],
|
||||
'only_mobile' => ['nullable', 'boolean'],
|
||||
'only_validated' => ['nullable', 'boolean'],
|
||||
'start_date_from' => ['nullable', 'date'],
|
||||
'start_date_to' => ['nullable', 'date'],
|
||||
'promise_date_from' => ['nullable', 'date'],
|
||||
'promise_date_to' => ['nullable', 'date'],
|
||||
]);
|
||||
|
||||
$segmentId = (int) $request->input('segment_id');
|
||||
$segmentId = $request->input('segment_id') ? (int) $request->input('segment_id') : null;
|
||||
$perPage = (int) ($request->input('per_page') ?? 25);
|
||||
|
||||
$query = Contract::query()
|
||||
->join('contract_segment', function ($j) use ($segmentId) {
|
||||
$j->on('contract_segment.contract_id', '=', 'contracts.id')
|
||||
->where('contract_segment.segment_id', '=', $segmentId)
|
||||
->where('contract_segment.active', true);
|
||||
})
|
||||
->with([
|
||||
'clientCase.person.phones',
|
||||
'clientCase.client.person',
|
||||
'account',
|
||||
])
|
||||
->select('contracts.*')
|
||||
->latest('contracts.id');
|
||||
|
||||
// Optional segment filter
|
||||
if ($segmentId) {
|
||||
$query->join('contract_segment', function ($j) use ($segmentId) {
|
||||
$j->on('contract_segment.contract_id', '=', 'contracts.id')
|
||||
->where('contract_segment.segment_id', '=', $segmentId)
|
||||
->where('contract_segment.active', true);
|
||||
});
|
||||
}
|
||||
|
||||
if ($q = trim((string) $request->input('q'))) {
|
||||
$query->where(function ($w) use ($q) {
|
||||
$w->where('contracts.reference', 'ILIKE', "%{$q}%");
|
||||
@@ -335,6 +352,30 @@ public function contracts(Request $request, PhoneSelector $selector): \Illuminat
|
||||
->where('client_cases.client_id', $clientId);
|
||||
}
|
||||
|
||||
// Date range filters for start_date
|
||||
if ($startDateFrom = $request->input('start_date_from')) {
|
||||
$query->where('contracts.start_date', '>=', $startDateFrom);
|
||||
}
|
||||
|
||||
if ($startDateTo = $request->input('start_date_to')) {
|
||||
$query->where('contracts.start_date', '<=', $startDateTo);
|
||||
}
|
||||
|
||||
// Date range filters for account.promise_date
|
||||
$promiseDateFrom = $request->input('promise_date_from');
|
||||
$promiseDateTo = $request->input('promise_date_to');
|
||||
|
||||
if ($promiseDateFrom || $promiseDateTo) {
|
||||
$query->whereHas('account', function ($q) use ($promiseDateFrom, $promiseDateTo) {
|
||||
if ($promiseDateFrom) {
|
||||
$q->where('promise_date', '>=', $promiseDateFrom);
|
||||
}
|
||||
if ($promiseDateTo) {
|
||||
$q->where('promise_date', '<=', $promiseDateTo);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Optional phone filters
|
||||
if ($request->boolean('only_mobile') || $request->boolean('only_validated')) {
|
||||
$query->whereHas('clientCase.person.phones', function ($q) use ($request) {
|
||||
@@ -359,6 +400,8 @@ public function contracts(Request $request, PhoneSelector $selector): \Illuminat
|
||||
'id' => $contract->id,
|
||||
'uuid' => $contract->uuid,
|
||||
'reference' => $contract->reference,
|
||||
'start_date' => $contract->start_date,
|
||||
'promise_date' => $contract->account?->promise_date,
|
||||
'case' => [
|
||||
'id' => $contract->clientCase?->id,
|
||||
'uuid' => $contract->clientCase?->uuid,
|
||||
@@ -481,4 +524,47 @@ public function storeFromContracts(StorePackageFromContractsRequest $request, Ph
|
||||
|
||||
return back()->with('success', 'Package created from contracts');
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten nested meta structure into dot-notation key-value pairs.
|
||||
* Extracts 'value' from objects with {title, value, type} structure.
|
||||
* Also creates direct access aliases for nested fields (skipping numeric keys).
|
||||
*/
|
||||
private function flattenMeta(array $meta, string $prefix = ''): array
|
||||
{
|
||||
$result = [];
|
||||
foreach ($meta as $key => $value) {
|
||||
$newKey = $prefix === '' ? $key : "{$prefix}.{$key}";
|
||||
|
||||
if (is_array($value)) {
|
||||
// Check if it's a structured meta entry with 'value' field
|
||||
if (isset($value['value'])) {
|
||||
$result[$newKey] = $value['value'];
|
||||
// If parent key is numeric, also create direct alias without the number
|
||||
if ($prefix !== '' && is_numeric($key)) {
|
||||
$result[$key] = $value['value'];
|
||||
}
|
||||
} else {
|
||||
// Recursively flatten nested arrays
|
||||
$nested = $this->flattenMeta($value, $newKey);
|
||||
$result = array_merge($result, $nested);
|
||||
|
||||
// If current key is numeric, also flatten without it for easier access
|
||||
if (is_numeric($key)) {
|
||||
$directNested = $this->flattenMeta($value, $prefix);
|
||||
foreach ($directNested as $dk => $dv) {
|
||||
// Only add if not already set (prefer first occurrence)
|
||||
if (! isset($result[$dk])) {
|
||||
$result[$dk] = $dv;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$result[$newKey] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,14 @@
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\StoreUserRequest;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
@@ -18,7 +20,7 @@ public function index(Request $request): Response
|
||||
{
|
||||
Gate::authorize('manage-settings');
|
||||
|
||||
$users = User::with('roles:id,slug,name')->orderBy('name')->get(['id', 'name', 'email']);
|
||||
$users = User::with('roles:id,slug,name')->orderBy('name')->get(['id', 'name', 'email', 'active']);
|
||||
$roles = Role::with('permissions:id,slug,name')->orderBy('name')->get(['id', 'name', 'slug']);
|
||||
$permissions = Permission::orderBy('slug')->get(['id', 'name', 'slug']);
|
||||
|
||||
@@ -29,6 +31,23 @@ public function index(Request $request): Response
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(StoreUserRequest $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validated();
|
||||
|
||||
$user = User::create([
|
||||
'name' => $validated['name'],
|
||||
'email' => $validated['email'],
|
||||
'password' => Hash::make($validated['password']),
|
||||
]);
|
||||
|
||||
if (! empty($validated['roles'])) {
|
||||
$user->roles()->sync($validated['roles']);
|
||||
}
|
||||
|
||||
return back()->with('success', 'Uporabnik uspešno ustvarjen');
|
||||
}
|
||||
|
||||
public function update(Request $request, User $user): RedirectResponse
|
||||
{
|
||||
Gate::authorize('manage-settings');
|
||||
@@ -42,4 +61,16 @@ public function update(Request $request, User $user): RedirectResponse
|
||||
|
||||
return back()->with('success', 'Roles updated');
|
||||
}
|
||||
|
||||
public function toggleActive(User $user): RedirectResponse
|
||||
{
|
||||
Gate::authorize('manage-settings');
|
||||
|
||||
$user->active = ! $user->active;
|
||||
$user->save();
|
||||
|
||||
$status = $user->active ? 'aktiviran' : 'deaktiviran';
|
||||
|
||||
return back()->with('success', "Uporabnik {$status}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
use App\Models\CaseObject;
|
||||
use App\Models\ClientCase;
|
||||
use App\Models\Contract;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CaseObjectController extends Controller
|
||||
@@ -27,8 +26,8 @@ public function store(ClientCase $clientCase, string $uuid, Request $request)
|
||||
|
||||
public function update(ClientCase $clientCase, int $id, Request $request)
|
||||
{
|
||||
$object = CaseObject::where('id', $id)
|
||||
->whereHas('contract', fn($q) => $q->where('client_case_id', $clientCase->id))
|
||||
$object = CaseObject::where('id', $id)
|
||||
->whereHas('contract', fn ($q) => $q->where('client_case_id', $clientCase->id))
|
||||
->firstOrFail();
|
||||
|
||||
$validated = $request->validate([
|
||||
@@ -45,8 +44,8 @@ public function update(ClientCase $clientCase, int $id, Request $request)
|
||||
|
||||
public function destroy(ClientCase $clientCase, int $id)
|
||||
{
|
||||
$object = CaseObject::where('id', $id)
|
||||
->whereHas('contract', fn($q) => $q->where('client_case_id', $clientCase->id))
|
||||
$object = CaseObject::where('id', $id)
|
||||
->whereHas('contract', fn ($q) => $q->where('client_case_id', $clientCase->id))
|
||||
->firstOrFail();
|
||||
|
||||
$object->delete();
|
||||
|
||||
@@ -399,6 +399,21 @@ public function updateContractSegment(ClientCase $clientCase, string $uuid, Requ
|
||||
return back()->with('success', 'Contract segment updated.')->with('flash_method', 'PATCH');
|
||||
}
|
||||
|
||||
public function patchContractMeta(ClientCase $clientCase, string $uuid, Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'meta' => ['required', 'array'],
|
||||
]);
|
||||
|
||||
$contract = $clientCase->contracts()->where('uuid', $uuid)->firstOrFail();
|
||||
|
||||
$contract->update([
|
||||
'meta' => $validated['meta'],
|
||||
]);
|
||||
|
||||
return back()->with('success', __('Meta podatki so bili posodobljeni.'));
|
||||
}
|
||||
|
||||
public function attachSegment(ClientCase $clientCase, Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
@@ -1224,7 +1239,7 @@ public function listContracts(ClientCase $clientCase)
|
||||
{
|
||||
$contracts = $clientCase->contracts()
|
||||
->with('account.type')
|
||||
->select('id', 'uuid', 'reference', 'active', 'start_date', 'end_date')
|
||||
->select('id', 'uuid', 'reference', 'active', 'start_date', 'end_date', 'meta')
|
||||
->latest('id')
|
||||
->get()
|
||||
->map(function ($c) {
|
||||
@@ -1240,6 +1255,7 @@ public function listContracts(ClientCase $clientCase)
|
||||
'active' => (bool) $c->active,
|
||||
'start_date' => (string) ($c->start_date ?? ''),
|
||||
'end_date' => (string) ($c->end_date ?? ''),
|
||||
'meta' => is_array($c->meta) && ! empty($c->meta) ? $this->flattenMeta($c->meta) : null,
|
||||
'account' => $acc ? [
|
||||
'reference' => $acc->reference,
|
||||
'type' => $acc->type?->name,
|
||||
@@ -1282,6 +1298,10 @@ public function previewSms(ClientCase $clientCase, Request $request, SmsService
|
||||
'start_date' => (string) ($contract->start_date ?? ''),
|
||||
'end_date' => (string) ($contract->end_date ?? ''),
|
||||
];
|
||||
// Include contract.meta as flattened key-value pairs
|
||||
if (is_array($contract->meta) && ! empty($contract->meta)) {
|
||||
$vars['contract']['meta'] = $this->flattenMeta($contract->meta);
|
||||
}
|
||||
if ($contract->account) {
|
||||
$initialRaw = (string) $contract->account->initial_amount;
|
||||
$balanceRaw = (string) $contract->account->balance_amount;
|
||||
@@ -1305,4 +1325,47 @@ public function previewSms(ClientCase $clientCase, Request $request, SmsService
|
||||
'variables' => $vars,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten nested meta structure into dot-notation key-value pairs.
|
||||
* Extracts 'value' from objects with {title, value, type} structure.
|
||||
* Also creates direct access aliases for nested fields (skipping numeric keys).
|
||||
*/
|
||||
private function flattenMeta(array $meta, string $prefix = ''): array
|
||||
{
|
||||
$result = [];
|
||||
foreach ($meta as $key => $value) {
|
||||
$newKey = $prefix === '' ? $key : "{$prefix}.{$key}";
|
||||
|
||||
if (is_array($value)) {
|
||||
// Check if it's a structured meta entry with 'value' field
|
||||
if (isset($value['value'])) {
|
||||
$result[$newKey] = $value['value'];
|
||||
// If parent key is numeric, also create direct alias without the number
|
||||
if ($prefix !== '' && is_numeric($key)) {
|
||||
$result[$key] = $value['value'];
|
||||
}
|
||||
} else {
|
||||
// Recursively flatten nested arrays
|
||||
$nested = $this->flattenMeta($value, $newKey);
|
||||
$result = array_merge($result, $nested);
|
||||
|
||||
// If current key is numeric, also flatten without it for easier access
|
||||
if (is_numeric($key)) {
|
||||
$directNested = $this->flattenMeta($value, $prefix);
|
||||
foreach ($directNested as $dk => $dv) {
|
||||
// Only add if not already set (prefer first occurrence)
|
||||
if (! isset($result[$dk])) {
|
||||
$result[$dk] = $dv;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$result[$newKey] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +105,8 @@ public function contracts(Client $client, Request $request)
|
||||
$from = $request->input('from');
|
||||
$to = $request->input('to');
|
||||
$search = $request->input('search');
|
||||
$segmentId = $request->input('segment');
|
||||
$segmentsParam = $request->input('segments');
|
||||
$segmentIds = $segmentsParam ? array_filter(explode(',', $segmentsParam)) : [];
|
||||
|
||||
$contractsQuery = \App\Models\Contract::query()
|
||||
->select(['contracts.id', 'contracts.uuid', 'contracts.reference', 'contracts.start_date', 'contracts.client_case_id'])
|
||||
|
||||
@@ -14,8 +14,8 @@ public function index()
|
||||
{
|
||||
return Inertia::render('Settings/ContractConfigs/Index', [
|
||||
'configs' => ContractConfig::with(['type:id,name', 'segment:id,name'])->get(),
|
||||
'types' => ContractType::query()->get(['id','name']),
|
||||
'segments' => Segment::query()->where('active', true)->get(['id','name']),
|
||||
'types' => ContractType::query()->get(['id', 'name']),
|
||||
'segments' => Segment::query()->where('active', true)->get(['id', 'name']),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ public function store(Request $request)
|
||||
ContractConfig::create([
|
||||
'contract_type_id' => $data['contract_type_id'],
|
||||
'segment_id' => $data['segment_id'],
|
||||
'is_initial' => (bool)($data['is_initial'] ?? false),
|
||||
'active' => (bool)($data['active'] ?? true),
|
||||
'is_initial' => (bool) ($data['is_initial'] ?? false),
|
||||
'active' => (bool) ($data['active'] ?? true),
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Configuration created');
|
||||
@@ -57,8 +57,8 @@ public function update(ContractConfig $config, Request $request)
|
||||
|
||||
$config->update([
|
||||
'segment_id' => $data['segment_id'],
|
||||
'is_initial' => (bool)($data['is_initial'] ?? $config->is_initial),
|
||||
'active' => (bool)($data['active'] ?? $config->active),
|
||||
'is_initial' => (bool) ($data['is_initial'] ?? $config->is_initial),
|
||||
'active' => (bool) ($data['active'] ?? $config->active),
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Configuration updated');
|
||||
@@ -67,6 +67,7 @@ public function update(ContractConfig $config, Request $request)
|
||||
public function destroy(ContractConfig $config)
|
||||
{
|
||||
$config->delete();
|
||||
|
||||
return back()->with('success', 'Configuration deleted');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,26 +4,28 @@
|
||||
|
||||
use App\Models\Contract;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Inertia\Inertia;
|
||||
|
||||
|
||||
class ContractController extends Controller
|
||||
{
|
||||
|
||||
public function index(Contract $contract) {
|
||||
public function index(Contract $contract)
|
||||
{
|
||||
return Inertia::render('Contract/Index', [
|
||||
'contracts' => $contract::with(['type', 'debtor'])
|
||||
->where('active', 1)
|
||||
->orderByDesc('created_at')
|
||||
->paginate(10),
|
||||
'person_types' => \App\Models\Person\PersonType::all(['id', 'name', 'description'])
|
||||
->where('deleted', 0)
|
||||
->where('deleted', 0),
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(Contract $contract){
|
||||
public function show(Contract $contract)
|
||||
{
|
||||
return inertia('Contract/Show', [
|
||||
'contract' => $contract::with(['type', 'client', 'debtor'])->findOrFail($contract->id)
|
||||
'contract' => $contract::with(['type', 'client', 'debtor'])->findOrFail($contract->id),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -32,16 +34,16 @@ public function store(Request $request)
|
||||
$uuid = $request->input('client_case_uuid');
|
||||
|
||||
$clientCase = \App\Models\ClientCase::where('uuid', $uuid)->firstOrFail();
|
||||
|
||||
if( isset($clientCase->id) ){
|
||||
|
||||
\DB::transaction(function() use ($request, $clientCase){
|
||||
if (isset($clientCase->id)) {
|
||||
|
||||
//Create contract
|
||||
\DB::transaction(function () use ($request, $clientCase) {
|
||||
|
||||
// Create 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'),
|
||||
]);
|
||||
|
||||
});
|
||||
@@ -50,12 +52,79 @@ public function store(Request $request)
|
||||
return back()->with('success', 'Contract created')->with('flash_method', 'POST');
|
||||
}
|
||||
|
||||
public function update(Contract $contract, Request $request){
|
||||
public function update(Contract $contract, Request $request)
|
||||
{
|
||||
$contract->update([
|
||||
'referenca' => $request->input('referenca'),
|
||||
'type_id' => $request->input('type_id')
|
||||
'type_id' => $request->input('type_id'),
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Contract updated')->with('flash_method', 'PUT');
|
||||
}
|
||||
|
||||
public function segment(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'segment_id' => ['required', 'integer', Rule::exists('segments', 'id')->where('active', true)],
|
||||
'contracts' => ['required', 'array', 'min:1'],
|
||||
'contracts.*' => ['string', Rule::exists('contracts', 'uuid')],
|
||||
]);
|
||||
|
||||
$segmentId = (int) $data['segment_id'];
|
||||
$uuids = array_values($data['contracts']);
|
||||
|
||||
$contracts = Contract::query()
|
||||
->whereIn('uuid', $uuids)
|
||||
->get(['id', 'client_case_id']);
|
||||
|
||||
DB::transaction(function () use ($contracts, $segmentId) {
|
||||
foreach ($contracts as $contract) {
|
||||
// Ensure the segment is attached to the client case and active
|
||||
$attached = DB::table('client_case_segment')
|
||||
->where('client_case_id', $contract->client_case_id)
|
||||
->where('segment_id', $segmentId)
|
||||
->first();
|
||||
|
||||
if (! $attached) {
|
||||
DB::table('client_case_segment')->insert([
|
||||
'client_case_id' => $contract->client_case_id,
|
||||
'segment_id' => $segmentId,
|
||||
'active' => true,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
} elseif (! $attached->active) {
|
||||
DB::table('client_case_segment')
|
||||
->where('id', $attached->id)
|
||||
->update(['active' => true, 'updated_at' => now()]);
|
||||
}
|
||||
|
||||
// Deactivate all current contract segments
|
||||
DB::table('contract_segment')
|
||||
->where('contract_id', $contract->id)
|
||||
->update(['active' => false, 'updated_at' => now()]);
|
||||
|
||||
// Activate or attach the target segment
|
||||
$pivot = DB::table('contract_segment')
|
||||
->where('contract_id', $contract->id)
|
||||
->where('segment_id', $segmentId)
|
||||
->first();
|
||||
|
||||
if ($pivot) {
|
||||
DB::table('contract_segment')
|
||||
->where('id', $pivot->id)
|
||||
->update(['active' => true, 'updated_at' => now()]);
|
||||
} else {
|
||||
DB::table('contract_segment')->insert([
|
||||
'contract_id' => $contract->id,
|
||||
'segment_id' => $segmentId,
|
||||
'active' => true,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return back()->with('success', __('Pogodbe so bile preusmerjene v izbrani segment.'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DebtController extends Controller
|
||||
{
|
||||
//
|
||||
|
||||
@@ -111,10 +111,10 @@ public function store(Request $request)
|
||||
'is_active' => 'boolean',
|
||||
'reactivate' => 'boolean',
|
||||
'entities' => 'nullable|array',
|
||||
'entities.*' => 'string|in:person,person_addresses,person_phones,emails,accounts,contracts,client_cases,payments',
|
||||
'entities.*' => 'string|in:person,person_addresses,person_phones,emails,accounts,contracts,client_cases,case_objects,payments',
|
||||
'mappings' => 'array',
|
||||
'mappings.*.source_column' => 'required|string',
|
||||
'mappings.*.entity' => 'nullable|string|in:person,person_addresses,person_phones,emails,accounts,contracts,client_cases,payments',
|
||||
'mappings.*.entity' => 'nullable|string|in:person,person_addresses,person_phones,emails,accounts,contracts,client_cases,case_objects,payments',
|
||||
'mappings.*.target_field' => 'nullable|string',
|
||||
'mappings.*.transform' => 'nullable|string|max:50',
|
||||
'mappings.*.apply_mode' => 'nullable|string|in:insert,update,both,keyref',
|
||||
@@ -244,7 +244,7 @@ public function addMapping(Request $request, ImportTemplate $template)
|
||||
}
|
||||
$data = validator($raw, [
|
||||
'source_column' => 'required|string',
|
||||
'entity' => 'nullable|string|in:person,person_addresses,person_phones,emails,accounts,contracts,client_cases,payments',
|
||||
'entity' => 'nullable|string|in:person,person_addresses,person_phones,emails,accounts,contracts,client_cases,case_objects,payments',
|
||||
'target_field' => 'nullable|string',
|
||||
'transform' => 'nullable|string|in:trim,upper,lower',
|
||||
'apply_mode' => 'nullable|string|in:insert,update,both,keyref',
|
||||
@@ -381,7 +381,7 @@ public function bulkAddMappings(Request $request, ImportTemplate $template)
|
||||
}
|
||||
$data = validator($raw, [
|
||||
'sources' => 'required|string', // comma and/or newline separated
|
||||
'entity' => 'nullable|string|in:person,person_addresses,person_phones,emails,accounts,contracts,client_cases,payments',
|
||||
'entity' => 'nullable|string|in:person,person_addresses,person_phones,emails,accounts,contracts,client_cases,case_objects,payments',
|
||||
'default_field' => 'nullable|string', // if provided, used as the field name for all entries
|
||||
'apply_mode' => 'nullable|string|in:insert,update,both,keyref',
|
||||
'transform' => 'nullable|string|in:trim,upper,lower',
|
||||
@@ -488,7 +488,7 @@ public function updateMapping(Request $request, ImportTemplate $template, Import
|
||||
}
|
||||
$data = validator($raw, [
|
||||
'source_column' => 'required|string',
|
||||
'entity' => 'nullable|string|in:person,person_addresses,person_phones,emails,accounts,contracts,client_cases,payments',
|
||||
'entity' => 'nullable|string|in:person,person_addresses,person_phones,emails,accounts,contracts,client_cases,case_objects,payments',
|
||||
'target_field' => 'nullable|string',
|
||||
'transform' => 'nullable|string|in:trim,upper,lower',
|
||||
'apply_mode' => 'nullable|string|in:insert,update,both,keyref',
|
||||
|
||||
@@ -35,7 +35,15 @@ public function unread(Request $request)
|
||||
->select(['id', 'due_date', 'amount', 'contract_id', 'client_case_id', 'created_at'])
|
||||
->whereNotNull('due_date')
|
||||
->whereDate('due_date', '<=', $today)
|
||||
// Removed per-user unread filter: show notifications regardless of individual reads
|
||||
// Exclude activities that have been marked as read by this user
|
||||
->whereNotExists(function ($q) use ($user, $today) {
|
||||
$q->select(\DB::raw(1))
|
||||
->from('activity_notification_reads')
|
||||
->whereColumn('activity_notification_reads.activity_id', 'activities.id')
|
||||
->where('activity_notification_reads.user_id', $user->id)
|
||||
->whereDate('activity_notification_reads.due_date', '<=', $today)
|
||||
->whereNotNull('activity_notification_reads.read_at');
|
||||
})
|
||||
->when($clientCaseIdsForFilter->isNotEmpty(), function ($q) use ($clientCaseIdsForFilter) {
|
||||
// Filter by clients: activities directly on any of the client's cases OR via contracts under those cases
|
||||
$q->where(function ($qq) use ($clientCaseIdsForFilter) {
|
||||
@@ -108,7 +116,15 @@ public function unread(Request $request)
|
||||
->select(['contract_id', 'client_case_id'])
|
||||
->whereNotNull('due_date')
|
||||
->whereDate('due_date', '<=', $today)
|
||||
// Removed per-user unread filter for client list base
|
||||
// Exclude activities that have been marked as read by this user
|
||||
->whereNotExists(function ($q) use ($user, $today) {
|
||||
$q->select(\DB::raw(1))
|
||||
->from('activity_notification_reads')
|
||||
->whereColumn('activity_notification_reads.activity_id', 'activities.id')
|
||||
->where('activity_notification_reads.user_id', $user->id)
|
||||
->whereDate('activity_notification_reads.due_date', '<=', $today)
|
||||
->whereNotNull('activity_notification_reads.read_at');
|
||||
})
|
||||
->when($clientCaseIdsForFilter->isNotEmpty(), function ($q) use ($clientCaseIdsForFilter) {
|
||||
$q->where(function ($qq) use ($clientCaseIdsForFilter) {
|
||||
$qq->whereIn('activities.client_case_id', $clientCaseIdsForFilter)
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PaymentController extends Controller
|
||||
{
|
||||
//
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Post;
|
||||
use App\Http\Requests\StorePostRequest;
|
||||
use App\Http\Requests\UpdatePostRequest;
|
||||
use App\Models\Post;
|
||||
|
||||
class PostController extends Controller
|
||||
{
|
||||
|
||||
@@ -9,7 +9,8 @@ class SettingController extends Controller
|
||||
{
|
||||
//
|
||||
|
||||
public function index(Request $request){
|
||||
public function index(Request $request)
|
||||
{
|
||||
return Inertia::render('Settings/Index');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user