@@ -4,6 +4,7 @@ const fileInput = document.getElementById('fileInput');
4
4
const fileList = document . getElementById ( 'fileList' ) ;
5
5
const progressBar = document . getElementById ( 'progressBar' ) . firstElementChild ;
6
6
const analyzeButton = document . getElementById ( 'analyzeButton' ) ;
7
+ const invoiceNameInput = document . getElementById ( 'invoiceName' ) ; // Yeni input alanı
7
8
let selectedFiles = [ ] ;
8
9
9
10
// Sürükle-bırak ve dosya seçme olayları
@@ -49,16 +50,26 @@ function handleFiles(files) {
49
50
selectedFiles = Array . from ( files . target . files ) ;
50
51
}
51
52
updateFileList ( ) ;
52
- analyzeButton . disabled = selectedFiles . length === 0 ;
53
+ analyzeButton . disabled = selectedFiles . length === 0 || ! invoiceNameInput . value . trim ( ) ;
53
54
}
54
55
56
+ invoiceNameInput . addEventListener ( 'input' , ( ) => {
57
+ analyzeButton . disabled = selectedFiles . length === 0 || ! invoiceNameInput . value . trim ( ) ;
58
+ } ) ;
59
+
55
60
function updateFileList ( ) {
56
61
fileList . innerHTML = selectedFiles . map ( file => `<p>${ file . name } </p>` ) . join ( '' ) ;
57
62
}
58
63
59
64
analyzeButton . addEventListener ( 'click' , analyzeInvoices ) ;
60
65
61
66
async function analyzeInvoices ( ) {
67
+ const invoiceName = invoiceNameInput . value . trim ( ) ;
68
+ if ( ! invoiceName ) {
69
+ alert ( "Lütfen satıcı veya alıcı adını giriniz!" ) ;
70
+ return ;
71
+ }
72
+
62
73
analyzeButton . disabled = true ;
63
74
const totalFiles = selectedFiles . length ;
64
75
let processedFiles = 0 ;
@@ -72,7 +83,7 @@ async function analyzeInvoices() {
72
83
}
73
84
74
85
for ( const chunk of chunks ) {
75
- const chunkPromises = chunk . map ( file => analyzeInvoice ( file ) ) ;
86
+ const chunkPromises = chunk . map ( file => analyzeInvoice ( file , invoiceName ) ) ;
76
87
const results = await Promise . all ( chunkPromises ) ;
77
88
78
89
results . forEach ( ( result , index ) => {
@@ -95,12 +106,12 @@ function updateProgress(percentage) {
95
106
progressBar . style . width = `${ percentage } %` ;
96
107
}
97
108
98
- async function analyzeInvoice ( file ) {
109
+ async function analyzeInvoice ( file , invoiceName ) {
99
110
try {
100
- API_KEY = localStorage . getItem ( 'API_KEY' ) || API_KEY ; // Anahtarı her işlemden önce günceller.
111
+ API_KEY = localStorage . getItem ( 'API_KEY' ) || API_KEY ;
101
112
const base64 = await fileToBase64 ( file ) ;
102
113
const mimeType = file . type ;
103
-
114
+
104
115
const response = await fetch ( `https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=${ API_KEY } ` , {
105
116
method : 'POST' ,
106
117
headers : {
@@ -112,7 +123,7 @@ async function analyzeInvoice(file) {
112
123
text : `Fatura bilgilerini analiz et ve sadece aşağıdaki bilgilere ulaşmaya çalış:
113
124
- Fatura Tarihi
114
125
- Fatura Türü (Alış/Satış)
115
- - Alıcı Firma 'nın VKN veya TCKN Numarası
126
+ - Alıcı veya Satıcı 'nın VKN veya V.D. veya TCKN Numarası(vkn veya tckn asla ${ invoiceName } firmasının olmamalı)
116
127
- Fatura Numarası
117
128
- Matrah (Toplam tutar)
118
129
- KDV Tutarı
0 commit comments