cr changes

This commit is contained in:
Bernat Exposito Domenech 2020-09-09 15:49:59 +02:00
parent ed926c39a1
commit d4b6d7cd96
13 changed files with 74 additions and 52 deletions

View File

@ -1,5 +1,5 @@
module.exports = Self => { module.exports = Self => {
Self.remoteMethod('freightPorts', { Self.remoteMethod('freightCost', {
description: 'Returns the freight cost of a ticket', description: 'Returns the freight cost of a ticket',
accessType: 'READ', accessType: 'READ',
accepts: { accepts: {
@ -14,12 +14,12 @@ module.exports = Self => {
root: true root: true
}, },
http: { http: {
path: `/:id/freightPorts`, path: `/:id/freightCost`,
verb: 'GET' verb: 'GET'
} }
}); });
Self.freightPorts = async ticketFk => { Self.freightCost = async ticketFk => {
const [freightCost] = await Self.rawSql(`SELECT vn.ticket_getFreightCost(?) total`, [ticketFk]); const [freightCost] = await Self.rawSql(`SELECT vn.ticket_getFreightCost(?) total`, [ticketFk]);
return freightCost.total; return freightCost.total;
}; };

View File

@ -1,6 +1,6 @@
module.exports = Self => { module.exports = Self => {
Self.remoteMethod('getComponentsSum', { 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', accessType: 'READ',
accepts: { accepts: {
arg: 'id', arg: 'id',

View File

@ -1,16 +1,16 @@
const app = require('vn-loopback/server/server'); const app = require('vn-loopback/server/server');
describe('ticket freightPorts()', () => { describe('ticket freightCost()', () => {
it('should return the freight cost of a given ticket', async() => { it('should return the freight cost of a given ticket', async() => {
let ticketId = 7; let ticketId = 7;
let freightCost = await app.models.Ticket.freightPorts(ticketId); let freightCost = await app.models.Ticket.freightCost(ticketId);
expect(freightCost).toBe(4); expect(freightCost).toBe(4);
}); });
it('should return null if the ticket does not exist', async() => { it('should return null if the ticket does not exist', async() => {
let ticketId = 99; let ticketId = 99;
let freightCost = await app.models.Ticket.freightPorts(ticketId); let freightCost = await app.models.Ticket.freightCost(ticketId);
expect(freightCost).toBeNull(); expect(freightCost).toBeNull();
}); });

View File

@ -2,16 +2,18 @@ const app = require('vn-loopback/server/server');
describe('ticket getComponentsSum()', () => { describe('ticket getComponentsSum()', () => {
it('should get the list of component for the ticket sales', async() => { it('should get the list of component for the ticket sales', async() => {
let ticketId = 7; const ticketId = 7;
let components = await app.models.Ticket.getComponentsSum(ticketId); 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.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() => { it('should return 0 if the given ticket does not have sales', async() => {
let ticketWithoutSales = 21; const ticketWithoutSales = 21;
let components = await app.models.Ticket.getComponentsSum(ticketWithoutSales); const components = await app.models.Ticket.getComponentsSum(ticketWithoutSales);
expect(components.length).toEqual(0); expect(components.length).toEqual(0);
}); });

View File

@ -30,7 +30,7 @@ module.exports = Self => {
require('../methods/ticket/deleteStowaway')(Self); require('../methods/ticket/deleteStowaway')(Self);
require('../methods/ticket/sendSms')(Self); require('../methods/ticket/sendSms')(Self);
require('../methods/ticket/isLocked')(Self); require('../methods/ticket/isLocked')(Self);
require('../methods/ticket/freightPorts')(Self); require('../methods/ticket/freightCost')(Self);
require('../methods/ticket/getComponentsSum')(Self); require('../methods/ticket/getComponentsSum')(Self);
Self.observe('before save', async function(ctx) { Self.observe('before save', async function(ctx) {

View File

@ -8,7 +8,7 @@
<vn-thead> <vn-thead>
<vn-tr> <vn-tr>
<vn-th number>Item</vn-th> <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>Quantity</vn-th>
<vn-th number>Price (PPU)</vn-th> <vn-th number>Price (PPU)</vn-th>
<vn-th number>New (PPU)</vn-th> <vn-th number>New (PPU)</vn-th>
@ -42,15 +42,15 @@
</vn-card> </vn-card>
<vn-side-menu side="right"> <vn-side-menu side="right">
<div class="vn-pa-md"> <div class="vn-pa-md">
<div class="totalBox" style="text-align: left;"> <div class="totalBox align-left">
<h6 style="text-align: center;" translate>Total</h6> <h6 class="align-center" translate>Total</h6>
<div> <vn-label translate>Price</vn-label> {{$ctrl.totalPrice | currency: 'EUR': 2}} </div> <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>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-label translate>Difference</vn-label> {{$ctrl.totalPriceDifference | currency: 'EUR': 2}} </div>
</div> </div>
<vn-card ng-show="::$ctrl.totalPriceDifference"> <vn-card ng-show="::$ctrl.totalPriceDifference">
<div class="totalBox" style="text-align: left;"> <div class="totalBox align-left" >
<h6 style="text-align: center;" translate>Charge difference to</h6> <h6 class="align-center" translate>Charge difference to</h6>
<div ng-repeat="action in ticketUpdateActions"> <div ng-repeat="action in ticketUpdateActions">
<vn-radio <vn-radio
ng-model="$ctrl.ticket.option" ng-model="$ctrl.ticket.option"

View File

@ -1,5 +1,6 @@
import ngModule from '../../module'; import ngModule from '../../module';
import Component from 'core/lib/component'; import Component from 'core/lib/component';
import './style.scss';
class Controller extends Component { class Controller extends Component {
$onInit() { $onInit() {

View File

@ -0,0 +1,9 @@
@import "variables";
.align-left {
text-align: left
}
.align-center {
text-align: center
}

View File

@ -21,7 +21,7 @@
</tr> </tr>
</thead> </thead>
<tbody ng-repeat="sale in components track by sale.id"> <tbody ng-repeat="sale in components track by sale.id">
<tr style="height: initial;"> <tr class="initial">
<td rowspan="{{::sale.components.length + 1}}" number> <td rowspan="{{::sale.components.length + 1}}" number>
<span <span
ng-click="descriptor.show($event, sale.itemFk, sale.id)" ng-click="descriptor.show($event, sale.itemFk, sale.id)"
@ -62,27 +62,24 @@
</vn-card> </vn-card>
</vn-data-viewer> </vn-data-viewer>
<vn-side-menu side="right"> <vn-side-menu side="right">
<div class="totalBox align-left">
<div class="totalBox" style="text-align: left;"> <h6 class="align-center" translate>Total</h6>
<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>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> <vn-label translate>Total without VAT</vn-label> {{$ctrl.getTotal() | currency: 'EUR': 3}} </div> </div>
</div> <div class="totalBox align-left">
<div class="totalBox" style="text-align: left;"> <h6 class="align-center" translate>Components</h6>
<h6 style="text-align: center;" translate>Components</h6> <section ng-repeat="component in $ctrl.componentsList">
<section ng-repeat="component in $ctrl.componentsList"> <div>
<div> <vn-label>{{component.name}}</vn-label> {{component.value | currency: 'EUR': 3}}
<vn-label>{{component.name}}</vn-label> {{component.value | currency: 'EUR': 3}} </div>
</div> </section>
</section> </div>
</div> <div class="totalBox align-left">
<div class="totalBox" style="text-align: left;"> <h6 class="align-center" translate>Theorical port</h6>
<h6 style="text-align: center;" translate>Theorical port</h6> <div> <vn-label translate>Price</vn-label> {{$ctrl.theoricalCost | currency: 'EUR': 2}} </div>
<div> <vn-label translate>Price</vn-label> {{$ctrl.theoricalPorts | currency: 'EUR': 2}} </div> </div>
</div>
</vn-side-menu> </vn-side-menu>
<vn-item-descriptor-popover <vn-item-descriptor-popover
vn-id="descriptor" vn-id="descriptor"
warehouse-fk="$ctrl.ticket.warehouseFk"> warehouse-fk="$ctrl.ticket.warehouseFk">

View File

@ -37,7 +37,8 @@ class Controller extends Section {
this._ticket = value; this._ticket = value;
if (!value) return; if (!value) return;
this.getTheoricalPorts();
this.getTheoricalCost();
this.getComponentsSum(); this.getComponentsSum();
} }
@ -56,7 +57,7 @@ class Controller extends Section {
} }
getTotal() { getTotal() {
let sales = this.$.model.data; const sales = this.$.model.data;
let total = 0; let total = 0;
if (!sales) return; if (!sales) return;
for (let sale of sales) { for (let sale of sales) {
@ -66,9 +67,9 @@ class Controller extends Section {
return total; return total;
} }
getTheoricalPorts() { getTheoricalCost() {
this.$http.get(`Tickets/${this.ticket.id}/freightPorts`) this.$http.get(`Tickets/${this.ticket.id}/freightCost`)
.then(res => this.theoricalPorts = res.data); .then(res => this.theoricalCost = res.data);
} }
getComponentsSum() { getComponentsSum() {

View File

@ -84,8 +84,8 @@ describe('ticket', () => {
}); });
describe('ticket setter', () => { describe('ticket setter', () => {
it('should set the ticket data and then call getTheoricalPorts() and getComponentsSum()', () => { it('should set the ticket data and then call getTheoricalCost() and getComponentsSum()', () => {
jest.spyOn(controller, 'getTheoricalPorts'); jest.spyOn(controller, 'getTheoricalCost');
jest.spyOn(controller, 'getComponentsSum'); jest.spyOn(controller, 'getComponentsSum');
controller._ticket = undefined; controller._ticket = undefined;
controller.ticket = { controller.ticket = {
@ -93,7 +93,7 @@ describe('ticket', () => {
}; };
expect(controller.ticket).toBeDefined(); expect(controller.ticket).toBeDefined();
expect(controller.getTheoricalPorts).toHaveBeenCalledWith(); expect(controller.getTheoricalCost).toHaveBeenCalledWith();
expect(controller.getComponentsSum).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', () => { it('should make a request to get the theorical port of a ticket', () => {
controller._ticket = { controller._ticket = {
id: 7 id: 7
}; };
$httpBackend.expect('GET', `Tickets/${controller._ticket.id}/freightPorts`).respond('My freight port'); $httpBackend.expect('GET', `Tickets/${controller._ticket.id}/freightCost`).respond('My freight port');
controller.getTheoricalPorts(); controller.getTheoricalCost();
$httpBackend.flush(); $httpBackend.flush();
expect(controller.theoricalPorts).toBe('My freight port'); expect(controller.theoricalCost).toBe('My freight port');
}); });
}); });

View File

@ -1,2 +1,2 @@
Theorical port: Porte teorico Theorical cost: Porte teorico
Total without VAT: Total sin IVA Total without VAT: Total sin IVA

View File

@ -27,4 +27,16 @@ vn-ticket-components {
.totalBox { .totalBox {
max-width: none; max-width: none;
} }
.align-left {
text-align: left
}
.align-center {
text-align: center
}
.initial {
height: initial
}
} }