![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/ts.corals.io/frontend/pages/ |
<template> <div> <CRUDIndex ref="incomesTable" :columns="columns" :resourceURL="resourceUrl" :options="options" :form="form" :bulk-action-options="bulkActionOptions" :labels="labels" :cloneAttr="cloneAttr" form-size="lg"> <template v-slot:project="{object}"> <nuxt-link :to="`/clients/${object.row.client_id}/projects/${object.row.project_id}`"> {{ object.row.project }} </nuxt-link> </template> <template v-slot:client="{object}"> <nuxt-link :to="'/clients/'+object.row.client_id"> {{ object.row.client }} </nuxt-link> </template> <template v-slot:status="{object}"> <span v-html="object.row.status"></span> </template> <template v-slot:payment_method="{object}"> {{ object.row.payment_method }} </template> <template v-slot:category_id="{object}"> {{ object.row.category }} </template> <template v-slot:file="{object}"> <a :href="object.row.file" target="_blank" v-if="object.row.file">File</a> <span v-else>-</span> </template> <template v-slot:default="{form}"> <div class="" v-if="!form.id"> <div class="custom-control custom-checkbox mb-2"> <input type="checkbox" id="active_options" class="custom-control-input" v-model="active_options"/> <label for="active_options" class="custom-control-label"> <small>Show Active Options</small> </label> </div> </div> <div class="row sm-gutters"> <div class="col-md-5"> <corals-datepicker :form="form" required field="income_date" label="Income Date"/> </div> <div class="col-md-4"> <corals-input :form="form" type="number" field="amount" step="0.1" required min="0"/> </div> <div class="col-md-3"> <corals-select :form="form" field="currency" :options="form.getFormData('currency_options')" required/> </div> </div> <div class="row sm-gutters"> <div class="col-md-5"> <corals-select :form="form" required label="Category" field="category_id" :options="getCategoriesOrProjectsOptions(form.getFormData('categories'))"/> </div> <div class="col-md-7"> <corals-textarea field="notes" required rows="3" :form="form"/> </div> </div> <div class="row sm-gutters"> <div class="col-md-5"> <corals-select :form="form" label="Project" field="project_id" :options="getCategoriesOrProjectsOptions(form.getFormData('projects'))"/> </div> <div class="col-md-4"> <corals-input :form="form" field="reference"/> </div> </div> <div class="row sm-gutters"> <div class="col-md-6"> <corals-radio :form="form" label="Payment Method" field="payment_method" :list="form.getFormData('payment_method_options')" required/> </div> <div class="col-md-6"> <corals-radio :form="form" field="status" required label="Status" :list="form.getFormData('status_options')"/> </div> </div> <div class="row sm-gutters"> <div class="col-md-6"> <label>Attachment</label> <div v-if="filePath"> <a :href="filePath" target="_blank">Show File</a> <corals-checkbox field="clear" :form="form"/> </div> <div class="mb-2"> <b-form-file v-model="form.file" placeholder="Upload File..."></b-form-file> <span v-if="filePath && form.file" class="text-muted small">Note: when a new file is uploaded, the existing file is automatically deleted</span> </div> </div> </div> </template> </CRUDIndex> </div> </template> <script> import CRUDIndex from "@/components/layout/CRUDIndex"; import commonMixin from "@/mixins/commonMixin"; import CoralsSelect from "@/components/CoralsForm/CoralsSelect"; export default { name: "index", components: {CoralsSelect, CRUDIndex}, middleware: 'Authorization', mixins: [commonMixin], provide() { return { handleBulkAction: this.handleBulkAction, } }, data() { return { active_options: 1, filePath: null, resourceUrl: 'timesheet/incomes', labels: { title: 'Incomes', singularTitle: 'Income', }, cloneAttr: { category_id: null, project_id: null, client_id: null, notes: null, amount: null, income_date: new Date(), status: null, currency: null, payment_method: null, reference: null, }, options: { listColumns: { status: [], payment_method: [], category_id: [], }, hideCreate: this.$cant('create', 'income'), customColumns: ['status', 'project', 'client', 'payment_method', 'file', 'category_id'], filterable: ['status', 'income_date', 'payment_method', 'category_id', 'project', 'client', 'notes', 'reference'], headings: { 'payment_method': 'Payment Method', 'category_id': 'Category' }, }, form: this.$form({ id: null, category_id: '', project_id: '', client_id: '', notes: '', amount: '', status: 'paid', file: null, clear: 0, income_date: new Date(), currency: 'usd', payment_method: 'paypal', reference: '', }, { fetchFormDataURL: '/timesheet/incomes/get-form-data', model: 'income', loadFormDataCallBack: () => { this.options.listColumns.status = this.getOptions(this.form.formData.status_options); let categories = JSON.parse(JSON.stringify(this.form.formData.categories)); categories.shift(); this.options.listColumns.category_id = this.getOptions(categories); this.options.listColumns.payment_method = this.getOptions(this.form.formData.payment_method_options); } }), } }, methods: { getOptions(list) { let allOption = {id: '', text: 'All'}; let options = []; options.push(allOption); list.map(row => { options.push({id: row.id ?? row.value, text: row.label}); }); return options; }, getCategoriesOrProjectsOptions(arrayData) { let resultsData = []; let DataGroups = []; let activeObjects = []; if (!this.active_options) { activeObjects = arrayData.filter((object => object['group'] !== true)); DataGroups = arrayData.filter((group => group['group'] === true)); } else { activeObjects = arrayData.filter((object => (object['is_active'] === 1 || object['status'] === 'active') && object['group'] !== true)); DataGroups = arrayData.filter((group => group['group'] === true && group['status'] === 'active')); } DataGroups.forEach(group => { group['is_group_empty'] = true; resultsData.push(group); activeObjects.filter(activeObject => { if (group['code'] === activeObject['group']) { group['is_group_empty'] = false; resultsData.push(activeObject); } }); }); return resultsData; }, handleBulkAction(action, selectedIds) { this.$bvModal.msgBoxConfirm('Are you sure?', { size: 'md', buttonSize: 'sm', okVariant: 'danger', footerClass: 'p-2', hideHeaderClose: false, centered: true }) .then(value => { if (value === true) { this.$axios.post('timesheet/incomes/bulk-action', { 'selection': selectedIds, 'action': action }).then(response => { let level = response.data.data.level; let message = response.data.data.message; if (level === 'success') { this.$toast.success(message); } else { this.$toast.error(message); } this.$eventBus.$emit('setSelectedIds', []); this.$refs.incomesTable.refresh(); }).catch(err => { this.$toast.error(err.response.data.message); }); } }) .catch(err => { }) }, }, watch: { 'form.id'() { this.filePath = null; if (this.form.file !== null && typeof this.form.file !== 'object') { this.filePath = this.form.file; this.form.file = null; } } }, computed: { columns() { let columns = []; if (this.$isAdmin() && this.bulkActionOptions.length) { columns.push('checkbox'); } columns.push('income_date', 'amount', 'file', 'status', 'payment_method', 'category_id', 'project', 'client', 'reference', 'notes', 'actions'); if (this.$notAdmin()) { columns.pop(); } return columns; }, bulkActionOptions() { let actions = ['delete', 'paid', 'pending', 'voided']; if (this.$notAdmin()) { actions.pop(); } return actions; }, }, } </script> <style scoped> </style>