mirror of
https://github.com/mokuappio/serverless-invoices.git
synced 2026-02-06 16:11:42 -05:00
Be able to add default taxes to team.
This commit is contained in:
15
src/store/models/tax.js
Normal file
15
src/store/models/tax.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Model } from '@vuex-orm/core';
|
||||
import { uuidv4 } from '@/utils/helpers';
|
||||
|
||||
export default class Tax extends Model {
|
||||
// This is the name used as module name of the Vuex Store.
|
||||
static entity = 'taxes';
|
||||
|
||||
static fields() {
|
||||
return {
|
||||
id: this.attr(() => uuidv4()),
|
||||
label: this.attr(''),
|
||||
value: this.attr(''),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -17,17 +17,20 @@ import invoiceTeamFields from '@/store/invoice-team-fields';
|
||||
import teams from '@/store/teams';
|
||||
import teamFields from '@/store/team-fields';
|
||||
import themes from '@/store/themes';
|
||||
import taxes from '@/store/taxes';
|
||||
import data from '@/store/data';
|
||||
import ClientField from '@/store/models/client-field';
|
||||
import TeamField from '@/store/models/team-field';
|
||||
import InvoiceClientField from '@/store/models/invoice-client-field';
|
||||
import InvoiceTeamField from '@/store/models/invoice-team-field';
|
||||
import Tax from '@/store/models/tax';
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
VuexORM.use(VuexORMisDirtyPlugin);
|
||||
const database = new VuexORM.Database();
|
||||
|
||||
database.register(Tax);
|
||||
database.register(Team);
|
||||
database.register(TeamField);
|
||||
database.register(Client);
|
||||
@@ -51,6 +54,7 @@ export default new Vuex.Store({
|
||||
teams,
|
||||
teamFields,
|
||||
themes,
|
||||
taxes,
|
||||
data,
|
||||
},
|
||||
state: {},
|
||||
|
||||
44
src/store/taxes.js
Normal file
44
src/store/taxes.js
Normal file
@@ -0,0 +1,44 @@
|
||||
import Tax from '@/store/models/tax';
|
||||
import TaxService from '@/services/tax.service';
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {},
|
||||
mutations: {},
|
||||
actions: {
|
||||
init({ dispatch }) {
|
||||
return dispatch('getTaxes');
|
||||
},
|
||||
terminate() {
|
||||
return Tax.deleteAll();
|
||||
},
|
||||
async getTaxes() {
|
||||
const taxes = await TaxService.getTaxes();
|
||||
await Tax.create({ data: taxes });
|
||||
return taxes;
|
||||
},
|
||||
async taxProps(store, payload) {
|
||||
return Tax.update({
|
||||
where: payload.taxId,
|
||||
data: payload.props,
|
||||
});
|
||||
},
|
||||
async updateTax({ dispatch }, payload) {
|
||||
const tax = await dispatch('taxProps', payload);
|
||||
return TaxService.updateTax(tax);
|
||||
},
|
||||
async addNewTax() {
|
||||
const tax = await Tax.createNew();
|
||||
return TaxService.createTax(tax);
|
||||
},
|
||||
async deleteTax(store, taxId) {
|
||||
await Tax.delete(taxId);
|
||||
return TaxService.deleteTax(taxId);
|
||||
},
|
||||
},
|
||||
getters: {
|
||||
all() {
|
||||
return Tax.all();
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -17,6 +17,7 @@ export default {
|
||||
dispatch('clients/terminate', null, { root: true }),
|
||||
dispatch('bankAccounts/terminate', null, { root: true }),
|
||||
dispatch('invoices/terminate', null, { root: true }),
|
||||
dispatch('taxes/terminate', null, { root: true }),
|
||||
]);
|
||||
|
||||
await dispatch('getTeam');
|
||||
@@ -24,6 +25,7 @@ export default {
|
||||
dispatch('clients/init', null, { root: true });
|
||||
dispatch('bankAccounts/init', null, { root: true });
|
||||
dispatch('invoices/init', null, { root: true });
|
||||
dispatch('taxes/init', null, { root: true });
|
||||
},
|
||||
async terminate() {
|
||||
return Team.deleteAll();
|
||||
|
||||
Reference in New Issue
Block a user