salix/modules/item/front/item-shelving/index.js

107 lines
2.8 KiB
JavaScript
Raw Normal View History

2022-10-05 13:13:48 +00:00
import ngModule from '../module';
import Section from 'salix/components/section';
export default class Controller extends Section {
constructor($element, $) {
super($element, $);
this.smartTableOptions = {
activeButtons: {
search: true
},
columns: [
{
2022-10-06 07:47:53 +00:00
field: 'parking',
2022-10-05 13:13:48 +00:00
autocomplete: {
2022-10-06 07:47:53 +00:00
url: 'Parkings',
showField: 'code',
valueField: 'code'
2022-10-05 13:13:48 +00:00
}
},
{
2022-10-06 07:47:53 +00:00
field: 'shelving',
2022-10-05 13:13:48 +00:00
autocomplete: {
2022-10-06 07:47:53 +00:00
url: 'Shelvings',
showField: 'code',
valueField: 'code'
2022-10-05 13:13:48 +00:00
}
},
{
2022-10-06 07:47:53 +00:00
field: 'created',
2022-10-05 13:13:48 +00:00
searchable: false
},
{
2022-10-06 07:47:53 +00:00
field: 'itemFk',
2022-10-05 13:13:48 +00:00
searchable: false
},
{
2022-10-06 07:47:53 +00:00
field: 'longName',
2022-10-05 13:13:48 +00:00
searchable: false
}
]
};
this.getBalanceDueTotal();
}
get checked() {
2022-10-06 07:47:53 +00:00
const itemShelvings = this.$.model.data || [];
2022-10-05 13:13:48 +00:00
const checkedLines = [];
2022-10-06 07:47:53 +00:00
for (let itemShelving of itemShelvings) {
if (itemShelving.checked)
checkedLines.push(itemShelving);
2022-10-05 13:13:48 +00:00
}
return checkedLines;
}
2022-10-06 07:47:53 +00:00
get label() {
const itemShelvings = this.$.model.data || [];
for (let itemShelving of itemShelvings)
itemShelving.label = itemShelving.stock / itemShelving.packing;
return true;
}
2022-10-05 13:13:48 +00:00
getBalanceDueTotal() {
this.$http.get('Defaulters/filter')
.then(res => {
if (!res.data) return 0;
this.balanceDueTotal = res.data.reduce(
(accumulator, currentValue) => {
return accumulator + (currentValue['amount'] || 0);
}, 0);
});
}
2022-10-06 07:47:53 +00:00
async onRemove() {
2022-10-05 13:13:48 +00:00
const params = [];
2022-10-06 07:47:53 +00:00
for (let itemShelving of this.checked)
params.push(itemShelving.itemShelvingFk);
for (let id of params) {
await this.$http.delete(`ItemShelvings/${id}`)
.then(() => {
this.vnApp.showSuccess(this.$t('ItemShelving removed'));
this.$state.reload();
});
2022-10-05 13:13:48 +00:00
}
}
exprBuilder(param, value) {
switch (param) {
2022-10-06 07:47:53 +00:00
case 'parking':
case 'shelving':
case 'label':
case 'packing':
return {[param]: value};
2022-10-05 13:13:48 +00:00
}
}
}
ngModule.vnComponent('vnItemShelving', {
template: require('./index.html'),
controller: Controller
});