Changes
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
||||
SelectValue,
|
||||
} from "@/Components/ui/select";
|
||||
import { Switch } from "@/Components/ui/switch";
|
||||
import AppMultiSelect from "@/Components/app/ui/AppMultiSelect.vue";
|
||||
import { ref, watch, computed } from "vue";
|
||||
|
||||
const props = defineProps({
|
||||
@@ -53,7 +54,7 @@ const form = useInertiaForm({
|
||||
props.actions[0].decisions.length > 0
|
||||
? props.actions[0].decisions[0].id
|
||||
: null,
|
||||
contract_uuid: props.contractUuid,
|
||||
contract_uuids: props.contractUuid ? [props.contractUuid] : [],
|
||||
send_auto_mail: true,
|
||||
attach_documents: false,
|
||||
attachment_document_ids: [],
|
||||
@@ -95,7 +96,7 @@ watch(
|
||||
watch(
|
||||
() => props.contractUuid,
|
||||
(cu) => {
|
||||
form.contract_uuid = cu || null;
|
||||
form.contract_uuids = cu ? [cu] : [];
|
||||
}
|
||||
);
|
||||
|
||||
@@ -103,7 +104,7 @@ watch(
|
||||
() => props.show,
|
||||
(visible) => {
|
||||
if (visible) {
|
||||
form.contract_uuid = props.contractUuid || null;
|
||||
form.contract_uuids = props.contractUuid ? [props.contractUuid] : [];
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -119,20 +120,28 @@ const store = async () => {
|
||||
return `${y}-${m}-${day}`;
|
||||
};
|
||||
|
||||
const contractUuids = Array.isArray(form.contract_uuids) && form.contract_uuids.length > 0
|
||||
? form.contract_uuids
|
||||
: null;
|
||||
|
||||
const isMultipleContracts = contractUuids && contractUuids.length > 1;
|
||||
|
||||
form
|
||||
.transform((data) => ({
|
||||
...data,
|
||||
phone_view: props.phoneMode,
|
||||
due_date: formatDateForSubmit(data.due_date),
|
||||
contract_uuids: contractUuids,
|
||||
create_for_all_contracts: isMultipleContracts,
|
||||
attachment_document_ids:
|
||||
templateAllowsAttachments.value && data.attach_documents
|
||||
templateAllowsAttachments.value && data.attach_documents && !isMultipleContracts
|
||||
? data.attachment_document_ids
|
||||
: [],
|
||||
}))
|
||||
.post(route("clientCase.activity.store", props.client_case), {
|
||||
onSuccess: () => {
|
||||
close();
|
||||
form.reset("due_date", "amount", "note");
|
||||
form.reset("due_date", "amount", "note", "contract_uuids");
|
||||
emit("saved");
|
||||
},
|
||||
});
|
||||
@@ -165,13 +174,39 @@ const autoMailRequiresContract = computed(() => {
|
||||
return types.includes("contract");
|
||||
});
|
||||
|
||||
const autoMailDisabled = computed(() => {
|
||||
return showSendAutoMail() && autoMailRequiresContract.value && !form.contract_uuid;
|
||||
const contractItems = computed(() => {
|
||||
return pageContracts.value.map(c => ({
|
||||
value: c.uuid,
|
||||
label: `${c.reference}${c.name ? ` - ${c.name}` : ''}`
|
||||
}));
|
||||
});
|
||||
|
||||
const autoMailDisabled = computed(() => {
|
||||
if (!showSendAutoMail()) return false;
|
||||
|
||||
// Disable if multiple contracts selected
|
||||
if (form.contract_uuids && form.contract_uuids.length > 1) return true;
|
||||
|
||||
// Disable if template requires contract but none selected
|
||||
if (autoMailRequiresContract.value && (!form.contract_uuids || form.contract_uuids.length === 0)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
const autoMailDisabledHint = computed(() => {
|
||||
return autoMailDisabled.value
|
||||
? "Ta e-poštna predloga zahteva pogodbo. Najprej izberite pogodbo."
|
||||
: "";
|
||||
if (!showSendAutoMail()) return "";
|
||||
|
||||
if (form.contract_uuids && form.contract_uuids.length > 1) {
|
||||
return "Avtomatska e-pošta ni na voljo pri več pogodbah.";
|
||||
}
|
||||
|
||||
if (autoMailRequiresContract.value && (!form.contract_uuids || form.contract_uuids.length === 0)) {
|
||||
return "Ta e-poštna predloga zahteva pogodbo. Najprej izberite pogodbo.";
|
||||
}
|
||||
|
||||
return "";
|
||||
});
|
||||
watch(
|
||||
() => autoMailDisabled.value,
|
||||
@@ -231,9 +266,12 @@ const docsSource = computed(() => {
|
||||
});
|
||||
|
||||
const availableContractDocs = computed(() => {
|
||||
if (!form.contract_uuid) return [];
|
||||
if (!form.contract_uuids || form.contract_uuids.length === 0) return [];
|
||||
// Only show docs if exactly one contract is selected
|
||||
if (form.contract_uuids.length > 1) return [];
|
||||
const selectedUuid = form.contract_uuids[0];
|
||||
const docs = docsSource.value;
|
||||
const all = docs.filter((d) => d.contract_uuid === form.contract_uuid);
|
||||
const all = docs.filter((d) => d.contract_uuid === selectedUuid);
|
||||
if (!props.phoneMode) return all;
|
||||
return all.filter((d) => {
|
||||
const mime = (d.mime_type || "").toLowerCase();
|
||||
@@ -264,14 +302,14 @@ watch(
|
||||
[
|
||||
() => props.phoneMode,
|
||||
() => templateAllowsAttachments.value,
|
||||
() => form.contract_uuid,
|
||||
() => form.contract_uuids,
|
||||
() => form.decision_id,
|
||||
() => availableContractDocs.value.length,
|
||||
],
|
||||
() => {
|
||||
if (!props.phoneMode) return;
|
||||
if (!templateAllowsAttachments.value) return;
|
||||
if (!form.contract_uuid) return;
|
||||
if (!form.contract_uuids || form.contract_uuids.length !== 1) return;
|
||||
const docs = availableContractDocs.value;
|
||||
if (docs.length === 0) return;
|
||||
form.attach_documents = true;
|
||||
@@ -324,6 +362,22 @@ watch(
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2">
|
||||
<Label>Pogodbe</Label>
|
||||
<AppMultiSelect
|
||||
v-model="form.contract_uuids"
|
||||
:items="contractItems"
|
||||
placeholder="Izberi pogodbe (neobvezno)"
|
||||
search-placeholder="Išči pogodbo..."
|
||||
empty-text="Ni pogodb."
|
||||
:clearable="true"
|
||||
:show-selected-chips="true"
|
||||
/>
|
||||
<p v-if="form.contract_uuids && form.contract_uuids.length > 1" class="text-xs text-muted-foreground">
|
||||
Bo ustvarjenih {{ form.contract_uuids.length }} aktivnosti (ena za vsako pogodbo).
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2">
|
||||
<Label for="activityNote">Opomba</Label>
|
||||
<Textarea
|
||||
@@ -369,7 +423,7 @@ watch(
|
||||
{{ autoMailDisabledHint }}
|
||||
</p>
|
||||
|
||||
<div v-if="templateAllowsAttachments && form.contract_uuid" class="mt-3">
|
||||
<div v-if="templateAllowsAttachments && form.contract_uuids && form.contract_uuids.length === 1" class="mt-3">
|
||||
<label class="inline-flex items-center gap-2">
|
||||
<Switch v-model="form.attach_documents" />
|
||||
<span class="text-sm">Dodaj priponke iz izbrane pogodbe</span>
|
||||
@@ -383,7 +437,7 @@ watch(
|
||||
</div>
|
||||
<div class="space-y-1">
|
||||
<template v-for="c in pageContracts" :key="c.uuid || c.id">
|
||||
<div v-if="c.uuid === form.contract_uuid">
|
||||
<div v-if="c.uuid === form.contract_uuids[0]">
|
||||
<div class="font-medium text-sm text-gray-700 mb-1">
|
||||
Pogodba {{ c.reference }}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user