-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprice-list-page.php
More file actions
266 lines (230 loc) · 14.3 KB
/
price-list-page.php
File metadata and controls
266 lines (230 loc) · 14.3 KB
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<?php include('partials/navbar.php');
include('price_list_queries.php');
include('fetch_data_price_list.php');
?>
<!-----------------------------------RIGHT TAB-------------------------------------------------------------->
<main id="main" class="main" style="margin-bottom: 0px;">
<section>
<div class="container" style="padding-top: 0px; margin-left: 0px; padding-bottom: 0px; padding-right:30px;">
<div class="tab-content" id="search">
<div class="tab-pane in active">
<h1 style="padding-top: 0px;">PRICE LIST</h1>
<div class="d-flex align-items-center">
<h2 style="padding-top: 0px;">Products</h2>
<div class="ms-auto">
<a href="pdf_price_list.php?ACTION=VIEW" id="btn-pdf-price-list" class="btn btn-info" target="_blank">Create PDF</a>
<a href="#" id="btn-execute-queries" class="btn btn-info">Update</a>
</div>
</div>
<?php
// Fetch all businesses and their full names
$business_query = "SELECT DISTINCT business FROM tbl_product";
$business_results = mysqli_query($conn, $business_query);
$full_names_query = "SELECT business, business_name FROM tbl_business";
$full_names_results = mysqli_query($conn, $full_names_query);
$businessNames = [];
while ($row = mysqli_fetch_assoc($full_names_results)) {
$short = $row['business'];
$full = $row['business_name'];
$businessNames[$short] = "$full ($short)";
}
// Store all business codes to reuse later for items section
$business_codes = [];
while ($business_row = mysqli_fetch_assoc($business_results)) {
$currentBusiness = $business_row['business'];
$business_codes[] = $currentBusiness;
$businessName = $businessNames[$currentBusiness] ?? $currentBusiness;
echo "<h2 class='text-center' style='color: #1997D4; font-size:30px; margin-top:30px;'>$businessName</h2>";
$product_query = "SELECT tbl_product.*, tbl_supplier.company_name
FROM tbl_product
LEFT JOIN tbl_supplier ON tbl_supplier.id = tbl_product.supplier_id
WHERE business = '$currentBusiness'
ORDER BY name ASC";
$query_run_product = mysqli_query($conn, $product_query);
echo '<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col" style="text-align: center;">S.N</th>
<th scope="col" style="text-align: center;">Product Name</th>
<th scope="col" style="text-align: center;">Brand</th>
<th scope="col" style="text-align: center;">Purchase Mode</th>
<th scope="col" style="text-align: center;">Supplier Company Name</th>
<th scope="col" style="text-align: center;">INR Purchase Price</th>
<th scope="col" style="text-align: center;" class="weight-column">Weight</th>
<th scope="col" style="text-align: center;">Auto Purchase Price</th>
<th scope="col" style="text-align: center;" class="weight-column">Margin</th>
<th scope="col" style="text-align: center;">Auto Selling Price</th>
<th scope="col" style="text-align: center;">Price List Price</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>';
$sn = 1;
if (mysqli_num_rows($query_run_product) > 0) {
echo '<tr>
<td class="product_id" style="display:none;"></td>
<td class="price" style="display:none;">
<button class="btn btn-info update-btn-product btn-sm">Update</button>
</td>
</tr>';
while ($row = mysqli_fetch_assoc($query_run_product)) {
$company_name = explode(" ", $row['company_name'])[0];
echo '<tr>
<td class="product_id" style="display:none;">' . $row["id"] . '</td>
<td style="text-align: center;">' . $sn++ . '</td>
<td>' . $row["name"] . '</td>
<td>' . $row["brand"] . '</td>
<td>' . $row["purchase_mode"] . '</td>
<td>' . $company_name . '</td>
<td style="text-align: right;">' . $row["INR_purchase_price"] . '</td>
<td class="weight-column" style="text-align: center;">' . $row["weight"] . '</td>
<td style="text-align: right; color: green;">' . number_format($row["auto_purchase_price"], 2) . '</td>
<td class="weight-column" style="text-align: center;">' . $row["margin"] . '</td>
<td style="text-align: right; color: #6C3BAA;">' . number_format($row["auto_selling_price"], 2) . '</td>
<td style="text-align: right; color: #6C3BAA;">' . number_format($row["price_list_price"], 2) . '</td>
<td id="table-data"><a href="#" class="btn btn-info edit_product_btn btn-sm col-xs-2" title="Edit Product"><i class="bi bi-pen"></i></a></td>
</tr>';
}
} else {
echo '<tr><td colspan="13" class="text-center">No Record Found</td></tr>';
}
echo '</tbody></table>';
}
// ITEM SECTION
echo "<h1 style='padding-top: 40px;'>PRICE LIST</h1>";
echo "<h2 style='padding-top: 0px;'>Items</h2>";
foreach ($business_codes as $currentBusiness) {
$businessName = $businessNames[$currentBusiness] ?? $currentBusiness;
echo "<h2 class='text-center' style='color: #1997D4; font-size:30px; margin-top:30px;'>$businessName</h2>";
echo '<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col" style="text-align: center;">S.N</th>
<th scope="col" style="text-align: center;">Item Name</th>
<th scope="col" style="text-align: center;">Brand</th>
<th scope="col" style="text-align: center;">Purchase Mode</th>
<th scope="col" style="text-align: center;">Supplier Company Name</th>
<th scope="col" style="text-align: center;">INR Purchase Price</th>
<th scope="col" style="text-align: center;" class="weight-column">Weight</th>
<th scope="col" style="text-align: center;">Auto Purchase Price</th>
<th scope="col" style="text-align: center;" class="weight-column">Margin</th>
<th scope="col" style="text-align: center;">Auto Selling Price</th>
<th scope="col" style="text-align: center;">Price List Price</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>';
$category_query = "SELECT DISTINCT category FROM tbl_item WHERE business = '$currentBusiness' ORDER BY category ASC";
$category_results = mysqli_query($conn, $category_query);
$sn = 1;
while ($category_row = mysqli_fetch_assoc($category_results)) {
$currentCategory = $category_row['category'];
$sub_category_query = "SELECT DISTINCT sub_category FROM tbl_item WHERE category = '$currentCategory' AND business = '$currentBusiness' ORDER BY sub_category ASC";
$sub_category_results = mysqli_query($conn, $sub_category_query);
while ($sub_category_row = mysqli_fetch_assoc($sub_category_results)) {
$currentSubCategory = $sub_category_row['sub_category'];
echo '<tr><td colspan="14" style="font-size:18px;">
<strong style="color: #1997D4;">' . htmlspecialchars($currentCategory) . '</strong>:
<span style="color: green;">' . htmlspecialchars($currentSubCategory) . '</span>
</td></tr>';
$item_query = "SELECT tbl_item.*, tbl_supplier.company_name
FROM tbl_item
INNER JOIN tbl_supplier ON tbl_supplier.id = tbl_item.supplier_id
WHERE category = '$currentCategory' AND sub_category = '$currentSubCategory' AND business = '$currentBusiness'
ORDER BY item_name ASC";
$query_run_item = mysqli_query($conn, $item_query);
if (mysqli_num_rows($query_run_item) > 0) {
while ($row = mysqli_fetch_assoc($query_run_item)) {
$company_name = explode(" ", $row['company_name'])[0];
echo '<tr>
<td class="item_id" style="display:none;">' . $row["id"] . '</td>
<td style="text-align: center;">' . $sn++ . '</td>
<td>' . $row["item_name"] . '</td>
<td>' . $row["brand"] . '</td>
<td>' . $row["purchase_mode"] . '</td>
<td>' . $company_name . '</td>
<td style="text-align: right;">' . $row["INR_purchase_price"] . '</td>
<td class="weight-column" style="text-align: center;">' . $row["weight"] . '</td>
<td style="text-align: right; color: green;">' . number_format($row["auto_purchase_price"], 2) . '</td>
<td class="weight-column" style="text-align: center;">' . $row["margin"] . '</td>
<td style="text-align: right; color: #6C3BAA;">' . number_format($row["auto_selling_price"], 2) . '</td>
<td style="text-align: right; color: #6C3BAA;">' . number_format($row["price_list_price"], 2) . '</td>
<td><a href="#" class="btn btn-info edit_item_btn btn-sm col-xs-2" title="Edit Item"><i class="bi bi-pen"></i></a></td>
</tr>';
}
} else {
echo '<tr><td colspan="15"><h5>No Record Found</h5></td></tr>';
}
}
}
echo '</tbody></table>';
}
?>
</div>
</div>
</div>
</section>
</main>
<!-- ======= Footer ======= -->
<!--<footer id="footer" class="footer">
<div class="copyright">
© Copyright <strong><span>Aquashine</span></strong>. All Rights Reserved 2023
</div>
</footer> End Footer -->
<!-- Template Main JS File -->
<?php
if(isset($_FILES["image"]["name"])){
$id = $_POST["id"];
$name = $_POST["name"];
$imageName = $_FILES["image"]["name"];
$imageSize = $_FILES["image"]["size"];
$tmpName = $_FILES["image"]["tmp_name"];
// Image validation
$validImageExtension = ['jpg', 'jpeg', 'png'];
$imageExtension = explode('.', $imageName);
$imageExtension = strtolower(end($imageExtension));
if (!in_array($imageExtension, $validImageExtension)){
echo
"
<script>
alert('Invalid Image Extension');
document.location.href = '../aquashine';
</script>
";
}
elseif ($imageSize > 1200000){
echo
"
<script>
alert('Image Size Is Too Large');
//document.location.href = '../aquashine';
</script>
";
}
else{
$newImageName = $name . " - " . date("Y.m.d") . " - " . date("h.i.sa"); // Generate new image name
$newImageName .= '.' . $imageExtension;
$query = "UPDATE tbl_admin SET image_name = '$newImageName' WHERE id = $id";
mysqli_query($conn, $query);
move_uploaded_file($tmpName, 'images/admin-images/' . $newImageName);
echo
"
<script>
document.location.href = '../aquashine/general-manager.php'?id='.$id;
</script>
";
}
}
?>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<!-- <script src="https://cdn.jsdelivr.net/npm/popper.js@1.14.7/dist/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script> -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="js/price-list.js"></script>
<script src="js/purchase-price.js"></script>
<!-- <script src="js/item-edit.js"></script> -->
<script src="js/main.js"></script>
</body>
</html>