Merge remote-tracking branch 'origin/master'

This commit is contained in:
M_Kececi
2026-06-02 16:14:54 +03:00
parent 5f3e975b6d
commit b4e87cfd47
25 changed files with 4918 additions and 287 deletions

View File

@@ -42,6 +42,7 @@ function mapRow (raw, index, baseIndex = 0) {
productCode: toText(raw?.ProductCode),
stockQty: toNumber(raw?.StockQty),
stockEntryDate: toText(raw?.StockEntryDate),
lastCostingDate: toText(raw?.LastCostingDate),
lastPricingDate: toText(raw?.LastPricingDate),
askiliYan: toText(raw?.AskiliYan),
kategori: toText(raw?.Kategori),
@@ -54,26 +55,26 @@ function mapRow (raw, index, baseIndex = 0) {
brandGroupSelection: toText(raw?.BrandGroupSec),
costPrice: toNumber(raw?.CostPrice),
expenseForBasePrice: 0,
basePriceUsd: 0,
basePriceTry: 0,
usd1: 0,
usd2: 0,
usd3: 0,
usd4: 0,
usd5: 0,
usd6: 0,
eur1: 0,
eur2: 0,
eur3: 0,
eur4: 0,
eur5: 0,
eur6: 0,
try1: 0,
try2: 0,
try3: 0,
try4: 0,
try5: 0,
try6: 0
basePriceUsd: toNumber(raw?.BasePriceUsd),
basePriceTry: toNumber(raw?.BasePriceTry),
usd1: toNumber(raw?.USD1),
usd2: toNumber(raw?.USD2),
usd3: toNumber(raw?.USD3),
usd4: toNumber(raw?.USD4),
usd5: toNumber(raw?.USD5),
usd6: toNumber(raw?.USD6),
eur1: toNumber(raw?.EUR1),
eur2: toNumber(raw?.EUR2),
eur3: toNumber(raw?.EUR3),
eur4: toNumber(raw?.EUR4),
eur5: toNumber(raw?.EUR5),
eur6: toNumber(raw?.EUR6),
try1: toNumber(raw?.TRY1),
try2: toNumber(raw?.TRY2),
try3: toNumber(raw?.TRY3),
try4: toNumber(raw?.TRY4),
try5: toNumber(raw?.TRY5),
try6: toNumber(raw?.TRY6)
}
}
@@ -95,11 +96,18 @@ function normalizeFilters (filters = {}) {
return out
}
function hasPrimaryFilter (filters = {}) {
return (Array.isArray(filters.urun_ilk_grubu) && filters.urun_ilk_grubu.length > 0) ||
(Array.isArray(filters.urun_ana_grubu) && filters.urun_ana_grubu.length > 0)
}
function makeCacheKey (limit, page, filters) {
return JSON.stringify({
limit: Number(limit) || 500,
page: Number(page) || 1,
filters: normalizeFilters(filters)
filters: normalizeFilters(filters),
sortBy: toText(filters?.__sortBy),
descending: Boolean(filters?.__descending)
})
}
@@ -145,6 +153,8 @@ export const useProductPricingStore = defineStore('product-pricing-store', {
const limit = Number(options?.limit) > 0 ? Number(options.limit) : 500
const page = Number(options?.page) > 0 ? Number(options.page) : 1
const filters = normalizeFilters(options?.filters || {})
const sortBy = toText(options?.sortBy)
const descending = Boolean(options?.descending)
const key = makeCacheKey(limit, page, filters)
if (this.pageCache[key]) return
if (this.prefetchInFlight[key]) {
@@ -153,7 +163,12 @@ export const useProductPricingStore = defineStore('product-pricing-store', {
}
const run = async () => {
try {
const params = { limit, page }
const includeTotal = hasPrimaryFilter(filters) ? 1 : 0
const params = { limit, page, include_total: includeTotal }
if (sortBy) {
params.sort_by = sortBy
params.desc = descending ? 1 : 0
}
for (const k of Object.keys(filters)) {
if (k === 'q') {
params.q = filters.q
@@ -169,11 +184,14 @@ export const useProductPricingStore = defineStore('product-pricing-store', {
params,
timeout: 180000
})
const totalCount = Number(res?.headers?.['x-total-count'] || 0)
const totalPages = Math.max(1, Number(res?.headers?.['x-total-pages'] || 1))
const currentPage = Math.max(1, Number(res?.headers?.['x-page'] || page))
const data = Array.isArray(res?.data) ? res.data : []
const mapped = data.map((x, i) => mapRow(x, i, 0))
const totalCount = Number(res?.headers?.['x-total-count'] || 0)
let totalPages = Math.max(1, Number(res?.headers?.['x-total-pages'] || 0))
const currentPage = Math.max(1, Number(res?.headers?.['x-page'] || page))
const data = Array.isArray(res?.data) ? res.data : []
const mapped = data.map((x, i) => mapRow(x, i, 0))
if (!Number.isFinite(totalPages) || totalPages <= 0) {
totalPages = mapped.length >= limit ? currentPage + 1 : currentPage
}
this.cachePut(key, {
rows: mapped,
totalCount: Number.isFinite(totalCount) ? totalCount : 0,
@@ -202,6 +220,8 @@ export const useProductPricingStore = defineStore('product-pricing-store', {
const append = Boolean(options?.append)
const baseIndex = append ? this.rows.length : 0
const filters = normalizeFilters(options?.filters || {})
const sortBy = toText(options?.sortBy)
const descending = Boolean(options?.descending)
const cacheKey = makeCacheKey(limit, page, filters)
const startedAt = Date.now()
console.info('[product-pricing][frontend] request:start', {
@@ -237,7 +257,12 @@ export const useProductPricingStore = defineStore('product-pricing-store', {
}
}
const params = { limit, page }
const includeTotal = hasPrimaryFilter(filters) ? 1 : 0
const params = { limit, page, include_total: includeTotal }
if (sortBy) {
params.sort_by = sortBy
params.desc = descending ? 1 : 0
}
for (const key of Object.keys(filters)) {
if (key === 'q') {
params.q = filters.q
@@ -253,11 +278,15 @@ export const useProductPricingStore = defineStore('product-pricing-store', {
timeout: 180000
})
const traceId = res?.headers?.['x-trace-id'] || null
const totalCount = Number(res?.headers?.['x-total-count'] || 0)
const totalPages = Math.max(1, Number(res?.headers?.['x-total-pages'] || 1))
const currentPage = Math.max(1, Number(res?.headers?.['x-page'] || page))
const data = Array.isArray(res?.data) ? res.data : []
const totalCount = Number(res?.headers?.['x-total-count'] || 0)
let totalPages = Math.max(1, Number(res?.headers?.['x-total-pages'] || 0))
const currentPage = Math.max(1, Number(res?.headers?.['x-page'] || page))
const data = Array.isArray(res?.data) ? res.data : []
const mapped = data.map((x, i) => mapRow(x, i, baseIndex))
if (!Number.isFinite(totalPages) || totalPages <= 0) {
// When server skips count, infer "hasMore" from page size.
totalPages = mapped.length >= limit ? currentPage + 1 : currentPage
}
const payload = {
rows: mapped,
totalCount: Number.isFinite(totalCount) ? totalCount : 0,
@@ -265,7 +294,15 @@ export const useProductPricingStore = defineStore('product-pricing-store', {
page: Number.isFinite(currentPage) ? currentPage : page
}
this.cachePut(cacheKey, payload)
this.applyPageResult(payload, page)
if (append) {
this.rows = [...cloneRows(this.rows || []), ...mapped.map((r) => ({ ...r }))]
this.totalCount = Number.isFinite(payload.totalCount) ? payload.totalCount : this.totalCount
this.totalPages = Math.max(1, Number(payload.totalPages || this.totalPages || 1))
this.page = Math.max(1, Number(payload.page || page))
this.hasMore = this.page < this.totalPages
} else {
this.applyPageResult(payload, page)
}
// Background prefetch for next page to reduce perceived wait on page change.
if (this.page < this.totalPages) {
@@ -311,6 +348,8 @@ export const useProductPricingStore = defineStore('product-pricing-store', {
}
},
// fetchAllByGroups removed: keep paging server-side.
updateCell (row, field, val) {
if (!row || !field) return
row[field] = toNumber(val)