- Update Destinataer template: added 8 missing fields (ist_abkoemmling, haushaltsgroesse, monatliche_bezuege, vermoegen, unterstuetzung_bestaetigt, vierteljaehrlicher_betrag, studiennachweis_erforderlich, letzter_studiennachweis) - Update Laendereien template: added 20 missing fields including property details, tenant info, contract terms, financial data, and tax information - Fix JavaScript template download functionality: correct block name from extra_js to javascript - Add comprehensive debugging and error handling for download process - Improve CSV formatting with proper quoting for text fields containing spaces - Add fallback download methods for better browser compatibility All CSV templates now include complete field sets matching current model definitions.
236 lines
14 KiB
HTML
236 lines
14 KiB
HTML
{% extends 'base.html' %}
|
|
|
|
{% block title %}CSV Import - Stiftungsverwaltung{% endblock %}
|
|
|
|
{% block content %}
|
|
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1><i class="fas fa-file-csv text-primary"></i> CSV Import</h1>
|
|
<a href="{% url 'stiftung:csv_import_list' %}" class="btn btn-outline-secondary">
|
|
<i class="fas fa-list"></i> Import-Verlauf
|
|
</a>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-lg-8">
|
|
<div class="card shadow-sm">
|
|
<div class="card-header bg-primary text-white">
|
|
<h5 class="card-title mb-0">
|
|
<i class="fas fa-upload"></i> Neue CSV-Datei importieren
|
|
</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<form method="post" enctype="multipart/form-data">
|
|
{% csrf_token %}
|
|
|
|
<div class="mb-3">
|
|
<label for="import_type" class="form-label">
|
|
<strong>Import-Typ *</strong>
|
|
</label>
|
|
<select name="import_type" id="import_type" class="form-select" required>
|
|
<option value="">Bitte wählen...</option>
|
|
{% for value, label in import_types %}
|
|
<option value="{{ value }}">{{ label }}</option>
|
|
{% endfor %}
|
|
</select>
|
|
<div class="form-text">Wählen Sie den Typ der zu importierenden Daten aus.</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="csv_file" class="form-label">
|
|
<strong>CSV-Datei *</strong>
|
|
</label>
|
|
<input type="file" name="csv_file" id="csv_file"
|
|
class="form-control" accept=".csv" required>
|
|
<div class="form-text">Nur CSV-Dateien werden unterstützt.</div>
|
|
</div>
|
|
|
|
<div class="d-grid gap-2 d-md-flex justify-content-md-end">
|
|
<a href="{% url 'stiftung:home' %}" class="btn btn-outline-secondary me-md-2">
|
|
<i class="fas fa-times"></i> Abbrechen
|
|
</a>
|
|
<button type="submit" class="btn btn-primary">
|
|
<i class="fas fa-upload"></i> Import starten
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-lg-4">
|
|
<div class="card shadow-sm">
|
|
<div class="card-header bg-info text-white">
|
|
<h6 class="card-title mb-0">
|
|
<i class="fas fa-info-circle"></i> Import-Informationen
|
|
</h6>
|
|
</div>
|
|
<div class="card-body">
|
|
<h6>Destinatäre Import:</h6>
|
|
<ul class="list-unstyled small">
|
|
<li><strong>Pflichtfelder:</strong> Vorname, Nachname</li>
|
|
<li><strong>Optionale Felder:</strong> E-Mail, Telefon, IBAN, Straße, PLZ, Ort, Notizen, Geburtsdatum, Familienzweig, Berufsgruppe, Ausbildungsstand, Institution, Projektbeschreibung, Jährliches_Einkommen, Finanzielle_Notlage, Aktiv</li>
|
|
<li><strong>Format:</strong> UTF-8 CSV mit Komma oder Semikolon als Trennzeichen</li>
|
|
</ul>
|
|
|
|
<hr>
|
|
|
|
<h6>Pächter Import:</h6>
|
|
<ul class="list-unstyled small">
|
|
<li><strong>Pflichtfelder:</strong> Vorname, Nachname</li>
|
|
<li><strong>Optionale Felder:</strong> E-Mail, Telefon, IBAN, Straße, PLZ, Ort, Personentyp, Notizen, Geburtsdatum, Pachtnummer, Pachtbeginn_Erste, Pachtende_Letzte, Pachtzins_Aktuell, Landwirtschaftliche_Ausbildung, Berufserfahrung_Jahre, Spezialisierung, Aktiv</li>
|
|
<li><strong>Format:</strong> UTF-8 CSV mit Komma oder Semikolon als Trennzeichen</li>
|
|
</ul>
|
|
|
|
<hr>
|
|
|
|
<h6>Ländereien Import:</h6>
|
|
<ul class="list-unstyled small">
|
|
<li><strong>Pflichtfelder:</strong> Lfd_Nr, Gemeinde, Gemarkung, Flur, Flurstück</li>
|
|
<li><strong>Optionale Felder:</strong> EW_Nummer, Amtsgericht, Größe_qm, Grünland_qm, Acker_qm, Wald_qm, Sonstiges_qm, Verpachtete_Gesamtfläche_qm, Verp_Fläche_aktuell_qm, Aktiv, Notizen</li>
|
|
<li><strong>Format:</strong> UTF-8 CSV mit Komma oder Semikolon als Trennzeichen</li>
|
|
</ul>
|
|
|
|
<hr>
|
|
|
|
<h6>Personen Import (Legacy):</h6>
|
|
<ul class="list-unstyled small">
|
|
<li><strong>Pflichtfelder:</strong> Vorname, Nachname</li>
|
|
<li><strong>Optionale Felder:</strong> E-Mail, Telefon, IBAN, Adresse, Notizen, Geburtsdatum, Familienzweig, Aktiv</li>
|
|
<li><strong>Format:</strong> UTF-8 CSV mit Komma oder Semikolon als Trennzeichen</li>
|
|
<li><strong>Hinweis:</strong> Nur für Legacy-Daten, neue Daten sollten als Destinatäre oder Pächter importiert werden</li>
|
|
</ul>
|
|
|
|
<div class="alert alert-warning mt-3">
|
|
<i class="fas fa-exclamation-triangle"></i>
|
|
<strong>Hinweis:</strong> Bestehende Datensätze werden aktualisiert, wenn sie anhand der eindeutigen Felder gefunden werden.
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card shadow-sm mt-3">
|
|
<div class="card-header bg-success text-white">
|
|
<h6 class="card-title mb-0">
|
|
<i class="fas fa-download"></i> CSV-Vorlagen herunterladen
|
|
</h6>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="d-grid gap-2">
|
|
<a href="#" class="btn btn-outline-success btn-sm" onclick="downloadTemplate('destinataere'); return false;">
|
|
<i class="fas fa-download"></i> Destinatäre-Vorlage
|
|
</a>
|
|
<a href="#" class="btn btn-outline-success btn-sm" onclick="downloadTemplate('paechter'); return false;">
|
|
<i class="fas fa-download"></i> Pächter-Vorlage
|
|
</a>
|
|
<a href="#" class="btn btn-outline-success btn-sm" onclick="downloadTemplate('laendereien'); return false;">
|
|
<i class="fas fa-download"></i> Ländereien-Vorlage
|
|
</a>
|
|
<a href="#" class="btn btn-outline-secondary btn-sm" onclick="downloadTemplate('personen'); return false;">
|
|
<i class="fas fa-download"></i> Personen-Vorlage (Legacy)
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{% endblock %}
|
|
|
|
{% block javascript %}
|
|
<script>
|
|
function downloadTemplate(type) {
|
|
console.log('downloadTemplate called with type:', type);
|
|
let headers, filename, exampleRow;
|
|
|
|
if (type === 'destinataere') {
|
|
headers = ['Vorname', 'Nachname', 'Familienzweig', 'E-Mail', 'Telefon', 'IBAN', 'Straße', 'PLZ', 'Ort', 'Geburtsdatum', 'Berufsgruppe', 'Ausbildungsstand', 'Institution', 'Projektbeschreibung', 'Jährliches_Einkommen', 'Finanzielle_Notlage', 'Ist_Abkömmling', 'Haushaltsgroesse', 'Monatliche_Bezuege', 'Vermoegen', 'Unterstuetzung_Bestaetigt', 'Vierteljaehrlicher_Betrag', 'Studiennachweis_Erforderlich', 'Letzter_Studiennachweis', 'Notizen', 'Aktiv'];
|
|
filename = 'destinataere_vorlage.csv';
|
|
exampleRow = 'Max,Mustermann,hauptzweig,max@email.com,0123456789,DE12345678901234567890,Musterstraße 1,12345,Musterstadt,01.01.1990,student,Abitur,Universität Musterstadt,Studium der Informatik,15000,false,true,1,500,10000,false,400,false,,Beispiel Notiz,true';
|
|
} else if (type === 'paechter') {
|
|
headers = ['Vorname', 'Nachname', 'E-Mail', 'Telefon', 'IBAN', 'Straße', 'PLZ', 'Ort', 'Personentyp', 'Geburtsdatum', 'Pachtnummer', 'Pachtbeginn_Erste', 'Pachtende_Letzte', 'Pachtzins_Aktuell', 'Landwirtschaftliche_Ausbildung', 'Berufserfahrung_Jahre', 'Spezialisierung', 'Notizen', 'Aktiv'];
|
|
filename = 'paechter_vorlage.csv';
|
|
exampleRow = 'Hans,Bauer,hans@email.com,0123456789,DE12345678901234567890,Bauernhof 1,12345,Bauerndorf,natuerlich,01.01.1980,P001,01.01.2020,31.12.2029,5000,true,15,Ackerbau,Beispiel Notiz,true';
|
|
} else if (type === 'laendereien') {
|
|
headers = ['Lfd_Nr', 'EW_Nummer', 'Grundbuchblatt', 'Amtsgericht', 'Gemeinde', 'Gemarkung', 'Flur', 'Flurstück', 'Adresse', 'Größe_qm', 'Grünland_qm', 'Acker_qm', 'Wald_qm', 'Sonstiges_qm', 'Verpachtete_Gesamtfläche_qm', 'Fläche_alte_Liste_qm', 'Verp_Fläche_aktuell_qm', 'Aktueller_Pächter', 'Pächter_Name', 'Pächter_Anschrift', 'Pachtbeginn', 'Pachtende', 'Verlängerung_Klausel', 'Zahlungsweise', 'Pachtzins_pro_ha', 'Pachtzins_pauschal', 'USt_Option', 'USt_Satz', 'Grundsteuer_Umlage', 'Versicherungen_Umlage', 'Verbandsbeiträge_Umlage', 'Jagdpacht_Anteil_Umlage', 'Anteil_Grundsteuer', 'Anteil_LWK', 'Aktiv', 'Notizen'];
|
|
filename = 'laendereien_vorlage.csv';
|
|
exampleRow = 'L001,EW001,Grundbuch123,Amtsgericht Musterstadt,Musterstadt,Mustergemarkung,1,123,"Musterfeld 1",10000,5000,3000,1500,500,8000,7500,8000,,Max Musterpächter,"Max Musterpächter Bauernhof 1 12345 Dorf",2020-01-01,2029-12-31,true,jaehrlich,500.00,4000.00,false,19.00,true,true,true,false,100.00,50.00,true,"Beispiel Notiz"';
|
|
} else if (type === 'personen') {
|
|
headers = ['Vorname', 'Nachname', 'Familienzweig', 'E-Mail', 'Telefon', 'IBAN', 'Adresse', 'Geburtsdatum', 'Notizen', 'Aktiv'];
|
|
filename = 'personen_legacy_vorlage.csv';
|
|
exampleRow = 'Beispiel,Beispiel,hauptzweig,beispiel@email.com,0123456789,DE12345678901234567890,Beispielstraße 1,01.01.1990,Beispiel Notiz,true';
|
|
}
|
|
|
|
console.log('Headers count:', headers ? headers.length : 'undefined');
|
|
console.log('Filename:', filename);
|
|
|
|
// Create CSV content
|
|
const csvContent = headers.join(',') + '\n' + exampleRow;
|
|
console.log('CSV content length:', csvContent.length);
|
|
|
|
try {
|
|
// Create download link
|
|
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
|
|
|
|
// Try the modern approach first
|
|
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
|
|
// For IE/Edge
|
|
window.navigator.msSaveOrOpenBlob(blob, filename);
|
|
console.log('Download via IE/Edge method');
|
|
} else {
|
|
// For other browsers
|
|
const link = document.createElement('a');
|
|
const url = URL.createObjectURL(blob);
|
|
link.setAttribute('href', url);
|
|
link.setAttribute('download', filename);
|
|
link.style.visibility = 'hidden';
|
|
link.style.display = 'none';
|
|
document.body.appendChild(link);
|
|
|
|
// Force click
|
|
setTimeout(() => {
|
|
link.click();
|
|
console.log('Link clicked');
|
|
|
|
// Clean up
|
|
setTimeout(() => {
|
|
document.body.removeChild(link);
|
|
URL.revokeObjectURL(url);
|
|
console.log('Cleanup completed');
|
|
}, 100);
|
|
}, 100);
|
|
}
|
|
console.log('Download should have started for:', filename);
|
|
} catch (error) {
|
|
console.error('Error in download:', error);
|
|
|
|
// Fallback: try data URL approach
|
|
try {
|
|
const dataUrl = 'data:text/csv;charset=utf-8,' + encodeURIComponent(csvContent);
|
|
const link = document.createElement('a');
|
|
link.setAttribute('href', dataUrl);
|
|
link.setAttribute('download', filename);
|
|
link.click();
|
|
console.log('Fallback download method used');
|
|
} catch (fallbackError) {
|
|
console.error('Fallback download also failed:', fallbackError);
|
|
alert('Fehler beim Download: ' + error.message + '\n\nBitte kopieren Sie den CSV-Inhalt aus der Browserkonsole.');
|
|
console.log('CSV Content for manual copy:\n' + csvContent);
|
|
}
|
|
}
|
|
}
|
|
|
|
// File validation
|
|
document.getElementById('csv_file').addEventListener('change', function(e) {
|
|
const file = e.target.files[0];
|
|
if (file && !file.name.toLowerCase().endsWith('.csv')) {
|
|
alert('Bitte wählen Sie eine gültige CSV-Datei aus.');
|
|
this.value = '';
|
|
}
|
|
});
|
|
</script>
|
|
{% endblock %}
|