cr changes
This commit is contained in:
parent
ed926c39a1
commit
d4b6d7cd96
|
@ -1,5 +1,5 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('freightPorts', {
|
||||
Self.remoteMethod('freightCost', {
|
||||
description: 'Returns the freight cost of a ticket',
|
||||
accessType: 'READ',
|
||||
accepts: {
|
||||
|
@ -14,12 +14,12 @@ module.exports = Self => {
|
|||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/freightPorts`,
|
||||
path: `/:id/freightCost`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.freightPorts = async ticketFk => {
|
||||
Self.freightCost = async ticketFk => {
|
||||
const [freightCost] = await Self.rawSql(`SELECT vn.ticket_getFreightCost(?) total`, [ticketFk]);
|
||||
return freightCost.total;
|
||||
};
|
|
@ -1,6 +1,6 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('getComponentsSum', {
|
||||
description: 'Returns the list of component and their sum from a ticket',
|
||||
description: 'Returns a list of component and their sum from a ticket',
|
||||
accessType: 'READ',
|
||||
accepts: {
|
||||
arg: 'id',
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('ticket freightPorts()', () => {
|
||||
describe('ticket freightCost()', () => {
|
||||
it('should return the freight cost of a given ticket', async() => {
|
||||
let ticketId = 7;
|
||||
let freightCost = await app.models.Ticket.freightPorts(ticketId);
|
||||
let freightCost = await app.models.Ticket.freightCost(ticketId);
|
||||
|
||||
expect(freightCost).toBe(4);
|
||||
});
|
||||
|
||||
it('should return null if the ticket does not exist', async() => {
|
||||
let ticketId = 99;
|
||||
let freightCost = await app.models.Ticket.freightPorts(ticketId);
|
||||
let freightCost = await app.models.Ticket.freightCost(ticketId);
|
||||
|
||||
expect(freightCost).toBeNull();
|
||||
});
|
|
@ -2,16 +2,18 @@ const app = require('vn-loopback/server/server');
|
|||
|
||||
describe('ticket getComponentsSum()', () => {
|
||||
it('should get the list of component for the ticket sales', async() => {
|
||||
let ticketId = 7;
|
||||
let components = await app.models.Ticket.getComponentsSum(ticketId);
|
||||
const ticketId = 7;
|
||||
const components = await app.models.Ticket.getComponentsSum(ticketId);
|
||||
const length = components.length;
|
||||
const anyComponent = components[Math.floor(Math.random() * Math.floor(length))];
|
||||
|
||||
expect(components.length).toBeGreaterThan(0);
|
||||
expect(components[0].componentFk).toBe(22);
|
||||
expect(anyComponent.componentFk).toBeDefined();
|
||||
});
|
||||
|
||||
it('should return 0 if the given ticket does not have sales', async() => {
|
||||
let ticketWithoutSales = 21;
|
||||
let components = await app.models.Ticket.getComponentsSum(ticketWithoutSales);
|
||||
const ticketWithoutSales = 21;
|
||||
const components = await app.models.Ticket.getComponentsSum(ticketWithoutSales);
|
||||
|
||||
expect(components.length).toEqual(0);
|
||||
});
|
||||
|
|
|
@ -30,7 +30,7 @@ module.exports = Self => {
|
|||
require('../methods/ticket/deleteStowaway')(Self);
|
||||
require('../methods/ticket/sendSms')(Self);
|
||||
require('../methods/ticket/isLocked')(Self);
|
||||
require('../methods/ticket/freightPorts')(Self);
|
||||
require('../methods/ticket/freightCost')(Self);
|
||||
require('../methods/ticket/getComponentsSum')(Self);
|
||||
|
||||
Self.observe('before save', async function(ctx) {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<vn-thead>
|
||||
<vn-tr>
|
||||
<vn-th number>Item</vn-th>
|
||||
<vn-th style="text-align:center">Description</vn-th>
|
||||
<vn-th class="align-center">Description</vn-th>
|
||||
<vn-th number>Quantity</vn-th>
|
||||
<vn-th number>Price (PPU)</vn-th>
|
||||
<vn-th number>New (PPU)</vn-th>
|
||||
|
@ -42,15 +42,15 @@
|
|||
</vn-card>
|
||||
<vn-side-menu side="right">
|
||||
<div class="vn-pa-md">
|
||||
<div class="totalBox" style="text-align: left;">
|
||||
<h6 style="text-align: center;" translate>Total</h6>
|
||||
<div class="totalBox align-left">
|
||||
<h6 class="align-center" translate>Total</h6>
|
||||
<div> <vn-label translate>Price</vn-label> {{$ctrl.totalPrice | currency: 'EUR': 2}} </div>
|
||||
<div> <vn-label translate>New price</vn-label> {{$ctrl.totalNewPrice | currency: 'EUR': 2}} </div>
|
||||
<div> <vn-label translate>Difference</vn-label> {{$ctrl.totalPriceDifference | currency: 'EUR': 2}} </div>
|
||||
</div>
|
||||
<vn-card ng-show="::$ctrl.totalPriceDifference">
|
||||
<div class="totalBox" style="text-align: left;">
|
||||
<h6 style="text-align: center;" translate>Charge difference to</h6>
|
||||
<div class="totalBox align-left" >
|
||||
<h6 class="align-center" translate>Charge difference to</h6>
|
||||
<div ng-repeat="action in ticketUpdateActions">
|
||||
<vn-radio
|
||||
ng-model="$ctrl.ticket.option"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import ngModule from '../../module';
|
||||
import Component from 'core/lib/component';
|
||||
import './style.scss';
|
||||
|
||||
class Controller extends Component {
|
||||
$onInit() {
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
@import "variables";
|
||||
|
||||
.align-left {
|
||||
text-align: left
|
||||
}
|
||||
|
||||
.align-center {
|
||||
text-align: center
|
||||
}
|
|
@ -21,7 +21,7 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody ng-repeat="sale in components track by sale.id">
|
||||
<tr style="height: initial;">
|
||||
<tr class="initial">
|
||||
<td rowspan="{{::sale.components.length + 1}}" number>
|
||||
<span
|
||||
ng-click="descriptor.show($event, sale.itemFk, sale.id)"
|
||||
|
@ -62,27 +62,24 @@
|
|||
</vn-card>
|
||||
</vn-data-viewer>
|
||||
<vn-side-menu side="right">
|
||||
|
||||
<div class="totalBox" style="text-align: left;">
|
||||
<h6 style="text-align: center;" translate>Total</h6>
|
||||
<div> <vn-label translate>Base to commission</vn-label> {{$ctrl.base() | currency: 'EUR':2}} </div>
|
||||
<div> <vn-label translate>Total without VAT</vn-label> {{$ctrl.getTotal() | currency: 'EUR': 3}} </div>
|
||||
</div>
|
||||
<div class="totalBox" style="text-align: left;">
|
||||
<h6 style="text-align: center;" translate>Components</h6>
|
||||
<section ng-repeat="component in $ctrl.componentsList">
|
||||
<div>
|
||||
<vn-label>{{component.name}}</vn-label> {{component.value | currency: 'EUR': 3}}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<div class="totalBox" style="text-align: left;">
|
||||
<h6 style="text-align: center;" translate>Theorical port</h6>
|
||||
<div> <vn-label translate>Price</vn-label> {{$ctrl.theoricalPorts | currency: 'EUR': 2}} </div>
|
||||
</div>
|
||||
|
||||
<div class="totalBox align-left">
|
||||
<h6 class="align-center" translate>Total</h6>
|
||||
<div> <vn-label translate>Base to commission</vn-label> {{$ctrl.base() | currency: 'EUR':2}} </div>
|
||||
<div> <vn-label translate>Total without VAT</vn-label> {{$ctrl.getTotal() | currency: 'EUR': 3}} </div>
|
||||
</div>
|
||||
<div class="totalBox align-left">
|
||||
<h6 class="align-center" translate>Components</h6>
|
||||
<section ng-repeat="component in $ctrl.componentsList">
|
||||
<div>
|
||||
<vn-label>{{component.name}}</vn-label> {{component.value | currency: 'EUR': 3}}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<div class="totalBox align-left">
|
||||
<h6 class="align-center" translate>Theorical port</h6>
|
||||
<div> <vn-label translate>Price</vn-label> {{$ctrl.theoricalCost | currency: 'EUR': 2}} </div>
|
||||
</div>
|
||||
</vn-side-menu>
|
||||
|
||||
<vn-item-descriptor-popover
|
||||
vn-id="descriptor"
|
||||
warehouse-fk="$ctrl.ticket.warehouseFk">
|
||||
|
|
|
@ -37,7 +37,8 @@ class Controller extends Section {
|
|||
this._ticket = value;
|
||||
|
||||
if (!value) return;
|
||||
this.getTheoricalPorts();
|
||||
|
||||
this.getTheoricalCost();
|
||||
this.getComponentsSum();
|
||||
}
|
||||
|
||||
|
@ -56,7 +57,7 @@ class Controller extends Section {
|
|||
}
|
||||
|
||||
getTotal() {
|
||||
let sales = this.$.model.data;
|
||||
const sales = this.$.model.data;
|
||||
let total = 0;
|
||||
if (!sales) return;
|
||||
for (let sale of sales) {
|
||||
|
@ -66,9 +67,9 @@ class Controller extends Section {
|
|||
return total;
|
||||
}
|
||||
|
||||
getTheoricalPorts() {
|
||||
this.$http.get(`Tickets/${this.ticket.id}/freightPorts`)
|
||||
.then(res => this.theoricalPorts = res.data);
|
||||
getTheoricalCost() {
|
||||
this.$http.get(`Tickets/${this.ticket.id}/freightCost`)
|
||||
.then(res => this.theoricalCost = res.data);
|
||||
}
|
||||
|
||||
getComponentsSum() {
|
||||
|
|
|
@ -84,8 +84,8 @@ describe('ticket', () => {
|
|||
});
|
||||
|
||||
describe('ticket setter', () => {
|
||||
it('should set the ticket data and then call getTheoricalPorts() and getComponentsSum()', () => {
|
||||
jest.spyOn(controller, 'getTheoricalPorts');
|
||||
it('should set the ticket data and then call getTheoricalCost() and getComponentsSum()', () => {
|
||||
jest.spyOn(controller, 'getTheoricalCost');
|
||||
jest.spyOn(controller, 'getComponentsSum');
|
||||
controller._ticket = undefined;
|
||||
controller.ticket = {
|
||||
|
@ -93,7 +93,7 @@ describe('ticket', () => {
|
|||
};
|
||||
|
||||
expect(controller.ticket).toBeDefined();
|
||||
expect(controller.getTheoricalPorts).toHaveBeenCalledWith();
|
||||
expect(controller.getTheoricalCost).toHaveBeenCalledWith();
|
||||
expect(controller.getComponentsSum).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
@ -106,16 +106,16 @@ describe('ticket', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('getTheoricalPorts()', () => {
|
||||
describe('getTheoricalCost()', () => {
|
||||
it('should make a request to get the theorical port of a ticket', () => {
|
||||
controller._ticket = {
|
||||
id: 7
|
||||
};
|
||||
$httpBackend.expect('GET', `Tickets/${controller._ticket.id}/freightPorts`).respond('My freight port');
|
||||
controller.getTheoricalPorts();
|
||||
$httpBackend.expect('GET', `Tickets/${controller._ticket.id}/freightCost`).respond('My freight port');
|
||||
controller.getTheoricalCost();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.theoricalPorts).toBe('My freight port');
|
||||
expect(controller.theoricalCost).toBe('My freight port');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
Theorical port: Porte teorico
|
||||
Theorical cost: Porte teorico
|
||||
Total without VAT: Total sin IVA
|
|
@ -27,4 +27,16 @@ vn-ticket-components {
|
|||
.totalBox {
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
.align-left {
|
||||
text-align: left
|
||||
}
|
||||
|
||||
.align-center {
|
||||
text-align: center
|
||||
}
|
||||
|
||||
.initial {
|
||||
height: initial
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue