hedera-web/forms/ecomerce/ticket/ticket.js

62 lines
1.5 KiB
JavaScript

Hedera.Ticket = new Class({
Extends: Hedera.Form,
onTicketChange: function(ticket) {
if (!ticket.value)
return;
var batch = new Sql.Batch();
batch.addValue('ticket', ticket.value);
this.conn.execQuery('CALL myTicket_logAccess(#ticket)', null, batch);
},
onTicketReady: function(form) {
if (form.$.method != 'PICKUP')
Vn.Node.setText(this.$.method, _('Agency'));
else
Vn.Node.setText(this.$.method, _('Warehouse'));
},
onPrintClick: function() {
let params = Vn.Url.makeUri({
authorization: this.conn.token,
ticketId: this.$.ticketId.value,
recipientId: this.gui.user.id,
type: 'deliveryNote'
});
window.open(`/api/report/delivery-note?${params}`);
},
repeaterFunc: function(res, form) {
var discount = res.$.discount;
discount.style.display = form.$.discount ? 'inline' : 'none';
res.$.discountSubtotal.value = this.discountSubtotal(form);
res.$.subtotal.value = this.subtotal(form);
},
discountSubtotal: function(form) {
return form.$.quantity * form.$.price;
},
subtotal: function(form) {
var discount = form.$.discount;
return this.discountSubtotal(form) * ((100 - discount) / 100);
},
servicesFunc: function(res, form) {
res.$.subtotal.value = form.$.quantity * form.$.price;
},
onServicesChanged: function(model) {
this.$.services.node.style.display =
model.numRows > 0 ? 'block' : 'none';
},
onPackagesChanged: function(model) {
this.$.packages.node.style.display =
model.numRows > 0 ? 'block' : 'none';
},
});