Fix product performance grouped JSON build
This commit is contained in:
@@ -1170,6 +1170,11 @@ func InitRoutes(pgDB *sql.DB, mssql *sql.DB, ml *mailer.GraphMailer) *mux.Router
|
||||
"costing", "view",
|
||||
wrapV3(http.HandlerFunc(routes.GetProductionHasCostHistoryHandler)),
|
||||
)
|
||||
bindV3(r, pgDB,
|
||||
"/api/pricing/production-product-costing/firm-cost-history", "GET",
|
||||
"costing", "view",
|
||||
wrapV3(http.HandlerFunc(routes.GetProductionFirmCostHistoryHandler)),
|
||||
)
|
||||
bindV3(r, pgDB,
|
||||
"/api/pricing/production-product-costing/has-cost-detail-groups", "GET",
|
||||
"costing", "view",
|
||||
|
||||
@@ -62,6 +62,16 @@ type ProductionHasCostHistoryRow struct {
|
||||
SAciklama string `json:"sAciklama"`
|
||||
}
|
||||
|
||||
type ProductionFirmCostHistoryRow struct {
|
||||
NOnMLNo int `json:"nOnMLNo"`
|
||||
UrunKodu string `json:"UrunKodu"`
|
||||
UrunAdi string `json:"UrunAdi"`
|
||||
Tarihi string `json:"Tarihi"`
|
||||
TPCount int `json:"tpCount"`
|
||||
DTCount int `json:"dtCount"`
|
||||
TotalRows int `json:"totalRows"`
|
||||
}
|
||||
|
||||
type ProductionType struct {
|
||||
ID string `json:"id"`
|
||||
Aciklama string `json:"aciklama"`
|
||||
|
||||
@@ -1049,6 +1049,62 @@ ORDER BY
|
||||
return uretimDB.QueryContext(ctx, sqlText, productCode)
|
||||
}
|
||||
|
||||
func GetProductionFirmCostHistory(
|
||||
ctx context.Context,
|
||||
uretimDB *sql.DB,
|
||||
nFirmaID int,
|
||||
excludeOnMLNo int,
|
||||
limit int,
|
||||
) ([]models.ProductionFirmCostHistoryRow, error) {
|
||||
if nFirmaID <= 0 {
|
||||
return []models.ProductionFirmCostHistoryRow{}, nil
|
||||
}
|
||||
if limit <= 0 {
|
||||
limit = 100
|
||||
}
|
||||
if limit > 300 {
|
||||
limit = 300
|
||||
}
|
||||
|
||||
rows, err := uretimDB.QueryContext(ctx, `
|
||||
SELECT TOP (@p3)
|
||||
M.nOnMLNo,
|
||||
LTRIM(RTRIM(ISNULL(M.UrunKodu, ''))) AS UrunKodu,
|
||||
ISNULL(M.UrunAdi, '') AS UrunAdi,
|
||||
CONVERT(VARCHAR(10), COALESCE(M.Tarihi, M.dteKayitTarihi), 23) AS Tarihi,
|
||||
SUM(CASE WHEN G.Grup = 'TP' THEN 1 ELSE 0 END) AS TPCount,
|
||||
SUM(CASE WHEN G.Grup = 'DT' THEN 1 ELSE 0 END) AS DTCount,
|
||||
COUNT(*) AS TotalRows
|
||||
FROM dbo.spUrtOnMLMas M
|
||||
INNER JOIN dbo.spUrtOnMLMasDet D
|
||||
ON D.nOnMLNo = M.nOnMLNo
|
||||
LEFT JOIN dbo.spUrtOnMLHammaddeTuru H
|
||||
ON H.nHammaddeTuruNo = D.nHammaddeTuruNo
|
||||
CROSS APPLY (
|
||||
SELECT UPPER(ISNULL(NULLIF(LTRIM(RTRIM(D.sAciklama3)), ''), LTRIM(RTRIM(ISNULL(H.sAciklama3, ''))))) AS Grup
|
||||
) G
|
||||
WHERE ISNULL(M.nFirmaID, 0) = @p1
|
||||
AND (ISNULL(@p2, 0) <= 0 OR M.nOnMLNo <> @p2)
|
||||
AND G.Grup IN ('TP', 'DT')
|
||||
GROUP BY M.nOnMLNo, M.UrunKodu, M.UrunAdi, M.Tarihi, M.dteKayitTarihi
|
||||
ORDER BY COALESCE(M.Tarihi, M.dteKayitTarihi) DESC, M.nOnMLNo DESC
|
||||
`, nFirmaID, excludeOnMLNo, limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
out := make([]models.ProductionFirmCostHistoryRow, 0, limit)
|
||||
for rows.Next() {
|
||||
var item models.ProductionFirmCostHistoryRow
|
||||
if err := rows.Scan(&item.NOnMLNo, &item.UrunKodu, &item.UrunAdi, &item.Tarihi, &item.TPCount, &item.DTCount, &item.TotalRows); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, item)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
func GetProductionHasCostDetailRowsByOnMLNo(
|
||||
ctx context.Context,
|
||||
uretimDB *sql.DB,
|
||||
|
||||
@@ -330,6 +330,32 @@ func GetProductionHasCostHistoryHandler(w http.ResponseWriter, r *http.Request)
|
||||
_ = json.NewEncoder(w).Encode(list)
|
||||
}
|
||||
|
||||
// GET /api/pricing/production-product-costing/firm-cost-history
|
||||
func GetProductionFirmCostHistoryHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
uretimDB := db.GetUretimDB()
|
||||
if uretimDB == nil {
|
||||
http.Error(w, "URETIM veritabani baglantisi aktif degil", http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
|
||||
nFirmaID, _ := strconv.Atoi(strings.TrimSpace(r.URL.Query().Get("n_firma_id")))
|
||||
excludeOnMLNo, _ := strconv.Atoi(strings.TrimSpace(r.URL.Query().Get("exclude_onml_no")))
|
||||
limit := parsePositiveIntOrDefault(r.URL.Query().Get("limit"), 100)
|
||||
if nFirmaID <= 0 {
|
||||
http.Error(w, "n_firma_id zorunlu ve pozitif sayi olmali", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
rows, err := queries.GetProductionFirmCostHistory(r.Context(), uretimDB, nFirmaID, excludeOnMLNo, limit)
|
||||
if err != nil {
|
||||
log.Printf("[ProductionFirmCostHistory] query error: %v", err)
|
||||
http.Error(w, "Veritabani hatasi", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(rows)
|
||||
}
|
||||
|
||||
// GET /api/pricing/production-product-costing/has-cost-detail-groups
|
||||
func GetProductionHasCostDetailGroupsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
|
||||
Reference in New Issue
Block a user