File: /home/slfopp7cb1df/www/inventorypacket.com/resources/src/views/app/pages/expense/index_expense.vue
<template>
<div class="main-content">
<breadcumb :page="$t('Expense_List')" :folder="$t('Expenses')"/>
<div v-if="isLoading" class="loading_page spinner spinner-primary mr-3"></div>
<div v-else>
<vue-good-table
mode="remote"
:columns="columns"
:totalRows="totalRows"
:rows="expenses"
@on-page-change="onPageChange"
@on-per-page-change="onPerPageChange"
@on-sort-change="onSortChange"
@on-search="onSearch"
:search-options="{
enabled: true,
placeholder: $t('Search_this_table'),
}"
:pagination-options="{
enabled: true,
mode: 'records',
nextLabel: 'next',
prevLabel: 'prev',
}"
styleClass="tableOne table-hover vgt-table"
>
<div slot="selected-row-actions">
<button class="btn btn-danger btn-sm" @click="delete_by_selected()">{{$t('Del')}}</button>
</div>
<div slot="table-actions" class="mt-2 mb-3">
<b-button variant="outline-info ripple m-1" size="sm" v-b-toggle.sidebar-right>
<i class="i-Filter-2"></i>
{{ $t("Filter") }}
</b-button>
<b-button @click="Expense_PDF()" size="sm" variant="outline-success ripple m-1">
<i class="i-File-Copy"></i> PDF
</b-button>
<vue-excel-xlsx
class="btn btn-sm btn-outline-danger ripple m-1"
:data="expenses"
:columns="columns"
:file-name="'Expenses'"
:file-type="'xlsx'"
:sheet-name="'Expenses'"
>
<i class="i-File-Excel"></i> EXCEL
</vue-excel-xlsx>
<router-link
class="btn-sm btn btn-primary ripple btn-icon m-1"
v-if="currentUserPermissions && currentUserPermissions.includes('expense_add')"
to="/app/expenses/store"
>
<span class="ul-btn__icon">
<i class="i-Add"></i>
</span>
<span class="ul-btn__text ml-1">{{$t('Add')}}</span>
</router-link>
</div>
<template slot="table-row" slot-scope="props">
<span v-if="props.column.field == 'actions'">
<router-link
v-if="currentUserPermissions && currentUserPermissions.includes('expense_edit')"
title="Edit"
v-b-tooltip.hover
:to="'/app/expenses/edit/'+props.row.id"
>
<i class="i-Edit text-25 text-success"></i>
</router-link>
<a
title="Delete"
class="cursor-pointer"
v-b-tooltip.hover
v-if="currentUserPermissions && currentUserPermissions.includes('expense_delete')"
@click="Remove_Expense(props.row.id)"
>
<i class="i-Close-Window text-25 text-danger"></i>
</a>
</span>
</template>
</vue-good-table>
</div>
<!-- Multiple Filters -->
<b-sidebar id="sidebar-right" :title="$t('Filter')" bg-variant="white" right shadow>
<div class="px-3 py-2">
<b-row>
<!-- date -->
<b-col md="12">
<b-form-group :label="$t('date')">
<b-form-input type="date" v-model="Filter_date"></b-form-input>
</b-form-group>
</b-col>
<!-- Reference -->
<b-col md="12">
<b-form-group :label="$t('Reference')">
<b-form-input label="Reference" :placeholder="$t('Reference')" v-model="Filter_Ref"></b-form-input>
</b-form-group>
</b-col>
<!-- Account -->
<b-col md="12">
<b-form-group :label="$t('Account')">
<v-select
:reduce="label => label.value"
:placeholder="$t('Choose_Account')"
v-model="Filter_account"
:options="accounts.map(accounts => ({label: accounts.account_name, value: accounts.id}))"
/>
</b-form-group>
</b-col>
<!-- warehouse -->
<b-col md="12">
<b-form-group :label="$t('warehouse')">
<v-select
:reduce="label => label.value"
:placeholder="$t('Choose_Warehouse')"
v-model="Filter_warehouse"
:options="warehouses.map(warehouses => ({label: warehouses.name, value: warehouses.id}))"
/>
</b-form-group>
</b-col>
<!-- Expense_Category -->
<b-col md="12">
<b-form-group :label="$t('Expense_Category')">
<v-select
:reduce="label => label.value"
:placeholder="$t('Choose_Category')"
v-model="Filter_category"
:options="expense_Category.map(expense_Category => ({label: expense_Category.name, value: expense_Category.id}))"
/>
</b-form-group>
</b-col>
<b-col md="6" sm="12">
<b-button
@click="Get_Expenses(serverParams.page)"
variant="primary m-1"
size="sm"
block
>
<i class="i-Filter-2"></i>
{{ $t("Filter") }}
</b-button>
</b-col>
<b-col md="6" sm="12">
<b-button @click="Reset_Filter()" variant="danger m-1" size="sm" block>
<i class="i-Power-2"></i>
{{ $t("Reset") }}
</b-button>
</b-col>
</b-row>
</div>
</b-sidebar>
</div>
</template>
<script>
import { mapActions, mapGetters } from "vuex";
import NProgress from "nprogress";
import jsPDF from "jspdf";
import "jspdf-autotable";
export default {
metaInfo: {
title: "Expense"
},
data() {
return {
isLoading: true,
serverParams: {
columnFilters: {},
sort: {
field: "id",
type: "desc"
},
page: 1,
perPage: 10
},
selectedIds: [],
totalRows: "",
search: "",
limit: "10",
Filter_date: "",
Filter_Ref: "",
Filter_warehouse: "",
Filter_category: "",
Filter_account: "",
expenses: [],
warehouses: [],
accounts: [],
expense_Category: []
};
},
computed: {
...mapGetters(["currentUserPermissions", "currentUser"]),
columns() {
return [
{
label: this.$t("date"),
field: "date",
tdClass: "text-left",
thClass: "text-left"
},
{
label: this.$t("Reference"),
field: "Ref",
tdClass: "text-left",
thClass: "text-left"
},
{
label: this.$t("Account"),
field: "account_name",
tdClass: "text-left",
thClass: "text-left"
},
{
label: this.$t("Amount"),
field: "amount",
type: "decimal",
tdClass: "text-left",
thClass: "text-left"
},
{
label: this.$t("Categorie"),
field: "category_name",
tdClass: "text-left",
thClass: "text-left"
},
{
label: this.$t("warehouse"),
field: "warehouse_name",
tdClass: "text-left",
thClass: "text-left"
},
{
label: this.$t("Details"),
field: "details",
tdClass: "text-left",
thClass: "text-left"
},
{
label: this.$t("Action"),
field: "actions",
html: true,
tdClass: "text-right",
thClass: "text-right",
sortable: false
}
];
}
},
methods: {
//---------------------- Expenses PDF -------------------------------\\
Expense_PDF() {
var self = this;
let pdf = new jsPDF("p", "pt");
let columns = [
{ title: "Date", dataKey: "date" },
{ title: "Reference", dataKey: "Ref" },
{ title: "Account", dataKey: "account_name" },
{ title: "Category", dataKey: "category_name" },
{ title: "Warehouse", dataKey: "warehouse_name" },
{ title: "Amount", dataKey: "amount" },
];
// Calculate totals
let totalGrandTotal = self.expenses.reduce((sum, expense) => sum + parseFloat(expense.amount || 0), 0);
let footer = [{
date: 'Total',
Ref: '',
account_name: '',
category_name: '',
warehouse_name: '',
amount: `${totalGrandTotal.toFixed(2)}`,
}];
pdf.autoTable({
columns: columns,
body: self.expenses,
foot: footer,
startY: 70,
didDrawPage: (data) => {
pdf.text("Expense List", 40, 25);
}
});
pdf.save("Expense_List.pdf");
},
//------ update Params Table
updateParams(newProps) {
this.serverParams = Object.assign({}, this.serverParams, newProps);
},
//---- Event Page Change
onPageChange({ currentPage }) {
if (this.serverParams.page !== currentPage) {
this.updateParams({ page: currentPage });
this.Get_Expenses(currentPage);
}
},
//---- Event Per Page Change
onPerPageChange({ currentPerPage }) {
if (this.limit !== currentPerPage) {
this.limit = currentPerPage;
this.updateParams({ page: 1, perPage: currentPerPage });
this.Get_Expenses(1);
}
},
//---- Event Select Rows
selectionChanged({ selectedRows }) {
this.selectedIds = [];
selectedRows.forEach((row, index) => {
this.selectedIds.push(row.id);
});
},
//------ Event Sort Change
onSortChange(params) {
let field = "";
if (params[0].field == "warehouse_name") {
field = "warehouse_id";
} else if (params[0].field == "category_name") {
field = "expense_category_id";
} else if (params[0].field == "account_name") {
field = "account_id";
} else {
field = params[0].field;
}
this.updateParams({
sort: {
type: params[0].type,
field: field
}
});
this.Get_Expenses(this.serverParams.page);
},
//------ Event Search
onSearch(value) {
this.search = value.searchTerm;
this.Get_Expenses(this.serverParams.page);
},
//------ Reset Filter
Reset_Filter() {
this.search = "";
this.Filter_date = "";
this.Filter_Ref = "";
this.Filter_warehouse = "";
this.Filter_category = "";
this.Filter_account = "";
this.Get_Expenses(this.serverParams.page);
},
// Simply replaces null values with strings=''
setToStrings() {
if (this.Filter_warehouse === null) {
this.Filter_warehouse = "";
} else if (this.Filter_category === null) {
this.Filter_category = "";
} else if (this.Filter_account === null) {
this.Filter_account = "";
}
},
//------------------------------------------------ Get All Expense -------------------------------\\
Get_Expenses(page) {
// Start the progress bar.
NProgress.start();
NProgress.set(0.1);
this.setToStrings();
axios
.get(
"expenses?page=" +
page +
"&Ref=" +
this.Filter_Ref +
"&account_id=" +
this.Filter_account +
"&warehouse_id=" +
this.Filter_warehouse +
"&date=" +
this.Filter_date +
"&expense_category_id=" +
this.Filter_category +
"&SortField=" +
this.serverParams.sort.field +
"&SortType=" +
this.serverParams.sort.type +
"&search=" +
this.search +
"&limit=" +
this.limit
)
.then(response => {
this.expenses = response.data.expenses;
this.expense_Category = response.data.Expenses_category;
this.warehouses = response.data.warehouses;
this.accounts = response.data.accounts;
this.totalRows = response.data.totalRows;
// Complete the animation of theprogress bar.
NProgress.done();
this.isLoading = false;
})
.catch(response => {
// Complete the animation of theprogress bar.
NProgress.done();
setTimeout(() => {
this.isLoading = false;
}, 500);
});
},
//------------------------------- Remove Expense -------------------------\\
Remove_Expense(id) {
this.$swal({
title: this.$t("Delete.Title"),
text: this.$t("Delete.Text"),
type: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
cancelButtonText: this.$t("Delete.cancelButtonText"),
confirmButtonText: this.$t("Delete.confirmButtonText")
}).then(result => {
if (result.value) {
// Start the progress bar.
NProgress.start();
NProgress.set(0.1);
axios
.delete("expenses/" + id)
.then(() => {
this.$swal(
this.$t("Delete.Deleted"),
this.$t("Expense_Deleted"),
"success"
);
Fire.$emit("Delete_Expense");
})
.catch(() => {
// Complete the animation of theprogress bar.
setTimeout(() => NProgress.done(), 500);
this.$swal(
this.$t("Delete.Failed"),
this.$t("Delete.Therewassomethingwronge"),
"warning"
);
});
}
});
},
},
//----------------------------- Created function-------------------
created: function() {
this.Get_Expenses(1);
Fire.$on("Delete_Expense", () => {
setTimeout(() => {
// Complete the animation of theprogress bar.
NProgress.done();
this.Get_Expenses(this.serverParams.page);
}, 500);
});
}
};
</script>