Fix product performance grouped JSON build

This commit is contained in:
M_Kececi
2026-08-29 18:34:16 +03:00
parent 456580b9fb
commit 7e7197dc0f
@@ -5094,31 +5094,61 @@ async function copyTPDTFromSelectedCost () {
trace_id: traceId.value trace_id: traceId.value
}) })
const sourceGroups = normalizeDetailGroups(sourceData).filter(group => isTPDTGroupName(group?.sAciklama3)) const sourceGroups = normalizeDetailGroups(sourceData).filter(group => isTPDTGroupName(group?.sAciklama3))
const populatedGroups = new Set( const currentTPDTRows = flatDetailRows.value.filter(row => isTPDTGroupName(row?.sAciklama3))
flatDetailRows.value const isIncompleteTPDTRow = row => (
.filter(row => isTPDTGroupName(row?.sAciklama3)) Boolean(row?.requiredPlaceholder) ||
.map(row => normalizeGroupName(row?.sAciklama3)) !String(row?.sKodu || '').trim() ||
!String(row?.sAciklama || '').trim() ||
!(parseMoneyInput(row?.inputPrice ?? row?.fiyat_girilen) > 0)
) )
const groupsToCopy = sourceGroups.filter(group => !populatedGroups.has(normalizeGroupName(group?.sAciklama3))) const availableTargets = currentTPDTRows.filter(isIncompleteTPDTRow)
const sourceRows = groupsToCopy.flatMap(group => ( const usedTargetKeys = new Set()
(Array.isArray(group?.items) ? group.items : []).map(row => ({ group, row })) let filledRowCount = 0
)) let addedRowCount = 0
if (sourceRows.length === 0) { const copiedGroupNames = new Set()
firmCostHistoryError.value = populatedGroups.has('TP') && populatedGroups.has('DT')
? 'Mevcut maliyette TP ve DT gruplari zaten dolu. Hicbir satir degistirilmedi.' const findTargetRow = (sourceRow, groupName) => {
: 'Secilen maliyette bos gruplari dolduracak TP/DT satiri bulunamadi.' const sourceHNo = normalizeHammaddeNo(sourceRow?.nHammaddeTuruNo)
return const sourceMT = parseInt(String(sourceRow?.nUrtMTBolumID ?? sourceRow?.NUrtMTBolumID ?? '0'), 10) || 0
const sourcePart = normalizeGroupName(sourceRow?.sParcaAdi || '')
return availableTargets
.filter(target => !usedTargetKeys.has(target?.__rowKey))
.filter(target => normalizeGroupName(target?.sAciklama3) === groupName)
.filter(target => normalizeHammaddeNo(target?.nHammaddeTuruNo) === sourceHNo)
.filter(target => {
const targetMT = parseInt(String(target?.nUrtMTBolumID ?? target?.NUrtMTBolumID ?? '0'), 10) || 0
const targetPart = normalizeGroupName(target?.sParcaAdi || '')
if (sourceMT > 0 && targetMT > 0) return sourceMT === targetMT
if (sourcePart && targetPart) return sourcePart === targetPart
return true
})
.map(target => {
const targetMT = parseInt(String(target?.nUrtMTBolumID ?? target?.NUrtMTBolumID ?? '0'), 10) || 0
const targetPart = normalizeGroupName(target?.sParcaAdi || '')
let score = 1
if (sourceMT > 0 && targetMT === sourceMT) score += 4
if (sourcePart && targetPart === sourcePart) score += 2
return { target, score }
})
.sort((left, right) => right.score - left.score)[0]?.target
} }
sourceRows.forEach(({ group, row }) => { sourceGroups.forEach(group => {
const groupName = normalizeGroupName(group?.sAciklama3)
const groupCurrentRows = currentTPDTRows.filter(row => normalizeGroupName(row?.sAciklama3) === groupName)
const groupSourceRows = Array.isArray(group?.items) ? group.items : []
groupSourceRows.forEach(row => {
const target = findTargetRow(row, groupName)
if (!target && groupCurrentRows.length > 0) return
newRowSequence.value += 1 newRowSequence.value += 1
const copiedRow = recalculateDetailRow({ const copiedRow = recalculateDetailRow({
...row, ...row,
__rowKey: `firm-history-copy-${sourceOnMLNo}-${newRowSequence.value}`, __rowKey: target?.__rowKey || `firm-history-copy-${sourceOnMLNo}-${newRowSequence.value}`,
isNew: true, isNew: target ? Boolean(target?.isNew) : true,
nOnMLNo: detailHeader.value?.nOnMLNo || onMLNo.value || '', nOnMLNo: detailHeader.value?.nOnMLNo || onMLNo.value || '',
nOnMLDetNo: getNextDetailNo(), nOnMLDetNo: target?.nOnMLDetNo || getNextDetailNo(),
sAciklama3: normalizeGroupName(group?.sAciklama3 || row?.sAciklama3), sAciklama3: groupName,
requiredPlaceholder: false, requiredPlaceholder: false,
draftChanged: true, draftChanged: true,
__copiedFromOnMLNo: sourceOnMLNo __copiedFromOnMLNo: sourceOnMLNo
@@ -5128,8 +5158,21 @@ async function copyTPDTFromSelectedCost () {
updateState: 'firm-history-copy', updateState: 'firm-history-copy',
markChanged: true markChanged: true
}) })
if (target) {
usedTargetKeys.add(target.__rowKey)
filledRowCount += 1
} else {
addedRowCount += 1
}
copiedGroupNames.add(groupName)
applyEditorRowToGroups(copiedRow) applyEditorRowToGroups(copiedRow)
}) })
})
if (filledRowCount + addedRowCount === 0) {
firmCostHistoryError.value = 'Secilen maliyette mevcut bos TP/DT satirlariyla eslesen malzeme bulunamadi. Dolu satirlar degistirilmedi.'
return
}
recalculateAllDetailRows() recalculateAllDetailRows()
syncAllGroupsOpen() syncAllGroupsOpen()
@@ -5138,7 +5181,7 @@ async function copyTPDTFromSelectedCost () {
firmCostHistoryDialogOpen.value = false firmCostHistoryDialogOpen.value = false
$q.notify({ $q.notify({
type: 'positive', type: 'positive',
message: `${groupsToCopy.map(group => normalizeGroupName(group?.sAciklama3)).join(' ve ')} gruplarindaki ${sourceRows.length} satir ${source?.UrunKodu || ''} maliyetinden tum ozellikleriyle eklendi. Kaydet butonu ile onaylayabilirsiniz.`, message: `${Array.from(copiedGroupNames).join(' ve ')} gruplarinda ${filledRowCount} bos satir dolduruldu${addedRowCount > 0 ? `, ${addedRowCount} satir eklendi` : ''}. Kaydet butonu ile onaylayabilirsiniz.`,
position: 'top-right', position: 'top-right',
timeout: 5000 timeout: 5000
}) })