Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -794,7 +794,27 @@ function toText (value) {
|
||||
}
|
||||
|
||||
function toNumber (value) {
|
||||
const n = Number(String(value ?? '0').replace(/\./g, '').replace(',', '.'))
|
||||
if (typeof value === 'number') return Number.isFinite(value) ? value : 0
|
||||
const text = String(value ?? '').trim().replace(/\s/g, '')
|
||||
if (!text) return 0
|
||||
const lastComma = text.lastIndexOf(',')
|
||||
const lastDot = text.lastIndexOf('.')
|
||||
let normalized = text
|
||||
if (lastComma >= 0 && lastDot >= 0) {
|
||||
normalized = lastComma > lastDot
|
||||
? text.replace(/\./g, '').replace(',', '.')
|
||||
: text.replace(/,/g, '')
|
||||
} else if (lastComma >= 0) {
|
||||
normalized = text.replace(/\./g, '').replace(',', '.')
|
||||
} else if (lastDot >= 0) {
|
||||
const parts = text.split('.')
|
||||
const lastPart = parts[parts.length - 1] || ''
|
||||
const looksLikeThousands = parts.length > 1 && lastPart.length === 3 && parts.slice(0, -1).every((p, i) => (
|
||||
i === 0 ? p.length >= 1 && p.length <= 3 : p.length === 3
|
||||
))
|
||||
normalized = looksLikeThousands ? text.replace(/\./g, '') : text
|
||||
}
|
||||
const n = Number(normalized)
|
||||
return Number.isFinite(n) ? n : 0
|
||||
}
|
||||
|
||||
@@ -1582,57 +1602,82 @@ function exportFileStamp () {
|
||||
return `${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}-${pad(d.getHours())}${pad(d.getMinutes())}`
|
||||
}
|
||||
|
||||
function buildServerPriceListExportPayload () {
|
||||
const filters = columnFilters.value || {}
|
||||
return {
|
||||
in_stock_only: !!showInStockOnly.value,
|
||||
include_meta: true,
|
||||
include_cost: false,
|
||||
include_base: false,
|
||||
price_fields: [...selectedPriceOptions.value],
|
||||
product_code: selectedProductCodes.value.length > 0 ? [...selectedProductCodes.value] : [],
|
||||
brand_group: Array.isArray(filters.brandGroupSelection) ? filters.brandGroupSelection : [],
|
||||
marka: Array.isArray(filters.marka) ? filters.marka : [],
|
||||
askili_yan: Array.isArray(filters.askiliYan) ? filters.askiliYan : [],
|
||||
kategori: Array.isArray(filters.kategori) ? filters.kategori : [],
|
||||
urun_ilk_grubu: topUrunIlkGrubu.value ? [topUrunIlkGrubu.value] : (Array.isArray(filters.urunIlkGrubu) ? filters.urunIlkGrubu : []),
|
||||
urun_ana_grubu: topUrunAnaGrubu.value ? [topUrunAnaGrubu.value] : (Array.isArray(filters.urunAnaGrubu) ? filters.urunAnaGrubu : []),
|
||||
urun_alt_grubu: Array.isArray(filters.urunAltGrubu) ? filters.urunAltGrubu : [],
|
||||
icerik: Array.isArray(filters.icerik) ? filters.icerik : [],
|
||||
karisim: Array.isArray(filters.karisim) ? filters.karisim : []
|
||||
}
|
||||
}
|
||||
|
||||
function downloadBlob (blob, fileName) {
|
||||
const url = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = fileName
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
a.remove()
|
||||
URL.revokeObjectURL(url)
|
||||
}
|
||||
|
||||
async function printVisibleRows () {
|
||||
try {
|
||||
const fileName = `Fiyat_Listesi-${exportFileStamp()}.pdf`
|
||||
const res = await api.request({
|
||||
method: 'POST',
|
||||
url: '/order/price-list/export-pdf',
|
||||
data: buildServerPriceListExportPayload(),
|
||||
responseType: 'blob',
|
||||
timeout: 0
|
||||
})
|
||||
const blob = res?.data instanceof Blob
|
||||
? res.data
|
||||
: new Blob([res?.data || ''], { type: 'application/pdf' })
|
||||
downloadBlob(blob, fileName)
|
||||
await notifyExportTaken('pdf')
|
||||
Notify.create({ type: 'positive', message: 'PDF indirildi.' })
|
||||
} catch (err) {
|
||||
Notify.create({ type: 'negative', message: err?.response?.data || err?.message || 'PDF olusturulamadi' })
|
||||
const stamp = exportFileStamp()
|
||||
const title = `Fiyat_Listesi-${stamp}`
|
||||
const cols = visibleColumns.value
|
||||
const generatedAt = new Date().toLocaleString('tr-TR')
|
||||
const body = filteredRows.value.map((row) => `<tr>${cols.map((c) => {
|
||||
if (c.name === 'image') {
|
||||
return row.imageUrl
|
||||
? `<td class="img-cell"><img src="${escapeHtml(row.imageUrl)}" class="thumb"></td>`
|
||||
: '<td class="img-cell"></td>'
|
||||
}
|
||||
const cls = [
|
||||
isExcelNumericColumn(c) ? 'num' : '',
|
||||
priceColumnNames.includes(c.name) ? 'price' : '',
|
||||
c.name.endsWith('Campaign') ? 'campaign-price' : '',
|
||||
c.name === 'karisim' ? 'wrap' : ''
|
||||
].filter(Boolean).join(' ')
|
||||
return `<td class="${cls}">${escapeHtml(exportCell(row, c))}</td>`
|
||||
}).join('')}</tr>`).join('')
|
||||
const headerCols = cols.map((c) => `<th>${escapeHtml(c.label || 'Gorsel')}</th>`).join('')
|
||||
const html = `<!doctype html><html><head><meta charset="utf-8"><title>${escapeHtml(title)}</title><style>
|
||||
@page { size: A3 landscape; margin: 8mm; }
|
||||
* { box-sizing: border-box; }
|
||||
body { font-family: Arial, sans-serif; color: #172033; font-size: 8px; margin: 0; }
|
||||
table { border-collapse: collapse; width: 100%; table-layout: fixed; }
|
||||
thead { display: table-header-group; }
|
||||
tfoot { display: table-footer-group; }
|
||||
tr { page-break-inside: avoid; break-inside: avoid; }
|
||||
th, td { border: 1px solid #cfd6df; padding: 3px; vertical-align: middle; overflow-wrap: anywhere; }
|
||||
th { background: #957116; color: #fff; text-align: center; font-weight: 700; line-height: 1.15; }
|
||||
.report-title th { background: #fff; color: #172033; border: 0; padding: 0 0 5px; text-align: left; }
|
||||
.title-main { font-size: 15px; font-weight: 800; color: #957116; }
|
||||
.title-meta { font-size: 8px; color: #56616f; margin-top: 2px; }
|
||||
td { background: #fff; line-height: 1.18; }
|
||||
.num, .price { text-align: right; font-weight: 700; white-space: nowrap; }
|
||||
.campaign-price { background: #eef7ee; color: #0f6b2f; font-weight: 800; }
|
||||
.wrap { white-space: normal; font-size: 7px; line-height: 1.1; }
|
||||
.img-cell { width: 28mm; text-align: center; padding: 2px; }
|
||||
.thumb { width: 24mm; height: 24mm; object-fit: contain; display: block; margin: 0 auto; }
|
||||
.page-footer {
|
||||
position: fixed;
|
||||
right: 8mm;
|
||||
bottom: 3mm;
|
||||
font-size: 8px;
|
||||
color: #56616f;
|
||||
}
|
||||
.page-footer::after {
|
||||
content: counter(page) "/" counter(pages);
|
||||
}
|
||||
@media print {
|
||||
thead { display: table-header-group; }
|
||||
tr { page-break-inside: avoid; }
|
||||
}
|
||||
</style></head><body>
|
||||
<table>
|
||||
<thead>
|
||||
<tr class="report-title"><th colspan="${cols.length}">
|
||||
<div class="title-main">Fiyat Listesi</div>
|
||||
<div class="title-meta">Tarih: ${escapeHtml(generatedAt)} | Satir: ${filteredRows.value.length} | Fiyatlar: ${escapeHtml(selectedPriceOptions.value.join(', '))}</div>
|
||||
</th></tr>
|
||||
<tr>${headerCols}</tr>
|
||||
</thead>
|
||||
<tbody>${body}</tbody>
|
||||
</table>
|
||||
<div class="page-footer"></div>
|
||||
<script>window.onload=function(){setTimeout(function(){window.print()},250)}<\/script>
|
||||
</body></html>`
|
||||
const win = window.open('', '_blank')
|
||||
if (!win) {
|
||||
Notify.create({ type: 'negative', message: 'PDF yazdirma penceresi acilamadi.' })
|
||||
return
|
||||
}
|
||||
win.document.open()
|
||||
win.document.write(html)
|
||||
win.document.close()
|
||||
await notifyExportTaken('pdf')
|
||||
}
|
||||
|
||||
async function notifyExportTaken (format) {
|
||||
@@ -1851,6 +1896,10 @@ onMounted(() => {
|
||||
z-index: 20;
|
||||
}
|
||||
|
||||
.top-x-scroll:hover {
|
||||
cursor: ew-resize;
|
||||
}
|
||||
|
||||
.top-x-scroll-inner {
|
||||
height: 18px;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user