big update
This commit is contained in:
parent
73d235b7bc
commit
0380dd10d8
18 changed files with 951 additions and 490 deletions
|
|
@ -370,6 +370,9 @@ const company = useCompanyStore();
|
|||
|
||||
const addressQuery = computed(() => route.query.address || "");
|
||||
const nameQuery = computed(() => route.query.name || "");
|
||||
const templateQuery = computed(() => route.query.template || "");
|
||||
const fromMeetingQuery = computed(() => route.query["from-meeting"] || "");
|
||||
const contactQuery = computed(() => route.query.contact || "");
|
||||
const isNew = computed(() => route.query.new === "true");
|
||||
|
||||
const isSubmitting = ref(false);
|
||||
|
|
@ -383,6 +386,7 @@ const formData = reactive({
|
|||
estimateName: null,
|
||||
requiresHalfPayment: false,
|
||||
projectTemplate: null,
|
||||
fromMeeting: null,
|
||||
});
|
||||
|
||||
const selectedAddress = ref(null);
|
||||
|
|
@ -450,6 +454,16 @@ const fetchTemplates = async () => {
|
|||
try {
|
||||
const result = await Api.getEstimateTemplates(company.currentCompany);
|
||||
templates.value = result;
|
||||
|
||||
// Check if template query param exists and set it after templates are loaded
|
||||
const templateParam = route.query.template;
|
||||
if (templateParam) {
|
||||
console.log("DEBUG: Setting template from query param:", templateParam);
|
||||
console.log("DEBUG: Available templates:", templates.value.map(t => t.name));
|
||||
selectedTemplate.value = templateParam;
|
||||
// Trigger template change to load items and project template
|
||||
onTemplateChange();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error fetching templates:", error);
|
||||
notificationStore.addNotification("Failed to fetch templates", "error");
|
||||
|
|
@ -570,7 +584,13 @@ const selectAddress = async (address) => {
|
|||
const primary = contacts.value.find((c) => c.isPrimaryContact);
|
||||
console.log("DEBUG: Selected address contacts:", contacts.value);
|
||||
const existingContactName = estimate.value ? contacts.value.find((c) => c.fullName === estimate.value.partyName)?.name || "" : null;
|
||||
formData.contact = estimate.value ? existingContactName : primary ? primary.name : contacts.value[0]?.name || "";
|
||||
// Check for contact query param, then existing contact, then primary, then first contact
|
||||
if (contactQuery.value) {
|
||||
const contactFromQuery = contacts.value.find((c) => c.name === contactQuery.value);
|
||||
formData.contact = contactFromQuery ? contactFromQuery.name : (primary ? primary.name : contacts.value[0]?.name || "");
|
||||
} else {
|
||||
formData.contact = estimate.value ? existingContactName : primary ? primary.name : contacts.value[0]?.name || "";
|
||||
}
|
||||
showAddressModal.value = false;
|
||||
};
|
||||
|
||||
|
|
@ -651,6 +671,7 @@ const saveDraft = async () => {
|
|||
estimateName: formData.estimateName,
|
||||
requiresHalfPayment: formData.requiresHalfPayment,
|
||||
projectTemplate: formData.projectTemplate,
|
||||
fromMeeting: formData.fromMeeting,
|
||||
company: company.currentCompany
|
||||
};
|
||||
estimate.value = await Api.createEstimate(data);
|
||||
|
|
@ -819,6 +840,8 @@ watch(
|
|||
formData.contact = estimate.value.contactPerson;
|
||||
selectedContact.value = contacts.value.find((c) => c.name === estimate.value.contactPerson) || null;
|
||||
|
||||
formData.projectTemplate = estimate.value.customProjectTemplate || estimate.value.custom_project_template || null;
|
||||
|
||||
if (estimate.value.items && estimate.value.items.length > 0) {
|
||||
selectedItems.value = estimate.value.items.map(item => {
|
||||
const fullItem = quotationItems.value.find(qi => qi.itemCode === item.itemCode);
|
||||
|
|
@ -857,10 +880,15 @@ onMounted(async () => {
|
|||
} catch (error) {
|
||||
console.error("Error loading quotation items:", error);
|
||||
}
|
||||
fetchProjectTemplates();
|
||||
await fetchProjectTemplates();
|
||||
|
||||
if (isNew.value) {
|
||||
fetchTemplates();
|
||||
await fetchTemplates();
|
||||
|
||||
// Handle from-meeting query parameter
|
||||
if (fromMeetingQuery.value) {
|
||||
formData.fromMeeting = fromMeetingQuery.value;
|
||||
}
|
||||
}
|
||||
|
||||
if (addressQuery.value && isNew.value) {
|
||||
|
|
@ -891,6 +919,8 @@ onMounted(async () => {
|
|||
formData.contact = estimate.value.contactPerson;
|
||||
selectedContact.value = contacts.value.find((c) => c.name === estimate.value.contactPerson) || null;
|
||||
|
||||
formData.projectTemplate = estimate.value.customProjectTemplate || estimate.value.custom_project_template || null;
|
||||
|
||||
// Populate items from the estimate
|
||||
if (estimate.value.items && estimate.value.items.length > 0) {
|
||||
selectedItems.value = estimate.value.items.map(item => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue