-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.php
240 lines (207 loc) · 8.02 KB
/
report.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
231
232
233
234
235
236
237
238
239
240
<?php
require "_core.php";
if (!isset($_SESSION["report"])) {
header("Location: report-login.php");
exit();
}
$session_report = $_SESSION["report"] ?? 0;
if (!is_numeric($session_report)) {
header("Location: report-login.php");
exit();
}
// only keep it valid for 10 minutes
if ($_SESSION["report"] < time() - 600) {
header("Location: report-login.php");
exit();
}
$result1 = [];
$result2 = [];
$now_year = fa2en(jdate("Y"));
function reportGames(array $from, array $to) : array
{
global $db;
$sql = "SELECT orders.planID, orders.planIndexID, orders.planDaste, plans.family, orders.planPrice, plans.name1, plans.name2, plans.name3, plans.name4, plans.price1, plans.price2, plans.price3, plans.price4, orders.startTime, orders.endTime
FROM `orders`
INNER JOIN `plans` ON `plans`.`id` = `orders`.`planID`
WHERE `orders`.`endTime` IS NOT NULL AND
`orders`.`has_canceled` = 0 AND
`orders`.`datetime`
BETWEEN '".$from["year"]."-".$from["month"]."-".$from["day"]."' AND '".$to["year"]."-".$to["month"]."-".$to["day"]."'";
// var_dump($sql);
$rows = $db->selectsRaw($sql);
foreach ($rows as $i => $order) {
$timeDiff = $order["endTime"] - $order["startTime"];
$timeMin = ceil($timeDiff / 60);
$price = $timeMin * $order["planPrice"];
if ($order["endTime"] === null) {
$rows[$i]["total_price"] = null;
} else {
$rows[$i]["total_price"] = $price;
}
$rows[$i]["family_index"] = $order["planIndexID"] . "امی";
$rows[$i]["family_daste"] = $order["name" . $order["planDaste"]];
}
return $rows;
}
function reportFoods(array $from, array $to) : array
{
global $db;
$sql = "SELECT foods.name, orders_food.price, orders_food.our_price, `orders_food`.count
FROM `orders_food`
INNER JOIN `foods` ON `orders_food`.`foodId` = `foods`.`id`
WHERE `orders_food`.`datetime`
BETWEEN '".$from["year"]."-".$from["month"]."-".$from["day"]."' AND '".$to["year"]."-".$to["month"]."-".$to["day"]."'";
// var_dump($sql);
$rows = $db->selectsRaw($sql);
foreach ($rows as $i => $row) {
$rows[$i]["profit"] = $row["price"] - $row["our_price"];
$rows[$i]["total_price"] = $row["price"] * $row["count"];
$rows[$i]["total_profit"] = $row["count"] * $rows[$i]["profit"];
}
return $rows;
}
if (isset($_POST["submit"])) {
$show_result = $_POST["type"];
$from = [
"year" => $_POST["from_year"],
"month" => $_POST["from_month"],
"day" => $_POST["from_day"],
];
$to = [
"year" => $_POST["to_year"],
"month" => $_POST["to_month"],
"day" => $_POST["to_day"],
];
// Convert jalali to gregorian
$from = jalali_to_gregorian($from["year"], $from["month"], $from["day"]);
$to = jalali_to_gregorian($to["year"], $to["month"], $to["day"]);
// Re-key and change keys
$from = [
"year" => $from[0],
"month" => $from[1],
"day" => $from[2],
];
$to = [
"year" => $to[0],
"month" => $to[1],
"day" => $to[2],
];
if ($show_result === "games" || $show_result === "all") {
$result1 = reportGames($from, $to);
}
if ($show_result === "foods" || $show_result === "all") {
$result2 = reportFoods($from, $to);
}
}
?>
<title>سیستم گیم نت</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<a href="index.php">
برگشت به اتاق فرمان
</a>
<br>
<center>
<h1>حسابداری</h1>
</center>
<form action="" method="POST" style="display: flex; justify-content: center;flex-direction: column;">
<!-- a form to ask from-date, to-date, type select -->
<b>از تاریخ</b>
<select name="from_year">
<option value="1400">1399</option>
<option value="1400">1400</option>
<?php for ($this_year = 1401; $this_year <= $now_year; $this_year++) { ?>
<option value="<?=$this_year?>"<?php print ($this_year == $now_year) ? " selected=\"\"" : ""?>><?=$this_year?></option>
<?php } ?>
</select>
<select name="from_month">
<?php for ($this_month = 1; $this_month <= 12; $this_month++) { ?>
<option value="<?=$this_month?>"><?=$this_month?></option>
<?php } ?>
</select>
<select name="from_day">
<?php for ($this_day = 1; $this_day <= 31; $this_day++) { ?>
<option value="<?=$this_day?>"><?=$this_day?></option>
<?php } ?>
</select>
<!-- <input type="date" name="from-date"> -->
<br>
<b>تا تاریخ</b>
<select name="to_year">
<option value="1400">1400</option>
<?php for ($this_year = 1401; $this_year <= $now_year; $this_year++) { ?>
<option value="<?=$this_year?>"<?php print ($this_year == $now_year) ? " selected=\"\"" : ""?>><?=$this_year?></option>
<?php } ?>
</select>
<select name="to_month">
<?php for ($this_month = 1; $this_month <= 12; $this_month++) { ?>
<option value="<?=$this_month?>"><?=$this_month?></option>
<?php } ?>
</select>
<select name="to_day">
<?php for ($this_day = 1; $this_day <= 31; $this_day++) { ?>
<option value="<?=$this_day?>"><?=$this_day?></option>
<?php } ?>
</select>
<!-- <input type="date" name="to-date"> -->
<br>
<b>نوع</b>
<select name="type">
<option value="games">بازی ها</option>
<option value="foods">غذاها</option>
<option value="coffee">کافه</option>
<option value="all">همه</option>
</select>
<br>
<button type="submit" name="submit">نمایش</button>
</form>
<?php if (isset($show_result)) { ?>
<?php if ($show_result === "games" || $show_result === "all") { ?>
<h2>بازی ها</h2>
<?php $total_price = 0 ?>
<table width="100%" border="1px">
<tr>
<th>سیستم</th>
<th>از</th>
<th>تا</th>
<th>قیمت</th>
</tr>
<?php foreach ($result1 as $row) { ?>
<tr>
<td><?=$row["family"]?> - <?=$row["family_index"]?> - <?=$row["family_daste"]?></td>
<td><?=jdate("Y/m/d h:j:s", $row["startTime"])?></td>
<td><?=jdate("Y/m/d h:j:s", $row["endTime"])?></td>
<td><?=$row["total_price"] === null ? "-" : number_format($row["total_price"]) . " تومان"?></td>
</tr>
<?php $total_price += $row["total_price"] ?? 0 ?>
<?php } ?>
</table>
<b>جمع کل: <?=number_format($total_price)?> تومان</b>
<?php } ?>
<?php if ($show_result === "foods" || $show_result === "all") { ?>
<h2>غذاها</h2>
<?php $total_price = 0 ?>
<table width="100%" border="1px">
<tr>
<th>جنس</th>
<th>فی خرید</th>
<th>فی فروش</th>
<th>تعداد</th>
<th>جمع فروش</th>
<th>جمع سود</th>
</tr>
<?php foreach ($result2 as $row) { ?>
<tr>
<td><?=$row["name"]?></td>
<td><?=number_format($row["our_price"])?></td>
<td><?=number_format($row["price"])?></td>
<td><?=$row["count"]?></td>
<td><?=number_format($row["total_price"])?></td>
<td><?=number_format($row["total_profit"])?></td>
</tr>
<?php $total_price += $row["total_price"] ?? 0 ?>
<?php } ?>
</table>
<b>جمع کل: <?=number_format($total_price)?> تومان</b>
<?php } ?>
<?php } ?>