getAvailable aislado

This commit is contained in:
Javi Gallego 2019-02-18 13:31:57 +01:00
parent 58706b8694
commit a3e69d604a
4 changed files with 26 additions and 37 deletions

View File

@ -60,16 +60,6 @@ module.exports = Self => {
}; };
[item] = await Self.app.models.Item.find(filter); [item] = await Self.app.models.Item.find(filter);
// Visible Available
let query = `
CALL vn.getItemVisibleAvailable(?,curdate(),?,?)`;
let options = [item.id, item.itemType().warehouseFk, false];
let [res] = await Self.rawSql(query, options);
item.available = res[0].available;
item.visible = res[0].visible;
return item; return item;
}; };
}; };

View File

@ -4,7 +4,7 @@ module.exports = Self => {
accessType: '', accessType: '',
accepts: [ accepts: [
{ {
arg: 'itemFk', arg: 'id',
type: 'Number', type: 'Number',
required: true, required: true,
}, },
@ -18,21 +18,20 @@ module.exports = Self => {
root: true root: true
}, },
http: { http: {
path: `/getVisibleAvailable`, path: `/:id/getVisibleAvailable`,
verb: 'GET' verb: 'GET'
} }
}); });
Self.getVisibleAvailable = async(itemFk, warehouseFk) => { Self.getVisibleAvailable = async(itemFk, warehouseFk) => {
let item = {};
let query = ` let query = `
CALL vn.getItemVisibleAvailable(?,curdate(),?,?)`; CALL vn.getItemVisibleAvailable(?,curdate(),?,?)`;
let options = [itemFk, warehouseFk, false]; let options = [itemFk, warehouseFk, false];
[res] = await Self.rawSql(query, options); [res] = await Self.rawSql(query, options);
item.available = res[0].available; return {
item.visible = res[0].visible; available: res[0].available,
return item; visible: res[0].visible};
}; };
}; };

View File

@ -1,10 +1,3 @@
<vn-crud-model
vn-id="model"
url="item/api/Items/getVisibleAvailable"
filter="$ctrl.params"
data="$ctrl.item.available"
on-data-change="$ctrl.calculateTotals()">
</vn-crud-model>
<div class="vn-descriptor"> <div class="vn-descriptor">
<div class="header"> <div class="header">
<a translate-attr="{title: 'Return to module index'}" ui-sref="item.index"> <a translate-attr="{title: 'Return to module index'}" ui-sref="item.index">
@ -41,11 +34,11 @@
<vn-horizontal class="item-state"> <vn-horizontal class="item-state">
<vn-one> <vn-one>
<p translate>Visible</p> <p translate>Visible</p>
<p>{{$ctrl.item.visible}}</p> <p>{{$ctrl.visible | dashIfEmpty}}</p>
</vn-one> </vn-one>
<vn-one> <vn-one>
<p translate>Available</p> <p translate>Available</p>
<p>{{$ctrl.item.available}}</p> <p>{{$ctrl.available | dashIfEmpty}}</p>
</vn-one> </vn-one>
</vn-horizontal> </vn-horizontal>
</div> </div>

View File

@ -1,5 +1,6 @@
import ngModule from '../module'; import ngModule from '../module';
import './style.scss'; import './style.scss';
import {runInThisContext} from 'vm';
class Controller { class Controller {
constructor($state, $scope, $http, vnApp, $translate) { constructor($state, $scope, $http, vnApp, $translate) {
@ -34,23 +35,29 @@ class Controller {
set item(value) { set item(value) {
this._item = value; this._item = value;
this.available = null; this.updateStock();
this.visible = null;
if (!this.item) {
this.params = {
params: {
itemFk: this.item,
warehouseFk: this._warehouseFk
}
};
}
return this._item;
} }
get item() { get item() {
return this._item; return this._item;
} }
updateStock() {
this.available = null;
this.visible = null;
if (this._item && this._item.id) {
let options = {
params: {
warehouseFk: this._warehouseFk
}
};
this.$http.get(`/item/api/Items/${this._item.id}/getVisibleAvailable`, options).then(response => {
this.available = response.data.available;
this.visible = response.data.visible;
});
}
}
onMoreChange(callback) { onMoreChange(callback) {
callback.call(this); callback.call(this);
} }
@ -75,7 +82,7 @@ class Controller {
warehouseFk: this.warehouseFk warehouseFk: this.warehouseFk
}).then(res => { }).then(res => {
this.vnApp.showSuccess(this.$translate.instant('Data saved!')); this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
this.card.reload(); this.updateStock();
}); });
} }
} }