Display sale taxes #342
This commit is contained in:
parent
0822f3ce53
commit
8f6a88f9b6
|
@ -1,4 +1,4 @@
|
||||||
<mg-ajax path="/ticket/api/sales/filter" options="vnIndexNonAuto"></mg-ajax>
|
<mg-ajax path="/ticket/api/sales/filter" options="vnIndexNonAuto" actions="$ctrl.getTaxes()"></mg-ajax>
|
||||||
<vn-vertical>
|
<vn-vertical>
|
||||||
<vn-card pad-large>
|
<vn-card pad-large>
|
||||||
<vn-vertical>
|
<vn-vertical>
|
||||||
|
@ -98,6 +98,17 @@
|
||||||
<tr ng-if="index.model.count === 0" class="list list-element">
|
<tr ng-if="index.model.count === 0" class="list list-element">
|
||||||
<td colspan="8" style="text-align: center" translate>No results</td>
|
<td colspan="8" style="text-align: center" translate>No results</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<td number colspan="8">
|
||||||
|
<section>
|
||||||
|
<p><vn-label translate>Subtotal</vn-label> {{$ctrl.subTotal | currency:' €':2}}</p>
|
||||||
|
<p><vn-label translate>VAT</vn-label> {{$ctrl.VAT | currency:' €':2}}</p>
|
||||||
|
<p><vn-label><strong>Total</strong></vn-label> <strong>{{$ctrl.total | currency:' €':2}}</strong></p>
|
||||||
|
</section>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</vn-vertical>
|
</vn-vertical>
|
||||||
|
|
|
@ -18,6 +18,29 @@ class Controller extends FilterTicketList {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getTaxes() {
|
||||||
|
this.getSubTotal();
|
||||||
|
this.getVAT();
|
||||||
|
}
|
||||||
|
|
||||||
|
getSubTotal() {
|
||||||
|
let sales = this.$.index.model.instances;
|
||||||
|
|
||||||
|
this.subTotal = 0.00;
|
||||||
|
sales.forEach(sale => {
|
||||||
|
this.subTotal += sale.quantity * sale.price;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getVAT() {
|
||||||
|
this.$http.get(`/ticket/api/Tickets/${this.ticket.id}/getVAT`).then(res => {
|
||||||
|
if (res.data) {
|
||||||
|
this.VAT = res.data;
|
||||||
|
this.total = this.subTotal + this.VAT;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
get isEditable() {
|
get isEditable() {
|
||||||
try {
|
try {
|
||||||
return !this.ticket.tracking.state.alertLevel;
|
return !this.ticket.tracking.state.alertLevel;
|
||||||
|
|
|
@ -46,10 +46,9 @@
|
||||||
<vn-one class="ticketSummary__taxes">
|
<vn-one class="ticketSummary__taxes">
|
||||||
<section>
|
<section>
|
||||||
<p><vn-label translate>Subtotal</vn-label> {{$ctrl.summary.subTotal | currency:' €':2}}</p>
|
<p><vn-label translate>Subtotal</vn-label> {{$ctrl.summary.subTotal | currency:' €':2}}</p>
|
||||||
<p><vn-label translate>VAT</vn-label> {{$ctrl.summary.totalTax | currency:' €':2}}</p>
|
<p><vn-label translate>VAT</vn-label> {{$ctrl.summary.VAT | currency:' €':2}}</p>
|
||||||
<p><vn-label><strong>Total</strong></vn-label> <strong>{{$ctrl.summary.total | currency:' €':2}}</strong></p>
|
<p><vn-label><strong>Total</strong></vn-label> <strong>{{$ctrl.summary.total | currency:' €':2}}</strong></p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
</vn-one>
|
</vn-one>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('getVAT', {
|
||||||
|
description: 'Returns ticket total VAT',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'ticket id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
}],
|
||||||
|
returns: {
|
||||||
|
type: 'number',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/:id/getVAT`,
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.getVAT = async ticketFk => {
|
||||||
|
let totalTax = 0.00;
|
||||||
|
let taxes = await Self.app.models.Ticket.getTaxes(ticketFk);
|
||||||
|
|
||||||
|
taxes.forEach(tax => {
|
||||||
|
totalTax += tax.tax;
|
||||||
|
});
|
||||||
|
|
||||||
|
return totalTax;
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,19 @@
|
||||||
|
const app = require(`${servicesDir}/ticket/server/server`);
|
||||||
|
|
||||||
|
describe('ticket getVAT()', () => {
|
||||||
|
it('should call the getVAT method and return the response', done => {
|
||||||
|
app.models.Ticket.getVAT(1)
|
||||||
|
.then(response => {
|
||||||
|
expect(response).toEqual(37.55);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should call the getVAT method and return zero if doesn't have lines`, done => {
|
||||||
|
app.models.Ticket.getVAT(13)
|
||||||
|
.then(response => {
|
||||||
|
expect(response).toEqual(0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -24,7 +24,7 @@ module.exports = Self => {
|
||||||
let summaryObj = await getTicketData(Self, ticketFk);
|
let summaryObj = await getTicketData(Self, ticketFk);
|
||||||
summaryObj.sales = await getSales(models.Sale, ticketFk);
|
summaryObj.sales = await getSales(models.Sale, ticketFk);
|
||||||
summaryObj.subTotal = getSubTotal(summaryObj.sales);
|
summaryObj.subTotal = getSubTotal(summaryObj.sales);
|
||||||
summaryObj.totalTax = await getTotalTax(models.Ticket, ticketFk);
|
summaryObj.VAT = await models.Ticket.getVAT(ticketFk);
|
||||||
summaryObj.total = await models.Ticket.getTotal(ticketFk);
|
summaryObj.total = await models.Ticket.getTotal(ticketFk);
|
||||||
|
|
||||||
return summaryObj;
|
return summaryObj;
|
||||||
|
@ -112,15 +112,4 @@ module.exports = Self => {
|
||||||
|
|
||||||
return subTotal;
|
return subTotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getTotalTax(ticket, ticketFk) {
|
|
||||||
let totalTax = 0.00;
|
|
||||||
let taxes = await ticket.getTaxes(ticketFk);
|
|
||||||
|
|
||||||
taxes.forEach(tax => {
|
|
||||||
totalTax += tax.tax;
|
|
||||||
});
|
|
||||||
|
|
||||||
return totalTax;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,4 +11,5 @@ module.exports = Self => {
|
||||||
require('../methods/ticket/isEditable')(Self);
|
require('../methods/ticket/isEditable')(Self);
|
||||||
require('../methods/ticket/threeLastActive')(Self);
|
require('../methods/ticket/threeLastActive')(Self);
|
||||||
require('../methods/ticket/deleted')(Self);
|
require('../methods/ticket/deleted')(Self);
|
||||||
|
require('../methods/ticket/getVAT')(Self);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue