2018-04-04 11:56:16 +00:00
|
|
|
import ngModule from '../../module';
|
2019-02-05 10:25:47 +00:00
|
|
|
import './style.scss';
|
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-11 07:11:45 +00:00
|
|
|
$onInit() {
|
|
|
|
this.data.registerChild(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
set ticket(value) {
|
|
|
|
this._ticket = value;
|
|
|
|
|
|
|
|
if (!value || !value.id) return;
|
|
|
|
|
2018-07-24 10:14:35 +00:00
|
|
|
this.onChangeAddress(value.clientFk);
|
2018-07-11 07:11:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get ticket() {
|
|
|
|
return this._ticket;
|
|
|
|
}
|
|
|
|
|
2018-07-02 11:14:14 +00:00
|
|
|
set clientFk(value) {
|
|
|
|
this.ticket.clientFk = value;
|
|
|
|
this.ticket.addressFk = null;
|
2018-07-11 07:11:45 +00:00
|
|
|
|
2018-07-24 10:14:35 +00:00
|
|
|
this.onChangeAddress(value);
|
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;
|
2019-01-24 14:41:48 +00:00
|
|
|
|
|
|
|
return null;
|
2018-07-02 11:14:14 +00:00
|
|
|
}
|
|
|
|
|
2018-08-16 11:12:18 +00:00
|
|
|
set shipped(value) {
|
|
|
|
this.ticket.shipped = value;
|
|
|
|
this.onChangeShipped(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
get shipped() {
|
|
|
|
if (this.ticket)
|
|
|
|
return this.ticket.shipped;
|
2019-01-24 14:41:48 +00:00
|
|
|
|
|
|
|
return null;
|
2018-08-16 11:12:18 +00:00
|
|
|
}
|
|
|
|
|
2018-07-24 10:14:35 +00:00
|
|
|
set landed(value) {
|
|
|
|
this.ticket.landed = value;
|
|
|
|
this.onChangeLanded(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
get landed() {
|
|
|
|
if (this.ticket)
|
|
|
|
return this.ticket.landed;
|
2019-01-24 14:41:48 +00:00
|
|
|
|
|
|
|
return null;
|
2018-07-24 10:14:35 +00:00
|
|
|
}
|
|
|
|
|
2018-08-16 11:12:18 +00:00
|
|
|
onChangeShipped(value) {
|
2019-05-30 06:41:08 +00:00
|
|
|
let params = {
|
2019-02-26 11:51:01 +00:00
|
|
|
shipped: value,
|
2018-08-16 11:12:18 +00:00
|
|
|
addressFk: this.ticket.addressFk,
|
|
|
|
agencyModeFk: this.ticket.agencyModeFk,
|
|
|
|
warehouseFk: this.ticket.warehouseFk
|
|
|
|
};
|
|
|
|
|
2019-05-30 06:41:08 +00:00
|
|
|
let query = `/api/Agencies/getLanded`;
|
|
|
|
this.$http.get(query, {params}).then(res => {
|
2018-08-16 11:12:18 +00:00
|
|
|
if (res.data && res.data.landed)
|
|
|
|
this.ticket.landed = res.data.landed;
|
2019-03-26 11:02:11 +00:00
|
|
|
else {
|
|
|
|
return this.vnApp.showError(
|
|
|
|
this.$translate.instant(`There's no available agency for this shipping date`)
|
|
|
|
);
|
|
|
|
}
|
2018-08-16 11:12:18 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-07-24 10:14:35 +00:00
|
|
|
onChangeLanded(value) {
|
2019-05-30 06:41:08 +00:00
|
|
|
let params = {
|
2018-07-24 10:14:35 +00:00
|
|
|
landed: value,
|
|
|
|
addressFk: this.ticket.addressFk,
|
2019-03-14 09:43:14 +00:00
|
|
|
agencyModeFk: this.ticket.agencyModeFk,
|
|
|
|
warehouseFk: this.ticket.warehouseFk
|
2018-07-24 10:14:35 +00:00
|
|
|
};
|
|
|
|
|
2019-05-30 06:41:08 +00:00
|
|
|
let query = `/api/Agencies/getShipped`;
|
|
|
|
this.$http.get(query, {params}).then(res => {
|
|
|
|
if (res.data)
|
|
|
|
this.ticket.shipped = res.data;
|
2019-03-26 11:02:11 +00:00
|
|
|
else {
|
|
|
|
return this.vnApp.showError(
|
|
|
|
this.$translate.instant(`There's no available agency for this landing date`)
|
|
|
|
);
|
|
|
|
}
|
2018-07-24 10:14:35 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onChangeAddress(value) {
|
2018-07-11 07:11:45 +00:00
|
|
|
let filter = {
|
|
|
|
include: [
|
|
|
|
{
|
|
|
|
relation: 'province',
|
|
|
|
scope: {
|
|
|
|
fields: ['name']
|
|
|
|
}
|
2019-01-24 14:41:48 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
relation: 'agencyMode',
|
|
|
|
scope: {
|
|
|
|
fields: ['name']
|
|
|
|
}
|
2018-07-11 07:11:45 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
filter = encodeURIComponent(JSON.stringify(filter));
|
2018-05-17 06:44:34 +00:00
|
|
|
|
2018-07-11 07:11:45 +00:00
|
|
|
let query = `/api/Clients/${value}/addresses?filter=${filter}`;
|
|
|
|
this.$http.get(query).then(res => {
|
|
|
|
if (res.data)
|
|
|
|
this.addresses = res.data;
|
|
|
|
});
|
2018-05-17 06:44:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-01 12:49:12 +00:00
|
|
|
async onStepChange() {
|
2019-01-24 14:41:48 +00:00
|
|
|
if (this.isFormInvalid()) {
|
2018-05-16 06:13:39 +00:00
|
|
|
return this.vnApp.showError(
|
|
|
|
this.$translate.instant('Some fields are invalid')
|
|
|
|
);
|
2019-01-24 14:41:48 +00:00
|
|
|
}
|
2018-05-16 06:13:39 +00:00
|
|
|
|
|
|
|
let query = `/ticket/api/sales/${this.ticket.id}/priceDifference`;
|
|
|
|
let data = {
|
2019-02-26 11:51:01 +00:00
|
|
|
landed: 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;
|
2019-04-01 12:49:12 +00:00
|
|
|
}, err => {
|
|
|
|
if (err.data.error.message === 'NO_AGENCY_AVAILABLE') {
|
2018-08-06 12:25:11 +00:00
|
|
|
this.vnApp.showMessage(
|
2018-05-16 06:13:39 +00:00
|
|
|
this.$translate.instant(`There's no available agency for this landing date`)
|
|
|
|
);
|
2019-04-01 12:49:12 +00:00
|
|
|
} else {
|
|
|
|
this.vnApp.showMessage(
|
|
|
|
this.$translate.instant(err.data.error.message)
|
|
|
|
);
|
2019-01-24 14:41:48 +00:00
|
|
|
}
|
2018-05-16 06:13:39 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2019-04-16 13:00:21 +00:00
|
|
|
ngModule.component('vnTicketBasicDataStepOne', {
|
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: {
|
2019-04-16 13:00:21 +00:00
|
|
|
data: '^vnTicketBasicData'
|
2018-04-18 07:47:05 +00:00
|
|
|
}
|
2018-04-04 11:56:16 +00:00
|
|
|
});
|