upraven index.html,přidán testovací csv soubor a upraven skrip.js
This commit is contained in:
		
							
								
								
									
										16
									
								
								finance_2024_corrected.csv
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								finance_2024_corrected.csv
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | ||||
| # Vytvoření testovacího DataFrame s podobnou strukturou jako uživatelův CSV soubor | ||||
| data_corrected = { | ||||
|     'Datum': ['2024-06-04', '2024-06-05', '2024-06-10', '2024-06-17', '2024-06-18'], | ||||
|     'Popis': ['Stav účtu', 'Příspěvek @tritol128', 'Příspěvek @fabia_man', 'Příspěvek @Onqa6', 'Příspěvek D.Kolaja'], | ||||
|     'Částka': [9253.0, 512.0, 100.0, 100.0, 111.0], | ||||
|     'Měna': ['CZK', 'CZK', 'CZK', 'CZK', 'CZK'], | ||||
|     'Typ': ['Příjem', 'Příjem', 'Příjem', 'Příjem', 'Příjem'] | ||||
| } | ||||
|  | ||||
| df_corrected = pd.DataFrame(data_corrected) | ||||
|  | ||||
| # Uložení do CSV souboru | ||||
| corrected_csv_path = "/mnt/data/finance_2024_corrected.csv" | ||||
| df_corrected.to_csv(corrected_csv_path, index=False) | ||||
|  | ||||
| corrected_csv_path | ||||
| Can't render this file because it contains an unexpected character in line 13 and column 22. | 
| @@ -37,6 +37,12 @@ | ||||
|                 </tbody> | ||||
|             </table> | ||||
|         </div> | ||||
|  | ||||
|         <!-- Archiv přehledů financí --> | ||||
|         <div class="container text-center mt-4"> | ||||
|             <h2>Archiv přehledů financí</h2> | ||||
|             <button id="load-archive-2024" class="btn btn-secondary">Načíst rok 2024</button> | ||||
|         </div> | ||||
|          | ||||
|         <footer class="text-center mt-auto py-3"> | ||||
|             <p>© 2024 <a href="https://git.arch-linux.cz/Archos/prehlad-financi-komunity" target="_blank">Archos</a></p> | ||||
|   | ||||
							
								
								
									
										107
									
								
								skript.js
									
									
									
									
									
								
							
							
						
						
									
										107
									
								
								skript.js
									
									
									
									
									
								
							| @@ -1,56 +1,59 @@ | ||||
| document.addEventListener('DOMContentLoaded', function() { | ||||
|     fetch('finance.csv') | ||||
|         .then(response => { | ||||
|             if (!response.ok) { | ||||
|                 throw new Error('Network response was not ok'); | ||||
|             } | ||||
|             return response.text(); | ||||
|         }) | ||||
|         .then(data => { | ||||
|             let rows = data.split('\n').slice(1); | ||||
|             rows = rows.filter(row => row.trim() !== ""); // Remove empty rows | ||||
|             rows.reverse(); // Reverse the order of rows | ||||
|             const tableBody = document.querySelector('#finance-table tbody'); | ||||
|             let accountBalance = 0; | ||||
|             rows.forEach(row => { | ||||
|                 const columns = row.split(','); | ||||
|                 if (columns.length >= 5) { | ||||
|                     const tr = document.createElement('tr'); | ||||
|                     columns.forEach(column => { | ||||
|                         const td = document.createElement('td'); | ||||
|                         td.textContent = column.trim(); | ||||
|                         tr.appendChild(td); | ||||
|                     }); | ||||
|                     tableBody.appendChild(tr); | ||||
|  | ||||
|                     // Debug output | ||||
|                     console.log('Row:', row); | ||||
|                     console.log('Columns:', columns); | ||||
|  | ||||
|                     // Calculate account balance | ||||
|                     const amount = parseFloat(columns[2].replace(/,/g, '').replace(/[^0-9.-]/g, '')); // Remove any invalid characters and ensure proper decimal handling | ||||
|                     const currency = columns[3].trim(); | ||||
|                      | ||||
|                     // Debug output | ||||
|                     console.log('Amount:', amount); | ||||
|                     console.log('Currency:', currency); | ||||
|  | ||||
|                     if (!isNaN(amount)) { | ||||
|                         if (currency === 'CZK') { | ||||
|                             accountBalance += amount; | ||||
|                         } else if (currency === 'EUR') { | ||||
|                             // For simplicity, assume 1 EUR = 25 CZK (you can adjust the conversion rate) | ||||
|                             accountBalance += amount * 25; | ||||
|                         } | ||||
|                     } else { | ||||
|                         console.error('Invalid amount:', columns[2]); | ||||
|                     } | ||||
|     // Funkce pro načítání financí | ||||
|     function loadFinanceData(csvFile) { | ||||
|         console.log(`Načítání souboru: ${csvFile}`);  // Debug výpis | ||||
|         fetch(csvFile) | ||||
|             .then(response => { | ||||
|                 if (!response.ok) { | ||||
|                     throw new Error('Network response was not ok'); | ||||
|                 } | ||||
|                 return response.text(); | ||||
|             }) | ||||
|             .then(data => { | ||||
|                 console.log('Načtená data:', data);  // Debug výpis načtených dat | ||||
|                 let rows = data.split('\n').slice(1); // Odstraníme hlavičku CSV souboru | ||||
|                 rows = rows.filter(row => row.trim() !== ""); // Odstranit prázdné řádky | ||||
|                 rows.reverse(); // Obrátit pořadí řádků | ||||
|                 const tableBody = document.querySelector('#finance-table tbody'); | ||||
|                 tableBody.innerHTML = ''; // Vyprázdnit tabulku před načtením nových dat | ||||
|                 let accountBalance = 0; | ||||
|                 rows.forEach(row => { | ||||
|                     const columns = row.split(','); | ||||
|                     if (columns.length >= 5) { | ||||
|                         const tr = document.createElement('tr'); | ||||
|                         columns.forEach(column => { | ||||
|                             const td = document.createElement('td'); | ||||
|                             td.textContent = column.trim(); | ||||
|                             tr.appendChild(td); | ||||
|                         }); | ||||
|                         tableBody.appendChild(tr); | ||||
|  | ||||
|                         // Výpočet zůstatku | ||||
|                         const amount = parseFloat(columns[2].replace(/,/g, '').replace(/[^0-9.-]/g, '')); // Ošetření čísel | ||||
|                         const currency = columns[3].trim(); | ||||
|  | ||||
|                         if (!isNaN(amount)) { | ||||
|                             if (currency === 'CZK') { | ||||
|                                 accountBalance += amount; | ||||
|                             } else if (currency === 'EUR') { | ||||
|                                 accountBalance += amount * 25;  // Pro jednoduchost: 1 EUR = 25 CZK | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                 }); | ||||
|                 document.getElementById('account-balance').textContent = accountBalance.toFixed(2) + ' CZK'; | ||||
|             }) | ||||
|             .catch(error => { | ||||
|                 console.error('Chyba při načítání CSV souboru:', error); | ||||
|                 document.getElementById('account-balance').textContent = 'Chyba při načítání dat'; | ||||
|             }); | ||||
|             document.getElementById('account-balance').textContent = accountBalance.toFixed(2) + ' CZK'; | ||||
|         }) | ||||
|         .catch(error => { | ||||
|             console.error('Error fetching the CSV file:', error); | ||||
|             document.getElementById('account-balance').textContent = 'Chyba při načítání dat'; | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     // Načítání aktuálního souboru finance.csv | ||||
|     loadFinanceData('finance.csv');  // Soubor je ve stejné složce, proto nemusíš zadávat cestu | ||||
|  | ||||
|     // Přidání funkce pro načítání archivovaných dat za rok 2024 | ||||
|     document.getElementById('load-archive-2024').addEventListener('click', function() { | ||||
|         loadFinanceData('finance_2024_corrected.csv');  // Stejná složka pro archivovaný soubor | ||||
|     }); | ||||
| }); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user