2018-07-09 11:54:43 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
|
|
|
|
class Controller {
|
2018-08-09 13:40:37 +00:00
|
|
|
constructor($http, vnApp, $translate, $state) {
|
2018-07-09 11:54:43 +00:00
|
|
|
this.$http = $http;
|
|
|
|
this.translate = $translate;
|
|
|
|
this.vnApp = vnApp;
|
2018-07-24 11:48:31 +00:00
|
|
|
this.order = {};
|
|
|
|
this.$state = $state;
|
2018-07-09 11:54:43 +00:00
|
|
|
}
|
|
|
|
|
2018-07-24 11:48:31 +00:00
|
|
|
set order(value) {
|
2018-11-22 12:56:35 +00:00
|
|
|
if (value)
|
2018-07-24 11:48:31 +00:00
|
|
|
this._order = value;
|
2018-07-09 11:54:43 +00:00
|
|
|
}
|
|
|
|
|
2018-07-24 11:48:31 +00:00
|
|
|
get order() {
|
|
|
|
return this._order;
|
2018-07-09 11:54:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set clientFk(value) {
|
2018-07-24 11:48:31 +00:00
|
|
|
this.order.clientFk = value;
|
2018-11-22 12:56:35 +00:00
|
|
|
|
|
|
|
if (value) {
|
|
|
|
let filter = {where: {clientFk: value, isDefaultAddress: true}};
|
|
|
|
filter = encodeURIComponent(JSON.stringify(filter));
|
|
|
|
let query = `/api/Addresses?filter=${filter}`;
|
|
|
|
this.$http.get(query).then(res => {
|
|
|
|
this.addressFk = res.data[0].id;
|
|
|
|
});
|
|
|
|
} else
|
|
|
|
this.addressFk = null;
|
2018-07-09 11:54:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get clientFk() {
|
2018-07-24 11:48:31 +00:00
|
|
|
return this.order.clientFk;
|
2018-07-09 11:54:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set addressFk(value) {
|
2018-07-24 11:48:31 +00:00
|
|
|
this.order.addressFk = value;
|
2018-07-17 11:04:24 +00:00
|
|
|
this.getAvailableAgencies();
|
2018-07-09 11:54:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get addressFk() {
|
2018-07-24 11:48:31 +00:00
|
|
|
return this.order.addressFk;
|
2018-07-09 11:54:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set landed(value) {
|
2018-07-24 11:48:31 +00:00
|
|
|
this.order.landed = value;
|
2018-07-17 11:04:24 +00:00
|
|
|
this.getAvailableAgencies();
|
2018-07-09 11:54:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get landed() {
|
2018-07-24 11:48:31 +00:00
|
|
|
return this.order.landed;
|
2018-07-09 11:54:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get warehouseFk() {
|
2018-07-24 11:48:31 +00:00
|
|
|
return this.order.warehouseFk;
|
2018-07-09 11:54:43 +00:00
|
|
|
}
|
|
|
|
|
2018-07-17 11:04:24 +00:00
|
|
|
getAvailableAgencies() {
|
2018-07-24 11:48:31 +00:00
|
|
|
this.order.agencyModeFk = null;
|
|
|
|
if (this.order.landed && this.order.addressFk) {
|
|
|
|
let filter = {addressFk: this.order.addressFk, landed: this.order.landed};
|
2018-07-09 11:54:43 +00:00
|
|
|
filter = encodeURIComponent(JSON.stringify(filter));
|
|
|
|
let query = `/api/Agencies/landsThatDay?filter=${filter}`;
|
|
|
|
this.$http.get(query).then(res => {
|
2018-07-17 11:04:24 +00:00
|
|
|
this._availableAgencies = res.data[0];
|
2018-07-09 11:54:43 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onSubmit() {
|
|
|
|
this.createOrder();
|
|
|
|
}
|
|
|
|
|
|
|
|
createOrder() {
|
|
|
|
let params = {
|
2018-07-24 11:48:31 +00:00
|
|
|
landed: this.order.landed,
|
|
|
|
addressFk: this.order.addressFk,
|
|
|
|
agencyModeFk: this.order.agencyModeFk
|
2018-07-09 11:54:43 +00:00
|
|
|
};
|
|
|
|
this.$http.post(`order/api/Orders/new`, params).then(res => {
|
|
|
|
this.vnApp.showSuccess(this.translate.instant('Data saved!'));
|
2018-11-22 12:56:35 +00:00
|
|
|
this.$state.go('order.card.catalog', {id: res.data});
|
2018-07-09 11:54:43 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-09 13:40:37 +00:00
|
|
|
Controller.$inject = ['$http', 'vnApp', '$translate', '$state'];
|
2018-07-09 11:54:43 +00:00
|
|
|
|
2018-07-24 11:48:31 +00:00
|
|
|
ngModule.component('vnOrderCreateCard', {
|
2018-07-09 11:54:43 +00:00
|
|
|
template: require('./card.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
2018-07-24 11:48:31 +00:00
|
|
|
order: '<?'
|
2018-07-09 11:54:43 +00:00
|
|
|
}
|
|
|
|
});
|