| 113 | |
| 114 | |
| 115 | W14. |
| 116 | -- sprawdzenie czy są uzupełnione cechy na kliencie, do którego jest kierowana oferta |
| 117 | SELECT x.potrzeba IS NOT NULL |
| 118 | AND x.segment IS NOT NULL |
| 119 | AND x.zrodlo IS NOT NULL |
| 120 | AND x.branza IS NOT NULL |
| 121 | FROM ( |
| 122 | SELECT |
| 123 | (SELECT ftopnm FROM features_opt_view fop WHERE fop.featid = 11 AND fop.tbl_id = fod.contid) AS segment, |
| 124 | (SELECT ftopnm FROM features_opt_view fop WHERE fop.featid = 17 AND fop.tbl_id = fod.contid) AS zrodlo, |
| 125 | (SELECT ftopnm FROM features_opt_view fop WHERE fop.featid = 13 AND fop.tbl_id = fod.contid) AS branza, |
| 126 | (SELECT data__ FROM features_text_view ftv WHERE ftv.featid = 26 AND ftv.tbl_id = fod.contid) AS potrzeba |
| 127 | FROM documents d |
| 128 | INNER JOIN fk_offer_documents fod USING(doc_id) |
| 129 | INNER JOIN contacts c1 ON c1.contid = fod.contid |
| 130 | WHERE d.doc_id = {DOC_ID}) x |
| 131 | |
| 132 | |
| 133 | W15. |
| 134 | -- sprawdzenie czy są uzupełnione cechy na fakturze do którego odbiorcy, lub klienta końcowego oznaczonego na cesze faktury jako klient z bazy - jest kierowana faktura |
| 135 | SELECT x.typ IS NOT NULL |
| 136 | AND x.segment IS NOT NULL |
| 137 | AND x.zrodlo IS NOT NULL |
| 138 | AND x.branza IS NOT NULL |
| 139 | FROM ( |
| 140 | SELECT |
| 141 | (SELECT text_sum(ftopnm) FROM features_opt_view fop WHERE fop.featid = 12 AND fop.ftopid IN (7,9, 28) AND fop.tbl_id = (COALESCE(ftv.data__::int, v.toctid))) AS typ, |
| 142 | (SELECT ftopnm FROM features_opt_view fop WHERE fop.featid = 11 AND fop.tbl_id = (COALESCE(ftv.data__::int, v.toctid))) AS segment, |
| 143 | (SELECT ftopnm FROM features_opt_view fop WHERE fop.featid = 17 AND fop.tbl_id = (COALESCE(ftv.data__::int, v.toctid))) AS zrodlo, |
| 144 | (SELECT ftopnm FROM features_opt_view fop WHERE fop.featid = 13 AND fop.tbl_id = (COALESCE(ftv.data__::int, v.toctid))) AS branza |
| 145 | FROM documents d |
| 146 | INNER JOIN vatnote v USING(doc_id) |
| 147 | INNER JOIN contacts c1 ON c1.contid = v.toctid |
| 148 | LEFT JOIN features_text_view ftv ON ftv.tbl_id = d.doc_id AND ftv.featid = 15 -- klient końcowy |
| 149 | LEFT JOIN contacts c2 ON c2.contid = ftv.data__::int |
| 150 | WHERE d.doc_id = 352273) x |
| 151 | |