2018-04-04 11:56:16 +00:00
|
|
|
import ngModule from '../../module';
|
|
|
|
|
|
|
|
class Controller {
|
2018-05-17 06:44:34 +00:00
|
|
|
constructor($scope, $http, $element, $translate, vnApp) {
|
2018-04-04 11:56:16 +00:00
|
|
|
this.$scope = $scope;
|
2018-05-16 06:13:39 +00:00
|
|
|
this.$http = $http;
|
2018-05-17 06:44:34 +00:00
|
|
|
this.$element = $element;
|
2018-05-16 06:13:39 +00:00
|
|
|
this.$translate = $translate;
|
|
|
|
this.vnApp = vnApp;
|
|
|
|
}
|
|
|
|
|
|
|
|
$onInit() {
|
|
|
|
this.data.registerChild(this);
|
|
|
|
}
|
|
|
|
|
2018-05-17 06:44:34 +00:00
|
|
|
onChange() {
|
|
|
|
if(this.ticket)
|
|
|
|
this.ticket.addressFk = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
getAddresses() {
|
|
|
|
if (this.ticket)
|
|
|
|
return `/api/Clients/${this.ticket.clientFk}/addresses`;
|
|
|
|
}
|
|
|
|
|
2018-05-16 06:13:39 +00:00
|
|
|
async onStepChange(state) {
|
|
|
|
if (this.isFormInvalid())
|
|
|
|
return this.vnApp.showError(
|
|
|
|
this.$translate.instant('Some fields are invalid')
|
|
|
|
);
|
|
|
|
|
|
|
|
let query = `/ticket/api/sales/${this.ticket.id}/priceDifference`;
|
|
|
|
let data = {
|
|
|
|
landed: this.ticket.landed,
|
|
|
|
addressFk: this.ticket.addressFk,
|
|
|
|
agencyModeFk: this.ticket.agencyModeFk
|
|
|
|
};
|
|
|
|
|
|
|
|
return this.$http.post(query, data).then(res => {
|
|
|
|
if (res.data);
|
|
|
|
this.ticket.sale = res.data;
|
|
|
|
|
|
|
|
return true
|
|
|
|
}, res => {
|
|
|
|
if (res.data.error.message === 'NO_AGENCY_AVAILABLE')
|
|
|
|
this.vnApp.showError(
|
|
|
|
this.$translate.instant(`There's no available agency for this landing date`)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
isFormInvalid() {
|
|
|
|
return !this.ticket.clientFk || !this.ticket.addressFk || !this.ticket.agencyModeFk
|
|
|
|
|| !this.ticket.companyFk || !this.ticket.shipped || !this.ticket.landed;
|
2018-04-04 11:56:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-17 06:44:34 +00:00
|
|
|
Controller.$inject = ['$scope', '$http', '$element', '$translate', 'vnApp'];
|
2018-04-04 11:56:16 +00:00
|
|
|
|
|
|
|
ngModule.component('vnTicketDataStepOne', {
|
|
|
|
template: require('./step-one.html'),
|
2018-04-18 07:47:05 +00:00
|
|
|
controller: Controller,
|
2018-04-04 11:56:16 +00:00
|
|
|
bindings: {
|
|
|
|
ticket: '<'
|
2018-05-16 06:13:39 +00:00
|
|
|
},
|
|
|
|
require: {
|
|
|
|
data: '^vnTicketData'
|
2018-04-18 07:47:05 +00:00
|
|
|
}
|
2018-04-04 11:56:16 +00:00
|
|
|
});
|