diff --git a/modules/item/front/index.js b/modules/item/front/index.js
index f853efa7c..c2f9a66f6 100644
--- a/modules/item/front/index.js
+++ b/modules/item/front/index.js
@@ -8,6 +8,8 @@ import './card';
import './descriptor';
import './descriptor-popover';
import './ticket-descriptor';
+import './ticket-descriptor/addStowaway';
+import './ticket-descriptor/removeStowaway';
import './ticket-descriptor-popover';
import './data';
import './tags';
diff --git a/modules/item/front/ticket-descriptor/addStowaway.html b/modules/item/front/ticket-descriptor/addStowaway.html
new file mode 100644
index 000000000..93a09b713
--- /dev/null
+++ b/modules/item/front/ticket-descriptor/addStowaway.html
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+ Ticket id
+ Shipped
+ Agency
+ Warehouse
+ State
+
+
+
+
+ {{ticket.id}}
+ {{ticket.landed | dateTime: 'dd/MM/yyyy'}}
+ {{ticket.agencyMode.name}}
+ {{ticket.warehouse.name}}
+ {{ticket.state.state.name}}
+
+
+
+ No results
+
+
+
+
+
\ No newline at end of file
diff --git a/modules/item/front/ticket-descriptor/addStowaway.js b/modules/item/front/ticket-descriptor/addStowaway.js
new file mode 100644
index 000000000..d61d88a66
--- /dev/null
+++ b/modules/item/front/ticket-descriptor/addStowaway.js
@@ -0,0 +1,46 @@
+import ngModule from '../module';
+
+class Controller {
+ constructor($state, $scope, $http) {
+ this.$scope = $scope;
+ this.$state = $state;
+ this.$http = $http;
+ }
+
+ getPossibleStowaways() {
+ this.$http.get(`/api/Tickets/${this.ticket.id}/getPossibleStowaways`)
+ .then(res => {
+ console.log(res);
+ this.possibleStowaways = res.data;
+ });
+ }
+
+ addStowaway(index) {
+ let params = {id: this.possibleStowaways[index].id, shipFk: this.ticket.id};
+ this.$http.post(`/api/Stowaways/`, params)
+ .then(() => {
+ this.card.reload();
+ });
+ }
+
+ show() {
+ this.$scope.dialog.show();
+ }
+
+ hide() {
+ this.$scope.dialog.hide();
+ }
+}
+
+Controller.$inject = ['$state', '$scope', '$http', 'vnApp', '$translate'];
+
+ngModule.component('vnAddStowaway', {
+ template: require('./addStowaway.html'),
+ controller: Controller,
+ bindings: {
+ ticket: '<'
+ },
+ require: {
+ card: '^vnTicketCard'
+ }
+});
diff --git a/modules/item/front/ticket-descriptor/index.html b/modules/item/front/ticket-descriptor/index.html
index 2d9e6d29a..e2bfc9677 100644
--- a/modules/item/front/ticket-descriptor/index.html
+++ b/modules/item/front/ticket-descriptor/index.html
@@ -91,6 +91,17 @@
icon="{{::$ctrl.quicklinks.btnThree.icon}}">
+
+
-
\ No newline at end of file
+
+
+
\ No newline at end of file
diff --git a/modules/item/front/ticket-descriptor/index.js b/modules/item/front/ticket-descriptor/index.js
index 8511f93db..b0d5c54fa 100644
--- a/modules/item/front/ticket-descriptor/index.js
+++ b/modules/item/front/ticket-descriptor/index.js
@@ -1,4 +1,5 @@
import ngModule from '../module';
+import './style.scss';
class Controller {
constructor($state, $scope, $http, vnApp, $translate) {
@@ -8,15 +9,34 @@ class Controller {
this.vnApp = vnApp;
this.$translate = $translate;
this.moreOptions = [
- {callback: this.showAddTurnDialog, name: 'Add turn'},
- {callback: this.showDeleteTicketDialog, name: 'Delete ticket'}
+ {callback: this.showAddTurnDialog, name: 'Add turn', show: true},
+ {callback: this.showDeleteTicketDialog, name: 'Delete ticket', show: true},
+ {callback: this.showAddStowaway, name: 'Add stowaway', show: true},
+ {callback: this.showRemoveStowaway, name: 'Remove stowaway', show: () => this.shouldShowRemoveStowaway()}
];
}
+ shouldShowRemoveStowaway() {
+ if (!this._ticket)
+ return false;
+ return (this._ticket.stowaway || this._ticket.ship.length > 1);
+ }
+
onMoreChange(callback) {
callback.call(this);
}
+ goToTicket(ticketID) {
+ this.$state.go('ticket.card.sale', {id: ticketID});
+ }
+
+ onMoreOpen() {
+ let options = this.moreOptions.filter(o => {
+ return o.show === true || typeof o.show === 'function' && o.show();
+ });
+ this.$scope.moreButton.data = options;
+ }
+
get isEditable() {
try {
return !this.ticket.tracking.state.alertLevel;
@@ -58,6 +78,15 @@ class Controller {
}
}
+ showAddStowaway() {
+ this.$scope.addStowaway.show();
+ console.log(this.$state.getCurrentPath());
+ }
+
+ showRemoveStowaway() {
+ this.$scope.removeStowaway.show();
+ }
+
get ticket() {
return this._ticket;
}
@@ -67,13 +96,31 @@ class Controller {
if (!value) return;
- this._quicklinks = {
+ let links = {
btnOne: {
icon: 'person',
state: `client.card.summary({id: ${value.clientFk}})`,
tooltip: 'Client card'
- }
- };
+ }};
+ if (value.stowaway) {
+ links.btnTwo = {
+ icon: 'icon-polizon',
+ state: `ticket.card.summary({id: ${value.stowaway.shipFk}})`,
+ tooltip: 'Ship'
+ };
+ }
+ console.log(value.ship);
+
+ if (value.ship.length == 1) {
+ links.btnThree = {
+ icon: 'icon-polizon',
+ state: `ticket.card.summary({id: ${value.ship[0].id}})`,
+ tooltip: 'Stowaway'
+ };
+ } else if (value.ship.length > 1)
+ this.shipStowaways = value.ship;
+
+ this._quicklinks = links;
}
set quicklinks(value = {}) {
diff --git a/modules/ticket/back/methods/ticket/getPossibleStowaways.js b/modules/ticket/back/methods/ticket/getPossibleStowaways.js
new file mode 100644
index 000000000..045e0595c
--- /dev/null
+++ b/modules/ticket/back/methods/ticket/getPossibleStowaways.js
@@ -0,0 +1,57 @@
+module.exports = Self => {
+ Self.remoteMethod('getPossibleStowaways', {
+ description: 'Returns mana of a salesperson of a ticket',
+ accessType: 'READ',
+ accepts: [{
+ arg: 'id',
+ type: 'number',
+ required: true,
+ description: 'ticket id',
+ http: {source: 'path'}
+ }],
+ returns: {
+ root: true
+ },
+ http: {
+ path: `/:id/getPossibleStowaways`,
+ verb: 'GET'
+ }
+ });
+
+ Self.getPossibleStowaways = async ticketFk => {
+ let ship = await Self.app.models.Ticket.findById(ticketFk);
+ let lowestDate = new Date(ship.shipped.getTime());
+ lowestDate.setHours(0, 0, -1, 0);
+
+ let highestDate = new Date(ship.shipped.getTime());
+ highestDate.setHours(23, 59, 59);
+
+
+ let possibleStowaways = await Self.app.models.Ticket.find({
+ where: {
+ clientFk: ship.clientFk,
+ addressFk: ship.addressFk,
+ agencyModeFk: ship.agencyModeFk,
+ warehouse: {neq: ship.warehouseFk},
+ shipped: {
+ between: [lowestDate.toJSON(), highestDate.toJSON()]
+ }
+ },
+ include: [
+ {relation: 'agencyMode'},
+ {relation: 'warehouse'},
+ {relation: 'state',
+ scope: {
+ fields: ['stateFk'],
+ include: {
+ relation: 'state',
+ fields: ['id', 'name'],
+ }
+ },
+ },
+ ]
+ });
+
+ return possibleStowaways;
+ };
+};
diff --git a/modules/ticket/back/model-config.json b/modules/ticket/back/model-config.json
index e4921393d..22c750a4f 100644
--- a/modules/ticket/back/model-config.json
+++ b/modules/ticket/back/model-config.json
@@ -32,6 +32,9 @@
"State":{
"dataSource": "vn"
},
+ "Stowaway": {
+ "dataSource": "vn"
+ },
"Ticket": {
"dataSource": "vn"
},
diff --git a/modules/ticket/back/models/ticket.js b/modules/ticket/back/models/ticket.js
index 1426bad80..52144ca4c 100644
--- a/modules/ticket/back/models/ticket.js
+++ b/modules/ticket/back/models/ticket.js
@@ -16,4 +16,5 @@ module.exports = Self => {
require('../methods/ticket/getShipped')(Self);
require('../methods/ticket/getLanded')(Self);
require('../methods/ticket/filter')(Self);
+ require('../methods/ticket/getPossibleStowaways')(Self);
};