Changes between Version 2 and Version 3 of AdvancedReports


Ignore:
Timestamp:
01/06/25 12:00:32 (9 days ago)
Author:
185022
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AdvancedReports

    v2 v3  
    44
    55{{{#!sql
    6 
     6with latestPrice as (
     7    select p.art_id,p.price as latest_price
     8    from price p
     9    where p.price_eff_date = (
     10        select max(price_eff_date)
     11        from price
     12        where p.art_id=p.art_id
     13        )
     14)
     15select c.cust_company_name as customerName,
     16       c.user_id as customerId,
     17       a.art_name as articleName,
     18       count(au.unit_id) as quantity,
     19       lp.latest_price as unitPrice,
     20       count(au.unit_id)*lp.latest_price as total_spent,
     21       sum(o.ord_sum) as orderTotal
     22from orders o
     23join article_unit au on o.ord_id = au.ord_id
     24join article a on au.art_id = a.art_id
     25join customer c on o.cust_id = c.user_id
     26join latestPrice lp on a.art_id=lp.art_id
     27where o.ord_date between '2024-01-01' and '2024-12-31'
     28group by c.cust_company_name,c.user_id,a.art_name,lp.latest_price
     29order by c.cust_company_name,a.art_name;
    730}}}
    831
    9 ==== Автоматско дополнување на залихите во зависност од моменталната и претпоставената идна потрошувачка/Артикли кои се при крај на залиха во магацинот и треба да се набават дополнителни количини
     32==== Артикли кои се при крај на залиха во магацинот и треба да се набават дополнителни количини
    1033
    1134{{{#!sql
    12 
     35select a.art_name as articleName, w.wh_id as warehouseId, count(distinct au.unit_id) as unitNumber
     36from article_unit au
     37         join warehouse w on au.wh_id = w.wh_id
     38         join article a on au.art_id = a.art_id
     39where w.wh_id = 1
     40group by a.art_name, w.wh_id
     41order by unitNumber;
    1342}}}
    1443
     
    1645
    1746{{{#!sql
    18 
     47with salesByPrice as (select au.art_id,
     48                             p.price,
     49                             p.price_eff_date,
     50                             count(au.unit_id)           as unitsSold,
     51                             count(au.unit_id) * p.price as revenue
     52                      from article_unit au
     53                               join orders o on au.ord_id = o.ord_id
     54                               join price p on au.art_id = p.art_id
     55                      where o.ord_date >= p.price_eff_date
     56                        and o.ord_date < coalesce(
     57                              (select min(price_eff_date)
     58                               from price p2
     59                               where p2.art_id = p.art_id
     60                                 and p2.price_eff_date > p.price_eff_date),
     61                              '9999-12-31'
     62                                         )
     63                      group by au.art_id, p.price, p.price_eff_date)
     64select a.art_name        as articleName,
     65       sp.price          as unitPrice,
     66       sp.price_eff_date as priceEffectiveDate,
     67       sp.unitsSold,
     68       sp.revenue
     69from salesByPrice sp
     70         join article a on sp.art_id = a.art_id
     71order by a.art_name,sp.price_eff_date;
    1972}}}
    2073
     
    2275
    2376{{{#!sql
    24 
     77with ArticleSales as (
     78    select au.art_id,
     79           a.ctg_id,
     80           w.wh_id,
     81           c.city_id,
     82           r.region_id,
     83           p.price as unitPrice,
     84           count(au.unit_id) as unitsSold,
     85           count(au.unit_id)*p.price as income
     86    from article_unit au
     87    join article a on au.art_id = a.art_id
     88    join warehouse w on au.wh_id = w.wh_id
     89    join city c on w.city_id = c.city_id
     90    join region r on c.region_id = r.region_id
     91    join price p on a.art_id = p.art_id
     92    join orders o on au.ord_id = o.ord_id
     93    where o.ord_date>=p.price_eff_date
     94    group by au.art_id, a.ctg_id, w.wh_id, c.city_id, r.region_id, p.price, p.price
     95)
     96select r.region_name as region,
     97       cat.ctg_name as category,
     98       sum(asales.unitsSold) as totalUnitsSold,
     99       sum(asales.income) as totalIncome
     100from ArticleSales asales
     101join category cat on asales.ctg_id=cat.ctg_id
     102join region r on asales.region_id=r.region_id
     103group by r.region_name, cat.ctg_name
     104order by r.region_name, totalIncome desc;
    25105}}}
    26106
     
    28108
    29109{{{#!sql
    30 
     110select w.wh_id as warehouseId,
     111       w.wh_adr as warehouseAddress,
     112       c.city_name as warehouseCity,
     113       r.region_name as warehouseRegion,
     114       extract(year from o.ord_date) as year,
     115       extract(quarter from o.ord_date) as quarter,
     116       count(au.unit_id) as totalArticlesSold,
     117       sum(o.ord_sum) as totalSales
     118from warehouse w
     119join city c on w.city_id = c.city_id
     120join region r on c.region_id = r.region_id
     121join article_unit au on w.wh_id = au.wh_id
     122join orders o on au.ord_id = o.ord_id
     123group by w.wh_id, w.wh_adr, c.city_name, r.region_name, extract(year from o.ord_date), extract(quarter from o.ord_date)
     124order by w.wh_id,year,quarter;
    31125}}}
    32126
     
    34128
    35129{{{#!sql
    36 
     130select w.wh_id as warehouseId,
     131       c.city_name as warehouseCity,
     132       r.region_name as warehouseRegion,
     133       extract(year from o.ord_date) as year,
     134       sum(o.ord_sum) as totalIncome,
     135       sum(ord_sum)-sum(au.unit_cost_price) as total_profit
     136from warehouse w
     137         join city c on w.city_id = c.city_id
     138         join region r on c.region_id = r.region_id
     139         join article_unit au on w.wh_id = au.wh_id
     140         join orders o on au.ord_id = o.ord_id
     141group by w.wh_id, c.city_name, r.region_name, o.ord_date
     142order by w.wh_id,year;
    37143}}}
    38144