init crater

This commit is contained in:
Mohit Panjwani
2019-11-11 12:16:00 +05:30
commit bdf2ba51d6
668 changed files with 158503 additions and 0 deletions

View File

@ -0,0 +1,368 @@
<template>
<div class="payment-create main-content">
<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
: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-input
:invalid="$v.formData.payment_number.$error"
v-model.trim="formData.payment_number"
read-only
type="text"
name="email"
@input="$v.formData.payment_number.$touch()"
/>
<div v-if="$v.formData.payment_number.$error">
<span v-if="!$v.formData.payment_number.required" class="text-danger">{{ $tc('validation.required') }}</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"
/>
<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')"
label="invoice_number"
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.numeric" class="text-danger">{{ $t('validation.numbers_only') }}</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_grater_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_mode"
:options="getPaymentMode"
:searchable="true"
:show-labels="false"
:placeholder="$t('payments.select_payment_mode')"
/>
</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>
</div>
</div>
</div>
</form>
</div>
</template>
<script>
import { mapActions, mapGetters } from 'vuex'
import MultiSelect from 'vue-multiselect'
import { validationMixin } from 'vuelidate'
import moment from 'moment'
const { required, numeric, between, maxLength } = require('vuelidate/lib/validators')
export default {
components: { MultiSelect },
mixins: [validationMixin],
data () {
return {
formData: {
user_id: null,
payment_number: null,
payment_date: null,
amount: 100,
payment_mode: null,
invoice_id: null,
notes: null
},
money: {
decimal: '.',
thousands: ',',
prefix: '$ ',
precision: 2,
masked: false
},
customer: null,
invoice: null,
customerList: [],
invoiceList: [],
isLoading: false,
maxPayableAmount: Number.MAX_SAFE_INTEGER
}
},
validations () {
return {
customer: {
required
},
formData: {
payment_number: {
required
},
payment_date: {
required
},
amount: {
required,
numeric,
between: between(1, this.maxPayableAmount + 1)
},
notes: {
maxLength: maxLength(255)
}
}
}
},
computed: {
...mapGetters('currency', [
'defaultCurrencyForInput'
]),
getPaymentMode () {
return ['Cash', 'Check', 'Credit Card', 'Bank Transfer']
},
amount: {
get: function () {
return this.formData.amount / 100
},
set: function (newValue) {
this.formData.amount = newValue * 100
}
},
isEdit () {
if (this.$route.name === 'payments.edit') {
return true
}
return false
},
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
}
} else {
return this.defaultCurrencyForInput
}
}
},
watch: {
customer (newValue) {
this.formData.user_id = newValue.id
if (!this.isEdit) {
this.fetchCustomerInvoices(newValue.id)
}
},
invoice (newValue) {
this.formData.invoice_id = newValue.id
if (!this.isEdit) {
this.setPaymentAmountByInvoiceData(newValue.id)
}
}
},
async mounted () {
// if (!this.$route.params.id) {
// this.$refs.baseSelect.$refs.search.focus()
// }
this.$nextTick(() => {
this.loadData()
if (this.$route.params.id && !this.isEdit) {
this.setInvoicePaymentData()
}
})
},
methods: {
...mapActions('invoice', [
'fetchInvoice'
]),
...mapActions('payment', [
'fetchCreatePayment',
'addPayment',
'updatePayment',
'fetchPayment'
]),
async loadData () {
if (this.isEdit) {
let response = await this.fetchPayment(this.$route.params.id)
this.customerList = response.data.customers
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.amount = parseFloat(response.data.payment.amount)
this.maxPayableAmount = response.data.payment.amount
if (response.data.payment.invoice !== null) {
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)
} else {
let response = await this.fetchCreatePayment()
this.customerList = response.data.customers
this.formData.payment_number = response.data.nextPaymentNumber
this.formData.payment_date = moment(new Date()).toString()
}
return true
},
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) {
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 submitPaymentData () {
this.$v.customer.$touch()
this.$v.formData.$touch()
if (this.$v.$invalid) {
return true
}
if (this.isEdit) {
let data = {
editData: {
...this.formData,
payment_date: moment(this.formData.payment_date).format('DD/MM/YYYY')
},
id: this.$route.params.id
}
let response = await this.updatePayment(data)
if (response.data.success) {
window.toastr['success'](this.$t('payments.updated_message'))
this.$router.push('/admin/payments')
return true
}
if (response.data.error === 'invalid_amount') {
window.toastr['error'](this.$t('invalid_amount_message'))
return false
}
window.toastr['error'](response.data.error)
} else {
let data = {
...this.formData,
payment_date: moment(this.formData.payment_date).format('DD/MM/YYYY')
}
this.isLoading = true
let response = await this.addPayment(data)
if (response.data.success) {
window.toastr['success'](this.$t('payments.created_message'))
this.$router.push('/admin/payments')
this.isLoading = true
return true
}
if (response.data.error === 'invalid_amount') {
window.toastr['error'](this.$t('invalid_amount_message'))
return false
}
window.toastr['error'](response.data.error)
}
}
}
}
</script>

View File

@ -0,0 +1,423 @@
<template>
<div class="payments main-content">
<div class="page-header">
<h3 class="page-title">{{ $t('payments.title') }}</h3>
<ol class="breadcrumb">
<li class="breadcrumb-item">
<router-link
slot="item-title"
to="dashboard">
{{ $t('general.home') }}
</router-link>
</li>
<li class="breadcrumb-item">
<router-link
slot="item-title"
to="#">
{{ $tc('payments.payment',2) }}
</router-link>
</li>
</ol>
<div class="page-actions row">
<div class="col-xs-2 mr-4">
<base-button
v-show="totalPayments || filtersApplied"
:outline="true"
:icon="filterIcon"
color="theme"
right-icon
size="large"
@click="toggleFilter"
>
{{ $t('general.filter') }}
</base-button>
</div>
<router-link slot="item-title" class="col-xs-2" to="payments/create">
<base-button
color="theme"
icon="plus"
size="large"
>
{{ $t('payments.add_payment') }}
</base-button>
</router-link>
</div>
</div>
<transition name="fade" mode="out-in">
<div v-show="showFilters" class="filter-section">
<div class="row">
<div class="col-md-4">
<label class="form-label">{{ $t('payments.customer') }}</label>
<base-customer-select
ref="customerSelect"
@select="onSelectCustomer"
@deselect="clearCustomerSearch"
/>
</div>
<div class="col-sm-4">
<label for="">{{ $t('payments.payment_number') }}</label>
<base-input
v-model="filters.payment_number"
:placeholder="$t(payments.payment_number)"
name="payment_number"
/>
</div>
<div class="col-sm-4">
<label class="form-label">{{ $t('payments.payment_mode') }}</label>
<base-select
v-model="filters.payment_mode"
:options="payment_mode"
:searchable="true"
:show-labels="false"
:placeholder="$t('payments.payment_mode')"
/>
</div>
</div>
<label class="clear-filter" @click="clearFilter">{{ $t('general.clear_all') }}</label>
</div>
</transition>
<div v-cloak v-show="showEmptyScreen" class="col-xs-1 no-data-info" align="center">
<capsule-icon class="mt-5 mb-4"/>
<div class="row" align="center">
<label class="col title">{{ $t('payments.no_payments') }}</label>
</div>
<div class="row">
<label class="description col mt-1" align="center">{{ $t('payments.list_of_payments') }}</label>
</div>
<div class="btn-container">
<base-button
:outline="true"
color="theme"
class="mt-3"
size="large"
@click="$router.push('payments/create')"
>
{{ $t('payments.add_new_payment') }}
</base-button>
</div>
</div>
<div v-show="!showEmptyScreen" class="table-container">
<div class="table-actions mt-5">
<p class="table-stats">{{ $t('general.showing') }}: <b>{{ payments.length }}</b> {{ $t('general.of') }} <b>{{ totalPayments }}</b></p>
<transition name="fade">
<v-dropdown v-if="selectedPayments.length" :show-arrow="false">
<span slot="activator" href="#" class="table-actions-button dropdown-toggle">
{{ $t('general.actions') }}
</span>
<v-dropdown-item>
<div class="dropdown-item" @click="removeMultiplePayments">
<font-awesome-icon :icon="['fas', 'trash']" class="dropdown-item-icon" />
{{ $t('general.delete') }}
</div>
</v-dropdown-item>
</v-dropdown>
</transition>
</div>
<div class="custom-control custom-checkbox">
<input
id="select-all"
v-model="selectAllFieldStatus"
type="checkbox"
class="custom-control-input"
@change="selectAllPayments"
>
<label v-show="!isRequestOngoing" for="select-all" class="custom-control-label selectall">
<span class="select-all-label">{{ $t('general.select_all') }} </span>
</label>
</div>
<table-component
ref="table"
:data="fetchData"
:show-filter="false"
table-class="table"
>
<table-column
:sortable="false"
:filterable="false"
cell-class="no-click"
>
<template slot-scope="row">
<div class="custom-control custom-checkbox">
<input
:id="row.id"
v-model="selectField"
:value="row.id"
type="checkbox"
class="custom-control-input"
>
<label :for="row.id" class="custom-control-label" />
</div>
</template>
</table-column>
<table-column
:label="$t('payments.date')"
sort-as="payment_date"
show="formattedPaymentDate"
/>
<table-column
:label="$t('payments.customer')"
show="name"
/>
<table-column
:label="$t('payments.payment_mode')"
show="payment_mode"
/>
<table-column
:label="$t('payments.payment_number')"
show="payment_number"
/>
<table-column
:label="$t('payments.invoice')"
sort-as="invoice_id"
show="invoice.invoice_number"
/>
<table-column
:label="$t('payments.amount')"
>
<template slot-scope="row">
<span>{{ $t('payments.amount') }}</span>
<div v-html="$utils.formatMoney(row.amount, row.user.currency)" />
</template>
</table-column>
<table-column
:sortable="false"
:filterable="false"
cell-class="action-dropdown no-click"
>
<template slot-scope="row">
<span>{{ $t('payments.action') }}</span>
<v-dropdown>
<a slot="activator" href="#">
<dot-icon />
</a>
<v-dropdown-item>
<router-link :to="{path: `payments/${row.id}/edit`}" class="dropdown-item">
<font-awesome-icon :icon="['fas', 'pencil-alt']" class="dropdown-item-icon" />
{{ $t('general.edit') }}
</router-link>
</v-dropdown-item>
<v-dropdown-item>
<div class="dropdown-item" @click="removePayment(row.id)">
<font-awesome-icon :icon="['fas', 'trash']" class="dropdown-item-icon" />
{{ $t('general.delete') }}
</div>
</v-dropdown-item>
</v-dropdown>
</template>
</table-column>
</table-component>
</div>
</div>
</template>
<script>
import { mapActions, mapGetters } from 'vuex'
import { SweetModal, SweetModalTab } from 'sweet-modal-vue'
import CapsuleIcon from '../../components/icon/CapsuleIcon'
import BaseButton from '../../../js/components/base/BaseButton'
import { request } from 'http'
export default {
components: {
'capsule-icon': CapsuleIcon,
'SweetModal': SweetModal,
'SweetModalTab': SweetModalTab,
BaseButton
},
data () {
return {
showFilters: false,
sortedBy: 'created_at',
filtersApplied: false,
isRequestOngoing: true,
payment_mode: ['Cash', 'Check', 'Credit Card', 'Bank Transfer'],
filters: {
customer: null,
payment_mode: '',
payment_number: ''
}
}
},
computed: {
showEmptyScreen () {
return !this.totalPayments && !this.isRequestOngoing && !this.filtersApplied
},
filterIcon () {
return (this.showFilters) ? 'times' : 'filter'
},
...mapGetters('customer', [
'customers'
]),
...mapGetters('payment', [
'selectedPayments',
'totalPayments',
'payments',
'selectAllField'
]),
selectField: {
get: function () {
return this.selectedPayments
},
set: function (val) {
this.selectPayment(val)
}
},
selectAllFieldStatus: {
get: function () {
return this.selectAllField
},
set: function (val) {
this.setSelectAllState(val)
}
}
},
watch: {
filters: {
handler: 'setFilters',
deep: true
}
},
mounted () {
this.fetchCustomers()
},
destroyed () {
if (this.selectAllField) {
this.selectAllPayments()
}
},
methods: {
...mapActions('payment', [
'fetchPayments',
'selectAllPayments',
'selectPayment',
'deletePayment',
'deleteMultiplePayments',
'setSelectAllState'
]),
...mapActions('customer', [
'fetchCustomers'
]),
async fetchData ({ page, filter, sort }) {
let data = {
customer_id: this.filters.customer !== null ? this.filters.customer.id : '',
payment_number: this.filters.payment_number,
payment_mode: this.filters.payment_mode ? this.filters.payment_mode : '',
orderByField: sort.fieldName || 'created_at',
orderBy: sort.order || 'desc',
page
}
this.isRequestOngoing = true
let response = await this.fetchPayments(data)
this.isRequestOngoing = false
return {
data: response.data.payments.data,
pagination: {
totalPages: response.data.payments.last_page,
currentPage: page,
count: response.data.payments.scount
}
}
},
refreshTable () {
this.$refs.table.refresh()
},
setFilters () {
this.filtersApplied = true
this.refreshTable()
},
clearFilter () {
if (this.filters.customer) {
this.$refs.customerSelect.$refs.baseSelect.removeElement(this.filters.customer)
}
this.filters = {
customer: null,
payment_mode: '',
payment_number: ''
}
this.$nextTick(() => {
this.filtersApplied = false
})
},
toggleFilter () {
if (this.showFilters && this.filtersApplied) {
this.clearFilter()
this.refreshTable()
}
this.showFilters = !this.showFilters
},
onSelectCustomer (customer) {
this.filters.customer = customer
},
async removePayment (id) {
this.id = id
swal({
title: this.$t('general.are_you_sure'),
text: this.$tc('payments.confirm_delete'),
icon: 'error',
buttons: true,
dangerMode: true
}).then(async (willDelete) => {
if (willDelete) {
let res = await this.deletePayment(this.id)
if (res.data.success) {
window.toastr['success'](this.$tc('payments.deleted_message', 1))
this.$refs.table.refresh()
return true
} else if (res.data.error) {
window.toastr['error'](res.data.message)
}
}
})
},
async removeMultiplePayments () {
swal({
title: this.$t('general.are_you_sure'),
text: this.$tc('payments.confirm_delete', 2),
icon: 'error',
buttons: true,
dangerMode: true
}).then(async (willDelete) => {
if (willDelete) {
let request = await this.deleteMultiplePayments()
if (request.data.success) {
window.toastr['success'](this.$tc('payments.deleted_message', 2))
this.$refs.table.refresh()
} else if (request.data.error) {
window.toastr['error'](request.data.message)
}
}
})
},
async clearCustomerSearch (removedOption, id) {
this.filters.customer = ''
this.$refs.table.refresh()
},
showModel (selectedRow) {
this.selectedRow = selectedRow
this.$refs.Delete_modal.open()
},
async removeSelectedItems () {
this.$refs.Delete_modal.close()
await this.selectedRow.forEach(row => {
this.deletePayment(this.id)
})
this.$refs.table.refresh()
}
}
}
</script>