mirror of
https://github.com/mokuappio/serverless-invoices.git
synced 2026-02-09 01:12:38 -05: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:
@@ -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