forked from frappe/hrms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm.vue
More file actions
116 lines (100 loc) · 2.52 KB
/
Form.vue
File metadata and controls
116 lines (100 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<template>
<ion-page>
<ion-content :fullscreen="true">
<FormView
v-if="formFields.data"
doctype="Employee Advance"
v-model="employeeAdvance"
:isSubmittable="true"
:fields="formFields.data"
:id="props.id"
:showAttachmentView="true"
@validateForm="validateForm"
/>
</ion-content>
</ion-page>
</template>
<script setup>
import { IonPage, IonContent } from "@ionic/vue"
import { createResource } from "frappe-ui"
import { ref, watch, inject } from "vue"
import FormView from "@/components/FormView.vue"
import { updateCurrencyLabels } from "@/composables/useCurrencyConversion"
const employee = inject("$employee")
const props = defineProps({
id: {
type: String,
required: false,
},
})
// object to store form data
const employeeAdvance = ref({
employee: employee.data.name,
employee_name: employee.data.employee_name,
company: employee.data.company,
department: employee.data.department,
})
// get form fields
const formFields = createResource({
url: "hrms.api.get_doctype_fields",
params: { doctype: "Employee Advance" },
transform(data) {
const fields = getFilteredFields(data)
return applyFilters(fields)
},
})
formFields.reload()
// scripts
watch(
() => [formFields.data, employeeAdvance.value.currency],
([fields, currency]) => {
if (!fields || !currency) return
updateCurrencyLabels({
formFields: fields,
doc: employeeAdvance.value,
baseFields: ["base_paid_amount"],
transactionFields: ["paid_amount"],
})
},
{ immediate: true }
)
watch(
() => employeeAdvance.value.currency,
(currency) => {
if (!currency) return
formFields.reload()
}
)
// helper functions
function getFilteredFields(fields) {
// reduce noise from the form view by excluding unnecessary fields
// eg: employee and other details can be fetched from the session user
const excludeFields = ["naming_series"]
const extraFields = [
"employee",
"employee_name",
"department",
"company",
"more_info_section",
"pending_amount",
]
if (!props.id) excludeFields.push(...extraFields)
return fields.filter((field) => !excludeFields.includes(field.fieldname))
}
function applyFilters(fields) {
return fields.map((field) => {
if (field.fieldname === "advance_account") {
if (!employeeAdvance.value.currency) return field
field.linkFilters = {
root_type: "Asset",
is_group: 0,
account_type: "Receivable",
account_currency: ["in", [employeeAdvance.value.currency]],
company: employeeAdvance.value.company,
}
}
return field
})
}
function validateForm() {}
</script>