-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathBlueprint_Overview.html
More file actions
493 lines (465 loc) · 25.8 KB
/
Copy pathBlueprint_Overview.html
File metadata and controls
493 lines (465 loc) · 25.8 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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inventory — Blueprint Overview</title>
<style>
:root {
--navy: #0d1421;
--silver: #e9edf2;
--blue: #2b7de9;
--orange: #e07018;
--text: #1a1a2e;
--muted: #556;
--border: #d0d5dd;
--code-bg: #f4f5f7;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: 'Plus Jakarta Sans', 'Segoe UI', system-ui, -apple-system, sans-serif;
color: var(--text);
background: var(--silver);
line-height: 1.6;
}
header {
background: var(--navy);
color: #fff;
padding: 2rem 1.5rem 1.5rem;
}
header h1 { font-size: 1.8rem; font-weight: 600; font-family: 'Exo 2', 'Segoe UI', sans-serif; }
header .subtitle { color: #8ea4c8; margin-top: 0.3rem; font-size: 0.95rem; }
.topbar-accent {
height: 3px;
background: linear-gradient(90deg, var(--blue), var(--orange));
}
.container { max-width: 960px; margin: 0 auto; padding: 1.5rem; }
h2 {
font-size: 1.3rem;
color: var(--navy);
border-bottom: 2px solid var(--border);
padding-bottom: 0.3rem;
margin: 2rem 0 0.8rem;
font-family: 'Exo 2', 'Segoe UI', sans-serif;
}
h3 { font-size: 1.05rem; color: var(--navy); margin: 1.2rem 0 0.5rem; }
p { margin-bottom: 0.7rem; }
ul { margin: 0.5rem 0 1rem 1.5rem; }
li { margin-bottom: 0.25rem; }
table {
width: 100%;
border-collapse: collapse;
margin: 0.8rem 0 1.2rem;
font-size: 0.9rem;
}
th, td {
text-align: left;
padding: 0.5rem 0.7rem;
border: 1px solid var(--border);
}
th { background: var(--navy); color: #fff; font-weight: 500; }
tr:nth-child(even) { background: #f8f9fb; }
code {
background: var(--code-bg);
padding: 0.15em 0.4em;
border-radius: 3px;
font-family: 'IBM Plex Mono', 'Consolas', monospace;
font-size: 0.88em;
}
pre {
background: var(--navy);
color: #c8d6e5;
padding: 1rem;
border-radius: 6px;
overflow-x: auto;
font-family: 'IBM Plex Mono', 'Consolas', monospace;
font-size: 0.82rem;
line-height: 1.5;
margin: 0.8rem 0 1.2rem;
}
.card-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 1rem;
margin: 0.8rem 0 1.2rem;
}
.card {
background: #fff;
border-radius: 6px;
padding: 1rem;
border-top: 3px solid var(--blue);
}
.card.orange { border-top-color: var(--orange); }
.card h4 { font-size: 0.95rem; color: var(--navy); margin-bottom: 0.4rem; }
.card p, .card li { font-size: 0.88rem; color: var(--muted); }
.badge {
display: inline-block;
padding: 0.15em 0.55em;
border-radius: 10px;
font-size: 0.78rem;
font-weight: 600;
}
.badge-green { background: #d4edda; color: #155724; }
.badge-yellow { background: #fff3cd; color: #856404; }
.badge-red { background: #f8d7da; color: #721c24; }
.badge-blue { background: #cce5ff; color: #004085; }
.flow-box {
background: #fff;
border: 1px solid var(--border);
border-radius: 6px;
padding: 1rem;
margin: 0.8rem 0;
font-size: 0.88rem;
font-family: 'IBM Plex Mono', 'Consolas', monospace;
}
.flow-box .arrow { color: var(--blue); font-weight: bold; }
.flow-box .step { color: var(--orange); font-weight: 600; }
.note {
background: #fff3cd;
border-left: 4px solid var(--orange);
padding: 0.6rem 1rem;
border-radius: 0 4px 4px 0;
font-size: 0.88rem;
margin: 0.5rem 0 1rem;
color: #5a4000;
}
footer {
text-align: center;
padding: 2rem 1rem;
font-size: 0.82rem;
color: var(--muted);
border-top: 1px solid var(--border);
margin-top: 2rem;
}
footer a { color: var(--blue); text-decoration: none; }
</style>
</head>
<body>
<header>
<h1>Inventory — Blueprint Overview</h1>
<p class="subtitle">Self-hosted Inventory Management System · PHP 8.x + MariaDB 10.x · 97 PHP files · 14 tables · 6 test suites · 62 tests · MIT License</p>
</header>
<div class="topbar-accent"></div>
<div class="container">
<!-- Executive Summary -->
<h2>What Is This?</h2>
<p>A complete, offline-capable inventory management system that runs on a Raspberry Pi or any LAMP server. Track products with SKUs and images, manage stock levels, process multi-line-item sales orders, print invoices and picklists, and generate sales reports — all through a responsive Bootstrap 5 interface with zero external dependencies.</p>
<div class="card-grid">
<div class="card">
<h4>Inventory Core</h4>
<ul>
<li>Products with SKU, location, quantity, pricing</li>
<li>Category organization with image support</li>
<li>Stock adjustment with comment history</li>
<li>AJAX search by name, SKU, or description</li>
</ul>
</div>
<div class="card orange">
<h4>Sales & Orders</h4>
<ul>
<li>Multi-line-item orders per customer</li>
<li>Add sales by SKU or product search</li>
<li>Auto quantity decrease on sale</li>
<li>Printable invoices and picklists</li>
</ul>
</div>
<div class="card">
<h4>Reporting</h4>
<ul>
<li>Date-range sales reports with profit calc</li>
<li>Daily and monthly breakdowns</li>
<li>Stock level reports</li>
<li>Buy vs. sell price margin analysis</li>
</ul>
</div>
<div class="card orange">
<h4>Security & Access</h4>
<ul>
<li>3-tier RBAC (Admin/Supervisor/User)</li>
<li>bcrypt passwords + legacy SHA1 migration</li>
<li>CSRF protection on all forms + GET deletes</li>
<li>CSP, rate limiting, session hardening</li>
</ul>
</div>
<div class="card">
<h4>Soft-Delete & Trash</h4>
<ul>
<li>Reversible delete on users, customers, sales, orders, stock</li>
<li>Admin trash UI with restore and purge</li>
<li>All list/find queries auto-filter deleted rows</li>
<li>Authenticated delete is blocked from soft-deleted accounts</li>
</ul>
</div>
<div class="card orange">
<h4>Settings & Configuration</h4>
<ul>
<li>DB-backed settings table (key/value)</li>
<li>Admin-only settings page (currency code, etc.)</li>
<li>Per-install currency with live format preview</li>
<li>Configurable via .env for credentials; DB for app settings</li>
</ul>
</div>
</div>
<!-- Architecture -->
<h2>Request Lifecycle</h2>
<div class="flow-box">
<span class="step">1. HTTP Request</span> → index.php or module page<br>
<span class="arrow">↓</span> require_once 'includes/load.php'<br>
<span class="step">2. Bootstrap</span> → Constants, session hardening (httponly/samesite/strict_mode), autoload config→functions→session→upload→database→sql→settings<br>
<span class="step">3. Config</span> → Parse .env → DB_HOST, DB_USER, DB_PASS, DB_NAME, APP_SECRET<br>
<span class="step">4. Session</span> → session_start() with strict_mode; Session class initialized<br>
<span class="step">5. Database</span> → MySqli_DB connects, $db global available<br>
<span class="step">6. RBAC Gate</span> → page_require_level(N): login → user active → group active → level ≤ required<br>
<span class="step">7. Handler</span> → POST: verify_csrf() → validate → execute prepared stmt → redirect with flash msg<br>
<span class="step">8. Render</span> → header.php (HTML shell, sidebar by role) → page content with h() escaping → footer.php
</div>
<h2>Directory Map</h2>
<pre>
inventory/
├── index.php Entry point / login
├── schema.sql Canonical schema (14 tables, indexes, seed data)
├── .env.example Configuration template
├── Blueprint_Overview.html This file — offline documentation
├── install.sh Automated setup (DB, Apache vhost, webuser, .env)
│
├── includes/ Core engine (8 files)
│ ├── load.php Bootstrap, session hardening, security headers, autoload
│ ├── config.php .env parser → DB_HOST, DB_USER, DB_PASS, DB_NAME, APP_SECRET
│ ├── database.php MySqli_DB class (connect, prepare_query, prepare_select)
│ ├── session.php Session class (login/logout, flash messages)
│ ├── functions.php CSRF helpers, h(), remove_junk(), redirect, validate_password()
│ ├── sql.php Data layer: CRUD, soft-delete, auth, products, sales, reports, rate-limiting
│ ├── upload.php Media class (image upload for products and users)
│ └── formatcurrency.php Currency display using DB-configured currency code
│
├── layouts/ UI shell (header, footer, 3 role-based sidebars)
│
├── products/ 17 files — CRUD, categories, stock, media, search, view
├── sales/ 17 files — orders, sales, invoices, picklists, AJAX helpers
├── customers/ 5 files — CRUD, soft-delete aware
├── reports/ 7 files — sales (date/daily/monthly), stock
├── users/ 24 files — user/group CRUD, profile, password, auth,
│ settings, log viewer, trash/restore/purge UI
│
├── migrations/ 009 numbered UP/DOWN SQL files (001–009 applied to main)
├── packaging/sql/ 012 tenancy migrations (010–021, feature/tenancy-schema branch)
│
├── libs/ Bundled CSS/JS (Bootstrap 5, jQuery 3, Datepicker) — no CDN
├── uploads/ User-uploaded images (products/, users/)
└── tests/ 6 suites, 62 tests — run via tests/run.sh
</pre>
<!-- Database -->
<h2>Database Schema (14 Tables)</h2>
<div class="note">Tables marked <strong>tenancy</strong> are defined on the <code>feature/tenancy-schema</code> branch and will land in a future PR.</div>
<table>
<tr><th>Table</th><th>Purpose</th><th>Key Relationships / Notes</th></tr>
<tr><td><code>categories</code></td><td>Product categories</td><td>products.category_id → categories.id (CASCADE)</td></tr>
<tr><td><code>products</code></td><td>Product catalog</td><td>FK to categories, FK to media; <code>deleted_at</code> on tenancy branch</td></tr>
<tr><td><code>media</code></td><td>Product images</td><td>Referenced by products.media_id</td></tr>
<tr><td><code>orders</code></td><td>Sales orders (per customer)</td><td>Referenced by sales.order_id; <code>deleted_at TIMESTAMP</code></td></tr>
<tr><td><code>sales</code></td><td>Order line items</td><td>sales.product_id → products.id (CASCADE); <code>deleted_at TIMESTAMP</code></td></tr>
<tr><td><code>stock</code></td><td>Stock adjustment history</td><td>stock.product_id → products.id; <code>deleted_at TIMESTAMP</code></td></tr>
<tr><td><code>customers</code></td><td>Customer directory</td><td>Referenced by orders.customer; <code>deleted_at TIMESTAMP</code></td></tr>
<tr><td><code>users</code></td><td>User accounts (login)</td><td>users.user_level → user_groups.group_level (CASCADE); <code>deleted_at TIMESTAMP</code></td></tr>
<tr><td><code>user_groups</code></td><td>RBAC group definitions</td><td>3 seed rows: Admin(1), Supervisor(2), User(3)</td></tr>
<tr><td><code>log</code></td><td>Activity audit trail</td><td>log.user_id → users.id ON DELETE SET NULL</td></tr>
<tr><td><code>failed_logins</code></td><td>Login rate-limit tracking</td><td>Indexed on (ip, attempted_at); pruned probabilistically</td></tr>
<tr><td><code>settings</code></td><td>App configuration (key/value)</td><td>PK (setting_key); seed: currency_code=USD</td></tr>
<tr><td><code>orgs</code> <em>(tenancy)</em></td><td>Organization registry</td><td>FK source for org_members and 7 business tables</td></tr>
<tr><td><code>org_members</code> <em>(tenancy)</em></td><td>User ↔ org membership + role</td><td>UNIQUE (org_id, user_id); role: owner | member | viewer</td></tr>
</table>
<!-- Soft-Delete Pattern -->
<h2>Soft-Delete Pattern</h2>
<p>Five tables (<code>users</code>, <code>customers</code>, <code>sales</code>, <code>orders</code>, <code>stock</code>) use reversible soft-delete instead of hard <code>DELETE</code>.</p>
<div class="flow-box">
<strong>Delete</strong> → soft_delete_by_id($table, $id) → stamps deleted_at = NOW(), deleted_by = $user<br>
<strong>Restore</strong> → restore_by_id($table, $id) → clears deleted_at and deleted_by<br>
<strong>Purge</strong> → purge_by_id($table, $id) → hard DELETE, only allowed when deleted_at IS NOT NULL<br>
<br>
find_all() / find_by_id() auto-filter WHERE deleted_at IS NULL (via table_has_soft_delete() probe, cached per request).<br>
find_with_deleted() / find_by_id_with_deleted() bypass the filter for trash UI.
</div>
<p>The trash UI is at <code>users/trash.php</code> (Admin-only, level 1). Restore and purge are at <code>users/restore.php</code> and <code>users/purge.php</code>.</p>
<!-- Core Abstractions -->
<h2>Key Abstractions</h2>
<h3>MySqli_DB (<code>includes/database.php</code>)</h3>
<pre>
// Prepared INSERT/UPDATE/DELETE — returns stmt (check affected_rows)
$db->prepare_query("UPDATE products SET quantity = quantity + ? WHERE id = ?", "ii", $qty, $id);
// Prepared SELECT → array of associative rows
$db->prepare_select("SELECT * FROM products WHERE category_id = ?", "i", $cat_id);
// Prepared SELECT → single associative row or null
$db->prepare_select_one("SELECT * FROM users WHERE username = ? LIMIT 1", "s", $user);
// Escape for table/column name interpolation (never for values)
$db->escape($table_name);
</pre>
<h3>Session (<code>includes/session.php</code>)</h3>
<p>Global <code>$session</code>. <code>login($id)</code> calls <code>session_regenerate_id(true)</code> — prevents session fixation. Flash messages (<code>msg()</code>) survive exactly one redirect.</p>
<h3>CSRF Protection (<code>includes/functions.php</code>)</h3>
<pre>
echo csrf_field(); // hidden input in every <form method="post">
verify_csrf(); // POST handler entry — returns bool
echo csrf_url_param(); // append to GET-based delete links
verify_get_csrf(); // GET delete handler entry — checks $_GET['csrf_token']
</pre>
<h3>Soft-Delete Helpers (<code>includes/sql.php</code>)</h3>
<pre>
soft_delete_by_id($table, $id) // stamps deleted_at + deleted_by
restore_by_id($table, $id) // clears both columns
purge_by_id($table, $id) // hard DELETE (only when already soft-deleted)
find_by_id_with_deleted($table, $id) // bypasses deleted_at filter (trash UI)
find_with_deleted($table) // all rows including deleted (trash UI)
</pre>
<h3>Rate-Limiting Helpers (<code>includes/sql.php</code>)</h3>
<pre>
is_login_rate_limited($ip) // true when >= 5 attempts in 15 min
record_failed_login($ip, $username) // inserts into failed_logins
clear_failed_logins($ip) // called on successful login
prune_failed_logins() // probabilistic cleanup, no cron needed
</pre>
<h3>SQL Helpers (<code>includes/sql.php</code>)</h3>
<p><code>find_by_id()</code>, <code>find_all()</code> — generic table CRUD with auto soft-delete filter. <code>authenticate()</code> — bcrypt login with legacy SHA1 auto-upgrade. <code>page_require_level(N)</code> — RBAC gate on every protected page.</p>
<!-- Auth & RBAC -->
<h2>Authentication & RBAC</h2>
<table>
<tr><th>Level</th><th>Role</th><th>Access</th></tr>
<tr><td>1</td><td>Admin</td><td>Full CRUD, user/group management, trash UI, all reports, settings</td></tr>
<tr><td>2</td><td>Supervisor</td><td>Product/stock management, sales, customer CRUD, reports</td></tr>
<tr><td>3</td><td>User</td><td>View products, basic sales entry, order lookup</td></tr>
</table>
<p><strong>Login flow</strong>: <code>authenticate($user, $pass)</code> → prepared SELECT → IP rate-limit check → <code>password_verify()</code> (or SHA1 legacy) → rehash if needed → <code>session_regenerate_id(true)</code> → <code>updateLastLogIn()</code></p>
<p><strong>Page guard</strong>: <code>page_require_level(N)</code> checks: logged in → user <code>status=1</code> → group <code>group_status=1</code> → <code>user_level ≤ N</code></p>
<!-- Security Summary -->
<h2>Security Summary</h2>
<table>
<tr><th>Feature</th><th>Status</th><th>Implementation</th></tr>
<tr><td>SQL injection</td><td><span class="badge badge-green">Protected</span></td><td><code>prepare_query()</code> / <code>prepare_select()</code> with bound params throughout</td></tr>
<tr><td>Password storage</td><td><span class="badge badge-green">bcrypt</span></td><td><code>password_hash(PASSWORD_BCRYPT)</code>; SHA1 auto-upgrade on login; <code>password_needs_rehash()</code> check</td></tr>
<tr><td>CSRF (POST forms)</td><td><span class="badge badge-green">Protected</span></td><td><code>random_bytes(32)</code> token, <code>hash_equals()</code> verify via <code>verify_csrf()</code></td></tr>
<tr><td>CSRF (GET deletes)</td><td><span class="badge badge-green">Protected</span></td><td><code>csrf_url_param()</code> on links; <code>verify_get_csrf()</code> in handler</td></tr>
<tr><td>XSS prevention</td><td><span class="badge badge-green">Protected</span></td><td><code>h()</code> — <code>htmlspecialchars(ENT_QUOTES, UTF-8)</code> on all dynamic output</td></tr>
<tr><td>Session fixation</td><td><span class="badge badge-green">Protected</span></td><td><code>session_regenerate_id(true)</code> on every login</td></tr>
<tr><td>Session cookies</td><td><span class="badge badge-green">Hardened</span></td><td>httponly, samesite=Lax, strict_mode, secure (when HTTPS) — set before session_start()</td></tr>
<tr><td>RBAC enforcement</td><td><span class="badge badge-green">Protected</span></td><td><code>page_require_level()</code> on every protected page; disabled user/group enforced (cast to int)</td></tr>
<tr><td>CSP headers</td><td><span class="badge badge-green">Protected</span></td><td><code>script-src 'self'</code>, <code>style-src 'self'</code> — no <code>unsafe-inline</code>; emitted on every request from <code>load.php</code></td></tr>
<tr><td>Login rate limiting</td><td><span class="badge badge-green">Protected</span></td><td>5 attempts per IP per 15 min via <code>failed_logins</code> table; auto-cleared on success</td></tr>
<tr><td>Password complexity</td><td><span class="badge badge-green">Enforced</span></td><td><code>validate_password()</code>: min 8 chars, requires letter + digit, common-password denylist</td></tr>
<tr><td>Upload SQL</td><td><span class="badge badge-green">Protected</span></td><td><code>insert_media()</code> and <code>update_userImg()</code> use <code>prepare_query()</code></td></tr>
<tr><td>Security headers</td><td><span class="badge badge-green">Present</span></td><td>X-Frame-Options: DENY, X-Content-Type-Options: nosniff, Referrer-Policy, Permissions-Policy</td></tr>
<tr><td>Directory listing</td><td><span class="badge badge-green">Blocked</span></td><td><code>.htaccess</code> in includes/, uploads/, and root deny directory indexing</td></tr>
<tr><td>Activity logging</td><td><span class="badge badge-green">Active</span></td><td>Every page request logged with user_id, IP, action, timestamp to <code>log</code> table</td></tr>
<tr><td>MIME re-validation on upload</td><td><span class="badge badge-yellow">Partial</span></td><td><code>getimagesize()</code> called but magic-byte deep check not performed; extension whitelist in place</td></tr>
<tr><td>Soft-delete coverage</td><td><span class="badge badge-yellow">Partial</span></td><td>users/customers/sales/orders/stock covered; products and categories still hard-delete</td></tr>
</table>
<!-- Test Coverage -->
<h2>Test Coverage (6 Suites, 62 Tests)</h2>
<table>
<tr><th>Suite</th><th>Type</th><th>Tests</th><th>Coverage</th></tr>
<tr><td><code>AuthTest.php</code></td><td>Integration</td><td>9 / 9 pass</td><td>All 3 user logins, wrong password, non-existent user, SHA1→bcrypt migration, session fixation prevention</td></tr>
<tr><td><code>CSRFTest.php</code></td><td>Unit</td><td>16 / 16 pass</td><td>Token lifecycle, POST + GET verification, multibyte, stale-token rejection, csrf_url_param()</td></tr>
<tr><td><code>CRUDTest.php</code></td><td>Integration</td><td>11 / 11 pass</td><td>Product CRUD, quantity adjust, SQL-injection resistance</td></tr>
<tr><td><code>SecurityHeadersTest.php</code></td><td>HTTP Integration</td><td>7 / 7 pass</td><td>CSP present, no unsafe-inline/eval, X-Frame-Options, X-Content-Type-Options, Referrer-Policy, Permissions-Policy</td></tr>
<tr><td><code>SettingsTest.php</code></td><td>Integration</td><td>6 / 6 pass</td><td>Settings::get() defaults, Settings::set() persistence, currency code round-trip, formatcurrency() fallback</td></tr>
<tr><td><code>SoftDeleteTest.php</code></td><td>Integration</td><td>13 / 13 pass</td><td>table_has_soft_delete probe, soft-delete/restore/purge lifecycle, find_all/find_by_id filters, authenticate() rejects deleted user</td></tr>
</table>
<p style="font-size:0.9em;color:var(--muted);">Run all suites: <code>bash tests/run.sh</code>. Tests use a custom <code>test()</code> / <code>check()</code> harness (not PHPUnit) with HARNESS_ prefixed data for isolation from production records.</p>
<!-- Quick Start -->
<h2>Quick Start</h2>
<pre>
git clone https://github.com/bitsandbots/inventory.git
cd inventory
bash install.sh
# Access at http://<server>:8080
# Default credentials — change all three immediately:
# admin / admin (level 1 — full access)
# special / special (level 2 — supervisor)
# user / user (level 3 — basic)
</pre>
<p>Reinstall from scratch (wipes database, vhost, symlink, uploads, <code>.env</code>):</p>
<pre>
bash install.sh --reinstall # prompts: type RESET to confirm
bash install.sh --reinstall -y # non-interactive
</pre>
<p>Full installation steps, Apache vhost config, and troubleshooting: <a href="docs/setup-and-usage.md">docs/setup-and-usage.md</a></p>
<!-- Gap Analysis -->
<h2>Gap Analysis — Current Items</h2>
<table>
<tr><th>Severity</th><th>Gap</th><th>Location</th></tr>
<tr>
<td><span class="badge badge-red">Critical</span></td>
<td>Products and categories have no soft-delete — hard DELETE permanently removes records and breaks historical sales/report data</td>
<td><code>schema.sql</code>, <code>includes/sql.php:139</code></td>
</tr>
<tr>
<td><span class="badge badge-red">Critical</span></td>
<td>Hand-written SQL queries (join_product_table, find_all_sales, etc.) have no <code>org_id</code> filter — cross-tenant data leaks when tenancy lands</td>
<td><code>includes/sql.php:610,923,944</code></td>
</tr>
<tr>
<td><span class="badge badge-red">Critical</span></td>
<td>File upload: MIME type not re-validated against magic bytes after upload — extension whitelist can be bypassed with crafted files</td>
<td><code>includes/upload.php:67,127,173</code></td>
</tr>
<tr>
<td><span class="badge badge-yellow">Significant</span></td>
<td>Zero tests for products, customers, sales, and reports modules — no regression detection for these workflows</td>
<td><code>tests/</code></td>
</tr>
<tr>
<td><span class="badge badge-yellow">Significant</span></td>
<td>Login rate limiting tracks only by IP — brute force by rotating usernames on same IP is undetected</td>
<td><code>users/auth.php</code>, <code>includes/sql.php:1097</code></td>
</tr>
<tr>
<td><span class="badge badge-yellow">Significant</span></td>
<td>No numeric range validation on product price/quantity fields — negative quantities and inverted prices accepted</td>
<td><code>products/add_product.php:27–29</code></td>
</tr>
<tr>
<td><span class="badge badge-yellow">Significant</span></td>
<td>unlink() in upload.php returns true unconditionally even on permission failure — silent orphaned-file accumulation</td>
<td><code>includes/upload.php:223,271</code></td>
</tr>
<tr>
<td><span class="badge badge-blue">Minor</span></td>
<td>Ajax endpoints (ajax_customer.php, ajax_sku.php) check isUserLoggedIn() only, not page_require_level() — inconsistent authz</td>
<td><code>sales/ajax_customer.php:10</code>, <code>sales/ajax_sku.php</code></td>
</tr>
<tr>
<td><span class="badge badge-blue">Minor</span></td>
<td>find_by_name() has no deleted_at filter — soft-deleted records block re-creation of same-named entities</td>
<td><code>includes/sql.php:91–99</code></td>
</tr>
<tr>
<td><span class="badge badge-blue">Minor</span></td>
<td>join_product_table() uses legacy find_by_sql() and has no deleted_at filter — soft-deleted products appear in listings</td>
<td><code>includes/sql.php:610–618</code></td>
</tr>
<tr>
<td><span class="badge badge-blue">Minor</span></td>
<td>Admin actions (user creation, deletion, role changes) are not logged to the audit log table</td>
<td><code>users/add_user.php</code>, <code>users/edit_user.php</code></td>
</tr>
</table>
<p>Full breakdown with resolved history: <a href="docs/gap-analysis.md">docs/gap-analysis.md</a></p>
<!-- Tenancy Roadmap -->
<h2>Tenancy Roadmap (In Progress)</h2>
<p>Branch: <code>feature/tenancy-schema</code>. Two-PR plan:</p>
<div class="flow-box">
<strong>PR 1 (schema + guards)</strong> — migrations 010–021:<br>
010 orgs table → 011 org_members → 012 default org seed<br>
013–019 org_id FK on customers/products/categories/sales/orders/stock/media<br>
020 settings PK reshape → 021 users.last_active_org_id<br>
Auto-filter in find_all/find_by_id · switch_org endpoint · shim for page_require_level<br>
<br>
<strong>PR 2 (org UI)</strong>:<br>
Org create/rename/soft-delete · member add/role-change/remove · topbar org switcher · remove shim
</div>
</div>
<footer>
<p>Inventory · MIT License · Enhanced by <a href="https://coreconduit.com">CoreConduit Consulting Services</a></p>
<p>Originally created by Siamon Hasan · Built with PHP, MySQL/MariaDB, Bootstrap 5</p>
<p>Full documentation: <a href="docs/README.md">docs/</a> · Generated 2026-05-16</p>
</footer>
</body>
</html>