-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathTransactionDetails.vue
More file actions
297 lines (283 loc) · 7.74 KB
/
TransactionDetails.vue
File metadata and controls
297 lines (283 loc) · 7.74 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<template>
<div class="flex flex-col h-full text-base">
<div class="flex items-center justify-between mb-10 -ml-1.5">
<div class="flex items-center space-x-2">
<ChevronLeft
class="size-5 stroke-1.5 text-ink-gray-7 cursor-pointer"
@click="emit('updateStep', 'list')"
/>
<div class="text-xl font-semibold text-ink-gray-9">
{{ __('Transaction Details') }}
</div>
</div>
<div class="space-x-2">
<Button
v-if="
transactionData?.payment_for_document_type &&
transactionData?.payment_for_document
"
@click="openDetails()"
>
{{ __('Open the ') }}
{{
transactionData.payment_for_document_type == 'LMS Course'
? __('Course')
: __('Batch')
}}
</Button>
<Button variant="solid" @click="saveTransaction()">
{{ __('Save') }}
</Button>
</div>
</div>
<div v-if="transactionData" class="overflow-y-auto">
<div class="grid grid-cols-3 gap-5">
<Switch
size="sm"
:label="__('Payment Received')"
:description="__('Mark the payment as received.')"
v-model="transactionData.payment_received"
/>
<Switch
size="sm"
:label="__('Payment For Certificate')"
:description="__('This payment is for a certificate.')"
v-model="transactionData.payment_for_certificate"
/>
<FormControl
:label="__('Member Consent')"
type="checkbox"
v-model="transactionData.member_consent"
:disabled="true"
/>
</div>
<div class="grid grid-cols-3 gap-5 mt-5">
<Link
:label="__('Member')"
doctype="User"
v-model="transactionData.member"
:required="!!fieldMeta.member?.reqd"
/>
<FormControl
:label="__('Billing Name')"
v-model="transactionData.billing_name"
:required="!!fieldMeta.billing_name?.reqd"
/>
<Link
:label="__('Source')"
v-model="transactionData.source"
doctype="LMS Source"
:required="!!fieldMeta.source?.reqd"
/>
<FormControl
type="select"
:options="documentTypeOptions"
:label="__('Payment For Document Type')"
v-model="transactionData.payment_for_document_type"
doctype="DocType"
:required="!!fieldMeta.payment_for_document_type?.reqd"
/>
<Link
v-if="transactionData.payment_for_document_type"
:label="__('Payment For Document')"
v-model="transactionData.payment_for_document"
:doctype="transactionData.payment_for_document_type"
:required="!!fieldMeta.payment_for_document?.reqd"
/>
</div>
<div class="font-semibold mt-10 text-ink-gray-9">
{{ __('Payment Details') }}
</div>
<div class="grid grid-cols-3 gap-5 mt-5">
<Link
:label="__('Currency')"
v-model="transactionData.currency"
doctype="Currency"
:required="!!fieldMeta.currency?.reqd"
/>
<FormControl
:label="__('Amount')"
v-model="transactionData.amount"
:required="!!fieldMeta.amount?.reqd"
/>
<FormControl
v-if="transactionData.amount_with_gst"
:label="__('Amount with GST')"
v-model="transactionData.amount_with_gst"
:required="!!fieldMeta.amount_with_gst?.reqd"
/>
</div>
<div v-if="transactionData.coupon">
<div class="font-semibold mt-10 text-ink-gray-9">
{{ __('Coupon Details') }}
</div>
<div class="grid grid-cols-3 gap-5 mt-5">
<FormControl
v-if="transactionData.coupon"
:label="__('Coupon Code')"
v-model="transactionData.coupon"
:required="!!fieldMeta.coupon?.reqd"
/>
<FormControl
v-if="transactionData.coupon"
:label="__('Coupon Code')"
v-model="transactionData.coupon_code"
:required="!!fieldMeta.coupon_code?.reqd"
/>
<FormControl
v-if="transactionData.coupon"
:label="__('Discount Amount')"
v-model="transactionData.discount_amount"
:required="!!fieldMeta.discount_amount?.reqd"
/>
<FormControl
v-if="transactionData.coupon"
:label="__('Original Amount')"
v-model="transactionData.original_amount"
:required="!!fieldMeta.original_amount?.reqd"
/>
</div>
</div>
<div class="font-semibold mt-10 text-ink-gray-9">
{{ __('Billing Details') }}
</div>
<div class="grid grid-cols-3 gap-5 mt-5">
<Link
:label="__('Address')"
v-model="transactionData.address"
doctype="Address"
:required="!!fieldMeta.address?.reqd"
/>
<FormControl
:label="__('GSTIN')"
v-model="transactionData.gstin"
:required="!!fieldMeta.gstin?.reqd"
/>
<FormControl
:label="__('PAN')"
v-model="transactionData.pan"
:required="!!fieldMeta.pan?.reqd"
/>
<FormControl
:label="__('Payment ID')"
v-model="transactionData.payment_id"
:required="!!fieldMeta.payment_id?.reqd"
/>
<FormControl
:label="__('Order ID')"
v-model="transactionData.order_id"
:required="!!fieldMeta.order_id?.reqd"
/>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { Button, FormControl, Switch, toast } from 'frappe-ui'
import { useRouter } from 'vue-router'
import { computed, ref, watch } from 'vue'
import { ChevronLeft } from 'lucide-vue-next'
import Link from '@/components/Controls/Link.vue'
const router = useRouter()
const transactionData = ref<{ [key: string]: any } | null>(null)
const emit = defineEmits(['updateStep'])
const show = defineModel('show')
const props = defineProps<{
transactions: any
data: any
fieldMeta: Record<
string,
{ reqd?: number; default?: string; description?: string }
>
}>()
const saveTransaction = () => {
if (props.data?.name) {
updateTransaction()
} else {
createTransaction()
}
}
const createTransaction = () => {
console.log(props.transactions)
props.transactions.insert
.submit({
...transactionData.value,
})
.then(() => {
toast.success(__('Transaction created successfully'))
})
.catch((err: any) => {
toast.error(__(err.messages?.[0] || err))
console.error(err)
})
}
const updateTransaction = () => {
props.transactions.setValue
.submit({
...transactionData.value,
})
.then(() => {
toast.success(__('Transaction updated successfully'))
})
.catch((err: any) => {
toast.error(__(err.messages?.[0] || err))
console.error(err)
})
}
const openDetails = () => {
const docType = transactionData.value?.payment_for_document_type
const docName = transactionData.value?.payment_for_document
if (docType && docName) {
router.push({
name: docType == 'LMS Course' ? 'CourseDetail' : 'BatchDetail',
params: {
[docType == 'LMS Course' ? 'courseName' : 'batchName']: docName,
},
})
show.value = false
}
}
const getDefault = (fieldname: string) =>
props.fieldMeta[fieldname]?.default || null
const getEmptyTransactionData = () => ({
payment_received: false,
payment_for_certificate: false,
member: getDefault('member'),
billing_name: getDefault('billing_name'),
source: getDefault('source'),
payment_for_document_type: getDefault('payment_for_document_type'),
payment_for_document: getDefault('payment_for_document'),
member_consent: false,
currency: getDefault('currency'),
amount: getDefault('amount'),
amount_with_gst: getDefault('amount_with_gst'),
coupon: getDefault('coupon'),
coupon_code: getDefault('coupon_code'),
discount_amount: getDefault('discount_amount'),
original_amount: getDefault('original_amount'),
order_id: getDefault('order_id'),
payment_id: getDefault('payment_id'),
gstin: getDefault('gstin'),
pan: getDefault('pan'),
address: getDefault('address'),
})
watch(
() => props.data,
(newVal) => {
transactionData.value = newVal ? { ...newVal } : getEmptyTransactionData()
},
{ immediate: true }
)
const documentTypeOptions = computed(() => {
return [
{
label: __('Course'),
value: 'LMS Course',
},
{
label: __('Batch'),
value: 'LMS Batch',
},
]
})
</script>