ui: add B2B olmayan stok (orphans) page

This commit is contained in:
M_Kececi
2026-06-24 23:27:42 +03:00
parent aa100973b3
commit 3095c06cbf
2 changed files with 127 additions and 80 deletions

View File

@@ -1149,12 +1149,33 @@ func productSeriesResolvePGVariant(ctx context.Context, pg *sql.DB, productCode,
}
return 0, 0, sql.NullInt64{}, false, err
}
dim1ID, ok, err := productSeriesResolveDimTokenID(ctx, pg, "dimval1", colorCode, mmitemID)
if err != nil {
return 0, 0, sql.NullInt64{}, false, err
}
if !ok || dim1ID <= 0 {
return 0, 0, sql.NullInt64{}, false, nil
// Authoritative dim1 resolver: for this installation, "color_code" tokens correspond to dfgrp.code on
// the dim values referenced by mmitem_dim.val1. Do NOT rely on mk_dim_token_map for dimval1 because
// it can be polluted and conflate tokens.
var dim1ID int64
{
tok := strings.ToUpper(strings.TrimSpace(colorCode))
if tok == "" || tok == "0" {
return 0, 0, sql.NullInt64{}, false, nil
}
if err := pg.QueryRowContext(ctx, `
SELECT md.val1
FROM mmitem_dim md
JOIN dfgrp d ON d.id = md.val1
WHERE md.mmitem_id = $1
AND md.is_active = TRUE
AND UPPER(BTRIM(d.code)) = $2
GROUP BY md.val1
LIMIT 1
`, mmitemID, tok).Scan(&dim1ID); err != nil {
if err == sql.ErrNoRows {
return 0, 0, sql.NullInt64{}, false, nil
}
return 0, 0, sql.NullInt64{}, false, err
}
if dim1ID <= 0 {
return 0, 0, sql.NullInt64{}, false, nil
}
}
var dim3ID sql.NullInt64
if strings.TrimSpace(dim3Code) != "" {