-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrollo_dotazioni.php
159 lines (127 loc) · 4.99 KB
/
controllo_dotazioni.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
<?php
include_once('config.php');
?>
<html>
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="css/bootstrap-color.min.css" >
<!-- Additional CSS -->
<link rel="stylesheet" href="css/main.css" >
<title>MY SHOP - Controllo dotazioni</title>
<style>
table {
border-collapse: collapse;
width: 50%;
}
th, td {
input: "text";
text-align: left;
padding: 8px;
}
th {
background-color: #E8E8E8;
}
tr:hover {background-color: AliceBlue;}
</style>
</head>
<body>
<?php include_once('header.php'); ?>
<div class="row" style="text-align:center;display: block;">
<form action="controllo_dotazioni.php" method="post">
<input name="family" style=" margin: 50px;width: 300px;padding: 5px 35px 5px 5px;font-size: 20px;border: 1px solid #CCC;height: 34px;" list="brow">
<datalist id="brow">
<?php
$query = "SELECT * FROM users ORDER BY username ASC";
$result = mysqli_query($db, $query) or die(mysql_error($db)."[".$query."]");
while ($row = mysqli_fetch_assoc($result))
{
echo "<option value='".$row['username']."'>".$row['username']."</option>";
}
?>
</datalist>
<input class="btn btn-primary" name="search" type="submit" value="Cerca"/>
</form>
</div>
<div class="container">
<div class="row">
<div class="col-12">
<div class="row mt-3">
<div class="col">
<p>
<?php
$family = "";
if(isset($_POST['family'])) {
$family = $_POST['family'];
}
try {
$con= new PDO('mysql:host=127.0.0.1:3306;dbname=rent_management', "root", "root");
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(!empty($family)) {
$queryusername = 'SELECT * FROM users WHERE username = "'.$family.'"';
$resultusername = mysqli_query($db, $queryusername);
$rowid = mysqli_fetch_assoc($resultusername);
$idretrieved= $rowid['id'];
$query = 'SELECT desart, sum(qta) - sum(CASE WHEN returncall=0 THEN 0 ELSE returnqta end) as "difference" FROM ordini WHERE idcliente = "'.$idretrieved.'" GROUP BY desart';
}
else {
$query = "";
}
//first pass just gets the column names
echo "<h2><span class='badge badge-secondary'>" .$family. "</span> </h2><hr/><h5 class='text-dark'> Biancheria in possesso del cliente:</h5> </br>";
print "<table class='table'>";
$result = $con->query($query);
//return only the first row (we only need field names)
$row = $result->fetch(PDO::FETCH_ASSOC);
print " <tr>";
print " <th>Articolo</th>";
print " <th>Q.ta Cliente</th>";
// end foreach
print " </tr>";
//second query gets the data
$data = $con->query($query);
$data->setFetchMode(PDO::FETCH_ASSOC);
foreach($data as $row){
print " <tr>";
foreach ($row as $name=>$value){
print " <td>$value</td>";
} //end field loop
print " </tr>";
} //end record loop
print "</table>";
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
} // end try
?>
</p>
</div>
<div class="col">
<?php
$select_borrow_data = "SELECT COUNT(DISTINCT numord) AS totalorders FROM ordini WHERE idcliente = '$idretrieved'";
$select_borrow_data_result = mysqli_query($db, $select_borrow_data);
$row_borrow_data = mysqli_fetch_assoc($select_borrow_data_result);
$select_borrow_data2 = "SELECT COUNT(DISTINCT numord) AS totalorders FROM ordini WHERE idcliente = '$idretrieved' AND status = 'active'";
$select_borrow_data_result2 = mysqli_query($db, $select_borrow_data2);
$row_borrow_data2 = mysqli_fetch_assoc($select_borrow_data_result2);
$select_borrow_data4 = "SELECT COUNT(DISTINCT numord) as expired FROM ordini WHERE idcliente = '$idretrieved' AND status = 'active' AND returndate < now()";
$select_borrow_data_result4 = mysqli_query($db, $select_borrow_data4);
$row_borrow_data4 = mysqli_fetch_assoc($select_borrow_data_result4);
?>
</br>
</br>
</br>
</br>
<h5 class="text-dark" style="padding-left: 120px;"> Totale ordini: <?php echo $row_borrow_data['totalorders']; ?> </h5>
<h5 class="text-dark" style="padding-left: 120px;"> Ordini attivi: <?php echo $row_borrow_data2['totalorders']; ?> </h5>
<h5 class="text-dark" style="padding-left: 120px;"> Ordini scaduti: <?php echo $row_borrow_data4['expired']; ?> </h5>
</div>
</div>
</div>
</div>
</div>
</br>
</br>
</body>
</html>