428 | | SELECT keyval, |
429 | | dscrpt, |
430 | | clsnam, |
431 | | ptstnm, |
432 | | dctpid, |
433 | | prtpnm, |
434 | | end___, |
435 | | ptstid, |
436 | | aa.prior_ |
437 | | FROM procedures_def |
438 | | RIGHT JOIN ( |
439 | | SELECT (doc_id) AS keyval, |
440 | | p2.prtpid, |
441 | | substr(d.dscrpt, 0, 100) AS dscrpt, |
442 | | 'DOCUMENT' AS clsnam, |
443 | | end___, |
444 | | s.ptstnm, |
445 | | d.dctpid, |
446 | | ptstid, |
447 | | orgarr, |
448 | | s.actdat, |
449 | | d.prior_ |
450 | | FROM procedures pd |
451 | | LEFT JOIN stages s USING (PROCID) |
452 | | LEFT JOIN procedures p2 ON (p2.PROCID = pd.rootpr) |
453 | | LEFT JOIN bpm_loops_def bld USING (ptstid) |
454 | | RIGHT JOIN documents d ON (d.PROCID = p2.PROCID) |
455 | | WHERE ( |
456 | | bld.multii IS NOT TRUE |
457 | | OR s.prn_id IS NOT NULL |
458 | | ) |
459 | | AND ( |
460 | | ((SELECT val FROM all_orunids) && s.orgarr) |
461 | | OR ( |
462 | | s.orgarr IS NULL |
463 | | AND ARRAY[d.target] <@ (SELECT val FROM all_orunids) |
| 428 | SELECT keyval, dscrpt, clsnam, ptstnm, dctpid, prtpnm, end___, ptstid, prior_, prtpid |
| 429 | FROM ( |
| 430 | SELECT keyval, dscrpt, clsnam, ptstnm, dctpid, prtpnm, end___, ptstid, aa.prior_, pd.prtpid, orgarr IS NOT NULL as orgarr, first_value(actdat) OVER (PARTITION BY ptstid ORDER BY actdat ASC) as actdat |
| 431 | FROM procedures_def pd |
| 432 | RIGHT JOIN ( |
| 433 | SELECT (doc_id) AS keyval, |
| 434 | p2.prtpid, |
| 435 | substr(d.dscrpt, 0, 100) AS dscrpt, |
| 436 | 'DOCUMENT' AS clsnam, |
| 437 | end___, |
| 438 | s.ptstnm, |
| 439 | d.dctpid, |
| 440 | ptstid, |
| 441 | orgarr, |
| 442 | s.actdat, |
| 443 | d.prior_ |
| 444 | FROM procedures pd |
| 445 | LEFT JOIN stages s USING (PROCID) |
| 446 | LEFT JOIN procedures p2 ON (p2.PROCID = pd.rootpr) |
| 447 | LEFT JOIN bpm_loops_def bld USING (ptstid) |
| 448 | RIGHT JOIN documents d ON (d.PROCID = p2.PROCID) |
| 449 | WHERE ( |
| 450 | bld.multii IS NOT TRUE |
| 451 | OR s.prn_id IS NOT NULL |
465 | | ) |
466 | | AND NOT d.is_del |
467 | | AND gostof IS NULL |
468 | | AND sop_id IS NOT NULL |
469 | | AND s.is_act |
470 | | AND NOT p2.comple |
471 | | AND ptsttp NOT IN ('SUBPROCESS', 'START', 'END') |
472 | | |
473 | | UNION |
474 | | |
475 | | SELECT (prc_id) AS keyval, |
476 | | p2.prtpid, |
477 | | substr(p.dscrpt, 0, 100) AS dscrpt, |
478 | | 'PROCESS' AS clsnam, |
479 | | end___, |
480 | | s.ptstnm, |
481 | | 0 AS dctpid, |
482 | | ptstid, |
483 | | orgarr, |
484 | | s.actdat, |
485 | | NULL AS prior_ |
486 | | FROM procedures pd |
487 | | LEFT JOIN stages s USING (PROCID) |
488 | | LEFT JOIN procedures p2 ON (p2.PROCID = pd.rootpr) |
489 | | LEFT JOIN bpm_loops_def bld USING (ptstid) |
490 | | RIGHT JOIN processes p ON (p.PROCID = p2.PROCID) |
491 | | WHERE ( |
492 | | bld.multii IS NOT TRUE |
493 | | OR s.prn_id IS NOT NULL |
494 | | ) |
495 | | AND p.is_fix IS FALSE |
496 | | AND p.is_del IS FALSE |
497 | | AND ((SELECT val FROM all_orunids) && s.orgarr) |
498 | | AND sop_id IS NOT NULL |
499 | | AND s.is_act IS TRUE |
500 | | AND p2.comple IS NOT TRUE |
501 | | AND ptsttp NOT IN ('SUBPROCESS', 'START', 'END') |
502 | | |
503 | | UNION |
504 | | |
505 | | SELECT (rcp_id) AS keyval, |
506 | | p2.prtpid, |
507 | | substr(p.dscrpt, 0, 100) AS dscrpt, |
508 | | 'RCP' AS clsnam, |
509 | | end___, |
510 | | s.ptstnm, |
511 | | 0 AS dctpid, |
512 | | ptstid, |
513 | | orgarr, |
514 | | s.actdat, |
515 | | NULL AS prior_ |
516 | | FROM procedures pd |
517 | | LEFT JOIN stages s USING (PROCID) |
518 | | LEFT JOIN procedures p2 ON (p2.PROCID = pd.rootpr) |
519 | | LEFT JOIN bpm_loops_def bld USING (ptstid) |
520 | | RIGHT JOIN rcp_cards p ON (p.PROCID = p2.PROCID) |
521 | | WHERE ( |
522 | | bld.multii IS NOT TRUE |
523 | | OR s.prn_id IS NOT NULL |
524 | | ) |
525 | | AND p.is_fix IS FALSE |
526 | | AND p.is_del IS FALSE |
527 | | AND ( |
528 | | ((SELECT val FROM all_orunids) && s.orgarr) |
529 | | OR ( |
530 | | s.orgarr IS NULL |
531 | | AND p.emp_id = {USR_ID} |
| 453 | AND ( |
| 454 | ((SELECT val FROM all_orunids) && s.orgarr) |
| 455 | OR ( |
| 456 | s.orgarr IS NULL |
| 457 | AND ARRAY[d.target] <@ (SELECT val FROM all_orunids) |
| 458 | ) |
533 | | ) |
534 | | AND sop_id IS NOT NULL |
535 | | AND s.is_act IS TRUE |
536 | | AND p2.comple IS NOT TRUE |
537 | | AND ptsttp NOT IN ('SUBPROCESS', 'START', 'END') |
| 460 | AND NOT d.is_del |
| 461 | AND gostof IS NULL |
| 462 | AND sop_id IS NOT NULL |
| 463 | AND s.is_act |
| 464 | AND NOT (p2.comple OR p2.cancel) |
| 465 | AND ptsttp NOT IN ('SUBPROCESS', 'START', 'END') |
| 466 | |
| 467 | UNION |
| 468 | |
| 469 | SELECT (prc_id) AS keyval, |
| 470 | p2.prtpid, |
| 471 | substr(p.dscrpt, 0, 100) AS dscrpt, |
| 472 | 'PROCESS' AS clsnam, |
| 473 | end___, |
| 474 | s.ptstnm, |
| 475 | 0 AS dctpid, |
| 476 | ptstid, |
| 477 | orgarr, |
| 478 | s.actdat, |
| 479 | NULL AS prior_ |
| 480 | FROM procedures pd |
| 481 | LEFT JOIN stages s USING (PROCID) |
| 482 | LEFT JOIN procedures p2 ON (p2.PROCID = pd.rootpr) |
| 483 | LEFT JOIN bpm_loops_def bld USING (ptstid) |
| 484 | RIGHT JOIN processes p ON (p.PROCID = p2.PROCID) |
| 485 | WHERE ( |
| 486 | bld.multii IS NOT TRUE |
| 487 | OR s.prn_id IS NOT NULL |
| 488 | ) |
| 489 | AND p.is_fix IS FALSE |
| 490 | AND p.is_del IS FALSE |
| 491 | AND ((SELECT val FROM all_orunids) && s.orgarr) |
| 492 | AND sop_id IS NOT NULL |
| 493 | AND s.is_act IS TRUE |
| 494 | AND NOT (p2.comple OR p2.cancel) |
| 495 | AND ptsttp NOT IN ('SUBPROCESS', 'START', 'END') |
| 496 | |
| 497 | UNION |
| 498 | |
| 499 | SELECT (rcp_id) AS keyval, |
| 500 | p2.prtpid, |
| 501 | substr(p.dscrpt, 0, 100) AS dscrpt, |
| 502 | 'RCP' AS clsnam, |
| 503 | end___, |
| 504 | s.ptstnm, |
| 505 | 0 AS dctpid, |
| 506 | ptstid, |
| 507 | orgarr, |
| 508 | s.actdat, |
| 509 | NULL AS prior_ |
| 510 | FROM procedures pd |
| 511 | LEFT JOIN stages s USING (PROCID) |
| 512 | LEFT JOIN procedures p2 ON (p2.PROCID = pd.rootpr) |
| 513 | LEFT JOIN bpm_loops_def bld USING (ptstid) |
| 514 | RIGHT JOIN rcp_cards p ON (p.PROCID = p2.PROCID) |
| 515 | WHERE ( |
| 516 | bld.multii IS NOT TRUE |
| 517 | OR s.prn_id IS NOT NULL |
| 518 | ) |
| 519 | AND p.is_fix IS FALSE |
| 520 | AND p.is_del IS FALSE |
| 521 | AND ( |
| 522 | ((SELECT val FROM all_orunids) && s.orgarr) |
| 523 | OR ( |
| 524 | s.orgarr IS NULL |
| 525 | AND p.emp_id = {USR_ID} |
| 526 | ) |
| 527 | ) |
| 528 | AND sop_id IS NOT NULL |
| 529 | AND s.is_act IS TRUE |
| 530 | AND NOT (p2.comple OR p2.cancel) |
| 531 | AND ptsttp NOT IN ('SUBPROCESS', 'START', 'END') |
539 | | ORDER BY prtpid, |
540 | | ptstid, |
541 | | ( |
542 | | end___ IS NOT NULL |
543 | | AND orgarr IS NOT NULL |
544 | | ) DESC, |
545 | | end___ IS NOT NULL DESC, |
546 | | end___ ASC, |
547 | | actdat ASC, |
548 | | orgarr IS NOT NULL DESC, |
549 | | dscrpt ASC |
| 533 | ) res |
| 534 | GROUP BY prtpid, keyval, dscrpt, clsnam, ptstnm, dctpid, prtpnm, end___, ptstid, prior_, orgarr, actdat |
| 535 | ORDER BY prtpid, ptstid, (end___ IS NOT NULL AND orgarr) DESC, end___ IS NOT NULL DESC, end___ ASC, actdat ASC, orgarr DESC, dscrpt ASC |