Merge branch 'dev' of https://git.verdnatura.es/salix into dev

This commit is contained in:
gerard 2018-09-24 12:13:11 +02:00
commit abaab3e34a
57 changed files with 709 additions and 504 deletions

View File

@ -4,18 +4,19 @@ import './style.scss';
export default class InputTime extends Textfield { export default class InputTime extends Textfield {
constructor($element, $scope, $attrs, vnTemplate, $transclude, $filter) {
super($element, $scope, $attrs, vnTemplate, $transclude);
this.$filter = $filter;
}
get value() { get value() {
return this._value; return this._value;
} }
set value(value) { set value(value) {
this._value = value; if (!value) return;
let newDate = new Date(value);
newDate.setSeconds(0);
newDate.setMilliseconds(0);
this._value = newDate;
this.hasValue = this._value !== null; this.hasValue = this._value !== null;
if (this.hasValue) this.element.classList.add('not-empty'); if (this.hasValue) this.element.classList.add('not-empty');
@ -24,7 +25,7 @@ export default class InputTime extends Textfield {
} }
get step() { get step() {
return parseFloat(this.input.step); return parseInt(this.input.step);
} }
set step(value) { set step(value) {
@ -32,7 +33,7 @@ export default class InputTime extends Textfield {
} }
} }
InputTime.$inject = ['$element', '$scope', '$attrs', 'vnTemplate', '$transclude', '$filter']; InputTime.$inject = ['$element', '$scope', '$attrs', 'vnTemplate', '$transclude'];
ngModule.component('vnInputTime', { ngModule.component('vnInputTime', {
template: require('./index.html'), template: require('./index.html'),

View File

@ -1,18 +1,22 @@
<form ng-submit="$ctrl.onSubmit()"> <form ng-submit="$ctrl.onSubmit()">
<vn-horizontal> <vn-horizontal>
<vn-icon-button <vn-textfield vn-one label="Search" model="$ctrl.searchString">
icon="search" <t-left-icons>
ng-click="$ctrl.clearFilter(); $ctrl.onSubmit()" <vn-icon
style="cursor: pointer; padding-top: 23px"> icon="search"
</vn-icon-button> ng-click="$ctrl.clearFilter(); $ctrl.onSubmit()"
<vn-textfield vn-one label="Search" model="$ctrl.searchString"></vn-textfield> pointer>
<vn-icon </vn-icon>
pad-medium-top </t-left-icons>
ng-if="$ctrl.panel" <t-right-icons>
ng-click="$ctrl.openPanel($event)" <vn-icon
icon="keyboard_arrow_down" ng-if="$ctrl.panel"
style="cursor: pointer; color: #aaa"> ng-click="$ctrl.openPanel($event)"
</vn-icon> icon="keyboard_arrow_down"
pointer>
</vn-icon>
</t-right-icons>
</vn-textfield>
</vn-horizontal> </vn-horizontal>
</form> </form>
<vn-popover <vn-popover

View File

@ -17,6 +17,7 @@ vn-textfield {
padding-top: 4px; padding-top: 4px;
} }
} }
.leftIcons, .rightIcons, .suffix { .leftIcons, .rightIcons, .suffix {
display: flex; display: flex;
color: $secondary-font-color; color: $secondary-font-color;
@ -25,7 +26,17 @@ vn-textfield {
font-size: 20px !important font-size: 20px !important
} }
} }
t-left-icons {
padding-right: 0.5em
}
t-right-icons {
padding-left: 0.5em
}
.infix { .infix {
position: relative;
display: block; display: block;
flex: auto; flex: auto;
width: 100%; width: 100%;

View File

@ -223,13 +223,15 @@ export default class Watcher extends Component {
let newCopy = {}; let newCopy = {};
if (data && typeof data === 'object') { if (data && typeof data === 'object') {
Object.keys(data).forEach( Object.keys(data).forEach(
val => { key => {
if (!isFullEmpty(data[val])) { let value = data[key];
if (typeof data[val] === 'object') { if (value instanceof Date)
newCopy[val] = this.copyInNewObject(data[val]); newCopy[key] = new Date(value.getTime());
} else { else if (!isFullEmpty(value)) {
newCopy[val] = data[val]; if (typeof value === 'object')
} newCopy[key] = this.copyInNewObject(value);
else
newCopy[key] = value;
} }
} }
); );

View File

@ -2,15 +2,17 @@ import isEqual from './equals';
export default function getModifiedData(object, objectOld) { export default function getModifiedData(object, objectOld) {
var newObject = {}; var newObject = {};
if (objectOld === null) { if (objectOld === null)
return object; return object;
}
for (var k in object) { for (var k in object) {
var val = object[k]; var val = object[k];
var valOld = objectOld[k] === undefined ? null : objectOld[k]; var valOld = objectOld[k] === undefined ? null : objectOld[k];
if (!isEqual(val, valOld)) { if (!isEqual(val, valOld)) {
if (val instanceof Object) { if (val instanceof Date) {
newObject[k] = new Date(val.getTime());
} else if (val instanceof Object) {
newObject[k] = getModifiedData(val, valOld); newObject[k] = getModifiedData(val, valOld);
} else { } else {
newObject[k] = val; newObject[k] = val;

View File

@ -50,7 +50,7 @@
"component": "vn-zone-basic-data", "component": "vn-zone-basic-data",
"description": "Basic data", "description": "Basic data",
"params": { "params": {
"client": "$ctrl.client" "zone": "$ctrl.zone"
}, },
"menu": { "menu": {
"icon": "settings" "icon": "settings"

View File

@ -6,3 +6,5 @@ import './zone/descriptor';
import './zone/search-panel'; import './zone/search-panel';
import './zone/index'; import './zone/index';
import './zone/create'; import './zone/create';
import './zone/basic-data';

View File

@ -0,0 +1,67 @@
<mg-ajax path="/route/api/Zones/{{patch.params.id}}" options="vnPatch"></mg-ajax>
<vn-watcher
vn-id="watcher"
data="$ctrl.zone"
form="form"
save="patch">
</vn-watcher>
<form name="form" ng-submit="$ctrl.onSubmit()">
<vn-card pad-large>
<vn-title>Basic data</vn-title>
<vn-horizontal>
<vn-textfield vn-two vn-focus
label="Name"
field="$ctrl.zone.name">
</vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
field="$ctrl.zone.warehouseFk"
url="/route/api/Warehouses"
show-field="name"
value-field="id"
label="Warehouse">
</vn-autocomplete>
<vn-autocomplete
vn-one
field="$ctrl.zone.agencyModeFk"
url="/route/api/AgencyModes"
show-field="name"
value-field="id"
label="Agency">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-input-number
vn-two
min="0"
step="1"
label="Traveling days"
field="$ctrl.zone.travelingDays">
</vn-input-number>
<vn-input-time
vn-two
label="Estimated hour (ETD)"
field="$ctrl.zone.hour">
</vn-input-time>
</vn-horizontal>
<vn-horizontal>
<vn-input-number vn-one
label="Price"
field="$ctrl.zone.price"
min="0.00"
step="0.50">
</vn-input-number>
<vn-input-number vn-one
label="Bonus"
field="$ctrl.zone.bonus"
min="0.00"
step="0.50">
</vn-input-number>
</vn-horizontal>
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
</vn-button-bar>
</form>

View File

@ -0,0 +1,27 @@
import ngModule from '../../module';
class Controller {
constructor($scope) {
this.$scope = $scope;
}
onSubmit() {
this.$scope.watcher.submit().then(() => {
this.card.reload();
});
}
}
Controller.$inject = ['$scope'];
ngModule.component('vnZoneBasicData', {
template: require('./index.html'),
controller: Controller,
bindings: {
zone: '<'
},
require: {
card: '^vnZoneCard'
}
});

View File

@ -1,7 +1,7 @@
<vn-main-block> <vn-main-block>
<vn-horizontal> <vn-horizontal>
<vn-auto class="left-block"> <vn-auto class="left-block">
<vn-zone-descriptor order="$ctrl.zone"></vn-zone-descriptor> <vn-zone-descriptor zone="$ctrl.zone"></vn-zone-descriptor>
<vn-left-menu></vn-left-menu> <vn-left-menu></vn-left-menu>
</vn-auto> </vn-auto>
<vn-one> <vn-one>

View File

@ -1,58 +1,36 @@
import ngModule from '../../module'; import ngModule from '../../module';
class Controller { class Controller {
constructor($http, $state) { constructor($http, $stateParams) {
this.$http = $http; this.$http = $http;
this.$state = $state; this.$stateParams = $stateParams;
this.order = {}; }
this.filter = {
$onInit() {
this.getCard();
}
getCard() {
let filter = {
include: [ include: [
{relation: 'agencyMode', scope: {fields: ['name']}}, {relation: 'warehouse', fields: ['name']},
{relation: 'address', scope: {fields: ['nickname']}}, {relation: 'agencyMode', fields: ['name']}
{relation: 'rows', scope: {fields: ['id']}},
{
relation: 'client',
scope: {
fields: ['salesPersonFk', 'name', 'isActive', 'isFreezed', 'isTaxDataChecked'],
include: {
relation: 'salesPerson',
fields: ['firstName', 'name']
}
}
}
] ]
}; };
} let json = encodeURIComponent(JSON.stringify(filter));
let query = `/route/api/Zones/${this.$stateParams.id}?filter=${json}`;
/* getOrder() {
let json = encodeURIComponent(JSON.stringify(this.filter));
let query = `/order/api/Orders/${this.$state.params.id}?filter=${json}`;
this.$http.get(query).then(res => { this.$http.get(query).then(res => {
if (res.data) { if (res.data)
this.order = res.data; this.zone = res.data;
this.getTotal();
}
}); });
} }
getTotal() {
let query = `/order/api/Orders/${this.$state.params.id}/getTotal`;
this.$http.get(query).then(res => {
if (res.data) {
this.order.total = res.data.total;
}
});
}
$onInit() {
this.getOrder();
}
reload() { reload() {
this.getOrder(); this.getCard();
} */ }
} }
Controller.$inject = ['$http', '$state']; Controller.$inject = ['$http', '$stateParams'];
ngModule.component('vnZoneCard', { ngModule.component('vnZoneCard', {
template: require('./index.html'), template: require('./index.html'),

View File

@ -1,15 +1,15 @@
import './index.js'; import './index.js';
describe('Order', () => { describe('Route', () => {
describe('Component vnOrderCard', () => { describe('Component vnZoneCard', () => {
let $componentController; let $componentController;
let $scope; let $scope;
let controller; let controller;
let $httpBackend; let $httpBackend;
let $state; let $stateParams;
beforeEach(() => { beforeEach(() => {
angular.mock.module('order'); angular.mock.module('route');
}); });
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_) => { beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_) => {
@ -17,50 +17,24 @@ describe('Order', () => {
$httpBackend = _$httpBackend_; $httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({}); $httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
$scope = $rootScope.$new(); $scope = $rootScope.$new();
$scope.card = {createOrder: () => {}}; $stateParams = {id: 1};
$state = {params: {id: 1}}; controller = $componentController('vnZoneCard', {$scope: $scope, $stateParams});
controller = $componentController('vnOrderCard', {$scope: $scope, $state: $state});
})); }));
describe('getOrder()', () => { describe('getCard()', () => {
it(`should make a query, save the data in order and call get order if the response has data`, () => { it(`should make a query and define zone property`, () => {
spyOn(controller, 'getTotal'); let filter = {
let json = encodeURIComponent(JSON.stringify(controller.filter)); include: [
$httpBackend.expectGET(`/order/api/Orders/${controller.$state.params.id}?filter=${json}`).respond({id: 1}); {relation: 'warehouse', fields: ['name']},
controller.getOrder(); {relation: 'agencyMode', fields: ['name']}
]
};
let json = encodeURIComponent(JSON.stringify(filter));
$httpBackend.expectGET(`/route/api/Zones/1?filter=${json}`).respond({id: 1});
controller.getCard();
$httpBackend.flush(); $httpBackend.flush();
expect(controller.order).toEqual({id: 1}); expect(controller.zone).toEqual({id: 1});
expect(controller.getTotal).toHaveBeenCalledWith();
});
it(`should make a query and not call getTotal if the response is not defined`, () => {
spyOn(controller, 'getTotal');
let json = encodeURIComponent(JSON.stringify(controller.filter));
$httpBackend.expectGET(`/order/api/Orders/${controller.$state.params.id}?filter=${json}`).respond(undefined);
controller.getOrder();
$httpBackend.flush();
expect(controller.order).toEqual({});
expect(controller.getTotal).not.toHaveBeenCalledWith();
});
});
describe('getTotal()', () => {
it(`should make a query and save the data in order.total`, () => {
$httpBackend.expectGET(`/order/api/Orders/${controller.$state.params.id}/getTotal`).respond({total: '20M'});
controller.getTotal();
$httpBackend.flush();
expect(controller.order.total).toEqual('20M');
});
it(`should make a query and not save the respones if is not defined`, () => {
$httpBackend.expectGET(`/order/api/Orders/${controller.$state.params.id}/getTotal`).respond();
controller.getTotal();
$httpBackend.flush();
expect(controller.order.total).toEqual(undefined);
}); });
}); });
}); });

View File

@ -9,11 +9,26 @@
</a> </a>
</vn-horizontal> </vn-horizontal>
<div pad-medium> <div pad-medium>
<vn-label-value label="ID" <vn-label-value label="Id"
value="{{$ctrl.zone.id}}"> value="{{$ctrl.zone.id}}">
</vn-label-value> </vn-label-value>
<vn-label-value label="Client" <vn-label-value label="Name"
value="{{$ctrl.order.client.name}}"> value="{{$ctrl.zone.name}}">
</vn-label-value>
<vn-label-value label="Warehouse"
value="{{$ctrl.zone.warehouse.name}}">
</vn-label-value>
<vn-label-value label="Agency"
value="{{$ctrl.zone.agencyMode.name}}">
</vn-label-value>
<vn-label-value label="Estimated hour (ETD)"
value="{{$ctrl.zone.hour | date: 'HH:mm'}}">
</vn-label-value>
<vn-label-value label="Price"
value="{{$ctrl.zone.price | currency: '€': 2}}">
</vn-label-value>
<vn-label-value label="Bonus"
value="{{$ctrl.zone.price | currency: '€': 2}}">
</vn-label-value> </vn-label-value>
</div> </div>
</vn-card> </vn-card>

View File

@ -1,18 +1,8 @@
import ngModule from '../../module'; import ngModule from '../../module';
import './style.scss';
class Controller {
constructor($translate) {
this.translate = $translate;
}
}
Controller.$inject = ['$translate'];
ngModule.component('vnZoneDescriptor', { ngModule.component('vnZoneDescriptor', {
template: require('./index.html'), template: require('./index.html'),
bindings: { bindings: {
order: '<' zone: '<'
}, }
controller: Controller
}); });

View File

@ -1,8 +0,0 @@
Client: Cliente
Confirmed: Confirmado
Not confirmed: Sin confirmar
State: Estado
Landed: F. entrega
Items: Articulos
Agency: Agencia
Sales person: Comercial

View File

@ -1,5 +0,0 @@
vn-label-value[label=Total]{
padding-top: 10px;
display: block;
font-size: 1.2em;
}

View File

@ -18,7 +18,7 @@ export default {
}, },
clientsIndex: { clientsIndex: {
searchClientInput: `${components.vnTextfield}`, searchClientInput: `${components.vnTextfield}`,
searchButton: `vn-searchbar vn-icon-button[icon="search"]`, searchButton: `vn-searchbar vn-icon[icon="search"]`,
searchResult: `vn-item-client a`, searchResult: `vn-item-client a`,
createClientButton: `${components.vnFloatButton}` createClientButton: `${components.vnFloatButton}`
}, },
@ -161,7 +161,7 @@ export default {
searchResultCloneButton: `vn-item-product .buttons > [icon="icon-clone"]`, searchResultCloneButton: `vn-item-product .buttons > [icon="icon-clone"]`,
acceptClonationAlertButton: `vn-item-index [vn-id="clone"] [response="ACCEPT"]`, acceptClonationAlertButton: `vn-item-index [vn-id="clone"] [response="ACCEPT"]`,
searchItemInput: `${components.vnTextfield}`, searchItemInput: `${components.vnTextfield}`,
searchButton: `vn-searchbar vn-icon-button[icon="search"]`, searchButton: `vn-searchbar vn-icon[icon="search"]`,
closeItemSummaryPreview: 'vn-item-index [vn-id="preview"] button.close' closeItemSummaryPreview: 'vn-item-index [vn-id="preview"] button.close'
}, },
itemCreateView: { itemCreateView: {
@ -278,7 +278,7 @@ export default {
searchResultDate: `vn-ticket-index vn-table vn-tbody > a:nth-child(1) > vn-td:nth-child(4)`, searchResultDate: `vn-ticket-index vn-table vn-tbody > a:nth-child(1) > vn-td:nth-child(4)`,
searchResultAddress: `vn-ticket-index vn-table vn-tbody > a:nth-child(1) > vn-td:nth-child(6)`, searchResultAddress: `vn-ticket-index vn-table vn-tbody > a:nth-child(1) > vn-td:nth-child(6)`,
searchTicketInput: `vn-ticket-index ${components.vnTextfield}`, searchTicketInput: `vn-ticket-index ${components.vnTextfield}`,
searchButton: `vn-ticket-index vn-searchbar vn-icon-button[icon="search"]` searchButton: `vn-ticket-index vn-searchbar vn-icon[icon="search"]`
}, },
ticketNotes: { ticketNotes: {
notesButton: `vn-menu-item a[ui-sref="ticket.card.observation"]`, notesButton: `vn-menu-item a[ui-sref="ticket.card.observation"]`,
@ -367,7 +367,7 @@ export default {
addressSelect: `vn-autocomplete[field="$ctrl.ticket.addressFk"] input`, addressSelect: `vn-autocomplete[field="$ctrl.ticket.addressFk"] input`,
addressSelectSecondOption: `vn-autocomplete[field="$ctrl.ticket.addressFk"] vn-drop-down ul > li:nth-child(2)`, addressSelectSecondOption: `vn-autocomplete[field="$ctrl.ticket.addressFk"] vn-drop-down ul > li:nth-child(2)`,
agencySelect: `vn-autocomplete[field="$ctrl.ticket.agencyModeFk"] input`, agencySelect: `vn-autocomplete[field="$ctrl.ticket.agencyModeFk"] input`,
agencySelectFifthOption: `vn-autocomplete[field="$ctrl.ticket.agencyModeFk"] vn-drop-down ul > li:nth-child(5)`, agencySelectOptionSix: `vn-autocomplete[field="$ctrl.ticket.agencyModeFk"] vn-drop-down ul > li:nth-child(6)`,
nextStepButton: `vn-step-control > section > section.buttons > section:nth-child(2) > vn-button`, nextStepButton: `vn-step-control > section > section.buttons > section:nth-child(2) > vn-button`,
finalizeButton: `vn-step-control > section > section.buttons > section:nth-child(2) > vn-submit`, finalizeButton: `vn-step-control > section > section.buttons > section:nth-child(2) > vn-submit`,
stepTwoTotalPriceDif: `vn-ticket-data-step-two > form > vn-card > div > vn-horizontal > table > tfoot > tr > td:nth-child(4)`, stepTwoTotalPriceDif: `vn-ticket-data-step-two > form > vn-card > div > vn-horizontal > table > tfoot > tr > td:nth-child(4)`,
@ -384,7 +384,7 @@ export default {
claimsIndex: { claimsIndex: {
searchClaimInput: `vn-claim-index ${components.vnTextfield}`, searchClaimInput: `vn-claim-index ${components.vnTextfield}`,
searchResult: `vn-claim-index vn-card > div > vn-table > div > vn-tbody > vn-tr`, searchResult: `vn-claim-index vn-card > div > vn-table > div > vn-tbody > vn-tr`,
searchButton: `vn-claim-index vn-searchbar > form > vn-horizontal > vn-icon-button > vn-icon` searchButton: `vn-claim-index vn-searchbar vn-icon[icon="search"]`
}, },
claimBasicData: { claimBasicData: {
basicDataButton: `vn-menu-item a[ui-sref="claim.card.basicData"]`, basicDataButton: `vn-menu-item a[ui-sref="claim.card.basicData"]`,

View File

@ -68,7 +68,7 @@ describe('Ticket List sale path', () => {
.wait(selectors.ticketSales.firstSaleText) .wait(selectors.ticketSales.firstSaleText)
.getInnerText(selectors.ticketSales.firstSalePrice) .getInnerText(selectors.ticketSales.firstSalePrice)
.then(value => { .then(value => {
expect(value).toContain('€11.42'); expect(value).toContain('€9.10');
}); });
}); });
@ -86,7 +86,7 @@ describe('Ticket List sale path', () => {
.wait(selectors.ticketSales.firstSaleText) .wait(selectors.ticketSales.firstSaleText)
.getInnerText(selectors.ticketSales.firstSaleImport) .getInnerText(selectors.ticketSales.firstSaleImport)
.then(value => { .then(value => {
expect(value).toContain('57.10'); expect(value).toContain('45.50');
}); });
}); });
@ -104,7 +104,7 @@ describe('Ticket List sale path', () => {
.wait(selectors.ticketSales.secondSaleText) .wait(selectors.ticketSales.secondSaleText)
.getInnerText(selectors.ticketSales.secondSalePrice) .getInnerText(selectors.ticketSales.secondSalePrice)
.then(value => { .then(value => {
expect(value).toContain('€1.30'); expect(value).toContain('€1.07');
}); });
}); });
@ -122,7 +122,7 @@ describe('Ticket List sale path', () => {
.wait(selectors.ticketSales.secondSaleText) .wait(selectors.ticketSales.secondSaleText)
.getInnerText(selectors.ticketSales.secondSaleImport) .getInnerText(selectors.ticketSales.secondSaleImport)
.then(value => { .then(value => {
expect(value).toContain('13.00'); expect(value).toContain('10.70');
}); });
}); });
}); });

View File

@ -106,7 +106,7 @@ describe('Ticket', () => {
it(`should edit the ticket agency then click next`, () => { it(`should edit the ticket agency then click next`, () => {
return nightmare return nightmare
.waitToClick(selectors.ticketBasicData.agencySelect) .waitToClick(selectors.ticketBasicData.agencySelect)
.waitToClick(selectors.ticketBasicData.agencySelectFifthOption) .waitToClick(selectors.ticketBasicData.agencySelectOptionSix)
.waitForTextInInput(selectors.ticketBasicData.agencySelect, 'Expensive') .waitForTextInInput(selectors.ticketBasicData.agencySelect, 'Expensive')
.click(selectors.ticketBasicData.nextStepButton) .click(selectors.ticketBasicData.nextStepButton)
.waitForURL('data/step-two') .waitForURL('data/step-two')

View File

@ -60,7 +60,7 @@ describe('Ticket Edit sale path', () => {
.wait(selectors.ticketSales.firstSaleText) .wait(selectors.ticketSales.firstSaleText)
.getInnerText(selectors.ticketSales.firstSalePrice) .getInnerText(selectors.ticketSales.firstSalePrice)
.then(value => { .then(value => {
expect(value).toEqual('€11.42'); expect(value).toEqual('€9.10');
}); });
}); });
@ -78,7 +78,7 @@ describe('Ticket Edit sale path', () => {
.wait(selectors.ticketSales.firstSaleText) .wait(selectors.ticketSales.firstSaleText)
.getInnerText(selectors.ticketSales.firstSaleImport) .getInnerText(selectors.ticketSales.firstSaleImport)
.then(value => { .then(value => {
expect(value).toEqual('€57.10'); expect(value).toEqual('€45.50');
}); });
}); });
@ -364,7 +364,7 @@ describe('Ticket Edit sale path', () => {
.waitToClick(selectors.ticketSales.moveToTicketButton) .waitToClick(selectors.ticketSales.moveToTicketButton)
.waitForLastSnackbar() .waitForLastSnackbar()
.then(result => { .then(result => {
expect(result).toEqual(`The sales of that ticket can't be modified`); expect(result).toEqual(`The sales of this ticket can't be modified`);
}); });
}); });

View File

@ -2,19 +2,20 @@ const app = require('../../../server/server');
const routes = require('../routes'); const routes = require('../routes');
const restoreFixtures = require('../../../../../services/db/testing_fixtures'); const restoreFixtures = require('../../../../../services/db/testing_fixtures');
describe('Auth routes', () => { xdescribe('Auth routes', () => {
let sqlStatements = {deletes: ` let route;
DELETE FROM salix.user WHERE id = 102;
`, inserts: ``, updates: ``};
beforeEach(() => { beforeAll(async() => {
restoreFixtures(sqlStatements); route = await app.models.Route.findOne({where: {id: 102}});
}); });
afterAll(() => { beforeEach(async() => {
restoreFixtures(sqlStatements);
}); });
afterAll(async() => {
});
let User = app.models.User; let User = app.models.User;
let loginFunction; let loginFunction;
let logoutFunction; let logoutFunction;

View File

@ -0,0 +1,4 @@
CREATE TABLE `vn`.`localLog` (
`id` INT NOT NULL AUTO_INCREMENT,
`ticketFk` VARCHAR(45) NULL,
PRIMARY KEY (`id`));

View File

@ -0,0 +1,21 @@
DROP TRIGGER IF EXISTS `vn2008`.`TicketsAfterUpdate`;
DELIMITER $$
USE `vn2008`$$
CREATE DEFINER=`root`@`%` TRIGGER `vn2008`.`TicketsAfterUpdate`
AFTER UPDATE ON `Tickets` FOR EACH ROW
BEGIN
IF NEW.Id_Ruta IS NULL AND OLD.Id_Ruta IS NOT NULL THEN
INSERT INTO vn.routeLog(originFk, userFk, `action`, description)
VALUES (OLD.Id_Ruta, account.userGetId(), 'update', CONCAT('Saca el ticket ', OLD.Id_Ticket, ' de la ruta'));
ELSEIF NOT (NEW.Id_Ruta <=> OLD.Id_Ruta) THEN
INSERT INTO vn.routeLog(originFk, userFk, `action`, description)
VALUES (NEW.Id_Ruta, account.userGetId(), 'update', CONCAT('Añade el ticket ', OLD.Id_Ticket, ' a la ruta'));
END IF;
CALL stock.queueAdd ('ticket', NEW.Id_Ticket, OLD.Id_Ticket);
INSERT INTO vn.localLog(ticketFk)
VALUES(NEW.Id_Ticket);
END$$
DELIMITER ;

View File

@ -4,10 +4,10 @@ DROP procedure IF EXISTS `orderAddItem`;
DELIMITER $$ DELIMITER $$
USE `hedera`$$ USE `hedera`$$
CREATE DEFINER=`root`@`%` PROCEDURE `orderAddItem`( CREATE DEFINER=`root`@`%` PROCEDURE `orderAddItem`(
vWarehouse INT, vOrder INT,
vWarehouse INT,
vItem INT, vItem INT,
vAmount INT, vAmount INT)
vOrder INT)
BEGIN BEGIN
DECLARE vRow INT; DECLARE vRow INT;
DECLARE vAdd INT; DECLARE vAdd INT;
@ -17,7 +17,9 @@ BEGIN
DECLARE vRate INT; DECLARE vRate INT;
DECLARE vShipment DATE; DECLARE vShipment DATE;
DECLARE vPrice DECIMAL(10,2); DECLARE vPrice DECIMAL(10,2);
DECLARE vDate DATE;
DECLARE vAddress INT;
DECLARE vAgencyMode INT;
DECLARE cur CURSOR FOR DECLARE cur CURSOR FOR
SELECT grouping, price, rate SELECT grouping, price, rate
FROM tmp.bionic_price FROM tmp.bionic_price
@ -34,7 +36,12 @@ BEGIN
RESIGNAL; RESIGNAL;
END; END;
CALL bionic_from_item (vItem); SELECT date_send, address_id, agency_id
INTO vDate, vAddress, vAgencyMode
FROM `order`
WHERE id = vOrder;
CALL vn2008.bionic_from_item(vDate, vAddress, vAgencyMode, vItem);
START TRANSACTION; START TRANSACTION;

View File

@ -12,9 +12,7 @@ BEGIN
SET vOrder = myBasketGetId(); SET vOrder = myBasketGetId();
CALL bionic_from_item (vItem); CALL orderAddItem(vOrder,vWarehouse, vItem, vAmount);
CALL addItem(vWarehouse, vItem, vAmount, vOrder);
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -1,98 +0,0 @@
USE `hedera`;
DROP procedure IF EXISTS `addItem`;
DELIMITER $$
USE `hedera`$$
CREATE DEFINER=`root`@`%` PROCEDURE `addItem`(
vWarehouse INT,
vItem INT,
vAmount INT,
vOrder INT)
BEGIN
DECLARE vRow INT;
DECLARE vAdd INT;
DECLARE vAvailable INT;
DECLARE vDone BOOL;
DECLARE vGrouping INT;
DECLARE vRate INT;
DECLARE vShipment DATE;
DECLARE vPrice DECIMAL(10,2);
DECLARE cur CURSOR FOR
SELECT grouping, price, rate
FROM tmp.bionic_price
WHERE warehouse_id = vWarehouse
AND item_id = vItem
ORDER BY grouping DESC;
DECLARE CONTINUE HANDLER FOR NOT FOUND
SET vDone = TRUE;
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
RESIGNAL;
END;
START TRANSACTION;
SELECT shipped INTO vShipment
FROM tmp.travel_tree
WHERE warehouseFk = vWarehouse;
SELECT available INTO vAvailable
FROM tmp.bionic_lot
WHERE warehouse_id = vWarehouse
AND item_id = vItem;
IF vAmount > vAvailable
THEN
CALL util.throw ('ORDER_ROW_UNAVAILABLE');
END IF;
OPEN cur;
l: LOOP
SET vDone = FALSE;
FETCH cur INTO vGrouping, vPrice, vRate;
IF vDone THEN
LEAVE l;
END IF;
SET vAdd = vAmount - MOD(vAmount, vGrouping);
SET vAmount = vAmount - vAdd;
IF vAdd = 0 THEN
ITERATE l;
END IF;
INSERT INTO order_row SET
order_id = vOrder,
item_id = vItem,
warehouse_id = vWarehouse,
shipment = vShipment,
rate = vRate,
amount = vAdd,
price = vPrice;
SET vRow = LAST_INSERT_ID();
INSERT INTO order_component (order_row_id, component_id, price)
SELECT vRow, c.component_id, c.cost
FROM tmp.bionic_component c
JOIN bi.tarifa_componentes t
ON t.Id_Componente = c.component_id
AND (t.tarifa_class IS NULL OR t.tarifa_class = vRate)
WHERE c.warehouse_id = vWarehouse
AND c.item_id = vItem;
END LOOP;
CLOSE cur;
COMMIT;
CALL vn2008.bionic_free ();
END$$
DELIMITER ;

View File

@ -0,0 +1,2 @@
ALTER TABLE `vn2008`.`agency`
ADD COLUMN `code` VARCHAR(45) NULL DEFAULT NULL AFTER `zone_label`;

View File

@ -1,27 +0,0 @@
USE `hedera`;
DROP procedure IF EXISTS `orderAddItem`;
DELIMITER $$
USE `hedera`$$
CREATE DEFINER=`root`@`%` PROCEDURE `orderAddItem`(
vWarehouse INT,
vItem INT,
vAmount INT,
vOrder INT)
BEGIN
DECLARE vDate DATE;
DECLARE vAddress INT;
DECLARE vAgencyMode INT;
SELECT date_send, address_id, agency_id
INTO vDate, vAddress, vAgencyMode
FROM `order`
WHERE id = vOrder;
CALL vn2008.bionic_from_item(vDate, vAddress, vAgencyMode, vItem);
CALL addItem(vWarehouse, vItem, vAmount, vOrder);
END$$
DELIMITER ;

View File

@ -0,0 +1,18 @@
USE `vn`;
CREATE
OR REPLACE ALGORITHM = UNDEFINED
DEFINER = `root`@`%`
SQL SECURITY DEFINER
VIEW `agency` AS
SELECT
`a`.`agency_id` AS `id`,
`a`.`name` AS `name`,
`a`.`warehouse_id` AS `warehouseFk`,
`a`.`por_volumen` AS `isVolumetric`,
`a`.`Id_Banco` AS `bankFk`,
`a`.`warehouse_alias_id` AS `warehouseAliasFk`,
`a`.`propios` AS `own`,
`a`.`zone_label` AS `labelZone`,
`a`.`code` AS `code`
FROM
`vn2008`.`agency` `a`;

View File

@ -0,0 +1,154 @@
USE `vn`;
DROP procedure IF EXISTS `ticketComponentUpdateSale`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentUpdateSale`(vOption INT)
BEGIN
/**
* A partir de la tabla tmp.sale, crea los Movimientos_componentes
* y modifica el campo Preu de la tabla Movimientos
*
* @param i_option integer tipo de actualizacion
* @param table tmp.sale tabla memory con el campo Id_Movimiento, warehouse_id
**/
DECLARE vComponentFk INT;
DECLARE vRenewComponents BOOLEAN;
DECLARE vKeepPrices BOOLEAN;
CASE vOption
WHEN 1 THEN
SET vRenewComponents = TRUE;
SET vKeepPrices = FALSE;
WHEN 2 THEN
SET vComponentFk = 17;
SET vRenewComponents = TRUE;
SET vKeepPrices = TRUE;
WHEN 3 THEN
SET vComponentFk = 37;
SET vRenewComponents = TRUE;
SET vKeepPrices = TRUE;
WHEN 4 THEN
SET vComponentFk = 34;
SET vRenewComponents = TRUE;
SET vKeepPrices = TRUE;
WHEN 5 THEN
SET vComponentFk = 35;
SET vRenewComponents = TRUE;
SET vKeepPrices = TRUE;
WHEN 6 THEN
SET vComponentFk = 36;
SET vRenewComponents = TRUE;
SET vKeepPrices = TRUE;
WHEN 7 THEN
REPLACE INTO saleComponent(saleFk, componentFk, value)
SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.8, 3)
FROM sale s
JOIN tmp.sale tmps ON tmps.saleFk = s.id
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
AND sc.componentFk NOT IN (28, 29)
GROUP BY s.id;
REPLACE INTO saleComponent(saleFk, componentFk, value)
SELECT s.id, 29, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.2, 3)
FROM sale s
JOIN tmp.sale tmps ON tmps.saleFk = s.id
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
AND sc.componentFk NOT IN (28, 29)
GROUP BY s.id;
SET vRenewComponents = FALSE;
SET vKeepPrices = FALSE;
WHEN 8 THEN
DELETE sc.*
FROM tmp.sale tmps JOIN saleComponent sc ON sc.saleFk = tmps.saleFk;
REPLACE INTO saleComponent(saleFk, componentFk, value)
SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100)), 3)
FROM sale s
JOIN tmp.sale tmps ON tmps.saleFk = s.id;
SET vRenewComponents = FALSE;
SET vKeepPrices = FALSE;
WHEN 9 THEN
SET vRenewComponents = TRUE;
SET vKeepPrices = TRUE;
END CASE;
IF vRenewComponents THEN
DELETE sc.*
FROM tmp.sale tmps
JOIN saleComponent sc ON sc.saleFk = tmps.saleFk
JOIN componentRate cr ON cr.id = sc.componentFk
WHERE cr.isRenewable;
REPLACE INTO saleComponent(saleFk, componentFk, value)
SELECT s.id, tc.componentFk, ROUND(tc.cost,3)
FROM sale s
JOIN tmp.sale tmps ON tmps.saleFk = s.id
JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
AND sc.componentFk = tc.componentFk
LEFT JOIN componentRate cr ON cr.id = tc.componentFk
WHERE IF(sc.componentFk IS NULL AND NOT cr.isRenewable, FALSE, TRUE);
END IF;
IF vKeepPrices THEN
REPLACE INTO saleComponent(saleFk, componentFk, value)
SELECT s.id, vComponentFk, ROUND((s.price * (100 - s.discount) / 100) - SUM(sc.value), 3) dif
FROM sale s
JOIN tmp.sale tmps ON tmps.saleFk = s.id
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
WHERE sc.saleFk <> vComponentFk
GROUP BY s.id
HAVING dif <> 0;
ELSE
UPDATE sale s
JOIN item i on i.id = s.itemFk
JOIN itemType it on it.id = i.typeFk
JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk
FROM saleComponent sc
JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk
GROUP BY sc.saleFk) sc ON sc.saleFk = s.id
SET s.price = sumValue
WHERE it.code != 'PRT';
REPLACE INTO saleComponent(saleFk, componentFk, value)
SELECT s.id, 21, ROUND((s.price * (100 - s.discount) / 100) - sum(value),3) saleValue
FROM sale s
JOIN tmp.sale tmps ON tmps.saleFk = s.id
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
WHERE sc.componentFk != 21
GROUP BY s.id
HAVING ROUND(saleValue, 4) <> 0;
END IF;
UPDATE sale s
JOIN (
SELECT SUM(sc.value) sumValue, sc.saleFk
FROM saleComponent sc
JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk
JOIN componentRate cr ON cr.id = sc.componentFk
JOIN componentTypeRate ctr on ctr.id = cr.componentTypeRate AND ctr.base
GROUP BY sc.saleFk) sc ON sc.saleFk = s.id
SET s.priceFixed = sumValue, s.isPriceFixed = 1;
DELETE sc.*
FROM saleComponent sc
JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk
JOIN sale s on s.id = sc.saleFk
JOIN item i ON i.id = s.itemFk
JOIN itemType it ON it.id = i.typeFk
WHERE it.code = 'PRT';
INSERT INTO saleComponent(saleFk, componentFk, value)
SELECT s.id, 15, ROUND(s.price,3)
FROM sale s
JOIN tmp.sale tmps ON tmps.saleFk = s.id
JOIN item i ON i.id = s.itemFK
JOIN itemType it ON it.id = i.typeFk
WHERE it.code = 'PRT' AND s.price > 0;
END$$
DELIMITER ;

View File

@ -5,4 +5,21 @@ ALTER TABLE `vn`.`zoneNest`
RENAME TO `vn`.`zoneGeo` ; RENAME TO `vn`.`zoneGeo` ;
ALTER TABLE `vn`.`zone` ALTER TABLE `vn`.`zone`
CHANGE COLUMN `agencyFk` `agencyModeFk` INT(11) NOT NULL ; CHANGE COLUMN `agencyFk` `agencyModeFk` INT(11) NOT NULL,
CHANGE COLUMN `hour` `hour` DATETIME NOT NULL,
CHANGE COLUMN `warehouseFk` `warehouseFk` SMALLINT(6) UNSIGNED NOT NULL ;
ALTER TABLE `vn`.`zone`
ADD INDEX `fk_zone_1_idx` (`warehouseFk` ASC),
ADD INDEX `fk_zone_2_idx` (`agencyModeFk` ASC);
ALTER TABLE `vn`.`zone`
ADD CONSTRAINT `fk_zone_1`
FOREIGN KEY (`warehouseFk`)
REFERENCES `vn2008`.`warehouse` (`id`)
ON DELETE NO ACTION
ON UPDATE CASCADE,
ADD CONSTRAINT `fk_zone_2`
FOREIGN KEY (`agencyModeFk`)
REFERENCES `vn2008`.`Agencias` (`Id_Agencia`)
ON DELETE NO ACTION
ON UPDATE NO ACTION;

View File

@ -68,16 +68,17 @@ INSERT INTO `vn`.`bank`(`id`, `bank`, `account`, `cash`, `entityFk`, `isActive`)
VALUES VALUES
(8, 'Pay on receipt', '0000000000', 4, 0, 1); (8, 'Pay on receipt', '0000000000', 4, 0, 1);
INSERT INTO `vn`.`agency`(`id`, `name`, `warehouseFk`, `isVolumetric`, `bankFk`, `warehouseAliasFk`) INSERT INTO `vn`.`agency`(`id`, `name`, `warehouseFk`, `isVolumetric`, `bankFk`, `warehouseAliasFk`, `code`)
VALUES VALUES
(1, 'inhouse pickup' , 1, 0, 8, 1), (1, 'inhouse pickup' , 1, 0, 8, 1, NULL),
(2, 'Super-Man delivery' , 1, 0, 8, 1), (2, 'Super-Man delivery' , 1, 0, 8, 1, NULL),
(3, 'Teleportation device' , 1, 0, 8, 1), (3, 'Teleportation device' , 1, 0, 8, 1, NULL),
(4, 'Entanglement' , 1, 0, 8, 1), (4, 'Entanglement' , 1, 0, 8, 1, NULL),
(5, 'Quantum break device' , 1, 0, 8, 1), (5, 'Quantum break device' , 1, 0, 8, 1, NULL),
(6, 'Walking' , 1, 0, 8, 1), (6, 'Walking' , 1, 0, 8, 1, NULL),
(7, 'Silla247' , 1, 0, 8, 1), (7, 'Silla247' , 1, 0, 8, 1, NULL),
(8, 'Silla247Expensive' , 1, 0, 8, 1); (8, 'Silla247Expensive' , 1, 0, 8, 1, NULL),
(9, 'Abono' , 1, 0, 8, 1, 'refund');
UPDATE `vn`.`agencyMode` SET `id` = 1 WHERE `name` = 'inhouse pickup'; UPDATE `vn`.`agencyMode` SET `id` = 1 WHERE `name` = 'inhouse pickup';
UPDATE `vn`.`agencyMode` SET `id` = 2 WHERE `name` = 'Super-Man delivery'; UPDATE `vn`.`agencyMode` SET `id` = 2 WHERE `name` = 'Super-Man delivery';
@ -87,6 +88,7 @@ UPDATE `vn`.`agencyMode` SET `id` = 5 WHERE `name` = 'Quantum break device';
UPDATE `vn`.`agencyMode` SET `id` = 6 WHERE `name` = 'Walking'; UPDATE `vn`.`agencyMode` SET `id` = 6 WHERE `name` = 'Walking';
UPDATE `vn`.`agencyMode` SET `id` = 7 WHERE `name` = 'Silla247'; UPDATE `vn`.`agencyMode` SET `id` = 7 WHERE `name` = 'Silla247';
UPDATE `vn`.`agencyMode` SET `id` = 8 WHERE `name` = 'Silla247Expensive'; UPDATE `vn`.`agencyMode` SET `id` = 8 WHERE `name` = 'Silla247Expensive';
UPDATE `vn`.`agencyMode` SET `id` = 23 WHERE `name` = 'Abono';
UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 1; UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 1;
UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 2; UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 2;
@ -96,6 +98,7 @@ UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 5;
UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 2 WHERE `id` = 6; UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 2 WHERE `id` = 6;
UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 7; UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 7;
UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 8; UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 8;
UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 4 WHERE `id` = 23;
UPDATE `vn`.`agencyMode` SET `web` = 1 WHERE `id` = 1; UPDATE `vn`.`agencyMode` SET `web` = 1 WHERE `id` = 1;
@ -269,7 +272,8 @@ INSERT INTO `vn`.`observationType`(`id`,`description`)
VALUES VALUES
(1,'observation one'), (1,'observation one'),
(2,'observation two'), (2,'observation two'),
(3,'observation three'); (3,'observation three'),
(4,'comercial');
INSERT INTO `vn`.`addressObservation`(`id`,`addressFk`,`observationTypeFk`,`description`) INSERT INTO `vn`.`addressObservation`(`id`,`addressFk`,`observationTypeFk`,`description`)
VALUES VALUES
@ -329,29 +333,29 @@ INSERT INTO `vn`.`invoiceOut`(`id`, `ref`, `serial`, `amount`, `issued`,`clientF
( 4, 'E4444444' , 'E', 290.30 , DATE_ADD(CURDATE(), INTERVAL +1 MONTH), 103, CURDATE(), 442, CURDATE(), CURDATE(), 8, 1), ( 4, 'E4444444' , 'E', 290.30 , DATE_ADD(CURDATE(), INTERVAL +1 MONTH), 103, CURDATE(), 442, CURDATE(), CURDATE(), 8, 1),
( 5, 'E5555555' , 'E', 190.30 , DATE_ADD(CURDATE(), INTERVAL +2 MONTH), 103, CURDATE(), 442, CURDATE(), CURDATE(), 8, 1); ( 5, 'E5555555' , 'E', 190.30 , DATE_ADD(CURDATE(), INTERVAL +2 MONTH), 103, CURDATE(), 442, CURDATE(), CURDATE(), 8, 1);
INSERT INTO `vn`.`ticket`(`id`, `agencyModeFk`,`warehouseFk`,`routeFk`, `shipped`, `landed`, `clientFk`,`nickname`, `addressFk`, `refFk`, `isDeleted`) INSERT INTO `vn`.`ticket`(`id`, `agencyModeFk`,`warehouseFk`,`routeFk`, `shipped`, `landed`, `clientFk`,`nickname`, `addressFk`, `refFk`, `isDeleted`, `created`)
VALUES VALUES
(1 , 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL -15 DAY) , DATE_ADD(CURDATE(), INTERVAL -15 DAY) , 101, 'address 21', 121, NULL, 0), (1 , 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL -15 DAY) , DATE_ADD(CURDATE(), INTERVAL -15 DAY) , 101, 'address 21', 121, NULL, 0, DATE_ADD(CURDATE(), INTERVAL -15 DAY) ),
(2 , 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL -10 DAY) , DATE_ADD(CURDATE(), INTERVAL -10 DAY) , 101, 'address 21', 121, NULL, 0), (2 , 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL -10 DAY) , DATE_ADD(CURDATE(), INTERVAL -10 DAY) , 101, 'address 21', 121, NULL, 0, DATE_ADD(CURDATE(), INTERVAL -10 DAY) ),
(3 , 2, 2, 2, DATE_ADD(CURDATE(), INTERVAL -5 DAY) , DATE_ADD(CURDATE(), INTERVAL -5 DAY) , 102, 'address 22', 122, NULL, 0), (3 , 2, 2, 2, DATE_ADD(CURDATE(), INTERVAL -5 DAY) , DATE_ADD(CURDATE(), INTERVAL -5 DAY) , 102, 'address 22', 122, NULL, 0, DATE_ADD(CURDATE(), INTERVAL -5 DAY) ),
(4 , 2, 2, 2, DATE_ADD(CURDATE(), INTERVAL -4 DAY) , DATE_ADD(CURDATE(), INTERVAL -4 DAY) , 102, 'address 22', 122, NULL, 0), (4 , 2, 2, 2, DATE_ADD(CURDATE(), INTERVAL -4 DAY) , DATE_ADD(CURDATE(), INTERVAL -4 DAY) , 102, 'address 22', 122, NULL, 0, DATE_ADD(CURDATE(), INTERVAL -4 DAY) ),
(5 , 3, 3, 3, DATE_ADD(CURDATE(), INTERVAL -3 DAY) , DATE_ADD(CURDATE(), INTERVAL -3 DAY) , 103, 'address 23', 123, NULL, 0), (5 , 3, 3, 3, DATE_ADD(CURDATE(), INTERVAL -3 DAY) , DATE_ADD(CURDATE(), INTERVAL -3 DAY) , 103, 'address 23', 123, NULL, 0, DATE_ADD(CURDATE(), INTERVAL -3 DAY) ),
(6 , 3, 3, 4, DATE_ADD(CURDATE(), INTERVAL -2 DAY) , DATE_ADD(CURDATE(), INTERVAL -2 DAY) , 103, 'address 23', 123, NULL, 0), (6 , 3, 3, 4, DATE_ADD(CURDATE(), INTERVAL -2 DAY) , DATE_ADD(CURDATE(), INTERVAL -2 DAY) , 103, 'address 23', 123, NULL, 0, DATE_ADD(CURDATE(), INTERVAL -2 DAY) ),
(7 , 4, 4, 4, DATE_ADD(CURDATE(), INTERVAL -1 DAY) , DATE_ADD(CURDATE(), INTERVAL -1 DAY) , 104, 'address 24', 124, NULL, 0), (7 , 4, 4, 4, DATE_ADD(CURDATE(), INTERVAL -1 DAY) , DATE_ADD(CURDATE(), INTERVAL -1 DAY) , 104, 'address 24', 124, NULL, 0, DATE_ADD(CURDATE(), INTERVAL -1 DAY) ),
(8 , 4, 4, 4, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 104, 'address 24', 124, NULL, 0), (8 , 4, 4, 4, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 104, 'address 24', 124, NULL, 0, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)),
(9 , 5, 5, 4, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), DATE_ADD(CURDATE(), INTERVAL -2 MONTH), 105, 'address 25', 125, NULL, 0), (9 , 5, 5, 4, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), DATE_ADD(CURDATE(), INTERVAL -2 MONTH), 105, 'address 25', 125, NULL, 0, DATE_ADD(CURDATE(), INTERVAL -2 MONTH)),
(10, 6, 5, 5, DATE_ADD(CURDATE(), INTERVAL -3 MONTH), DATE_ADD(CURDATE(), INTERVAL -3 MONTH), 105, 'address 25', 125, NULL, 0), (10, 6, 5, 5, DATE_ADD(CURDATE(), INTERVAL -3 MONTH), DATE_ADD(CURDATE(), INTERVAL -3 MONTH), 105, 'address 25', 125, NULL, 0, DATE_ADD(CURDATE(), INTERVAL -3 MONTH)),
(11, 7, 1, 1, CURDATE() , CURDATE() , 101, 'address 21', 121, NULL, 0), (11, 7, 1, 1, CURDATE() , CURDATE() , 101, 'address 21', 121, NULL, 0, CURDATE() ),
(12, 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), DATE_ADD(CURDATE(), INTERVAL +1 MONTH), 101, 'address 21', 121, NULL, 0), (12, 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), DATE_ADD(CURDATE(), INTERVAL +1 MONTH), 101, 'address 21', 121, NULL, 0, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)),
(13, 2, 2, 2, DATE_ADD(CURDATE(), INTERVAL +2 MONTH), DATE_ADD(CURDATE(), INTERVAL +2 MONTH), 101, 'address 21', 121, NULL, 0), (13, 2, 2, 2, DATE_ADD(CURDATE(), INTERVAL +2 MONTH), DATE_ADD(CURDATE(), INTERVAL +2 MONTH), 101, 'address 21', 121, NULL, 0, DATE_ADD(CURDATE(), INTERVAL +2 MONTH)),
(14, 2, 2, 2, DATE_ADD(CURDATE(), INTERVAL +3 MONTH), DATE_ADD(CURDATE(), INTERVAL +3 MONTH), 101, 'address 21', 121, NULL, 0), (14, 2, 2, 2, DATE_ADD(CURDATE(), INTERVAL +3 MONTH), DATE_ADD(CURDATE(), INTERVAL +3 MONTH), 101, 'address 21', 121, NULL, 0, DATE_ADD(CURDATE(), INTERVAL +3 MONTH)),
(15, 3, 3, 3, DATE_ADD(CURDATE(), INTERVAL +4 MONTH), DATE_ADD(CURDATE(), INTERVAL +4 MONTH), 101, 'address 21', 121, NULL, 0), (15, 3, 3, 3, DATE_ADD(CURDATE(), INTERVAL +4 MONTH), DATE_ADD(CURDATE(), INTERVAL +4 MONTH), 101, 'address 21', 121, NULL, 0, DATE_ADD(CURDATE(), INTERVAL +4 MONTH)),
(16, 1, 1, 1, CURDATE() , CURDATE() , 101, 'address 21', 121, NULL, 0), (16, 1, 1, 1, CURDATE() , CURDATE() , 101, 'address 21', 121, NULL, 0, CURDATE() ),
(17, 4, 4, 4, CURDATE() , CURDATE() , 106, 'address 26', 126, NULL, 0), (17, 4, 4, 4, CURDATE() , CURDATE() , 106, 'address 26', 126, NULL, 0, CURDATE() ),
(18, 4, 4, 4, CURDATE() , CURDATE() , 107, 'address 27', 127, NULL, 0), (18, 4, 4, 4, CURDATE() , CURDATE() , 107, 'address 27', 127, NULL, 0, CURDATE() ),
(19, 5, 5, 4, CURDATE() , CURDATE() , 108, 'address 28', 128, NULL, 0), (19, 5, 5, 4, CURDATE() , CURDATE() , 108, 'address 28', 128, NULL, 0, CURDATE() ),
(20, 5, 5, 4, CURDATE() , CURDATE() , 109, 'address 19', 119, NULL, 0), (20, 5, 5, 4, CURDATE() , CURDATE() , 109, 'address 19', 119, NULL, 0, CURDATE() ),
(21, 5, 5, 4, CURDATE() , CURDATE() , 110, 'address 29', 129, NULL, 1); (21, 5, 5, 4, CURDATE() , CURDATE() , 110, 'address 29', 129, NULL, 1, CURDATE() );
INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `description`) INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `description`)
VALUES VALUES
@ -361,16 +365,16 @@ INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `des
INSERT INTO `vn`.`ticketTracking`(`id`, `ticketFk`, `stateFk`, `workerFk`, `created`) INSERT INTO `vn`.`ticketTracking`(`id`, `ticketFk`, `stateFk`, `workerFk`, `created`)
VALUES VALUES
(1 , 1 , 3 , 5 , CURDATE()), (1 , 1 , 16, 5 , DATE_ADD(CURDATE(), INTERVAL -15 DAY) ),
(2 , 2 , 15, 5 , CURDATE()), (2 , 2 , 16, 5 , DATE_ADD(CURDATE(), INTERVAL -10 DAY) ),
(3 , 3 , 16, 5 , CURDATE()), (3 , 3 , 16, 5 , DATE_ADD(CURDATE(), INTERVAL -5 DAY) ),
(4 , 4 , 13, 5 , CURDATE()), (4 , 4 , 16, 5 , DATE_ADD(CURDATE(), INTERVAL -4 DAY) ),
(5 , 5 , 15, 18, CURDATE()), (5 , 5 , 16, 18, DATE_ADD(CURDATE(), INTERVAL -3 DAY) ),
(6 , 6 , 16, 18, CURDATE()), (6 , 6 , 16, 18, DATE_ADD(CURDATE(), INTERVAL -2 DAY) ),
(7 , 7 , 13, 18, CURDATE()), (7 , 7 , 16, 18, DATE_ADD(CURDATE(), INTERVAL -1 DAY) ),
(8 , 8 , 15, 19, CURDATE()), (8 , 8 , 16, 19, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)),
(9 , 9 , 16, 19, CURDATE()), (9 , 9 , 16, 19, DATE_ADD(CURDATE(), INTERVAL -2 MONTH)),
(10, 10, 13, 19, CURDATE()), (10, 10, 16, 19, DATE_ADD(CURDATE(), INTERVAL -3 MONTH)),
(11, 11, 3 , 19, CURDATE()), (11, 11, 3 , 19, CURDATE()),
(12, 12, 3 , 19, CURDATE()), (12, 12, 3 , 19, CURDATE()),
(13, 13, 3 , 19, CURDATE()), (13, 13, 3 , 19, CURDATE()),
@ -519,18 +523,18 @@ INSERT INTO `vn`.`ticketPackaging`(`id`, `ticketFk`, `packagingFk`, `quantity`,
INSERT INTO `vn`.`sale`(`id`, `itemFk`, `ticketFk`, `concept`, `quantity`, `price`, `discount`, `reserved`, `isPicked`, `created`) INSERT INTO `vn`.`sale`(`id`, `itemFk`, `ticketFk`, `concept`, `quantity`, `price`, `discount`, `reserved`, `isPicked`, `created`)
VALUES VALUES
( 1, 1, 1 , 'Gem of Time', 5 , 11.42, 0, 0, 0, CURDATE()), ( 1, 1, 1 , 'Gem of Time', 5, 9.10, 0, 0, 0, CURDATE()),
( 2, 2, 1 , 'Gem of Mind', 10 , 1.30, 0, 0, 0, CURDATE()), ( 2, 2, 1 , 'Gem of Mind', 10, 1.07, 0, 0, 0, CURDATE()),
( 3, 1, 1 , 'Gem of Time', 2 , 11.42, 0, 0, 0, CURDATE()), ( 3, 1, 1 , 'Gem of Time', 2, 9.10, 0, 0, 0, CURDATE()),
( 4, 4, 1 , 'Mark I' , 20 , 3.26, 0, 0, 0, CURDATE()), ( 4, 4, 1 , 'Mark I' , 20, 3.06, 0, 0, 0, CURDATE()),
( 5, 1, 2 , 'Gem of Time', 10 , 11.42, 0, 0, 0, CURDATE()), ( 5, 1, 2 , 'Gem of Time', 10, 9.10, 0, 0, 0, CURDATE()),
( 6, 1, 3 , 'Gem of Time', 15 , 11.42, 0, 0, 0, CURDATE()), ( 6, 1, 3 , 'Gem of Time', 15, 6.50, 0, 0, 0, CURDATE()),
( 7, 2, 11, 'Gem of Mind', 15 , 1.30, 0, 0, 0, CURDATE()), ( 7, 2, 11, 'Gem of Mind', 15, 1.30, 0, 0, 0, CURDATE()),
( 8, 4, 11, 'Mark I' , 10 , 3.26, 0, 0, 0, CURDATE()), ( 8, 4, 11, 'Mark I' , 10, 3.26, 0, 0, 0, CURDATE()),
( 9, 1, 16, 'Gem of Time', 5 , 11.42, 0, 0, 0, CURDATE()), ( 9, 1, 16, 'Gem of Time', 5, 9.10, 0, 0, 0, CURDATE()),
( 10, 2, 16, 'Gem of Mind', 10 , 1.30, 0, 0, 0, CURDATE()), ( 10, 2, 16, 'Gem of Mind', 10, 1.07, 0, 0, 0, CURDATE()),
( 11, 1, 16, 'Gem of Time', 2 , 11.42, 0, 0, 0, CURDATE()), ( 11, 1, 16, 'Gem of Time', 2, 9.10, 0, 0, 0, CURDATE()),
( 12, 4, 16, 'Mark I' , 20 , 3.26, 0, 0, 0, CURDATE()); ( 12, 4, 16, 'Mark I' , 20, 3.06, 0, 0, 0, CURDATE());
INSERT INTO `vn`.`saleChecked`(`saleFk`, `isChecked`) INSERT INTO `vn`.`saleChecked`(`saleFk`, `isChecked`)
VALUES VALUES
@ -539,68 +543,64 @@ INSERT INTO `vn`.`saleChecked`(`saleFk`, `isChecked`)
INSERT INTO `vn`.`saleComponent`(`saleFk`, `componentFk`, `value`) INSERT INTO `vn`.`saleComponent`(`saleFk`, `componentFk`, `value`)
VALUES VALUES
( 1, 10, 1), ( 1, 15, 0.58),
( 1, 14, 2.5), ( 1, 23, 6.5),
( 1, 15, 3), ( 1, 28, 20.72),
( 1, 17, 4.5), ( 1, 29, -18.72),
( 1, 21, 5), ( 1, 39, 0.02),
( 1, 23, 6.5), ( 2, 15, 0.058),
( 1, 28, 1), ( 2, 21, 0.002),
( 2, 28, 1), ( 2, 28, 5.6),
( 3, 10, 1), ( 2, 29, -4.6),
( 3, 14, 2.5), ( 2, 39, 0.01),
( 3, 15, 3), ( 3, 15, 0.58),
( 3, 17, 4.5), ( 3, 23, 6.5),
( 3, 21, 5), ( 3, 28, 20.72),
( 3, 23, 6.5), ( 3, 29, -18.72),
( 3, 28, 1), ( 3, 39, 0.02),
( 4, 28, 1), ( 4, 15, 0.051),
( 4, 10, 1), ( 4, 21, -0.001),
( 2, 17, 3.5), ( 4, 28, 20.72),
( 4, 39, 5), ( 4, 29, -19.72),
( 4, 37, 2), ( 4, 37, 2),
( 5, 10, 1), ( 4, 39, 0.01),
( 5, 14, 2.5), ( 5, 15, 0.58),
( 5, 15, 3), ( 5, 23, 6.5),
( 5, 17, 4.5), ( 5, 28, 20.72),
( 5, 21, 5), ( 5, 29, -18.72),
( 5, 23, 6.5), ( 5, 39, 0.02),
( 5, 28, 1), ( 6, 23, 6.5),
( 6, 10, 1), ( 7, 15, 0.29),
( 6, 14, 2.5), ( 7, 28, 5.6),
( 6, 15, 3), ( 7, 29, -4.6),
( 6, 17, 4.5), ( 7, 39, 0.01),
( 6, 21, 5), ( 8, 15, 0.254),
( 6, 23, 6.5), ( 8, 21, -0.004),
( 6, 28, 1), ( 8, 28, 20.72),
( 7, 28, 1), ( 8, 29, -19.72),
( 7, 17, 3.5), ( 8, 37, 2),
( 7, 15, 3), ( 8, 39, 0.01),
( 8, 28, 1), ( 9, 15, 0.58),
( 8, 10, 1), ( 9, 23, 6.5),
( 8, 39, 5), ( 9, 28, 20.72),
( 8, 15, 5), ( 9, 29, -18.72),
( 8, 37, 2), ( 9, 39, 0.02),
( 9, 10, 1), ( 10, 15, 0.058),
( 9, 14, 2.5), ( 10, 21, 0.002),
( 9, 15, 3), ( 10, 28, 5.6),
( 9, 17, 4.5), ( 10, 29, -4.6),
( 9, 21, 5), ( 10, 39, 0.01),
( 9, 23, 6.5), ( 11, 15, 0.58),
( 9, 28, 1), ( 11, 23, 6.5),
( 10, 28, 1), ( 11, 28, 20.72),
( 11, 10, 1), ( 11, 29, -18.72),
( 11, 14, 2.5), ( 11, 39, 0.02),
( 11, 15, 3), ( 12, 15, 0.051),
( 11, 17, 4.5), ( 12, 22, -0.001),
( 11, 21, 5), ( 12, 28, 20.72),
( 11, 23, 6.5), ( 12, 29, -19.72),
( 11, 28, 1), ( 12, 37, 2),
( 12, 28, 1), ( 12, 39, 0.01);
( 12, 10, 1),
( 10, 17, 3.5),
( 12, 39, 5),
( 12, 37, 2);
INSERT INTO `vn`.`saleTracking`(`saleFk`, `isChecked`, `created`, `originalQuantity`, `workerFk`, `actionFk`, `id`, `stateFk`) INSERT INTO `vn`.`saleTracking`(`saleFk`, `isChecked`, `created`, `originalQuantity`, `workerFk`, `actionFk`, `id`, `stateFk`)
VALUES VALUES

View File

@ -31,6 +31,8 @@
"Sample type cannot be blank": "Sample type cannot be blank", "Sample type cannot be blank": "Sample type cannot be blank",
"The package cannot be blank": "The package cannot be blank", "The package cannot be blank": "The package cannot be blank",
"The warehouse can't be repeated": "The warehouse can't be repeated", "The warehouse can't be repeated": "The warehouse can't be repeated",
"The sales of that ticket can't be modified": "The sales of that ticket can't be modified", "The new quantity should be smaller than the old one": "The new quantity should be smaller than the old one",
"The new quantity should be smaller than the old one": "The new quantity should be smaller than the old one" "Package cannot be blank": "Package cannot be blank",
"The sales of this ticket can't be modified": "The sales of this ticket can't be modified",
"You don't have enough privileges to do that": "You don't have enough privileges to do that"
} }

View File

@ -1,20 +1,17 @@
const app = require(`${servicesDir}/client/server/server`); const app = require(`${servicesDir}/client/server/server`);
const restoreFixtures = require(`${servicesDir}/db/testing_fixtures`);
describe('Client addressesPropagateRe', () => { describe('Client addressesPropagateRe', () => {
let sqlStatements = {deletes: ``, inserts: ``, updates: beforeEach(async() => {
`UPDATE vn.address SET isEqualizated = FALSE WHERE clientFk = 101; await app.models.Address.update({clientFk: 101}, {isEqualizated: false});
UPDATE vn.client SET hasToInvoiceByAddress = TRUE WHERE id = 101;` await app.models.Client.update({id: 101}, {hasToInvoiceByAddress: true});
};
beforeEach(() => {
restoreFixtures(sqlStatements);
}); });
afterAll(() => { afterAll(async() => {
restoreFixtures(sqlStatements); await app.models.Address.update({clientFk: 101}, {isEqualizated: false});
await app.models.Client.update({id: 101}, {hasToInvoiceByAddress: true});
}); });
it('should propagate the isEqualizated on both addresses of Mr Wayne and set hasToInvoiceByAddress to false', async () => { it('should propagate the isEqualizated on both addresses of Mr Wayne and set hasToInvoiceByAddress to false', async() => {
let id = 101; let id = 101;
let data = { let data = {
isEqualizated: true isEqualizated: true

View File

@ -7,6 +7,6 @@ describe('Client card', () => {
expect(result.id).toEqual(101); expect(result.id).toEqual(101);
expect(result.name).toEqual('Bruce Wayne'); expect(result.name).toEqual('Bruce Wayne');
expect(result.debt).toEqual(1048.76); expect(result.debt).toEqual(972.78);
}); });
}); });

View File

@ -4,7 +4,7 @@ describe('client getDebt()', () => {
it('should return the client debt', async() => { it('should return the client debt', async() => {
let result = await app.models.Client.getDebt(101); let result = await app.models.Client.getDebt(101);
expect(result.debt).toEqual(1048.76); expect(result.debt).toEqual(972.78);
}); });
}); });

View File

@ -4,7 +4,7 @@ describe('client getMana()', () => {
it('should call the getMana method', async() => { it('should call the getMana method', async() => {
let result = await app.models.Client.getMana(101); let result = await app.models.Client.getMana(101);
expect(result.mana).toEqual(400); expect(result.mana).toEqual(151.33);
}); });
}); });

View File

@ -11,13 +11,13 @@ describe('client summary()', () => {
it('should return a summary object containing mana', async() => { it('should return a summary object containing mana', async() => {
let result = await app.models.Client.summary(101); let result = await app.models.Client.summary(101);
expect(result.mana.mana).toEqual(400); expect(result.mana.mana).toEqual(151.33);
}); });
it('should return a summary object containing debt', async() => { it('should return a summary object containing debt', async() => {
let result = await app.models.Client.summary(101); let result = await app.models.Client.summary(101);
expect(result.debt.debt).toEqual(1048.76); expect(result.debt.debt).toEqual(972.78);
}); });
it('should return a summary object containing averageInvoiced', async() => { it('should return a summary object containing averageInvoiced', async() => {

View File

@ -28,7 +28,7 @@ module.exports = Self => {
let newTicketIsEditable = await Self.app.models.Ticket.isEditable(params.newTicketFk); let newTicketIsEditable = await Self.app.models.Ticket.isEditable(params.newTicketFk);
if (!newTicketIsEditable) if (!newTicketIsEditable)
throw new UserError(`The sales of that ticket can't be modified`); throw new UserError(`The sales of this ticket can't be modified`);
for (let i = 0; i < params.sales.length; i++) { for (let i = 0; i < params.sales.length; i++) {
await Self.app.models.Sale.update({id: params.sales[i].id}, {ticketFk: params.newTicketFk}); await Self.app.models.Sale.update({id: params.sales[i].id}, {ticketFk: params.newTicketFk});

View File

@ -9,7 +9,7 @@ module.exports = Self => {
arg: 'params', arg: 'params',
type: 'object', type: 'object',
required: true, required: true,
description: '[sales IDs], actualTicketFk, reserved', description: '[sales IDs], ticketFk, reserved',
http: {source: 'body'} http: {source: 'body'}
}], }],
returns: { returns: {
@ -23,7 +23,7 @@ module.exports = Self => {
}); });
Self.reserve = async params => { Self.reserve = async params => {
let thisTicketIsEditable = await Self.app.models.Ticket.isEditable(params.actualTicketFk); let thisTicketIsEditable = await Self.app.models.Ticket.isEditable(params.ticketFk);
if (!thisTicketIsEditable) if (!thisTicketIsEditable)
throw new UserError(`The sales of this ticket can't be modified`); throw new UserError(`The sales of this ticket can't be modified`);

View File

@ -22,62 +22,58 @@ describe('sale moveToTicket()', () => {
await app.models.Sale.moveToTicket(params) await app.models.Sale.moveToTicket(params)
.catch(response => { .catch(response => {
expect(response.message).toEqual(`The sales of that ticket can't be modified`); expect(response.message).toEqual(`The sales of this ticket can't be modified`);
error = response; error = response;
}); });
expect(error).toBeDefined(); expect(error).toBeDefined();
}); });
it('should transfer the sales from ticket 1 to ticket 13', async() => { it('should transfer the sales from one ticket to another', async() => {
let senderTicketSales = await app.models.Ticket.getSales(1); let senderTicketSales = await app.models.Ticket.getSales(11);
let receiverTicketSales = await app.models.Ticket.getSales(13); let receiverTicketSales = await app.models.Ticket.getSales(13);
expect(senderTicketSales.length).toEqual(4); expect(senderTicketSales.length).toEqual(2);
expect(receiverTicketSales.length).toEqual(0); expect(receiverTicketSales.length).toEqual(0);
let params = { let params = {
actualTicketFk: 1, actualTicketFk: 11,
newTicketFk: 13, newTicketFk: 13,
sales: [ sales: [
{id: 1}, {id: 7},
{id: 2}, {id: 8}]
{id: 3},
{id: 4}]
}; };
await app.models.Sale.moveToTicket(params); await app.models.Sale.moveToTicket(params);
senderTicketSales = await app.models.Ticket.getSales(1); senderTicketSales = await app.models.Ticket.getSales(11);
receiverTicketSales = await app.models.Ticket.getSales(13); receiverTicketSales = await app.models.Ticket.getSales(13);
expect(senderTicketSales.length).toEqual(0); expect(senderTicketSales.length).toEqual(0);
expect(receiverTicketSales.length).toEqual(4); expect(receiverTicketSales.length).toEqual(2);
}); });
it('should transfer the sales back from ticket 13 to ticket 1', async() => { it('should transfers back the sales', async() => {
let senderTicketSales = await app.models.Ticket.getSales(13); let senderTicketSales = await app.models.Ticket.getSales(13);
let receiverTicketSales = await app.models.Ticket.getSales(1); let receiverTicketSales = await app.models.Ticket.getSales(11);
expect(senderTicketSales.length).toEqual(4); expect(senderTicketSales.length).toEqual(2);
expect(receiverTicketSales.length).toEqual(0); expect(receiverTicketSales.length).toEqual(0);
let params = { let params = {
actualTicketFk: 13, actualTicketFk: 13,
newTicketFk: 1, newTicketFk: 11,
sales: [ sales: [
{id: 1}, {id: 7},
{id: 2}, {id: 8}]
{id: 3},
{id: 4}]
}; };
await app.models.Sale.moveToTicket(params); await app.models.Sale.moveToTicket(params);
senderTicketSales = await app.models.Ticket.getSales(13); senderTicketSales = await app.models.Ticket.getSales(13);
receiverTicketSales = await app.models.Ticket.getSales(1); receiverTicketSales = await app.models.Ticket.getSales(11);
expect(senderTicketSales.length).toEqual(0); expect(senderTicketSales.length).toEqual(0);
expect(receiverTicketSales.length).toEqual(4); expect(receiverTicketSales.length).toEqual(2);
}); });
}); });

View File

@ -10,8 +10,8 @@ describe('sale priceDifference()', () => {
}; };
let result = await app.models.Sale.priceDifference(1, data); let result = await app.models.Sale.priceDifference(1, data);
expect(result.totalUnitPrice).toEqual(27.4); expect(result.totalUnitPrice).toEqual(22.33);
expect(result.totalNewPrice).toEqual(22.33); expect(result.totalNewPrice).toEqual(22.33);
expect(result.totalDifference).toEqual(22.54); expect(result.totalDifference).toEqual(0);
}); });
}); });

View File

@ -4,11 +4,9 @@ describe('sale reserve()', () => {
afterAll(async() => { afterAll(async() => {
let params = { let params = {
sales: [ sales: [
{id: 1}, {id: 7},
{id: 2}, {id: 8}],
{id: 3}, ticketFk: 11,
{id: 4}],
ticketFk: 1,
reserved: false reserved: false
}; };
@ -17,7 +15,9 @@ describe('sale reserve()', () => {
it('should throw an error if the ticket can not be modified', async() => { it('should throw an error if the ticket can not be modified', async() => {
let error; let error;
let params = {actualTicketFk: 10, sales: [{id: 4, instance: 3}]}; let params = {ticketFk: 2,
sales: [{id: 5}],
reserved: false};
await app.models.Sale.reserve(params) await app.models.Sale.reserve(params)
.catch(response => { .catch(response => {
@ -28,31 +28,25 @@ describe('sale reserve()', () => {
expect(error).toBeDefined(); expect(error).toBeDefined();
}); });
it('should update the given sales of a ticket as reserved', async() => { it('should update the given sales of a ticket to reserved', async() => {
originalTicketSales = await app.models.Ticket.getSales(1); originalTicketSales = await app.models.Ticket.getSales(11);
expect(originalTicketSales[0].reserved).toEqual(0); expect(originalTicketSales[0].reserved).toEqual(0);
expect(originalTicketSales[1].reserved).toEqual(0); expect(originalTicketSales[1].reserved).toEqual(0);
expect(originalTicketSales[2].reserved).toEqual(0);
expect(originalTicketSales[3].reserved).toEqual(0);
let params = { let params = {
sales: [ sales: [
{id: 1}, {id: 7},
{id: 2}, {id: 8}],
{id: 3}, ticketFk: 11,
{id: 4}],
ticketFk: 1,
reserved: true reserved: true
}; };
await app.models.Sale.reserve(params); await app.models.Sale.reserve(params);
let reservedTicketSales = await app.models.Ticket.getSales(1); let reservedTicketSales = await app.models.Ticket.getSales(11);
expect(reservedTicketSales[0].reserved).toEqual(1); expect(reservedTicketSales[0].reserved).toEqual(1);
expect(reservedTicketSales[1].reserved).toEqual(1); expect(reservedTicketSales[1].reserved).toEqual(1);
expect(reservedTicketSales[2].reserved).toEqual(1);
expect(reservedTicketSales[3].reserved).toEqual(1);
}); });
}); });

View File

@ -1,21 +1,76 @@
const app = require(`${servicesDir}/ticket/server/server`); const app = require(`${servicesDir}/ticket/server/server`);
xdescribe('ticket componentUpdate()', () => { describe('ticket componentUpdate()', () => {
it('should call the componentUpdate method and receive an error', async() => { let firstvalueBeforeChange;
let secondvalueBeforeChange;
let componentOfSaleSeven = `SELECT value FROM vn.saleComponent
WHERE saleFk = 7 AND componentFk = 15`;
let componentOfSaleEight = `SELECT value FROM vn.saleComponent
WHERE saleFk = 8 AND componentFk = 15`;
const toDay = new Date();
beforeAll(async() => {
[componentValue] = await app.models.SaleComponent.rawSql(componentOfSaleSeven);
firstvalueBeforeChange = componentValue.value;
[componentValue] = await app.models.SaleComponent.rawSql(componentOfSaleEight);
secondvalueBeforeChange = componentValue.value;
});
it('should change the agencyMode to modify the sale components value', async() => {
let firstvalueAfterChange;
let secondvalueAfterChange;
let data = { let data = {
clientFk: 101, clientFk: 101,
agencyModeFk: 1, agencyModeFk: 8,
addressFk: 121, addressFk: 121,
warehouseFk: 1, warehouseFk: 1,
shipped: new Date(), shipped: toDay,
landed: new Date(), landed: toDay,
isDeleted: false, isDeleted: false,
hasToBeUnrouted: false, hasToBeUnrouted: false,
option: 1 option: 1
}; };
let ctx = {req: {accessToken: {userId: 101}}};
let result = await app.models.Ticket.componentUpdate(1, data, ctx);
expect(result.constructor.name).toEqual('OkPacket'); let ctx = {req: {accessToken: {userId: 101}}};
await app.models.Ticket.componentUpdate(11, data, ctx);
[componentValue] = await app.models.SaleComponent.rawSql(componentOfSaleSeven);
firstvalueAfterChange = componentValue.value;
[componentValue] = await app.models.SaleComponent.rawSql(componentOfSaleEight);
secondvalueAfterChange = componentValue.value;
expect(firstvalueBeforeChange).not.toEqual(firstvalueAfterChange);
expect(secondvalueBeforeChange).not.toEqual(secondvalueAfterChange);
});
it('should change the agencyMode to go back to the originals sale components value', async() => {
let firstvalueAfterChange;
let secondvalueAfterChange;
let data = {
clientFk: 101,
agencyModeFk: 7,
addressFk: 121,
warehouseFk: 1,
shipped: toDay,
landed: toDay,
isDeleted: false,
hasToBeUnrouted: false,
option: 1
};
let ctx = {req: {accessToken: {userId: 101}}};
await app.models.Ticket.componentUpdate(11, data, ctx);
[componentValue] = await app.models.SaleComponent.rawSql(componentOfSaleSeven);
firstvalueAfterChange = componentValue.value;
[componentValue] = await app.models.SaleComponent.rawSql(componentOfSaleEight);
secondvalueAfterChange = componentValue.value;
expect(firstvalueBeforeChange).toEqual(firstvalueAfterChange);
expect(secondvalueBeforeChange).toEqual(secondvalueAfterChange);
}); });
}); });

View File

@ -4,7 +4,7 @@ describe('ticket getSalesPersonMana()', () => {
it('should get the mana of a salesperson of a given ticket', async() => { it('should get the mana of a salesperson of a given ticket', async() => {
let mana = await app.models.Ticket.getSalesPersonMana(1); let mana = await app.models.Ticket.getSalesPersonMana(1);
expect(mana).toEqual(470); expect(mana).toEqual(221);
}); });
it('should return 0 if the given ticket does not exists', async() => { it('should return 0 if the given ticket does not exists', async() => {

View File

@ -4,6 +4,6 @@ describe('ticket getTaxes()', () => {
it('should return the tax of a given ticket', async() => { it('should return the tax of a given ticket', async() => {
let result = await app.models.Ticket.getTaxes(1); let result = await app.models.Ticket.getTaxes(1);
expect(result[0].tax).toEqual(9.29); expect(result[0].tax).toEqual(7.44);
}); });
}); });

View File

@ -4,7 +4,7 @@ describe('ticket getTotal()', () => {
it('should return the total of a ticket', async() => { it('should return the total of a ticket', async() => {
let result = await app.models.Ticket.getTotal(1); let result = await app.models.Ticket.getTotal(1);
expect(result).toEqual(181.12); expect(result).toEqual(155.89);
}); });
it(`should return zero if the ticket doesn't have lines`, async() => { it(`should return zero if the ticket doesn't have lines`, async() => {

View File

@ -4,7 +4,7 @@ describe('ticket getVAT()', () => {
it('should call the getVAT method and return the response', async() => { it('should call the getVAT method and return the response', async() => {
await app.models.Ticket.getVAT(1) await app.models.Ticket.getVAT(1)
.then(response => { .then(response => {
expect(response).toEqual(22.98); expect(response).toEqual(20.29);
}); });
}); });

View File

@ -17,13 +17,13 @@ describe('ticket summary()', () => {
it('should return a summary object containing subTotal for 1 ticket', async() => { it('should return a summary object containing subTotal for 1 ticket', async() => {
let result = await app.models.Ticket.summary(1); let result = await app.models.Ticket.summary(1);
expect(result.subTotal).toEqual(158.14); expect(Math.round(result.subTotal * 100) / 100).toEqual(135.60);
}); });
it('should return a summary object containing VAT for 1 ticket', async() => { it('should return a summary object containing VAT for 1 ticket', async() => {
let result = await app.models.Ticket.summary(1); let result = await app.models.Ticket.summary(1);
expect(Math.round(result.VAT * 100) / 100).toEqual(22.98); expect(Math.round(result.VAT * 100) / 100).toEqual(20.29);
}); });
it('should return a summary object containing total for 1 ticket', async() => { it('should return a summary object containing total for 1 ticket', async() => {

View File

@ -4,7 +4,7 @@ describe('workerMana getCurrentWorkerMana()', () => {
it('should get the mana of the logged worker', async() => { it('should get the mana of the logged worker', async() => {
let mana = await app.models.WorkerMana.getCurrentWorkerMana({req: {accessToken: {userId: 18}}}); let mana = await app.models.WorkerMana.getCurrentWorkerMana({req: {accessToken: {userId: 18}}});
expect(mana).toEqual(470); expect(mana).toEqual(221);
}); });
it('should return 0 if the user doesnt uses mana', async() => { it('should return 0 if the user doesnt uses mana', async() => {

View File

@ -15,6 +15,10 @@
"name": { "name": {
"type": "String", "type": "String",
"required": false "required": false
},
"code": {
"type": "String",
"required": false
} }
} }
} }

View File

@ -4,7 +4,7 @@
"dear": "Estimado cliente,", "dear": "Estimado cliente,",
"bodyDescription": "Siga las intrucciones especificadas en este correo para llevar a cabo la instalación de la impresora.", "bodyDescription": "Siga las intrucciones especificadas en este correo para llevar a cabo la instalación de la impresora.",
"followGuide": "Puede utilizar como guía, el video del montaje del ribon y la cinta <a href=\"https:\//www.youtube.com/watch?v=qhb0kgQF3o8\" title=\"Youtube\" target=\"_blank\" style=\"color:#8dba25\">https://www.youtube.com/watch?v=qhb0kgQF3o8</a>. También necesitará el QLabel, el programa para imprimir las cintas.", "followGuide": "Puede utilizar como guía, el video del montaje del ribon y la cinta <a href=\"https:\//www.youtube.com/watch?v=qhb0kgQF3o8\" title=\"Youtube\" target=\"_blank\" style=\"color:#8dba25\">https://www.youtube.com/watch?v=qhb0kgQF3o8</a>. También necesitará el QLabel, el programa para imprimir las cintas.",
"downloadFrom": "Puede descargarlo desde este enlace <a href=\"http://www.godexintl.com/en/product/type/Download/2967\" title=\"Descargar QLabel\" target=\"_blank\" style=\"color:#8dba25\">http://www.godexintl.com/en/product/type/Download/2967</a>", "downloadFrom": "Puede descargarlo desde este enlace <a href=\"http://ww.godexintl.com/es1/download/downloads/Download/2996\" title=\"Descargar QLabel\" target=\"_blank\" style=\"color:#8dba25\">http://ww.godexintl.com/es1/download/downloads/Download/2996</a>",
"sectionQLabelTitle": "Utilización de QLabel", "sectionQLabelTitle": "Utilización de QLabel",
"sectionQLabelDescription": "Para utilizar el programa de impresión de cintas siga estos pasos:", "sectionQLabelDescription": "Para utilizar el programa de impresión de cintas siga estos pasos:",
"sectionQLabelStep1": "Abra el programa QLabel.", "sectionQLabelStep1": "Abra el programa QLabel.",

View File

@ -1,6 +1,6 @@
const app = require(`${servicesDir}/order/server/server`); const app = require(`${servicesDir}/order/server/server`);
xdescribe('order getTaxes()', () => { describe('order getTaxes()', () => {
it('should call the getTaxes method and return undefined if its called with a string', async() => { it('should call the getTaxes method and return undefined if its called with a string', async() => {
let result = await app.models.Order.getTaxes('pepinillos'); let result = await app.models.Order.getTaxes('pepinillos');

View File

@ -1,6 +1,6 @@
const app = require(`${servicesDir}/order/server/server`); const app = require(`${servicesDir}/order/server/server`);
xdescribe('order getTotal()', () => { describe('order getTotal()', () => {
it('should return the total', async() => { it('should return the total', async() => {
let result = await app.models.Order.getTotal(1); let result = await app.models.Order.getTotal(1);

View File

@ -16,7 +16,7 @@
"required": true "required": true
}, },
"hour": { "hour": {
"type": "Date", "type": "date",
"required": true "required": true
}, },
"travelingDays": { "travelingDays": {