-
Notifications
You must be signed in to change notification settings - Fork 0
/
tilaus_info.php
230 lines (209 loc) · 8.12 KB
/
tilaus_info.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?php declare(strict_types=1);
require '_start.php'; global $db, $user, $cart;
$tilaus_id = isset( $_GET[ 'id' ] ) ? (int)$_GET[ 'id' ] : null;
if ( !$tilaus_id ) {
header( "Location:tilaushistoria.php?id={$user->id}" );
exit();
}
if ( !empty($_POST['peruuta_id']) ) {
if ( !$user->isAdmin() ) {
return;
}
// Yes, yes, voisi tehdä tehokkaammin, I know, I'm just lazy.
$kayttaja = new User( $db, (int)$_POST['user_id'] );
$ostoskori = new Ostoskori( $db, $kayttaja->yritys_id, -1 );
if ( PaymentAPI::peruutaTilausPalautaTuotteet( $db, $kayttaja, (int)$_POST['peruuta_id'], $ostoskori->id )) {
// Something something feedback
}
}
/** Tarkistetaan feedback, ja estetään formin uudelleenlähetys */
if ( !empty( $_POST ) ) { //Estetään formin uudelleenlähetyksen
header( "Location: " . $_SERVER[ 'REQUEST_URI' ] ); exit();
} else {
$feedback = isset( $_SESSION[ 'feedback' ] ) ? $_SESSION[ 'feedback' ] : "";
unset( $_SESSION[ "feedback" ] );
}
$tilaus = new Tilaus($db, $tilaus_id);
// Löytyikö tilauksen tiedot ID:llä.
if ( !$tilaus ) {
header( "Location:tilaushistoria.php" );
exit();
}
// Tarkistetaan onko tilaus sen hetkisen käyttäjän tekemä, tai onko käyttäjä admin.
// Lähetään pois, jos ei kumpaankin.
elseif ( ($tilaus->asiakas->id != $user->id) && !$user->isAdmin() ) {
header( "Location:tilaushistoria.php" );
exit();
}
$lasku_file_nimi = "lasku-". sprintf( '%05d', $tilaus->laskunro) ."-{$tilaus->asiakas->id}.pdf";
$noutolista_file_nimi = "noutolista-".sprintf('%05d',$tilaus->laskunro)."-{$tilaus->asiakas->id}.pdf";
?>
<!DOCTYPE html>
<html lang="fi">
<head>
<meta charset="UTF-8">
<title>Tilaus-info</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="./css/jsmodal-light.css">
<link rel="stylesheet" href="./css/styles.css">
<script src="./js/jsmodal-1.0d.min.js" async></script>
</head>
<body>
<?php include 'header.php'; ?>
<main class="main_body_container">
<div class="otsikko_container">
<section class="takaisin">
<?php if ( $user->isAdmin() ) : ?>
<a href="javascript:history.go(-1)" class="nappi grey">
<i class="material-icons">navigate_before</i>Takaisin</a>
<?php else : ?>
<a href="tilaushistoria.php" class="nappi grey">
<i class="material-icons">navigate_before</i>Tilaushistoriaan</a>
<?php endif; ?>
</section>
<section class="otsikko">
<h1 class="inline-block">Tilaus <?=sprintf('%04d', $tilaus->id)?> </h1>
<!-- Tilauksen tila -->
<?php if ( $tilaus->maksettu == 0 ) : ?>
<span style="color:orangered;"> Odottaa maksua. Lasku ei saatavilla. </span>
<?php if ( $user->isAdmin() ) : ?>
<button class="nappi red" id="peruuta_tilaus">Peruuta tilaus?</button>
<?php endif; ?>
<?php elseif ( $tilaus->maksettu == -1 ) : ?>
<span style="color:red;font-weight: bold">Tilaus peruttu. Maksua ei suoritettu.</span>
<?php elseif ( $tilaus->kasitelty == false ) : ?>
<span style="color:steelblue;"> Odottaa käsittelyä. </span>
<?php else: ?>
<span style="color:green;"> Käsitelty ja toimitettu. </span>
<?php endif; ?>
</section>
<section class="napit">
<?php if ( $tilaus->maksettu AND !is_null($tilaus->laskunro) ) : ?>
<!-- Laskun lataus -->
<form method="post" action="download.php" class="inline-block">
<input type="hidden" name="filepath" value="./tilaukset/<?= $lasku_file_nimi ?>">
<button type="submit" class="nappi">Lasku <i class="material-icons">file_download</i></button>
</form>
<?php if ( $user->isAdmin() ) : ?>
<!-- Noutolistan lataus -->
<form method="post" action="download.php" class="inline-block">
<input type="hidden" name="filepath" value="./tilaukset/<?= $noutolista_file_nimi ?>">
<button type="submit" class="nappi">Noutolista <i class="material-icons">file_download</i></button>
</form>
<?php endif; ?>
<?php endif; ?>
</section>
</div>
<?= $feedback ?>
<div class="flex_row">
<div class="table white-bg">
<div class="tr">
<div class="td pad">Tilausnumero: <?= sprintf('%04d', $tilaus->id) ?></div>
<div class="td pad">Päivämäärä: <?= date("d.m.Y", strtotime($tilaus->paivamaara)) ?></div>
</div>
<div class="tr">
<div class="td pad">Tilaaja: <?= $tilaus->asiakas->etunimi ?> <?= $tilaus->asiakas->sukunimi ?></div>
<div class="td pad">Yritys: <?= $tilaus->yritys->nimi ?></div>
</div>
<div class="tr">
<div class="td pad">Tuotteet: <?= $tilaus->tuotteet_kpl ?></div>
<div class="td pad">Summa: <?= format_number($tilaus->hintatiedot["summa_yhteensa"]) ?></div>
</div>
<div class="tr">
<div class="td pad">Maksutapa: <?= ($tilaus->maksutapa) ? "Lasku 14pv" : "e-korttimaksu"; ?></div>
<div class="td pad"></div>
</div>
<div class="tr">
<div class="td pad small_note">Kaikki hinnat sisältävät ALV:n</div>
<div class="td pad"></div>
</div>
</div>
<div class="white-bg" style="padding-left: 10px;">
<p style="font-weight: bold;">Toimitusosoite</p>
<p style="margin:10px;"><?= $tilaus->toimitusosoite["koko_nimi"] ?>, <?= $tilaus->toimitusosoite["yritys"] ?></p>
<p style="margin:10px;"><?= $tilaus->toimitusosoite["katuosoite"] ?></p>
<p style="margin:10px;"><?= $tilaus->toimitusosoite["postinumero"] ?> <?= $tilaus->toimitusosoite["postitoimipaikka"] ?></p>
<p style="margin:10px;"><?= $tilaus->toimitusosoite["puhelin"] ?> <?= $tilaus->toimitusosoite["sahkoposti"] ?></p>
</div>
</div>
<br>
<table width="100%">
<thead>
<tr><th colspan="9" class="center" style="background-color:#1d7ae2;">Tilatut tuotteet</th></tr>
<tr><th>Tuotenumero</th>
<th>Tuote</th>
<th>Valmistaja</th>
<th class="number">Kpl-hinta</th>
<th class="number">Kpl</th>
<th class="number">Hinta (yht.)</th>
<th class="number">ALV-%</th>
<th class="number">Alennus</th>
<th></th><!-- Lisäinfot -->
</tr>
</thead>
<tbody>
<?php foreach ( $tilaus->tuotteet as $tuote ) : ?>
<tr>
<td><?= $tuote->tuotekoodi ?></td>
<td><?= $tuote->nimi ?></td>
<td><?= $tuote->valmistaja ?></td>
<td class="number"><?= $tuote->aHinta_toString() ?></td>
<td class="number"><?= $tuote->kpl_maara ?></td>
<td class="number"><?= $tuote->summa_toString() ?></td>
<td class="number"><?= $tuote->alv_toString() ?></td>
<td class="number">
<?= ((float)$tuote->alennus_prosentti!=0) ? (round($tuote->alennus_prosentti*100)." %") : ("---") ?>
</td>
<td>
<?php if ( $tuote->tilaustuote ) : ?>
<span style="color: darkorange">Tilaustuote</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<tr style="background-color:#cecece;">
<td>---</td>
<td>Rahtimaksu</td>
<td></td>
<td class="number"><?= $tilaus->rahtimaksu_toString() ?></td>
<td></td>
<td class="number"><?= $tilaus->rahtimaksu_toString() ?></td>
<td class="number"><?= $tilaus->rahtimaksuALV_toString() ?></td>
<td class="number"><?= ($tilaus->hintatiedot["rahtimaksu"]==0) ? "Ilmainen toimitus" : "---" ?></td>
<td></td>
</tr>
</tbody>
</table>
</main>
<?php require 'footer.php'; ?>
<?php if ($user->isAdmin()) : ?>
<script async>
let peruuta_nappi = document.getElementById('peruuta_tilaus');
let tilaus_id = <?= $tilaus->id ?>;
let user_id = <?= $tilaus->asiakas->id ?>;
if ( peruuta_nappi ) {
peruuta_nappi.addEventListener('click', function () {
Modal.open({
content: `
<div>
<h2>Oletko varma, että haluat peruuttaa tilauksen?</h2>
<h3>Tämä palauttaa tuotteet asiakkaan ostoskoriin,<br>
ja merkitsee tilauksen peruutetuksia.</h3>
<h3>Huom. Tilaus voi silti olla mahdollisesti maksettu!</h3>
<button class="nappi grey" onclick="Modal.close();">Palaa takaisin. Älä peruuta tilausta.</button>
<br><br>
<form method="post">
<input type="hidden" name="peruuta_id" value="${tilaus_id}">
<input type="hidden" name="user_id" value="${user_id}">
<input type="Submit" value="Poista tilaus." class="nappi red">
</form>
</div>
`,
draggable: true
});
});
}
</script>
<?php endif; ?>
</body>
</html>