Advertisement
tiko_pb

rma_reportt1t2v10fabric

Jan 29th, 2020
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  SELECT po.created AS issue_date,
  2.     ''::text AS order_number,
  3.     to_char((po.updated - '07:00:00'::interval), 'yyyy-MM-dd HH24:mi'::text) AS latest_update,
  4.     'Apparel One Indonesia'::text AS buyer,
  5.         CASE
  6.             WHEN ((wh.name)::text ~~ '%AOI 1%'::text) THEN 'Jl. Raya Semarang-Kendal Km 12 Kawasan Rukti Mukti Bawana Blok B5'::text
  7.             WHEN ((wh.name)::text ~~ '%AOI 2%'::text) THEN 'Tugu Wijaya IV Kawasan Industri Wijaya Kusuma Randu Garut'::text
  8.             ELSE ''::text
  9.         END AS t1_address1buy,
  10.     'Kel. Randu Garut'::text AS t1_address2buy,
  11.     'Kec. Tugu'::text AS t1_address3buy,
  12.     loc.address4 AS t1_address4buy,
  13.     'Semarang'::text AS t1_addresscitybuy,
  14.     'Jawa Tengah'::text AS t1_addressstatebuy,
  15.         CASE
  16.             WHEN ((wh.name)::text ~~ '%AOI 1%'::text) THEN '50156'::text
  17.             WHEN ((wh.name)::text ~~ '%AOI 2%'::text) THEN '50153'::text
  18.             ELSE ''::text
  19.         END AS t1_addresspostalcodebuy,
  20.     'Indonesia'::text AS t1_addresscountrybuy,
  21.     po.ad_client_id,
  22.     ad.description AS contact_personbuyer,
  23.     '+62-24843-10051'::text AS contact_nobuyer,
  24.     ad.email AS emailbuyer,
  25.         CASE
  26.             WHEN ((wh.name)::text ~~ '%AOI 1%'::text) THEN 'PT. APPAREL ONE INDONESIA 1'::text
  27.             WHEN ((wh.name)::text ~~ '%AOI 2%'::text) THEN 'PT. APPAREL ONE INDONESIA 2'::text
  28.             ELSE ''::text
  29.         END AS ship_to,
  30.         CASE
  31.             WHEN ((wh.name)::text ~~ '%AOI 1%'::text) THEN 'Jl. Raya Semarang-Kendal Km 12 Kawasan Rukti Mukti Bawana Blok B5 Kel. Randu Garut, Tugu'::text
  32.             WHEN ((wh.name)::text ~~ '%AOI 2%'::text) THEN 'Tugu Wijaya IV Kawasan Industri Wijaya Kusuma Randu Garut, Tugu'::text
  33.             ELSE ''::text
  34.         END AS t1_address1,
  35.         CASE
  36.             WHEN ((wh.name)::text ~~ '%AOI 1%'::text) THEN 'SEMARANG'::text
  37.             WHEN ((wh.name)::text ~~ '%AOI 2%'::text) THEN 'SEMARANG'::text
  38.             ELSE ''::text
  39.         END AS t1_addresscity,
  40.         CASE
  41.             WHEN ((wh.name)::text ~~ '%AOI 1%'::text) THEN 'JAWA TENGAH'::text
  42.             WHEN ((wh.name)::text ~~ '%AOI 2%'::text) THEN 'JAWA TENGAH'::text
  43.             ELSE ''::text
  44.         END AS t1_addressprovince,
  45.         CASE
  46.             WHEN ((wh.name)::text ~~ '%AOI 1%'::text) THEN '50156'::text
  47.             WHEN ((wh.name)::text ~~ '%AOI 2%'::text) THEN '50153'::text
  48.             ELSE ''::text
  49.         END AS t1_addresspostal,
  50.         CASE
  51.             WHEN ((wh.name)::text ~~ '%AOI 1%'::text) THEN 'INDONESIA'::text
  52.             WHEN ((wh.name)::text ~~ '%AOI 2%'::text) THEN 'INDONESIA'::text
  53.             ELSE ''::text
  54.         END AS t1_addresscountry,
  55.     'ATV009'::character varying(40) AS t1_6digit_factorycode,
  56.     pol.c_bpartner_id,
  57.     bp1.name AS seller,
  58.     bp1.name AS actual_manufacturer,
  59.     bp1.value AS t2_6digit_factorycode,
  60.     to_char(COALESCE(( SELECT max(so_1.kst_lcdate) AS max
  61.            FROM c_order so_1
  62.           WHERE (((so_1.poreference)::text = (prl.poreference)::text) AND (so_1.c_doctype_id = (1000051)::numeric))), po.created), 'yyyy-MM-dd'::text) AS po_download_date,
  63.     bp.c_currency_id,
  64.     cur.iso_code AS currency,
  65.     bp.po_paymentterm_id,
  66.     pay.name AS payment_terms,
  67.     po.kst_shippingmethod AS ship_mode,
  68.     co1.name AS country_origin,
  69.         CASE
  70.             WHEN ((po.version)::integer = 0) THEN 'No Change'::text
  71.             WHEN (( SELECT count(1) AS count
  72.                FROM ad_changelog
  73.               WHERE ((ad_changelog.ad_table_id = (260)::numeric) AND (ad_changelog.record_id = pol.c_orderline_id) AND (ad_changelog.ad_column_id = (2208)::numeric) AND ((ad_changelog.newvalue)::boolean = false) AND (ad_changelog.created > po.date_from_version) AND (po.created <= po.date_to_version))) > 0) THEN 'Line Cancellation'::text
  74.             WHEN (( SELECT count(1) AS count
  75.                FROM ad_changelog
  76.               WHERE ((ad_changelog.ad_table_id = (260)::numeric) AND (ad_changelog.record_id = pol.c_orderline_id) AND (ad_changelog.ad_column_id = (2205)::numeric) AND (ad_changelog.created > po.date_from_version) AND (po.created <= po.date_to_version))) > 0) THEN 'Add New Line'::text
  77.             WHEN (( SELECT count(1) AS count
  78.                FROM ad_changelog
  79.               WHERE ((ad_changelog.ad_table_id = (260)::numeric) AND (ad_changelog.record_id = pol.c_orderline_id) AND (po.created > po.date_from_version) AND (po.created <= po.date_to_version))) = 0) THEN 'No Change'::text
  80.             ELSE 'Line Amendment'::text
  81.         END AS line_status,
  82.     po.m_warehouse_id,
  83.     pol.line,
  84.     pol.m_product_id,
  85.     mp.upc AS ref,
  86.     mp.description AS material_name,
  87.     mp.kst_width_id,
  88.     ( SELECT wid1.value
  89.            FROM (m_product mp1
  90.              LEFT JOIN kst_width wid1 ON ((mp1.kst_width_id = wid1.kst_width_id)))
  91.           WHERE ((mp1.m_product_category_id = (1000003)::numeric) AND (mp1.m_product_id = pol.m_product_id) AND ((wid1.value)::text !~~ '%X%'::text))) AS width,
  92.     mp.kst_sourcesize_id,
  93.     ( SELECT wid2.value
  94.            FROM (m_product mp2
  95.              LEFT JOIN kst_width wid2 ON ((mp2.kst_width_id = wid2.kst_width_id)))
  96.           WHERE ((mp2.m_product_category_id <> (1000003)::numeric) AND (mp2.m_product_id = pol.m_product_id))) AS size,
  97.         CASE
  98.             WHEN ((col.value)::text ~~ '%DTM%'::text) THEN (col.value)::text
  99.             ELSE (((col.name)::text || ' '::text) || (col.value)::text)
  100.         END AS material_colour,
  101.         CASE
  102.             WHEN (mp.m_product_category_id = ANY (ARRAY[(1000050)::numeric, (1000052)::numeric, (1000064)::numeric, (1000070)::numeric, (1000027)::numeric])) THEN pol.priceentered
  103.             ELSE pol.priceactual
  104.         END AS unit_price,
  105.         CASE
  106.             WHEN (mp.m_product_category_id = ANY (ARRAY[(1000050)::numeric, (1000052)::numeric, (1000064)::numeric, (1000070)::numeric, (1000027)::numeric])) THEN pol.qtyentered
  107.             ELSE pol.qtyordered
  108.         END AS order_quantity,
  109.     mp.c_uom_id,
  110.         CASE
  111.             WHEN (mp.m_product_category_id = ANY (ARRAY[(1000050)::numeric, (1000052)::numeric, (1000064)::numeric, (1000070)::numeric, (1000027)::numeric])) THEN uom2.uomsymbol
  112.             ELSE uom.uomsymbol
  113.         END AS uom,
  114.     to_char(so.kst_mr_date, 'yyyy-MM-dd'::text) AS buyer_requestdate,
  115.     po.kst_deliverydate AS delivery_date,
  116.     pol.qtydelivered AS delivery_quantity,
  117.     so.kst_season AS season,
  118.     ''::text AS adidas_ordernumber,
  119.     ''::text AS adidas_articlenumber,
  120.     po.ad_org_id,
  121.     po.documentno,
  122.     po.version,
  123.     po.purpose,
  124.     ( SELECT inco.code
  125.            FROM t1t2_incoterm inco
  126.           WHERE ((po.incoterm)::text = (inco.name)::text)) AS incoterm,
  127.     bpf.name AS forwarder,
  128.         CASE
  129.             WHEN (po.c_doctypetarget_id = (1000049)::numeric) THEN 'APP_Bulk_Speed_NOOS_P1'::text
  130.             WHEN (po.c_doctypetarget_id = (1000112)::numeric) THEN 'APP_Bulk_Inline_MTF_P2'::text
  131.             WHEN (po.c_doctypetarget_id = (1000103)::numeric) THEN 'APP_Sample_P1'::text
  132.             WHEN (po.c_doctypetarget_id = (1000050)::numeric) THEN 'APP_Sample_P1'::text
  133.             WHEN (po.c_doctypetarget_id = ANY (ARRAY[(1000087)::numeric, (1000128)::numeric, ('10001321000067'::bigint)::numeric, (1000129)::numeric, (1000135)::numeric])) THEN 'APP_Bulk_Inline_P2'::text
  134.             ELSE ''::text
  135.         END AS ordertype,
  136.     bp1.name2,
  137.     (po.version)::text AS versi,
  138.     'adidas'::text AS t1_customer,
  139.     (wid.value)::text AS width1,
  140.     ' '::text AS weight1,
  141.         CASE
  142.             WHEN ((mp.m_product_category_id = ANY (ARRAY[(1000012)::numeric, (1000048)::numeric])) OR ((mp.value)::text ~~ '%tiecord%'::text)) THEN wid.value
  143.             ELSE ' '::character varying
  144.         END AS length,
  145.         CASE
  146.             WHEN (mp.m_product_category_id = (1000048)::numeric) THEN wid.value
  147.             ELSE ' '::character varying
  148.         END AS height,
  149.         CASE
  150.             WHEN ((mp.m_product_category_id = (1000003)::numeric) AND ((mp.description)::text ~~ '%CM%'::text)) THEN 'CM'::text
  151.             WHEN ((mp.m_product_category_id = (1000003)::numeric) AND ((mp.description)::text !~~ '%CM%'::text)) THEN 'INCH'::text
  152.             ELSE ' '::text
  153.         END AS uom_width,
  154.     ' '::text AS uom_weight,
  155.         CASE
  156.             WHEN ((mp.m_product_category_id = (1000048)::numeric) OR ((mp.value)::text ~~ '%tiecord%'::text)) THEN uom.uomsymbol
  157.             WHEN (mp.m_product_category_id = (1000012)::numeric) THEN 'CM'::character varying
  158.             ELSE ' '::character varying
  159.         END AS uom_length,
  160.         CASE
  161.             WHEN (mp.m_product_category_id = (1000048)::numeric) THEN uom.uomsymbol
  162.             ELSE ' '::character varying
  163.         END AS uom_height,
  164.     string_agg(DISTINCT "left"((so.kst_joborder)::text, (strpos((so.kst_joborder)::text, '::'::text) - 1)), ':'::text) AS model_name,
  165.     COALESCE(
  166.         CASE
  167.             WHEN ((mp.m_product_category_id = (1000012)::numeric) AND ((mp.value)::text ~~ '%RT%'::text)) THEN 'RT'::text
  168.             WHEN ((mp.m_product_category_id = (1000012)::numeric) AND ((mp.value)::text ~~ '%LT%'::text)) THEN 'LT'::text
  169.             WHEN ((mp.m_product_category_id = (1000003)::numeric) AND ((wid.value)::text ~~ '%X%'::text)) THEN (wid.value)::text
  170.             ELSE ''::text
  171.         END, (pol.additional1)::text) AS additional1,
  172.     mp.value,
  173.     loc1.address1 AS t2_address_line_1,
  174.     loc1.address2 AS t2_address_line_2,
  175.     loc1.address3 AS t2_address_line_3,
  176.     loc1.address4 AS t2_address_line_4,
  177.     loc1.city AS t2_address_city,
  178.     loc1.postal AS t2_address_postal,
  179.     co1.name AS t2_address_country,
  180.     po.dyed AS color_matching,
  181.     bp.c_paymentterm_id,
  182.     to_char(po.created, 'yyyy-MM-dd'::text) AS issue_date2,
  183.     po.incoterm AS incoterm2,
  184.         CASE
  185.             WHEN ((po.kst_shippingmethod)::text = 'AC'::text) THEN 'Air-Collect'::text
  186.             WHEN ((po.kst_shippingmethod)::text = 'AP'::text) THEN 'Air-Prepaid'::text
  187.             WHEN ((po.kst_shippingmethod)::text = 'AT'::text) THEN 'Air-Truck Prepaid'::text
  188.             WHEN ((po.kst_shippingmethod)::text = 'CC'::text) THEN 'Courrier-Collect'::text
  189.             WHEN ((po.kst_shippingmethod)::text = 'CP'::text) THEN 'Courrier-Prepaid'::text
  190.             WHEN ((po.kst_shippingmethod)::text = 'SA'::text) THEN 'Sea Air-Prepaid'::text
  191.             WHEN ((po.kst_shippingmethod)::text = 'SP'::text) THEN 'Sea-Prepaid'::text
  192.             WHEN ((po.kst_shippingmethod)::text = 'SC'::text) THEN 'Sea-Collect'::text
  193.             WHEN ((po.kst_shippingmethod)::text = 'T'::text) THEN 'Truck'::text
  194.             ELSE ''::text
  195.         END AS ship_mode2,
  196.     to_char(pol.datepromised, 'yyyy-MM-dd'::text) AS buyer_requestdate2,
  197.     po.c_order_id,
  198.     uom2.uomsymbol AS uom2,
  199.     ( SELECT wid2.value
  200.            FROM (m_product mp2
  201.              LEFT JOIN kst_width wid2 ON ((mp2.kst_width_id = wid2.kst_width_id)))
  202.           WHERE ((mp2.m_product_category_id <> ALL (ARRAY[(1000003)::numeric, (1000012)::numeric, (1000050)::numeric, (1000052)::numeric])) AND (mp2.m_product_id = pol.m_product_id))) AS size2,
  203.     to_char(so.kst_statisticaldate, 'yyyy-MM-dd'::text) AS adidas_crd,
  204.     to_char(so.datepromised, 'yyyy-MM-dd'::text) AS plan_date,
  205.     mp.m_product_category_id,
  206.     pol.c_orderline_id
  207.    FROM (((((((((((((((((((((((((m_requisitionline prl
  208.      LEFT JOIN m_requisition pr ON ((prl.m_requisition_id = pr.m_requisition_id)))
  209.      LEFT JOIN kst_orderdetail odt ON ((prl.m_requisitionline_id = odt.m_requisitionline_id)))
  210.      LEFT JOIN c_orderline pol ON ((odt.c_orderline_id = pol.c_orderline_id)))
  211.      LEFT JOIN c_order po ON ((pol.c_order_id = po.c_order_id)))
  212.      LEFT JOIN c_bpartner bp1 ON ((pol.c_bpartner_id = bp1.c_bpartner_id)))
  213.      LEFT JOIN c_bpartner_location bpl1 ON ((po.c_bpartner_location_id = bpl1.c_bpartner_location_id)))
  214.      LEFT JOIN c_location loc1 ON ((bpl1.c_location_id = loc1.c_location_id)))
  215.      LEFT JOIN c_country co1 ON ((loc1.c_country_id = co1.c_country_id)))
  216.      LEFT JOIN c_bpartner bpf ON ((po.kst_bpartner_forwarder_id = bpf.c_bpartner_id)))
  217.      LEFT JOIN m_warehouse wh ON ((po.m_warehouse_id = wh.m_warehouse_id)))
  218.      LEFT JOIN m_product mp ON ((pol.m_product_id = mp.m_product_id)))
  219.      LEFT JOIN kst_colordetails col ON ((mp.kst_colordetails_id = col.kst_colordetails_id)))
  220.      LEFT JOIN c_uom uom ON ((mp.c_uom_id = uom.c_uom_id)))
  221.      LEFT JOIN c_uom uom2 ON ((pol.c_uom_id = uom2.c_uom_id)))
  222.      LEFT JOIN kst_width wid ON ((mp.kst_width_id = wid.kst_width_id)))
  223.      LEFT JOIN kst_sourcesize si ON ((mp.kst_sourcesize_id = si.kst_sourcesize_id)))
  224.      LEFT JOIN c_order so ON ((((prl.poreference)::text = (so.poreference)::text) AND (so.issotrx = 'Y'::bpchar) AND (so.c_doctype_id <> (1000082)::numeric))))
  225.      LEFT JOIN c_bpartner bp ON ((po.c_bpartner_id = bp.c_bpartner_id)))
  226.      LEFT JOIN c_paymentterm pay ON ((bp.po_paymentterm_id = pay.c_paymentterm_id)))
  227.      LEFT JOIN c_currency cur ON ((bp.c_currency_id = cur.c_currency_id)))
  228.      LEFT JOIN ad_user ad ON ((ad.ad_user_id = po.createdby)))
  229.      LEFT JOIN c_bpartner_location bpl ON ((po.c_bpartner_location_id = bpl.c_bpartner_location_id)))
  230.      LEFT JOIN c_location loc ON ((bpl.c_location_id = loc.c_location_id)))
  231.      LEFT JOIN c_region reg ON ((loc.c_region_id = reg.c_region_id)))
  232.      LEFT JOIN c_country co ON ((loc.c_country_id = co.c_country_id)))
  233.   GROUP BY po.documentno, po.created, po.updated, wh.name, loc.address4, bp.ad_client_id, ad.description, ad.email, pol.c_bpartner_id, bp1.name, bp1.value, bp.c_currency_id, cur.iso_code, bp.po_paymentterm_id, pay.name, po.kst_shippingmethod, co1.name, po.version, pol.c_orderline_id, po.date_from_version, po.date_to_version, po.m_warehouse_id, mp.upc, mp.description, mp.kst_width_id, mp.kst_sourcesize_id, col.value, col.name, mp.c_uom_id, uom.uomsymbol, po.kst_deliverydate, so.kst_season, bp.ad_org_id, po.purpose, po.incoterm, po.kst_bpartner_forwarder_id, po.ordertype, bp1.name2, po.ad_client_id, prl.poreference, so.kst_mr_date, po.ad_org_id, bpf.name, po.c_doctype_id, wid.value, mp.m_product_category_id, mp.value, loc1.address1, loc1.address2, loc1.address3, loc1.address4, loc1.city, loc1.postal, po.dyed, bp.c_paymentterm_id, po.c_order_id,
  234.         CASE
  235.             WHEN ((wh.name)::text ~~ '%AOI 1%'::text) THEN 'Jl. Raya Semarang-Kendal Km 12 Kawasan Rukti Mukti Bawana Blok B5'::text
  236.             WHEN ((wh.name)::text ~~ '%AOI 2%'::text) THEN 'Tugu Wijaya IV Kawasan Industri Wijaya Kusuma Randu Garut'::text
  237.             ELSE ''::text
  238.         END, so.kst_joborder, uom2.uomsymbol, so.kst_statisticaldate, so.datepromised;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement