Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -454,6 +454,27 @@ func normalizeKeyPart(ns models.NullString) string {
|
||||
return strings.ToUpper(s)
|
||||
}
|
||||
|
||||
// normalizeNumericToken: sadece rakamlardan oluşan değeri baştaki sıfırlardan arındırır.
|
||||
// Rakam dışı içerik varsa boş döner.
|
||||
func normalizeNumericToken(s string) string {
|
||||
if s == "" {
|
||||
return ""
|
||||
}
|
||||
for i := 0; i < len(s); i++ {
|
||||
if s[i] < '0' || s[i] > '9' {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
i := 0
|
||||
for i < len(s) && s[i] == '0' {
|
||||
i++
|
||||
}
|
||||
if i == len(s) {
|
||||
return "0"
|
||||
}
|
||||
return s[i:]
|
||||
}
|
||||
|
||||
// =======================================================
|
||||
// AKSBIR DETECTION
|
||||
// =======================================================
|
||||
@@ -493,6 +514,7 @@ func ValidateItemVariant(tx *sql.Tx, ln models.OrderDetail) error {
|
||||
color = normalizeEmpty(color)
|
||||
dim1 = normalizeEmpty(dim1)
|
||||
dim2 = normalizeEmpty(dim2)
|
||||
dim1Numeric := normalizeNumericToken(dim1)
|
||||
|
||||
if item == "" {
|
||||
return fmt.Errorf(
|
||||
@@ -511,6 +533,9 @@ func ValidateItemVariant(tx *sql.Tx, ln models.OrderDetail) error {
|
||||
SELECT CASE WHEN EXISTS (
|
||||
SELECT 1
|
||||
FROM BAGGI_V3.dbo.prItemVariant V WITH (NOLOCK)
|
||||
CROSS APPLY (
|
||||
SELECT UPPER(REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(V.ItemDim1Code)),'') ,' ', ''), 'YAS', ''), 'Y', '')) AS Dim1Norm
|
||||
) X
|
||||
WHERE ISNULL(LTRIM(RTRIM(V.ItemCode)),'') = @p1
|
||||
AND (
|
||||
(
|
||||
@@ -526,16 +551,15 @@ func ValidateItemVariant(tx *sql.Tx, ln models.OrderDetail) error {
|
||||
)
|
||||
)
|
||||
AND (
|
||||
UPPER(REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(V.ItemDim1Code)),'') ,' ', ''), 'YAS', ''), 'Y', ''))
|
||||
= UPPER(REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(@p3)),'') ,' ', ''), 'YAS', ''), 'Y', ''))
|
||||
X.Dim1Norm = @p3
|
||||
OR (
|
||||
TRY_CONVERT(INT, NULLIF(UPPER(REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(V.ItemDim1Code)),'') ,' ', ''), 'YAS', ''), 'Y', '')), ''))
|
||||
= TRY_CONVERT(INT, NULLIF(UPPER(REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(@p3)),'') ,' ', ''), 'YAS', ''), 'Y', '')), ''))
|
||||
AND TRY_CONVERT(INT, NULLIF(UPPER(REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(@p3)),'') ,' ', ''), 'YAS', ''), 'Y', '')), '')) IS NOT NULL
|
||||
ISNULL(LTRIM(RTRIM(@p5)),'') <> ''
|
||||
AND X.Dim1Norm NOT LIKE '%[^0-9]%'
|
||||
AND SUBSTRING(X.Dim1Norm, PATINDEX('%[^0]%', X.Dim1Norm + '0'), LEN(X.Dim1Norm)) = @p5
|
||||
)
|
||||
)
|
||||
) THEN 1 ELSE 0 END
|
||||
`, item, color, dim1, dim2).Scan(&exists)
|
||||
`, item, color, dim1, dim2, dim1Numeric).Scan(&exists)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("ItemVariant kontrol query hatası: %w", err)
|
||||
@@ -572,6 +596,9 @@ func ValidateOrderVariants(db *sql.DB, lines []models.OrderDetail) ([]models.Inv
|
||||
SELECT CASE WHEN EXISTS (
|
||||
SELECT 1
|
||||
FROM BAGGI_V3.dbo.prItemVariant V WITH (NOLOCK)
|
||||
CROSS APPLY (
|
||||
SELECT UPPER(REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(V.ItemDim1Code)),'') ,' ', ''), 'YAS', ''), 'Y', '')) AS Dim1Norm
|
||||
) X
|
||||
WHERE ISNULL(LTRIM(RTRIM(V.ItemCode)),'') = @p1
|
||||
AND (
|
||||
(
|
||||
@@ -587,12 +614,11 @@ func ValidateOrderVariants(db *sql.DB, lines []models.OrderDetail) ([]models.Inv
|
||||
)
|
||||
)
|
||||
AND (
|
||||
UPPER(REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(V.ItemDim1Code)),'') ,' ', ''), 'YAS', ''), 'Y', ''))
|
||||
= UPPER(REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(@p3)),'') ,' ', ''), 'YAS', ''), 'Y', ''))
|
||||
X.Dim1Norm = @p3
|
||||
OR (
|
||||
TRY_CONVERT(INT, NULLIF(UPPER(REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(V.ItemDim1Code)),'') ,' ', ''), 'YAS', ''), 'Y', '')), ''))
|
||||
= TRY_CONVERT(INT, NULLIF(UPPER(REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(@p3)),'') ,' ', ''), 'YAS', ''), 'Y', '')), ''))
|
||||
AND TRY_CONVERT(INT, NULLIF(UPPER(REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(@p3)),'') ,' ', ''), 'YAS', ''), 'Y', '')), '')) IS NOT NULL
|
||||
ISNULL(LTRIM(RTRIM(@p5)),'') <> ''
|
||||
AND X.Dim1Norm NOT LIKE '%[^0-9]%'
|
||||
AND SUBSTRING(X.Dim1Norm, PATINDEX('%[^0]%', X.Dim1Norm + '0'), LEN(X.Dim1Norm)) = @p5
|
||||
)
|
||||
)
|
||||
) THEN 1 ELSE 0 END
|
||||
@@ -614,6 +640,7 @@ func ValidateOrderVariants(db *sql.DB, lines []models.OrderDetail) ([]models.Inv
|
||||
color := normalizeEmpty(normalizeKeyPart(ln.ColorCode))
|
||||
dim1 := normalizeEmpty(normalizeKeyPart(ln.ItemDim1Code))
|
||||
dim2 := normalizeEmpty(normalizeKeyPart(ln.ItemDim2Code))
|
||||
dim1Numeric := normalizeNumericToken(dim1)
|
||||
|
||||
// ItemCode boş ise invalid
|
||||
if strings.TrimSpace(item) == "" {
|
||||
@@ -632,7 +659,7 @@ func ValidateOrderVariants(db *sql.DB, lines []models.OrderDetail) ([]models.Inv
|
||||
}
|
||||
|
||||
var exists int
|
||||
if err := stmt.QueryRow(item, color, dim1, dim2).Scan(&exists); err != nil {
|
||||
if err := stmt.QueryRow(item, color, dim1, dim2, dim1Numeric).Scan(&exists); err != nil {
|
||||
return nil, fmt.Errorf("validate query hatası (i=%d): %w", i, err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user