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>
|
<input type="text" name="description" maxlength="250"><br>
|
||||||
<button type="submit" class="btn">Add Location</button>
|
<button type="submit" class="btn">Add Location</button>
|
||||||
</form>
|
</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>
|
</div>
|
||||||
<!-- Locations Table Card -->
|
<!-- Locations Table Card -->
|
||||||
<div class="card scan-table-card">
|
<div class="card scan-table-card">
|
||||||
@@ -42,13 +50,5 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -2,20 +2,69 @@
|
|||||||
{% block title %}Import Warehouse Locations from CSV{% endblock %}
|
{% block title %}Import Warehouse Locations from CSV{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="scan-container">
|
<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;">
|
<div class="card scan-form-card" style="margin-bottom: 24px;">
|
||||||
<h3>Import Locations from CSV</h3>
|
<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>
|
<label for="csv_file">Choose CSV file:</label>
|
||||||
<input type="file" name="csv_file" accept=".csv" required><br>
|
{% if not locations %}
|
||||||
<button type="submit" class="btn">Upload & Preview</button>
|
<input type="file" name="csv_file" accept=".csv" required><br>
|
||||||
{% if locations %}
|
<button type="submit" class="btn">Upload & Preview</button>
|
||||||
<button type="submit" name="create_locations" value="1" class="btn" style="margin-left: 12px;">Create Locations</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 %}
|
{% 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>
|
</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>
|
</div>
|
||||||
<!-- Preview Table Card (always visible) -->
|
<!-- Preview Table Card (expandable height, scrollable) -->
|
||||||
<div class="card scan-table-card" style="margin-bottom: 24px;">
|
<div class="card scan-table-card" style="margin-bottom: 24px; max-height: 480px; overflow-y: auto;">
|
||||||
<h3>Preview Table</h3>
|
<h3>Preview Table</h3>
|
||||||
<table class="scan-table">
|
<table class="scan-table">
|
||||||
<thead>
|
<thead>
|
||||||
@@ -46,26 +95,5 @@
|
|||||||
<p>{{ report }}</p>
|
<p>{{ report }}</p>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% 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>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
<div class="dashboard-card">
|
<div class="dashboard-card">
|
||||||
<h3>Create Warehouse Locations</h3>
|
<h3>Create Warehouse Locations</h3>
|
||||||
<p>Define and manage storage locations in the warehouse.</p>
|
<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>
|
</div>
|
||||||
|
|
||||||
<!-- Card 3: Warehouse Reports -->
|
<!-- Card 3: Warehouse Reports -->
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import mariadb
|
import mariadb
|
||||||
from flask import current_app, request, render_template
|
from flask import current_app, request, render_template, session, redirect, url_for
|
||||||
import csv
|
import csv, os, tempfile
|
||||||
|
|
||||||
def get_db_connection():
|
def get_db_connection():
|
||||||
settings_file = current_app.instance_path + '/external_server.conf'
|
settings_file = current_app.instance_path + '/external_server.conf'
|
||||||
@@ -90,23 +90,42 @@ def import_locations_csv_handler():
|
|||||||
report = None
|
report = None
|
||||||
locations = []
|
locations = []
|
||||||
errors = []
|
errors = []
|
||||||
|
temp_dir = tempfile.gettempdir()
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
file = request.files.get('csv_file')
|
file = request.files.get('csv_file')
|
||||||
if file and file.filename.endswith('.csv'):
|
if file and file.filename.endswith('.csv'):
|
||||||
content = file.read().decode('utf-8').splitlines()
|
temp_path = os.path.join(temp_dir, file.filename)
|
||||||
reader = csv.DictReader(content)
|
file.save(temp_path)
|
||||||
locations = [(row.get('location_code'), row.get('size'), row.get('description')) for row in reader]
|
session['csv_filename'] = file.filename
|
||||||
if request.form.get('create_locations'):
|
session['csv_filepath'] = temp_path
|
||||||
added = 0
|
with open(temp_path, 'r', encoding='utf-8') as f:
|
||||||
failed = 0
|
reader = csv.DictReader(f)
|
||||||
errors = []
|
locations = []
|
||||||
for loc in locations:
|
for row in reader:
|
||||||
location_code, size, description = loc
|
location_code = row.get('Location Code') or row.get('location_code') or ''
|
||||||
result = add_location(location_code, size, description)
|
size = row.get('Size') or row.get('size') or ''
|
||||||
if result and 'success' in result.lower():
|
description = row.get('Description') or row.get('description') or ''
|
||||||
added += 1
|
locations.append((location_code, size, description))
|
||||||
else:
|
session['csv_locations'] = locations
|
||||||
failed += 1
|
elif 'csv_locations' in session:
|
||||||
errors.append(location_code)
|
locations = session['csv_locations']
|
||||||
report = f"{added} locations were added to warehouse_locations table. {failed} locations failed: {', '.join(errors)}"
|
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)
|
return render_template('import_locations_csv.html', report=report, locations=locations)
|
||||||
|
|||||||
Reference in New Issue
Block a user