2018-04-04 11:56:16 +00:00
|
|
|
import ngModule from '../../module';
|
2018-07-10 12:55:13 +00:00
|
|
|
import {toJsonDate} from 'core/src/lib/date';
|
2018-04-04 11:56:16 +00:00
|
|
|
|
|
|
|
class Controller {
|
2018-05-22 06:14:16 +00:00
|
|
|
constructor($scope, $http, $translate, vnApp) {
|
2018-04-04 11:56:16 +00:00
|
|
|
this.$scope = $scope;
|
2018-05-16 06:13:39 +00:00
|
|
|
this.$http = $http;
|
|
|
|
this.$translate = $translate;
|
|
|
|
this.vnApp = vnApp;
|
|
|
|
}
|
|
|
|
|
2018-07-02 11:14:14 +00:00
|
|
|
set clientFk(value) {
|
|
|
|
this.ticket.clientFk = value;
|
|
|
|
this.ticket.addressFk = null;
|
2018-05-16 06:13:39 +00:00
|
|
|
}
|
|
|
|
|
2018-07-02 11:14:14 +00:00
|
|
|
get clientFk() {
|
2018-05-22 06:14:16 +00:00
|
|
|
if (this.ticket)
|
2018-07-02 11:14:14 +00:00
|
|
|
return this.ticket.clientFk;
|
|
|
|
}
|
|
|
|
|
|
|
|
$onInit() {
|
|
|
|
this.data.registerChild(this);
|
2018-05-17 06:44:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getAddresses() {
|
2018-07-02 11:14:14 +00:00
|
|
|
if (this.ticket && this.ticket.addressFk)
|
2018-05-17 06:44:34 +00:00
|
|
|
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 = {
|
2018-07-10 12:55:13 +00:00
|
|
|
landed: toJsonDate(this.ticket.landed),
|
2018-05-22 06:14:16 +00:00
|
|
|
addressFk: this.ticket.addressFk,
|
2018-05-30 08:55:54 +00:00
|
|
|
agencyModeFk: this.ticket.agencyModeFk,
|
|
|
|
warehouseFk: this.ticket.warehouseFk
|
2018-05-16 06:13:39 +00:00
|
|
|
};
|
2018-05-25 15:25:35 +00:00
|
|
|
|
2018-05-16 06:13:39 +00:00
|
|
|
return this.$http.post(query, data).then(res => {
|
2018-05-22 06:14:16 +00:00
|
|
|
if (res.data)
|
2018-05-16 06:13:39 +00:00
|
|
|
this.ticket.sale = res.data;
|
|
|
|
|
2018-05-22 06:14:16 +00:00
|
|
|
return true;
|
2018-05-16 06:13:39 +00:00
|
|
|
}, res => {
|
|
|
|
if (res.data.error.message === 'NO_AGENCY_AVAILABLE')
|
2018-06-19 06:12:36 +00:00
|
|
|
this.vnApp.showSuccess(
|
2018-05-16 06:13:39 +00:00
|
|
|
this.$translate.instant(`There's no available agency for this landing date`)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
isFormInvalid() {
|
2018-05-22 06:14:16 +00:00
|
|
|
return !this.ticket.clientFk || !this.ticket.addressFk || !this.ticket.agencyModeFk
|
2018-05-16 06:13:39 +00:00
|
|
|
|| !this.ticket.companyFk || !this.ticket.shipped || !this.ticket.landed;
|
2018-04-04 11:56:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-22 06:14:16 +00:00
|
|
|
Controller.$inject = ['$scope', '$http', '$translate', 'vnApp'];
|
2018-04-04 11:56:16 +00:00
|
|
|
|
|
|
|
ngModule.component('vnTicketDataStepOne', {
|
2018-05-25 08:03:45 +00:00
|
|
|
template: require('./index.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
|
|
|
});
|