Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -5,12 +5,20 @@ import (
|
||||
"bssapp-backend/models"
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetProductPricingList(ctx context.Context) ([]models.ProductPricing, error) {
|
||||
const query = `
|
||||
func GetProductPricingList(ctx context.Context, limit int, offset int) ([]models.ProductPricing, error) {
|
||||
if limit <= 0 {
|
||||
limit = 500
|
||||
}
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
|
||||
query := `
|
||||
WITH base_products AS (
|
||||
SELECT
|
||||
LTRIM(RTRIM(ProductCode)) AS ProductCode,
|
||||
@@ -27,6 +35,13 @@ func GetProductPricingList(ctx context.Context) ([]models.ProductPricing, error)
|
||||
AND IsBlocked = 0
|
||||
AND LEN(LTRIM(RTRIM(ProductCode))) = 13
|
||||
),
|
||||
paged_products AS (
|
||||
SELECT
|
||||
bp.ProductCode
|
||||
FROM base_products bp
|
||||
ORDER BY bp.ProductCode
|
||||
OFFSET %d ROWS FETCH NEXT %d ROWS ONLY
|
||||
),
|
||||
latest_base_price AS (
|
||||
SELECT
|
||||
LTRIM(RTRIM(b.ItemCode)) AS ItemCode,
|
||||
@@ -42,8 +57,8 @@ func GetProductPricingList(ctx context.Context) ([]models.ProductPricing, error)
|
||||
AND LTRIM(RTRIM(b.CurrencyCode)) = 'USD'
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM base_products bp
|
||||
WHERE bp.ProductCode = LTRIM(RTRIM(b.ItemCode))
|
||||
FROM paged_products pp
|
||||
WHERE pp.ProductCode = LTRIM(RTRIM(b.ItemCode))
|
||||
)
|
||||
),
|
||||
stock_entry_dates AS (
|
||||
@@ -61,8 +76,8 @@ func GetProductPricingList(ctx context.Context) ([]models.ProductPricing, error)
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM base_products bp
|
||||
WHERE bp.ProductCode = LTRIM(RTRIM(s.ItemCode))
|
||||
FROM paged_products pp
|
||||
WHERE pp.ProductCode = LTRIM(RTRIM(s.ItemCode))
|
||||
)
|
||||
GROUP BY LTRIM(RTRIM(s.ItemCode))
|
||||
),
|
||||
@@ -75,8 +90,8 @@ func GetProductPricingList(ctx context.Context) ([]models.ProductPricing, error)
|
||||
AND LEN(LTRIM(RTRIM(s.ItemCode))) = 13
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM base_products bp
|
||||
WHERE bp.ProductCode = LTRIM(RTRIM(s.ItemCode))
|
||||
FROM paged_products pp
|
||||
WHERE pp.ProductCode = LTRIM(RTRIM(s.ItemCode))
|
||||
)
|
||||
GROUP BY LTRIM(RTRIM(s.ItemCode))
|
||||
),
|
||||
@@ -89,8 +104,8 @@ func GetProductPricingList(ctx context.Context) ([]models.ProductPricing, error)
|
||||
AND LEN(LTRIM(RTRIM(p.ItemCode))) = 13
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM base_products bp
|
||||
WHERE bp.ProductCode = LTRIM(RTRIM(p.ItemCode))
|
||||
FROM paged_products pp
|
||||
WHERE pp.ProductCode = LTRIM(RTRIM(p.ItemCode))
|
||||
)
|
||||
GROUP BY LTRIM(RTRIM(p.ItemCode))
|
||||
),
|
||||
@@ -103,8 +118,8 @@ func GetProductPricingList(ctx context.Context) ([]models.ProductPricing, error)
|
||||
AND LEN(LTRIM(RTRIM(r.ItemCode))) = 13
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM base_products bp
|
||||
WHERE bp.ProductCode = LTRIM(RTRIM(r.ItemCode))
|
||||
FROM paged_products pp
|
||||
WHERE pp.ProductCode = LTRIM(RTRIM(r.ItemCode))
|
||||
)
|
||||
GROUP BY LTRIM(RTRIM(r.ItemCode))
|
||||
),
|
||||
@@ -117,29 +132,29 @@ func GetProductPricingList(ctx context.Context) ([]models.ProductPricing, error)
|
||||
AND LEN(LTRIM(RTRIM(d.ItemCode))) = 13
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM base_products bp
|
||||
WHERE bp.ProductCode = LTRIM(RTRIM(d.ItemCode))
|
||||
FROM paged_products pp
|
||||
WHERE pp.ProductCode = LTRIM(RTRIM(d.ItemCode))
|
||||
)
|
||||
GROUP BY LTRIM(RTRIM(d.ItemCode))
|
||||
),
|
||||
stock_totals AS (
|
||||
SELECT
|
||||
bp.ProductCode AS ItemCode,
|
||||
pp.ProductCode AS ItemCode,
|
||||
CAST(ROUND(
|
||||
ISNULL(sb.InventoryQty1, 0)
|
||||
- ISNULL(pb.PickingQty1, 0)
|
||||
- ISNULL(rb.ReserveQty1, 0)
|
||||
- ISNULL(db.DispOrderQty1, 0)
|
||||
, 2) AS DECIMAL(18, 2)) AS StockQty
|
||||
FROM base_products bp
|
||||
FROM paged_products pp
|
||||
LEFT JOIN stock_base sb
|
||||
ON sb.ItemCode = bp.ProductCode
|
||||
ON sb.ItemCode = pp.ProductCode
|
||||
LEFT JOIN pick_base pb
|
||||
ON pb.ItemCode = bp.ProductCode
|
||||
ON pb.ItemCode = pp.ProductCode
|
||||
LEFT JOIN reserve_base rb
|
||||
ON rb.ItemCode = bp.ProductCode
|
||||
ON rb.ItemCode = pp.ProductCode
|
||||
LEFT JOIN disp_base db
|
||||
ON db.ItemCode = bp.ProductCode
|
||||
ON db.ItemCode = pp.ProductCode
|
||||
)
|
||||
SELECT
|
||||
bp.ProductCode AS ProductCode,
|
||||
@@ -155,7 +170,9 @@ func GetProductPricingList(ctx context.Context) ([]models.ProductPricing, error)
|
||||
bp.Icerik,
|
||||
bp.Karisim,
|
||||
bp.Marka
|
||||
FROM base_products bp
|
||||
FROM paged_products pp
|
||||
INNER JOIN base_products bp
|
||||
ON bp.ProductCode = pp.ProductCode
|
||||
LEFT JOIN latest_base_price lp
|
||||
ON lp.ItemCode = bp.ProductCode
|
||||
AND lp.rn = 1
|
||||
@@ -165,6 +182,7 @@ func GetProductPricingList(ctx context.Context) ([]models.ProductPricing, error)
|
||||
ON st.ItemCode = bp.ProductCode
|
||||
ORDER BY bp.ProductCode;
|
||||
`
|
||||
query = fmt.Sprintf(query, offset, limit)
|
||||
|
||||
var (
|
||||
rows *sql.Rows
|
||||
|
||||
Reference in New Issue
Block a user