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() {
|
2019-07-26 09:48:01 +00:00
|
|
|
this.basicData.registerChild(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
get ticket() {
|
|
|
|
return this._ticket;
|
2018-07-11 07:11:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set ticket(value) {
|
|
|
|
this._ticket = value;
|
|
|
|
|
|
|
|
if (!value || !value.id) return;
|
|
|
|
|
2020-03-06 07:38:03 +00:00
|
|
|
this.clientAddressesList(value.clientFk);
|
2018-07-11 07:11:45 +00:00
|
|
|
}
|
|
|
|
|
2019-07-26 09:48:01 +00:00
|
|
|
get clientId() {
|
2019-10-04 07:28:09 +00:00
|
|
|
return this.ticket && this.ticket.clientFk;
|
2018-07-11 07:11:45 +00:00
|
|
|
}
|
|
|
|
|
2019-07-26 09:48:01 +00:00
|
|
|
set clientId(value) {
|
2018-07-02 11:14:14 +00:00
|
|
|
this.ticket.clientFk = value;
|
|
|
|
this.ticket.addressFk = null;
|
2018-07-11 07:11:45 +00:00
|
|
|
|
2020-03-06 07:50:55 +00:00
|
|
|
if (!value) return;
|
|
|
|
|
2020-03-06 07:38:03 +00:00
|
|
|
this.getClientDefaultAddress(value);
|
|
|
|
this.clientAddressesList(value);
|
2018-07-02 11:14:14 +00:00
|
|
|
}
|
|
|
|
|
2019-10-04 07:28:09 +00:00
|
|
|
get addressId() {
|
|
|
|
return this.ticket && this.ticket.addressFk;
|
|
|
|
}
|
|
|
|
|
|
|
|
set addressId(value) {
|
|
|
|
if (value != this.ticket.addressFk) {
|
|
|
|
this.ticket.addressFk = value;
|
|
|
|
this.getShipped({
|
|
|
|
landed: this.ticket.landed,
|
|
|
|
addressFk: value,
|
2019-11-18 11:32:50 +00:00
|
|
|
agencyModeFk: this.ticket.agencyModeFk,
|
|
|
|
warehouseFk: this.ticket.warehouseFk
|
2019-10-04 07:28:09 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-09-02 12:36:54 +00:00
|
|
|
|
2019-10-04 07:28:09 +00:00
|
|
|
get warehouseId() {
|
|
|
|
return this.ticket && this.ticket.warehouseFk;
|
2018-08-16 11:12:18 +00:00
|
|
|
}
|
|
|
|
|
2019-09-04 06:04:31 +00:00
|
|
|
set warehouseId(value) {
|
|
|
|
if (value != this.ticket.warehouseFk) {
|
|
|
|
this.ticket.warehouseFk = value;
|
|
|
|
this.getShipped({
|
|
|
|
landed: this.ticket.landed,
|
|
|
|
addressFk: this.ticket.addressFk,
|
|
|
|
agencyModeFk: this.ticket.agencyModeFk,
|
|
|
|
warehouseFk: value
|
|
|
|
});
|
2019-09-02 12:36:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 11:12:18 +00:00
|
|
|
get shipped() {
|
2019-10-04 07:28:09 +00:00
|
|
|
return this.ticket && this.ticket.shipped;
|
2018-08-16 11:12:18 +00:00
|
|
|
}
|
|
|
|
|
2019-09-02 12:36:54 +00:00
|
|
|
set shipped(value) {
|
|
|
|
this.ticket.shipped = value;
|
2019-09-04 06:04:31 +00:00
|
|
|
this.getLanded({
|
|
|
|
shipped: value,
|
|
|
|
addressFk: this.ticket.addressFk,
|
2019-11-18 11:32:50 +00:00
|
|
|
agencyModeFk: this.ticket.agencyModeFk,
|
|
|
|
warehouseFk: this.ticket.warehouseFk
|
2019-09-04 06:04:31 +00:00
|
|
|
});
|
2019-09-02 12:36:54 +00:00
|
|
|
}
|
|
|
|
|
2019-07-26 09:48:01 +00:00
|
|
|
get landed() {
|
2019-10-04 07:28:09 +00:00
|
|
|
return this.ticket && this.ticket.landed;
|
2019-07-26 09:48:01 +00:00
|
|
|
}
|
|
|
|
|
2018-07-24 10:14:35 +00:00
|
|
|
set landed(value) {
|
|
|
|
this.ticket.landed = value;
|
2019-09-04 06:04:31 +00:00
|
|
|
this.getShipped({
|
|
|
|
landed: value,
|
|
|
|
addressFk: this.ticket.addressFk,
|
2019-11-18 11:32:50 +00:00
|
|
|
agencyModeFk: this.ticket.agencyModeFk,
|
|
|
|
warehouseFk: this.ticket.warehouseFk
|
2019-09-04 06:04:31 +00:00
|
|
|
});
|
2018-07-24 10:14:35 +00:00
|
|
|
}
|
|
|
|
|
2019-07-26 09:48:01 +00:00
|
|
|
get agencyModeId() {
|
2019-10-04 07:28:09 +00:00
|
|
|
return this.ticket && this.ticket.agencyModeFk;
|
2019-07-26 09:48:01 +00:00
|
|
|
}
|
|
|
|
|
2019-09-04 06:04:31 +00:00
|
|
|
set agencyModeId(value) {
|
|
|
|
if (value != this.ticket.agencyModeFk) {
|
|
|
|
this.ticket.agencyModeFk = value;
|
2019-10-04 07:28:09 +00:00
|
|
|
this.getLanded({
|
|
|
|
shipped: this.ticket.shipped,
|
2019-09-04 06:04:31 +00:00
|
|
|
addressFk: this.ticket.addressFk,
|
2019-11-18 11:32:50 +00:00
|
|
|
agencyModeFk: value,
|
|
|
|
warehouseFk: this.ticket.warehouseFk
|
2019-09-04 06:04:31 +00:00
|
|
|
});
|
2019-08-20 12:18:32 +00:00
|
|
|
}
|
2019-07-26 09:48:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get zoneId() {
|
2019-10-04 07:28:09 +00:00
|
|
|
return this.ticket && this.ticket.zoneFk;
|
2018-07-24 10:14:35 +00:00
|
|
|
}
|
|
|
|
|
2019-09-04 06:04:31 +00:00
|
|
|
set zoneId(value) {
|
|
|
|
if (value != this.ticket.zoneFk) {
|
|
|
|
this.ticket.zoneFk = value;
|
|
|
|
this.onChangeZone(value);
|
2019-08-20 12:18:32 +00:00
|
|
|
}
|
2019-07-26 09:48:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Autocompletes address on client change
|
|
|
|
*/
|
2020-03-06 07:38:03 +00:00
|
|
|
clientAddressesList(value) {
|
2019-07-26 09:48:01 +00:00
|
|
|
let filter = {
|
|
|
|
include: [
|
|
|
|
{
|
|
|
|
relation: 'province',
|
|
|
|
scope: {
|
|
|
|
fields: ['name']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
relation: 'agencyMode',
|
|
|
|
scope: {
|
|
|
|
fields: ['name']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
filter = encodeURIComponent(JSON.stringify(filter));
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
let query = `Clients/${value}/addresses?filter=${filter}`;
|
2019-07-26 09:48:01 +00:00
|
|
|
this.$http.get(query).then(res => {
|
|
|
|
if (res.data)
|
|
|
|
this.addresses = res.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-03-06 07:38:03 +00:00
|
|
|
getClientDefaultAddress(value) {
|
|
|
|
let query = `Clients/${value}`;
|
|
|
|
this.$http.get(query).then(res => {
|
|
|
|
if (res.data)
|
|
|
|
this.ticket.addressFk = res.data.defaultAddressFk;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-26 09:48:01 +00:00
|
|
|
/*
|
|
|
|
* Gets an agency from an specified zone
|
|
|
|
*/
|
|
|
|
onChangeZone(zoneId) {
|
2019-08-20 12:18:32 +00:00
|
|
|
this.ticket.agencyModeFk = null;
|
2019-10-24 22:53:53 +00:00
|
|
|
const query = `Zones/${zoneId}`;
|
2019-07-26 09:48:01 +00:00
|
|
|
this.$http.get(query).then(res => {
|
2019-11-12 07:51:50 +00:00
|
|
|
this.ticket.agencyModeFk = res.data.agencyModeFk;
|
2019-07-26 09:48:01 +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
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
let query = `tickets/${this.ticket.id}/priceDifference`;
|
2019-07-26 09:48:01 +00:00
|
|
|
let params = {
|
2019-02-26 11:51:01 +00:00
|
|
|
landed: this.ticket.landed,
|
2019-07-26 09:48:01 +00:00
|
|
|
addressId: this.ticket.addressFk,
|
|
|
|
agencyModeId: this.ticket.agencyModeFk,
|
|
|
|
zoneId: this.ticket.zoneFk,
|
|
|
|
warehouseId: this.ticket.warehouseFk
|
2018-05-16 06:13:39 +00:00
|
|
|
};
|
2018-05-25 15:25:35 +00:00
|
|
|
|
2019-07-26 09:48:01 +00:00
|
|
|
return this.$http.post(query, params).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 => {
|
2019-07-26 09:48:01 +00:00
|
|
|
this.vnApp.showError(
|
|
|
|
this.$translate.instant(err.data.error.message)
|
|
|
|
);
|
2018-05-16 06:13:39 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-09-02 12:36:54 +00:00
|
|
|
/*
|
|
|
|
* Returns a landing date
|
|
|
|
*/
|
|
|
|
getLanded(params) {
|
2019-09-04 06:04:31 +00:00
|
|
|
this.ticket.zoneFk = null;
|
2019-10-24 22:53:53 +00:00
|
|
|
const query = `Agencies/getLanded`;
|
2019-09-04 06:04:31 +00:00
|
|
|
this.$http.get(query, {params}).then(res => {
|
|
|
|
if (res.data) {
|
|
|
|
this.ticket.zoneFk = res.data.zoneFk;
|
2019-10-04 07:28:09 +00:00
|
|
|
this.ticket.landed = res.data.landed;
|
|
|
|
this.ticket.shipped = params.shipped;
|
2019-09-04 06:04:31 +00:00
|
|
|
} else {
|
|
|
|
return this.vnApp.showError(
|
|
|
|
this.$translate.instant(`No delivery zone available for this landing date`)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2019-09-02 12:36:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns a shipment date
|
|
|
|
*/
|
|
|
|
getShipped(params) {
|
2019-09-04 06:04:31 +00:00
|
|
|
this.ticket.zoneFk = null;
|
2019-10-24 22:53:53 +00:00
|
|
|
const query = `Agencies/getShipped`;
|
2019-09-04 06:04:31 +00:00
|
|
|
this.$http.get(query, {params}).then(res => {
|
|
|
|
if (res.data) {
|
|
|
|
this.ticket.zoneFk = res.data.zoneFk;
|
2019-10-04 07:28:09 +00:00
|
|
|
this.ticket.landed = params.landed;
|
|
|
|
this.ticket.shipped = res.data.shipped;
|
2019-09-04 06:04:31 +00:00
|
|
|
} else {
|
|
|
|
return this.vnApp.showError(
|
|
|
|
this.$translate.instant(`No delivery zone available for this landing date`)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2019-09-02 12:36:54 +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
|
2019-07-26 09:48:01 +00:00
|
|
|
|| !this.ticket.companyFk || !this.ticket.shipped || !this.ticket.landed
|
|
|
|
|| !this.ticket.zoneFk;
|
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-07-26 09:48:01 +00:00
|
|
|
basicData: '^vnTicketBasicData'
|
2018-04-18 07:47:05 +00:00
|
|
|
}
|
2018-04-04 11:56:16 +00:00
|
|
|
});
|