mirror of
https://github.com/mokuappio/serverless-invoices.git
synced 2025-10-27 16:01:07 -04:00
Only add taxes that have labels to invoice rows. Be able to overwrite invoice row taxes when changing taxes on team.
This commit is contained in:
@ -26,5 +26,11 @@
|
||||
"company_city": "City",
|
||||
"company_county": "County/State",
|
||||
"company_country": "Country"
|
||||
},
|
||||
"tax_modal": {
|
||||
"title": "Overwrite taxes for current invoice rows?",
|
||||
"ok_title": "Overwrite",
|
||||
"cancel_title": "Dismiss",
|
||||
"taxes_updated": "Taxes updated"
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,5 +26,11 @@
|
||||
"company_city": "Linn",
|
||||
"company_county": "Maakond",
|
||||
"company_country": "Riik"
|
||||
},
|
||||
"tax_modal": {
|
||||
"title": "Kirjuta antud arve ridade maksud üle?",
|
||||
"ok_title": "Kirjuta üle",
|
||||
"cancel_title": "Sulge",
|
||||
"taxes_updated": "Maksud uuendatud"
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<h4>{{ $t('title') }}</h4>
|
||||
<div v-if="team">
|
||||
<button class="btn btn-sm btn-primary"
|
||||
@click="$emit('done')">{{ $t('done') }}
|
||||
@click="done">{{ $t('done') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@ -62,7 +62,7 @@
|
||||
</b-tab>
|
||||
|
||||
<b-tab :title="$t('tabs.taxes')" class="col-12">
|
||||
<TeamTaxes class="row"/>
|
||||
<TeamTaxes class="row" @changed="taxesChanged = true"/>
|
||||
</b-tab>
|
||||
|
||||
</b-tabs>
|
||||
@ -96,6 +96,7 @@ export default {
|
||||
return {
|
||||
errors: new Errors(),
|
||||
loading: false,
|
||||
taxesChanged: false,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@ -113,6 +114,25 @@ export default {
|
||||
})
|
||||
.catch(err => this.errors.set(err.errors));
|
||||
},
|
||||
async done() {
|
||||
if (this.taxesChanged) {
|
||||
await this.promptUpdateInvoiceRowTaxes();
|
||||
}
|
||||
this.$emit('done');
|
||||
},
|
||||
async promptUpdateInvoiceRowTaxes() {
|
||||
const confirmed = await this.$bvModal.msgBoxConfirm(this.$t('tax_modal.title'), {
|
||||
okTitle: this.$t('tax_modal.ok_title'),
|
||||
okVariant: 'primary',
|
||||
cancelTitle: this.$t('tax_modal.cancel_title'),
|
||||
cancelVariant: 'btn-link',
|
||||
contentClass: 'bg-base dp--24',
|
||||
});
|
||||
if (confirmed) {
|
||||
await this.$store.dispatch('invoiceRows/overwriteTaxes');
|
||||
NotificationService.success(this.$t('tax_modal.taxes_updated'));
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
@ -48,6 +48,7 @@ export default {
|
||||
if (confirmed) {
|
||||
await this.$store.dispatch('taxes/deleteTax', field.id);
|
||||
try {
|
||||
this.$emit('changed');
|
||||
NotificationService.success(this.$t('notification_deleted'));
|
||||
} catch (err) {
|
||||
NotificationService.error(err.message);
|
||||
@ -59,6 +60,7 @@ export default {
|
||||
props,
|
||||
taxId: tax.id,
|
||||
});
|
||||
this.$emit('changed');
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@ -2,6 +2,16 @@ import InvoiceRow from '@/store/models/invoice-row';
|
||||
import InvoiceRowTax from '@/store/models/invoice-row-tax';
|
||||
import { flatten, uniqBy } from 'lodash';
|
||||
|
||||
function addTaxes(taxes, row) {
|
||||
taxes.forEach((tax) => {
|
||||
const rowTax = new InvoiceRowTax();
|
||||
rowTax.label = tax.label;
|
||||
rowTax.value = tax.value;
|
||||
rowTax.row_id = row.id;
|
||||
rowTax.$save();
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {},
|
||||
@ -35,16 +45,21 @@ export default {
|
||||
if (client && client.has_tax) {
|
||||
const taxes = getters.taxes.length > 0
|
||||
? getters.taxes
|
||||
: rootGetters['taxes/all'];
|
||||
taxes.forEach((tax) => {
|
||||
const rowTax = new InvoiceRowTax();
|
||||
rowTax.label = tax.label;
|
||||
rowTax.value = tax.value;
|
||||
rowTax.row_id = row.id;
|
||||
rowTax.$save();
|
||||
});
|
||||
: rootGetters['taxes/allWithLabels'];
|
||||
addTaxes(taxes, row);
|
||||
}
|
||||
},
|
||||
overwriteTaxes({ rootGetters, rootState }) {
|
||||
const taxes = rootGetters['taxes/allWithLabels'];
|
||||
const rows = InvoiceRow.query()
|
||||
.where('invoice_id', rootState.invoices.invoiceId)
|
||||
.get();
|
||||
|
||||
rows.forEach((row) => {
|
||||
InvoiceRowTax.delete(tax => tax.row_id === row.id)
|
||||
.then(() => addTaxes(taxes, row));
|
||||
});
|
||||
},
|
||||
async removeRow(store, rowId) {
|
||||
await InvoiceRow.delete(rowId);
|
||||
},
|
||||
|
||||
@ -40,5 +40,8 @@ export default {
|
||||
all() {
|
||||
return Tax.all();
|
||||
},
|
||||
allWithLabels() {
|
||||
return Tax.all().filter(tax => !!tax.label);
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user