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

107 lines
2.7 KiB
JavaScript

import ngModule from '../module';
import './style.scss';
class Controller {
constructor($state, $scope, $http, vnApp, $translate, vnConfig) {
this.$state = $state;
this.$scope = $scope;
this.$http = $http;
this.vnApp = vnApp;
this.$translate = $translate;
this.vnConfig = vnConfig;
this.moreOptions = [
{callback: this.showRegularizeDialog, name: 'Regularize stock'}
];
}
set quantity(value) {
this._quantity = parseInt(value);
}
get quantity() {
return this._quantity;
}
set warehouseFk(value) {
if (value)
this._warehouseFk = value;
}
get warehouseFk() {
if (!this._warehouseFk)
this._warehouseFk = this.vnConfig.warehouseFk;
return this._warehouseFk;
}
set item(value) {
this._item = value;
if (value && value.itemType && value.itemType.warehouseFk)
this.updateStock(value.itemType.warehouseFk);
}
get item() {
return this._item;
}
updateStock(warehouseFk) {
this.available = null;
this.visible = null;
if (this._item && this._item.id) {
let options = {
params: {
warehouseFk: warehouseFk
}
};
this.$http.get(`Items/${this._item.id}/getVisibleAvailable`, options).then(response => {
this.available = response.data.available;
this.visible = response.data.visible;
});
}
}
onMoreChange(callback) {
callback.call(this);
}
showRegularizeDialog() {
this.$scope.regularize.show();
}
set quicklinks(value = {}) {
this._quicklinks = Object.assign(value, this._quicklinks);
}
get quicklinks() {
return this._quicklinks;
}
saveRegularize(response) {
if (response == 'accept') {
this.$http.post(`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);
});
}
}
clearRegularizeDialog() {
this.warehouseFk = null;
this.quantity = null;
}
}
Controller.$inject = ['$state', '$scope', '$http', 'vnApp', '$translate', 'vnConfig'];
ngModule.component('vnItemDescriptor', {
template: require('./index.html'),
controller: Controller,
bindings: {
item: '<',
quicklinks: '<'
}
});