Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -162,50 +162,50 @@ func GetAllProductPricingRows(ctx context.Context, chunkSize int, filters Produc
|
||||
CREATE CLUSTERED INDEX IX_req_codes_ProductCode ON #req_codes(ProductCode);
|
||||
|
||||
SELECT
|
||||
LTRIM(RTRIM(s.ItemCode)) AS ItemCode,
|
||||
s.ItemCode AS ItemCode,
|
||||
SUM(s.In_Qty1 - s.Out_Qty1) AS InventoryQty1
|
||||
INTO #stock_base
|
||||
FROM trStock s WITH(NOLOCK)
|
||||
FROM trStock s
|
||||
INNER JOIN #req_codes rc
|
||||
ON rc.ProductCode = LTRIM(RTRIM(s.ItemCode))
|
||||
ON rc.ProductCode = s.ItemCode
|
||||
WHERE s.ItemTypeCode = 1
|
||||
AND LEN(LTRIM(RTRIM(s.ItemCode))) = 13
|
||||
GROUP BY LTRIM(RTRIM(s.ItemCode));
|
||||
AND LEN(s.ItemCode) = 13
|
||||
GROUP BY s.ItemCode;
|
||||
|
||||
CREATE CLUSTERED INDEX IX_stock_base_ItemCode ON #stock_base(ItemCode);
|
||||
|
||||
SELECT
|
||||
LTRIM(RTRIM(p.ItemCode)) AS ItemCode,
|
||||
p.ItemCode AS ItemCode,
|
||||
SUM(p.Qty1) AS PickingQty1
|
||||
INTO #pick_base
|
||||
FROM PickingStates p
|
||||
INNER JOIN #req_codes rc
|
||||
ON rc.ProductCode = LTRIM(RTRIM(p.ItemCode))
|
||||
ON rc.ProductCode = p.ItemCode
|
||||
WHERE p.ItemTypeCode = 1
|
||||
AND LEN(LTRIM(RTRIM(p.ItemCode))) = 13
|
||||
GROUP BY LTRIM(RTRIM(p.ItemCode));
|
||||
AND LEN(p.ItemCode) = 13
|
||||
GROUP BY p.ItemCode;
|
||||
|
||||
SELECT
|
||||
LTRIM(RTRIM(r.ItemCode)) AS ItemCode,
|
||||
r.ItemCode AS ItemCode,
|
||||
SUM(r.Qty1) AS ReserveQty1
|
||||
INTO #reserve_base
|
||||
FROM ReserveStates r
|
||||
INNER JOIN #req_codes rc
|
||||
ON rc.ProductCode = LTRIM(RTRIM(r.ItemCode))
|
||||
ON rc.ProductCode = r.ItemCode
|
||||
WHERE r.ItemTypeCode = 1
|
||||
AND LEN(LTRIM(RTRIM(r.ItemCode))) = 13
|
||||
GROUP BY LTRIM(RTRIM(r.ItemCode));
|
||||
AND LEN(r.ItemCode) = 13
|
||||
GROUP BY r.ItemCode;
|
||||
|
||||
SELECT
|
||||
LTRIM(RTRIM(d.ItemCode)) AS ItemCode,
|
||||
d.ItemCode AS ItemCode,
|
||||
SUM(d.Qty1) AS DispOrderQty1
|
||||
INTO #disp_base
|
||||
FROM DispOrderStates d
|
||||
INNER JOIN #req_codes rc
|
||||
ON rc.ProductCode = LTRIM(RTRIM(d.ItemCode))
|
||||
ON rc.ProductCode = d.ItemCode
|
||||
WHERE d.ItemTypeCode = 1
|
||||
AND LEN(LTRIM(RTRIM(d.ItemCode))) = 13
|
||||
GROUP BY LTRIM(RTRIM(d.ItemCode));
|
||||
AND LEN(d.ItemCode) = 13
|
||||
GROUP BY d.ItemCode;
|
||||
|
||||
SELECT
|
||||
rc.ProductCode,
|
||||
@@ -315,16 +315,16 @@ func enrichAllProductPricingRows(ctx context.Context, out []models.ProductPricin
|
||||
),
|
||||
latest_pricelist_line AS (
|
||||
SELECT
|
||||
LTRIM(RTRIM(p.ItemCode)) AS ItemCode,
|
||||
p.ItemCode AS ItemCode,
|
||||
LTRIM(RTRIM(p.DocCurrencyCode)) AS DocCurrencyCode,
|
||||
CAST(p.Price AS DECIMAL(18, 2)) AS Price,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY LTRIM(RTRIM(p.ItemCode)), LTRIM(RTRIM(p.DocCurrencyCode))
|
||||
PARTITION BY p.ItemCode, LTRIM(RTRIM(p.DocCurrencyCode))
|
||||
ORDER BY p.ValidDate DESC, p.ValidTime DESC, p.LastUpdatedDate DESC
|
||||
) AS rn
|
||||
FROM dbo.trPriceListLine p WITH(NOLOCK)
|
||||
FROM dbo.trPriceListLine p
|
||||
INNER JOIN req_codes rc
|
||||
ON rc.ProductCode = LTRIM(RTRIM(p.ItemCode))
|
||||
ON rc.ProductCode = p.ItemCode
|
||||
WHERE p.ItemTypeCode = 1
|
||||
AND ISNULL(p.IsDisabled, 0) = 0
|
||||
AND LTRIM(RTRIM(p.DocCurrencyCode)) IN ('USD', 'TRY')
|
||||
@@ -346,29 +346,29 @@ func enrichAllProductPricingRows(ctx context.Context, out []models.ProductPricin
|
||||
),
|
||||
latest_base_price AS (
|
||||
SELECT
|
||||
LTRIM(RTRIM(b.ItemCode)) AS ItemCode,
|
||||
b.ItemCode AS ItemCode,
|
||||
CAST(b.Price AS DECIMAL(18, 2)) AS CostPrice,
|
||||
CONVERT(VARCHAR(10), b.PriceDate, 23) AS LastPricingDate,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY LTRIM(RTRIM(b.ItemCode))
|
||||
PARTITION BY b.ItemCode
|
||||
ORDER BY b.PriceDate DESC, b.LastUpdatedDate DESC
|
||||
) AS rn
|
||||
FROM prItemBasePrice b
|
||||
INNER JOIN req_codes rc
|
||||
ON rc.ProductCode = LTRIM(RTRIM(b.ItemCode))
|
||||
ON rc.ProductCode = b.ItemCode
|
||||
WHERE b.ItemTypeCode = 1
|
||||
AND b.BasePriceCode = 1
|
||||
AND LTRIM(RTRIM(b.CurrencyCode)) = 'USD'
|
||||
),
|
||||
stock_entry_dates AS (
|
||||
SELECT
|
||||
LTRIM(RTRIM(s.ItemCode)) AS ItemCode,
|
||||
s.ItemCode AS ItemCode,
|
||||
CONVERT(VARCHAR(10), MAX(s.OperationDate), 23) AS StockEntryDate
|
||||
FROM trStock s WITH(NOLOCK)
|
||||
FROM trStock s
|
||||
INNER JOIN req_codes rc
|
||||
ON rc.ProductCode = LTRIM(RTRIM(s.ItemCode))
|
||||
ON rc.ProductCode = s.ItemCode
|
||||
WHERE s.ItemTypeCode = 1
|
||||
AND LEN(LTRIM(RTRIM(s.ItemCode))) = 13
|
||||
AND LEN(s.ItemCode) = 13
|
||||
AND s.In_Qty1 > 0
|
||||
AND LTRIM(RTRIM(s.InnerProcessCode)) = 'OP'
|
||||
AND LTRIM(RTRIM(s.WarehouseCode)) IN (
|
||||
@@ -376,7 +376,7 @@ func enrichAllProductPricingRows(ctx context.Context, out []models.ProductPricin
|
||||
'1-0-24','1-2-6','1-1-14','1-0-2','1-0-52','1-1-2','1-0-21','1-1-3',
|
||||
'1-0-33','101','1-014','1-0-49','1-0-36'
|
||||
)
|
||||
GROUP BY LTRIM(RTRIM(s.ItemCode))
|
||||
GROUP BY s.ItemCode
|
||||
)
|
||||
SELECT
|
||||
rc.ProductCode,
|
||||
@@ -431,7 +431,7 @@ func enrichAllProductPricingRows(ctx context.Context, out []models.ProductPricin
|
||||
SELECT
|
||||
LTRIM(RTRIM(m.UrunKodu)) AS UrunKodu,
|
||||
CONVERT(VARCHAR(10), MAX(m.Tarihi), 23) AS LastCostingDate
|
||||
FROM dbo.spUrtOnMLMas m WITH(NOLOCK)
|
||||
FROM dbo.spUrtOnMLMas m
|
||||
INNER JOIN req_codes rc
|
||||
ON rc.ProductCode = LTRIM(RTRIM(m.UrunKodu))
|
||||
GROUP BY LTRIM(RTRIM(m.UrunKodu));
|
||||
@@ -878,15 +878,15 @@ func GetProductPricingPage(ctx context.Context, page int, limit int, filters Pro
|
||||
CREATE CLUSTERED INDEX IX_req_codes_ProductCode ON #req_codes(ProductCode);
|
||||
|
||||
SELECT
|
||||
LTRIM(RTRIM(s.ItemCode)) AS ItemCode,
|
||||
s.ItemCode AS ItemCode,
|
||||
SUM(s.In_Qty1 - s.Out_Qty1) AS InventoryQty1
|
||||
INTO #stock_base
|
||||
FROM trStock s WITH(NOLOCK)
|
||||
FROM trStock s
|
||||
INNER JOIN #req_codes rc
|
||||
ON rc.ProductCode = LTRIM(RTRIM(s.ItemCode))
|
||||
ON rc.ProductCode = s.ItemCode
|
||||
WHERE s.ItemTypeCode = 1
|
||||
AND LEN(LTRIM(RTRIM(s.ItemCode))) = 13
|
||||
GROUP BY LTRIM(RTRIM(s.ItemCode));
|
||||
AND LEN(s.ItemCode) = 13
|
||||
GROUP BY s.ItemCode;
|
||||
|
||||
CREATE CLUSTERED INDEX IX_stock_base_ItemCode ON #stock_base(ItemCode);
|
||||
|
||||
@@ -927,7 +927,7 @@ func GetProductPricingPage(ctx context.Context, page int, limit int, filters Pro
|
||||
),
|
||||
attr AS (
|
||||
SELECT
|
||||
LTRIM(RTRIM(a.ItemCode)) AS ProductCode,
|
||||
a.ItemCode AS ProductCode,
|
||||
MAX(CASE WHEN a.AttributeTypeCode = 45 THEN COALESCE(NULLIF(LTRIM(RTRIM(d.AttributeDescription)), ''), LTRIM(RTRIM(a.AttributeCode))) ELSE '' END) AS AskiliYan,
|
||||
MAX(CASE WHEN a.AttributeTypeCode = 44 THEN COALESCE(NULLIF(LTRIM(RTRIM(d.AttributeDescription)), ''), LTRIM(RTRIM(a.AttributeCode))) ELSE '' END) AS Kategori,
|
||||
MAX(CASE WHEN a.AttributeTypeCode = 42 THEN LTRIM(RTRIM(a.AttributeCode)) ELSE '' END) AS UrunIlkGrubuCode,
|
||||
@@ -938,17 +938,17 @@ func GetProductPricingPage(ctx context.Context, page int, limit int, filters Pro
|
||||
MAX(CASE WHEN a.AttributeTypeCode = 29 THEN COALESCE(NULLIF(LTRIM(RTRIM(d.AttributeDescription)), ''), LTRIM(RTRIM(a.AttributeCode))) ELSE '' END) AS Karisim,
|
||||
MAX(CASE WHEN a.AttributeTypeCode = 10 THEN COALESCE(NULLIF(LTRIM(RTRIM(d.AttributeDescription)), ''), LTRIM(RTRIM(a.AttributeCode))) ELSE '' END) AS Marka,
|
||||
MAX(CASE WHEN a.AttributeTypeCode = 10 THEN LTRIM(RTRIM(a.AttributeCode)) ELSE '' END) AS BrandCode
|
||||
FROM dbo.prItemAttribute a WITH(NOLOCK)
|
||||
FROM dbo.prItemAttribute a
|
||||
INNER JOIN req_codes rc
|
||||
ON rc.ProductCode = LTRIM(RTRIM(a.ItemCode))
|
||||
LEFT JOIN dbo.cdItemAttributeDesc d WITH(NOLOCK)
|
||||
ON rc.ProductCode = a.ItemCode
|
||||
LEFT JOIN dbo.cdItemAttributeDesc d
|
||||
ON d.ItemTypeCode = a.ItemTypeCode
|
||||
AND d.AttributeTypeCode = a.AttributeTypeCode
|
||||
AND d.AttributeCode = a.AttributeCode
|
||||
AND d.LangCode = 'TR'
|
||||
WHERE a.ItemTypeCode = 1
|
||||
AND a.AttributeTypeCode IN (1,2,10,29,41,42,44,45)
|
||||
GROUP BY LTRIM(RTRIM(a.ItemCode))
|
||||
GROUP BY a.ItemCode
|
||||
)
|
||||
SELECT
|
||||
rc.ProductCode,
|
||||
@@ -963,13 +963,13 @@ func GetProductPricingPage(ctx context.Context, page int, limit int, filters Pro
|
||||
COALESCE(attr.Marka, '') AS Marka,
|
||||
COALESCE(attr.BrandCode, '') AS BrandCode
|
||||
FROM req_codes rc
|
||||
INNER JOIN dbo.cdItem ci WITH(NOLOCK)
|
||||
INNER JOIN dbo.cdItem ci
|
||||
ON ci.ItemTypeCode = 1
|
||||
AND LTRIM(RTRIM(ci.ItemCode)) = rc.ProductCode
|
||||
AND ci.ItemCode = rc.ProductCode
|
||||
LEFT JOIN attr
|
||||
ON attr.ProductCode = rc.ProductCode
|
||||
WHERE ISNULL(ci.IsBlocked, 0) = 0
|
||||
AND LEN(LTRIM(RTRIM(ci.ItemCode))) = 13
|
||||
AND LEN(ci.ItemCode) = 13
|
||||
AND COALESCE(attr.UrunIlkGrubuCode, '') IN ('SERI', 'AKSESUAR')
|
||||
ORDER BY rc.ProductCode ASC
|
||||
OFFSET ` + strconv.Itoa(offset) + ` ROWS
|
||||
@@ -1109,16 +1109,16 @@ func GetProductPricingPage(ctx context.Context, page int, limit int, filters Pro
|
||||
-- Base prices from Nebim V3 price lists (trPriceListLine).
|
||||
-- Pick the latest record per (ItemCode, Currency) using ValidDate/ValidTime, then LastUpdatedDate.
|
||||
SELECT
|
||||
LTRIM(RTRIM(p.ItemCode)) AS ItemCode,
|
||||
p.ItemCode AS ItemCode,
|
||||
LTRIM(RTRIM(p.DocCurrencyCode)) AS DocCurrencyCode,
|
||||
CAST(p.Price AS DECIMAL(18, 2)) AS Price,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY LTRIM(RTRIM(p.ItemCode)), LTRIM(RTRIM(p.DocCurrencyCode))
|
||||
PARTITION BY p.ItemCode, LTRIM(RTRIM(p.DocCurrencyCode))
|
||||
ORDER BY p.ValidDate DESC, p.ValidTime DESC, p.LastUpdatedDate DESC
|
||||
) AS rn
|
||||
FROM dbo.trPriceListLine p WITH(NOLOCK)
|
||||
FROM dbo.trPriceListLine p
|
||||
INNER JOIN req_codes rc
|
||||
ON rc.ProductCode = LTRIM(RTRIM(p.ItemCode))
|
||||
ON rc.ProductCode = p.ItemCode
|
||||
WHERE p.ItemTypeCode = 1
|
||||
AND ISNULL(p.IsDisabled, 0) = 0
|
||||
AND LTRIM(RTRIM(p.DocCurrencyCode)) IN ('USD', 'TRY')
|
||||
@@ -1140,29 +1140,29 @@ func GetProductPricingPage(ctx context.Context, page int, limit int, filters Pro
|
||||
),
|
||||
latest_base_price AS (
|
||||
SELECT
|
||||
LTRIM(RTRIM(b.ItemCode)) AS ItemCode,
|
||||
b.ItemCode AS ItemCode,
|
||||
CAST(b.Price AS DECIMAL(18, 2)) AS CostPrice,
|
||||
CONVERT(VARCHAR(10), b.PriceDate, 23) AS LastPricingDate,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY LTRIM(RTRIM(b.ItemCode))
|
||||
PARTITION BY b.ItemCode
|
||||
ORDER BY b.PriceDate DESC, b.LastUpdatedDate DESC
|
||||
) AS rn
|
||||
FROM prItemBasePrice b
|
||||
INNER JOIN req_codes rc
|
||||
ON rc.ProductCode = LTRIM(RTRIM(b.ItemCode))
|
||||
ON rc.ProductCode = b.ItemCode
|
||||
WHERE b.ItemTypeCode = 1
|
||||
AND b.BasePriceCode = 1
|
||||
AND LTRIM(RTRIM(b.CurrencyCode)) = 'USD'
|
||||
),
|
||||
stock_entry_dates AS (
|
||||
SELECT
|
||||
LTRIM(RTRIM(s.ItemCode)) AS ItemCode,
|
||||
s.ItemCode AS ItemCode,
|
||||
CONVERT(VARCHAR(10), MAX(s.OperationDate), 23) AS StockEntryDate
|
||||
FROM trStock s WITH(NOLOCK)
|
||||
FROM trStock s
|
||||
INNER JOIN req_codes rc
|
||||
ON rc.ProductCode = LTRIM(RTRIM(s.ItemCode))
|
||||
ON rc.ProductCode = s.ItemCode
|
||||
WHERE s.ItemTypeCode = 1
|
||||
AND LEN(LTRIM(RTRIM(s.ItemCode))) = 13
|
||||
AND LEN(s.ItemCode) = 13
|
||||
AND s.In_Qty1 > 0
|
||||
AND LTRIM(RTRIM(s.InnerProcessCode)) = 'OP'
|
||||
AND LTRIM(RTRIM(s.WarehouseCode)) IN (
|
||||
@@ -1170,51 +1170,51 @@ func GetProductPricingPage(ctx context.Context, page int, limit int, filters Pro
|
||||
'1-0-24','1-2-6','1-1-14','1-0-2','1-0-52','1-1-2','1-0-21','1-1-3',
|
||||
'1-0-33','101','1-014','1-0-49','1-0-36'
|
||||
)
|
||||
GROUP BY LTRIM(RTRIM(s.ItemCode))
|
||||
GROUP BY s.ItemCode
|
||||
),
|
||||
stock_base AS (
|
||||
SELECT
|
||||
LTRIM(RTRIM(s.ItemCode)) AS ItemCode,
|
||||
s.ItemCode AS ItemCode,
|
||||
SUM(s.In_Qty1 - s.Out_Qty1) AS InventoryQty1
|
||||
FROM trStock s WITH(NOLOCK)
|
||||
FROM trStock s
|
||||
INNER JOIN req_codes rc
|
||||
ON rc.ProductCode = LTRIM(RTRIM(s.ItemCode))
|
||||
ON rc.ProductCode = s.ItemCode
|
||||
WHERE s.ItemTypeCode = 1
|
||||
AND LEN(LTRIM(RTRIM(s.ItemCode))) = 13
|
||||
GROUP BY LTRIM(RTRIM(s.ItemCode))
|
||||
AND LEN(s.ItemCode) = 13
|
||||
GROUP BY s.ItemCode
|
||||
),
|
||||
pick_base AS (
|
||||
SELECT
|
||||
LTRIM(RTRIM(p.ItemCode)) AS ItemCode,
|
||||
p.ItemCode AS ItemCode,
|
||||
SUM(p.Qty1) AS PickingQty1
|
||||
FROM PickingStates p
|
||||
INNER JOIN req_codes rc
|
||||
ON rc.ProductCode = LTRIM(RTRIM(p.ItemCode))
|
||||
ON rc.ProductCode = p.ItemCode
|
||||
WHERE p.ItemTypeCode = 1
|
||||
AND LEN(LTRIM(RTRIM(p.ItemCode))) = 13
|
||||
GROUP BY LTRIM(RTRIM(p.ItemCode))
|
||||
AND LEN(p.ItemCode) = 13
|
||||
GROUP BY p.ItemCode
|
||||
),
|
||||
reserve_base AS (
|
||||
SELECT
|
||||
LTRIM(RTRIM(r.ItemCode)) AS ItemCode,
|
||||
r.ItemCode AS ItemCode,
|
||||
SUM(r.Qty1) AS ReserveQty1
|
||||
FROM ReserveStates r
|
||||
INNER JOIN req_codes rc
|
||||
ON rc.ProductCode = LTRIM(RTRIM(r.ItemCode))
|
||||
ON rc.ProductCode = r.ItemCode
|
||||
WHERE r.ItemTypeCode = 1
|
||||
AND LEN(LTRIM(RTRIM(r.ItemCode))) = 13
|
||||
GROUP BY LTRIM(RTRIM(r.ItemCode))
|
||||
AND LEN(r.ItemCode) = 13
|
||||
GROUP BY r.ItemCode
|
||||
),
|
||||
disp_base AS (
|
||||
SELECT
|
||||
LTRIM(RTRIM(d.ItemCode)) AS ItemCode,
|
||||
d.ItemCode AS ItemCode,
|
||||
SUM(d.Qty1) AS DispOrderQty1
|
||||
FROM DispOrderStates d
|
||||
INNER JOIN req_codes rc
|
||||
ON rc.ProductCode = LTRIM(RTRIM(d.ItemCode))
|
||||
ON rc.ProductCode = d.ItemCode
|
||||
WHERE d.ItemTypeCode = 1
|
||||
AND LEN(LTRIM(RTRIM(d.ItemCode))) = 13
|
||||
GROUP BY LTRIM(RTRIM(d.ItemCode))
|
||||
AND LEN(d.ItemCode) = 13
|
||||
GROUP BY d.ItemCode
|
||||
)
|
||||
SELECT
|
||||
rc.ProductCode,
|
||||
@@ -1311,7 +1311,7 @@ func GetProductPricingPage(ctx context.Context, page int, limit int, filters Pro
|
||||
SELECT
|
||||
LTRIM(RTRIM(m.UrunKodu)) AS UrunKodu,
|
||||
CONVERT(VARCHAR(10), MAX(m.Tarihi), 23) AS LastCostingDate
|
||||
FROM dbo.spUrtOnMLMas m WITH(NOLOCK)
|
||||
FROM dbo.spUrtOnMLMas m
|
||||
INNER JOIN req_codes rc
|
||||
ON rc.ProductCode = LTRIM(RTRIM(m.UrunKodu))
|
||||
GROUP BY LTRIM(RTRIM(m.UrunKodu));
|
||||
|
||||
Reference in New Issue
Block a user