| 1 | {{{#!html |
| 2 | <h1 style="text-align: left; color: #5d5250; margin: 0; margin-top: 10px"> |
| 3 | Напредни извештаи од базата (SQL и складирани процедури) |
| 4 | </h1> |
| 5 | <hr style="margin: 0; margin-bottom:10px"> |
| 6 | }}} |
| 7 | |
| 8 | {{{#!html |
| 9 | <h3 style="text-align: left; color: #5d5250; margin: 0; margin-top: 10px"> |
| 10 | Промет во последната година |
| 11 | </h3> |
| 12 | <hr style="margin: 0; margin-bottom:10px"> |
| 13 | }}} |
| 14 | |
| 15 | {{{#!sql |
| 16 | SELECT |
| 17 | SUM(CASE WHEN TipDok.TipID = 10 THEN -Stavka.Cena_Vkupno |
| 18 | WHEN TipDok.TipID = 20 THEN Stavka.Cena_Vkupno END) as Promet |
| 19 | FROM |
| 20 | Stavka |
| 21 | JOIN TipDok ON Stavka.TipID = TipDok.TipID |
| 22 | WHERE |
| 23 | Datum >= date_trunc('year', current_date) - INTERVAL '1 year' |
| 24 | AND Datum < date_trunc('year', current_date) |
| 25 | }}} |
| 26 | |
| 27 | {{{#!html |
| 28 | <h3 style="text-align: left; color: #5d5250; margin: 0; margin-top: 10px"> |
| 29 | Најтргован продукт во последната година |
| 30 | </h3> |
| 31 | <hr style="margin: 0; margin-bottom:10px"> |
| 32 | }}} |
| 33 | |
| 34 | {{{#!sql |
| 35 | SELECT Artikal_Ime, SUM(Kolicina) |
| 36 | AS Vkupno_Trgovan |
| 37 | FROM |
| 38 | LagerList |
| 39 | JOIN Artikal ON LagerList.Artikal_ID = Artikal.Artikal_ID |
| 40 | JOIN Stavka ON LagerList.StavkaID = Stavka.StavkaID |
| 41 | WHERE |
| 42 | Datum >= date_trunc('year', current_date) - INTERVAL '1 year' |
| 43 | AND Datum < date_trunc('year', current_date) |
| 44 | GROUP BY Artikal_Ime |
| 45 | ORDER BY Vkupno_Trgovan DESC |
| 46 | LIMIT 1; |
| 47 | }}} |
| 48 | |
| 49 | {{{#!html |
| 50 | <h3 style="text-align: left; color: #5d5250; margin: 0; margin-top: 10px"> |
| 51 | Клиенти подредени по најпрофитабилни во последниот квартал |
| 52 | </h3> |
| 53 | <hr style="margin: 0; margin-bottom:10px"> |
| 54 | }}} |
| 55 | |
| 56 | {{{#!sql |
| 57 | SELECT |
| 58 | Klient.KlientIme, |
| 59 | SUM(CASE WHEN Stavka.TipID = 10 THEN -Stavka.Cena_Vkupno |
| 60 | WHEN Stavka.TipID = 20 THEN Stavka.Cena_Vkupno END) AS Vkupen_Promet |
| 61 | FROM |
| 62 | Klient |
| 63 | JOIN Stavka ON Klient.KlientID = Stavka.KlientID |
| 64 | JOIN TipDok ON Stavka.TipID = TipDok.TipID |
| 65 | WHERE |
| 66 | Stavka.Datum >= date_trunc('quarter', current_date) - INTERVAL '3 months' |
| 67 | AND Stavka.Datum < date_trunc('quarter', current_date) |
| 68 | GROUP BY Klient.KlientIme |
| 69 | ORDER BY Vkupen_Promet DESC |
| 70 | }}} |
| 71 | |