mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-28 04:01:10 -04:00
build version 400
This commit is contained in:
@ -1,262 +1,375 @@
|
||||
<template>
|
||||
<div class="payment-create main-content">
|
||||
<base-page class="relative payment-create">
|
||||
<form action="" @submit.prevent="submitPaymentData">
|
||||
<div class="page-header">
|
||||
<h3 class="page-title">{{ isEdit ? $t('payments.edit_payment') : $t('payments.new_payment') }}</h3>
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><router-link slot="item-title" to="/admin/dashboard">{{ $t('general.home') }}</router-link></li>
|
||||
<li class="breadcrumb-item"><router-link slot="item-title" to="/admin/payments">{{ $tc('payments.payment', 2) }}</router-link></li>
|
||||
<li class="breadcrumb-item">{{ isEdit ? $t('payments.edit_payment') : $t('payments.new_payment') }}</li>
|
||||
</ol>
|
||||
<div class="page-actions header-button-container">
|
||||
<base-button
|
||||
<sw-page-header class="mb-5" :title="pageTitle">
|
||||
<sw-breadcrumb slot="breadcrumbs">
|
||||
<sw-breadcrumb-item
|
||||
to="/admin/dashboard"
|
||||
:title="$t('general.home')"
|
||||
/>
|
||||
<sw-breadcrumb-item
|
||||
to="/admin/payments"
|
||||
:title="$tc('payments.payment', 2)"
|
||||
/>
|
||||
<sw-breadcrumb-item
|
||||
v-if="$route.name === 'payments.edit'"
|
||||
to="#"
|
||||
:title="$t('payments.edit_payment')"
|
||||
active
|
||||
/>
|
||||
<sw-breadcrumb-item
|
||||
v-else
|
||||
to="#"
|
||||
:title="$t('payments.new_payment')"
|
||||
active
|
||||
/>
|
||||
</sw-breadcrumb>
|
||||
|
||||
<template slot="actions">
|
||||
<sw-button
|
||||
:loading="isLoading"
|
||||
:disabled="isLoading"
|
||||
icon="save"
|
||||
color="theme"
|
||||
type="submit">
|
||||
{{ isEdit ? $t('payments.update_payment') : $t('payments.save_payment') }}
|
||||
</base-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="payment-card card">
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="form-label">{{ $t('payments.date') }}</label><span class="text-danger"> *</span>
|
||||
<base-date-picker
|
||||
v-model="formData.payment_date"
|
||||
:invalid="$v.formData.payment_date.$error"
|
||||
:calendar-button="true"
|
||||
calendar-button-icon="calendar"
|
||||
@change="$v.formData.payment_date.$touch()"
|
||||
/>
|
||||
<div v-if="$v.formData.payment_date.$error">
|
||||
<span v-if="!$v.formData.payment_date.required" class="text-danger">{{ $t('validation.required') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="form-label">{{ $t('payments.payment_number') }}</label><span class="text-danger"> *</span>
|
||||
<base-prefix-input
|
||||
:invalid="$v.paymentNumAttribute.$error"
|
||||
v-model.trim="paymentNumAttribute"
|
||||
:prefix="paymentPrefix"
|
||||
@input="$v.paymentNumAttribute.$touch()"
|
||||
/>
|
||||
<div v-if="$v.paymentNumAttribute.$error">
|
||||
<span v-if="!$v.paymentNumAttribute.required" class="text-danger">{{ $tc('validation.required') }}</span>
|
||||
<span v-if="!$v.paymentNumAttribute.numeric" class="text-danger">{{ $tc('validation.numbers_only') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<label class="form-label">{{ $t('payments.customer') }}</label><span class="text-danger"> *</span>
|
||||
<base-select
|
||||
ref="baseSelect"
|
||||
v-model="customer"
|
||||
:invalid="$v.customer.$error"
|
||||
:options="customerList"
|
||||
:searchable="true"
|
||||
:show-labels="false"
|
||||
:allow-empty="false"
|
||||
:disabled="isEdit"
|
||||
:placeholder="$t('customers.select_a_customer')"
|
||||
label="name"
|
||||
track-by="id"
|
||||
variant="primary"
|
||||
type="submit"
|
||||
size="lg"
|
||||
class="hidden sm:flex"
|
||||
>
|
||||
<save-icon v-if="!isLoading" class="mr-2 -ml-1" />
|
||||
{{
|
||||
isEdit
|
||||
? $t('payments.update_payment')
|
||||
: $t('payments.save_payment')
|
||||
}}
|
||||
</sw-button>
|
||||
</template>
|
||||
</sw-page-header>
|
||||
|
||||
<base-loader v-if="isRequestOnGoing" :show-bg-overlay="true" />
|
||||
|
||||
<sw-card v-else>
|
||||
<div class="grid gap-6 grid-col-1 md:grid-cols-2">
|
||||
<sw-input-group
|
||||
:label="$t('payments.date')"
|
||||
:error="DateError"
|
||||
required
|
||||
>
|
||||
<base-date-picker
|
||||
v-model="formData.payment_date"
|
||||
:invalid="$v.formData.payment_date.$error"
|
||||
:calendar-button="true"
|
||||
class="mt-1"
|
||||
calendar-button-icon="calendar"
|
||||
@change="$v.formData.payment_date.$touch()"
|
||||
/>
|
||||
</sw-input-group>
|
||||
|
||||
<sw-input-group
|
||||
:label="$t('payments.payment_number')"
|
||||
:error="paymentNumError"
|
||||
required
|
||||
>
|
||||
<sw-input
|
||||
:prefix="`${paymentPrefix} - `"
|
||||
:invalid="$v.paymentNumAttribute.$error"
|
||||
v-model.trim="paymentNumAttribute"
|
||||
class="mt-1"
|
||||
@input="$v.paymentNumAttribute.$touch()"
|
||||
/>
|
||||
</sw-input-group>
|
||||
|
||||
<sw-input-group
|
||||
:label="$t('payments.customer')"
|
||||
:error="customerError"
|
||||
required
|
||||
>
|
||||
<sw-select
|
||||
v-model="customer"
|
||||
:options="customers"
|
||||
:searchable="true"
|
||||
:show-labels="false"
|
||||
:allow-empty="false"
|
||||
:disabled="isEdit"
|
||||
:placeholder="$t('customers.select_a_customer')"
|
||||
label="name"
|
||||
class="mt-1"
|
||||
track-by="id"
|
||||
/>
|
||||
</sw-input-group>
|
||||
|
||||
<sw-input-group :label="$t('payments.invoice')">
|
||||
<sw-select
|
||||
v-model="invoice"
|
||||
:options="invoiceList"
|
||||
:searchable="true"
|
||||
:show-labels="false"
|
||||
:allow-empty="false"
|
||||
:disabled="isEdit"
|
||||
:placeholder="$t('invoices.select_invoice')"
|
||||
:custom-label="invoiceWithAmount"
|
||||
class="mt-1"
|
||||
track-by="invoice_number"
|
||||
/>
|
||||
</sw-input-group>
|
||||
|
||||
<sw-input-group
|
||||
:label="$t('payments.amount')"
|
||||
:error="amountError"
|
||||
required
|
||||
>
|
||||
<div class="relative w-full mt-1">
|
||||
<sw-money
|
||||
v-model="amount"
|
||||
:currency="customerCurrency"
|
||||
:invalid="$v.formData.amount.$error"
|
||||
class="relative w-full focus:border focus:border-solid focus:border-primary-500"
|
||||
@input="$v.formData.amount.$touch()"
|
||||
/>
|
||||
<div v-if="$v.customer.$error">
|
||||
<span v-if="!$v.customer.required" class="text-danger">{{ $tc('validation.required') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="form-label">{{ $t('payments.invoice') }}</label>
|
||||
<base-select
|
||||
v-model="invoice"
|
||||
:options="invoiceList"
|
||||
:searchable="true"
|
||||
:show-labels="false"
|
||||
:allow-empty="false"
|
||||
:disabled="isEdit"
|
||||
:placeholder="$t('invoices.select_invoice')"
|
||||
:custom-label="invoiceWithAmount"
|
||||
track-by="invoice_number"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="form-label">{{ $t('payments.amount') }}</label><span class="text-danger"> *</span>
|
||||
<div class="base-input">
|
||||
<money
|
||||
:class="{'invalid' : $v.formData.amount.$error}"
|
||||
v-model="amount"
|
||||
v-bind="customerCurrency"
|
||||
class="input-field"
|
||||
/>
|
||||
</div>
|
||||
<div v-if="$v.formData.amount.$error">
|
||||
<span v-if="!$v.formData.amount.required" class="text-danger">{{ $t('validation.required') }}</span>
|
||||
<span v-if="!$v.formData.amount.between && $v.formData.amount.numeric && amount <= 0" class="text-danger">{{ $t('validation.payment_greater_than_zero') }}</span>
|
||||
<span v-if="!$v.formData.amount.between && amount > 0" class="text-danger">{{ $t('validation.payment_greater_than_due_amount') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="form-label">{{ $t('payments.payment_mode') }}</label>
|
||||
<base-select
|
||||
v-model="formData.payment_method"
|
||||
:options="paymentModes"
|
||||
:searchable="true"
|
||||
:show-labels="false"
|
||||
:placeholder="$t('payments.select_payment_mode')"
|
||||
label="name"
|
||||
</sw-input-group>
|
||||
|
||||
<sw-input-group :label="$t('payments.payment_mode')">
|
||||
<sw-select
|
||||
v-model="formData.payment_method"
|
||||
:options="paymentModes"
|
||||
:searchable="true"
|
||||
:show-labels="false"
|
||||
:placeholder="$t('payments.select_payment_mode')"
|
||||
label="name"
|
||||
:maxHeight="150"
|
||||
class="mt-1"
|
||||
>
|
||||
<div slot="afterList">
|
||||
<button
|
||||
type="button"
|
||||
class="flex items-center justify-center w-full px-2 py-2 bg-gray-200 border-none outline-none text-primary-400"
|
||||
@click="addPaymentMode"
|
||||
>
|
||||
<div slot="afterList">
|
||||
<button type="button" class="list-add-button" @click="addPaymentMode">
|
||||
<font-awesome-icon class="icon" icon="cart-plus" />
|
||||
<label>{{ $t('settings.customization.payments.add_payment_mode') }}</label>
|
||||
</button>
|
||||
</div>
|
||||
</base-select>
|
||||
<shopping-cart-icon class="h-5 mr-3 text-primary-400" />
|
||||
<label>{{
|
||||
$t('settings.customization.payments.add_payment_mode')
|
||||
}}</label>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-12 ">
|
||||
<div class="form-group">
|
||||
<label class="form-label">{{ $t('payments.note') }}</label>
|
||||
<base-text-area
|
||||
v-model="formData.notes"
|
||||
@input="$v.formData.notes.$touch()"
|
||||
/>
|
||||
<div v-if="$v.formData.notes.$error">
|
||||
<span v-if="!$v.formData.notes.maxLength" class="text-danger">{{ $t('validation.notes_maxlength') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-12">
|
||||
<div class="form-group collapse-button-container">
|
||||
<base-button
|
||||
:loading="isLoading"
|
||||
icon="save"
|
||||
color="theme"
|
||||
type="submit"
|
||||
class="collapse-button"
|
||||
>
|
||||
{{ $t('payments.save_payment') }}
|
||||
</base-button>
|
||||
</div>
|
||||
</div>
|
||||
</sw-select>
|
||||
</sw-input-group>
|
||||
</div>
|
||||
|
||||
<div v-if="customFields.length > 0">
|
||||
<div class="grid gap-6 mt-6 grid-col-1 md:grid-cols-2">
|
||||
<sw-input-group
|
||||
v-for="(field, index) in customFields"
|
||||
:label="field.label"
|
||||
:required="field.is_required ? true : false"
|
||||
:key="index"
|
||||
>
|
||||
<component
|
||||
:type="field.type.label"
|
||||
:field="field"
|
||||
:isEdit="isEdit"
|
||||
:is="field.type + 'Field'"
|
||||
:invalid-fields="invalidFields"
|
||||
@update="setCustomFieldValue"
|
||||
/>
|
||||
</sw-input-group>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<sw-popup
|
||||
ref="notePopup"
|
||||
class="my-6 text-sm font-semibold leading-5 text-primary-400"
|
||||
>
|
||||
<div slot="activator" class="float-right mt-1">
|
||||
+ {{ $t('general.insert_note') }}
|
||||
</div>
|
||||
<note-select-popup type="Payment" @select="onSelectNote" />
|
||||
</sw-popup>
|
||||
|
||||
<sw-input-group :label="$t('payments.note')" class="mt-6 mb-4">
|
||||
<base-custom-input
|
||||
v-model="formData.notes"
|
||||
:fields="PaymentFields"
|
||||
class="mb-4"
|
||||
/>
|
||||
</sw-input-group>
|
||||
|
||||
<sw-button
|
||||
:disabled="isLoading"
|
||||
:loading="isLoading"
|
||||
variant="primary"
|
||||
type="submit"
|
||||
class="flex w-full mt-4 sm:hidden md:hidden"
|
||||
>
|
||||
<save-icon v-if="!isLoading" class="mr-2 -ml-1" />
|
||||
{{
|
||||
isEdit ? $t('payments.update_payment') : $t('payments.save_payment')
|
||||
}}
|
||||
</sw-button>
|
||||
</sw-card>
|
||||
</form>
|
||||
</div>
|
||||
</base-page>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mapActions, mapGetters } from 'vuex'
|
||||
import MultiSelect from 'vue-multiselect'
|
||||
import { validationMixin } from 'vuelidate'
|
||||
import moment from 'moment'
|
||||
const { required, between, maxLength, numeric } = require('vuelidate/lib/validators')
|
||||
import { ShoppingCartIcon } from '@vue-hero-icons/solid'
|
||||
import CustomFieldsMixin from '../../mixins/customFields'
|
||||
|
||||
const { required, between, numeric } = require('vuelidate/lib/validators')
|
||||
|
||||
export default {
|
||||
components: { MultiSelect },
|
||||
mixins: [validationMixin],
|
||||
data () {
|
||||
mixins: [CustomFieldsMixin],
|
||||
|
||||
components: { ShoppingCartIcon },
|
||||
|
||||
data() {
|
||||
return {
|
||||
formData: {
|
||||
user_id: null,
|
||||
payment_number: null,
|
||||
payment_date: null,
|
||||
amount: 0,
|
||||
payment_date: new Date(),
|
||||
amount: 100,
|
||||
payment_method: null,
|
||||
invoice_id: null,
|
||||
notes: null,
|
||||
payment_method_id: null
|
||||
payment_method_id: null,
|
||||
},
|
||||
money: {
|
||||
decimal: '.',
|
||||
thousands: ',',
|
||||
prefix: '$ ',
|
||||
precision: 2,
|
||||
masked: false
|
||||
masked: false,
|
||||
},
|
||||
customer: null,
|
||||
invoice: null,
|
||||
customerList: [],
|
||||
invoiceList: [],
|
||||
isLoading: false,
|
||||
isRequestOnGoing: false,
|
||||
maxPayableAmount: Number.MAX_SAFE_INTEGER,
|
||||
isSettingInitialData: true,
|
||||
paymentNumAttribute: null,
|
||||
paymentPrefix: ''
|
||||
paymentPrefix: '',
|
||||
PaymentFields: [
|
||||
'customer',
|
||||
'company',
|
||||
'customerCustom',
|
||||
'payment',
|
||||
'paymentCustom',
|
||||
],
|
||||
}
|
||||
},
|
||||
validations () {
|
||||
validations() {
|
||||
return {
|
||||
customer: {
|
||||
required
|
||||
required,
|
||||
},
|
||||
formData: {
|
||||
payment_date: {
|
||||
required
|
||||
required,
|
||||
},
|
||||
amount: {
|
||||
required,
|
||||
between: between(1, this.maxPayableAmount + 1)
|
||||
between: between(1, this.maxPayableAmount + 1),
|
||||
},
|
||||
notes: {
|
||||
maxLength: maxLength(255)
|
||||
}
|
||||
},
|
||||
paymentNumAttribute: {
|
||||
required,
|
||||
numeric
|
||||
}
|
||||
numeric,
|
||||
},
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapGetters('currency', [
|
||||
'defaultCurrencyForInput'
|
||||
]),
|
||||
...mapGetters('payment', [
|
||||
'paymentModes'
|
||||
]),
|
||||
...mapGetters('company', ['defaultCurrencyForInput']),
|
||||
...mapGetters('payment', ['paymentModes', 'selectedNote']),
|
||||
...mapGetters('customer', ['customers']),
|
||||
amount: {
|
||||
get: function () {
|
||||
return this.formData.amount / 100
|
||||
},
|
||||
set: function (newValue) {
|
||||
this.formData.amount = newValue * 100
|
||||
}
|
||||
},
|
||||
},
|
||||
isEdit () {
|
||||
pageTitle() {
|
||||
if (this.$route.name === 'payments.edit') {
|
||||
return this.$t('payments.edit_payment')
|
||||
}
|
||||
return this.$t('payments.new_payment')
|
||||
},
|
||||
isEdit() {
|
||||
if (this.$route.name === 'payments.edit') {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
},
|
||||
customerCurrency () {
|
||||
customerCurrency() {
|
||||
if (this.customer && this.customer.currency) {
|
||||
return {
|
||||
decimal: this.customer.currency.decimal_separator,
|
||||
thousands: this.customer.currency.thousand_separator,
|
||||
prefix: this.customer.currency.symbol + ' ',
|
||||
precision: this.customer.currency.precision,
|
||||
masked: false
|
||||
masked: false,
|
||||
}
|
||||
} else {
|
||||
return this.defaultCurrencyForInput
|
||||
}
|
||||
}
|
||||
},
|
||||
customerError() {
|
||||
if (!this.$v.customer.$error) {
|
||||
return ''
|
||||
}
|
||||
|
||||
if (!this.$v.customer.required) {
|
||||
return this.$tc('validation.required')
|
||||
}
|
||||
},
|
||||
DateError() {
|
||||
if (!this.$v.formData.payment_date.$error) {
|
||||
return ''
|
||||
}
|
||||
if (!this.$v.formData.payment_date.required) {
|
||||
return this.$t('validation.required')
|
||||
}
|
||||
},
|
||||
amountError() {
|
||||
if (!this.$v.formData.amount.$error) {
|
||||
return ''
|
||||
}
|
||||
|
||||
if (!this.$v.formData.amount.required) {
|
||||
return this.$t('validation.required')
|
||||
}
|
||||
|
||||
if (
|
||||
!this.$v.formData.amount.between &&
|
||||
this.$v.formData.amount.numeric &&
|
||||
this.amount <= 0
|
||||
) {
|
||||
return this.$t('validation.payment_greater_than_zero')
|
||||
}
|
||||
|
||||
if (!this.$v.formData.amount.between && this.amount > 0) {
|
||||
return this.$t('validation.payment_greater_than_due_amount')
|
||||
}
|
||||
},
|
||||
paymentNumError() {
|
||||
if (!this.$v.paymentNumAttribute.$error) {
|
||||
return ''
|
||||
}
|
||||
|
||||
if (!this.$v.paymentNumAttribute.required) {
|
||||
return this.$tc('validation.required')
|
||||
}
|
||||
|
||||
if (!this.$v.paymentNumAttribute.numeric) {
|
||||
return this.$tc('validation.numbers_only')
|
||||
}
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
customer (newValue) {
|
||||
customer(newValue) {
|
||||
this.formData.user_id = newValue.id
|
||||
if (!this.isEdit) {
|
||||
if (this.isSettingInitialData) {
|
||||
@ -270,16 +383,23 @@ export default {
|
||||
this.fetchCustomerInvoices(newValue.id)
|
||||
}
|
||||
},
|
||||
invoice (newValue) {
|
||||
selectedNote() {
|
||||
if (this.selectedNote) {
|
||||
this.formData.notes = this.selectedNote
|
||||
}
|
||||
},
|
||||
invoice(newValue) {
|
||||
if (newValue) {
|
||||
this.formData.invoice_id = newValue.id
|
||||
if (!this.isEdit) {
|
||||
this.setPaymentAmountByInvoiceData(newValue.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
async mounted () {
|
||||
async mounted() {
|
||||
this.$v.formData.$reset()
|
||||
this.resetSelectedNote()
|
||||
this.$nextTick(() => {
|
||||
this.loadData()
|
||||
if (this.$route.params.id && !this.isEdit) {
|
||||
@ -288,91 +408,159 @@ export default {
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
...mapActions('invoice', [
|
||||
'fetchInvoice'
|
||||
]),
|
||||
...mapActions('invoice', ['fetchInvoice', 'fetchInvoices']),
|
||||
|
||||
...mapActions('payment', [
|
||||
'fetchCreatePayment',
|
||||
'addPayment',
|
||||
'updatePayment',
|
||||
'fetchEditPaymentData'
|
||||
'fetchPayment',
|
||||
'fetchPaymentModes',
|
||||
'resetSelectedNote',
|
||||
]),
|
||||
...mapActions('modal', [
|
||||
'openModal'
|
||||
]),
|
||||
invoiceWithAmount ({ invoice_number, due_amount }) {
|
||||
return `${invoice_number} (${this.$utils.formatGraphMoney(due_amount, this.customer.currency)})`
|
||||
|
||||
...mapActions('company', ['fetchCompanySettings']),
|
||||
|
||||
...mapActions('modal', ['openModal']),
|
||||
|
||||
...mapActions('customer', ['fetchCustomers']),
|
||||
|
||||
invoiceWithAmount({ invoice_number, due_amount }) {
|
||||
return `${invoice_number} (${this.$utils.formatGraphMoney(
|
||||
due_amount,
|
||||
this.customer.currency
|
||||
)})`
|
||||
},
|
||||
async addPaymentMode () {
|
||||
|
||||
async addPaymentMode() {
|
||||
this.openModal({
|
||||
'title': this.$t('settings.customization.payments.add_payment_mode'),
|
||||
'componentName': 'PaymentMode'
|
||||
title: this.$t('settings.customization.payments.add_payment_mode'),
|
||||
componentName: 'PaymentMode',
|
||||
})
|
||||
},
|
||||
async loadData () {
|
||||
|
||||
async checkAutoGenerate() {
|
||||
let response = await this.fetchCompanySettings(['payment_auto_generate'])
|
||||
|
||||
let response1 = await axios.get('/api/v1/next-number?key=payment')
|
||||
|
||||
if (response.data && response.data.payment_auto_generate === 'YES') {
|
||||
if (response1.data) {
|
||||
this.paymentNumAttribute = response1.data.nextNumber
|
||||
this.paymentPrefix = response1.data.prefix
|
||||
return true
|
||||
}
|
||||
} else {
|
||||
this.paymentPrefix = response1.data.prefix
|
||||
}
|
||||
},
|
||||
|
||||
async loadData() {
|
||||
if (this.isEdit) {
|
||||
let response = await this.fetchEditPaymentData(this.$route.params.id)
|
||||
this.customerList = response.data.customers
|
||||
this.formData = { ...response.data.payment }
|
||||
this.isRequestOnGoing = true
|
||||
let response = await this.fetchPayment(this.$route.params.id)
|
||||
this.formData = { ...this.formData, ...response.data.payment }
|
||||
this.customer = response.data.payment.user
|
||||
this.formData.payment_date = moment(response.data.payment.payment_date, 'YYYY-MM-DD').toString()
|
||||
this.formData.payment_date = moment(
|
||||
response.data.payment.payment_date,
|
||||
'YYYY-MM-DD'
|
||||
).toString()
|
||||
this.formData.amount = parseFloat(response.data.payment.amount)
|
||||
this.paymentPrefix = response.data.payment_prefix
|
||||
this.paymentNumAttribute = response.data.nextPaymentNumber
|
||||
this.formData.payment_method = response.data.payment.payment_method
|
||||
if (response.data.payment.invoice !== null) {
|
||||
this.maxPayableAmount = parseInt(response.data.payment.amount) + parseInt(response.data.payment.invoice.due_amount)
|
||||
this.maxPayableAmount =
|
||||
parseInt(response.data.payment.amount) +
|
||||
parseInt(response.data.payment.invoice.due_amount)
|
||||
this.invoice = response.data.payment.invoice
|
||||
}
|
||||
// this.fetchCustomerInvoices(this.customer.id)
|
||||
let res = await this.fetchCustomFields({
|
||||
type: 'Payment',
|
||||
limit: 'all',
|
||||
})
|
||||
this.setEditCustomFields(
|
||||
response.data.payment.fields,
|
||||
res.data.customFields.data
|
||||
)
|
||||
|
||||
if (this.formData.payment_method_id) {
|
||||
await this.fetchPaymentModes({ limit: 'all' })
|
||||
}
|
||||
|
||||
if (this.formData.user_id) {
|
||||
await this.fetchCustomers({ limit: 'all' })
|
||||
}
|
||||
this.isRequestOnGoing = false
|
||||
} else {
|
||||
let response = await this.fetchCreatePayment()
|
||||
this.customerList = response.data.customers
|
||||
this.paymentNumAttribute = response.data.nextPaymentNumberAttribute
|
||||
this.paymentPrefix = response.data.payment_prefix
|
||||
this.formData.payment_date = moment(new Date()).toString()
|
||||
this.isRequestOnGoing = true
|
||||
this.checkAutoGenerate()
|
||||
this.setInitialCustomFields('Payment')
|
||||
this.formData.payment_date = moment().toString()
|
||||
this.fetchPaymentModes({ limit: 'all' })
|
||||
await this.fetchCustomers({ limit: 'all' })
|
||||
if (this.$route.query.customer) {
|
||||
this.setPaymentCustomer(parseInt(this.$route.query.customer))
|
||||
}
|
||||
this.isRequestOnGoing = false
|
||||
}
|
||||
return true
|
||||
},
|
||||
async setInvoicePaymentData () {
|
||||
setPaymentCustomer(id) {
|
||||
this.customer = this.customers.find((c) => {
|
||||
return c.id === id
|
||||
})
|
||||
},
|
||||
async setInvoicePaymentData() {
|
||||
let data = await this.fetchInvoice(this.$route.params.id)
|
||||
this.customer = data.data.invoice.user
|
||||
this.invoice = data.data.invoice
|
||||
},
|
||||
async setPaymentAmountByInvoiceData (id) {
|
||||
async setPaymentAmountByInvoiceData(id) {
|
||||
let data = await this.fetchInvoice(id)
|
||||
this.formData.amount = data.data.invoice.due_amount
|
||||
this.maxPayableAmount = data.data.invoice.due_amount
|
||||
},
|
||||
async fetchCustomerInvoices (userID) {
|
||||
let response = await axios.get(`/api/invoices/unpaid/${userID}`)
|
||||
if (response.data) {
|
||||
this.invoiceList = response.data.invoices
|
||||
async fetchCustomerInvoices(userId) {
|
||||
let data = {
|
||||
customer_id: userId,
|
||||
status: 'UNPAID',
|
||||
}
|
||||
let response = await this.fetchInvoices(data)
|
||||
this.invoiceList = response.data.invoices.data
|
||||
},
|
||||
async submitPaymentData () {
|
||||
async submitPaymentData() {
|
||||
let validate = await this.touchCustomField()
|
||||
this.$v.customer.$touch()
|
||||
this.$v.formData.$touch()
|
||||
if (this.$v.$invalid) {
|
||||
if (this.$v.$invalid || validate.error) {
|
||||
return true
|
||||
}
|
||||
|
||||
this.formData.payment_number = this.paymentPrefix + '-' + this.paymentNumAttribute
|
||||
this.formData.payment_number =
|
||||
this.paymentPrefix + '-' + this.paymentNumAttribute
|
||||
|
||||
if (this.isEdit) {
|
||||
let data = {
|
||||
editData: {
|
||||
...this.formData,
|
||||
payment_method_id: this.formData.payment_method ? this.formData.payment_method.id : null,
|
||||
payment_date: moment(this.formData.payment_date).format('DD/MM/YYYY')
|
||||
payment_method_id: this.formData.payment_method
|
||||
? this.formData.payment_method.id
|
||||
: null,
|
||||
payment_date: moment(this.formData.payment_date).format(
|
||||
'YYYY-MM-DD'
|
||||
),
|
||||
},
|
||||
id: this.$route.params.id
|
||||
id: this.$route.params.id,
|
||||
}
|
||||
try {
|
||||
this.isLoading = true
|
||||
let response = await this.updatePayment(data)
|
||||
if (response.data.success) {
|
||||
this.isLoading = false
|
||||
this.$router.push(
|
||||
`/admin/payments/${response.data.payment.id}/view`
|
||||
)
|
||||
window.toastr['success'](this.$t('payments.updated_message'))
|
||||
this.$router.push('/admin/payments')
|
||||
return true
|
||||
}
|
||||
if (response.data.error === 'invalid_amount') {
|
||||
@ -391,15 +579,19 @@ export default {
|
||||
} else {
|
||||
let data = {
|
||||
...this.formData,
|
||||
payment_method_id: this.formData.payment_method ? this.formData.payment_method.id : null,
|
||||
payment_date: moment(this.formData.payment_date).format('DD/MM/YYYY')
|
||||
payment_method_id: this.formData.payment_method
|
||||
? this.formData.payment_method.id
|
||||
: null,
|
||||
payment_date: moment(this.formData.payment_date).format('YYYY-MM-DD'),
|
||||
}
|
||||
this.isLoading = true
|
||||
try {
|
||||
let response = await this.addPayment(data)
|
||||
if (response.data.success) {
|
||||
this.$router.push(
|
||||
`/admin/payments/${response.data.payment.id}/view`
|
||||
)
|
||||
window.toastr['success'](this.$t('payments.created_message'))
|
||||
this.$router.push('/admin/payments')
|
||||
this.isLoading = true
|
||||
return true
|
||||
}
|
||||
@ -417,7 +609,11 @@ export default {
|
||||
window.toastr['error'](err.response.data.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
onSelectNote(data) {
|
||||
this.formData.notes = '' + data.notes
|
||||
this.$refs.notePopup.close()
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user