Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 3689-deliveryBoss
This commit is contained in:
commit
bacfa3f1f5
|
@ -2453,6 +2453,18 @@ INSERT INTO `bs`.`defaulter` (`clientFk`, `amount`, `created`, `defaulterSinced`
|
|||
(1107, 500, CURDATE(), CURDATE()),
|
||||
(1109, 500, CURDATE(), CURDATE());
|
||||
|
||||
INSERT INTO `bs`.`salesPerson` (`workerFk`, `year`, `month`, `portfolioWeight`)
|
||||
VALUES
|
||||
(18, YEAR(CURDATE()), MONTH(CURDATE()), 807.23),
|
||||
(19, YEAR(CURDATE()), MONTH(CURDATE()), 34.40);
|
||||
|
||||
INSERT INTO `bs`.`sale` (`saleFk`, `amount`, `dated`, `typeFk`, `clientFk`)
|
||||
VALUES
|
||||
(1, 501.95, CURDATE(), 2, 1101),
|
||||
(2, 70.7, CURDATE(), 2, 1101),
|
||||
(3, 200.78, CURDATE(), 2, 1101),
|
||||
(4, 33.8, CURDATE(), 1, 1101),
|
||||
(30, 34.4, CURDATE(), 1, 1108);
|
||||
INSERT INTO `vn`.`docuware` (`code`, `fileCabinetName`, `dialogName` , `find`)
|
||||
VALUES
|
||||
('deliveryClientTest', 'deliveryClientTest', 'findTest', 'word');
|
||||
|
|
|
@ -97,7 +97,8 @@ ngModule.vnComponent('vnDescriptor', {
|
|||
btnOne: '?btnOne',
|
||||
btnTwo: '?btnTwo',
|
||||
btnThree: '?btnThree',
|
||||
btnFour: '?btnFour'
|
||||
btnFour: '?btnFour',
|
||||
btnFive: '?btnFive'
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ vn-descriptor-content {
|
|||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0 $spacing-sm;
|
||||
margin: 0 $spacing-sm;
|
||||
margin: 0 $spacing-xs;
|
||||
|
||||
& > vn-icon {
|
||||
font-size: 1.75rem;
|
||||
|
|
|
@ -64,6 +64,12 @@ module.exports = function(Self) {
|
|||
scope: {
|
||||
fields: ['id', 'name', 'active']
|
||||
}
|
||||
},
|
||||
{
|
||||
relation: 'supplier',
|
||||
scope: {
|
||||
fields: ['id', 'nif']
|
||||
}
|
||||
}
|
||||
]
|
||||
}, myOptions);
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
xdescribe('Client updatePortfolio', () => {
|
||||
const salesPersonId = 18;
|
||||
const clientId = 1108;
|
||||
it('should update the portfolioWeight', async() => {
|
||||
const tx = await models.Client.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const expectedResult = 841.63;
|
||||
|
||||
await models.Client.rawSql(`UPDATE vn.client SET salesPersonFk = ${salesPersonId} WHERE id = ${clientId}; `);
|
||||
|
||||
await models.Client.updatePortfolio();
|
||||
|
||||
let [vendedores] = await models.Client.rawSql(`SELECT portfolioWeight FROM bs.vendedores WHERE Id_Trabajador = ${salesPersonId}; `, null, options);
|
||||
|
||||
expect(vendedores.portfolioWeight).toEqual(expectedResult);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -0,0 +1,20 @@
|
|||
module.exports = function(Self) {
|
||||
Self.remoteMethodCtx('updatePortfolio', {
|
||||
description: 'Update salesPeson potfolio weight',
|
||||
accessType: 'READ',
|
||||
accepts: [],
|
||||
returns: {
|
||||
type: 'Object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/updatePortfolio`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.updatePortfolio = async() => {
|
||||
query = `CALL bs.salesPerson_updatePortfolio()`;
|
||||
return await Self.rawSql(query);
|
||||
};
|
||||
};
|
|
@ -29,6 +29,7 @@ module.exports = Self => {
|
|||
require('../methods/client/updateAddress')(Self);
|
||||
require('../methods/client/consumption')(Self);
|
||||
require('../methods/client/createReceipt')(Self);
|
||||
require('../methods/client/updatePortfolio')(Self);
|
||||
|
||||
// Validations
|
||||
|
||||
|
|
|
@ -228,6 +228,12 @@
|
|||
"type": "belongsTo",
|
||||
"model": "Client",
|
||||
"foreignKey": "transferorFk"
|
||||
},
|
||||
"supplier": {
|
||||
"type": "belongsTo",
|
||||
"model": "Supplier",
|
||||
"foreignKey": "fi",
|
||||
"primaryKey": "nif"
|
||||
}
|
||||
},
|
||||
"scopes": {
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
url="ContactChannels"
|
||||
data="contactChannels">
|
||||
</vn-crud-model>
|
||||
<form name="form" vn-http-submit="watcher.submit()" class="vn-w-md">
|
||||
<form name="form" vn-http-submit="$ctrl.onSubmit()" class="vn-w-md">
|
||||
<vn-card class="vn-pa-lg">
|
||||
<vn-horizontal>
|
||||
<vn-textfield
|
||||
|
|
|
@ -7,6 +7,13 @@ export default class Controller extends Section {
|
|||
? {id: $search}
|
||||
: {name: {like: '%' + $search + '%'}};
|
||||
}
|
||||
|
||||
onSubmit() {
|
||||
return this.$.watcher.submit().then(() => {
|
||||
const query = `Clients/updatePortfolio`;
|
||||
this.$http.get(query);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ngModule.vnComponent('vnClientBasicData', {
|
||||
|
|
|
@ -101,6 +101,14 @@
|
|||
icon="face">
|
||||
</vn-quick-link>
|
||||
</div>
|
||||
<div ng-transclude="btnFive">
|
||||
<vn-quick-link
|
||||
ng-if="$ctrl.client.supplier.nif"
|
||||
tooltip="Go to client"
|
||||
state="['supplier.card.summary', {id: $ctrl.client.supplier.id}]"
|
||||
icon="icon-supplier">
|
||||
</vn-quick-link>
|
||||
</div>
|
||||
</div>
|
||||
</slot-body>
|
||||
</vn-descriptor-content>
|
||||
|
|
|
@ -53,11 +53,11 @@ describe('order filter()', () => {
|
|||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const filter = {where: {'o.confirmed': false, 'c.salesPersonFk': 18}};
|
||||
const filter = {where: {'o.confirmed': false, 'c.salesPersonFk': 9}};
|
||||
const result = await models.Order.filter(myCtx, filter, options);
|
||||
|
||||
expect(result.length).toEqual(9);
|
||||
expect(result[0].id).toEqual(7);
|
||||
expect(result.length).toEqual(4);
|
||||
expect(result[0].id).toEqual(19);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
|
|
|
@ -11,3 +11,4 @@ import './create';
|
|||
import './basic-data';
|
||||
import './log';
|
||||
import './tickets';
|
||||
import './ticket-popup';
|
||||
|
|
|
@ -48,6 +48,11 @@
|
|||
<vn-td number>{{::route.m3 | dashIfEmpty}}</vn-td>
|
||||
<vn-td>{{::route.description | dashIfEmpty}}</vn-td>
|
||||
<vn-td>
|
||||
<vn-icon-button
|
||||
vn-click-stop="$ctrl.showTicketPopup(route)"
|
||||
vn-tooltip="Añadir tickets"
|
||||
icon="icon-ticketAdd">
|
||||
</vn-icon-button>
|
||||
<vn-icon-button
|
||||
vn-click-stop="$ctrl.preview(route)"
|
||||
vn-tooltip="Preview"
|
||||
|
@ -66,9 +71,20 @@
|
|||
</vn-route-summary>
|
||||
</vn-popup>
|
||||
|
||||
<vn-route-ticket-popup
|
||||
vn-id="ticketPopup"
|
||||
route="$ctrl.routeSelected">
|
||||
</vn-route-ticket-popup>
|
||||
|
||||
<vn-worker-descriptor-popover
|
||||
vn-id="workerDescriptor">
|
||||
</vn-worker-descriptor-popover>
|
||||
<vn-ticket-descriptor-popover
|
||||
vn-id="ticketDescriptor">
|
||||
</vn-ticket-descriptor-popover>
|
||||
<vn-client-descriptor-popover
|
||||
vn-id="clientDescriptor">
|
||||
</vn-client-descriptor-popover>
|
||||
|
||||
<div fixed-bottom-right>
|
||||
<vn-vertical style="align-items: center;">
|
||||
|
|
|
@ -13,6 +13,11 @@ export default class Controller extends Section {
|
|||
this.$.summary.show();
|
||||
}
|
||||
|
||||
showTicketPopup(route) {
|
||||
this.routeSelected = route;
|
||||
this.$.ticketPopup.show();
|
||||
}
|
||||
|
||||
get checked() {
|
||||
const rows = this.$.model.data || [];
|
||||
const checkedRows = [];
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
|
||||
<tpl-title>
|
||||
<vn-horizontal>
|
||||
<span translate>Tickets to add</span>
|
||||
<div class="button-right">
|
||||
<vn-button label="Add" ng-click="$ctrl.setTicketsRoute()"></vn-button>
|
||||
</div>
|
||||
</vn-horizontal>
|
||||
</tpl-title>
|
||||
<tpl-body id="manifold-form">
|
||||
<vn-crud-model
|
||||
vn-id="model"
|
||||
url="Routes/{{$ctrl.route.id}}/getSuggestedTickets"
|
||||
data="$ctrl.possibleTickets"
|
||||
auto-load="true">
|
||||
</vn-crud-model>
|
||||
<vn-data-viewer data="$ctrl.possibleTickets" class="manifold-panel">
|
||||
<vn-table auto-load="true">
|
||||
<vn-thead>
|
||||
<vn-tr>
|
||||
<vn-th shrink>
|
||||
<vn-multi-check
|
||||
model="model">
|
||||
</vn-multi-check>
|
||||
</vn-th>
|
||||
<vn-th number>Ticket</vn-th>
|
||||
<vn-th>Client</vn-th>
|
||||
<vn-th shrink>Province</vn-th>
|
||||
<vn-th shrink>
|
||||
<span translate>
|
||||
Population
|
||||
</span>
|
||||
</vn-th>
|
||||
<vn-th expand>PC</vn-th>
|
||||
<vn-th>Address</vn-th>
|
||||
<vn-th shrink>Warehouse</vn-th>
|
||||
</vn-tr>
|
||||
</vn-thead>
|
||||
<vn-tbody>
|
||||
<vn-tr ng-repeat="ticket in $ctrl.possibleTickets">
|
||||
<vn-td shrink>
|
||||
<vn-check
|
||||
ng-model="ticket.checked">
|
||||
</vn-check>
|
||||
</vn-td>
|
||||
<vn-td number>
|
||||
<span class="link" ng-click="ticketDescriptor.show($event, ticket.id)">
|
||||
{{::ticket.id}}
|
||||
</span>
|
||||
</vn-td>
|
||||
<vn-td expand>
|
||||
<span class="link" ng-click="clientDescriptor.show($event, ticket.clientFk)">
|
||||
{{::ticket.nickname}}
|
||||
</span>
|
||||
</vn-td>
|
||||
<vn-td shrink>{{::ticket.address.province.name}}</vn-td>
|
||||
<vn-td shrink>{{::ticket.address.city}}</vn-td>
|
||||
<vn-td number shrink>{{::ticket.address.postalCode}}</vn-td>
|
||||
<vn-td expand title="{{::ticket.address.street}}">{{::ticket.address.street}}</vn-td>
|
||||
<vn-td expand>
|
||||
{{::ticket.zone.name}}
|
||||
<vn-icon-button
|
||||
icon="link_off"
|
||||
class="pointer"
|
||||
translate-attr="{title: 'Unlink zone: {{::ticket.zone.name}} from agency: {{::ticket.agencyMode.name}}'}"
|
||||
ng-click="unlinkZoneConfirmation.show(ticket)">
|
||||
</vn-icon-button>
|
||||
</vn-td>
|
||||
</vn-tr>
|
||||
</vn-tbody>
|
||||
</vn-table>
|
||||
</vn-data-viewer>
|
||||
<vn-confirm
|
||||
vn-id="unlinkZoneConfirmation"
|
||||
on-accept="$ctrl.unlinkZone($data)"
|
||||
question="{{$ctrl.confirmationMessage}}"
|
||||
message="Unlink selected zone?">
|
||||
</vn-confirm>
|
||||
</tpl-body>
|
|
@ -0,0 +1,80 @@
|
|||
import ngModule from '../module';
|
||||
import Dialog from 'core/components/dialog';
|
||||
import './style.scss';
|
||||
|
||||
class Controller extends Dialog {
|
||||
constructor($element, $, $transclude) {
|
||||
super($element, $, $transclude);
|
||||
}
|
||||
|
||||
getSelectedTickets(tickets) {
|
||||
const selectedTickets = [];
|
||||
|
||||
if (tickets) {
|
||||
for (let i = 0; i < tickets.length; i++) {
|
||||
if (tickets[i].checked)
|
||||
selectedTickets.push(tickets[i]);
|
||||
}
|
||||
}
|
||||
return selectedTickets;
|
||||
}
|
||||
|
||||
updateVolume() {
|
||||
let url = `Routes/${this.route.id}/updateVolume`;
|
||||
this.$http.post(url).then(() => {
|
||||
this.$.model.refresh();
|
||||
if (this.parentReload)
|
||||
this.parentReload();
|
||||
});
|
||||
}
|
||||
|
||||
setTicketsRoute() {
|
||||
const tickets = this.getSelectedTickets(this.possibleTickets);
|
||||
if (tickets.length === 0) return;
|
||||
|
||||
const updates = [];
|
||||
|
||||
for (let ticket of tickets) {
|
||||
delete ticket.checked;
|
||||
const update = {
|
||||
where: {id: ticket.id},
|
||||
data: {routeFk: this.route.id}
|
||||
};
|
||||
|
||||
updates.push(update);
|
||||
}
|
||||
|
||||
const data = {creates: [], updates: updates, deletes: []};
|
||||
return this.$http.post(`Tickets/crud`, data)
|
||||
.then(() => {
|
||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||
this.updateVolume();
|
||||
this.hide();
|
||||
});
|
||||
}
|
||||
|
||||
unlinkZone(ticket) {
|
||||
const params = {
|
||||
agencyModeId: this.route.agencyModeFk,
|
||||
zoneId: ticket.zoneFk,
|
||||
};
|
||||
|
||||
const query = `Routes/unlink`;
|
||||
this.$http.post(query, params).then(() => {
|
||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||
this.$.model.refresh();
|
||||
this.hide();
|
||||
});
|
||||
}
|
||||
}
|
||||
Controller.$inject = ['$element', '$scope', '$transclude'];
|
||||
|
||||
ngModule.vnComponent('vnRouteTicketPopup', {
|
||||
slotTemplate: require('./index.html'),
|
||||
controller: Controller,
|
||||
bindings: {
|
||||
route: '<',
|
||||
model: '<?',
|
||||
parentReload: '&'
|
||||
}
|
||||
});
|
|
@ -0,0 +1,82 @@
|
|||
/* eslint max-len: ["error", { "code": 150 }]*/
|
||||
import './index';
|
||||
|
||||
describe('Route', () => {
|
||||
let controller;
|
||||
let $httpBackend;
|
||||
let $scope;
|
||||
|
||||
beforeEach(ngModule('route'));
|
||||
|
||||
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
|
||||
$httpBackend = _$httpBackend_;
|
||||
$scope = $rootScope.$new();
|
||||
const $element = angular.element('<vn-route-ticket-popup></vn-route-ticket-popup>');
|
||||
const $transclude = {
|
||||
$$boundTransclude: {
|
||||
$$slots: []
|
||||
}
|
||||
};
|
||||
controller = $componentController('vnRouteTicketPopup', {$element, $scope, $transclude});
|
||||
controller.route = {id: 1};
|
||||
controller.$.model = {
|
||||
refresh: () => {},
|
||||
remove: () => {}
|
||||
};
|
||||
controller.card = {reload: () => {}};
|
||||
}));
|
||||
|
||||
describe('unlink()', () => {
|
||||
it('should call the route unlink endpoint with the agency and zone ids', () => {
|
||||
controller.$.model = {refresh: jest.fn()};
|
||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||
jest.spyOn(controller, 'hide');
|
||||
|
||||
controller.route = {
|
||||
agencyModeFk: 1
|
||||
};
|
||||
|
||||
const ticket = {
|
||||
zoneFk: 2,
|
||||
};
|
||||
const params = {
|
||||
agencyModeId: controller.route.agencyModeFk,
|
||||
zoneId: ticket.zoneFk,
|
||||
};
|
||||
|
||||
$httpBackend.expectPOST(`Routes/unlink`, params).respond('ok');
|
||||
controller.unlinkZone(ticket);
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
||||
expect(controller.hide).toHaveBeenCalled();
|
||||
expect(controller.$.model.refresh).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
describe('setTicketsRoute()', () => {
|
||||
it('should perform a POST query to add tickets to the route', () => {
|
||||
controller.$.model = {refresh: jest.fn()};
|
||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||
jest.spyOn(controller, 'hide');
|
||||
|
||||
controller.route = {id: 111};
|
||||
|
||||
controller.possibleTickets = [
|
||||
{id: 2, checked: false},
|
||||
{id: 3, checked: true},
|
||||
{id: 4, checked: false},
|
||||
{id: 5, checked: true},
|
||||
];
|
||||
|
||||
$httpBackend.whenPOST(`Routes/${controller.route.id}/updateVolume`).respond(200);
|
||||
$httpBackend.expectPOST('Tickets/crud').respond();
|
||||
controller.setTicketsRoute();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
||||
expect(controller.hide).toHaveBeenCalled();
|
||||
expect(controller.$.model.refresh).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,5 @@
|
|||
@import "variables";
|
||||
|
||||
.dialog{
|
||||
padding: $float-spacing
|
||||
}
|
|
@ -115,83 +115,16 @@
|
|||
question="Delete ticket from route?"
|
||||
on-accept="$ctrl.removeTicketFromRoute($index)">
|
||||
</vn-confirm>
|
||||
<vn-crud-model
|
||||
vn-id="possibleTicketsModel"
|
||||
url="Routes/{{$ctrl.$params.id}}/getSuggestedTickets"
|
||||
data="$ctrl.possibleTickets">
|
||||
</vn-crud-model>
|
||||
<vn-dialog
|
||||
vn-id="possibleTicketsDialog">
|
||||
<tpl-title>
|
||||
<vn-horizontal>
|
||||
<span translate>Tickets to add</span>
|
||||
<div class="button-right">
|
||||
<vn-button label="Add" ng-click="$ctrl.setTicketsRoute()"></vn-button>
|
||||
</div>
|
||||
</vn-horizontal>
|
||||
</tpl-title>
|
||||
<tpl-body>
|
||||
<vn-data-viewer model="possibleTicketsModel">
|
||||
<vn-table model="possibleTicketsModel" auto-load="false">
|
||||
<vn-thead>
|
||||
<vn-tr>
|
||||
<vn-th shrink>
|
||||
<vn-multi-check
|
||||
model="possibleTicketsModel">
|
||||
</vn-multi-check>
|
||||
</vn-th>
|
||||
<vn-th number>Ticket</vn-th>
|
||||
<vn-th>Client</vn-th>
|
||||
<vn-th shrink>Province</vn-th>
|
||||
<vn-th shrink>
|
||||
<span translate>
|
||||
Population
|
||||
</span>
|
||||
</vn-th>
|
||||
<vn-th expand>PC</vn-th>
|
||||
<vn-th>Address</vn-th>
|
||||
<vn-th shrink>Zone</vn-th>
|
||||
</vn-tr>
|
||||
</vn-thead>
|
||||
<vn-tbody>
|
||||
<vn-tr ng-repeat="ticket in $ctrl.possibleTickets">
|
||||
<vn-td shrink>
|
||||
<vn-check
|
||||
ng-model="ticket.checked">
|
||||
</vn-check>
|
||||
</vn-td>
|
||||
<vn-td number>
|
||||
<span class="link" ng-click="ticketDescriptor.show($event, ticket.id)">
|
||||
{{::ticket.id}}
|
||||
</span>
|
||||
</vn-td>
|
||||
<vn-td expand>
|
||||
<span class="link" ng-click="clientDescriptor.show($event, ticket.clientFk)">
|
||||
{{::ticket.nickname}}
|
||||
</span>
|
||||
</vn-td>
|
||||
<vn-td shrink>{{::ticket.address.province.name}}</vn-td>
|
||||
<vn-td shrink>{{::ticket.address.city}}</vn-td>
|
||||
<vn-td number shrink>{{::ticket.address.postalCode}}</vn-td>
|
||||
<vn-td expand title="{{::ticket.address.street}}">{{::ticket.address.street}}</vn-td>
|
||||
<vn-td expand>
|
||||
{{::ticket.zone.name}}
|
||||
<vn-icon-button
|
||||
icon="link_off"
|
||||
class="pointer"
|
||||
translate-attr="{title: 'Unlink zone: {{::ticket.zone.name}} from agency: {{::ticket.agencyMode.name}}'}"
|
||||
ng-click="unlinkZoneConfirmation.show(ticket)">
|
||||
</vn-icon-button>
|
||||
</vn-td>
|
||||
</vn-tr>
|
||||
</vn-tbody>
|
||||
</vn-table>
|
||||
</vn-data-viewer>
|
||||
</tpl-body>
|
||||
</vn-dialog>
|
||||
|
||||
<vn-route-ticket-popup
|
||||
vn-id="ticketPopup"
|
||||
route="$ctrl.$params"
|
||||
parent-reload="$ctrl.$.model.refresh()">
|
||||
</vn-route-ticket-popup>
|
||||
|
||||
<vn-float-button
|
||||
icon="add"
|
||||
ng-click="$ctrl.openPossibleTicketsDialog()"
|
||||
ng-click="$ctrl.$.ticketPopup.show()"
|
||||
vn-tooltip="Add ticket"
|
||||
vn-acl="delivery"
|
||||
vn-acl-action="remove"
|
||||
|
@ -204,11 +137,3 @@
|
|||
<vn-client-descriptor-popover
|
||||
vn-id="client-descriptor">
|
||||
</vn-client-descriptor-popover>
|
||||
|
||||
<!-- Unlink zone confirmation dialog -->
|
||||
<vn-confirm
|
||||
vn-id="unlinkZoneConfirmation"
|
||||
on-accept="$ctrl.unlinkZone($data)"
|
||||
question="{{$ctrl.confirmationMessage}}"
|
||||
message="Unlink selected zone?">
|
||||
</vn-confirm>
|
|
@ -4,14 +4,6 @@ import './style.scss';
|
|||
import UserError from 'core/lib/user-error';
|
||||
|
||||
class Controller extends Section {
|
||||
get route() {
|
||||
return this._route;
|
||||
}
|
||||
|
||||
set route(value) {
|
||||
this._route = value;
|
||||
}
|
||||
|
||||
get isChecked() {
|
||||
if (this.tickets) {
|
||||
for (let instance of this.tickets)
|
||||
|
@ -37,19 +29,6 @@ class Controller extends Section {
|
|||
});
|
||||
}
|
||||
|
||||
unlinkZone(ticket) {
|
||||
const params = {
|
||||
agencyModeId: this.route.agencyModeFk,
|
||||
zoneId: ticket.zoneFk,
|
||||
};
|
||||
|
||||
const query = `Routes/unlink`;
|
||||
this.$http.post(query, params).then(() => {
|
||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||
this.$.possibleTicketsModel.refresh();
|
||||
});
|
||||
}
|
||||
|
||||
getSelectedItems(items) {
|
||||
const selectedItems = [];
|
||||
|
||||
|
@ -117,38 +96,6 @@ class Controller extends Section {
|
|||
});
|
||||
}
|
||||
|
||||
openPossibleTicketsDialog() {
|
||||
this.$.possibleTicketsModel.refresh();
|
||||
this.$.possibleTicketsDialog.show();
|
||||
}
|
||||
|
||||
setTicketsRoute() {
|
||||
let tickets = this.getSelectedItems(this.possibleTickets);
|
||||
if (tickets.length === 0) return;
|
||||
|
||||
const updates = [];
|
||||
|
||||
for (let ticket of tickets) {
|
||||
delete ticket.checked;
|
||||
const update = {
|
||||
where: {id: ticket.id},
|
||||
data: {routeFk: this.route.id}
|
||||
};
|
||||
|
||||
updates.push(update);
|
||||
}
|
||||
|
||||
const data = {creates: [], updates: updates, deletes: []};
|
||||
|
||||
return this.$http.post(`Tickets/crud`, data)
|
||||
.then(() => {
|
||||
this.$.model.data = this.$.model.data.concat(tickets);
|
||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||
this.updateVolume();
|
||||
this.$.possibleTicketsDialog.hide();
|
||||
});
|
||||
}
|
||||
|
||||
onDrop($event) {
|
||||
const ticketId = $event.dataTransfer.getData('Text');
|
||||
|
||||
|
|
|
@ -74,32 +74,6 @@ describe('Route', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('unlink()', () => {
|
||||
it('should call the route unlink endpoint with the agency and zone ids', () => {
|
||||
controller.$.possibleTicketsModel = {refresh: jest.fn()};
|
||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||
|
||||
controller.route = {
|
||||
agencyModeFk: 1
|
||||
};
|
||||
|
||||
const ticket = {
|
||||
zoneFk: 2,
|
||||
};
|
||||
const params = {
|
||||
agencyModeId: controller.route.agencyModeFk,
|
||||
zoneId: ticket.zoneFk,
|
||||
};
|
||||
|
||||
$httpBackend.expectPOST(`Routes/unlink`, params).respond('ok');
|
||||
controller.unlinkZone(ticket);
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
||||
expect(controller.$.possibleTicketsModel.refresh).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getSelectedItems()', () => {
|
||||
it('should return the selected items', () => {
|
||||
let items = [
|
||||
|
@ -208,55 +182,6 @@ describe('Route', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('openPossibleTicketsDialog()', () => {
|
||||
it('should call both refresh and show methods in posible tickets model and dialog', () => {
|
||||
controller.$.possibleTicketsModel = {refresh: () => {}};
|
||||
jest.spyOn(controller.$.possibleTicketsModel, 'refresh');
|
||||
controller.$.possibleTicketsDialog = {show: () => {}};
|
||||
jest.spyOn(controller.$.possibleTicketsDialog, 'show');
|
||||
|
||||
controller.openPossibleTicketsDialog();
|
||||
|
||||
expect(controller.$.possibleTicketsModel.refresh).toHaveBeenCalledWith();
|
||||
expect(controller.$.possibleTicketsDialog.show).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
describe('setTicketsRoute()', () => {
|
||||
it('should perform a POST query to add tickets to the route', () => {
|
||||
controller.$.possibleTicketsDialog = {hide: () => {}};
|
||||
jest.spyOn(controller.$.possibleTicketsDialog, 'hide');
|
||||
|
||||
controller.$params = {id: 1101};
|
||||
controller.$.model.data = [{id: 1, checked: false}];
|
||||
|
||||
const existingTicket = controller.$.model.data[0];
|
||||
|
||||
controller.route = {id: 111};
|
||||
|
||||
controller.possibleTickets = [
|
||||
{id: 2, checked: false},
|
||||
{id: 3, checked: true},
|
||||
{id: 4, checked: false},
|
||||
{id: 5, checked: true},
|
||||
];
|
||||
|
||||
let expectedResult = [
|
||||
existingTicket,
|
||||
{id: 3},
|
||||
{id: 5}
|
||||
];
|
||||
|
||||
$httpBackend.whenPOST(`Routes/${controller.$params.id}/updateVolume`).respond(200);
|
||||
$httpBackend.expectPOST('Tickets/crud').respond();
|
||||
controller.setTicketsRoute();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.$.model.data).toEqual(expectedResult);
|
||||
expect(controller.$.possibleTicketsDialog.hide).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
describe('onDrop()', () => {
|
||||
it('should call the insert method when dragging a ticket number', () => {
|
||||
jest.spyOn(controller, 'insert');
|
||||
|
|
|
@ -17,11 +17,6 @@ module.exports = Self => {
|
|||
arg: 'year',
|
||||
type: 'date',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'all',
|
||||
type: 'boolean',
|
||||
required: false,
|
||||
}],
|
||||
returns: [{
|
||||
arg: 'absences',
|
||||
|
|
|
@ -139,10 +139,6 @@
|
|||
<th class="font gray align-right">{{$t('salesPerson')}}</th>
|
||||
<td>{{ticket.salesPersonName}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="font gray align-right">{{$t('import')}}</th>
|
||||
<td>{{ticket.import | currency('EUR', $i18n.locale)}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div v-if="ticket.description || ticket.shipFk" class="text-area">
|
||||
|
|
Loading…
Reference in New Issue