This commit is contained in:
Juan Ferrer 2019-02-01 12:32:50 +01:00
commit 19d8a2c98c
5 changed files with 35 additions and 18 deletions

View File

@ -1,7 +1,9 @@
import ngModule from '../module';
class Controller {
constructor($state, $scope, $http) {
constructor($state, $scope, $http, vnApp, $translate) {
this.vnApp = vnApp;
this.$translate = $translate;
this.$scope = $scope;
this.$state = $state;
this.$http = $http;
@ -17,9 +19,9 @@ class Controller {
addStowaway(index) {
let params = {id: this.possibleStowaways[index].id, shipFk: this.ticket.id};
this.$http.post(`/api/Stowaways/`, params)
.then(res => {
this.ticket.ship.push = res.data[0];
this.hide;
.then(() => {
this.card.reload();
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
});
}
@ -39,5 +41,8 @@ ngModule.component('vnAddStowaway', {
controller: Controller,
bindings: {
ticket: '<'
},
require: {
card: '^vnTicketCard'
}
});

View File

@ -95,7 +95,7 @@
<vn-button-menu
ng-if="$ctrl.ticket.ship.length > 1"
vn-id="stowaways-button"
icon="icon-polizon"
icon="icon-stowaway"
show-filter="false"
show-field="id"
value-field="id"

View File

@ -40,7 +40,8 @@ class Controller {
shouldShowRemoveStowaway() {
if (!this._ticket)
return false;
return (this._ticket.stowaway || (this._ticket.ship && this._ticket.ship.length > 1));
return (this._ticket.stowaway || (this._ticket.ship && this._ticket.ship.length > 0));
}
onMoreChange(callback) {
@ -124,7 +125,7 @@ class Controller {
}};
if (value.stowaway) {
links.btnTwo = {
icon: 'icon-polizon',
icon: 'icon-stowaway',
state: `ticket.card.summary({id: ${value.stowaway.shipFk}})`,
tooltip: 'Ship'
};
@ -132,7 +133,7 @@ class Controller {
if (value.ship && value.ship.length == 1) {
links.btnThree = {
icon: 'icon-polizon',
icon: 'icon-stowaway',
state: `ticket.card.summary({id: ${value.ship[0].id}})`,
tooltip: 'Stowaway'
};

View File

@ -1,7 +1,9 @@
import ngModule from '../module';
class Controller {
constructor($state, $scope, $http) {
constructor($state, $scope, $http, vnApp, $translate) {
this.vnApp = vnApp;
this.$translate = $translate;
this.$scope = $scope;
this.$state = $state;
this.$http = $http;
@ -44,15 +46,8 @@ class Controller {
deleteStowaway(response) {
if (response === 'ACCEPT') {
this.$http.delete(`/api/Stowaways/${this.stowawayToDelete.id}`).then(res => {
if (this.ticket.stowaway)
delete this.ticket.stowaway;
else {
for (let i = 0; i < this.ticket.ship.length; i++) {
if (this.ticket.ship[i].id === this.stowawayToDelete.id)
delete this.ticket.ship[i];
}
}
this.hide();
this.card.reload();
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
});
}
}
@ -78,5 +73,8 @@ ngModule.component('vnRemoveStowaway', {
controller: Controller,
bindings: {
ticket: '<'
},
require: {
card: '^vnTicketCard'
}
});

View File

@ -0,0 +1,13 @@
DROP TRIGGER IF EXISTS vn2008.expeditionsBeforeDelete;
USE vn2008;
DELIMITER $$
$$
CREATE DEFINER=`root`@`%` TRIGGER `vn2008`.`expeditionsBeforeDelete`
BEFORE DELETE ON `expeditions` FOR EACH ROW
BEGIN
UPDATE Tickets SET Bultos = (SELECT COUNT(counter)-1
FROM expeditions WHERE ticket_id = OLD.ticket_id and EsBulto)
WHERE Id_Ticket = OLD.ticket_id;
END$$
DELIMITER ;