#1040 ticket.step2

This commit is contained in:
Carlos Jimenez Ruiz 2019-01-25 12:52:12 +01:00
parent d19809c318
commit 5b252fbc47
3 changed files with 100 additions and 3 deletions

View File

@ -26,9 +26,9 @@
<tfoot>
<tr>
<td colspan="3"></td>
<td number><strong>{{$ctrl.ticket.sale.totalUnitPrice | currency: '€': 2}}</strong></td>
<td number><strong>{{$ctrl.ticket.sale.totalNewPrice | currency: '€': 2}}</strong></td>
<td number><strong>{{$ctrl.ticket.sale.totalDifference | currency: '€': 2}}</strong></td>
<td number><strong>{{$ctrl.totalPrice | currency: '€': 2}}</strong></td>
<td number><strong>{{$ctrl.totalNewPrice | currency: '€': 2}}</strong></td>
<td number><strong>{{$ctrl.totalPriceDifference | currency: '€': 2}}</strong></td>
</tr>
</tfoot>
</table>

View File

@ -7,11 +7,41 @@ class Controller {
$onInit() {
this.data.registerChild(this);
this.getTotalPrice();
this.getTotalNewPrice();
this.getTotalDifferenceOfPrice();
}
onStepChange(state) {
return true;
}
getTotalPrice() {
let totalPrice = 0;
this.ticket.sale.items.forEach(item => {
let itemTotalPrice = item.quantity * item.price;
totalPrice += itemTotalPrice;
});
this.totalPrice = totalPrice;
}
getTotalNewPrice() {
let totalNewPrice = 0;
this.ticket.sale.items.forEach(item => {
let itemTotalNewPrice = item.quantity * item.component.newPrice;
totalNewPrice += itemTotalNewPrice;
});
this.totalNewPrice = totalNewPrice;
}
getTotalDifferenceOfPrice() {
let totalPriceDifference = 0;
this.ticket.sale.items.forEach(item => {
let itemTotalPriceDifference = item.quantity * item.component.difference;
totalPriceDifference += itemTotalPriceDifference;
});
this.totalPriceDifference = totalPriceDifference;
}
}
Controller.$inject = ['$http'];

View File

@ -0,0 +1,67 @@
import './index.js';
describe('Ticket', () => {
describe('Component vnTicketDataStepTwo', () => {
let controller;
beforeEach(ngModule('ticket'));
beforeEach(angular.mock.inject($componentController => {
controller = $componentController('vnTicketDataStepTwo');
}));
describe('getTotalPrice()', () => {
it('should calculate the total price of the sale based on the data received', () => {
controller.ticket = {
sale: {
items: [{
quantity: 10,
price: 0.1,
component: {newPrice: 0.2, difference: 0.3}
}]
}
};
controller.getTotalPrice();
expect(controller.totalPrice).toEqual(1);
});
});
describe('getTotalNewPrice()', () => {
it('should calculate the total new price of the sale based on the data received', () => {
controller.ticket = {
sale: {
items: [{
quantity: 10,
price: 0.1,
component: {newPrice: 0.2, difference: 0.3}
}]
}
};
controller.getTotalNewPrice();
expect(controller.totalNewPrice).toEqual(2);
});
});
describe('getTotalDifferenceOfPrice()', () => {
it('should calculate the total price difference of the sale based on the data received', () => {
controller.ticket = {
sale: {
items: [{
quantity: 10,
price: 0.1,
component: {newPrice: 0.2, difference: 0.3}
}]
}
};
controller.getTotalDifferenceOfPrice();
expect(controller.totalPriceDifference).toEqual(3);
});
});
});
});