| 467 | [[BR]] |
| 468 | |
| 469 | zapytanie dla wszystkich zadań workflow z modułu Dokumenty: |
| 470 | {{{ |
| 471 | SELECT doc.*, reg.regtyp,reg.ndenam, type.dctptp,type.dctpnm,type.dctpic, |
| 472 | (SELECT ARRAY[count(f.fileid),min(f.fileid)] FROM attachments LEFT JOIN files f USING(fileid) WHERE is_del IS NOT TRUE AND doc_id = doc.doc_id) as files, |
| 473 | (EXISTS (SELECT 1 FROM documents_history WHERE doc_id=doc.doc_id AND orunid = 1 AND strpos(dscrpt, 'Otwarcie')=1)) as is_ack |
| 474 | FROM documents doc |
| 475 | INNER JOIN ( |
| 476 | SELECT doc_id, (array_agg(attrib))[1] as attrib |
| 477 | FROM ( |
| 478 | SELECT documents_view.doc_id, (CASE WHEN dlu_doc_id IS NULL THEN NULL ELSE coalesce(dlu.attrib, '') END) as attrib |
| 479 | FROM documents documents_view |
| 480 | LEFT JOIN storage_places stp using(strpid) |
| 481 | LEFT JOIN ( |
| 482 | SELECT dlu.doc_id as dlu_doc_id, dlu.attrib, dlu.usr_id, ul.prior_ |
| 483 | FROM doc_link_users dlu |
| 484 | LEFT JOIN users_link_group ul on(ul.grp_id = dlu.grp_id AND ul.usr_id = 2) |
| 485 | WHERE dlu.usr_id = 2 OR ul.usr_id = 2 |
| 486 | ) dlu ON (dlu_doc_id = documents_view.doc_id) |
| 487 | WHERE is_del IS NOT TRUE AND gostof IS NULL |
| 488 | AND procid IN ( |
| 489 | SELECT p.rootpr |
| 490 | FROM procedures p |
| 491 | LEFT JOIN stages s USING(procid) |
| 492 | WHERE (ARRAY(SELECT orunid FROM orgtree_view LEFT JOIN users_link_org_units ulo USING(orunid) WHERE orunid = 1 OR (ourpid = 1 AND EXISTS(SELECT 1 FROM (SELECT value_ FROM global_sys_conf WHERE ent_id = 2 AND objnam = 'Replacement_'||ulo.usr_id AND varnam = 'from__') as as1 WHERE value_::date <= now()::date) AND EXISTS(SELECT 1 FROM (SELECT value_ FROM global_sys_conf WHERE ent_id = 2 AND objnam = 'Replacement_'||ulo.usr_id AND varnam = 'to____') as sd2 WHERE value_::date >= now()::date))) && s.orgarr) AND s.ptsttp != 'SUBPROCESS' AND sop_id IS NOT NULL AND is_act IS TRUE |
| 493 | ) |
| 494 | AND is_iso IS FALSE AND partof IS NULL ORDER BY dlu_doc_id, dlu.usr_id IS NOT NULL DESC, dlu.prior_ ASC |
| 495 | ) foo2 |
| 496 | GROUP BY doc_id |
| 497 | ) dolu USING (doc_id) |
| 498 | LEFT JOIN types_of_documents type USING(dctpid) |
| 499 | LEFT JOIN registers reg USING(reg_id) |
| 500 | WHERE (substr(dolu.attrib, 1, 1) = 'r') OR (dolu.attrib IS NULL AND (prionl IS NOT TRUE OR doc.adduid = 2)) |
| 501 | ORDER BY timest DESC,doc_id DESC |
| 502 | }}} |