1 | | Во изведба |
| 1 | = **Напредни извештаи од базата (SQL и складирани процедури)** |
| 2 | |
| 3 | === ** Преглед и одобрување на набавка ** |
| 4 | |
| 5 | {{{ |
| 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 | ) |
| 22 | |
| 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; |
| 33 | }}} |
| 34 | |
| 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 | === ** Информации за соработка со подизведувачи ** |
| 98 | |
| 99 | {{{ |
| 100 | CREATE PROCEDURE GetPodizveduvacDetails(IN input_Podizveduvac_Ime VARCHAR(50)) |
| 101 | BEGIN |
| 102 | SELECT |
| 103 | p.Podizveduvac_Ime, |
| 104 | p.Struka AS Expertise, |
| 105 | p.Br_vraboteni AS Total_Employees, |
| 106 | p.Saatnica AS Hourly_Rate |
| 107 | FROM Podizveduvac p |
| 108 | WHERE p.Podizveduvac_Ime = input_Podizveduvac_Ime; |
| 109 | |
| 110 | SELECT |
| 111 | r.Maticen_br AS Employee_ID, |
| 112 | r.Ime AS Employee_Name, |
| 113 | r.Seniornost AS Seniority |
| 114 | FROM Raboti_Za rz |
| 115 | JOIN Rabotnik r ON rz.Maticen_br = r.Maticen_br |
| 116 | WHERE rz.Podizveduvac_Ime = input_Podizveduvac_Ime; |
| 117 | |
| 118 | SELECT |
| 119 | o.Objekt_ID, |
| 120 | o.Tip AS Objekt_Type, |
| 121 | o.Adresa AS Objekt_Address, |
| 122 | TIMESTAMPDIFF(HOUR, FROM_UNIXTIME(rn.Od_vreme), FROM_UNIXTIME(rn.Do_vreme)) AS Total_Hours_Worked, |
| 123 | TIMESTAMPDIFF(HOUR, FROM_UNIXTIME(rn.Od_vreme), FROM_UNIXTIME(rn.Do_vreme)) * p.Saatnica AS Total_Payments |
| 124 | FROM Raboti_Na rn |
| 125 | JOIN Objekt o ON rn.Objekt_ID = o.Objekt_ID |
| 126 | JOIN Podizveduvac p ON rn.Podizveduvac_Ime = p.Podizveduvac_Ime |
| 127 | WHERE rn.Podizveduvac_Ime = input_Podizveduvac_Ime; |
| 128 | |
| 129 | SELECT |
| 130 | n.Nabavka_ID, |
| 131 | n.Datum AS Request_Date, |
| 132 | n.Cena AS Cost, |
| 133 | n.Kolicina AS Quantity, |
| 134 | n.Predmet AS Item |
| 135 | FROM Pobaruva pb |
| 136 | JOIN Nabavka n ON pb.Nabavka_ID = n.Nabavka_ID |
| 137 | WHERE pb.Podizveduvac_Ime = input_Podizveduvac_Ime; |
| 138 | END |
| 139 | }}} |
| 140 | |
| 141 | === ** Информации за соработка со добавувачи ** |
| 142 | |
| 143 | {{{ |
| 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; |
| 149 | |
| 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; |
| 155 | |
| 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 |
| 161 | }}} |