tko_pb

rz_print_all_po_v2.sql

Jun 3rd, 2020
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- adempiere.rz_print_all_po_v2 source
  2.  
  3. CREATE OR REPLACE VIEW adempiere.rz_print_all_po_v2
  4. AS SELECT ord.c_order_id,
  5.         CASE
  6.             WHEN p.m_product_category_id = ANY (ARRAY[1000050::numeric, 1000049::numeric, 1000012::numeric]) THEN
  7.             CASE
  8.                 WHEN p.kst_width_id <> 1000000::numeric THEN COALESCE(p.value::text || ' CM '::text, 'charge'::text)::character varying
  9.                 ELSE COALESCE(p.value, 'charge'::character varying)
  10.             END
  11.             ELSE COALESCE(p.value, 'charge'::character varying)
  12.         END AS itemcode,
  13.     COALESCE(p.name, c.name) AS name,
  14.     p.description AS productdescription,
  15.     u.name AS uom,
  16.     ol.datepromised AS datepromised_l,
  17.     ol.qtyentered,
  18.     ol.qtyordered,
  19.     ol.priceentered AS hargasatuan,
  20.     ol.linenetamt AS total,
  21.     ol.qtyentered * ol.priceentered AS su,
  22.     otx.taxamt AS sumppn,
  23.     tx.rate AS rateppn,
  24.     cur.iso_code,
  25.     ol.description,
  26.     cur.c_currency_id,
  27.     (( SELECT sum(pol2.qtyentered) AS sum
  28.            FROM c_orderline pol2
  29.           WHERE pol2.c_order_id = ol.c_order_id AND pol2.m_product_id = ol.m_product_id AND pol2.isfockst = 'N'::bpchar)) * ol.priceentered AS sump,
  30.     ol.isfockst,
  31.     ol.poreference,
  32.     part.name AS customername,
  33.     ord.kst_season,
  34.     concat(loc.address1, loc.city) AS alamat,
  35.     bloc.phone AS telp,
  36.     bloc.fax,
  37.     bloc.name AS cp,
  38.     ord.documentno AS docno,
  39.     ord.dateordered AS tanggal,
  40.     ord.datepromised AS datepromised_h,
  41.     concat(locc.address1, locc.city) AS alamatkirim,
  42.     payterm.name AS paymentterm,
  43.     reflst.name AS refname,
  44.     ord.kst_sltnote AS note,
  45.     ord.note AS onote,
  46.     ord.docstatus,
  47.     ord.kst_etddate AS dd,
  48.     whs.value AS wh,
  49.     ord.c_doctypetarget_id,
  50.     string_agg(DISTINCT pso.upc::text, ';'::text ORDER BY (pso.upc::text)) AS so,
  51.     COALESCE(( SELECT cr.dividerate
  52.            FROM c_conversion_rate cr
  53.           WHERE cr.c_conversiontype_id = ord.c_conversiontype_id AND cr.c_currency_id = ord.c_currency_id AND cr.c_currency_id_to = 100::numeric AND ord.dateordered <= cr.validto AND ord.dateordered >= cr.validfrom
  54.           ORDER BY cr.validfrom DESC
  55.          LIMIT 1), 0::numeric) AS rate,
  56.     ord.dyed,
  57.         CASE
  58.             WHEN whs.value::text ~~ '%AOI 2%'::text THEN 'Jl. TUGU WIJAYA IV, KAW. INDUSTRI WIJAYAKUSUMA, TUGU, SEMARANG 50153 INDONESIA, PHONE +62-248666-4482, FAX. +62-248666-4483'::text
  59.             WHEN whs.value::text ~~ '%AOI 1%'::text THEN 'KAWASAN BERIKAT RUKTI MUKTI BAWANA B-05, Jl. SEMARANG KENDAL KM.12, RANDU GARUT, TUGU, KOTA SEMARANG, JAWA TENGAH 50181, INDONESIA, PHONE +62 24 8664482'::text
  60.             ELSE NULL::text
  61.         END AS alamataoi,
  62.     ord.c_bpartner_id,
  63.     x.status,
  64.     x.created_time,
  65.     ol.c_orderline_id,
  66.     xx.date_promised,
  67.     xx.lock
  68.    FROM c_orderline ol
  69.      LEFT JOIN m_product p ON p.m_product_id = ol.m_product_id
  70.      LEFT JOIN c_charge c ON c.c_charge_id = ol.c_charge_id
  71.      LEFT JOIN c_order ord ON ord.c_order_id = ol.c_order_id
  72.      LEFT JOIN c_currency cur ON ord.c_currency_id = cur.c_currency_id
  73.      LEFT JOIN c_uom u ON u.c_uom_id = ol.c_uom_id
  74.      LEFT JOIN c_ordertax otx ON otx.c_order_id = ord.c_order_id
  75.      LEFT JOIN c_tax tx ON tx.c_tax_id = otx.c_tax_id
  76.      LEFT JOIN kst_width width ON p.kst_width_id = width.kst_width_id
  77.      LEFT JOIN kst_colordetails clr ON p.kst_colordetails_id = clr.kst_colordetails_id
  78.      JOIN m_warehouse whs ON ord.m_warehouse_id = whs.m_warehouse_id
  79.      JOIN c_bpartner part ON part.c_bpartner_id = ord.c_bpartner_id
  80.      JOIN c_bpartner_location bloc ON bloc.c_bpartner_id = ord.c_bpartner_id
  81.      JOIN c_location loc ON loc.c_location_id = bloc.c_location_id
  82.      JOIN c_location locc ON locc.c_location_id = whs.c_location_id
  83.      JOIN c_paymentterm payterm ON payterm.c_paymentterm_id = ord.c_paymentterm_id
  84.      JOIN ad_ref_list reflst ON reflst.value::bpchar = ord.paymentrule
  85.      JOIN ad_reference ref ON ref.ad_reference_id = reflst.ad_reference_id
  86.      LEFT JOIN c_order so ON so.poreference::text = ol.poreference::text
  87.      LEFT JOIN c_orderline sol ON sol.c_order_id = so.c_order_id
  88.      LEFT JOIN m_product pso ON pso.m_product_id = sol.m_product_id
  89.      LEFT JOIN dblink('dbname=import port=5432 host=192.168.51.52 user=postgres password=Becarefulwithme'::text, '
  90.     select
  91.     c_order_id,
  92.     status,
  93.     created_time
  94.     from show_po_status
  95.     where status is true'::text) x(c_order_id numeric, status text, created_time date) ON x.c_order_id = ord.c_order_id
  96.      LEFT JOIN dblink('dbname=import port=5432 host=192.168.51.52 user=postgres password=Becarefulwithme'::text, '
  97.     select
  98.     a.c_orderline_id,
  99.     b.date_promised,
  100.     a.lock
  101.     from m_date_promised a
  102.     left join adt_max_date_promised b on b.c_orderline_id = a.c_orderline_id
  103.     where a.lock != true
  104. '::text) xx(c_orderline_id numeric, date_promised date, lock text) ON xx.c_orderline_id = ol.c_orderline_id
  105.   WHERE ref.ad_reference_id = 195::numeric AND ol.qtydelivered < ol.qtyordered AND (ord.docstatus = ANY (ARRAY['CO'::bpchar, 'DR'::bpchar])) AND ord.issotrx = 'N'::bpchar AND x.status = 't'::text AND (ord.c_doctypetarget_id <> ALL (ARRAY[1000016::numeric, 1000065::numeric, 1000114::numeric, 1000047::numeric, 1000127::numeric, 1000131::numeric, 1000050::numeric, 1000113::numeric, 1000122::numeric, 1000103::numeric, 1000076::numeric, 1000146::numeric, 1000126::numeric])) AND ol.isclosed = 'N'::bpchar AND (ord.c_doctype_id <> ALL (ARRAY[1000016::numeric, 1000065::numeric, 1000114::numeric, 1000047::numeric, 1000127::numeric, 1000131::numeric, 1000050::numeric, 1000113::numeric, 1000122::numeric, 1000103::numeric, 1000076::numeric, 1000146::numeric, 1000126::numeric])) AND ol.isactive = 'Y'::bpchar
  106.   GROUP BY ord.c_order_id, p.m_product_category_id, p.description, u.name, ol.datepromised, ol.qtyentered, ol.qtyordered, ol.priceentered, ol.linenetamt, otx.taxamt, tx.rate, cur.iso_code, ol.description, cur.c_currency_id, ol.isfockst, ol.poreference, p.kst_width_id, p.value, p.name, c.name, ol.c_order_id, ol.m_product_id, part.name, ord.kst_season, bloc.phone, bloc.fax, bloc.name, ord.documentno, ord.dateordered, ord.datepromised, payterm.name, reflst.name, ord.kst_sltnote, ord.note, ord.docstatus, loc.address1, locc.city, loc.city, locc.address1, whs.value, ord.c_doctypetarget_id, ord.c_bpartner_id, x.status, x.created_time, ol.c_orderline_id, xx.date_promised, xx.lock;
Add Comment
Please, Sign In to add comment