feat: add total labels
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Vicent Llopis 2022-10-11 08:40:22 +02:00
parent 7b7e01f49e
commit 9c52508a88
9 changed files with 98 additions and 40 deletions

View File

@ -0,0 +1,47 @@
module.exports = Self => {
Self.remoteMethod('deleteItemShelvings', {
description: 'Deletes the selected orders',
accessType: 'WRITE',
accepts: [{
arg: 'itemShelvingIds',
type: ['number'],
required: true,
description: 'The itemShelving ids to delete'
}],
returns: {
type: ['object'],
root: true
},
http: {
path: `/deleteItemShelvings`,
verb: 'POST'
}
});
Self.deleteItemShelvings = async(itemShelvingIds, options) => {
const models = Self.app.models;
const myOptions = {};
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
const deletedItemShelvings = await models.ItemShelving.destroyAll({
id: {inq: itemShelvingIds}
}, myOptions);
if (tx) await tx.commit();
return deletedItemShelvings;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -0,0 +1,21 @@
const models = require('vn-loopback/server/server').models;
describe('ItemShelving deleteItemShelvings()', () => {
it('should return the deleted itemShelvings', async() => {
const tx = await models.Order.beginTransaction({});
try {
const options = {transaction: tx};
const itemShelvingIds = [1, 2];
const result = await models.ItemShelving.deleteItemShelvings(itemShelvingIds, options);
expect(result.count).toEqual(2);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -0,0 +1,3 @@
module.exports = Self => {
require('../methods/item-shelving/deleteItemShelvings')(Self);
};

View File

@ -2,7 +2,7 @@
vn-id="model"
url="ItemShelvingPlacementSupplyStocks"
link="{itemFk: $ctrl.$params.id}"
data="itemShelvingPlacementSupplyStocks"
data="$ctrl.itemShelvingPlacementSupplyStocks"
auto-load="true">
</vn-crud-model>
<vn-card>
@ -15,18 +15,18 @@
<div class="totalBox" style="text-align: center;">
<h6 translate>Total</h6>
<vn-label-value
label="Balance due"
value="{{$ctrl.balanceDueTotal | currency: 'EUR': 2}}">
label="Total labels"
value="{{$ctrl.labelTotal.toFixed(2)}}">
</vn-label-value>
</div>
</div>
<div class="vn-pa-md">
<vn-button
ng-show="$ctrl.checked.length > 0"
disabled="!$ctrl.checked.length"
ng-click="removeConfirm.show()"
icon="delete"
vn-tooltip="Remove selected lines"
vn-acl="replenisherBos"
icon="delete">
vn-acl="replenisherBos">
</vn-button>
</div>
</slot-actions>
@ -68,7 +68,9 @@
</tr>
</thead>
<tbody>
<tr ng-repeat="itemShelvingPlacementSupplyStock in itemShelvingPlacementSupplyStocks">
<tr
ng-repeat="itemShelvingPlacementSupplyStock in $ctrl.itemShelvingPlacementSupplyStocks"
vn-repeat-last on-last="$ctrl.calculateTotals()">
<td shrink>
<vn-check
ng-model="itemShelvingPlacementSupplyStock.checked"
@ -93,7 +95,7 @@
{{::itemShelvingPlacementSupplyStock.shelving}}
</td>
<td>
{{::itemShelvingPlacementSupplyStock.label}}
{{(itemShelvingPlacementSupplyStock.stock / itemShelvingPlacementSupplyStock.packing).toFixed(2)}}
</td>
<td>
{{::itemShelvingPlacementSupplyStock.packing}}

View File

@ -40,8 +40,6 @@ export default class Controller extends Section {
}
]
};
this.getBalanceDueTotal();
}
get checked() {
@ -49,46 +47,31 @@ export default class Controller extends Section {
const checkedLines = [];
for (let itemShelving of itemShelvings) {
if (itemShelving.checked)
checkedLines.push(itemShelving);
checkedLines.push(itemShelving.itemShelvingFk);
}
return checkedLines;
}
get label() {
calculateTotals() {
this.labelTotal = 0;
const itemShelvings = this.$.model.data || [];
for (let itemShelving of itemShelvings)
itemShelving.label = itemShelving.stock / itemShelving.packing;
return true;
itemShelvings.forEach(itemShelving => {
const label = itemShelving.stock / itemShelving.packing;
this.labelTotal += label;
});
}
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);
onRemove() {
const params = {itemShelvingIds: this.checked};
const query = `ItemShelvings/deleteItemShelvings`;
this.$http.post(query, params)
.then(() => {
this.vnApp.showSuccess(this.$t('ItemShelvings removed'));
this.$.model.refresh();
});
}
async onRemove() {
const params = [];
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();
});
}
}
exprBuilder(param, value) {
switch (param) {
case 'parking':

View File

@ -1,3 +1,5 @@
Shelving: Matrícula
Remove selected lines: Eliminar líneas seleccionadas
Selected lines will be deleted: Las líneas seleccionadas serán eliminadas
Selected lines will be deleted: Las líneas seleccionadas serán eliminadas
ItemShelvings removed: Carros eliminados
Total labels: Total etiquetas