Subversion Repositories wpShopGermany4

Rev

Rev 8214 | 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');
8010 daniel 185
 
8057 daniel 186
						function check_invoice_amount(event) {
8063 daniel 187
 
8057 daniel 188
							let ok = false;
189
 
8063 daniel 190
							for (let el_checkbox of document.getElementsByClassName('wpsg_check_amount_invoice')) {
8057 daniel 191
 
192
								if (el_checkbox.checked) {
8063 daniel 193
 
8057 daniel 194
									if (parseInt(el_checkbox.nextElementSibling.value) > 0) {
195
 
196
										ok = true; break;
197
 
198
                                    }
199
 
200
                                }
201
 
202
                            }
203
 
204
							if (ok) {
8214 daniel 205
 
8057 daniel 206
								if (event.target.getAttribute("id") === 'invoice_wpsg_rechnungen_submit') {
207
 
8214 daniel 208
                                    window.setTimeout(function() { location.href = '<?php
209
 
8267 karl 210
                                        echo wpsg_admin_url('Order', 'view', ['edit_id' => $oOrder->getId()], [], true);
8057 daniel 211
 
212
                                    ?>'; }, 1000);
213
 
214
								}
215
 
216
							} else {
217
 
218
								alert('<?php echo __('Bitte mindestens ein Produkt auswählen!', 'wpsg'); ?>');
219
 
220
								event.stopPropagation();
221
							    event.preventDefault();
222
 
223
                            }
224
 
225
                        }
226
 
227
						el_invoice_wpsg_rechnungen_preview.addEventListener('click', check_invoice_amount);
228
						el_invoice_wpsg_rechnungen_submit.addEventListener('click', check_invoice_amount);
229
 
8010 daniel 230
                    </script>
231
 
232
                </form>
8007 daniel 233
 
8010 daniel 234
            </div>
235
        <?php } ?>
236
 
237
        <?php if ($bCanStorno) { ?>
238
            <div role="tabpanel" class="tabcontent bg_storno" id="tabcontent2">
8007 daniel 239
 
8010 daniel 240
                <form method="post" id="storno_form" target="_blank" action="<?php
241
 
242
                    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';
243
 
244
                ?>" class="grid">
245
 
246
                    <?php \wp_nonce_field('wpsg-mod_invoice-order_ajax-storno-'.$this->view['data']['id']);
247
 
248
                        $arInvoiceLabel = [];
249
 
250
                        foreach ($arInvoice as $oInvoice) {
251
 
252
                            if ($oInvoice->isStorno() && $oInvoice->getMeta('include_shipping', false, '0') === '1') {
253
 
254
                                $arInvoiceLabel[] = $oInvoice->getNr(true);
8007 daniel 255
 
8010 daniel 256
                            }
257
 
258
                        }
8007 daniel 259
 
8010 daniel 260
                    ?>
8007 daniel 261
 
8010 daniel 262
                    <!-- Gutschrift -->
8007 daniel 263
 
8077 karl 264
                    <input type="checkbox" name="storno_send" id="storno_send" value="1" />
8010 daniel 265
                    <label for="storno_send"><?php echo __('E-Mail an Kunden senden', 'wpsg'); ?></label>
266
                    <input type="email" name="storno_mail" value="<?php echo $oCustomer->getEMail(); ?>" />
8007 daniel 267
 
8010 daniel 268
                    <input type="checkbox" id="storno_shippay" name="storno_shippay" value="1" id="invoice_shippay" <?php
269
 
270
                        if (sizeof($arInvoiceLabel) <= 0) echo ' checked="checked" ';
271
 
272
                    ?> />
273
                    <label style="grid-column:2 / span 2;" for="storno_shippay"><?php
274
 
275
                        echo __('Versand-/Zahlungskosten stornieren', 'wpsg');
276
 
277
                        if (sizeof($arInvoiceLabel) > 0) {
278
 
279
                            echo wpsg_translate(__(' (Enthalten in #1#)', 'wpsg'), implode(', ', $arInvoiceLabel));
280
 
281
                        }
282
 
283
                    ?></label>
8007 daniel 284
 
8010 daniel 285
                    <input type="checkbox" name="storno_state" value="1" id="storno_state" checked="checked" />
286
                    <label for="storno_state"><?php echo __('Neuer Status', 'wpsg'); ?></label>
287
                    <select name="storno_state_new">
288
                        <?php foreach ($this->arStatus as $status_key => $status_label) { ?>
289
                        <option value="<?php echo $status_key; ?>"><?php echo $status_label; ?></option>
290
                        <?php } ?>
291
                    </select>
8007 daniel 292
 
8077 karl 293
                    <input type="checkbox" name="wpsg_rechnungen_discount_voucher_coupon" value="1" id="wpsg_rechnungen_storno_discount_voucher_coupon" checked="checked" />
8076 karl 294
                    <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 295
 
8010 daniel 296
                    <input type="checkbox" name="storno_fee_set" id="storno_fee_set" value="1" id="storno_fee_set" />
297
                    <label for="storno_fee_set"><?php echo __('Stornierungsgebühr in % oder EUR', 'wpsg'); ?></label>
298
                    <input type="text" value="" name="storno_fee_value" />
8007 daniel 299
 
8010 daniel 300
                    <span style="grid-column:1 / span 3;"></span>
8007 daniel 301
 
8010 daniel 302
                    <span style="display:flex; justify-content:flex-end; gap:0.5rem; grid-column:1/span 3;">
303
 
304
                        <input class="button" style="" id="invoice_wpsg_storno_preview" name="wpsg_storno_preview" type="submit" value="Vorschau">
8057 daniel 305
                        <input class="button" style="" id="invoice_wpsg_storno_submit" onclick="" name="wpsg_storno_write" type="submit" value="Rechnungskorrektur schreiben">
8010 daniel 306
 
307
                    </span>
8007 daniel 308
 
8010 daniel 309
                    <script>
310
 
311
                        let el_storno_form = document.getElementById('storno_form');
312
 
313
                        let el_invoice_wpsg_storno_preview = document.getElementById('invoice_wpsg_storno_preview');
314
                        let el_invoice_wpsg_storno_submit = document.getElementById('invoice_wpsg_storno_submit');
8057 daniel 315
 
316
						function check_invoice_amount(event) {
317
 
318
							let ok = false;
319
 
8063 daniel 320
							for (let el_checkbox of document.getElementsByClassName('wpsg_check_amount_storno')) {
8057 daniel 321
 
322
								if (el_checkbox.checked) {
323
 
324
									if (parseInt(el_checkbox.nextElementSibling.value) > 0) {
325
 
326
										ok = true; break;
327
 
328
                                    }
329
 
330
                                }
331
 
332
                            }
333
 
334
							if (ok) {
335
 
336
								if (event.target.getAttribute("id") === 'invoice_wpsg_storno_submit') {
337
 
338
                                    window.setTimeout(function() { location.href = '<?php
339
 
8267 karl 340
                                        echo wpsg_admin_url('Order', 'view', ['edit_id' => $oOrder->getId()], [], true);
8057 daniel 341
 
342
                                    ?>'; }, 1000);
343
 
344
								}
345
 
346
							} else {
347
 
348
								alert('<?php echo __('Bitte mindestens ein Produkt auswählen!', 'wpsg'); ?>');
349
 
350
								event.stopPropagation();
351
							    event.preventDefault();
352
 
353
                            }
354
 
355
                        }
356
 
357
						el_invoice_wpsg_storno_preview.addEventListener('click', check_invoice_amount);
358
						el_invoice_wpsg_storno_submit.addEventListener('click', check_invoice_amount);
359
 
8010 daniel 360
                    </script>
361
 
362
                </form>
8007 daniel 363
 
8010 daniel 364
            </div>
365
        <?php } ?>
8007 daniel 366
 
367
    </div>
368
 
369
</div>
370
 
371
<style>
372
 
373
    #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; }
374
    #wpsg_mod_invoice_tabs .grid input[type="checkbox"] { margin-top:0; }
375
    #wpsg_mod_invoice_tabs .grid label { font-weight:normal; margin-bottom:0; }
376
 
377
    .nav-tabs > li.active > a.bg_invoice,
378
    .nav-tabs > li.active > a.bg_invoice:focus,
379
    label.bg_invoice,
380
    .link_invoice.bg_invoice,
381
    .tabcontent.bg_invoice { background-color:lightgreen; color:black; }
382
 
383
    .nav-tabs > li.active > a.bg_storno,
384
    .nav-tabs > li.active > a.bg_storno:focus,
385
    label.bg_storno,
386
    .link_invoice.bg_storno,
387
    .tabcontent.bg_storno { background-color:lightpink; color:black; }
388
 
389
    .link_invoice { transform:translateX(-5px); padding:2px 5px; font-siz:12px; text-decoration:underline; }
8010 daniel 390
    label[for="invoice_shippay"] .link_invoice,
391
    label[for="storno_shippay"] .link_invoice { padding:0; }
392
 
8057 daniel 393
    .wpsg_mod_rechnungen_row { display:block; width:100%; }
394
    .wpsg_mod_rechnungen_row > div { padding:5px; }
8010 daniel 395
    .wpsg_mod_rechnungen_row .invoice_wrap:not(:only-child) { margin-top:0.5rem; }
396
    .wpsg_mod_rechnungen_row .invoice_wrap > a:first-child { padding-left:0; }
8007 daniel 397
 
398
</style>
399
 
400
<script>
401
 
402
    jQuery('#wpsg_mod_invoice_tabs').wpsg_tab( {
8010 daniel 403
        aktTab: <?php echo $act; ?>
8007 daniel 404
	} );
405
 
406
</script>