Newer
Older
/**
* @module package/quiqqer/invoice/bin/backend/utils/Dialogs
* @author www.pcsg.de (Henning Leutz)

Patrick Müller
committed
*
* @event (global) onQuiqqerInvoiceCreateCreditNoteDialogOpen [invoiceId, Win]
* @event (global) onQuiqqerInvoiceCreateCreditNoteDialogSubmit [creditNoteId, Win]
*/
define('package/quiqqer/invoice/bin/backend/utils/Dialogs', [
'qui/QUI',
'Locale',
'package/quiqqer/invoice/bin/Invoices',
'qui/controls/windows/Confirm',
'qui/controls/windows/Popup',
'css!package/quiqqer/invoice/bin/backend/utils/Dialogs.css'
], function (QUI, QUILocale, Invoices, QUIConfirm, QUIPopup) {
return {
/**
* Opens the print dialog for a specific invoice
*
* @param {String} invoiceId - Invoice ID or Hash
* @param {String} [entityType]
openPrintDialog: function (invoiceId, entityType) {
entityType = entityType || 'Invoice';
return Invoices.getInvoiceHistory(invoiceId).then(function (comments) {
return new Promise(function (resolve) {

Patrick Müller
committed
require([
'package/quiqqer/erp/bin/backend/controls/OutputDialog'

Patrick Müller
committed
new OutputDialog({

Patrick Müller
committed
entityType: entityType,
entityPlugin: 'quiqqer/invoice',
comments: comments.length ? comments : false

Patrick Müller
committed
}).open();
resolve();
});
});
});
},
/**
* Opens a storno / cancellation dialog for a specific invoice
*
* @param {String} invoiceId - Invoice ID or Hash
* @return {Promise}
*/
openStornoDialog: function (invoiceId) {
return Invoices.get(invoiceId).then(function (result) {
const id = result.id_prefix + result.id;
return new Promise(function (resolve, reject) {
icon: 'fa fa-ban',
texticon: 'fa fa-ban',
title: QUILocale.get(lg, 'dialog.invoice.reversal.title', {
text: QUILocale.get(lg, 'dialog.invoice.reversal.text', {
invoiceId: id
}),
information: QUILocale.get(lg, 'dialog.invoice.reversal.information', {
invoiceId: id
}),
autoclose: false,
ok_button: {
text: QUILocale.get(lg, 'dialog.invoice.reversal.submit'),
maxHeight: 500,
maxWidth: 750,
events: {
const Container = Win.getContent().getElement('.textbody');
const Label = new Element('label', {
html: '<span>' + QUILocale.get(
lg,
'dialog.invoice.reversal.reason.title'
) + '</span>',
marginTop: 20,
width: 'calc(100% - 100px)'
const Reason = new Element('textarea', {
name: 'reason',
autofocus: true,
placeholder: QUILocale.get(lg, 'dialog.invoice.reversal.reason.placeholder'),
}
}).inject(Label);
Reason.focus();
},
const Reason = Win.getContent().getElement('[name="reason"]');
const value = Reason.value;
Reason.focus();
Reason.required = true;
if ('reportValidity' in Reason) {
Reason.reportValidity();
}
Invoices.reversalInvoice(result.hash, value).then(function (result) {
}).catch(function (Exception) {
Win.close();
reject(Exception);
});
},
});
},
/**
* Alias for openStornoDialog()
*
* @param {String} invoiceId - Invoice ID or Hash
* @return {*|Promise}
*/
openCancellationDialog: function (invoiceId) {
return this.openStornoDialog(invoiceId);
},
/**
* Alias for openStornoDialog()
*
* @param {String} invoiceId - Invoice ID or Hash
* @return {*|Promise}
*/
openReversalDialog: function (invoiceId) {
return this.openStornoDialog(invoiceId);
},
/**
* Opens a copy dialog for a specific invoice
*
* @param {String} invoiceId - Invoice ID or Hash
* @return {Promise}
*/
openCopyDialog: function (invoiceId) {
return Invoices.get(invoiceId).then(function (result) {
const id = result.id_prefix + result.id;
return new Promise(function (resolve) {
title: QUILocale.get(lg, 'dialog.invoice.copy.title'),
text: QUILocale.get(lg, 'dialog.invoice.copy.text'),
information: QUILocale.get(lg, 'dialog.invoice.copy.information', {
id: id
}),
icon: 'fa fa-copy',
texticon: 'fa fa-copy',
maxHeight: 400,
maxWidth: 600,
autoclose: false,
ok_button: {
text: QUILocale.get('quiqqer/system', 'copy'),
Invoices.copyInvoice(result.hash).then(function (newId) {
});
},
/**
* Opens a credit note dialog for a specific invoice
*
* @param {String} invoiceId - Invoice ID or Hash
* @return {Promise}
*/
openCreateCreditNoteDialog: function (invoiceId) {
return Invoices.get(invoiceId).then(function (result) {
let paymentHasRefund = false;
const id = result.id_prefix + result.id;
return new Promise(function (resolve, reject) {
icon: 'fa fa-clipboard',
texticon: 'fa fa-clipboard',
title: QUILocale.get(lg, 'dialog.invoice.createCreditNote.title', {
text: QUILocale.get(lg, 'dialog.invoice.createCreditNote.text', {
invoiceId: id
}),
information: QUILocale.get(lg, 'dialog.invoice.createCreditNote.information', {
invoiceId: id
}),
autoclose: false,
ok_button: {
text: QUILocale.get(lg, 'dialog.invoice.createCreditNote.submit'),
maxHeight: 400,
maxWidth: 600,
events: {
Win.Loader.show();
Invoices.hasRefund(id).then(function (hasRefund) {
paymentHasRefund = hasRefund;

Patrick Müller
committed
QUI.fireEvent('quiqqerInvoiceCreateCreditNoteDialogOpen', [id, Win]);
if (!paymentHasRefund) {
Win.Loader.hide();
return;
const Content = Win.getContent(),
Body = Content.getElement('.textbody');
new Element('label', {
'class': 'quiqqer-invoice-dialog-refund-label',
html: '<input type="checkbox" name="refund" />' + QUILocale.get(
lg,
'dialog.invoice.createCreditNote.refund'
),
styles: {
cursor: 'pointer',
display: 'block',
marginTop: 20
}
}).inject(Body);
Win.Loader.hide();
});
const Content = Win.getContent(),
Refund = Content.getElement('[name="refund"]');
const createInvoice = function (values) {
Invoices.createCreditNote(result.hash, values).then(function (newId) {

Patrick Müller
committed
QUI.fireEvent(
'quiqqerInvoiceCreateCreditNoteDialogSubmit',
[newId, Win]
);
Win.Loader.hide();
console.error(Err);
reject(Err);
});
};
if (paymentHasRefund && Refund.checked) {
self.openRefundWindow(invoiceId).then(function (RefundWindow) {
if (!RefundWindow) {
Win.Loader.hide();
return;
}
createInvoice({
refund: RefundWindow.getValues()
});
Win.Loader.hide();
console.error(Err);
});
return;
}
createInvoice();

Henning Leutz
committed
}
},
/**
*
* @param invoiceId
* @return {Promise}
*/
openRefundWindow: function (invoiceId) {
return new Promise(function (resolve) {
require([
'package/quiqqer/invoice/bin/backend/controls/panels/refund/Window'
], function (RefundWindow) {
resolve(false);
}
}
}).open();
});
});
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
},
openDownloadDialog: function (hash) {
new QUIPopup({
icon: 'fa fa-download',
title: QUILocale.get(lg, 'dialog.invoice.download.title'),
autoclose: false,
maxHeight: 400,
maxWidth: 600,
buttons: false,
events: {
onOpen: function (Win) {
Win.Loader.show();
const Content = Win.getContent();
Content.classList.add('quiqqer-invoice-download-dialog');
Content.set(
'html',
'<h3>' + QUILocale.get(lg, 'dialog.invoice.download.header') + '</h3>' +
QUILocale.get(lg, 'dialog.invoice.download.text') +
'<div class="quiqqer-invoice-download-dialog-buttons">' +
' <button value="PDF" class="qui-button">PDF</button>' +
' <button value="PROFILE_BASIC" class="qui-button">ZUGFeRD Basic</button>' +
' <button value="PROFILE_EN16931" class="qui-button">ZUGFeRD EN16931</button>' +
' <button value="PROFILE_EXTENDED" class="qui-button">ZUGFeRD Extended</button>' +
' <button value="PROFILE_XRECHNUNG_2_3" class="qui-button">XRechnung 2.3</button>' +
' <button value="PROFILE_XRECHNUNG_3" class="qui-button">XRechnung 3</button>' +
'</div>'
);
Content.querySelectorAll('button').forEach(function (Button) {
Button.addEventListener('click', function () {
const id = 'download-invoice-' + hash + '-' + Button.value;
new Element('iframe', {
src: URL_OPT_DIR + 'quiqqer/invoice/bin/backend/download.php?' + Object.toQueryString({
invoice: hash,
type: Button.value
}),
id: id,
styles: {
position: 'absolute',
top: -200,
left: -200,
width: 50,
height: 50
}
}).inject(document.body);
(function () {
}).delay(1000, this);
});
});
Win.Loader.hide();
}
}
}).open();