Fix product performance grouped JSON build
This commit is contained in:
@@ -5094,43 +5094,86 @@ 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 => {
|
||||||
newRowSequence.value += 1
|
const groupName = normalizeGroupName(group?.sAciklama3)
|
||||||
const copiedRow = recalculateDetailRow({
|
const groupCurrentRows = currentTPDTRows.filter(row => normalizeGroupName(row?.sAciklama3) === groupName)
|
||||||
...row,
|
const groupSourceRows = Array.isArray(group?.items) ? group.items : []
|
||||||
__rowKey: `firm-history-copy-${sourceOnMLNo}-${newRowSequence.value}`,
|
groupSourceRows.forEach(row => {
|
||||||
isNew: true,
|
const target = findTargetRow(row, groupName)
|
||||||
nOnMLNo: detailHeader.value?.nOnMLNo || onMLNo.value || '',
|
if (!target && groupCurrentRows.length > 0) return
|
||||||
nOnMLDetNo: getNextDetailNo(),
|
|
||||||
sAciklama3: normalizeGroupName(group?.sAciklama3 || row?.sAciklama3),
|
newRowSequence.value += 1
|
||||||
requiredPlaceholder: false,
|
const copiedRow = recalculateDetailRow({
|
||||||
draftChanged: true,
|
...row,
|
||||||
__copiedFromOnMLNo: sourceOnMLNo
|
__rowKey: target?.__rowKey || `firm-history-copy-${sourceOnMLNo}-${newRowSequence.value}`,
|
||||||
}, {
|
isNew: target ? Boolean(target?.isNew) : true,
|
||||||
preserveInputs: true,
|
nOnMLNo: detailHeader.value?.nOnMLNo || onMLNo.value || '',
|
||||||
priceType: 'COPY',
|
nOnMLDetNo: target?.nOnMLDetNo || getNextDetailNo(),
|
||||||
updateState: 'firm-history-copy',
|
sAciklama3: groupName,
|
||||||
markChanged: true
|
requiredPlaceholder: false,
|
||||||
|
draftChanged: true,
|
||||||
|
__copiedFromOnMLNo: sourceOnMLNo
|
||||||
|
}, {
|
||||||
|
preserveInputs: true,
|
||||||
|
priceType: 'COPY',
|
||||||
|
updateState: 'firm-history-copy',
|
||||||
|
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()
|
||||||
schedulePersistLocalDraft()
|
schedulePersistLocalDraft()
|
||||||
@@ -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
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user