diff --git a/src/components/team/TeamForm.vue b/src/components/team/TeamForm.vue
index 909436b..e1f13de 100644
--- a/src/components/team/TeamForm.vue
+++ b/src/components/team/TeamForm.vue
@@ -34,9 +34,11 @@
+
+
+
+
Loading
@@ -76,11 +82,13 @@ import AppInput from '@/components/form/AppInput';
import Errors from '@/utils/errors';
import TeamFields from '@/components/team/TeamFields';
import TeamLogo from '@/components/team/TeamLogo';
+import TeamTaxes from '@/components/team/TeamTaxes';
export default {
components: {
TeamLogo,
TeamFields,
+ TeamTaxes,
AppInput,
BTab,
BTabs,
diff --git a/src/components/team/TeamTaxes.vue b/src/components/team/TeamTaxes.vue
new file mode 100644
index 0000000..d042cda
--- /dev/null
+++ b/src/components/team/TeamTaxes.vue
@@ -0,0 +1,64 @@
+
+
+
+
diff --git a/src/services/tax.service.js b/src/services/tax.service.js
new file mode 100644
index 0000000..6baf544
--- /dev/null
+++ b/src/services/tax.service.js
@@ -0,0 +1,45 @@
+import storage from 'localforage';
+import { removeVuexORMFlags } from '@/utils/helpers';
+
+class TaxService {
+ async getTaxes() {
+ const taxes = await storage.getItem('taxes');
+
+ return taxes || [];
+ }
+
+ async getTax(taxId) {
+ const taxes = await this.getTaxes();
+ return taxes.find(tax => tax.id === taxId);
+ }
+
+ async createTax(tax) {
+ return this.saveTax(tax);
+ }
+
+ async updateTax(tax) {
+ return this.saveTax(tax);
+ }
+
+ async deleteTax(taxId) {
+ const taxes = await this.getTaxes();
+ const index = taxes.findIndex(item => item.id === taxId);
+ taxes.splice(index, 1);
+ return storage.setItem('taxes', taxes);
+ }
+
+ async saveTax(tax) {
+ const taxes = await this.getTaxes();
+ const index = taxes.findIndex(item => item.id === tax.id);
+ removeVuexORMFlags(tax);
+ if (index === -1) {
+ taxes.push(tax);
+ } else {
+ taxes[index] = tax;
+ }
+ await storage.setItem('taxes', taxes);
+ return tax;
+ }
+}
+
+export default new TaxService();
diff --git a/src/store/models/tax.js b/src/store/models/tax.js
new file mode 100644
index 0000000..0c6131b
--- /dev/null
+++ b/src/store/models/tax.js
@@ -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(''),
+ };
+ }
+}
diff --git a/src/store/store.js b/src/store/store.js
index caceaca..a9aa203 100644
--- a/src/store/store.js
+++ b/src/store/store.js
@@ -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: {},
diff --git a/src/store/taxes.js b/src/store/taxes.js
new file mode 100644
index 0000000..ff8fc9e
--- /dev/null
+++ b/src/store/taxes.js
@@ -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();
+ },
+ },
+};
diff --git a/src/store/teams.js b/src/store/teams.js
index df1114f..b4cb963 100644
--- a/src/store/teams.js
+++ b/src/store/teams.js
@@ -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();