Changes between Version 2 and Version 3 of AdvancedReports


Ignore:
Timestamp:
05/17/25 13:05:24 (7 days ago)
Author:
213231
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AdvancedReports

    v2 v3  
    11
    22== **Напредни извештаи од базата (SQL и складирани процедури)**
     3
     4== 1.Вкупен приход по месец од купување и изнајмување
     5
     6
     7
     8{{{
     9SELECT
     10    DATE_FORMAT(p.ProcurementDate, '%Y-%m') AS Mesec,
     11    SUM(COALESCE(t.TotalPrice, t.MonthlyPay * t.Duration)) AS VkupenPrihod
     12FROM
     13    Procurement p
     14JOIN
     15    T_Type t ON p.TransactionID = t.TransactionID
     16GROUP BY
     17    Mesec
     18ORDER BY
     19    Mesec DESC;
     20}}}
     21
     22== 2.Најактивни клиенти според број на трансакции
     23
     24
     25
     26
     27{{{
     28SELECT
     29    c.CustomerName, c.CustomerSurName,
     30    COUNT(p.TransactionID) AS VkupnoTransakcii
     31FROM
     32    Customer c
     33JOIN
     34    Procurement p ON c.CustomerID = p.CustomerID
     35GROUP BY
     36    c.CustomerID
     37ORDER BY
     38    VkupnoTransakcii DESC;
     39}}}
     40
     41
     42== 3.Најчесто сервисирани производи (камиони/приколки)
     43
     44
     45
     46
     47{{{
     48SELECT
     49    pr.Model,
     50    COUNT(m.MainID) AS BrojNaServisi
     51FROM
     52    Maintenance m
     53JOIN
     54    Product pr ON m.ProductID = pr.ProductID
     55GROUP BY
     56    pr.ProductID
     57ORDER BY
     58    BrojNaServisi DESC;
     59}}}
     60
     61
     62== 4.Приход по тип на трансакција
     63
     64
     65
     66
     67{{{
     68SELECT
     69    t.Type,
     70    SUM(CASE
     71            WHEN t.Type = 'Buy' THEN t.TotalPrice
     72            WHEN t.Type = 'Rent' THEN t.MonthlyPay * t.Duration
     73         END) AS VkupenPrihod
     74FROM
     75    T_Type t
     76GROUP BY
     77    t.Type;
     78}}}
     79
     80
     81== 5.Производи со најдобри оценки од корисници
     82
     83
     84
     85
     86{{{
     87SELECT
     88    pr.Model,
     89    AVG(f.Rating) AS ProsecnaOcena,
     90    COUNT(f.FeedbackID) AS BrojNaOceni
     91FROM
     92    CustomerFeedback f
     93JOIN
     94    Product pr ON f.ProductID = pr.ProductID
     95GROUP BY
     96    f.ProductID
     97ORDER BY
     98    ProsecnaOcena DESC, BrojNaOceni DESC;
     99}}}
     100
     101
     102== 6. Највредни производи (цени)
     103
     104
     105
     106
     107{{{
     108SELECT
     109    Model, Price, Status
     110FROM
     111    Product
     112ORDER BY
     113    Price DESC;
     114}}}
     115
     116
     117== 7.Месечен извештај по типови трансакции и вкупен приход
     118
     119
     120
     121
     122
     123{{{
     124SELECT
     125    DATE_FORMAT(p.ProcurementDate, '%Y-%m') AS Month_Year,
     126    COUNT(p.TransactionID) AS Total_Transactions,
     127    COUNT(CASE WHEN t.Type = 'Rent' THEN 1 END) AS Rent_Transactions,
     128    COUNT(CASE WHEN t.Type = 'Buy' THEN 1 END) AS Buy_Transactions,
     129    SUM(CASE WHEN t.Type = 'Rent' THEN t.MonthlyPay * t.Duration ELSE 0 END) AS Rent_Revenue,
     130    SUM(CASE WHEN t.Type = 'Buy' THEN t.TotalPrice ELSE 0 END) AS Buy_Revenue,
     131    COUNT(DISTINCT m.MainID) AS Maintenance_Count,
     132    ROUND(AVG(f.Rating), 2) AS Avg_Feedback_Rating
     133FROM
     134    Procurement p
     135LEFT JOIN
     136    T_Type t ON p.TransactionID = t.TransactionID
     137LEFT JOIN
     138    Maintenance m ON p.ProductID = m.ProductID
     139                 AND DATE_FORMAT(p.ProcurementDate, '%Y-%m') = DATE_FORMAT(m.MainDate, '%Y-%m')
     140LEFT JOIN
     141    CustomerFeedback f ON p.TransactionID = f.TransactionID
     142GROUP BY
     143    Month_Year
     144ORDER BY
     145    Month_Year DESC;
     146}}}