saved the creation of warehows locations
This commit is contained in:
Binary file not shown.
@@ -17,6 +17,14 @@
|
||||
<input type="text" name="description" maxlength="250"><br>
|
||||
<button type="submit" class="btn">Add Location</button>
|
||||
</form>
|
||||
<!-- Import from CSV content moved here -->
|
||||
<div style="margin-top: 24px;">
|
||||
<h3 style="font-size: 1.1em;">Import Locations from CSV</h3>
|
||||
<div style="display: flex; flex-direction: row; gap: 16px; align-items: center;">
|
||||
<span style="font-size: 0.95em;">Bulk import warehouse locations using a CSV file.</span>
|
||||
<a href="{{ url_for('warehouse.import_locations_csv') }}" class="btn" style="padding: 4px 12px; font-size: 0.95em;">Go to Import Page</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Locations Table Card -->
|
||||
<div class="card scan-table-card">
|
||||
@@ -42,13 +50,5 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!-- Import Locations from CSV Card (original size, last position) -->
|
||||
<div class="card scan-form-card" style="margin-top: 24px;">
|
||||
<h3>Import Locations from CSV</h3>
|
||||
<div style="display: flex; flex-direction: row; gap: 16px; align-items: center;">
|
||||
<span>Bulk import warehouse locations using a CSV file.</span>
|
||||
<a href="{{ url_for('warehouse.import_locations_csv') }}" class="btn">Go to Import Page</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
@@ -2,20 +2,69 @@
|
||||
{% block title %}Import Warehouse Locations from CSV{% endblock %}
|
||||
{% block content %}
|
||||
<div class="scan-container">
|
||||
<!-- Import Locations from CSV Card (first) -->
|
||||
<!-- Import Locations from CSV Card (first, fixed position) -->
|
||||
<div class="card scan-form-card" style="margin-bottom: 24px;">
|
||||
<h3>Import Locations from CSV</h3>
|
||||
<form method="POST" enctype="multipart/form-data" class="form-centered">
|
||||
<form method="POST" enctype="multipart/form-data" class="form-centered" id="csv-upload-form">
|
||||
<label for="csv_file">Choose CSV file:</label>
|
||||
<input type="file" name="csv_file" accept=".csv" required><br>
|
||||
<button type="submit" class="btn">Upload & Preview</button>
|
||||
{% if locations %}
|
||||
<button type="submit" name="create_locations" value="1" class="btn" style="margin-left: 12px;">Create Locations</button>
|
||||
{% if not locations %}
|
||||
<input type="file" name="csv_file" accept=".csv" required><br>
|
||||
<button type="submit" class="btn">Upload & Preview</button>
|
||||
{% else %}
|
||||
<label style="font-weight: bold;">Selected file: {{ session['csv_filename'] if session['csv_filename'] else 'Unknown' }}</label><br>
|
||||
<button type="button" class="btn" onclick="showPopupAndSubmit()">Create Locations</button>
|
||||
{% endif %}
|
||||
<!-- CSV File Format Guidance (moved here) -->
|
||||
<div style="margin-top: 8px;">
|
||||
<h4 style="margin-bottom: 4px;">CSV File Format</h4>
|
||||
<label style="margin-bottom: 8px; display: block;">Fisierul CSV trebuie sa aiba urmatorul format:</label>
|
||||
<table class="scan-table" style="width: 100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Location Code</th>
|
||||
<th>Size</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>EX123</td>
|
||||
<td>100</td>
|
||||
<td>Zona depozitare A</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</form>
|
||||
<!-- Popup Modal -->
|
||||
<div id="popup-modal" style="display:none; position:fixed; top:0; left:0; width:100vw; height:100vh; background:rgba(0,0,0,0.3); z-index:9999; align-items:center; justify-content:center;">
|
||||
<div style="background:#fff; padding:32px; border-radius:8px; box-shadow:0 2px 8px #333; text-align:center;">
|
||||
<h3>Performing the creation of the warehouse locations</h3>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
function showPopupAndSubmit() {
|
||||
document.getElementById('popup-modal').style.display = 'flex';
|
||||
// Submit the form after showing popup
|
||||
setTimeout(function() {
|
||||
var form = document.getElementById('csv-upload-form');
|
||||
var input = document.createElement('input');
|
||||
input.type = 'hidden';
|
||||
input.name = 'create_locations';
|
||||
input.value = '1';
|
||||
form.appendChild(input);
|
||||
form.submit();
|
||||
}, 500);
|
||||
}
|
||||
window.onload = function() {
|
||||
if (window.location.hash === '#created') {
|
||||
document.getElementById('popup-modal').style.display = 'none';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
<!-- Preview Table Card (always visible) -->
|
||||
<div class="card scan-table-card" style="margin-bottom: 24px;">
|
||||
<!-- Preview Table Card (expandable height, scrollable) -->
|
||||
<div class="card scan-table-card" style="margin-bottom: 24px; max-height: 480px; overflow-y: auto;">
|
||||
<h3>Preview Table</h3>
|
||||
<table class="scan-table">
|
||||
<thead>
|
||||
@@ -46,26 +95,5 @@
|
||||
<p>{{ report }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
<!-- CSV File Format Card (last) -->
|
||||
<div class="card scan-form-card" style="margin-bottom: 24px;">
|
||||
<h3>CSV File Format</h3>
|
||||
<label style="margin-bottom: 8px; display: block;">Fisierul CSV trebuie sa aiba urmatorul format:</label>
|
||||
<table class="scan-table" style="width: 100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Location Code</th>
|
||||
<th>Size</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>EX123</td>
|
||||
<td>100</td>
|
||||
<td>Zona depozitare A</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<div class="dashboard-card">
|
||||
<h3>Create Warehouse Locations</h3>
|
||||
<p>Define and manage storage locations in the warehouse.</p>
|
||||
<a href="{{ url_for('main.create_locations') }}" class="btn">Go to Locations</a>
|
||||
<a href="{{ url_for('warehouse.create_locations') }}" class="btn">Go to Locations</a>
|
||||
</div>
|
||||
|
||||
<!-- Card 3: Warehouse Reports -->
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import mariadb
|
||||
from flask import current_app, request, render_template
|
||||
import csv
|
||||
from flask import current_app, request, render_template, session, redirect, url_for
|
||||
import csv, os, tempfile
|
||||
|
||||
def get_db_connection():
|
||||
settings_file = current_app.instance_path + '/external_server.conf'
|
||||
@@ -90,23 +90,42 @@ def import_locations_csv_handler():
|
||||
report = None
|
||||
locations = []
|
||||
errors = []
|
||||
temp_dir = tempfile.gettempdir()
|
||||
if request.method == 'POST':
|
||||
file = request.files.get('csv_file')
|
||||
if file and file.filename.endswith('.csv'):
|
||||
content = file.read().decode('utf-8').splitlines()
|
||||
reader = csv.DictReader(content)
|
||||
locations = [(row.get('location_code'), row.get('size'), row.get('description')) for row in reader]
|
||||
if request.form.get('create_locations'):
|
||||
added = 0
|
||||
failed = 0
|
||||
errors = []
|
||||
for loc in locations:
|
||||
location_code, size, description = loc
|
||||
result = add_location(location_code, size, description)
|
||||
if result and 'success' in result.lower():
|
||||
added += 1
|
||||
else:
|
||||
failed += 1
|
||||
errors.append(location_code)
|
||||
report = f"{added} locations were added to warehouse_locations table. {failed} locations failed: {', '.join(errors)}"
|
||||
temp_path = os.path.join(temp_dir, file.filename)
|
||||
file.save(temp_path)
|
||||
session['csv_filename'] = file.filename
|
||||
session['csv_filepath'] = temp_path
|
||||
with open(temp_path, 'r', encoding='utf-8') as f:
|
||||
reader = csv.DictReader(f)
|
||||
locations = []
|
||||
for row in reader:
|
||||
location_code = row.get('Location Code') or row.get('location_code') or ''
|
||||
size = row.get('Size') or row.get('size') or ''
|
||||
description = row.get('Description') or row.get('description') or ''
|
||||
locations.append((location_code, size, description))
|
||||
session['csv_locations'] = locations
|
||||
elif 'csv_locations' in session:
|
||||
locations = session['csv_locations']
|
||||
if request.form.get('create_locations') and locations:
|
||||
added = 0
|
||||
failed = 0
|
||||
errors = []
|
||||
for loc in locations:
|
||||
location_code, size, description = loc
|
||||
result = add_location(location_code, size, description)
|
||||
if result and 'success' in result.lower():
|
||||
added += 1
|
||||
else:
|
||||
failed += 1
|
||||
errors.append(location_code or '')
|
||||
report = f"{added} locations were added to warehouse_locations table. {failed} locations failed: {', '.join(errors)}"
|
||||
session.pop('csv_locations', None)
|
||||
session.pop('csv_filename', None)
|
||||
session.pop('csv_filepath', None)
|
||||
return redirect(url_for('warehouse.import_locations_csv') + '#created')
|
||||
elif 'csv_locations' in session:
|
||||
locations = session['csv_locations']
|
||||
return render_template('import_locations_csv.html', report=report, locations=locations)
|
||||
|
||||
Reference in New Issue
Block a user