-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpay.php
149 lines (149 loc) · 4.99 KB
/
pay.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
session_start();
$site_title = "Bezahlung";
include 'inc/header.inc.php';
$user = check_user();
if (!$_SESSION['cart']) {
header("Location:shop_form.php");
}
?>
<script>
function calculateChange(money_given) {
var gpreis = <?=$_SESSION['gpreis']?>;
document.getElementById('change').value = "Rückgeld: " + (money_given - gpreis) + "€";
}
$(document).ready(function () {
$('#bill').hide();
$('#cash_given').on('input', function(){
calculateChange(this.value)
});
$('#payment').on('change', function() {
if (this.value == 'credit') {
$('#cash_given').val(parseFloat(<?=$_SESSION['gpreis']?>));
calculateChange($('#cash_given').value)
}else if (this.value == 'cash') {
$('#cash_given').val("");
calculateChange($('#cash_given').value)
}else if (this.value == 'gift') {
$('#cash_given').val("");
calculateChange($('#cash_given').value)
}
});
$('#paid').change(function(){
console.log("it changed");
var c = this.checked;
switch (c) {
case true:
$('#bill').show();
break;
default:
$('#bill').hide();
}
});
$('#pay_form').submit(function(e) {
e.preventDefault();
url = "money_ajax.php?action=add_money&money=" + <?=$_SESSION['gpreis']?> + "&user=" + "<?=$_SESSION['userid']?>";
$.getJSON(url, function (data) {
console.log("[ACTION RESULT OF add_money]");
console.log(data);
if (data.success || data.error) {
var html = "";
if (data.success) {
html += '<i class="material-icons left">check</i>';
} else if (data.error) {
html += '<i class="material-icons left">error</i>';
}
html += data.message;
M.toast({html: html});
window.location.replace("print_bill.php?type=" + $("#payment option:selected").text());
}
});
});
});
</script>
<h1 class="<?=$site_color_accent_text?>">Bezahlung</h1>
<p>Links sehen sie die Übersicht an gekauften Artikeln, rechts können sie kassieren.</p>
<div class="row">
<div class="col s12 m6">
<table class="striped">
<thead>
<tr>
<th>Menge</th>
<th>Barcode</th>
<th>Artikelname</th>
<th>EPREIS</th>
<th>GPREIS</th>
</tr>
</thead>
<?php
$gpreis = 0;
foreach ($_SESSION['cart'] as $value) {
$gpreis += $value['quantity'] * $value['article']['price'];
echo "<tr>".
"<td>" .
$value['quantity'] .
"</td>" .
"<td>" .
$value['article']['barcode'] .
"</td>" .
"<td>" .
$value['article']['name'] .
"</td>" .
"<td>" .
$value['article']['price'] . "€" .
"</td>" .
"<td>" .
$value['quantity'] * $value['article']['price'] . "€" .
"</td>" .
"</tr>";
}
echo "<tr>" .
"<th colspan='4'>" .
"Gesamt:" .
"</th>" .
"<th>" .
$gpreis . "€" .
"</th>" .
"</tr>";
$_SESSION['gpreis'] = $gpreis;
?>
</table>
</div>
<div class="col s12 m6">
<form method="post" action="print_bill.php" id="pay_form">
<div class="input-field col s12">
<select name="payment" id="payment" required>
<option value="" disabled selected>Zahlungsmethode auswählen</option>
<option value="cash" data-icon="icons/payment_options/money.svg" class="left">Bargeld</option>
<option value="credit" data-icon="icons/payment_options/credit_card.svg" class="left">Kartenzahlung</option>
<option value="gift" data-icon="icons/payment_options/card_giftcard.svg" class="left">Geschenkgutschein</option>
</select>
</div>
<div class="input-field col s12">
<i class="material-icons prefix">attach_money</i>
<input id="cash_given" type="text" name="money" placeholder="Gegebenes Geld" required>
<!--<label for="cash_given">Gegebenes Geld</label>-->
</div>
<!-- Discount only in future, not now!-->
<!--<div class="input-field col s12">
<i class="material-icons prefix">stars</i>
<input id="discount" type="text" name="discount" value="0%">
<label for="discount">Rabatt für ganzen Einkauf</label>
</div>-->
<div class="input-field col s12">
<i class="material-icons prefix">settings_backup_restore</i>
<input id="change" type="text" name="discount" value="Rückgeld: " disabled>
</div>
<div class="col s12">
<label>
<input type="checkbox" name="paid" required id="paid"/>
<span>Bezahlung durchgeführt</span>
</label>
</div>
<button type="submit" class="btn waves-effect waves-light <?=$site_color?> col s12" id="bill"><i class="material-icons right">print</i>Rechnung drucken</button>
</form>
</div>
</div>
<?php
include 'inc/footer.inc.php';
?>