Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -4,15 +4,16 @@ import api from 'src/services/api'
|
||||
|
||||
export const useStatementdetailStore = defineStore('statementdetail', {
|
||||
state: () => ({
|
||||
details: [],
|
||||
detailsByRow: {},
|
||||
detailsByBelge: {},
|
||||
loading: false,
|
||||
error: null
|
||||
}),
|
||||
|
||||
actions: {
|
||||
async loadDetails ({ accountCode, startDate, endDate, parislemler }) {
|
||||
async loadDetails ({ accountCode, belgeNo, rowKey }) {
|
||||
if (!accountCode) {
|
||||
this.error = 'Geçerli bir cari kod seçilmedi.'
|
||||
this.error = 'Gecerli bir cari kod secilmedi.'
|
||||
return
|
||||
}
|
||||
|
||||
@@ -20,46 +21,74 @@ export const useStatementdetailStore = defineStore('statementdetail', {
|
||||
this.error = null
|
||||
|
||||
try {
|
||||
// ✅ Params (arrayFormat=repeat global)
|
||||
const params = {
|
||||
startdate: startDate,
|
||||
enddate: endDate
|
||||
const normalizedBelgeNo = String(belgeNo || '').trim()
|
||||
const params = { belgeno: normalizedBelgeNo }
|
||||
|
||||
if (this.detailsByBelge[normalizedBelgeNo]) {
|
||||
const keyCached = String(rowKey || '').trim()
|
||||
if (keyCached) {
|
||||
this.detailsByRow[keyCached] = this.detailsByBelge[normalizedBelgeNo]
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (Array.isArray(parislemler) && parislemler.length > 0) {
|
||||
params.parislemler = parislemler.filter(
|
||||
p => p !== undefined && p !== null && p !== ''
|
||||
)
|
||||
}
|
||||
|
||||
// 🔐 TOKEN + SERIALIZER + ERROR HANDLING OTOMATİK
|
||||
const res = await api.get(
|
||||
`/statements/${accountCode}/details`,
|
||||
`/statements/${encodeURIComponent(accountCode)}/details`,
|
||||
{ params }
|
||||
)
|
||||
|
||||
this.details = res.data || []
|
||||
|
||||
const key = String(rowKey || '').trim()
|
||||
const rows = Array.isArray(res.data) ? res.data : []
|
||||
if (normalizedBelgeNo) {
|
||||
this.detailsByBelge[normalizedBelgeNo] = rows
|
||||
}
|
||||
if (key) {
|
||||
this.detailsByRow[key] = rows
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('❌ Details yüklenemedi:', err)
|
||||
console.error('Details yuklenemedi:', err)
|
||||
this.error =
|
||||
err?.data?.message ||
|
||||
err?.message ||
|
||||
'Detaylar yüklenemedi'
|
||||
'Detaylar yuklenemedi'
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
|
||||
getDetailsByBelge (belgeNo) {
|
||||
const needle = String(belgeNo || '').trim()
|
||||
return this.details.filter(
|
||||
d => String(d.belge_ref_numarasi || '').trim() === needle
|
||||
)
|
||||
hasDetailsByRowKey (rowKey) {
|
||||
const key = String(rowKey || '').trim()
|
||||
return Array.isArray(this.detailsByRow[key])
|
||||
},
|
||||
|
||||
getDetailsByRowKey (rowKey) {
|
||||
const key = String(rowKey || '').trim()
|
||||
return this.detailsByRow[key] || []
|
||||
},
|
||||
|
||||
async preloadForRows ({ accountCode, rows, getRowKey }) {
|
||||
const tasks = []
|
||||
|
||||
for (const row of rows || []) {
|
||||
const belgeNo = String(row?.belge_no || '').trim()
|
||||
if (!belgeNo || belgeNo === 'Baslangic_devir') continue
|
||||
|
||||
const rowKey = String(getRowKey(row) || '').trim()
|
||||
if (!rowKey) continue
|
||||
if (this.hasDetailsByRowKey(rowKey)) continue
|
||||
|
||||
tasks.push(
|
||||
this.loadDetails({ accountCode, belgeNo, rowKey })
|
||||
)
|
||||
}
|
||||
|
||||
if (tasks.length === 0) return
|
||||
await Promise.all(tasks)
|
||||
},
|
||||
|
||||
reset () {
|
||||
this.details = []
|
||||
this.detailsByRow = {}
|
||||
this.detailsByBelge = {}
|
||||
this.loading = false
|
||||
this.error = null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user