6 | | CREATE PROCEDURE GetDobavuvacDetails(IN input_Dobavuvac_Ime VARCHAR(50)) |
7 | | BEGIN |
8 | | SELECT d.Dobavuvac_Ime, d.Klasa AS Class, d.Tip AS Type, d.Poteklo AS Origin |
9 | | FROM Dobavuvac d |
10 | | WHERE d.Dobavuvac_Ime = input_Dobavuvac_Ime; |
| 6 | CREATE PROCEDURE `Display_Nabavki_For_Nadzor` (IN N_Ime VARCHAR(50)) |
| 7 | BEGIN |
| 8 | WITH select_objekt_nabavki AS ( |
| 9 | SELECT |
| 10 | o.Objekt_ID AS son_OID, |
| 11 | nb.Nabavka_ID AS son_NID, |
| 12 | nb.Datum AS son_D, |
| 13 | nb.Predmet AS son_P, |
| 14 | nb.Kolicina AS son_K, |
| 15 | nb.Cena AS son_C |
| 16 | FROM Objekt o |
| 17 | JOIN Nadgleduva n ON o.Objekt_ID = n.Objekt_ID |
| 18 | JOIN Nameneta_Za nz ON nz.Objekt_ID = o.Objekt_ID |
| 19 | JOIN Nabavka nb ON nb.Nabavka_ID = nz.Nabavka_ID |
| 20 | WHERE n.Nadzor_Ime = N_Ime |
| 21 | ) |
12 | | SELECT o.Objekt_ID, o.Tip AS Objekt_Type, o.Adresa AS Objekt_Address, n.Predmet AS Item_Supplied, n.Cena AS Item_Cost, n.Kolicina AS Quantity_Supplied |
13 | | FROM Ispolnuva i |
14 | | JOIN Nabavka n ON i.Nabavka_ID = n.Nabavka_ID |
15 | | JOIN Objekt o ON n.Objekt_ID = o.Objekt_ID |
16 | | WHERE i.Dobavuvac_Ime = input_Dobavuvac_Ime; |
17 | | |
18 | | SELECT SUM(n.Cena * n.Kolicina) AS Total_Spent |
19 | | FROM Ispolnuva i |
20 | | JOIN Nabavka n ON i.Nabavka_ID = n.Nabavka_ID |
21 | | WHERE i.Dobavuvac_Ime = input_Dobavuvac_Ime; |
22 | | END |
| 23 | SELECT son_OID, son_NID, son_D, son_P, son_K, son_C |
| 24 | FROM select_objekt_nabavki son |
| 25 | LEFT JOIN Odobruva o ON son.son_NID = o.Nabavka_ID |
| 26 | WHERE o.Nabavka_ID IS NULL; |
| 27 | |
| 28 | SELECT son_OID, son_NID, son_D, son_P, son_K, son_C |
| 29 | FROM select_objekt_nabavki son |
| 30 | LEFT JOIN Odobruva o ON son.son_NID = o.Nabavka_ID |
| 31 | WHERE o.Nabavka_ID IS NOT NULL; |
| 32 | END; |
25 | | === ** Информации за соработка со подизведувачи ** |
| 35 | === ** Интерфејс за создавање на едноставно квери ** |
| 36 | |
| 37 | {{{ |
| 38 | CREATE PROCEDURE `simple_select_with_filter` ( |
| 39 | IN od VARCHAR(50), |
| 40 | IN shto VARCHAR(50), |
| 41 | IN filter_uslov TEXT |
| 42 | ) |
| 43 | BEGIN |
| 44 | SET @query = CONCAT('SELECT ', shto, ' FROM ', od); |
| 45 | |
| 46 | IF filter_uslov IS NOT NULL AND filter_uslov != '' THEN |
| 47 | SET @query = CONCAT(@query, ' WHERE ', filter_uslov); |
| 48 | END IF; |
| 49 | |
| 50 | PREPARE stmt FROM @query; |
| 51 | EXECUTE stmt; |
| 52 | DEALLOCATE PREPARE stmt; |
| 53 | END; |
| 54 | }}} |
| 55 | |
| 56 | === ** Генерална состојба на објект ** |
| 57 | |
| 58 | {{{ |
| 59 | CREATE PROCEDURE GetObjektDetails(IN input_Objekt_ID INT) |
| 60 | BEGIN |
| 61 | -- Opsti informacii za objektot |
| 62 | SELECT |
| 63 | o.Objekt_ID, |
| 64 | o.Tip AS Objekt_Type, |
| 65 | o.Adresa AS Objekt_Address, |
| 66 | vi.Budzet AS Objekt_Budget, |
| 67 | n.Nadzor_Ime |
| 68 | FROM Objekt o |
| 69 | LEFT JOIN Vo_Izgradba vi ON o.Objekt_ID = vi.Objekt_ID |
| 70 | LEFT JOIN Nadgleduva nd ON o.Objekt_ID = nd.Objekt_ID |
| 71 | LEFT JOIN Nadzor n ON nd.Nadzor_Ime = n.Nadzor_Ime |
| 72 | WHERE o.Objekt_ID = input_Objekt_ID |
| 73 | GROUP BY o.Objekt_ID; |
| 74 | |
| 75 | -- Info za podizveduvacite koi rabotele na objektot |
| 76 | SELECT |
| 77 | pn.Podizveduvac_Ime, |
| 78 | TIMESTAMPDIFF(HOUR, FROM_UNIXTIME(rn.Od_vreme), FROM_UNIXTIME(rn.Do_vreme)) AS Total_Hours_Worked, |
| 79 | TIMESTAMPDIFF(HOUR, FROM_UNIXTIME(rn.Od_vreme), FROM_UNIXTIME(rn.Do_vreme)) * pn.Saatnica AS Total_Cost |
| 80 | FROM Raboti_Na rn |
| 81 | JOIN Podizveduvac pn ON rn.Podizveduvac_Ime = pn.Podizveduvac_Ime |
| 82 | WHERE rn.Objekt_ID = input_Objekt_ID; |
| 83 | |
| 84 | -- Info za dobavuvachi |
| 85 | SELECT |
| 86 | d.Dobavuvac_Ime, |
| 87 | SUM(n.Cena * n.Kolicina) AS Total_Spent |
| 88 | FROM Nabavka n |
| 89 | JOIN Nameneta_Za nz ON n.Nabavka_ID = nz.Nabavka_ID |
| 90 | JOIN Ispolnuva i ON n.Nabavka_ID = i.Nabavka_ID |
| 91 | JOIN Dobavuvac d ON i.Dobavuvac_Ime = d.Dobavuvac_Ime |
| 92 | WHERE nz.Objekt_ID = input_Objekt_ID |
| 93 | GROUP BY d.Dobavuvac_Ime; |
| 94 | END |
| 95 | }}} |
| 96 | |
| 97 | === ** Информации за соработка со подизведувачи ** |
72 | | CREATE PROCEDURE GetObjektDetails(IN input_Objekt_ID INT) |
73 | | BEGIN |
74 | | -- Opsti informacii za objektot |
75 | | SELECT |
76 | | o.Objekt_ID, |
77 | | o.Tip AS Objekt_Type, |
78 | | o.Adresa AS Objekt_Address, |
79 | | vi.Budzet AS Objekt_Budget, |
80 | | n.Nadzor_Ime |
81 | | FROM Objekt o |
82 | | LEFT JOIN Vo_Izgradba vi ON o.Objekt_ID = vi.Objekt_ID |
83 | | LEFT JOIN Nadgleduva nd ON o.Objekt_ID = nd.Objekt_ID |
84 | | LEFT JOIN Nadzor n ON nd.Nadzor_Ime = n.Nadzor_Ime |
85 | | WHERE o.Objekt_ID = input_Objekt_ID |
86 | | GROUP BY o.Objekt_ID; |
| 144 | CREATE PROCEDURE GetDobavuvacDetails(IN input_Dobavuvac_Ime VARCHAR(50)) |
| 145 | BEGIN |
| 146 | SELECT d.Dobavuvac_Ime, d.Klasa AS Class, d.Tip AS Type, d.Poteklo AS Origin |
| 147 | FROM Dobavuvac d |
| 148 | WHERE d.Dobavuvac_Ime = input_Dobavuvac_Ime; |
88 | | -- Info za podizveduvacite koi rabotele na objektot |
89 | | SELECT |
90 | | pn.Podizveduvac_Ime, |
91 | | TIMESTAMPDIFF(HOUR, FROM_UNIXTIME(rn.Od_vreme), FROM_UNIXTIME(rn.Do_vreme)) AS Total_Hours_Worked, |
92 | | TIMESTAMPDIFF(HOUR, FROM_UNIXTIME(rn.Od_vreme), FROM_UNIXTIME(rn.Do_vreme)) * pn.Saatnica AS Total_Cost |
93 | | FROM Raboti_Na rn |
94 | | JOIN Podizveduvac pn ON rn.Podizveduvac_Ime = pn.Podizveduvac_Ime |
95 | | WHERE rn.Objekt_ID = input_Objekt_ID; |
| 150 | SELECT o.Objekt_ID, o.Tip AS Objekt_Type, o.Adresa AS Objekt_Address, n.Predmet AS Item_Supplied, n.Cena AS Item_Cost, n.Kolicina AS Quantity_Supplied |
| 151 | FROM Ispolnuva i |
| 152 | JOIN Nabavka n ON i.Nabavka_ID = n.Nabavka_ID |
| 153 | JOIN Objekt o ON n.Objekt_ID = o.Objekt_ID |
| 154 | WHERE i.Dobavuvac_Ime = input_Dobavuvac_Ime; |
97 | | -- Info za dobavuvachi |
98 | | SELECT |
99 | | d.Dobavuvac_Ime, |
100 | | SUM(n.Cena * n.Kolicina) AS Total_Spent |
101 | | FROM Nabavka n |
102 | | JOIN Nameneta_Za nz ON n.Nabavka_ID = nz.Nabavka_ID |
103 | | JOIN Ispolnuva i ON n.Nabavka_ID = i.Nabavka_ID |
104 | | JOIN Dobavuvac d ON i.Dobavuvac_Ime = d.Dobavuvac_Ime |
105 | | WHERE nz.Objekt_ID = input_Objekt_ID |
106 | | GROUP BY d.Dobavuvac_Ime; |
107 | | END |
| 156 | SELECT SUM(n.Cena * n.Kolicina) AS Total_Spent |
| 157 | FROM Ispolnuva i |
| 158 | JOIN Nabavka n ON i.Nabavka_ID = n.Nabavka_ID |
| 159 | WHERE i.Dobavuvac_Ime = input_Dobavuvac_Ime; |
| 160 | END |
109 | | |
110 | | === ** Преглед и одобрување на набавка ** |
111 | | |
112 | | {{{ |
113 | | CREATE PROCEDURE `Display_Nabavki_For_Nadzor` (IN N_Ime VARCHAR(50)) |
114 | | BEGIN |
115 | | WITH select_objekt_nabavki AS ( |
116 | | SELECT |
117 | | o.Objekt_ID AS son_OID, |
118 | | nb.Nabavka_ID AS son_NID, |
119 | | nb.Datum AS son_D, |
120 | | nb.Predmet AS son_P, |
121 | | nb.Kolicina AS son_K, |
122 | | nb.Cena AS son_C |
123 | | FROM Objekt o |
124 | | JOIN Nadgleduva n ON o.Objekt_ID = n.Objekt_ID |
125 | | JOIN Nameneta_Za nz ON nz.Objekt_ID = o.Objekt_ID |
126 | | JOIN Nabavka nb ON nb.Nabavka_ID = nz.Nabavka_ID |
127 | | WHERE n.Nadzor_Ime = N_Ime |
128 | | ) |
129 | | |
130 | | SELECT son_OID, son_NID, son_D, son_P, son_K, son_C |
131 | | FROM select_objekt_nabavki son |
132 | | LEFT JOIN Odobruva o ON son.son_NID = o.Nabavka_ID |
133 | | WHERE o.Nabavka_ID IS NULL; |
134 | | |
135 | | SELECT son_OID, son_NID, son_D, son_P, son_K, son_C |
136 | | FROM select_objekt_nabavki son |
137 | | LEFT JOIN Odobruva o ON son.son_NID = o.Nabavka_ID |
138 | | WHERE o.Nabavka_ID IS NOT NULL; |
139 | | END; |
140 | | }}} |