Subversion Repositories wpShopGermany4

Rev

Rev 8390 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8007 daniel 1
<?php
2
 
3
    declare(strict_types=1);
4
 
5
    /**
6
     * @author: Daniel Schmitzer (daschmi@daschmi.de)
7
     * @date: 09.06.22
8
     * @time: 07:44
9
     */
10
 
11
    namespace wpsg;
12
 
13
    /** @var \wpsg_customer $oCustomer */
14
    $oCustomer = $this->view['oCustomer']??null;
15
 
16
    /** @var \wpsg_order $oOrder */
17
    $oOrder = $this->view['oOrder']??null;
18
 
19
    $wpsg_rechnungen_footer = $this->get_option("wpsg_rechnungen_footer");
20
 
8017 daniel 21
    if (is_string($wpsg_rechnungen_footer)) $wpsg_rechnungen_footer = unserialize($this->get_option("wpsg_rechnungen_footer"));
8007 daniel 22
    if (!is_array($wpsg_rechnungen_footer)) $wpsg_rechnungen_footer = Array();
23
 
24
    $default = $this->get_option('wpsg_rechnungen_foottext_standard');
25
 
8010 daniel 26
    /** @var \wpsg\wpsg_invoice[] $arInvoice */
27
    $arInvoice = $this->callMod('wpsg_mod_rechnungen', 'getInvoiceToOrder', [$oOrder->getId()]);
28
 
29
    $bCanInvoice = false;
30
    $bCanStorno = false;
31
 
32
    foreach ($oOrder->getOrderProducts() as $oOrderProduct) {
33
 
34
        if ($this->callMod('wpsg_mod_rechnungen', 'getAmountToInvoice', [$oOrderProduct]) > 0) {
35
 
36
            $bCanInvoice = true;
37
 
38
        }
39
 
40
        if ($this->callMod('wpsg_mod_rechnungen', 'getAmountToStorno', [$oOrderProduct]) > 0) {
41
 
42
            $bCanStorno = true;
43
 
44
        }
45
 
46
        if ($bCanInvoice && $bCanStorno) break;
47
 
48
    }
49
 
50
    $act = 0;
51
 
52
    if ($bCanInvoice) $act = 1;
53
    else if ($bCanStorno) $act = 2;
54
 
8007 daniel 55
?>
56
 
57
 
58
<div id="wpsg_mod_invoice_tabs">
59
 
60
    <ul class="nav nav-tabs" role="tablist">
8010 daniel 61
        <?php if ($bCanInvoice) { ?>
62
        <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>
63
        <?php } ?>
64
        <?php if ($bCanStorno) { ?>
65
        <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>
66
        <?php } ?>
8007 daniel 67
    </ul>
68
 
69
	<div class="tab-content">
70
 
8010 daniel 71
        <?php if ($bCanInvoice) { ?>
72
            <div role="tabpanel" class="tabcontent bg_invoice" id="tabcontent1">
8007 daniel 73
 
8010 daniel 74
                <form method="post" id="invoice_form" target="_blank" action="<?php
75
 
76
                    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();
77
 
78
                ?>" class="grid">
79
 
80
                    <?php \wp_nonce_field('wpsg-mod_invoice-order_ajax-rechnung-'.$this->view['data']['id']);
81
 
82
                        $arInvoiceLabel = [];
8007 daniel 83
 
8010 daniel 84
                        foreach ($arInvoice as $oInvoice) {
85
 
86
                            if ($oInvoice->isInvoice() && $oInvoice->getMeta('include_shipping', false, '0') === '1') {
87
 
88
                                $arInvoiceLabel[] = $oInvoice->getNr(true);
89
 
90
                            }
91
 
92
                        }
8007 daniel 93
 
8010 daniel 94
                    ?>
95
 
96
                    <!-- Rechnung -->
97
 
8081 karl 98
                    <input type="checkbox" name="wpsg_rechnungen_sendmail" value="1" id="invoice_sendmail" checked="checked" />
8010 daniel 99
                    <label for="invoice_sendmail"><?php echo __('E-Mail an Kunden senden', 'wpsg'); ?></label>
8456 daniel 100
                    <input type="email" name="wpsg_rechnungen_email" value="<?php
101
 
102
						$mail = $oCustomer->getEMailEInvoice();
103
						if ($mail === null) $mail = $oCustomer->getEMail();
104
 
105
						echo $mail;
106
 
107
					?>" />
8010 daniel 108
 
8081 karl 109
                    <input type="checkbox" name="wpsg_rechnungen_faelligkeit" value="1" id="invoice_faelligkeit" checked="checked" />
8010 daniel 110
                    <label for="invoice_faelligkeit"><?php echo __('Fälligkeit anzeigen', 'wpsg'); ?></label>
8078 karl 111
                    <input type="date" name="wpsg_rechnungen_faelligkeitsdatum" value="<?php echo date('Y-m-d', strtotime('+'.intval($this->get_option("wpsg_rechnungen_faelligkeit")).' day')); ?>" />
8010 daniel 112
 
8077 karl 113
                    <input type="checkbox" name="wpsg_rechnungen_status" value="1" id="invoice_state" checked="checked" />
8010 daniel 114
                    <label for="invoice_state"><?php echo __('Neuer Status', 'wpsg'); ?></label>
115
                    <select name="wpsg_rechnungen_status_neu">
116
                        <?php foreach ($this->arStatus as $status_key => $status_label) { ?>
8081 karl 117
                            <option value="<?php echo $status_key; ?>" <?php echo ((intval($status_key) === 110)?'selected="selected"':''); ?>><?php echo $status_label; ?></option>
8010 daniel 118
                        <?php } ?>
119
                    </select>
120
 
121
                    <input type="checkbox" name="wpsg_rechnungen_shippay" value="1" id="invoice_shippay" <?php
122
 
123
                        if (sizeof($arInvoiceLabel) <= 0) echo ' checked="checked" ';
8007 daniel 124
 
8010 daniel 125
                    ?> />
126
                    <label style="grid-column:2 / span 2;" for="invoice_shippay"><?php
8007 daniel 127
 
8076 karl 128
                        echo __('Versand-/Zahlungskosten berechnen', 'wpsg');
8010 daniel 129
 
130
                        if (sizeof($arInvoiceLabel) > 0) {
131
 
132
                            echo wpsg_translate(__(' (Enthalten in #1#)', 'wpsg'), implode(', ', $arInvoiceLabel));
133
 
8007 daniel 134
                        }
135
 
8010 daniel 136
                    ?></label>
8007 daniel 137
 
8077 karl 138
                    <input type="checkbox" name="wpsg_rechnungen_discount_voucher_coupon" value="1" id="wpsg_rechnungen_discount_voucher_coupon" checked="checked" />
8076 karl 139
                    <label style="grid-column:2 / span 2;" for="wpsg_rechnungen_discount_voucher_coupon"><?php echo __('Rabatt, Gutschein, Wertgutschein berechnen wenn vorhanden', 'wpsg'); ?></label>
8061 daniel 140
 
8010 daniel 141
                    <input type="checkbox" name="wpsg_rechnungen_url" value="1" id="invoice_url" />
142
                    <label  for="invoice_url" style="grid-column: 2 / span 2;"><?php echo __('URL Benachrichtigung', 'wpsg'); ?></label>
143
 
144
                    <span></span>
145
                    <label for="invoice_date"><?php echo __('Rechnungsdatum', 'wpsg') ;?></label>
146
                    <input type="date" value="<?php echo date('Y-m-d'); ?>" name="wpsg_rechnungen_datum" id="invoice_date" />
147
 
148
                    <span></span>
149
                    <label for="invoice_foottext_select"><?php echo __('Fußtext', 'wpsg'); ?></label>
150
 
151
                    <?php if (sizeof($wpsg_rechnungen_footer) > 0) { ?>
152
                    <select id="invoice_foottext_select">
153
                        <?php foreach ($wpsg_rechnungen_footer as $k => $v) { ?>
154
                        <option value="<?php echo wpsg_hspc($v[1]); ?>" <?php echo ((intval($default) === intval($k))?'selected="selected"':''); ?>><?php echo wpsg_hspc($v[0]); ?></option>
155
                        <?php } ?>
156
                    </select>
157
                    <?php } else { ?>
158
                    <span></span>
159
                    <?php } ?>
160
 
161
                    <span></span>
162
                    <input type="text" name="wpsg_rechnungen_fusstext" id="wpsg_rechnungen_fusstext" value="" style="grid-column: 2 / span 2;" />
163
 
164
                    <span style="grid-column:1 / span 3;"></span>
165
 
166
                    <span style="display:flex; justify-content:flex-end; gap:0.5rem; grid-column:1/span 3;">
8007 daniel 167
 
8010 daniel 168
                        <input class="button" style="" id="invoice_wpsg_rechnungen_preview" name="wpsg_rechnungen_preview" type="submit" value="Vorschau">
8057 daniel 169
                        <input class="button" style="" id="invoice_wpsg_rechnungen_submit" onclick="" name="wpsg_rechnungen_write" type="submit" value="Rechnung schreiben">
8007 daniel 170
 
8010 daniel 171
                    </span>
8007 daniel 172
 
8010 daniel 173
                    <script>
174
 
175
                        let el_invoice_foottext_select = document.getElementById('invoice_foottext_select');
176
                        let el_invoice_form = document.getElementById('invoice_form');
177
 
178
                        if (el_invoice_foottext_select) {
179
 
180
                            el_invoice_foottext_select.addEventListener('change', (event) => {
181
 
182
                                document.getElementById('wpsg_rechnungen_fusstext').value = event.target.value;
183
 
184
                            });
185
 
186
                            el_invoice_foottext_select.dispatchEvent(new Event('change'));
187
 
188
                        };
189
 
190
                        let el_invoice_wpsg_rechnungen_preview = document.getElementById('invoice_wpsg_rechnungen_preview');
8057 daniel 191
                        let el_invoice_wpsg_rechnungen_submit = document.getElementById('invoice_wpsg_rechnungen_submit');
8390 daniel 192
 
193
						let submit = false;
194
 
8057 daniel 195
						function check_invoice_amount(event) {
8390 daniel 196
 
197
							if (submit === true) return;
198
 
199
							submit = true;
200
 
8057 daniel 201
							let ok = false;
202
 
8063 daniel 203
							for (let el_checkbox of document.getElementsByClassName('wpsg_check_amount_invoice')) {
8057 daniel 204
 
205
								if (el_checkbox.checked) {
8063 daniel 206
 
8057 daniel 207
									if (parseInt(el_checkbox.nextElementSibling.value) > 0) {
208
 
209
										ok = true; break;
210
 
211
                                    }
212
 
213
                                }
214
 
215
                            }
216
 
217
							if (ok) {
8390 daniel 218
 
8057 daniel 219
								if (event.target.getAttribute("id") === 'invoice_wpsg_rechnungen_submit') {
220
 
8214 daniel 221
                                    window.setTimeout(function() { location.href = '<?php
222
 
8267 karl 223
                                        echo wpsg_admin_url('Order', 'view', ['edit_id' => $oOrder->getId()], [], true);
8057 daniel 224
 
225
                                    ?>'; }, 1000);
226
 
227
								}
228
 
229
							} else {
230
 
8390 daniel 231
								submit = false;
232
 
8057 daniel 233
								alert('<?php echo __('Bitte mindestens ein Produkt auswählen!', 'wpsg'); ?>');
234
 
235
								event.stopPropagation();
236
							    event.preventDefault();
237
 
238
                            }
239
 
240
                        }
241
 
242
						el_invoice_wpsg_rechnungen_preview.addEventListener('click', check_invoice_amount);
243
						el_invoice_wpsg_rechnungen_submit.addEventListener('click', check_invoice_amount);
244
 
8010 daniel 245
                    </script>
246
 
247
                </form>
8007 daniel 248
 
8010 daniel 249
            </div>
250
        <?php } ?>
251
 
252
        <?php if ($bCanStorno) { ?>
253
            <div role="tabpanel" class="tabcontent bg_storno" id="tabcontent2">
8007 daniel 254
 
8010 daniel 255
                <form method="post" id="storno_form" target="_blank" action="<?php
256
 
257
                    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';
258
 
259
                ?>" class="grid">
260
 
261
                    <?php \wp_nonce_field('wpsg-mod_invoice-order_ajax-storno-'.$this->view['data']['id']);
262
 
263
                        $arInvoiceLabel = [];
264
 
265
                        foreach ($arInvoice as $oInvoice) {
266
 
267
                            if ($oInvoice->isStorno() && $oInvoice->getMeta('include_shipping', false, '0') === '1') {
268
 
269
                                $arInvoiceLabel[] = $oInvoice->getNr(true);
8007 daniel 270
 
8010 daniel 271
                            }
272
 
273
                        }
8007 daniel 274
 
8010 daniel 275
                    ?>
8007 daniel 276
 
8010 daniel 277
                    <!-- Gutschrift -->
8007 daniel 278
 
8077 karl 279
                    <input type="checkbox" name="storno_send" id="storno_send" value="1" />
8010 daniel 280
                    <label for="storno_send"><?php echo __('E-Mail an Kunden senden', 'wpsg'); ?></label>
8456 daniel 281
                    <input type="email" name="storno_mail" value="<?php
282
 
283
						$mail = $oCustomer->getEMailEInvoice();
284
						if ($mail === null) $mail = $oCustomer->getEMail();
285
 
286
						echo $mail;
287
 
288
					?>" />
8007 daniel 289
 
8010 daniel 290
                    <input type="checkbox" id="storno_shippay" name="storno_shippay" value="1" id="invoice_shippay" <?php
291
 
292
                        if (sizeof($arInvoiceLabel) <= 0) echo ' checked="checked" ';
293
 
294
                    ?> />
295
                    <label style="grid-column:2 / span 2;" for="storno_shippay"><?php
296
 
297
                        echo __('Versand-/Zahlungskosten stornieren', 'wpsg');
298
 
299
                        if (sizeof($arInvoiceLabel) > 0) {
300
 
301
                            echo wpsg_translate(__(' (Enthalten in #1#)', 'wpsg'), implode(', ', $arInvoiceLabel));
302
 
303
                        }
304
 
305
                    ?></label>
8007 daniel 306
 
8010 daniel 307
                    <input type="checkbox" name="storno_state" value="1" id="storno_state" checked="checked" />
308
                    <label for="storno_state"><?php echo __('Neuer Status', 'wpsg'); ?></label>
309
                    <select name="storno_state_new">
310
                        <?php foreach ($this->arStatus as $status_key => $status_label) { ?>
311
                        <option value="<?php echo $status_key; ?>"><?php echo $status_label; ?></option>
312
                        <?php } ?>
313
                    </select>
8007 daniel 314
 
8077 karl 315
                    <input type="checkbox" name="wpsg_rechnungen_discount_voucher_coupon" value="1" id="wpsg_rechnungen_storno_discount_voucher_coupon" checked="checked" />
8076 karl 316
                    <label style="grid-column:2 / span 2;" for="wpsg_rechnungen_storno_discount_voucher_coupon"><?php echo __('Rabatt, Gutschein, Wertgutschein berechnen wenn vorhanden', 'wpsg'); ?></label>
8061 daniel 317
 
8010 daniel 318
                    <input type="checkbox" name="storno_fee_set" id="storno_fee_set" value="1" id="storno_fee_set" />
319
                    <label for="storno_fee_set"><?php echo __('Stornierungsgebühr in % oder EUR', 'wpsg'); ?></label>
320
                    <input type="text" value="" name="storno_fee_value" />
8007 daniel 321
 
8010 daniel 322
                    <span style="grid-column:1 / span 3;"></span>
8007 daniel 323
 
8010 daniel 324
                    <span style="display:flex; justify-content:flex-end; gap:0.5rem; grid-column:1/span 3;">
325
 
326
                        <input class="button" style="" id="invoice_wpsg_storno_preview" name="wpsg_storno_preview" type="submit" value="Vorschau">
8057 daniel 327
                        <input class="button" style="" id="invoice_wpsg_storno_submit" onclick="" name="wpsg_storno_write" type="submit" value="Rechnungskorrektur schreiben">
8010 daniel 328
 
329
                    </span>
8007 daniel 330
 
8010 daniel 331
                    <script>
332
 
333
                        let el_storno_form = document.getElementById('storno_form');
334
 
335
                        let el_invoice_wpsg_storno_preview = document.getElementById('invoice_wpsg_storno_preview');
336
                        let el_invoice_wpsg_storno_submit = document.getElementById('invoice_wpsg_storno_submit');
8057 daniel 337
 
338
						function check_invoice_amount(event) {
339
 
340
							let ok = false;
341
 
8063 daniel 342
							for (let el_checkbox of document.getElementsByClassName('wpsg_check_amount_storno')) {
8057 daniel 343
 
344
								if (el_checkbox.checked) {
345
 
346
									if (parseInt(el_checkbox.nextElementSibling.value) > 0) {
347
 
348
										ok = true; break;
349
 
350
                                    }
351
 
352
                                }
353
 
354
                            }
355
 
356
							if (ok) {
357
 
358
								if (event.target.getAttribute("id") === 'invoice_wpsg_storno_submit') {
359
 
360
                                    window.setTimeout(function() { location.href = '<?php
361
 
8267 karl 362
                                        echo wpsg_admin_url('Order', 'view', ['edit_id' => $oOrder->getId()], [], true);
8057 daniel 363
 
364
                                    ?>'; }, 1000);
365
 
366
								}
367
 
368
							} else {
369
 
370
								alert('<?php echo __('Bitte mindestens ein Produkt auswählen!', 'wpsg'); ?>');
371
 
372
								event.stopPropagation();
373
							    event.preventDefault();
374
 
375
                            }
376
 
377
                        }
378
 
379
						el_invoice_wpsg_storno_preview.addEventListener('click', check_invoice_amount);
380
						el_invoice_wpsg_storno_submit.addEventListener('click', check_invoice_amount);
381
 
8010 daniel 382
                    </script>
383
 
384
                </form>
8007 daniel 385
 
8010 daniel 386
            </div>
387
        <?php } ?>
8007 daniel 388
 
389
    </div>
390
 
391
</div>
392
 
393
<style>
394
 
395
    #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; }
396
    #wpsg_mod_invoice_tabs .grid input[type="checkbox"] { margin-top:0; }
397
    #wpsg_mod_invoice_tabs .grid label { font-weight:normal; margin-bottom:0; }
398
 
399
    .nav-tabs > li.active > a.bg_invoice,
400
    .nav-tabs > li.active > a.bg_invoice:focus,
401
    label.bg_invoice,
402
    .link_invoice.bg_invoice,
403
    .tabcontent.bg_invoice { background-color:lightgreen; color:black; }
404
 
405
    .nav-tabs > li.active > a.bg_storno,
406
    .nav-tabs > li.active > a.bg_storno:focus,
407
    label.bg_storno,
408
    .link_invoice.bg_storno,
409
    .tabcontent.bg_storno { background-color:lightpink; color:black; }
410
 
411
    .link_invoice { transform:translateX(-5px); padding:2px 5px; font-siz:12px; text-decoration:underline; }
8010 daniel 412
    label[for="invoice_shippay"] .link_invoice,
413
    label[for="storno_shippay"] .link_invoice { padding:0; }
414
 
8057 daniel 415
    .wpsg_mod_rechnungen_row { display:block; width:100%; }
416
    .wpsg_mod_rechnungen_row > div { padding:5px; }
8010 daniel 417
    .wpsg_mod_rechnungen_row .invoice_wrap:not(:only-child) { margin-top:0.5rem; }
418
    .wpsg_mod_rechnungen_row .invoice_wrap > a:first-child { padding-left:0; }
8007 daniel 419
 
420
</style>
421
 
422
<script>
423
 
424
    jQuery('#wpsg_mod_invoice_tabs').wpsg_tab( {
8010 daniel 425
        aktTab: <?php echo $act; ?>
8007 daniel 426
	} );
427
 
428
</script>