Changes between Version 3 and Version 4 of AdvancedReports


Ignore:
Timestamp:
01/22/25 15:33:45 (16 hours ago)
Author:
153093
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AdvancedReports

    v3 v4  
    55
    66   - Оваа функција вади извештај според месец и година за сите клиенти. Извештајот содржи:
     7   
     8{{{
     9CREATE FUNCTION GetCustomerShipmentsReport(month INT, year INT)
     10RETURNS TABLE(
     11    CustomerName varchar(50),
     12    CustomerTypeName varchar(50),
     13    TotalWineQuantity bigint,
     14    TotalWineProfit double precision,
     15    TotalWineBasePrice double precision,
     16    TotalWineAgreedPrice double precision,
     17    PercentageDifference double precision
     18)
     19LANGUAGE plpgsql
     20AS $$
     21BEGIN
     22    RETURN QUERY
     23    SELECT
     24       c.customer_name as CustomerName,
     25       ct.customer_type_name as CustomerTypeName,
     26       SUM(wine_quantity) AS TotalWineQuantity,
     27       SUM(wine_base_price * wine_quantity) AS TotalWineBasePrice,
     28       SUM(wine_agreed_price * wine_quantity) AS TotalWineAgreedPrice,
     29       SUM((wine_agreed_price * wine_quantity) - (wine_base_price * wine_quantity)) as TotalWineProfit,
     30       (SUM((wine_agreed_price * wine_quantity) - (wine_base_price * wine_quantity)) / SUM(wine_base_price * wine_quantity)) * 100 as PercentageDifference
     31FROM shipment_load sl
     32join customer c on c.customer_id = sl.customer_id
     33join customer_type ct on c.customer_type_id = ct.customer_type_id
     34JOIN shipment s ON sl.shipment_id = s.shipment_id
     35WHERE EXTRACT(MONTH FROM s.shipment_date) = month AND EXTRACT(YEAR FROM s.shipment_date) = year
     36GROUP BY c.customer_name, ct.customer_type_name
     37order by SUM((wine_agreed_price * wine_quantity) - (wine_base_price * wine_quantity)) desc;
     38END;
     39$$;
     40}}}
     41
    742 
    843