Rev 8267 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php
declare(strict_types=1);
/**
* @author: Daniel Schmitzer (daschmi@daschmi.de)
* @date: 09.06.22
* @time: 07:44
*/
namespace wpsg;
/** @var \wpsg_customer $oCustomer */
$oCustomer = $this->view['oCustomer']??null;
/** @var \wpsg_order $oOrder */
$oOrder = $this->view['oOrder']??null;
$wpsg_rechnungen_footer = $this->get_option("wpsg_rechnungen_footer");
if (is_string($wpsg_rechnungen_footer)) $wpsg_rechnungen_footer = unserialize($this->get_option("wpsg_rechnungen_footer"));
if (!is_array($wpsg_rechnungen_footer)) $wpsg_rechnungen_footer = Array();
$default = $this->get_option('wpsg_rechnungen_foottext_standard');
/** @var \wpsg\wpsg_invoice[] $arInvoice */
$arInvoice = $this->callMod('wpsg_mod_rechnungen', 'getInvoiceToOrder', [$oOrder->getId()]);
$bCanInvoice = false;
$bCanStorno = false;
foreach ($oOrder->getOrderProducts() as $oOrderProduct) {
if ($this->callMod('wpsg_mod_rechnungen', 'getAmountToInvoice', [$oOrderProduct]) > 0) {
$bCanInvoice = true;
}
if ($this->callMod('wpsg_mod_rechnungen', 'getAmountToStorno', [$oOrderProduct]) > 0) {
$bCanStorno = true;
}
if ($bCanInvoice && $bCanStorno) break;
}
$act = 0;
if ($bCanInvoice) $act = 1;
else if ($bCanStorno) $act = 2;
?>
<div id="wpsg_mod_invoice_tabs">
<ul class="nav nav-tabs" role="tablist">
<?php if ($bCanInvoice) { ?>
<li role="presentation" class="tab <?php echo (($act === 1)?'akttab active':''); ?>" id="tab1"><a href="#tab1" role="tab" data-toggle="tab" class="bg_invoice"><?php echo __('Rechnung erstellen', 'wpsg'); ?></a></li>
<?php } ?>
<?php if ($bCanStorno) { ?>
<li role="presentation" class="tab <?php echo (($act === 2)?'akttab active':''); ?>" id="tab2"><a href="#tab2" role="tab" data-toggle="tab" class="bg_storno"><?php echo __('Gutschrift/Rechnungskorrektur erstellen', 'wpsg'); ?></a></li>
<?php } ?>
</ul>
<div class="tab-content">
<?php if ($bCanInvoice) { ?>
<div role="tabpanel" class="tabcontent bg_invoice" id="tabcontent1">
<form method="post" id="invoice_form" target="_blank" action="<?php
echo WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Order&action=ajax&mod=wpsg_mod_rechnungen&cmd=rechnung&noheader=1&edit_id='.$oOrder->getId();
?>" class="grid">
<?php \wp_nonce_field('wpsg-mod_invoice-order_ajax-rechnung-'.$this->view['data']['id']);
$arInvoiceLabel = [];
foreach ($arInvoice as $oInvoice) {
if ($oInvoice->isInvoice() && $oInvoice->getMeta('include_shipping', false, '0') === '1') {
$arInvoiceLabel[] = $oInvoice->getNr(true);
}
}
?>
<!-- Rechnung -->
<input type="checkbox" name="wpsg_rechnungen_sendmail" value="1" id="invoice_sendmail" checked="checked" />
<label for="invoice_sendmail"><?php echo __('E-Mail an Kunden senden', 'wpsg'); ?></label>
<input type="email" name="wpsg_rechnungen_email" value="<?php echo $oCustomer->getEMail(); ?>" />
<input type="checkbox" name="wpsg_rechnungen_faelligkeit" value="1" id="invoice_faelligkeit" checked="checked" />
<label for="invoice_faelligkeit"><?php echo __('Fälligkeit anzeigen', 'wpsg'); ?></label>
<input type="date" name="wpsg_rechnungen_faelligkeitsdatum" value="<?php echo date('Y-m-d', strtotime('+'.intval($this->get_option("wpsg_rechnungen_faelligkeit")).' day')); ?>" />
<input type="checkbox" name="wpsg_rechnungen_status" value="1" id="invoice_state" checked="checked" />
<label for="invoice_state"><?php echo __('Neuer Status', 'wpsg'); ?></label>
<select name="wpsg_rechnungen_status_neu">
<?php foreach ($this->arStatus as $status_key => $status_label) { ?>
<option value="<?php echo $status_key; ?>" <?php echo ((intval($status_key) === 110)?'selected="selected"':''); ?>><?php echo $status_label; ?></option>
<?php } ?>
</select>
<input type="checkbox" name="wpsg_rechnungen_shippay" value="1" id="invoice_shippay" <?php
if (sizeof($arInvoiceLabel) <= 0) echo ' checked="checked" ';
?> />
<label style="grid-column:2 / span 2;" for="invoice_shippay"><?php
echo __('Versand-/Zahlungskosten berechnen', 'wpsg');
if (sizeof($arInvoiceLabel) > 0) {
echo wpsg_translate(__(' (Enthalten in #1#)', 'wpsg'), implode(', ', $arInvoiceLabel));
}
?></label>
<input type="checkbox" name="wpsg_rechnungen_discount_voucher_coupon" value="1" id="wpsg_rechnungen_discount_voucher_coupon" checked="checked" />
<label style="grid-column:2 / span 2;" for="wpsg_rechnungen_discount_voucher_coupon"><?php echo __('Rabatt, Gutschein, Wertgutschein berechnen wenn vorhanden', 'wpsg'); ?></label>
<input type="checkbox" name="wpsg_rechnungen_url" value="1" id="invoice_url" />
<label for="invoice_url" style="grid-column: 2 / span 2;"><?php echo __('URL Benachrichtigung', 'wpsg'); ?></label>
<span></span>
<label for="invoice_date"><?php echo __('Rechnungsdatum', 'wpsg') ;?></label>
<input type="date" value="<?php echo date('Y-m-d'); ?>" name="wpsg_rechnungen_datum" id="invoice_date" />
<span></span>
<label for="invoice_foottext_select"><?php echo __('Fußtext', 'wpsg'); ?></label>
<?php if (sizeof($wpsg_rechnungen_footer) > 0) { ?>
<select id="invoice_foottext_select">
<?php foreach ($wpsg_rechnungen_footer as $k => $v) { ?>
<option value="<?php echo wpsg_hspc($v[1]); ?>" <?php echo ((intval($default) === intval($k))?'selected="selected"':''); ?>><?php echo wpsg_hspc($v[0]); ?></option>
<?php } ?>
</select>
<?php } else { ?>
<span></span>
<?php } ?>
<span></span>
<input type="text" name="wpsg_rechnungen_fusstext" id="wpsg_rechnungen_fusstext" value="" style="grid-column: 2 / span 2;" />
<span style="grid-column:1 / span 3;"></span>
<span style="display:flex; justify-content:flex-end; gap:0.5rem; grid-column:1/span 3;">
<input class="button" style="" id="invoice_wpsg_rechnungen_preview" name="wpsg_rechnungen_preview" type="submit" value="Vorschau">
<input class="button" style="" id="invoice_wpsg_rechnungen_submit" onclick="" name="wpsg_rechnungen_write" type="submit" value="Rechnung schreiben">
</span>
<script>
let el_invoice_foottext_select = document.getElementById('invoice_foottext_select');
let el_invoice_form = document.getElementById('invoice_form');
if (el_invoice_foottext_select) {
el_invoice_foottext_select.addEventListener('change', (event) => {
document.getElementById('wpsg_rechnungen_fusstext').value = event.target.value;
});
el_invoice_foottext_select.dispatchEvent(new Event('change'));
};
let el_invoice_wpsg_rechnungen_preview = document.getElementById('invoice_wpsg_rechnungen_preview');
let el_invoice_wpsg_rechnungen_submit = document.getElementById('invoice_wpsg_rechnungen_submit');
let submit = false;
function check_invoice_amount(event) {
if (submit === true) return;
submit = true;
let ok = false;
for (let el_checkbox of document.getElementsByClassName('wpsg_check_amount_invoice')) {
if (el_checkbox.checked) {
if (parseInt(el_checkbox.nextElementSibling.value) > 0) {
ok = true; break;
}
}
}
if (ok) {
if (event.target.getAttribute("id") === 'invoice_wpsg_rechnungen_submit') {
window.setTimeout(function() { location.href = '<?php
echo wpsg_admin_url('Order', 'view', ['edit_id' => $oOrder->getId()], [], true);
?>'; }, 1000);
}
} else {
submit = false;
alert('<?php echo __('Bitte mindestens ein Produkt auswählen!', 'wpsg'); ?>');
event.stopPropagation();
event.preventDefault();
}
}
el_invoice_wpsg_rechnungen_preview.addEventListener('click', check_invoice_amount);
el_invoice_wpsg_rechnungen_submit.addEventListener('click', check_invoice_amount);
</script>
</form>
</div>
<?php } ?>
<?php if ($bCanStorno) { ?>
<div role="tabpanel" class="tabcontent bg_storno" id="tabcontent2">
<form method="post" id="storno_form" target="_blank" action="<?php
echo WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Order&noheader=1&action=ajax&mod=wpsg_mod_rechnungen&edit_id='.$oOrder->getId().'&do=storno';
?>" class="grid">
<?php \wp_nonce_field('wpsg-mod_invoice-order_ajax-storno-'.$this->view['data']['id']);
$arInvoiceLabel = [];
foreach ($arInvoice as $oInvoice) {
if ($oInvoice->isStorno() && $oInvoice->getMeta('include_shipping', false, '0') === '1') {
$arInvoiceLabel[] = $oInvoice->getNr(true);
}
}
?>
<!-- Gutschrift -->
<input type="checkbox" name="storno_send" id="storno_send" value="1" />
<label for="storno_send"><?php echo __('E-Mail an Kunden senden', 'wpsg'); ?></label>
<input type="email" name="storno_mail" value="<?php echo $oCustomer->getEMail(); ?>" />
<input type="checkbox" id="storno_shippay" name="storno_shippay" value="1" id="invoice_shippay" <?php
if (sizeof($arInvoiceLabel) <= 0) echo ' checked="checked" ';
?> />
<label style="grid-column:2 / span 2;" for="storno_shippay"><?php
echo __('Versand-/Zahlungskosten stornieren', 'wpsg');
if (sizeof($arInvoiceLabel) > 0) {
echo wpsg_translate(__(' (Enthalten in #1#)', 'wpsg'), implode(', ', $arInvoiceLabel));
}
?></label>
<input type="checkbox" name="storno_state" value="1" id="storno_state" checked="checked" />
<label for="storno_state"><?php echo __('Neuer Status', 'wpsg'); ?></label>
<select name="storno_state_new">
<?php foreach ($this->arStatus as $status_key => $status_label) { ?>
<option value="<?php echo $status_key; ?>"><?php echo $status_label; ?></option>
<?php } ?>
</select>
<input type="checkbox" name="wpsg_rechnungen_discount_voucher_coupon" value="1" id="wpsg_rechnungen_storno_discount_voucher_coupon" checked="checked" />
<label style="grid-column:2 / span 2;" for="wpsg_rechnungen_storno_discount_voucher_coupon"><?php echo __('Rabatt, Gutschein, Wertgutschein berechnen wenn vorhanden', 'wpsg'); ?></label>
<input type="checkbox" name="storno_fee_set" id="storno_fee_set" value="1" id="storno_fee_set" />
<label for="storno_fee_set"><?php echo __('Stornierungsgebühr in % oder EUR', 'wpsg'); ?></label>
<input type="text" value="" name="storno_fee_value" />
<span style="grid-column:1 / span 3;"></span>
<span style="display:flex; justify-content:flex-end; gap:0.5rem; grid-column:1/span 3;">
<input class="button" style="" id="invoice_wpsg_storno_preview" name="wpsg_storno_preview" type="submit" value="Vorschau">
<input class="button" style="" id="invoice_wpsg_storno_submit" onclick="" name="wpsg_storno_write" type="submit" value="Rechnungskorrektur schreiben">
</span>
<script>
let el_storno_form = document.getElementById('storno_form');
let el_invoice_wpsg_storno_preview = document.getElementById('invoice_wpsg_storno_preview');
let el_invoice_wpsg_storno_submit = document.getElementById('invoice_wpsg_storno_submit');
function check_invoice_amount(event) {
let ok = false;
for (let el_checkbox of document.getElementsByClassName('wpsg_check_amount_storno')) {
if (el_checkbox.checked) {
if (parseInt(el_checkbox.nextElementSibling.value) > 0) {
ok = true; break;
}
}
}
if (ok) {
if (event.target.getAttribute("id") === 'invoice_wpsg_storno_submit') {
window.setTimeout(function() { location.href = '<?php
echo wpsg_admin_url('Order', 'view', ['edit_id' => $oOrder->getId()], [], true);
?>'; }, 1000);
}
} else {
alert('<?php echo __('Bitte mindestens ein Produkt auswählen!', 'wpsg'); ?>');
event.stopPropagation();
event.preventDefault();
}
}
el_invoice_wpsg_storno_preview.addEventListener('click', check_invoice_amount);
el_invoice_wpsg_storno_submit.addEventListener('click', check_invoice_amount);
</script>
</form>
</div>
<?php } ?>
</div>
</div>
<style>
#wpsg_mod_invoice_tabs .grid { width:100%; padding:1rem; display:grid; row-gap:0.5rem; column-gap:0.5rem; grid-template-columns:25px 1fr 300px; align-items:center; grid-auto-rows:30px; padding-bottom:0.5rem; }
#wpsg_mod_invoice_tabs .grid input[type="checkbox"] { margin-top:0; }
#wpsg_mod_invoice_tabs .grid label { font-weight:normal; margin-bottom:0; }
.nav-tabs > li.active > a.bg_invoice,
.nav-tabs > li.active > a.bg_invoice:focus,
label.bg_invoice,
.link_invoice.bg_invoice,
.tabcontent.bg_invoice { background-color:lightgreen; color:black; }
.nav-tabs > li.active > a.bg_storno,
.nav-tabs > li.active > a.bg_storno:focus,
label.bg_storno,
.link_invoice.bg_storno,
.tabcontent.bg_storno { background-color:lightpink; color:black; }
.link_invoice { transform:translateX(-5px); padding:2px 5px; font-siz:12px; text-decoration:underline; }
label[for="invoice_shippay"] .link_invoice,
label[for="storno_shippay"] .link_invoice { padding:0; }
.wpsg_mod_rechnungen_row { display:block; width:100%; }
.wpsg_mod_rechnungen_row > div { padding:5px; }
.wpsg_mod_rechnungen_row .invoice_wrap:not(:only-child) { margin-top:0.5rem; }
.wpsg_mod_rechnungen_row .invoice_wrap > a:first-child { padding-left:0; }
</style>
<script>
jQuery('#wpsg_mod_invoice_tabs').wpsg_tab( {
aktTab: <?php echo $act; ?>
} );
</script>