Dev branch

This commit is contained in:
Simon Pocrnjič
2025-11-02 12:31:01 +01:00
parent 5f879c9436
commit 63e0958b66
241 changed files with 17686 additions and 7327 deletions
+106 -97
View File
@@ -2,9 +2,20 @@
import AppLayout from "@/Layouts/AppLayout.vue";
import { ref } from "vue";
import { Link, router } from "@inertiajs/vue3";
import DataTableServer from "@/Components/DataTable/DataTableServer.vue";
import PersonInfoGrid from "@/Components/PersonInfoGrid.vue";
import DataTable from "@/Components/DataTable/DataTable.vue";
import { Button } from "@/Components/ui/button";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/Components/ui/select";
import PersonInfoGrid from "@/Components/PersonInfo/PersonInfoGrid.vue";
import SectionTitle from "@/Components/SectionTitle.vue";
import DateRangePicker from "@/Components/DateRangePicker.vue";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { ButtonGroup } from "@/Components/ui/button-group";
const props = defineProps({
client: Object,
@@ -14,21 +25,24 @@ const props = defineProps({
types: Object,
});
const fromDate = ref(props.filters?.from || "");
const toDate = ref(props.filters?.to || "");
const dateRange = ref({
start: props.filters?.from || null,
end: props.filters?.to || null,
});
const search = ref(props.filters?.search || "");
const selectedSegment = ref(props.filters?.segment || "");
const selectedSegment = ref(props.filters?.segment || null);
function applyDateFilter() {
const params = Object.fromEntries(
new URLSearchParams(window.location.search).entries()
);
if (fromDate.value) {
params.from = fromDate.value;
if (dateRange.value?.start) {
params.from = dateRange.value.start;
} else {
delete params.from;
}
if (toDate.value) {
params.to = toDate.value;
if (dateRange.value?.end) {
params.to = dateRange.value.end;
} else {
delete params.to;
}
@@ -38,7 +52,7 @@ function applyDateFilter() {
delete params.search;
}
if (selectedSegment.value) {
params.segment = selectedSegment.value;
params.segment = String(selectedSegment.value);
} else {
delete params.segment;
}
@@ -47,13 +61,22 @@ function applyDateFilter() {
preserveState: true,
replace: true,
preserveScroll: true,
only: ['contracts'],
});
}
function clearDateFilter() {
fromDate.value = "";
toDate.value = "";
selectedSegment.value = "";
dateRange.value = { start: null, end: null };
selectedSegment.value = null;
applyDateFilter();
}
function handleDateRangeUpdate() {
applyDateFilter();
}
function handleSegmentChange(value) {
selectedSegment.value = value;
applyDateFilter();
}
@@ -101,36 +124,6 @@ function formatDate(value) {
</template>
</SectionTitle>
</div>
<nav class="mt-2 border-b border-gray-200">
<ul class="flex gap-6 -mb-px">
<li>
<Link
:href="route('client.show', { uuid: client.uuid })"
:class="[
'inline-flex items-center px-3 py-2 text-sm font-medium border-b-2',
route().current('client.show')
? 'text-indigo-600 border-indigo-600'
: 'text-gray-600 border-transparent hover:text-gray-800 hover:border-gray-300'
]"
>
Primeri
</Link>
</li>
<li>
<Link
:href="route('client.contracts', { uuid: client.uuid })"
:class="[
'inline-flex items-center px-3 py-2 text-sm font-medium border-b-2',
route().current('client.contracts')
? 'text-indigo-600 border-indigo-600'
: 'text-gray-600 border-transparent hover:text-gray-800 hover:border-gray-300'
]"
>
Pogodbe
</Link>
</li>
</ul>
</nav>
</div>
</div>
</div>
@@ -154,56 +147,31 @@ function formatDate(value) {
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="px-3 bg-white overflow-hidden shadow-xl sm:rounded-lg">
<div class="mx-auto max-w-4x1 py-3">
<div
class="flex flex-col gap-3 md:flex-row md:items-center md:justify-between"
>
<div class="flex items-center gap-3 flex-wrap">
<label class="font-medium mr-2">Filtri:</label>
<div class="flex items-center gap-2">
<span class="text-sm text-gray-600">Od</span>
<input
type="date"
v-model="fromDate"
@change="applyDateFilter"
class="rounded border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 px-3 py-2 text-sm"
/>
</div>
<div class="flex items-center gap-2">
<span class="text-sm text-gray-600">Do</span>
<input
type="date"
v-model="toDate"
@change="applyDateFilter"
class="rounded border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 px-3 py-2 text-sm"
/>
</div>
<div class="flex items-center gap-2">
<span class="text-sm text-gray-600">Segment</span>
<select
v-model="selectedSegment"
@change="applyDateFilter"
class="rounded border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 px-3 py-2 text-sm"
>
<option value="">Vsi segmenti</option>
<option v-for="segment in segments" :key="segment.id" :value="segment.id">
{{ segment.name }}
</option>
</select>
</div>
<button
type="button"
class="inline-flex items-center px-3 py-2 text-sm font-medium rounded border border-gray-300 text-gray-700 hover:bg-gray-50 disabled:opacity-50"
:disabled="!fromDate && !toDate && !selectedSegment"
@click="clearDateFilter"
title="Počisti filtre"
<div class="mb-4">
<ButtonGroup>
<Button
as-child
:variant="route().current('client.show') ? 'default' : 'ghost'"
>
Počisti
</button>
</div>
<!-- Search lives in DataTable toolbar -->
<Link :href="route('client.show', { uuid: client.uuid })">
Primeri
</Link>
</Button>
<Button
as-child
:variant="route().current('client.contracts') ? 'default' : 'ghost'"
>
<Link :href="route('client.contracts', { uuid: client.uuid })">
Pogodbe
</Link>
</Button>
</ButtonGroup>
</div>
<DataTableServer
class="mt-3"
<DataTable
:show-search="true"
:show-page-size="true"
:show-filters="true"
:has-active-filters="!!(dateRange?.start || dateRange?.end || selectedSegment)"
:columns="[
{ key: 'reference', label: 'Referenca', sortable: false },
{ key: 'customer', label: 'Stranka', sortable: false },
@@ -212,14 +180,58 @@ function formatDate(value) {
{ key: 'balance', label: 'Stanje', sortable: false, align: 'right' },
]"
:rows="contracts.data || []"
:meta="{ current_page: contracts.current_page, per_page: contracts.per_page, total: contracts.total, last_page: contracts.last_page }"
:meta="{ current_page: contracts.current_page, per_page: contracts.per_page, total: contracts.total, last_page: contracts.last_page, from: contracts.from, to: contracts.to, links: contracts.links }"
route-name="client.contracts"
:route-params="{ uuid: client.uuid }"
:query="{ from: fromDate || undefined, to: toDate || undefined, segment: selectedSegment || undefined }"
:search="search"
row-key="uuid"
:only-props="['contracts']"
>
<template #toolbar-filters>
<div class="space-y-4">
<div class="space-y-2">
<label class="text-sm font-medium">Datumska območja</label>
<DateRangePicker
v-model="dateRange"
format="dd.MM.yyyy"
@update:model-value="handleDateRangeUpdate"
placeholder="Izberi datumska območja"
/>
</div>
<div class="space-y-2">
<label class="text-sm font-medium">Segment</label>
<Select
:model-value="selectedSegment"
@update:model-value="handleSegmentChange"
>
<SelectTrigger class="w-full">
<SelectValue placeholder="Vsi segmenti" />
</SelectTrigger>
<SelectContent class="w-[var(--radix-select-trigger-width)]">
<SelectItem :value="null">Vsi segmenti</SelectItem>
<SelectItem
v-for="segment in segments"
:key="segment.id"
:value="String(segment.id)"
>
{{ segment.name }}
</SelectItem>
</SelectContent>
</Select>
</div>
<div class="flex justify-end pt-2 border-t">
<Button
type="button"
variant="outline"
size="sm"
:disabled="!dateRange?.start && !dateRange?.end && !selectedSegment"
@click="clearDateFilter"
>
Počisti
</Button>
</div>
</div>
</template>
<template #cell-reference="{ row }">
<Link :href="route('clientCase.show', caseShowParams(row))" class="text-indigo-600 hover:underline">
{{ row.reference }}
@@ -239,10 +251,7 @@ function formatDate(value) {
{{ new Intl.NumberFormat('sl-SI', { style: 'currency', currency: 'EUR' }).format(Number(row.account?.balance_amount ?? 0)) }}
</div>
</template>
<template #empty>
<div class="p-6 text-center text-gray-500">Ni zadetkov.</div>
</template>
</DataTableServer>
</DataTable>
</div>
<!-- Pagination handled by DataTableServer -->
</div>
+292 -180
View File
@@ -1,14 +1,34 @@
<script setup>
import { computed, ref } from "vue";
import AppLayout from "@/Layouts/AppLayout.vue";
import PrimaryButton from "@/Components/PrimaryButton.vue";
import InputLabel from "@/Components/InputLabel.vue";
import TextInput from "@/Components/TextInput.vue";
import { Link, useForm, router, usePage } from "@inertiajs/vue3";
import ActionMessage from "@/Components/ActionMessage.vue";
import DialogModal from "@/Components/DialogModal.vue";
import DataTableServer from "@/Components/DataTable/DataTableServer.vue";
import { Link, router, usePage } from "@inertiajs/vue3";
import CreateDialog from "@/Components/Dialogs/CreateDialog.vue";
import DataTable from "@/Components/DataTable/DataTable.vue";
import { hasPermission } from "@/Services/permissions";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { faUserGroup } from "@fortawesome/free-solid-svg-icons";
import { Button } from "@/Components/ui/button";
import { Input } from "@/Components/ui/input";
import ActionMenuItem from "@/Components/DataTable/ActionMenuItem.vue";
import { faPlus } from "@fortawesome/free-solid-svg-icons";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/Components/ui/select";
import {
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@/Components/ui/form";
import { useForm } from "vee-validate";
import { toTypedSchema } from "@vee-validate/zod";
import * as z from "zod";
import ActionMessage from "@/Components/ActionMessage.vue";
const props = defineProps({
clients: Object,
@@ -21,27 +41,47 @@ const hasPerm = computed(() => (permission) =>
hasPermission(page.props.auth?.user, permission)
);
const Address = {
address: "",
country: "",
type_id: 1,
};
const Phone = {
nu: "",
country_code: "00386",
type_id: 1,
};
const formSchema = toTypedSchema(
z.object({
first_name: z.string().optional(),
last_name: z.string().optional(),
full_name: z.string().min(1, "Naziv je obvezen."),
tax_number: z.string().optional(),
social_security_number: z.string().optional(),
description: z.string().optional(),
address: z.object({
address: z.string().optional(),
country: z.string().optional(),
type_id: z.number().default(1),
}),
phone: z.object({
nu: z.string().optional(),
country_code: z.string().default("00386"),
type_id: z.number().default(1),
}),
})
);
const formClient = useForm({
first_name: "",
last_name: "",
full_name: "",
tax_number: "",
social_security_number: "",
description: "",
address: Address,
phone: Phone,
validationSchema: formSchema,
initialValues: {
first_name: "",
last_name: "",
full_name: "",
tax_number: "",
social_security_number: "",
description: "",
address: {
address: "",
country: "",
type_id: 1,
},
phone: {
nu: "",
country_code: "00386",
type_id: 1,
},
},
});
//Create client drawer
@@ -58,21 +98,58 @@ const openDrawerCreateClient = () => {
//Close any drawer on page
const closeDrawer = () => {
drawerCreateClient.value = false;
formClient.resetForm();
};
const processing = ref(false);
//Ajax call post to store new client
const storeClient = () => {
formClient.post(route("client.store"), {
onBefore: () => {
formClient.address.type_id = Number(formClient.address.type_id);
const storeClient = async () => {
processing.value = true;
const { values } = formClient;
// Ensure type_id is a number
const payload = {
...values,
address: {
...values.address,
type_id: Number(values.address.type_id),
},
onSuccess: () => {
closeDrawer();
formClient.reset();
phone: {
...values.phone,
type_id: Number(values.phone.type_id),
},
});
};
router.post(
route("client.store"),
payload,
{
onSuccess: () => {
closeDrawer();
formClient.resetForm();
processing.value = false;
},
onError: (errors) => {
Object.keys(errors).forEach((field) => {
const errorMessages = Array.isArray(errors[field])
? errors[field]
: [errors[field]];
formClient.setFieldError(field, errorMessages[0]);
});
processing.value = false;
},
onFinish: () => {
processing.value = false;
},
}
);
};
const onConfirmCreate = formClient.handleSubmit(() => {
storeClient();
});
// Formatting helpers
const fmtCurrency = (v) => {
const n = Number(v ?? 0);
@@ -93,20 +170,11 @@ const fmtCurrency = (v) => {
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="px-3 bg-white overflow-hidden shadow-xl sm:rounded-lg">
<div class="mx-auto max-w-4x1 py-3 space-y-3">
<!-- Top actions -->
<div
class="flex items-center justify-between gap-3"
v-if="hasPerm('client-edit')"
>
<PrimaryButton
@click="openDrawerCreateClient"
class="bg-blue-600 hover:bg-blue-700"
>Dodaj</PrimaryButton
>
</div>
<!-- DataTable (server-side) -->
<DataTableServer
<DataTable
:show-search="true"
:show-page-size="true"
:show-add="true"
:columns="[
{ key: 'nu', label: 'Št.', sortable: false, class: 'w-40' },
{ key: 'name', label: 'Naročnik', sortable: false },
@@ -129,6 +197,9 @@ const fmtCurrency = (v) => {
per_page: clients.per_page,
total: clients.total,
last_page: clients.last_page,
from: clients.from,
to: clients.to,
links: clients.links,
}"
:sort="{
key: props.filters?.sort || null,
@@ -137,9 +208,19 @@ const fmtCurrency = (v) => {
:search="initialSearch"
route-name="client"
row-key="uuid"
:page-size-options="[clients.per_page]"
:only-props="['clients']"
:empty-icon="faUserGroup"
empty-text="Ni zadetkov"
empty-description="Ni najdenih naročnikov. Ustvarite novega naročnika ali preverite iskalne kriterije."
>
<template #toolbar-add>
<ActionMenuItem
v-if="hasPerm('client-edit')"
label="Dodaj naročnika"
:icon="faPlus"
@click="openDrawerCreateClient"
/>
</template>
<template #cell-nu="{ row }">
{{ row.person?.nu || "-" }}
</template>
@@ -151,12 +232,13 @@ const fmtCurrency = (v) => {
{{ row.person?.full_name || "-" }}
</Link>
<div v-if="!row.person" class="mt-1">
<PrimaryButton
class="!py-0.5 !px-2 bg-red-500 hover:bg-red-600 text-xs"
<Button
variant="destructive"
size="sm"
@click.prevent="
router.post(route('client.emergencyPerson', { uuid: row.uuid }))
"
>Add Person</PrimaryButton
>Add Person</Button
>
</div>
</template>
@@ -170,146 +252,176 @@ const fmtCurrency = (v) => {
{{ fmtCurrency(row.active_contracts_balance_sum) }}
</div>
</template>
<template #empty>
<div class="p-6 text-center text-gray-500">Ni zadetkov.</div>
</template>
</DataTableServer>
</DataTable>
</div>
</div>
</div>
</div>
</AppLayout>
<DialogModal :show="drawerCreateClient" @close="drawerCreateClient = false">
<template #title>Novi naročnik</template>
<template #content>
<form @submit.prevent="storeClient">
<div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="fullname" value="Naziv" />
<TextInput
id="fullname"
ref="fullnameInput"
v-model="formClient.full_name"
type="text"
class="mt-1 block w-full"
autocomplete="full-name"
/>
</div>
<CreateDialog
:show="drawerCreateClient"
title="Novi naročnik"
confirm-text="Shrani"
:processing="processing"
@close="drawerCreateClient = false"
@confirm="onConfirmCreate"
>
<form @submit.prevent="onConfirmCreate">
<div class="space-y-4">
<FormField v-slot="{ componentField }" name="full_name">
<FormItem>
<FormLabel>Naziv</FormLabel>
<FormControl>
<Input
id="fullname"
type="text"
autocomplete="full-name"
placeholder="Naziv"
v-bind="componentField"
/>
</FormControl>
<FormMessage />
</FormItem>
</FormField>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="taxnumber" value="Davčna" />
<TextInput
id="taxnumber"
ref="taxnumberInput"
v-model="formClient.tax_number"
type="text"
class="mt-1 block w-full"
autocomplete="tax-number"
/>
</div>
<FormField v-slot="{ componentField }" name="tax_number">
<FormItem>
<FormLabel>Davčna</FormLabel>
<FormControl>
<Input
id="taxnumber"
type="text"
autocomplete="tax-number"
placeholder="Davčna številka"
v-bind="componentField"
/>
</FormControl>
<FormMessage />
</FormItem>
</FormField>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="socialSecurityNumber" value="Matična / Emšo" />
<TextInput
id="socialSecurityNumber"
ref="socialSecurityNumberInput"
v-model="formClient.social_security_number"
type="text"
class="mt-1 block w-full"
autocomplete="social-security-number"
/>
</div>
<FormField v-slot="{ componentField }" name="social_security_number">
<FormItem>
<FormLabel>Matična / Emšo</FormLabel>
<FormControl>
<Input
id="socialSecurityNumber"
type="text"
autocomplete="social-security-number"
placeholder="Matična / Emšo"
v-bind="componentField"
/>
</FormControl>
<FormMessage />
</FormItem>
</FormField>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="address" value="Naslov" />
<TextInput
id="address"
ref="addressInput"
v-model="formClient.address.address"
type="text"
class="mt-1 block w-full"
autocomplete="address"
/>
</div>
<FormField v-slot="{ componentField }" name="address.address">
<FormItem>
<FormLabel>Naslov</FormLabel>
<FormControl>
<Input
id="address"
type="text"
autocomplete="address"
placeholder="Naslov"
v-bind="componentField"
/>
</FormControl>
<FormMessage />
</FormItem>
</FormField>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="addressCountry" value="Država" />
<TextInput
id="addressCountry"
ref="addressCountryInput"
v-model="formClient.address.country"
type="text"
class="mt-1 block w-full"
autocomplete="address-country"
/>
</div>
<FormField v-slot="{ componentField }" name="address.country">
<FormItem>
<FormLabel>Država</FormLabel>
<FormControl>
<Input
id="addressCountry"
type="text"
autocomplete="address-country"
placeholder="Država"
v-bind="componentField"
/>
</FormControl>
<FormMessage />
</FormItem>
</FormField>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="addressType" value="Vrsta naslova" />
<select
class="block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
id="addressType"
v-model="formClient.address.type_id"
>
<option value="1">Stalni</option>
<option value="2">Začasni</option>
<!-- ... -->
</select>
</div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="phoneCountyCode" value="Koda države tel." />
<select
class="block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
id="phoneCountyCode"
v-model="formClient.phone.country_code"
>
<option value="00386">+386 (Slovenija)</option>
<option value="00385">+385 (Hrvaška)</option>
<option value="0039">+39 (Italija)</option>
<option value="0036">+39 (Madžarska)</option>
<option value="0043">+43 (Avstrija)</option>
<option value="00381">+381 (Srbija)</option>
<option value="00387">+387 (Bosna in Hercegovina)</option>
<option value="00382">+382 (Črna gora)</option>
<!-- ... -->
</select>
</div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="phoneNu" value="Telefonska št." />
<TextInput
id="phoneNu"
ref="phoneNuInput"
v-model="formClient.phone.nu"
type="text"
class="mt-1 block w-full"
autocomplete="phone-nu"
/>
</div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="description" value="Opis" />
<TextInput
id="description"
ref="descriptionInput"
v-model="formClient.description"
type="text"
class="mt-1 block w-full"
autocomplete="description"
/>
</div>
</div>
<div class="flex justify-end mt-4">
<ActionMessage :on="formClient.recentlySuccessful" class="me-3">
Shranjeno.
</ActionMessage>
<FormField v-slot="{ value, handleChange }" name="address.type_id">
<FormItem>
<FormLabel>Vrsta naslova</FormLabel>
<Select :model-value="value" @update:model-value="handleChange">
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Izberi vrsto naslova" />
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem :value="1">Stalni</SelectItem>
<SelectItem :value="2">Začasni</SelectItem>
</SelectContent>
</Select>
<FormMessage />
</FormItem>
</FormField>
<PrimaryButton
:class="{ 'opacity-25': formClient.processing }"
:disabled="formClient.processing"
>
Shrani
</PrimaryButton>
<FormField v-slot="{ value, handleChange }" name="phone.country_code">
<FormItem>
<FormLabel>Koda države tel.</FormLabel>
<Select :model-value="value" @update:model-value="handleChange">
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Izberi kodo države" />
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem value="00386">+386 (Slovenija)</SelectItem>
<SelectItem value="00385">+385 (Hrvaška)</SelectItem>
<SelectItem value="0039">+39 (Italija)</SelectItem>
<SelectItem value="0036">+36 (Madžarska)</SelectItem>
<SelectItem value="0043">+43 (Avstrija)</SelectItem>
<SelectItem value="00381">+381 (Srbija)</SelectItem>
<SelectItem value="00387">+387 (Bosna in Hercegovina)</SelectItem>
<SelectItem value="00382">+382 (Črna gora)</SelectItem>
</SelectContent>
</Select>
<FormMessage />
</FormItem>
</FormField>
<FormField v-slot="{ componentField }" name="phone.nu">
<FormItem>
<FormLabel>Telefonska št.</FormLabel>
<FormControl>
<Input
id="phoneNu"
type="text"
autocomplete="phone-nu"
placeholder="Telefonska številka"
v-bind="componentField"
/>
</FormControl>
<FormMessage />
</FormItem>
</FormField>
<FormField v-slot="{ componentField }" name="description">
<FormItem>
<FormLabel>Opis</FormLabel>
<FormControl>
<Input
id="description"
type="text"
autocomplete="description"
placeholder="Opis"
v-bind="componentField"
/>
</FormControl>
<FormMessage />
</FormItem>
</FormField>
</div>
</form>
</template>
</DialogModal>
</CreateDialog>
</template>
@@ -1,11 +1,26 @@
<script setup>
import DialogModal from '@/Components/DialogModal.vue';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import InputLabel from '@/Components/InputLabel.vue';
import TextInput from '@/Components/TextInput.vue';
import { useForm } from '@inertiajs/vue3';
import { ref } from 'vue';
import CreateDialog from '@/Components/Dialogs/CreateDialog.vue';
import { useForm, Field as FormField } from "vee-validate";
import { toTypedSchema } from "@vee-validate/zod";
import * as z from "zod";
import { router } from '@inertiajs/vue3';
import SectionTitle from '@/Components/SectionTitle.vue';
import ActionMessage from '@/Components/ActionMessage.vue';
import {
FormControl,
FormItem,
FormLabel,
FormMessage,
} from "@/Components/ui/form";
import { Input } from "@/Components/ui/input";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/Components/ui/select";
const props = defineProps({
show: {
@@ -18,184 +33,267 @@ const props = defineProps({
const emit = defineEmits(['close']);
const close = () => {
form.resetForm();
emit('close');
}
const Address = {
address: '',
country: '',
type_id: 1
}
const formSchema = toTypedSchema(
z.object({
client_uuid: z.string(),
person: z.object({
first_name: z.string().optional(),
last_name: z.string().optional(),
full_name: z.string().min(1, "Naziv je obvezen."),
tax_number: z.string().optional(),
social_security_number: z.string().optional(),
description: z.string().optional(),
address: z.object({
address: z.string().optional(),
country: z.string().optional(),
type_id: z.number().default(1),
}),
phone: z.object({
nu: z.string().optional(),
country_code: z.string().default('00386'),
type_id: z.number().default(1),
}),
}),
})
);
const Phone = {
nu: '',
country_code: '00386',
type_id: 1
}
const Person = {
first_name: '',
last_name: '',
full_name: '',
tax_number: '',
social_security_number: '',
description: '',
address: Address,
phone: Phone
}
const formCreateCase = useForm({
const form = useForm({
validationSchema: formSchema,
initialValues: {
client_uuid: props.clientUuid,
person: Person
person: {
first_name: '',
last_name: '',
full_name: '',
tax_number: '',
social_security_number: '',
description: '',
address: {
address: '',
country: '',
type_id: 1
},
phone: {
nu: '',
country_code: '00386',
type_id: 1
}
}
},
});
const storeCase = () => {
formCreateCase.post(route('clientCase.store'), {
onSuccess: () => {
close();
formCreateCase.reset();
}
});
const processing = ref(false);
const storeCase = async () => {
processing.value = true;
const { values } = form;
router.post(
route('clientCase.store'),
values,
{
onSuccess: () => {
close();
form.resetForm();
processing.value = false;
},
onError: (errors) => {
Object.keys(errors).forEach((field) => {
const errorMessages = Array.isArray(errors[field])
? errors[field]
: [errors[field]];
// Handle nested field paths like "person.full_name"
const fieldPath = field.includes('.') ? field : field;
form.setFieldError(fieldPath, errorMessages[0]);
});
processing.value = false;
},
onFinish: () => {
processing.value = false;
},
}
);
};
const onConfirm = form.handleSubmit(() => {
storeCase();
});
</script>
<template>
<DialogModal
<CreateDialog
:show="show"
@close="close">
title="Nova primer"
confirm-text="Shrani"
:processing="processing"
@close="close"
@confirm="onConfirm"
>
<form @submit.prevent="onConfirm">
<SectionTitle class="border-b mb-4">
<template #title>
Oseba
</template>
</SectionTitle>
<template #title>Nova primer</template>
<template #content>
<form @submit.prevent="storeCase">
<SectionTitle class="border-b mb-4">
<template #title>
Oseba
</template>
</SectionTitle>
<div class="space-y-4">
<FormField v-slot="{ componentField }" name="person.full_name">
<FormItem>
<FormLabel>Naziv</FormLabel>
<FormControl>
<Input
id="fullname"
type="text"
placeholder="Naziv"
autocomplete="full-name"
v-bind="componentField"
/>
</FormControl>
<FormMessage />
</FormItem>
</FormField>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="fullname" value="Naziv"/>
<TextInput
id="fullname"
ref="fullnameInput"
v-model="formCreateCase.person.full_name"
type="text"
class="mt-1 block w-full"
autocomplete="full-name"
/>
</div>
<FormField v-slot="{ componentField }" name="person.tax_number">
<FormItem>
<FormLabel>Davčna</FormLabel>
<FormControl>
<Input
id="taxnumber"
type="text"
placeholder="Davčna številka"
autocomplete="tax-number"
v-bind="componentField"
/>
</FormControl>
<FormMessage />
</FormItem>
</FormField>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="taxnumber" value="Davčna"/>
<TextInput
id="taxnumber"
ref="taxnumberInput"
v-model="formCreateCase.tax_number"
type="text"
class="mt-1 block w-full"
autocomplete="tax-number"
/>
</div>
<FormField v-slot="{ componentField }" name="person.social_security_number">
<FormItem>
<FormLabel>Matična / Emšo</FormLabel>
<FormControl>
<Input
id="socialSecurityNumber"
type="text"
placeholder="Matična / Emšo"
autocomplete="social-security-number"
v-bind="componentField"
/>
</FormControl>
<FormMessage />
</FormItem>
</FormField>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="socialSecurityNumber" value="Matična / Emšo"/>
<TextInput
id="socialSecurityNumber"
ref="socialSecurityNumberInput"
v-model="formCreateCase.social_security_number"
type="text"
class="mt-1 block w-full"
autocomplete="social-security-number"
/>
</div>
<FormField v-slot="{ componentField }" name="person.address.address">
<FormItem>
<FormLabel>Naslov</FormLabel>
<FormControl>
<Input
id="address"
type="text"
placeholder="Naslov"
autocomplete="street-address"
v-bind="componentField"
/>
</FormControl>
<FormMessage />
</FormItem>
</FormField>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="address" value="Naslov"/>
<TextInput
id="address"
ref="addressInput"
v-model="formCreateCase.person.address.address"
type="text"
class="mt-1 block w-full"
autocomplete="address"
/>
</div>
<FormField v-slot="{ componentField }" name="person.address.country">
<FormItem>
<FormLabel>Država</FormLabel>
<FormControl>
<Input
id="addressCountry"
type="text"
placeholder="Država"
autocomplete="country"
v-bind="componentField"
/>
</FormControl>
<FormMessage />
</FormItem>
</FormField>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="addressCountry" value="Država"/>
<TextInput
id="addressCountry"
ref="addressCountryInput"
v-model="formCreateCase.person.address.country"
type="text"
class="mt-1 block w-full"
autocomplete="address-country"
/>
</div>
<FormField v-slot="{ value, handleChange }" name="person.address.type_id">
<FormItem>
<FormLabel>Vrsta naslova</FormLabel>
<Select :model-value="value" @update:model-value="handleChange">
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Izberi vrsto" />
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem :value="1">Stalni</SelectItem>
<SelectItem :value="2">Začasni</SelectItem>
</SelectContent>
</Select>
<FormMessage />
</FormItem>
</FormField>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="addressType" value="Vrsta naslova"/>
<select
class="block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
id="addressType"
v-model="formCreateCase.person.address.type_id"
>
<option value="1">Stalni</option>
<option value="2">Začasni</option>
<!-- ... -->
</select>
</div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="phoneCountyCode" value="Koda države tel."/>
<select
class="block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
id="phoneCountyCode"
v-model="formCreateCase.person.phone.country_code"
>
<option value="00386">+386 (Slovenija)</option>
<option value="00385">+385 (Hrvaška)</option>
<option value="0039">+39 (Italija)</option>
<option value="0036">+39 (Madžarska)</option>
<option value="0043">+43 (Avstrija)</option>
<option value="00381">+381 (Srbija)</option>
<option value="00387">+387 (Bosna in Hercegovina)</option>
<option value="00382">+382 (Črna gora)</option>
<!-- ... -->
</select>
</div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="phoneNu" value="Telefonska št."/>
<TextInput
id="phoneNu"
ref="phoneNuInput"
v-model="formCreateCase.person.phone.nu"
type="text"
class="mt-1 block w-full"
autocomplete="phone-nu"
/>
</div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="description" value="Opis"/>
<TextInput
id="description"
ref="descriptionInput"
v-model="formCreateCase.description"
type="text"
class="mt-1 block w-full"
autocomplete="description"
/>
</div>
<div class="flex justify-end mt-4">
<ActionMessage :on="formCreateCase.recentlySuccessful" class="me-3">
Shranjeno.
</ActionMessage>
<FormField v-slot="{ value, handleChange }" name="person.phone.country_code">
<FormItem>
<FormLabel>Koda države tel.</FormLabel>
<Select :model-value="value" @update:model-value="handleChange">
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Izberi kodo" />
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem value="00386">+386 (Slovenija)</SelectItem>
<SelectItem value="00385">+385 (Hrvaška)</SelectItem>
<SelectItem value="0039">+39 (Italija)</SelectItem>
<SelectItem value="0036">+36 (Madžarska)</SelectItem>
<SelectItem value="0043">+43 (Avstrija)</SelectItem>
<SelectItem value="00381">+381 (Srbija)</SelectItem>
<SelectItem value="00387">+387 (Bosna in Hercegovina)</SelectItem>
<SelectItem value="00382">+382 (Črna gora)</SelectItem>
</SelectContent>
</Select>
<FormMessage />
</FormItem>
</FormField>
<PrimaryButton :class="{ 'opacity-25': formCreateCase.processing }" :disabled="formCreateCase.processing">
Shrani
</PrimaryButton>
<FormField v-slot="{ componentField }" name="person.phone.nu">
<FormItem>
<FormLabel>Telefonska št.</FormLabel>
<FormControl>
<Input
id="phoneNu"
type="text"
placeholder="Telefonska številka"
autocomplete="tel"
v-bind="componentField"
/>
</FormControl>
<FormMessage />
</FormItem>
</FormField>
<FormField v-slot="{ componentField }" name="person.description">
<FormItem>
<FormLabel>Opis</FormLabel>
<FormControl>
<Input
id="description"
type="text"
placeholder="Opis"
autocomplete="off"
v-bind="componentField"
/>
</FormControl>
<FormMessage />
</FormItem>
</FormField>
</div>
</form>
</template>
</DialogModal>
</template>
</CreateDialog>
</template>
+41 -46
View File
@@ -1,13 +1,16 @@
<script setup>
import AppLayout from "@/Layouts/AppLayout.vue";
import PrimaryButton from "@/Components/PrimaryButton.vue";
import { computed, ref } from "vue";
import { Link, usePage } from "@inertiajs/vue3";
import SectionTitle from "@/Components/SectionTitle.vue";
import PersonInfoGrid from "@/Components/PersonInfoGrid.vue";
import PersonInfoGrid from "@/Components/PersonInfo/PersonInfoGrid.vue";
import FormCreateCase from "./Partials/FormCreateCase.vue";
import DataTableServer from "@/Components/DataTable/DataTableServer.vue";
import DataTable from "@/Components/DataTable/DataTable.vue";
import { hasPermission } from "@/Services/permissions";
import { Button } from "@/Components/ui/button";
import { ButtonGroup } from "@/Components/ui/button-group";
import ActionMenuItem from "@/Components/DataTable/ActionMenuItem.vue";
import { faPlus } from "@fortawesome/free-solid-svg-icons";
const props = defineProps({
client: Object,
@@ -49,36 +52,6 @@ const openDrawerCreateCase = () => {
</template>
</SectionTitle>
</div>
<nav class="mt-2 border-b border-gray-200">
<ul class="flex gap-6 -mb-px">
<li>
<Link
:href="route('client.show', { uuid: client.uuid })"
:class="[
'inline-flex items-center px-3 py-2 text-sm font-medium border-b-2',
route().current('client.show')
? 'text-indigo-600 border-indigo-600'
: 'text-gray-600 border-transparent hover:text-gray-800 hover:border-gray-300',
]"
>
Primeri
</Link>
</li>
<li>
<Link
:href="route('client.contracts', { uuid: client.uuid })"
:class="[
'inline-flex items-center px-3 py-2 text-sm font-medium border-b-2',
route().current('client.contracts')
? 'text-indigo-600 border-indigo-600'
: 'text-gray-600 border-transparent hover:text-gray-800 hover:border-gray-300',
]"
>
Pogodbe
</Link>
</li>
</ul>
</nav>
</div>
</div>
</div>
@@ -103,16 +76,30 @@ const openDrawerCreateCase = () => {
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="px-3 bg-white overflow-hidden shadow-xl sm:rounded-lg">
<div class="mx-auto max-w-4x1 py-3">
<div
class="flex items-center justify-between gap-3"
v-if="hasPerm('case-edit')"
>
<PrimaryButton @click="openDrawerCreateCase" class="bg-blue-400"
>Dodaj</PrimaryButton
>
<div class="mb-4">
<ButtonGroup>
<Button
as-child
:variant="route().current('client.show') ? 'default' : 'ghost'"
>
<Link :href="route('client.show', { uuid: client.uuid })">
Primeri
</Link>
</Button>
<Button
as-child
:variant="route().current('client.contracts') ? 'default' : 'ghost'"
>
<Link :href="route('client.contracts', { uuid: client.uuid })">
Pogodbe
</Link>
</Button>
</ButtonGroup>
</div>
<DataTableServer
class="mt-3"
<DataTable
:show-search="true"
:show-page-size="true"
:show-add="true"
:columns="[
{ key: 'nu', label: 'Št.', sortable: false, class: 'w-40' },
{ key: 'case', label: 'Primer', sortable: false },
@@ -136,6 +123,9 @@ const openDrawerCreateCase = () => {
per_page: client_cases.per_page,
total: client_cases.total,
last_page: client_cases.last_page,
from: client_cases.from,
to: client_cases.to,
links: client_cases.links,
}"
route-name="client.show"
:route-params="{ uuid: client.uuid }"
@@ -143,6 +133,14 @@ const openDrawerCreateCase = () => {
:search="search"
:only-props="['client_cases']"
>
<template #toolbar-add>
<ActionMenuItem
v-if="hasPerm('case-edit')"
label="Dodaj primer"
:icon="faPlus"
@click="openDrawerCreateCase"
/>
</template>
<template #cell-nu="{ row }">
{{ row.person?.nu || "-" }}
</template>
@@ -170,10 +168,7 @@ const openDrawerCreateCase = () => {
}}
</div>
</template>
<template #empty>
<div class="p-6 text-center text-gray-500">Ni zadetkov.</div>
</template>
</DataTableServer>
</DataTable>
</div>
<!-- Pagination handled by DataTableServer -->
</div>