Changes 0228092025 Laptop

This commit is contained in:
2025-09-28 14:51:02 +02:00
parent 765beb78b7
commit b40ee9dcde
36 changed files with 2099 additions and 65 deletions
@@ -2,12 +2,13 @@
import ActionMessage from '@/Components/ActionMessage.vue';
import DialogModal from '@/Components/DialogModal.vue';
import InputLabel from '@/Components/InputLabel.vue';
import InputError from '@/Components/InputError.vue';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import SectionTitle from '@/Components/SectionTitle.vue';
import TextInput from '@/Components/TextInput.vue';
import DatePickerField from '@/Components/DatePickerField.vue';
import { useForm } from '@inertiajs/vue3';
import { watch } from 'vue';
import { watch, nextTick, ref as vRef } from 'vue';
const props = defineProps({
client_case: Object,
@@ -22,7 +23,10 @@ console.log(props.types);
const emit = defineEmits(['close']);
const close = () => {
emit('close');
// Clear any previous validation warnings when closing
formContract.clearErrors()
formContract.recentlySuccessful = false
emit('close')
}
// form state for create or edit
@@ -58,6 +62,20 @@ watch(() => props.show, (open) => {
// reset for create
applyContract(null)
}
if (!open) {
// Ensure warnings are cleared when dialog hides
formContract.clearErrors()
formContract.recentlySuccessful = false
}
})
// optional: focus the reference input when a reference validation error appears
const contractRefInput = vRef(null)
watch(() => formContract.errors.reference, async (err) => {
if (err && props.show) {
await nextTick()
try { contractRefInput.value?.focus?.() } catch (e) {}
}
})
const storeOrUpdate = () => {
@@ -90,6 +108,9 @@ const storeOrUpdate = () => {
<template #title>{{ formContract.uuid ? 'Uredi pogodbo' : 'Dodaj pogodbo' }}</template>
<template #content>
<form @submit.prevent="storeOrUpdate">
<div v-if="formContract.errors.reference" class="mb-4 rounded border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-700">
{{ formContract.errors.reference }}
</div>
<SectionTitle class="mt-4 border-b mb-4">
<template #title>
Pogodba
@@ -102,9 +123,10 @@ const storeOrUpdate = () => {
ref="contractRefInput"
v-model="formContract.reference"
type="text"
class="mt-1 block w-full"
:class="['mt-1 block w-full', formContract.errors.reference ? 'border-red-500 focus:border-red-500 focus:ring-red-500' : '']"
autocomplete="contract-reference"
/>
<InputError :message="formContract.errors.reference" />
</div>
<DatePickerField
id="contractStartDate"
@@ -10,6 +10,8 @@ const props = defineProps({
client_case: Object,
contract_types: Array,
contracts: { type: Array, default: () => [] },
segments: { type: Array, default: () => [] },
all_segments: { type: Array, default: () => [] },
})
const emit = defineEmits(['edit', 'delete', 'add-activity'])
@@ -30,7 +32,8 @@ const onDelete = (c) => emit('delete', c)
const onAddActivity = (c) => emit('add-activity', c)
// CaseObject dialog state
import { ref } from 'vue'
import { ref, computed } from 'vue'
import { router } from '@inertiajs/vue3'
const showObjectDialog = ref(false)
const showObjectsList = ref(false)
const selectedContract = ref(null)
@@ -38,6 +41,39 @@ const openObjectDialog = (c) => { selectedContract.value = c; showObjectDialog.v
const closeObjectDialog = () => { showObjectDialog.value = false; selectedContract.value = null }
const openObjectsList = (c) => { selectedContract.value = c; showObjectsList.value = true }
const closeObjectsList = () => { showObjectsList.value = false; selectedContract.value = null }
// Segment helpers
const contractActiveSegment = (c) => {
const arr = c?.segments || []
return arr.find(s => s.pivot?.active) || arr[0] || null
}
const segmentName = (id) => props.segments.find(s => s.id === id)?.name || ''
const confirmChange = ref({ show: false, contract: null, segmentId: null, fromAll: false })
const askChangeSegment = (c, segmentId, fromAll = false) => {
confirmChange.value = { show: true, contract: c, segmentId, fromAll }
}
const closeConfirm = () => { confirmChange.value = { show: false, contract: null, segmentId: null } }
const doChangeSegment = () => {
const { contract, segmentId, fromAll } = confirmChange.value
if (!contract || !segmentId) return closeConfirm()
if (fromAll) {
router.post(route('clientCase.segments.attach', props.client_case), {
segment_id: segmentId,
contract_uuid: contract.uuid,
make_active_for_contract: true,
}, {
preserveScroll: true,
only: ['contracts', 'segments'],
onFinish: () => closeConfirm(),
})
} else {
router.post(route('clientCase.contract.updateSegment', { client_case: props.client_case.uuid, uuid: contract.uuid }), { segment_id: segmentId }, {
preserveScroll: true,
only: ['contracts'],
onFinish: () => closeConfirm(),
})
}
}
</script>
<template>
@@ -47,6 +83,7 @@ const closeObjectsList = () => { showObjectsList.value = false; selectedContract
<FwbTableHeadCell class="uppercase text-xs font-semibold tracking-wide text-gray-700 py-3">Ref.</FwbTableHeadCell>
<FwbTableHeadCell class="uppercase text-xs font-semibold tracking-wide text-gray-700 py-3">Datum začetka</FwbTableHeadCell>
<FwbTableHeadCell class="uppercase text-xs font-semibold tracking-wide text-gray-700 py-3">Tip</FwbTableHeadCell>
<FwbTableHeadCell class="uppercase text-xs font-semibold tracking-wide text-gray-700 py-3">Segment</FwbTableHeadCell>
<FwbTableHeadCell class="uppercase text-xs font-semibold tracking-wide text-gray-700 py-3 text-right">Predano</FwbTableHeadCell>
<FwbTableHeadCell class="uppercase text-xs font-semibold tracking-wide text-gray-700 py-3 text-right">Odprto</FwbTableHeadCell>
<FwbTableHeadCell class="uppercase text-xs font-semibold tracking-wide text-gray-700 py-3 text-center">Opis</FwbTableHeadCell>
@@ -58,6 +95,43 @@ const closeObjectsList = () => { showObjectsList.value = false; selectedContract
<FwbTableCell>{{ c.reference }}</FwbTableCell>
<FwbTableCell>{{ formatDate(c.start_date) }}</FwbTableCell>
<FwbTableCell>{{ c?.type?.name }}</FwbTableCell>
<FwbTableCell>
<div class="flex items-center gap-2">
<span class="text-gray-700">{{ contractActiveSegment(c)?.name || '-' }}</span>
<Dropdown width="64" align="left">
<template #trigger>
<button
type="button"
class="inline-flex items-center justify-center h-7 w-7 rounded-full hover:bg-gray-100"
:class="{ 'opacity-50 cursor-not-allowed': !segments || segments.length === 0 }"
:title="segments && segments.length ? 'Change segment' : 'No segments available for this case'"
>
<FontAwesomeIcon :icon="faPenToSquare" class="h-4 w-4 text-gray-600" />
</button>
</template>
<template #content>
<div class="py-1">
<template v-if="segments && segments.length">
<button v-for="s in segments" :key="s.id" type="button" class="w-full px-3 py-1.5 text-left text-sm hover:bg-gray-50" @click="askChangeSegment(c, s.id)">
<span>{{ s.name }}</span>
</button>
</template>
<template v-else>
<template v-if="all_segments && all_segments.length">
<div class="px-3 py-2 text-xs text-gray-500">Ni segmentov v tem primeru. Dodaj in nastavi segment:</div>
<button v-for="s in all_segments" :key="s.id" type="button" class="w-full px-3 py-1.5 text-left text-sm hover:bg-gray-50" @click="askChangeSegment(c, s.id, true)">
<span>{{ s.name }}</span>
</button>
</template>
<template v-else>
<div class="px-3 py-2 text-sm text-gray-500">No segments configured.</div>
</template>
</template>
</div>
</template>
</Dropdown>
</div>
</FwbTableCell>
<FwbTableCell class="text-right">{{ Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(c?.account?.initial_amount ?? 0) }}</FwbTableCell>
<FwbTableCell class="text-right">{{ Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(c?.account?.balance_amount ?? 0) }}</FwbTableCell>
<FwbTableCell class="text-center">
@@ -149,6 +223,18 @@ const closeObjectsList = () => { showObjectsList.value = false; selectedContract
</FwbTable>
<div v-if="!contracts || contracts.length === 0" class="p-6 text-center text-sm text-gray-500">No contracts.</div>
</div>
<!-- Confirm change segment -->
<div v-if="confirmChange.show" class="fixed inset-0 z-50 flex items-center justify-center bg-black/30">
<div class="bg-white rounded-lg shadow-lg p-4 w-full max-w-sm">
<div class="text-sm text-gray-800">
Ali želite spremeniti segment za pogodbo <span class="font-medium">{{ confirmChange.contract?.reference }}</span>?
</div>
<div class="mt-4 flex justify-end gap-2">
<button class="px-4 py-2 rounded bg-gray-200 hover:bg-gray-300" @click="closeConfirm">Prekliči</button>
<button class="px-4 py-2 rounded bg-indigo-600 text-white hover:bg-indigo-700" @click="doChangeSegment">Potrdi</button>
</div>
</div>
</div>
<CaseObjectCreateDialog
:show="showObjectDialog"
@close="closeObjectDialog"