| 23 | | select d.* |
| 24 | | from delivery d join orders o on o.delivery_id=d.delivery_id |
| 25 | | where o.customer_id=curr_usr_id and d.delivery_status_id <>4; |
| | 33 | select del.del_id as id, |
| | 34 | del.del_date_created as dateCreated, |
| | 35 | del.del_date as deliveryDate, |
| | 36 | del.del_start_km as delStartKm, |
| | 37 | del.del_end_km as delEndKm, |
| | 38 | to_char(d.del_start_time, 'HH24:MI:22') as delStartTime, |
| | 39 | to_char(d.del_end_time, 'HH24:MI:SS') as delEndTime, |
| | 40 | del.d_status_id as dStatusId, |
| | 41 | ds.d_status_name as delStatus, |
| | 42 | v.veh_id as vehId, |
| | 43 | dr.user_id as driverId, |
| | 44 | u.user_name as driverName, |
| | 45 | u.user_image as driverImage |
| | 46 | from delivery del |
| | 47 | join orders o on o.del_id=del.del_id |
| | 48 | join delivery d on o.del_id = d.del_id |
| | 49 | join delivery_status ds on d.d_status_id=ds.d_status_id |
| | 50 | join vehicle v on v.veh_id=d.veh_id |
| | 51 | join driver dr on dr.veh_id=v.veh_id |
| | 52 | join users u on u.user_id=dr.user_id |
| | 53 | where o.cust_id=:customer and del.d_status_id <> 4; |
| | 59 | |
| | 60 | Тука во моделот се праќаат листи на категории, артикли, произведувачи и единки од секој артикл во магацинот од регионот на корисникот. |
| | 61 | |
| | 62 | ===== Вчитување на корисник и магацин на моменталниот корисник |
| | 63 | {{{#!sql |
| | 64 | -- Вчитување на корисник: |
| | 65 | select u.user_id as id, |
| | 66 | u.user_name as firstName, |
| | 67 | u.user_surname as lastName, |
| | 68 | u.user_email as email, |
| | 69 | u.user_mobile as phone, |
| | 70 | u.user_image as image, |
| | 71 | u.city_id as cityId, |
| | 72 | c.city_name as cityName, |
| | 73 | r.region_name as regionName, |
| | 74 | u.user_role as role, |
| | 75 | clazz_ as clazz_, |
| | 76 | u.user_active as userActive |
| | 77 | from users u |
| | 78 | join city c on u.city_id = c.city_id |
| | 79 | join region r on c.region_id = r.region_id |
| | 80 | where user_email = ?1; |
| | 81 | |
| | 82 | -- Вчитување на магацин: |
| | 83 | with reg as ( |
| | 84 | select r.* |
| | 85 | from city c1 join region r on c1.region_id = r.region_id |
| | 86 | where c1.city_id = :city |
| | 87 | ) |
| | 88 | select w.wh_id as id, |
| | 89 | w.wh_adr as address, |
| | 90 | c.city_id as cityId, |
| | 91 | c.city_name as cityName, |
| | 92 | r1.region_id as regionId, |
| | 93 | r1.region_name as regionName |
| | 94 | from warehouse w |
| | 95 | join city c on c.city_id = w.city_id |
| | 96 | join reg r1 on r1.region_id = c.region_id |
| | 97 | where c.region_id = r1.region_id |
| | 98 | }}} |
| | 99 | ===== Категории во магацинот |
| | 100 | {{{#!sql |
| | 101 | select ctg_id as id, |
| | 102 | ctg_name as name |
| | 103 | from category |
| | 104 | }}} |
| | 105 | ===== Артикли во магацинот |
| | 106 | {{{#!sql |
| | 107 | with stock as ( |
| | 108 | select a.art_id, |
| | 109 | count(au.unit_id) as quantity |
| | 110 | from article a |
| | 111 | join price p on a.art_id = p.art_id |
| | 112 | join unit_price up on p.price_id = up.price_id |
| | 113 | join article_unit au on up.unit_id = au.unit_id |
| | 114 | group by a.art_id |
| | 115 | ) |
| | 116 | select a.art_id as id, |
| | 117 | a.art_name as name, |
| | 118 | m.man_name as manufacturer, |
| | 119 | st.quantity as quantity, |
| | 120 | m.man_id as manufacturerId, |
| | 121 | p.price as price, |
| | 122 | c.ctg_name as category, |
| | 123 | c.ctg_id as categoryId, |
| | 124 | a.art_weight as weight, |
| | 125 | a.art_image as image |
| | 126 | from article a |
| | 127 | join stock st on st.art_id=a.art_id |
| | 128 | join manufacturer m on a.man_id = m.man_id |
| | 129 | join category c on a.ctg_id = c.ctg_id |
| | 130 | join price p on a.art_id = p.art_id |
| | 131 | join unit_price up on p.price_id = up.price_id |
| | 132 | join article_unit au on up.unit_id = au.unit_id |
| | 133 | join warehouse w on w.wh_id = au.wh_id |
| | 134 | where w.wh_id = ?1 |
| | 135 | }}} |
| | 136 | ===== Произведувачи на артикли во магацинот |
| | 137 | {{{#!sql |
| | 138 | select m.man_id as id, |
| | 139 | m.man_name as name, |
| | 140 | m.man_adr as address, |
| | 141 | m.man_mobile as phone, |
| | 142 | m.man_email as email |
| | 143 | from manufacturer m |
| | 144 | }}} |
| | 145 | ===== Единки од артикли во магацинот |
| | 146 | {{{#!sql |
| | 147 | select au.unit_id as id, |
| | 148 | au.unit_expiration_date as expiryDate, |
| | 149 | au.unit_serial_number as serialNo, |
| | 150 | au.unit_batch_number as batchNo, |
| | 151 | au.unit_manufacture_date as manufactureDate, |
| | 152 | au.unit_cost_price as costPrice, |
| | 153 | a.art_id as artId, |
| | 154 | a.art_name as artName, |
| | 155 | au.wh_id as whId, |
| | 156 | r.region_name as whRegion, |
| | 157 | c.city_name as whCity, |
| | 158 | au.ord_id as ordId, |
| | 159 | u.user_email as customerEmail |
| | 160 | from article_unit au |
| | 161 | join warehouse wh on au.wh_id = wh.wh_id |
| | 162 | join city c on wh.city_id = c.city_id |
| | 163 | join region r on c.region_id = r.region_id |
| | 164 | join unit_price up on au.unit_id = up.unit_id |
| | 165 | join price p on up.price_id = p.price_id |
| | 166 | join article a on p.art_id = a.art_id |
| | 167 | join orders o on au.ord_id = o.ord_id |
| | 168 | join customer cust on o.cust_id = cust.user_id |
| | 169 | join users u on cust.user_id = u.user_id |
| | 170 | }}} |
| 53 | | По одбирање на производот, корисникот одбира посакувана количина и клика на копчето `Креирај ја нарачката`. По ова се креира нарачка во базата. |
| 54 | | ===== Внесување на податоците во табелата за нарачки |
| 55 | | {{{#!sql |
| 56 | | insert into orders (order_date, order_sum, order_status_id, order_fulfillment_date, |
| 57 | | customer_id, delivery_id, pro_forma_id) |
| 58 | | values (curr_date, sum, 1, null, curr_usr_id, null, null) |
| 59 | | }}} |
| 60 | | |
| 61 | | ===== Кога менаџерот ќе ја потврди нарачката и ќе ја креира профактурата |
| 62 | | {{{#!sql |
| 63 | | insert into pro_forma (pro_forma_status_id, pro_forma_deadline, pro_forma_date_created) |
| 64 | | values (1, order_date_created + 1 week, current date) |
| 65 | | }}} |
| 66 | | {{{#!sql |
| 67 | | update orders |
| 68 | | set pro_forma_id=created_pf_id and order_status_id=2 |
| 69 | | where order_id=the_orders_id |
| 70 | | }}} |
| 71 | | |
| 72 | | Во првиот код се креира нова профактура за таа нарачка, а во вториот се поврзува постоечката нарачка со новокреираната профактура и статусот на нарачката се променува во ''Pending''. |
| | 182 | По одбирање на производот, корисникот одбира посакувана количина и одбира дали сака да добие профактура со нарачката, клика на копчето `Креирај ја нарачката`. По ова се креира нарачка во базата. |
| | 183 | |
| | 184 | ===== Креирање на нарачка |
| | 185 | |
| | 186 | {{{#!sql |
| | 187 | insert into orders (ord_date, ord_sum, ord_fulfillment_date, ord_comment, o_status_id, cust_id, del_id, pf_id) |
| | 188 | values (?1,?2,?3,?4,?5,?6,?7,?8) |
| | 189 | }}} |
| | 190 | |
| | 191 | ===== Се добива нарачката од листа на нарачки за корисникот и се додава нејзиниот примарен клуч за секој тип на одбран артикл |
| | 192 | |
| | 193 | {{{#!sql |
| | 194 | -- За секој одбран артикл се добиваат единките артикли во магацинот и на првите |
| | 195 | select au.unit_id as id, |
| | 196 | au.unit_expiration_date as expiryDate, |
| | 197 | au.unit_serial_number as serialNo, |
| | 198 | au.unit_batch_number as batchNo, |
| | 199 | au.unit_manufacture_date as manufactureDate, |
| | 200 | au.unit_cost_price as costPrice, |
| | 201 | a.art_id as artId, |
| | 202 | au.wh_id as whId, |
| | 203 | au.ord_id as ordId |
| | 204 | from article_unit au |
| | 205 | join unit_price up on au.unit_id = up.unit_id |
| | 206 | join price p on up.price_id = p.price_id |
| | 207 | join article a on p.art_id = a.art_id |
| | 208 | where au.wh_id = ?2 and a.art_id = ?1 |
| | 209 | |
| | 210 | -- Според одбраната количина од тој артикл на толку единки ѝм се додава примарниот клуч на новокреираната нарачка |
| | 211 | update article_unit |
| | 212 | set unit_expiration_date = ?2, unit_serial_number = ?3, unit_batch_number = ?4,unit_manufacture_date = ?5,unit_cost_price = ?6,wh_id = ?7,ord_id = ?8 |
| | 213 | where unit_id=?1 |
| | 214 | }}} |
| | 215 | |
| | 216 | |
| | 217 | ===== Доколку корисникот одбрал профактура, се креира профактурата и нејзиниот примарен клуч се додава на нарачката. |
| | 218 | {{{#!sql |
| | 219 | insert into pro_forma(pf_deadline, pf_date_created, pf_status_id) |
| | 220 | values (?1,?2,?3) |
| | 221 | }}} |