Subversion Repositories wpShopGermany4

Rev

Rev 8267 | Go to most recent revision | 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>
100
                    <input type="email" name="wpsg_rechnungen_email" value="<?php echo $oCustomer->getEMail(); ?>" />
101
 
8081 karl 102
                    <input type="checkbox" name="wpsg_rechnungen_faelligkeit" value="1" id="invoice_faelligkeit" checked="checked" />
8010 daniel 103
                    <label for="invoice_faelligkeit"><?php echo __('Fälligkeit anzeigen', 'wpsg'); ?></label>
8078 karl 104
                    <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 105
 
8077 karl 106
                    <input type="checkbox" name="wpsg_rechnungen_status" value="1" id="invoice_state" checked="checked" />
8010 daniel 107
                    <label for="invoice_state"><?php echo __('Neuer Status', 'wpsg'); ?></label>
108
                    <select name="wpsg_rechnungen_status_neu">
109
                        <?php foreach ($this->arStatus as $status_key => $status_label) { ?>
8081 karl 110
                            <option value="<?php echo $status_key; ?>" <?php echo ((intval($status_key) === 110)?'selected="selected"':''); ?>><?php echo $status_label; ?></option>
8010 daniel 111
                        <?php } ?>
112
                    </select>
113
 
114
                    <input type="checkbox" name="wpsg_rechnungen_shippay" value="1" id="invoice_shippay" <?php
115
 
116
                        if (sizeof($arInvoiceLabel) <= 0) echo ' checked="checked" ';
8007 daniel 117
 
8010 daniel 118
                    ?> />
119
                    <label style="grid-column:2 / span 2;" for="invoice_shippay"><?php
8007 daniel 120
 
8076 karl 121
                        echo __('Versand-/Zahlungskosten berechnen', 'wpsg');
8010 daniel 122
 
123
                        if (sizeof($arInvoiceLabel) > 0) {
124
 
125
                            echo wpsg_translate(__(' (Enthalten in #1#)', 'wpsg'), implode(', ', $arInvoiceLabel));
126
 
8007 daniel 127
                        }
128
 
8010 daniel 129
                    ?></label>
8007 daniel 130
 
8077 karl 131
                    <input type="checkbox" name="wpsg_rechnungen_discount_voucher_coupon" value="1" id="wpsg_rechnungen_discount_voucher_coupon" checked="checked" />
8076 karl 132
                    <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 133
 
8010 daniel 134
                    <input type="checkbox" name="wpsg_rechnungen_url" value="1" id="invoice_url" />
135
                    <label  for="invoice_url" style="grid-column: 2 / span 2;"><?php echo __('URL Benachrichtigung', 'wpsg'); ?></label>
136
 
137
                    <span></span>
138
                    <label for="invoice_date"><?php echo __('Rechnungsdatum', 'wpsg') ;?></label>
139
                    <input type="date" value="<?php echo date('Y-m-d'); ?>" name="wpsg_rechnungen_datum" id="invoice_date" />
140
 
141
                    <span></span>
142
                    <label for="invoice_foottext_select"><?php echo __('Fußtext', 'wpsg'); ?></label>
143
 
144
                    <?php if (sizeof($wpsg_rechnungen_footer) > 0) { ?>
145
                    <select id="invoice_foottext_select">
146
                        <?php foreach ($wpsg_rechnungen_footer as $k => $v) { ?>
147
                        <option value="<?php echo wpsg_hspc($v[1]); ?>" <?php echo ((intval($default) === intval($k))?'selected="selected"':''); ?>><?php echo wpsg_hspc($v[0]); ?></option>
148
                        <?php } ?>
149
                    </select>
150
                    <?php } else { ?>
151
                    <span></span>
152
                    <?php } ?>
153
 
154
                    <span></span>
155
                    <input type="text" name="wpsg_rechnungen_fusstext" id="wpsg_rechnungen_fusstext" value="" style="grid-column: 2 / span 2;" />
156
 
157
                    <span style="grid-column:1 / span 3;"></span>
158
 
159
                    <span style="display:flex; justify-content:flex-end; gap:0.5rem; grid-column:1/span 3;">
8007 daniel 160
 
8010 daniel 161
                        <input class="button" style="" id="invoice_wpsg_rechnungen_preview" name="wpsg_rechnungen_preview" type="submit" value="Vorschau">
8057 daniel 162
                        <input class="button" style="" id="invoice_wpsg_rechnungen_submit" onclick="" name="wpsg_rechnungen_write" type="submit" value="Rechnung schreiben">
8007 daniel 163
 
8010 daniel 164
                    </span>
8007 daniel 165
 
8010 daniel 166
                    <script>
167
 
168
                        let el_invoice_foottext_select = document.getElementById('invoice_foottext_select');
169
                        let el_invoice_form = document.getElementById('invoice_form');
170
 
171
                        if (el_invoice_foottext_select) {
172
 
173
                            el_invoice_foottext_select.addEventListener('change', (event) => {
174
 
175
                                document.getElementById('wpsg_rechnungen_fusstext').value = event.target.value;
176
 
177
                            });
178
 
179
                            el_invoice_foottext_select.dispatchEvent(new Event('change'));
180
 
181
                        };
182
 
183
                        let el_invoice_wpsg_rechnungen_preview = document.getElementById('invoice_wpsg_rechnungen_preview');
8057 daniel 184
                        let el_invoice_wpsg_rechnungen_submit = document.getElementById('invoice_wpsg_rechnungen_submit');
8390 daniel 185
 
186
						let submit = false;
187
 
8057 daniel 188
						function check_invoice_amount(event) {
8390 daniel 189
 
190
							if (submit === true) return;
191
 
192
							submit = true;
193
 
8057 daniel 194
							let ok = false;
195
 
8063 daniel 196
							for (let el_checkbox of document.getElementsByClassName('wpsg_check_amount_invoice')) {
8057 daniel 197
 
198
								if (el_checkbox.checked) {
8063 daniel 199
 
8057 daniel 200
									if (parseInt(el_checkbox.nextElementSibling.value) > 0) {
201
 
202
										ok = true; break;
203
 
204
                                    }
205
 
206
                                }
207
 
208
                            }
209
 
210
							if (ok) {
8390 daniel 211
 
8057 daniel 212
								if (event.target.getAttribute("id") === 'invoice_wpsg_rechnungen_submit') {
213
 
8214 daniel 214
                                    window.setTimeout(function() { location.href = '<?php
215
 
8267 karl 216
                                        echo wpsg_admin_url('Order', 'view', ['edit_id' => $oOrder->getId()], [], true);
8057 daniel 217
 
218
                                    ?>'; }, 1000);
219
 
220
								}
221
 
222
							} else {
223
 
8390 daniel 224
								submit = false;
225
 
8057 daniel 226
								alert('<?php echo __('Bitte mindestens ein Produkt auswählen!', 'wpsg'); ?>');
227
 
228
								event.stopPropagation();
229
							    event.preventDefault();
230
 
231
                            }
232
 
233
                        }
234
 
235
						el_invoice_wpsg_rechnungen_preview.addEventListener('click', check_invoice_amount);
236
						el_invoice_wpsg_rechnungen_submit.addEventListener('click', check_invoice_amount);
237
 
8010 daniel 238
                    </script>
239
 
240
                </form>
8007 daniel 241
 
8010 daniel 242
            </div>
243
        <?php } ?>
244
 
245
        <?php if ($bCanStorno) { ?>
246
            <div role="tabpanel" class="tabcontent bg_storno" id="tabcontent2">
8007 daniel 247
 
8010 daniel 248
                <form method="post" id="storno_form" target="_blank" action="<?php
249
 
250
                    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';
251
 
252
                ?>" class="grid">
253
 
254
                    <?php \wp_nonce_field('wpsg-mod_invoice-order_ajax-storno-'.$this->view['data']['id']);
255
 
256
                        $arInvoiceLabel = [];
257
 
258
                        foreach ($arInvoice as $oInvoice) {
259
 
260
                            if ($oInvoice->isStorno() && $oInvoice->getMeta('include_shipping', false, '0') === '1') {
261
 
262
                                $arInvoiceLabel[] = $oInvoice->getNr(true);
8007 daniel 263
 
8010 daniel 264
                            }
265
 
266
                        }
8007 daniel 267
 
8010 daniel 268
                    ?>
8007 daniel 269
 
8010 daniel 270
                    <!-- Gutschrift -->
8007 daniel 271
 
8077 karl 272
                    <input type="checkbox" name="storno_send" id="storno_send" value="1" />
8010 daniel 273
                    <label for="storno_send"><?php echo __('E-Mail an Kunden senden', 'wpsg'); ?></label>
274
                    <input type="email" name="storno_mail" value="<?php echo $oCustomer->getEMail(); ?>" />
8007 daniel 275
 
8010 daniel 276
                    <input type="checkbox" id="storno_shippay" name="storno_shippay" value="1" id="invoice_shippay" <?php
277
 
278
                        if (sizeof($arInvoiceLabel) <= 0) echo ' checked="checked" ';
279
 
280
                    ?> />
281
                    <label style="grid-column:2 / span 2;" for="storno_shippay"><?php
282
 
283
                        echo __('Versand-/Zahlungskosten stornieren', 'wpsg');
284
 
285
                        if (sizeof($arInvoiceLabel) > 0) {
286
 
287
                            echo wpsg_translate(__(' (Enthalten in #1#)', 'wpsg'), implode(', ', $arInvoiceLabel));
288
 
289
                        }
290
 
291
                    ?></label>
8007 daniel 292
 
8010 daniel 293
                    <input type="checkbox" name="storno_state" value="1" id="storno_state" checked="checked" />
294
                    <label for="storno_state"><?php echo __('Neuer Status', 'wpsg'); ?></label>
295
                    <select name="storno_state_new">
296
                        <?php foreach ($this->arStatus as $status_key => $status_label) { ?>
297
                        <option value="<?php echo $status_key; ?>"><?php echo $status_label; ?></option>
298
                        <?php } ?>
299
                    </select>
8007 daniel 300
 
8077 karl 301
                    <input type="checkbox" name="wpsg_rechnungen_discount_voucher_coupon" value="1" id="wpsg_rechnungen_storno_discount_voucher_coupon" checked="checked" />
8076 karl 302
                    <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 303
 
8010 daniel 304
                    <input type="checkbox" name="storno_fee_set" id="storno_fee_set" value="1" id="storno_fee_set" />
305
                    <label for="storno_fee_set"><?php echo __('Stornierungsgebühr in % oder EUR', 'wpsg'); ?></label>
306
                    <input type="text" value="" name="storno_fee_value" />
8007 daniel 307
 
8010 daniel 308
                    <span style="grid-column:1 / span 3;"></span>
8007 daniel 309
 
8010 daniel 310
                    <span style="display:flex; justify-content:flex-end; gap:0.5rem; grid-column:1/span 3;">
311
 
312
                        <input class="button" style="" id="invoice_wpsg_storno_preview" name="wpsg_storno_preview" type="submit" value="Vorschau">
8057 daniel 313
                        <input class="button" style="" id="invoice_wpsg_storno_submit" onclick="" name="wpsg_storno_write" type="submit" value="Rechnungskorrektur schreiben">
8010 daniel 314
 
315
                    </span>
8007 daniel 316
 
8010 daniel 317
                    <script>
318
 
319
                        let el_storno_form = document.getElementById('storno_form');
320
 
321
                        let el_invoice_wpsg_storno_preview = document.getElementById('invoice_wpsg_storno_preview');
322
                        let el_invoice_wpsg_storno_submit = document.getElementById('invoice_wpsg_storno_submit');
8057 daniel 323
 
324
						function check_invoice_amount(event) {
325
 
326
							let ok = false;
327
 
8063 daniel 328
							for (let el_checkbox of document.getElementsByClassName('wpsg_check_amount_storno')) {
8057 daniel 329
 
330
								if (el_checkbox.checked) {
331
 
332
									if (parseInt(el_checkbox.nextElementSibling.value) > 0) {
333
 
334
										ok = true; break;
335
 
336
                                    }
337
 
338
                                }
339
 
340
                            }
341
 
342
							if (ok) {
343
 
344
								if (event.target.getAttribute("id") === 'invoice_wpsg_storno_submit') {
345
 
346
                                    window.setTimeout(function() { location.href = '<?php
347
 
8267 karl 348
                                        echo wpsg_admin_url('Order', 'view', ['edit_id' => $oOrder->getId()], [], true);
8057 daniel 349
 
350
                                    ?>'; }, 1000);
351
 
352
								}
353
 
354
							} else {
355
 
356
								alert('<?php echo __('Bitte mindestens ein Produkt auswählen!', 'wpsg'); ?>');
357
 
358
								event.stopPropagation();
359
							    event.preventDefault();
360
 
361
                            }
362
 
363
                        }
364
 
365
						el_invoice_wpsg_storno_preview.addEventListener('click', check_invoice_amount);
366
						el_invoice_wpsg_storno_submit.addEventListener('click', check_invoice_amount);
367
 
8010 daniel 368
                    </script>
369
 
370
                </form>
8007 daniel 371
 
8010 daniel 372
            </div>
373
        <?php } ?>
8007 daniel 374
 
375
    </div>
376
 
377
</div>
378
 
379
<style>
380
 
381
    #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; }
382
    #wpsg_mod_invoice_tabs .grid input[type="checkbox"] { margin-top:0; }
383
    #wpsg_mod_invoice_tabs .grid label { font-weight:normal; margin-bottom:0; }
384
 
385
    .nav-tabs > li.active > a.bg_invoice,
386
    .nav-tabs > li.active > a.bg_invoice:focus,
387
    label.bg_invoice,
388
    .link_invoice.bg_invoice,
389
    .tabcontent.bg_invoice { background-color:lightgreen; color:black; }
390
 
391
    .nav-tabs > li.active > a.bg_storno,
392
    .nav-tabs > li.active > a.bg_storno:focus,
393
    label.bg_storno,
394
    .link_invoice.bg_storno,
395
    .tabcontent.bg_storno { background-color:lightpink; color:black; }
396
 
397
    .link_invoice { transform:translateX(-5px); padding:2px 5px; font-siz:12px; text-decoration:underline; }
8010 daniel 398
    label[for="invoice_shippay"] .link_invoice,
399
    label[for="storno_shippay"] .link_invoice { padding:0; }
400
 
8057 daniel 401
    .wpsg_mod_rechnungen_row { display:block; width:100%; }
402
    .wpsg_mod_rechnungen_row > div { padding:5px; }
8010 daniel 403
    .wpsg_mod_rechnungen_row .invoice_wrap:not(:only-child) { margin-top:0.5rem; }
404
    .wpsg_mod_rechnungen_row .invoice_wrap > a:first-child { padding-left:0; }
8007 daniel 405
 
406
</style>
407
 
408
<script>
409
 
410
    jQuery('#wpsg_mod_invoice_tabs').wpsg_tab( {
8010 daniel 411
        aktTab: <?php echo $act; ?>
8007 daniel 412
	} );
413
 
414
</script>