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,307 +1,437 @@
|
||||
<template>
|
||||
<div class="main-content expenses">
|
||||
<base-page class="relative">
|
||||
<form action="" @submit.prevent="sendData">
|
||||
<div class="page-header">
|
||||
<h3 class="page-title">{{ isEdit ? $t('expenses.edit_expense') : $t('expenses.new_expense') }}</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/expenses">{{ $tc('expenses.expense', 2) }}</router-link></li>
|
||||
<li class="breadcrumb-item"><a href="#">{{ isEdit ? $t('expenses.edit_expense') : $t('expenses.new_expense') }}</a></li>
|
||||
</ol>
|
||||
<div class="page-actions row header-button-container">
|
||||
<div v-if="isReceiptAvailable" class="col-xs-2 mr-4">
|
||||
<a :href="getReceiptUrl">
|
||||
<base-button
|
||||
:loading="isLoading"
|
||||
icon="download"
|
||||
color="theme"
|
||||
outline
|
||||
>
|
||||
{{ $t('expenses.download_receipt') }}
|
||||
</base-button>
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-xs-2">
|
||||
<base-button
|
||||
<!-- Page Header -->
|
||||
<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/expenses"
|
||||
:title="$tc('expenses.expense', 2)"
|
||||
/>
|
||||
|
||||
<sw-breadcrumb-item
|
||||
v-if="$route.name === 'expenses.edit'"
|
||||
to="#"
|
||||
:title="$t('expenses.edit_expense')"
|
||||
active
|
||||
/>
|
||||
|
||||
<sw-breadcrumb-item
|
||||
v-else
|
||||
to="#"
|
||||
:title="$t('expenses.new_expense')"
|
||||
active
|
||||
/>
|
||||
</sw-breadcrumb>
|
||||
|
||||
<template slot="actions">
|
||||
<sw-button
|
||||
v-if="isReceiptAvailable"
|
||||
tag-name="a"
|
||||
:href="getReceiptUrl"
|
||||
variant="primary"
|
||||
outline
|
||||
size="lg"
|
||||
class="mr-2"
|
||||
>
|
||||
<download-icon class="h-5 mr-2 -ml-1" />
|
||||
{{ $t('expenses.download_receipt') }}
|
||||
</sw-button>
|
||||
|
||||
<div class="hidden md:block">
|
||||
<sw-button
|
||||
:loading="isLoading"
|
||||
icon="save"
|
||||
color="theme"
|
||||
:disabled="isLoading"
|
||||
variant="primary"
|
||||
type="submit"
|
||||
size="lg"
|
||||
>
|
||||
{{ isEdit ? $t('expenses.update_expense') : $t('expenses.save_expense') }}
|
||||
</base-button>
|
||||
<save-icon v-if="!isLoading" class="mr-2 -ml-1" />
|
||||
{{
|
||||
isEdit
|
||||
? $t('expenses.update_expense')
|
||||
: $t('expenses.save_expense')
|
||||
}}
|
||||
</sw-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<!-- <div class="form-group col-sm-6">
|
||||
<label class="control-label">{{ $t('expenses.expense_title') }}</label>
|
||||
<input v-model="formData.title" type="text" name="name" class="form-control">
|
||||
</div> -->
|
||||
<div class="form-group col-sm-6">
|
||||
<label class="control-label">{{ $t('expenses.category') }}</label><span class="text-danger"> * </span>
|
||||
<base-select
|
||||
ref="baseSelect"
|
||||
v-model="category"
|
||||
:options="categories"
|
||||
:invalid="$v.category.$error"
|
||||
:searchable="true"
|
||||
:show-labels="false"
|
||||
:placeholder="$t('expenses.categories.select_a_category')"
|
||||
label="name"
|
||||
track-by="id"
|
||||
@input="$v.category.$touch()"
|
||||
</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('expenses.category')"
|
||||
:error="categoryError"
|
||||
required
|
||||
>
|
||||
<sw-select
|
||||
ref="baseSelect"
|
||||
v-model="category"
|
||||
:options="categories"
|
||||
:invalid="$v.category.$error"
|
||||
:searchable="true"
|
||||
:show-labels="false"
|
||||
:placeholder="$t('expenses.categories.select_a_category')"
|
||||
class="mt-2"
|
||||
label="name"
|
||||
track-by="id"
|
||||
@input="$v.category.$touch()"
|
||||
>
|
||||
<sw-button
|
||||
slot="afterList"
|
||||
type="button"
|
||||
variant="gray-light"
|
||||
class="flex items-center justify-center w-full px-4 py-3 bg-gray-200 border-none outline-none"
|
||||
@click="openCategoryModal"
|
||||
>
|
||||
<shopping-cart-icon class="h-5 text-center text-primary-400" />
|
||||
<label class="ml-2 text-xs leading-none text-primary-400">{{
|
||||
$t('settings.expense_category.add_new_category')
|
||||
}}</label>
|
||||
</sw-button>
|
||||
</sw-select>
|
||||
</sw-input-group>
|
||||
|
||||
<sw-input-group
|
||||
:label="$t('expenses.expense_date')"
|
||||
:error="dateError"
|
||||
required
|
||||
>
|
||||
<base-date-picker
|
||||
v-model="formData.expense_date"
|
||||
:invalid="$v.formData.expense_date.$error"
|
||||
:calendar-button="true"
|
||||
class="mt-2"
|
||||
calendar-button-icon="calendar"
|
||||
@change="$v.formData.expense_date.$touch()"
|
||||
/>
|
||||
</sw-input-group>
|
||||
|
||||
<sw-input-group
|
||||
:label="$t('expenses.amount')"
|
||||
:error="amountError"
|
||||
required
|
||||
>
|
||||
<sw-money
|
||||
v-model="amount"
|
||||
:currency="defaultCurrencyForInput"
|
||||
class="focus:border focus:border-solid focus:border-primary-500"
|
||||
:invalid="$v.formData.amount.$error"
|
||||
@input="$v.formData.amount.$touch()"
|
||||
/>
|
||||
</sw-input-group>
|
||||
|
||||
<sw-input-group :label="$t('expenses.customer')">
|
||||
<sw-select
|
||||
ref="baseSelect"
|
||||
v-model="customer"
|
||||
:options="customers"
|
||||
:searchable="true"
|
||||
:show-labels="false"
|
||||
:placeholder="$t('customers.select_a_customer')"
|
||||
class="mt-1"
|
||||
label="name"
|
||||
track-by="id"
|
||||
/>
|
||||
</sw-input-group>
|
||||
|
||||
<sw-input-group :label="$t('expenses.note')" :error="notesError">
|
||||
<sw-textarea
|
||||
v-model="formData.notes"
|
||||
rows="4"
|
||||
@input="$v.formData.notes.$touch()"
|
||||
/>
|
||||
</sw-input-group>
|
||||
|
||||
<sw-input-group :label="$t('expenses.receipt')">
|
||||
<div
|
||||
id="receipt-box"
|
||||
class="relative flex items-center justify-center h-24 p-6 bg-transparent border-2 border-gray-200 border-dashed rounded-md image-upload-box"
|
||||
>
|
||||
<img
|
||||
v-if="previewReceipt"
|
||||
:src="previewReceipt"
|
||||
class="absolute opacity-100 preview-logo"
|
||||
style="max-height: 80%; animation: fadeIn 2s ease"
|
||||
/>
|
||||
<div v-else class="flex flex-col items-center">
|
||||
<cloud-upload-icon
|
||||
class="h-5 mb-2 text-xl leading-6 text-gray-400"
|
||||
/>
|
||||
<p class="text-xs leading-4 text-center text-gray-400">
|
||||
Drag a file here or
|
||||
<span id="pick-avatar" class="cursor-pointer text-primary-500"
|
||||
>browse</span
|
||||
>
|
||||
<div slot="afterList">
|
||||
<button type="button" class="list-add-button" @click="openCategoryModal">
|
||||
<font-awesome-icon class="icon" icon="cart-plus" />
|
||||
<label>{{ $t('settings.expense_category.add_new_category') }}</label>
|
||||
</button>
|
||||
</div>
|
||||
</base-select>
|
||||
<div v-if="$v.category.$error">
|
||||
<span v-if="!$v.category.required" class="text-danger">{{ $t('validation.required') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- <div class="form-group col-sm-6">
|
||||
<label>{{ $t('expenses.contact') }}</label>
|
||||
<select v-model="formData.contact" name="contact" class="form-control ls-select2">
|
||||
<option v-for="(contact, index) in contacts" :key="index" :value="contact.id"> {{ contact.name }}</option>
|
||||
</select>
|
||||
</div> -->
|
||||
<div class="form-group col-sm-6">
|
||||
<label>{{ $t('expenses.expense_date') }}</label><span class="text-danger"> * </span>
|
||||
<base-date-picker
|
||||
v-model="formData.expense_date"
|
||||
:invalid="$v.formData.expense_date.$error"
|
||||
:calendar-button="true"
|
||||
calendar-button-icon="calendar"
|
||||
@change="$v.formData.expense_date.$touch()"
|
||||
/>
|
||||
<div v-if="$v.formData.expense_date.$error">
|
||||
<span v-if="!$v.formData.expense_date.required" class="text-danger">{{ $t('validation.required') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-sm-6">
|
||||
<label>{{ $t('expenses.amount') }}</label> <span class="text-danger"> * </span>
|
||||
<div class="base-input">
|
||||
<money
|
||||
:class="{'invalid' : $v.formData.amount.$error}"
|
||||
v-model="amount"
|
||||
v-bind="defaultCurrencyForInput"
|
||||
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.maxLength" class="text-danger">{{ $t('validation.price_maxlength') }}</span>
|
||||
<span v-if="!$v.formData.amount.minValue" class="text-danger">{{ $t('validation.price_minvalue') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-sm-6">
|
||||
<label class="form-label">{{ $t('expenses.customer') }}</label>
|
||||
<base-select
|
||||
ref="baseSelect"
|
||||
v-model="customer"
|
||||
:options="customerList"
|
||||
:searchable="true"
|
||||
:show-labels="false"
|
||||
:placeholder="$t('customers.select_a_customer')"
|
||||
label="name"
|
||||
track-by="id"
|
||||
/>
|
||||
</div>
|
||||
<div class="form-group col-sm-6">
|
||||
<label for="description">{{ $t('expenses.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 class="form-group col-md-6">
|
||||
<label for="description">{{ $t('expenses.receipt') }} : </label>
|
||||
<div class="image-upload-box" @click="$refs.file.click()">
|
||||
<input ref="file" class="d-none" type="file" @change="onFileChange">
|
||||
<img v-if="previewReceipt" :src="previewReceipt" class="preview-logo">
|
||||
<div v-else class="upload-content">
|
||||
<font-awesome-icon class="upload-icon" icon="cloud-upload-alt"/>
|
||||
<p class="upload-text"> {{ $t('general.choose_file') }} </p>
|
||||
</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"
|
||||
>
|
||||
{{ isEdit ? $t('expenses.update_expense') : $t('expenses.save_expense') }}
|
||||
</base-button>
|
||||
</div>
|
||||
</div>
|
||||
to choose a file
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<sw-avatar
|
||||
trigger="#receipt-box"
|
||||
:preview-avatar="previewReceipt"
|
||||
:enable-cropper="false"
|
||||
@changed="onChange"
|
||||
>
|
||||
<template v-slot:icon>
|
||||
<cloud-upload-icon
|
||||
class="h-5 mb-2 text-xl leading-6 text-gray-400"
|
||||
/>
|
||||
</template>
|
||||
</sw-avatar>
|
||||
</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>
|
||||
|
||||
<div class="block mt-2 md:hidden">
|
||||
<sw-button
|
||||
:disabled="isLoading"
|
||||
:loading="isLoading"
|
||||
:tabindex="6"
|
||||
variant="primary"
|
||||
type="submit"
|
||||
size="lg"
|
||||
class="flex w-full"
|
||||
>
|
||||
<save-icon v-if="!isLoading" class="mr-2 -ml-1" />
|
||||
{{
|
||||
isEdit
|
||||
? $t('expenses.update_expense')
|
||||
: $t('expenses.save_expense')
|
||||
}}
|
||||
</sw-button>
|
||||
</div>
|
||||
</sw-card>
|
||||
</form>
|
||||
</div>
|
||||
</base-page>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import MultiSelect from 'vue-multiselect'
|
||||
import moment from 'moment'
|
||||
import { mapActions, mapGetters } from 'vuex'
|
||||
import { validationMixin } from 'vuelidate'
|
||||
const { required, minValue, maxLength } = require('vuelidate/lib/validators')
|
||||
import { DownloadIcon } from '@vue-hero-icons/outline'
|
||||
import { CloudUploadIcon, ShoppingCartIcon } from '@vue-hero-icons/solid'
|
||||
import CustomFieldsMixin from '../../mixins/customFields'
|
||||
|
||||
export default {
|
||||
mixins: [CustomFieldsMixin],
|
||||
|
||||
components: {
|
||||
MultiSelect
|
||||
CloudUploadIcon,
|
||||
ShoppingCartIcon,
|
||||
DownloadIcon,
|
||||
},
|
||||
mixins: [validationMixin],
|
||||
|
||||
props: {
|
||||
addname: {
|
||||
type: String,
|
||||
default: ''
|
||||
}
|
||||
default: '',
|
||||
},
|
||||
},
|
||||
data () {
|
||||
|
||||
data() {
|
||||
return {
|
||||
formData: {
|
||||
expense_category_id: null,
|
||||
expense_date: new Date(),
|
||||
amount: null,
|
||||
amount: 100,
|
||||
notes: '',
|
||||
user_id: null
|
||||
user_id: null,
|
||||
},
|
||||
|
||||
money: {
|
||||
decimal: '.',
|
||||
thousands: ',',
|
||||
prefix: '$ ',
|
||||
precision: 2,
|
||||
masked: false
|
||||
masked: false,
|
||||
},
|
||||
isRequestOnGoing: false,
|
||||
isReceiptAvailable: false,
|
||||
isLoading: false,
|
||||
file: null,
|
||||
category: null,
|
||||
passData: [],
|
||||
contacts: [],
|
||||
previewReceipt: null,
|
||||
fileSendUrl: '/api/expenses',
|
||||
fileSendUrl: '/api/v1/expenses',
|
||||
customer: null,
|
||||
customerList: []
|
||||
fileObject: null,
|
||||
}
|
||||
},
|
||||
|
||||
validations: {
|
||||
category: {
|
||||
required
|
||||
required,
|
||||
},
|
||||
|
||||
formData: {
|
||||
expense_date: {
|
||||
required
|
||||
required,
|
||||
},
|
||||
|
||||
amount: {
|
||||
required,
|
||||
minValue: minValue(0.1),
|
||||
maxLength: maxLength(20)
|
||||
maxLength: maxLength(20),
|
||||
},
|
||||
|
||||
notes: {
|
||||
maxLength: maxLength(255)
|
||||
}
|
||||
}
|
||||
maxLength: maxLength(255),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
computed: {
|
||||
...mapGetters('currency', [
|
||||
'defaultCurrencyForInput'
|
||||
]),
|
||||
...mapGetters('company', ['defaultCurrencyForInput']),
|
||||
|
||||
amount: {
|
||||
get: function () {
|
||||
return this.formData.amount / 100
|
||||
},
|
||||
set: function (newValue) {
|
||||
this.formData.amount = newValue * 100
|
||||
}
|
||||
},
|
||||
},
|
||||
isEdit () {
|
||||
|
||||
pageTitle() {
|
||||
if (this.$route.name === 'expenses.edit') {
|
||||
return this.$t('expenses.edit_expense')
|
||||
}
|
||||
return this.$t('expenses.new_expense')
|
||||
},
|
||||
|
||||
isEdit() {
|
||||
if (this.$route.name === 'expenses.edit') {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
},
|
||||
...mapGetters('category', [
|
||||
'categories'
|
||||
]),
|
||||
...mapGetters('company', [
|
||||
'getSelectedCompany'
|
||||
]),
|
||||
getReceiptUrl () {
|
||||
|
||||
...mapGetters('category', ['categories']),
|
||||
|
||||
...mapGetters('customer', ['customers']),
|
||||
|
||||
...mapGetters('company', ['getSelectedCompany']),
|
||||
|
||||
getReceiptUrl() {
|
||||
if (this.isEdit) {
|
||||
return `/expenses/${this.$route.params.id}/receipt/${this.getSelectedCompany.unique_hash}`
|
||||
return `/expenses/${this.$route.params.id}/receipt`
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
categoryError() {
|
||||
if (!this.$v.category.$error) {
|
||||
return ''
|
||||
}
|
||||
if (!this.$v.category.required) {
|
||||
return this.$t('validation.required')
|
||||
}
|
||||
},
|
||||
|
||||
dateError() {
|
||||
if (!this.$v.formData.expense_date.$error) {
|
||||
return ''
|
||||
}
|
||||
if (!this.$v.formData.expense_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.maxLength) {
|
||||
return this.$t('validation.price_maxlength')
|
||||
}
|
||||
if (!this.$v.formData.amount.minValue) {
|
||||
return this.$t('validation.price_minvalue')
|
||||
}
|
||||
},
|
||||
|
||||
notesError() {
|
||||
if (!this.$v.formData.notes.$error) {
|
||||
return ''
|
||||
}
|
||||
if (!this.$v.formData.notes.maxLength) {
|
||||
return this.$t('validation.notes_maxlength')
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
watch: {
|
||||
category (newValue) {
|
||||
category(newValue) {
|
||||
this.formData.expense_category_id = newValue.id
|
||||
}
|
||||
},
|
||||
},
|
||||
mounted () {
|
||||
// this.$refs.baseSelect.$refs.search.focus()
|
||||
this.fetchInitialData()
|
||||
if (this.isEdit) {
|
||||
this.getReceipt()
|
||||
}
|
||||
|
||||
mounted() {
|
||||
this.$v.formData.$reset()
|
||||
|
||||
this.loadData()
|
||||
|
||||
window.hub.$on('newCategory', (val) => {
|
||||
this.category = val
|
||||
})
|
||||
},
|
||||
|
||||
methods: {
|
||||
...mapActions('expense', [
|
||||
'fetchCreateExpense',
|
||||
'getFile',
|
||||
'sendFileWithData',
|
||||
'getExpenseReceipt',
|
||||
'addExpense',
|
||||
'updateExpense',
|
||||
'fetchExpense'
|
||||
'fetchExpense',
|
||||
]),
|
||||
...mapActions('modal', [
|
||||
'openModal'
|
||||
]),
|
||||
...mapActions('category', [
|
||||
'fetchCategories'
|
||||
]),
|
||||
openCategoryModal () {
|
||||
|
||||
...mapActions('modal', ['openModal']),
|
||||
|
||||
...mapActions('category', ['fetchCategories']),
|
||||
|
||||
...mapActions('customer', ['fetchCustomers']),
|
||||
|
||||
openCategoryModal() {
|
||||
this.openModal({
|
||||
'title': 'Add Category',
|
||||
'componentName': 'CategoryModal'
|
||||
title: this.$t('settings.expense_category.add_category'),
|
||||
componentName: 'CategoryModal',
|
||||
})
|
||||
// this.$refs.table.refresh()
|
||||
},
|
||||
onFileChange (e) {
|
||||
var input = event.target
|
||||
this.file = input.files[0]
|
||||
if (input.files && input.files[0]) {
|
||||
var reader = new FileReader()
|
||||
reader.onload = (e) => {
|
||||
this.previewReceipt = e.target.result
|
||||
}
|
||||
reader.readAsDataURL(input.files[0])
|
||||
}
|
||||
|
||||
onChange(data) {
|
||||
this.previewReceipt = data.image
|
||||
this.fileObject = data.file
|
||||
},
|
||||
async getReceipt () {
|
||||
let res = await axios.get(`/api/expenses/${this.$route.params.id}/show/receipt`)
|
||||
|
||||
async getReceipt() {
|
||||
let res = await this.getExpenseReceipt(this.$route.params.id)
|
||||
|
||||
if (res.data.error) {
|
||||
this.isReceiptAvailable = false
|
||||
@ -311,47 +441,99 @@ export default {
|
||||
this.isReceiptAvailable = true
|
||||
this.previewReceipt = res.data.image
|
||||
},
|
||||
async fetchInitialData () {
|
||||
this.fetchCategories()
|
||||
let fetchData = await this.fetchCreateExpense()
|
||||
this.customerList = fetchData.data.customers
|
||||
if (this.isEdit) {
|
||||
let response = await this.fetchExpense(this.$route.params.id)
|
||||
this.category = response.data.expense.category
|
||||
this.formData = { ...response.data.expense }
|
||||
this.formData.expense_date = moment(this.formData.expense_date).toString()
|
||||
this.formData.amount = (response.data.expense.amount)
|
||||
this.fileSendUrl = `/api/expenses/${this.$route.params.id}`
|
||||
if (response.data.expense.user_id) {
|
||||
this.customer = this.customerList.find(customer => customer.id === response.data.expense.user_id)
|
||||
}
|
||||
}
|
||||
|
||||
setExpenseCustomer(id) {
|
||||
this.customer = this.customers.find((c) => {
|
||||
return c.id == id
|
||||
})
|
||||
},
|
||||
async sendData () {
|
||||
|
||||
async loadData() {
|
||||
this.isRequestOnGoing = true
|
||||
await this.fetchCategories({ limit: 'all' })
|
||||
await this.fetchCustomers({ limit: 'all' })
|
||||
if (this.isEdit) {
|
||||
this.isRequestOnGoing = true
|
||||
let response = await this.fetchExpense(this.$route.params.id)
|
||||
|
||||
this.formData = { ...this.formData, ...response.data.expense }
|
||||
|
||||
this.formData.expense_date = moment(
|
||||
this.formData.expense_date
|
||||
).toString()
|
||||
|
||||
this.formData.amount = response.data.expense.amount
|
||||
|
||||
this.fileSendUrl = `/api/v1/expenses/${this.$route.params.id}`
|
||||
|
||||
if (response.data.expense.expense_category_id) {
|
||||
this.category = this.categories.find(
|
||||
(category) =>
|
||||
category.id === response.data.expense.expense_category_id
|
||||
)
|
||||
}
|
||||
|
||||
if (response.data.expense.user_id) {
|
||||
this.customer = this.customers.find(
|
||||
(customer) => customer.id === response.data.expense.user_id
|
||||
)
|
||||
}
|
||||
|
||||
let res = await this.fetchCustomFields({
|
||||
type: 'Expense',
|
||||
limit: 'all',
|
||||
})
|
||||
|
||||
this.setEditCustomFields(
|
||||
response.data.expense.fields,
|
||||
res.data.customFields.data
|
||||
)
|
||||
|
||||
this.getReceipt()
|
||||
this.isRequestOnGoing = false
|
||||
return true
|
||||
}
|
||||
await this.setInitialCustomFields('Expense')
|
||||
if (this.$route.query.customer) {
|
||||
this.setExpenseCustomer(parseInt(this.$route.query.customer))
|
||||
}
|
||||
this.isRequestOnGoing = false
|
||||
},
|
||||
|
||||
async sendData() {
|
||||
let validate = await this.touchCustomField()
|
||||
this.$v.category.$touch()
|
||||
this.$v.formData.$touch()
|
||||
if (this.$v.$invalid) {
|
||||
if (this.$v.$invalid || validate.error) {
|
||||
return true
|
||||
}
|
||||
|
||||
let data = new FormData()
|
||||
|
||||
if (this.file) {
|
||||
data.append('attachment_receipt', this.file)
|
||||
if (this.fileObject) {
|
||||
data.append('attachment_receipt', this.fileObject)
|
||||
}
|
||||
data.append('expense_category_id', this.formData.expense_category_id)
|
||||
data.append('expense_date', moment(this.formData.expense_date).format('DD/MM/YYYY'))
|
||||
data.append('amount', (this.formData.amount))
|
||||
data.append(
|
||||
'expense_date',
|
||||
moment(this.formData.expense_date).format('YYYY-MM-DD')
|
||||
)
|
||||
data.append('amount', this.formData.amount)
|
||||
data.append('notes', this.formData.notes ? this.formData.notes : '')
|
||||
data.append('user_id', this.customer ? this.customer.id : '')
|
||||
data.append('customFields', JSON.stringify(this.formData.customFields))
|
||||
|
||||
if (this.isEdit) {
|
||||
this.isLoading = true
|
||||
data.append('_method', 'PUT')
|
||||
let response = await this.updateExpense({id: this.$route.params.id, editData: data})
|
||||
let response = await this.updateExpense({
|
||||
id: this.$route.params.id,
|
||||
editData: data,
|
||||
})
|
||||
|
||||
if (response.data.success) {
|
||||
window.toastr['success'](this.$t('expenses.updated_message'))
|
||||
this.isLoading = false
|
||||
window.toastr['success'](this.$t('expenses.updated_message'))
|
||||
this.$router.push('/admin/expenses')
|
||||
return true
|
||||
}
|
||||
@ -359,16 +541,16 @@ export default {
|
||||
} else {
|
||||
this.isLoading = true
|
||||
let response = await this.addExpense(data)
|
||||
this.isLoading = false
|
||||
|
||||
if (response.data.success) {
|
||||
window.toastr['success'](this.$t('expenses.created_message'))
|
||||
this.isLoading = false
|
||||
this.$router.push('/admin/expenses')
|
||||
this.isLoading = false
|
||||
return true
|
||||
}
|
||||
window.toastr['success'](response.data.success)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user