🛡️ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!
Manual Uploads
sassanix3436b64bb900
diff --git a/backend/app.py b/backend/app.pyindex 874d3da..55103a1 100644--- a/backend/app.py+++ b/backend/app.py@@ -95,6 +95,7 @@ def init_db():warranty_years INTEGER NOT NULL,expiration_date DATE,invoice_path TEXT,+ manual_path TEXT,created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP)''')@@ -193,7 +194,7 @@ def add_warranty():expiration_date = purchase_date + timedelta(days=warranty_years * 365)- # Handle file upload+ # Handle invoice file uploaddb_invoice_path = Noneif 'invoice' in request.files:invoice = request.files['invoice']@@ -212,15 +213,34 @@ def add_warranty():invoice.save(invoice_path)db_invoice_path = os.path.join('uploads', filename)+ # Handle manual file upload+ db_manual_path = None+ if 'manual' in request.files:+ manual = request.files['manual']+ if manual.filename != '':+ if not allowed_file(manual.filename):+ return jsonify({"error": "File type not allowed. Use PDF, PNG, JPG, or JPEG"}), 400++ filename = secure_filename(manual.filename)+ # Make filename unique by adding timestamp+ filename = f"{datetime.now().strftime('%Y%m%d%H%M%S')}_manual_{filename}"+ manual_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)++ # Ensure directory exists+ os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)++ manual.save(manual_path)+ db_manual_path = os.path.join('uploads', filename)+# Save to databaseconn = get_db_connection()with conn.cursor() as cur:# Insert warrantycur.execute('''- INSERT INTO warranties (product_name, purchase_date, warranty_years, expiration_date, invoice_path)- VALUES (%s, %s, %s, %s, %s)+ INSERT INTO warranties (product_name, purchase_date, warranty_years, expiration_date, invoice_path, manual_path)+ VALUES (%s, %s, %s, %s, %s, %s)RETURNING id- ''', (product_name, purchase_date, warranty_years, expiration_date, db_invoice_path))+ ''', (product_name, purchase_date, warranty_years, expiration_date, db_invoice_path, db_manual_path))warranty_id = cur.fetchone()[0]# Insert serial numbers@@ -255,13 +275,14 @@ def delete_warranty(warranty_id):conn = get_db_connection()with conn.cursor() as cur:# First get the invoice path to delete the file- cur.execute('SELECT invoice_path FROM warranties WHERE id = %s', (warranty_id,))+ cur.execute('SELECT invoice_path, manual_path FROM warranties WHERE id = %s', (warranty_id,))result = cur.fetchone()if not result:return jsonify({"error": "Warranty not found"}), 404invoice_path = result[0]+ manual_path = result[1]# Delete the warranty from databasecur.execute('DELETE FROM warranties WHERE id = %s', (warranty_id,))@@ -274,6 +295,12 @@ def delete_warranty(warranty_id):if os.path.exists(full_path):os.remove(full_path)+ # Delete the manual file if it exists+ if manual_path:+ full_path = os.path.join('/data', manual_path)+ if os.path.exists(full_path):+ os.remove(full_path)+return jsonify({"message": "Warranty deleted successfully"}), 200except Exception as e:@@ -318,15 +345,16 @@ def update_warranty(warranty_id):conn = get_db_connection()with conn.cursor() as cur:# Check if warranty exists- cur.execute('SELECT invoice_path FROM warranties WHERE id = %s', (warranty_id,))+ cur.execute('SELECT invoice_path, manual_path FROM warranties WHERE id = %s', (warranty_id,))result = cur.fetchone()if not result:return jsonify({"error": "Warranty not found"}), 404old_invoice_path = result[0]+ old_manual_path = result[1]- # Handle file upload if new file is provided+ # Handle invoice file upload if new file is provideddb_invoice_path = old_invoice_pathif 'invoice' in request.files:invoice = request.files['invoice']@@ -347,14 +375,35 @@ def update_warranty(warranty_id):if os.path.exists(old_full_path):os.remove(old_full_path)+ # Handle manual file upload if new file is provided+ db_manual_path = old_manual_path+ if 'manual' in request.files:+ manual = request.files['manual']+ if manual.filename != '':+ if not allowed_file(manual.filename):+ return jsonify({"error": "File type not allowed. Use PDF, PNG, JPG, or JPEG"}), 400++ filename = secure_filename(manual.filename)+ filename = f"{datetime.now().strftime('%Y%m%d%H%M%S')}_manual_{filename}"+ manual_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)++ manual.save(manual_path)+ db_manual_path = os.path.join('uploads', filename)++ # Remove old manual file if exists and different from new one+ if old_manual_path and old_manual_path != db_manual_path:+ old_full_path = os.path.join('/data', old_manual_path)+ if os.path.exists(old_full_path):+ os.remove(old_full_path)+# Update the warranty in databasecur.execute('''UPDATE warrantiesSET product_name = %s, purchase_date = %s, warranty_years = %s,- expiration_date = %s, invoice_path = %s+ expiration_date = %s, invoice_path = %s, manual_path = %sWHERE id = %s''', (product_name, purchase_date, warranty_years, expiration_date,- db_invoice_path, warranty_id))+ db_invoice_path, db_manual_path, warranty_id))# Update serial numbers# First, delete existing serial numbers for this warrantydiff --git a/backend/init.sql b/backend/init.sqlindex 295fbd0..f2c5849 100644--- a/backend/init.sql+++ b/backend/init.sql@@ -7,6 +7,7 @@ CREATE TABLE warranties (warranty_years INTEGER NOT NULL,expiration_date DATE,invoice_path TEXT,+ manual_path TEXT,created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);diff --git a/frontend/index.html b/frontend/index.htmlindex 7611043..2a148ce 100644--- a/frontend/index.html+++ b/frontend/index.html@@ -101,6 +101,17 @@<div id="fileName" class="file-name"></div></div>+ <div class="form-group">+ <label>Product Manual (Optional)</label>+ <div class="file-input-wrapper">+ <label for="manual" class="file-input-label">+ <i class="fas fa-upload"></i> Choose File+ </label>+ <input type="file" id="manual" name="manual" class="file-input" accept=".pdf,.png,.jpg,.jpeg">+ </div>+ <div id="manualFileName" class="file-name"></div>+ </div>+<button type="submit" class="btn btn-primary">Add Warranty</button></form></div>@@ -179,6 +190,18 @@<div id="editFileName" class="file-name"></div><div id="currentInvoice" class="mt-10"></div></div>++ <div class="form-group">+ <label>Product Manual (Optional)</label>+ <div class="file-input-wrapper">+ <label for="editManual" class="file-input-label">+ <i class="fas fa-upload"></i> Choose File+ </label>+ <input type="file" id="editManual" name="manual" class="file-input" accept=".pdf,.png,.jpg,.jpeg">+ </div>+ <div id="editManualFileName" class="file-name"></div>+ <div id="currentManual" class="mt-10"></div>+ </div></form></div><div class="modal-footer">diff --git a/frontend/script.js b/frontend/script.jsindex 5a3844a..c918267 100644--- a/frontend/script.js+++ b/frontend/script.js@@ -78,6 +78,8 @@ const refreshBtn = document.getElementById('refreshBtn');const searchInput = document.getElementById('searchWarranties');const fileInput = document.getElementById('invoice');const fileName = document.getElementById('fileName');+const manualInput = document.getElementById('manual');+const manualFileName = document.getElementById('manualFileName');const editModal = document.getElementById('editModal');const deleteModal = document.getElementById('deleteModal');const editWarrantyForm = document.getElementById('editWarrantyForm');@@ -115,10 +117,14 @@ document.addEventListener('DOMContentLoaded', () => {});// File input change event-fileInput.addEventListener('change', updateFileName);+fileInput.addEventListener('change', (e) => updateFileName(e, 'invoice', 'fileName'));+manualInput.addEventListener('change', (e) => updateFileName(e, 'manual', 'manualFileName'));document.getElementById('editInvoice').addEventListener('change', () => {updateFileName(null, 'editInvoice', 'editFileName');});+document.getElementById('editManual').addEventListener('change', () => {+ updateFileName(null, 'editManual', 'editManualFileName');+});// Form submissionwarrantyForm.addEventListener('submit', addWarranty);@@ -286,12 +292,19 @@ function renderWarranties(filteredWarranties = null) {</div>` : ''}${warranty.invoice_path ? `- <div>+ <div class="document-link-container"><a href="${warranty.invoice_path}" class="invoice-link" target="_blank"><i class="fas fa-file-invoice"></i> View Invoice</a></div>` : ''}+ ${warranty.manual_path ? `+ <div class="document-link-container">+ <a href="${warranty.manual_path}" class="manual-link" target="_blank">+ <i class="fas fa-book"></i> View Manual+ </a>+ </div>+ ` : ''}</div>`;@@ -473,6 +486,20 @@ function openEditModal(warranty) {currentInvoiceElement.innerHTML = '<span>No invoice uploaded</span>';}+ // Show current manual if exists+ const currentManualElement = document.getElementById('currentManual');+ if (warranty.manual_path) {+ currentManualElement.innerHTML = `+ <span class="text-success">+ <i class="fas fa-check-circle"></i> Current manual:+ <a href="${warranty.manual_path}" target="_blank">View</a>+ (Upload a new file to replace)+ </span>+ `;+ } else {+ currentManualElement.innerHTML = '<span>No manual uploaded</span>';+ }+// Reset file input displaydocument.getElementById('editFileName').textContent = '';diff --git a/frontend/style.css b/frontend/style.cssindex b1df543..f3efb13 100644--- a/frontend/style.css+++ b/frontend/style.css@@ -1294,4 +1294,33 @@ tr.status-expiring {.refresh-btn.loading i {animation: spin 1s linear infinite;+}++/* Document links */+.document-link-container {+ margin-top: 10px;+}++.invoice-link, .manual-link {+ display: inline-flex !important;+ align-items: center !important;+ color: var(--primary-color) !important;+ text-decoration: none !important;+ font-weight: 500 !important;+ padding: 5px 10px !important;+ background-color: var(--light-gray) !important;+ border-radius: var(--border-radius) !important;+ transition: var(--transition) !important;+ border: none !important;+}++.invoice-link i, .manual-link i {+ margin-right: 5px !important;+ font-size: 1rem !important;+}++.invoice-link:hover, .manual-link:hover {+ text-decoration: none !important;+ background-color: var(--medium-gray) !important;+ color: var(--primary-dark) !important;}\ No newline at end of file