fixed update discount
gitea/salix/dev This commit looks good Details

This commit is contained in:
Joan Sanchez 2019-05-06 07:40:59 +02:00
parent 8771098045
commit 4aff31a165
4 changed files with 25 additions and 13 deletions

View File

@ -26,24 +26,20 @@ module.exports = Self => {
throw new UserError(`The value should be a number`); throw new UserError(`The value should be a number`);
let model = Self.app.models; let model = Self.app.models;
let ticket = await model.Ticket.find({ let ticket = await model.Ticket.findById(params.editLines[0].ticketFk, {
where: { include: {
id: params.editLines[0].ticketFk
},
include: [{
relation: 'client', relation: 'client',
scope: { scope: {
fields: ['salesPersonFk'] fields: ['salesPersonFk']
} }
}], },
fields: ['id', 'clientFk', 'refFk']
}); });
if (ticket.refFk) if (ticket.refFk)
throw new UserError(`The sales of this ticket can't be modified`); throw new UserError(`The sales of this ticket can't be modified`);
let componentToUse; let componentToUse;
let usesMana = await model.WorkerMana.findOne({where: {workerFk: ticket[0].client().salesPersonFk}, fields: 'amount'}); let usesMana = await model.WorkerMana.findOne({where: {workerFk: ticket.client().salesPersonFk}, fields: 'amount'});
if (usesMana) if (usesMana)
componentToUse = 37; componentToUse = 37;
@ -61,7 +57,7 @@ module.exports = Self => {
if (usesMana) { if (usesMana) {
query = ` query = `
call vn.manaSpellersRequery(?)`; call vn.manaSpellersRequery(?)`;
await Self.rawSql(query, [ticket[0].client().salesPersonFk]); await Self.rawSql(query, [ticket.client().salesPersonFk]);
} }
}; };
}; };

View File

@ -44,13 +44,14 @@ class Controller {
} }
if (modified) { if (modified) {
this.$http.post(`/ticket/api/Sales/updateDiscount`, {editLines}).then(() => { this.$http.post(`/ticket/api/Sales/updateDiscount`, {editLines}).then(() => {
this.onHide();
this.vnApp.showSuccess(this.$translate.instant('Data saved!')); this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
this.clear(); this.clear();
modified = false; modified = false;
}).catch(e => { }).catch(e => {
this.vnApp.showError(e.data.error.message); this.vnApp.showError(e.data.error.message);
}); });
this.onHide();
} else } else
this.vnApp.showError(this.$translate.instant('There is no changes to save')); this.vnApp.showError(this.$translate.instant('There is no changes to save'));
} }

View File

@ -134,7 +134,7 @@
<vn-td number ng-if="!$ctrl.isEditable"> <vn-td number ng-if="!$ctrl.isEditable">
{{sale.price | currency: 'EUR':2}} {{sale.price | currency: 'EUR':2}}
</vn-td> </vn-td>
<vn-td number ng-if="$ctrl.isEditable"> <vn-td number ng-if="!$ctrl.ticket.refFk">
<span class="link" <span class="link"
vn-tooltip="Edit discount" vn-tooltip="Edit discount"
ng-click="$ctrl.showEditPopover($event, sale)"> ng-click="$ctrl.showEditPopover($event, sale)">

View File

@ -14,7 +14,7 @@ class Controller {
this.moreOptions = [ this.moreOptions = [
{callback: this.markAsReserved, name: 'Mark as reserved'}, {callback: this.markAsReserved, name: 'Mark as reserved'},
{callback: this.unmarkAsReserved, name: 'Unmark as reserved'}, {callback: this.unmarkAsReserved, name: 'Unmark as reserved'},
{callback: this.showEditDialog, name: 'Update discount'}, {callback: this.showEditDialog, name: 'Update discount', show: () => !this.hasInvoice()},
{callback: this.createClaim, name: 'Add claim'}, {callback: this.createClaim, name: 'Add claim'},
{callback: this.showSMSDialog, name: 'Send SMS'} {callback: this.showSMSDialog, name: 'Send SMS'}
]; ];
@ -60,7 +60,13 @@ class Controller {
} }
onMoreOpen() { onMoreOpen() {
let options = this.moreOptions.filter(o => o.always || this.isChecked); let options = this.moreOptions.filter(option => {
const hasShowProperty = Object.hasOwnProperty.call(option, 'show');
const shouldShow = !hasShowProperty || option.show === true ||
typeof option.show === 'function' && option.show();
return (shouldShow && (option.always || this.isChecked));
});
this.$scope.moreButton.data = options; this.$scope.moreButton.data = options;
} }
@ -337,6 +343,15 @@ class Controller {
}; };
this.$scope.sms.open(); this.$scope.sms.open();
} }
/**
* Returns if the current ticket
* is already invoiced
* @return {Boolean} - True if invoiced
*/
hasInvoice() {
return this.ticket.refFk !== null;
}
} }
Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate']; Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate'];