dev #1731

Merged
jgallego merged 105 commits from dev into test 2023-08-31 09:13:29 +00:00
5 changed files with 200 additions and 40 deletions
Showing only changes of commit 0d85069e0f - Show all commits

View File

@ -0,0 +1,53 @@
module.exports = Self => {
Self.remoteMethod('delete', {
description: 'Elimina el registro (si se cumple la condición) y inserta uno nuevo',
accessType: 'READ',
accepts: [
{
arg: 'saleFk',
type: 'number',
description: 'The sale id'
},
{
arg: 'stateCode',
type: 'string'
}
],
returns: {
type: ['object'],
root: true
},
http: {
path: `/delete`,
verb: 'POST'
}
});
Self.delete = async(saleFk, stateCode, options) => {
const models = Self.app.models;
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
// const [itemShelvingSale] = await models.ItemShelvingSale.find({saleFk: saleFk}, myOptions);
// if (itemShelvingSale) await itemShelvingSale.destroy(myOptions);
// const filter = {
// where: {
// saleFk: saleFk,
// code: stateCode
// }
// };
// const [saleTracking] = await models.SaleTracking.find(filter, myOptions);
// return saleTracking.destroy(myOptions);
query = `CALL vn.saleTracking_del(?, ?)`;
return Self.rawSql(query,
[
saleFk,
stateCode,
], myOptions);
};
};

View File

@ -0,0 +1,69 @@
module.exports = Self => {
Self.remoteMethodCtx('replace', {
description: 'Remplaza el registro o lo crea si no existe',
accessType: 'READ',
accepts: [
{
arg: 'saleFk',
type: 'number',
description: 'The sale id'
},
{
arg: 'isChecked',
type: 'boolean'
},
{
arg: 'quantity',
type: 'number'
},
{
arg: 'stateCode',
type: 'string'
}
],
returns: {
type: ['object'],
root: true
},
http: {
path: `/replace`,
verb: 'POST'
}
});
Self.replace = async(ctx, saleFk, isChecked, quantity, stateCode, options) => {
const models = Self.app.models;
const myOptions = {};
const userId = ctx.req.accessToken.userId;
if (typeof options == 'object')
Object.assign(myOptions, options);
// const state = await models.State.findOne({
// where: {code: stateCode}
// }, myOptions);
// if (!state) return;
// const data = {
// saleFk: saleFk,
// isChecked: isChecked,
// originalQuantity: quantity,
// workerFk: userId,
// stateFk: state.id
// };
// return models.SaleTracking.replaceOrCreate(data, myOptions);
query = `CALL vn.saleTracking_new(?, ?, ?, ?, ?, ?)`;
return Self.rawSql(query,
[
saleFk,
isChecked,
quantity,
userId,
stateCode,
null
], myOptions);
};
};

View File

@ -1,3 +1,5 @@
module.exports = Self => { module.exports = Self => {
require('../methods/sale-tracking/listSaleTracking')(Self); require('../methods/sale-tracking/listSaleTracking')(Self);
require('../methods/sale-tracking/replace')(Self);
require('../methods/sale-tracking/delete')(Self);
}; };

View File

@ -1,6 +1,6 @@
<vn-crud-model <vn-crud-model
vn-id="model" vn-id="model"
url="sales" url="Sales"
filter="::$ctrl.filter" filter="::$ctrl.filter"
link="{ticketFk: $ctrl.$params.id}" link="{ticketFk: $ctrl.$params.id}"
limit="20" limit="20"
@ -25,43 +25,48 @@
<vn-tr ng-repeat="sale in $ctrl.sales"> <vn-tr ng-repeat="sale in $ctrl.sales">
<vn-td center> <vn-td center>
<vn-chip <vn-chip
ng-class="::{ ng-class="{
'pink': sale.preparingList.hasSaleGroupDetail, 'pink': sale.preparingList.hasSaleGroupDetail,
'none': !sale.preparingList.hasSaleGroupDetail, 'none': !sale.preparingList.hasSaleGroupDetail,
}" }"
class="circleState" class="circleState"
vn-tooltip="has saleGroupDetail" vn-tooltip="has saleGroupDetail"
> >
</vn-chip> </vn-chip>
<vn-chip ng-class="::{ <vn-chip
'notice': sale.preparingList.isPreviousSelected, ng-class="{
'none': !sale.preparingList.isPreviousSelected, 'notice': sale.preparingList.isPreviousSelected,
}" 'none': !sale.preparingList.isPreviousSelected,
class="circleState" }"
vn-tooltip="is previousSelected"> class="circleState"
vn-tooltip="is previousSelected"
vn-click-stop="$ctrl.clickPreviousSelected($index)">
</vn-chip> </vn-chip>
<vn-chip ng-class="::{ <vn-chip
'dark-notice': sale.preparingList.isPrevious, ng-class="{
'none': !sale.preparingList.isPrevious, 'dark-notice': sale.preparingList.isPrevious,
}" 'none': !sale.preparingList.isPrevious,
class="circleState" }"
vn-tooltip="is previous"> class="circleState"
vn-tooltip="is previous">
</vn-chip> </vn-chip>
<vn-chip ng-class="::{ <vn-chip
'warning': sale.preparingList.isPrepared, ng-class="{
'none': !sale.preparingList.isPrepared, 'warning': sale.preparingList.isPrepared,
}" 'none': !sale.preparingList.isPrepared,
class="circleState" }"
vn-tooltip="is prepared"> class="circleState"
vn-tooltip="is prepared">
</vn-chip> </vn-chip>
<vn-chip ng-class="::{ <vn-chip
'yellow': sale.preparingList.isControled, ng-class="{
'none': !sale.preparingList.isControled, 'yellow': sale.preparingList.isControled,
}" 'none': !sale.preparingList.isControled,
class="circleState" }"
vn-tooltip="is controled"> class="circleState"
vn-tooltip="is controled">
</vn-chip> </vn-chip>
</vn-td> </vn-td>
<vn-td number> <vn-td number>
<span <span
ng-click="itemDescriptor.show($event, sale.item.id)" ng-click="itemDescriptor.show($event, sale.item.id)"

View File

@ -48,13 +48,10 @@ class Controller extends Section {
const query = `Sales/${this.$params.id}/salePreparingList`; const query = `Sales/${this.$params.id}/salePreparingList`;
this.$http.get(query) this.$http.get(query)
.then(res => { .then(res => {
this.salePreparingList = res.data; res.data.forEach(salePreparing => {
for (const salePreparing of this.salePreparingList) { const sale = this.sales.find(sale => salePreparing.saleFk === sale.id);
for (const sale of this.sales) { if (sale) sale.preparingList = salePreparing;
if (salePreparing.saleFk == sale.id) });
sale.preparingList = salePreparing;
}
}
}); });
} }
} }
@ -83,12 +80,46 @@ class Controller extends Section {
this.saleId = sale.id; this.saleId = sale.id;
this.$.itemShelvingSale.show(); this.$.itemShelvingSale.show();
} }
clickPreviousSelected(index) {
const sale = this.sales[index];
if (!sale.preparingList.isPreviousSelected) {
this.saleTrackingNew(sale, 'PREVIOUS_PREPARATION', false);
sale.preparingList.isPreviousSelected = true;
} else {
this.saleTrackingDel(sale, 'PREVIOUS_PREPARATION');
sale.preparingList.isPreviousSelected = false;
}
}
saleTrackingNew(sale, stateCode, isChecked) {
const params = {
saleFk: sale.id,
isChecked: isChecked,
quantity: sale.quantity,
stateCode: stateCode
};
this.$http.post(`SaleTrackings/replace`, params).then(() => {
this.vnApp.showSuccess(this.$t('Data saved!'));
});
}
saleTrackingDel(sale, stateCode) {
const params = {
saleFk: sale.id,
stateCode: stateCode
};
this.$http.post(`SaleTrackings/delete`, params).then(() => {
this.vnApp.showSuccess(this.$t('Data saved!'));
});
}
} }
ngModule.vnComponent('vnTicketSaleTracking', { ngModule.vnComponent('vnTicketSaleTracking', {
template: require('./index.html'), template: require('./index.html'),
controller: Controller, controller: Controller,
bindings: { bindings: {
ticket: '<' ticket: '<',
model: '<?'
} }
}); });