salix/modules/item/front/descriptor/index.js

107 lines
2.7 KiB
JavaScript
Raw Normal View History

import ngModule from '../module';
import './style.scss';
class Controller {
2019-10-09 22:47:29 +00:00
constructor($state, $scope, $http, vnApp, $translate, vnConfig) {
this.$state = $state;
2018-11-12 12:12:25 +00:00
this.$scope = $scope;
this.$http = $http;
this.vnApp = vnApp;
this.$translate = $translate;
2019-10-09 22:47:29 +00:00
this.vnConfig = vnConfig;
2018-11-12 12:12:25 +00:00
this.moreOptions = [
2019-02-13 08:49:41 +00:00
{callback: this.showRegularizeDialog, name: 'Regularize stock'}
2018-11-12 12:12:25 +00:00
];
}
set quantity(value) {
this._quantity = parseInt(value);
}
get quantity() {
return this._quantity;
}
set warehouseFk(value) {
2019-02-13 08:49:41 +00:00
if (value)
this._warehouseFk = value;
2018-11-12 12:12:25 +00:00
}
get warehouseFk() {
if (!this._warehouseFk)
2019-10-09 22:47:29 +00:00
this._warehouseFk = this.vnConfig.warehouseFk;
2018-11-12 12:12:25 +00:00
return this._warehouseFk;
}
2019-02-15 15:04:24 +00:00
set item(value) {
2019-02-18 06:57:15 +00:00
this._item = value;
if (value && value.itemType && value.itemType.warehouseFk)
this.updateStock(value.itemType.warehouseFk);
2019-02-18 12:31:57 +00:00
}
get item() {
return this._item;
}
updateStock(warehouseFk) {
2019-02-18 06:57:15 +00:00
this.available = null;
this.visible = null;
2019-02-18 12:31:57 +00:00
if (this._item && this._item.id) {
let options = {
2019-02-18 06:57:15 +00:00
params: {
warehouseFk: warehouseFk
2019-02-18 06:57:15 +00:00
}
};
2019-02-18 12:31:57 +00:00
this.$http.get(`/item/api/Items/${this._item.id}/getVisibleAvailable`, options).then(response => {
this.available = response.data.available;
this.visible = response.data.visible;
});
2019-02-18 06:57:15 +00:00
}
2019-02-15 15:04:24 +00:00
}
2018-11-12 12:12:25 +00:00
onMoreChange(callback) {
callback.call(this);
}
showRegularizeDialog() {
this.$scope.regularize.show();
}
set quicklinks(value = {}) {
2018-08-02 08:06:11 +00:00
this._quicklinks = Object.assign(value, this._quicklinks);
}
get quicklinks() {
return this._quicklinks;
}
2018-11-12 12:12:25 +00:00
saveRegularize(response) {
if (response == 'ACCEPT') {
this.$http.post(`/item/api/Items/regularize`, {
itemFk: this.item.id,
quantity: this.quantity,
warehouseFk: this.warehouseFk
}).then(res => {
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
this.updateStock(this.item.itemType.warehouseFk);
2018-11-12 12:12:25 +00:00
});
}
}
clearRegularizeDialog() {
this.warehouseFk = null;
this.quantity = null;
}
}
2019-10-09 22:47:29 +00:00
Controller.$inject = ['$state', '$scope', '$http', 'vnApp', '$translate', 'vnConfig'];
ngModule.component('vnItemDescriptor', {
template: require('./index.html'),
controller: Controller,
bindings: {
item: '<',
quicklinks: '<'
}
});