| 177 | |
| 178 | -- Formatuje status z obrazkiem czy zakończony |
| 179 | -- Pokazuje wiele osób na równoegłych etapach w obiegu faktury |
| 180 | SELECT 'DOCUMENT'::text AS clsnam, d.doc_id AS keyval, d.doc_id, v.amount, v.vat___, v.number, reg.evdnum, |
| 181 | regexp_replace(d.dscrpt, 'Od:[ 0-9a-zA-ZąęłóśćńźżĄĘŚÓĆŃŁŹŻ\";\./.)(,-]*$', '') AS dscrpt, d.trgtxt, v.payed_, v.seldat::date, d.adddat::date AS dwplywu, |
| 182 | CASE WHEN tps.status IN ('FINAL', 'CANCEL') THEN '<img src=../../framework/img/MessageBox/checked.png width=18 title=Status>' ELSE '' END AS icon, |
| 183 | v.paytrm::date AS paytrm, |
| 184 | COALESCE(name_1, name_2) AS contrah, |
| 185 | ftv.ftopnm AS rodzaj, |
| 186 | tps.dscrpt AS status, |
| 187 | tps.tpstid, |
| 188 | toa.code__, |
| 189 | (SELECT text_sum(osoby) FROM ( |
| 190 | SELECT DISTINCT (firnam||' '||lasnam) AS osoby |
| 191 | FROM stages s |
| 192 | INNER JOIN procedures pr2 USING(procid) |
| 193 | LEFT JOIN orgtree_view o3 ON o3.orunid = any(s.orgarr) |
| 194 | WHERE |
| 195 | ((s.is_act IS TRUE AND s.is_fix IS FALSE) |
| 196 | OR (s.ptsttp = 'END' AND s.is_fix IS TRUE)) |
| 197 | AND (s.ptsttp != 'SUBPROCESS') AND (pr2.rootpr = d.procid) |
| 198 | ) x) AS osoby, |
| 199 | d.procid, |
| 200 | pr.prtpnm |
| 201 | FROM documents d |
| 202 | INNER JOIN vatnote v USING(doc_id) |
| 203 | INNER JOIN contacts c ON (c.contid = v.frctid) |
| 204 | LEFT JOIN regofvatnotes reg USING (doc_id) |
| 205 | LEFT JOIN features_opt_view ftv ON d.doc_id = ftv.tbl_id AND ftv.featid = 2 |
| 206 | LEFT JOIN types_of_accountants_doc toa USING(accdid) |
| 207 | LEFT JOIN types_of_processes_states AS tps ON d.tpstid = tps.tpstid |
| 208 | LEFT JOIN procedures pr USING(procid) |
| 209 | |
| 210 | WHERE d.gostof IS NULL AND d.copyof IS NULL AND d.state_ = 2 AND d.is_del IS FALSE |
| 211 | AND d.adddat BETWEEN '{DATE_FROM}'::date AND '{DATE_TO}'::date |
| 212 | AND {FILTER_STRING} |
| 213 | ORDER BY d.doc_id |
| 214 | |
| 215 | |