Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -2,6 +2,67 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import api from 'src/services/api'
|
||||
|
||||
function normalizeTextForMatch (v) {
|
||||
return String(v || '')
|
||||
.trim()
|
||||
.toUpperCase()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
}
|
||||
|
||||
// Production ekranlari icin beden grup tespiti helper'i.
|
||||
// Ozel kural:
|
||||
// YETISKIN/GARSON = GARSON ve URUN ANA GRUBU "GOMLEK ATA YAKA" veya "GOMLEK KLASIK" ise => yas
|
||||
export function detectProductionBedenGroup (bedenList, urunAnaGrubu = '', urunKategori = '', yetiskinGarson = '') {
|
||||
const list = Array.isArray(bedenList) ? bedenList : []
|
||||
const hasLetterSizes = list
|
||||
.map(v => String(v || '').trim().toUpperCase())
|
||||
.some(v => ['XS', 'S', 'M', 'L', 'XL', '2XL', '3XL', '4XL', '5XL', '6XL', '7XL'].includes(v))
|
||||
|
||||
const ana = normalizeTextForMatch(urunAnaGrubu)
|
||||
const kat = normalizeTextForMatch(urunKategori)
|
||||
const yg = normalizeTextForMatch(yetiskinGarson)
|
||||
|
||||
if ((kat.includes('GARSON') || yg.includes('GARSON')) &&
|
||||
(ana.includes('GOMLEK ATAYAKA') || ana.includes('GOMLEK KLASIK'))) {
|
||||
return 'yas'
|
||||
}
|
||||
|
||||
if (hasLetterSizes) return 'gom'
|
||||
if ((ana.includes('AYAKKABI') || kat.includes('AYAKKABI')) && (kat.includes('GARSON') || yg.includes('GARSON'))) return 'ayk_garson'
|
||||
if (kat.includes('GARSON') || yg.includes('GARSON') || ana.includes('GARSON')) return 'yas'
|
||||
if (ana.includes('PANTOLON') && kat.includes('YETISKIN')) return 'pan'
|
||||
if (ana.includes('AKSESUAR')) return 'aksbir'
|
||||
return 'tak'
|
||||
}
|
||||
|
||||
function extractApiErrorMessage (err, fallback) {
|
||||
const data = err?.response?.data
|
||||
if (typeof data === 'string' && data.trim()) return data
|
||||
if (data && typeof data === 'object') {
|
||||
const msg = String(data.message || '').trim()
|
||||
const step = String(data.step || '').trim()
|
||||
const detail = String(data.detail || '').trim()
|
||||
const parts = [msg]
|
||||
if (step) parts.push(`step=${step}`)
|
||||
if (detail) parts.push(detail)
|
||||
const merged = parts.filter(Boolean).join(' | ')
|
||||
if (merged) return merged
|
||||
}
|
||||
return err?.message || fallback
|
||||
}
|
||||
|
||||
function logApiError (action, err, payload = null) {
|
||||
const status = err?.response?.status
|
||||
const data = err?.response?.data
|
||||
console.error(`[OrderProductionItemStore] ${action} failed`, {
|
||||
status,
|
||||
payload,
|
||||
data,
|
||||
message: err?.message
|
||||
})
|
||||
}
|
||||
|
||||
export const useOrderProductionItemStore = defineStore('orderproductionitems', {
|
||||
state: () => ({
|
||||
items: [],
|
||||
@@ -118,7 +179,8 @@ export const useOrderProductionItemStore = defineStore('orderproductionitems', {
|
||||
)
|
||||
return res?.data || { missingCount: 0, missing: [] }
|
||||
} catch (err) {
|
||||
this.error = err?.response?.data || err?.message || 'Kontrol basarisiz'
|
||||
logApiError('validateUpdates', err, { orderHeaderID, lineCount: lines?.length || 0 })
|
||||
this.error = extractApiErrorMessage(err, 'Kontrol basarisiz')
|
||||
throw err
|
||||
} finally {
|
||||
this.saving = false
|
||||
@@ -137,7 +199,8 @@ export const useOrderProductionItemStore = defineStore('orderproductionitems', {
|
||||
)
|
||||
return res?.data || { updated: 0, inserted: 0 }
|
||||
} catch (err) {
|
||||
this.error = err?.response?.data || err?.message || 'Guncelleme basarisiz'
|
||||
logApiError('applyUpdates', err, { orderHeaderID, lineCount: lines?.length || 0, insertMissing })
|
||||
this.error = extractApiErrorMessage(err, 'Guncelleme basarisiz')
|
||||
throw err
|
||||
} finally {
|
||||
this.saving = false
|
||||
|
||||
Reference in New Issue
Block a user