Merge remote-tracking branch 'origin/master'

This commit is contained in:
M_Kececi
2026-04-03 14:16:05 +03:00
parent 67ef80936a
commit e1064010f3
6 changed files with 133 additions and 9 deletions

View File

@@ -603,6 +603,11 @@ func InitRoutes(pgDB *sql.DB, mssql *sql.DB, ml *mailer.GraphMailer) *mux.Router
"order", "view",
wrapV3(http.HandlerFunc(routes.GetProductAttributesHandler)),
)
bindV3(r, pgDB,
"/api/product-item-attributes", "GET",
"order", "view",
wrapV3(http.HandlerFunc(routes.GetProductItemAttributesHandler)),
)
bindV3(r, pgDB,
"/api/product-stock-query", "GET",
"order", "view",

View File

@@ -7,3 +7,9 @@ type ProductAttributeOption struct {
AttributeCode string `json:"attribute_code"`
AttributeDescription string `json:"attribute_description"`
}
type ProductItemAttributeValue struct {
ItemTypeCode int16 `json:"item_type_code"`
AttributeTypeCode int `json:"attribute_type_code"`
AttributeCode string `json:"attribute_code"`
}

View File

@@ -47,3 +47,13 @@ ORDER BY
CASE WHEN a.AttributeCode IN ('-', '.') THEN 0 ELSE 1 END,
a.AttributeCode;
`
const GetProductItemAttributes = `
SELECT
a.ItemTypeCode,
a.AttributeTypeCode,
ISNULL(a.AttributeCode, '') AS AttributeCode
FROM dbo.prItemAttribute AS a WITH(NOLOCK)
WHERE a.ItemTypeCode = @p1
AND ISNULL(LTRIM(RTRIM(a.ItemCode)), '') = ISNULL(LTRIM(RTRIM(@p2)), '')
`

View File

@@ -52,3 +52,50 @@ func GetProductAttributesHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
_ = json.NewEncoder(w).Encode(list)
}
func GetProductItemAttributesHandler(w http.ResponseWriter, r *http.Request) {
claims, ok := auth.GetClaimsFromContext(r.Context())
if !ok || claims == nil {
http.Error(w, "unauthorized", http.StatusUnauthorized)
return
}
itemTypeCode := int16(1)
if raw := r.URL.Query().Get("itemTypeCode"); raw != "" {
v, err := strconv.Atoi(raw)
if err != nil || v <= 0 {
http.Error(w, "itemTypeCode gecersiz", http.StatusBadRequest)
return
}
itemTypeCode = int16(v)
}
itemCode := r.URL.Query().Get("itemCode")
if itemCode == "" {
http.Error(w, "itemCode zorunlu", http.StatusBadRequest)
return
}
rows, err := db.MssqlDB.Query(queries.GetProductItemAttributes, itemTypeCode, itemCode)
if err != nil {
http.Error(w, "Product item attributes alinamadi: "+err.Error(), http.StatusInternalServerError)
return
}
defer rows.Close()
list := make([]models.ProductItemAttributeValue, 0, 64)
for rows.Next() {
var x models.ProductItemAttributeValue
if err := rows.Scan(
&x.ItemTypeCode,
&x.AttributeTypeCode,
&x.AttributeCode,
); err != nil {
continue
}
list = append(list, x)
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
_ = json.NewEncoder(w).Encode(list)
}

View File

@@ -164,7 +164,7 @@
@click="openCdItemDialog(props.row.NewItemCode)"
/>
<q-btn
v-if="props.row.NewItemMode === 'new'"
v-if="props.row.NewItemMode && props.row.NewItemMode !== 'empty'"
class="q-ml-xs"
dense
flat
@@ -535,6 +535,8 @@ function onNewItemChange (row, val, source = 'typed') {
}
if (row.NewItemMode === 'new' && isValidBaggiModelCode(row.NewItemCode) && row.NewItemCode !== prevCode) {
openNewCodeSetupFlow(row.NewItemCode)
} else if (row.NewItemMode === 'existing' && isValidBaggiModelCode(row.NewItemCode) && row.NewItemCode !== prevCode) {
openAttributeDialog(row.NewItemCode)
}
}
@@ -913,17 +915,33 @@ async function openAttributeDialog (itemCode) {
const code = String(itemCode || '').trim().toUpperCase()
if (!code) return
attributeTargetCode.value = code
const existing = store.getProductAttributeDraft(code)
const existingDraft = store.getProductAttributeDraft(code)
const fetched = await store.fetchProductAttributes(1)
const fromLookup = buildAttributeRowsFromLookup(fetched)
if (!fromLookup.length) {
$q.notify({ type: 'negative', message: 'Urun ozellikleri listesi alinamadi. Lutfen daha sonra tekrar deneyin.' })
return
}
const baseRows = fromLookup
attributeRows.value = Array.isArray(existing) && existing.length
? JSON.parse(JSON.stringify(existing))
: baseRows
const modeInfo = store.classifyItemCode(code)
const dbCurrent = modeInfo.mode === 'existing'
? await store.fetchProductItemAttributes(code, 1)
: []
const dbMap = new Map(
(dbCurrent || []).map(x => [
Number(x?.attribute_type_code || x?.AttributeTypeCode || 0),
String(x?.attribute_code || x?.AttributeCode || '').trim()
]).filter(x => x[0] > 0)
)
const baseRows = fromLookup.map(row => ({
...row,
AttributeCode: dbMap.get(Number(row.AttributeTypeCodeNumber || 0)) || ''
}))
attributeRows.value = Array.isArray(existingDraft) && existingDraft.length
? JSON.parse(JSON.stringify(existingDraft))
: JSON.parse(JSON.stringify(baseRows))
for (const row of (attributeRows.value || [])) {
if (!Array.isArray(row.AllOptions)) {
row.AllOptions = Array.isArray(row.Options) ? [...row.Options] : []
@@ -932,6 +950,9 @@ async function openAttributeDialog (itemCode) {
row.Options = [...row.AllOptions]
}
}
if ((!existingDraft || !existingDraft.length) && baseRows.length) {
store.setProductAttributeDraft(code, JSON.parse(JSON.stringify(baseRows)))
}
attributeDialogOpen.value = true
}
@@ -950,7 +971,7 @@ function saveAttributeDraft () {
$q.notify({ type: 'positive', message: 'Urun ozellikleri taslagi kaydedildi.' })
}
function collectProductAttributesFromSelectedRows (selectedRows) {
async function collectProductAttributesFromSelectedRows (selectedRows) {
const codeSet = [...new Set(
(selectedRows || [])
.map(r => String(r?.NewItemCode || '').trim().toUpperCase())
@@ -959,7 +980,23 @@ function collectProductAttributesFromSelectedRows (selectedRows) {
const out = []
for (const code of codeSet) {
const rows = store.getProductAttributeDraft(code)
let rows = store.getProductAttributeDraft(code)
if (!Array.isArray(rows) || !rows.length) {
const lookup = await store.fetchProductAttributes(1)
const baseRows = buildAttributeRowsFromLookup(lookup)
const dbCurrent = await store.fetchProductItemAttributes(code, 1)
const dbMap = new Map(
(dbCurrent || []).map(x => [
Number(x?.attribute_type_code || x?.AttributeTypeCode || 0),
String(x?.attribute_code || x?.AttributeCode || '').trim()
]).filter(x => x[0] > 0)
)
rows = baseRows.map(row => ({
...row,
AttributeCode: dbMap.get(Number(row.AttributeTypeCodeNumber || 0)) || ''
}))
store.setProductAttributeDraft(code, JSON.parse(JSON.stringify(rows)))
}
if (!Array.isArray(rows) || !rows.length) {
return { errMsg: `${code} icin urun ozellikleri secilmedi`, productAttributes: [] }
}
@@ -1185,7 +1222,7 @@ async function onBulkSubmit () {
if (firstCode) openCdItemDialog(firstCode)
return
}
const { errMsg: attrErrMsg, productAttributes } = collectProductAttributesFromSelectedRows(selectedRows)
const { errMsg: attrErrMsg, productAttributes } = await collectProductAttributesFromSelectedRows(selectedRows)
if (attrErrMsg) {
$q.notify({ type: 'negative', message: attrErrMsg })
const firstCode = String(attrErrMsg.split(' ')[0] || '').trim()

View File

@@ -50,6 +50,7 @@ export const useOrderProductionItemStore = defineStore('orderproductionitems', {
secondColorRequestsByKey: {},
newSecondColorRequestsByKey: {},
productAttributesByItemType: {},
productItemAttributesByKey: {},
cdItemLookups: null,
cdItemDraftsByCode: {},
productAttributeDraftsByCode: {},
@@ -272,6 +273,24 @@ export const useOrderProductionItemStore = defineStore('orderproductionitems', {
return []
}
},
async fetchProductItemAttributes (itemCode, itemTypeCode = 1, force = false) {
const code = String(itemCode || '').trim().toUpperCase()
const itc = Number(itemTypeCode || 1)
if (!code) return []
const key = `${itc}|${code}`
if (!force && this.productItemAttributesByKey[key]) {
return this.productItemAttributesByKey[key]
}
try {
const res = await api.get('/product-item-attributes', { params: { itemTypeCode: itc, itemCode: code } })
const list = Array.isArray(res?.data) ? res.data : []
this.productItemAttributesByKey[key] = list
return list
} catch (err) {
this.error = err?.response?.data || err?.message || 'Urunun mevcut ozellikleri alinamadi'
return []
}
},
async fetchCdItemLookups (force = false) {
if (this.cdItemLookups && !force) return this.cdItemLookups
try {