Advertisement
tko_pb

f_material_requirement.sql

Mar 2nd, 2022
1,018
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- adempiere.f_material_requirement source
  2.  
  3. CREATE OR REPLACE VIEW adempiere.f_material_requirement
  4. AS SELECT ppb.pp_product_bom_id,
  5.     ppb.documentno,
  6.     mp.m_product_id,
  7.     mp.value,
  8.     mp.upc AS style,
  9.     ppbl.pp_product_bomline_id,
  10.     ppbl.line,
  11.     mpc.m_product_id AS componentid,
  12.     mpc.value AS componentvalue,
  13.     ppbl.isconfirmedkst,
  14.     ppbl.kst_sourcesize_id,
  15.     ks.value AS sourcesize,
  16.     ppbl.c_country_id,
  17.     cc.countrycode,
  18.     cbc.c_bpartner_id,
  19.     cbc.value AS bpartnervalue,
  20.     ppbl.qtybom,
  21.     mpc.c_uom_id,
  22.     cu.name,
  23.     ppbl.kst_part,
  24.     co.documentno AS salesorderno,
  25.     co.poreference,
  26.     co.kst_joborder,
  27.     co.kst_lcdate,
  28.     co.c_order_id,
  29.     col.c_orderline_id,
  30.     col.qtyordered,
  31.     col.qtyordered * ppbl.qtybom AS qtyrequired,
  32.     co.ad_client_id,
  33.     co.ad_org_id,
  34.     co.issotrx,
  35.     ctg.m_product_category_id,
  36.     ppbl.dateconfirm,
  37.     cbco.value AS cust_no,
  38.     mp.kst_articleno,
  39.     ksc.value AS gmt_size,
  40.     ccc.countrycode AS ctycode,
  41.     mpc.name AS desc_raw,
  42.     cbc2.value AS supp_code,
  43.     cbc2.name AS supp_name,
  44.     ppbl.ispiping,
  45.     ppbl.poreference AS poreference_bom,
  46.     ccc.name AS ctyname,
  47.     cbbs.value AS supp_code_bs,
  48.     cbbs.name AS supp_name_bs,
  49.     wh.name AS warehouse,
  50.     date(co.datepromised) AS datepromised,
  51.     date(co.kst_statisticaldate2) AS statisticaldate,
  52.     date(co.kst_statisticaldate) AS kst_statisticaldate,
  53.     mp.kst_season,
  54.     ctgg.m_product_category_id AS m_product_category_id_fp,
  55.     ctgg.value AS m_product_category_value_fp,
  56.     ctgg.name AS m_product_category_name_fp,
  57.     getcountryname(cg.c_countrygroup_id, co.c_country_id, co.c_bpartner_id, ppbl.poreference, ppbl.c_countrygroup_id, ppbl.c_country_id, ppbl.c_bpartner_id)::text AS countrycodegroup,
  58.     ctggg.name AS m_product_category_name_fg,
  59.     mp.kst_isartwork,
  60.     mpc.kst_isila,
  61.     ceiling(ppbl.qtybom / 0.001) * 0.001 AS qtybomnew,
  62.     ceiling(ppbl.qtybom / 0.001) * 0.001 * col.qtyordered AS qtyrequirednew,
  63.     co.kst_mr_date,
  64.     ppbl.ref_bpartner_id,
  65.     co.kst_ordertype
  66.    FROM c_order co
  67.      JOIN c_orderline col ON co.c_order_id = col.c_order_id
  68.      JOIN m_warehouse wh ON wh.m_warehouse_id = co.m_warehouse_id
  69.      JOIN c_bpartner cbp ON co.c_bpartner_id = cbp.c_bpartner_id
  70.      JOIN c_bpartner_location cbpl ON cbpl.c_bpartner_location_id = co.c_bpartner_location_id
  71.      JOIN c_location cl ON cl.c_location_id = cbpl.c_location_id
  72.      JOIN m_product mp ON col.m_product_id = mp.m_product_id
  73.      JOIN pp_product_bom ppb ON ppb.m_product_id = mp.m_product_id AND ppb.pp_product_bom_id = kst_validbomlcdate(ppb.m_product_id, co.kst_lcdate)
  74.      JOIN pp_product_bomline ppbl ON ppb.pp_product_bom_id = ppbl.pp_product_bom_id
  75.      JOIN m_product mpc ON ppbl.m_product_id = mpc.m_product_id
  76.      LEFT JOIN m_product_category ctg ON ppbl.m_product_category_id = ctg.m_product_category_id
  77.      LEFT JOIN kst_sourcesize ks ON ppbl.kst_sourcesize_id = ks.kst_sourcesize_id
  78.      LEFT JOIN c_country cc ON ppbl.c_country_id = cc.c_country_id
  79.      LEFT JOIN c_bpartner cbc ON ppbl.c_bpartner_id = cbc.c_bpartner_id
  80.      JOIN c_uom cu ON mpc.c_uom_id = cu.c_uom_id
  81.      LEFT JOIN c_bpartner cbco ON cbco.c_bpartner_id = co.c_bpartner_id
  82.      LEFT JOIN kst_sourcesize ksc ON ksc.kst_sourcesize_id = mp.kst_sourcesize_id
  83.      LEFT JOIN c_country ccc ON ccc.c_country_id = co.c_country_id
  84.      LEFT JOIN c_bpartner cbc2 ON ppbl.ref_bpartner_id = cbc2.c_bpartner_id
  85.      LEFT JOIN kst_bom_supplier bs ON "right"(co.poreference::text, 9) = "right"(bs.poreference::text, 9) AND ppbl.m_product_id = bs.m_product_id AND ppbl.ispiping = bs.ispiping AND bs.isactive = 'Y'::bpchar AND co.kst_joborder::text = bs.kst_joborder::text
  86.      LEFT JOIN c_bpartner cbbs ON bs.c_bpartner_id = cbbs.c_bpartner_id
  87.      LEFT JOIN m_product_category ctgg ON mpc.m_product_category_id = ctgg.m_product_category_id
  88.      LEFT JOIN c_countrygroupcountry cgc ON co.c_country_id = cgc.c_country_id AND co.c_bpartner_id = cgc.c_bpartner_id
  89.      LEFT JOIN c_countrygroup cg ON cgc.c_countrygroup_id = cg.c_countrygroup_id
  90.      LEFT JOIN m_product_category ctggg ON ctggg.m_product_category_id = mp.m_product_category_id
  91.   WHERE co.issotrx = 'Y'::bpchar AND (co.docstatus = ANY (ARRAY['CO'::bpchar, 'CL'::bpchar])) AND (ppbl.c_bpartner_id IS NULL OR ppbl.c_bpartner_id = co.c_bpartner_id) AND (ppbl.c_country_id IS NULL OR ppbl.c_country_id = co.c_country_id) AND (ppbl.poreference IS NULL OR "right"(ppbl.poreference::text, 9) = "right"(co.poreference::text, 9)) AND ppbl.isactive = 'Y'::bpchar AND ppbl.pp_product_bomline_id = getproductbomlinebycountry(ppbl.pp_product_bomline_id, ppbl.pp_product_bom_id, mpc.m_product_id, co.c_country_id, co.c_bpartner_id, co.poreference, cgc.c_countrygroup_id, mp.m_product_id, ppbl.kst_part, co.kst_statisticaldate) AND ctgg.m_product_category_id <> 1000032::numeric
  92. UNION
  93.  SELECT ppb2.pp_product_bom_id,
  94.     ppb2.documentno,
  95.     mp2.m_product_id,
  96.     mp2.value,
  97.     mp2.upc AS style,
  98.     ppbl2.pp_product_bomline_id,
  99.     ppbl2.line,
  100.     mpc.m_product_id AS componentid,
  101.     mpc.value AS componentvalue,
  102.     ppbl2.isconfirmedkst,
  103.     ppbl2.kst_sourcesize_id,
  104.     ks.value AS sourcesize,
  105.     ppbl2.c_country_id,
  106.     cc.countrycode,
  107.     cbc.c_bpartner_id,
  108.     cbc.value AS bpartnervalue,
  109.     ppbl2.qtybom,
  110.     mpc.c_uom_id,
  111.     cu.name,
  112.     ppbl2.kst_part,
  113.     co.documentno AS salesorderno,
  114.     co.poreference,
  115.     co.kst_joborder,
  116.     co.kst_lcdate,
  117.     co.c_order_id,
  118.     col.c_orderline_id,
  119.     col.qtyordered,
  120.     col.qtyordered * ppbl2.qtybom AS qtyrequired,
  121.     co.ad_client_id,
  122.     co.ad_org_id,
  123.     co.issotrx,
  124.     ctg.m_product_category_id,
  125.     ppbl2.dateconfirm,
  126.     cbco.value AS cust_no,
  127.     mp2.kst_articleno,
  128.     ksc.value AS gmt_size,
  129.     ccc.countrycode AS ctycode,
  130.     mpc.name AS desc_raw,
  131.     cbc2.value AS supp_code,
  132.     cbc2.name AS supp_name,
  133.     ppbl2.ispiping,
  134.     ppbl2.poreference AS poreference_bom,
  135.     ccc.name AS ctyname,
  136.     cbbs.value AS supp_code_bs,
  137.     cbbs.name AS supp_name_bs,
  138.     wh.name AS warehouse,
  139.     date(co.datepromised) AS datepromised,
  140.     date(co.kst_statisticaldate2) AS statisticaldate,
  141.     date(co.kst_statisticaldate) AS kst_statisticaldate,
  142.     mp2.kst_season,
  143.     ctgg.m_product_category_id AS m_product_category_id_fp,
  144.     ctgg.value AS m_product_category_value_fp,
  145.     ctgg.name AS m_product_category_name_fp,
  146.     getcountryname(cg.c_countrygroup_id, co.c_country_id, co.c_bpartner_id, ppbl2.poreference, ppbl2.c_countrygroup_id, ppbl2.c_country_id, ppbl2.c_bpartner_id)::text AS countrycodegroup,
  147.     ctggg.name AS m_product_category_name_fg,
  148.     mp2.kst_isartwork,
  149.     mpc.kst_isila,
  150.     ceiling(ppbl2.qtybom / 0.001) * 0.001 AS qtybomnew,
  151.     ceiling(ppbl2.qtybom / 0.001) * 0.001 * col.qtyordered AS qtyrequirednew,
  152.     co.kst_mr_date,
  153.     ppbl2.ref_bpartner_id,
  154.     co.kst_ordertype
  155.    FROM c_order co
  156.      JOIN c_orderline col ON co.c_order_id = col.c_order_id
  157.      JOIN m_warehouse wh ON wh.m_warehouse_id = co.m_warehouse_id
  158.      JOIN c_bpartner cbp ON co.c_bpartner_id = cbp.c_bpartner_id
  159.      JOIN c_bpartner_location cbpl ON cbpl.c_bpartner_location_id = co.c_bpartner_location_id
  160.      JOIN c_location cl ON cl.c_location_id = cbpl.c_location_id
  161.      JOIN m_product mp ON col.m_product_id = mp.m_product_id
  162.      JOIN pp_product_bom ppb ON ppb.m_product_id = mp.m_product_id AND ppb.pp_product_bom_id = kst_validbomlcdate(ppb.m_product_id, co.kst_lcdate)
  163.      JOIN pp_product_bomline ppbl ON ppb.pp_product_bom_id = ppbl.pp_product_bom_id
  164.      JOIN m_product mp2 ON ppbl.m_product_id = mp2.m_product_id
  165.      JOIN pp_product_bom ppb2 ON ppb2.m_product_id = mp2.m_product_id AND ppb2.pp_product_bom_id = kst_validbomlcdate(ppb2.m_product_id, co.kst_lcdate)
  166.      JOIN pp_product_bomline ppbl2 ON ppb2.pp_product_bom_id = ppbl2.pp_product_bom_id
  167.      JOIN m_product mpc ON ppbl2.m_product_id = mpc.m_product_id
  168.      LEFT JOIN m_product_category ctg ON ppbl2.m_product_category_id = ctg.m_product_category_id
  169.      LEFT JOIN kst_sourcesize ks ON ppbl2.kst_sourcesize_id = ks.kst_sourcesize_id
  170.      LEFT JOIN c_country cc ON ppbl2.c_country_id = cc.c_country_id
  171.      LEFT JOIN c_bpartner cbc ON ppbl2.c_bpartner_id = cbc.c_bpartner_id
  172.      JOIN c_uom cu ON mpc.c_uom_id = cu.c_uom_id
  173.      LEFT JOIN c_bpartner cbco ON cbco.c_bpartner_id = co.c_bpartner_id
  174.      LEFT JOIN kst_sourcesize ksc ON ksc.kst_sourcesize_id = mp2.kst_sourcesize_id
  175.      LEFT JOIN c_country ccc ON ccc.c_country_id = co.c_country_id
  176.      LEFT JOIN c_bpartner cbc2 ON ppbl2.ref_bpartner_id = cbc2.c_bpartner_id
  177.      LEFT JOIN kst_bom_supplier bs ON "right"(co.poreference::text, 9) = "right"(bs.poreference::text, 9) AND ppbl2.m_product_id = bs.m_product_id AND ppbl2.ispiping = bs.ispiping AND bs.isactive = 'Y'::bpchar AND co.kst_joborder::text = bs.kst_joborder::text
  178.      LEFT JOIN c_bpartner cbbs ON bs.c_bpartner_id = cbbs.c_bpartner_id
  179.      LEFT JOIN m_product_category ctgg ON mpc.m_product_category_id = ctgg.m_product_category_id
  180.      LEFT JOIN c_countrygroupcountry cgc ON co.c_country_id = cgc.c_country_id AND co.c_bpartner_id = cgc.c_bpartner_id
  181.      LEFT JOIN c_countrygroup cg ON cgc.c_countrygroup_id = cg.c_countrygroup_id
  182.      LEFT JOIN m_product_category ctggg ON ctggg.m_product_category_id = mp2.m_product_category_id
  183.   WHERE co.issotrx = 'Y'::bpchar AND (co.docstatus = ANY (ARRAY['CO'::bpchar, 'CL'::bpchar])) AND (ppbl2.c_bpartner_id IS NULL OR ppbl2.c_bpartner_id = co.c_bpartner_id) AND (ppbl2.c_country_id IS NULL OR ppbl2.c_country_id = co.c_country_id) AND (ppbl2.poreference IS NULL OR "right"(ppbl2.poreference::text, 9) = "right"(co.poreference::text, 9)) AND ppbl2.isactive = 'Y'::bpchar AND ppbl2.pp_product_bomline_id = getproductbomlinebycountry(ppbl2.pp_product_bomline_id, ppbl2.pp_product_bom_id, mpc.m_product_id, co.c_country_id, co.c_bpartner_id, co.poreference, cgc.c_countrygroup_id, mp.m_product_id, ppbl2.kst_part, co.kst_statisticaldate) AND ctgg.m_product_category_id <> 1000032::numeric
  184. UNION
  185.  SELECT ppb3.pp_product_bom_id,
  186.     ppb3.documentno,
  187.     mp3.m_product_id,
  188.     mp3.value,
  189.     mp3.upc AS style,
  190.     ppbl3.pp_product_bomline_id,
  191.     ppbl3.line,
  192.     mpc.m_product_id AS componentid,
  193.     mpc.value AS componentvalue,
  194.     ppbl3.isconfirmedkst,
  195.     ppbl3.kst_sourcesize_id,
  196.     ks.value AS sourcesize,
  197.     ppbl3.c_country_id,
  198.     cc.countrycode,
  199.     cbc.c_bpartner_id,
  200.     cbc.value AS bpartnervalue,
  201.     ppbl3.qtybom,
  202.     mpc.c_uom_id,
  203.     cu.name,
  204.     ppbl3.kst_part,
  205.     co.documentno AS salesorderno,
  206.     co.poreference,
  207.     co.kst_joborder,
  208.     co.kst_lcdate,
  209.     co.c_order_id,
  210.     col.c_orderline_id,
  211.     col.qtyordered,
  212.     col.qtyordered * ppbl3.qtybom AS qtyrequired,
  213.     co.ad_client_id,
  214.     co.ad_org_id,
  215.     co.issotrx,
  216.     ctg.m_product_category_id,
  217.     ppbl3.dateconfirm,
  218.     cbco.value AS cust_no,
  219.     mp3.kst_articleno,
  220.     ksc.value AS gmt_size,
  221.     ccc.countrycode AS ctycode,
  222.     mpc.name AS desc_raw,
  223.     cbc2.value AS supp_code,
  224.     cbc2.name AS supp_name,
  225.     ppbl3.ispiping,
  226.     ppbl3.poreference AS poreference_bom,
  227.     ccc.name AS ctyname,
  228.     cbbs.value AS supp_code_bs,
  229.     cbbs.name AS supp_name_bs,
  230.     wh.name AS warehouse,
  231.     date(co.datepromised) AS datepromised,
  232.     date(co.kst_statisticaldate2) AS statisticaldate,
  233.     date(co.kst_statisticaldate) AS kst_statisticaldate,
  234.     mp3.kst_season,
  235.     ctgg.m_product_category_id AS m_product_category_id_fp,
  236.     ctgg.value AS m_product_category_value_fp,
  237.     ctgg.name AS m_product_category_name_fp,
  238.     getcountryname(cg.c_countrygroup_id, co.c_country_id, co.c_bpartner_id, ppbl3.poreference, ppbl3.c_countrygroup_id, ppbl3.c_country_id, ppbl3.c_bpartner_id)::text AS countrycodegroup,
  239.     ctggg.name AS m_product_category_name_fg,
  240.     mp3.kst_isartwork,
  241.     mpc.kst_isila,
  242.     ceiling(ppbl3.qtybom / 0.001) * 0.001 AS qtybomnew,
  243.     ceiling(ppbl3.qtybom / 0.001) * 0.001 * col.qtyordered AS qtyrequirednew,
  244.     co.kst_mr_date,
  245.     ppbl3.ref_bpartner_id,
  246.     co.kst_ordertype
  247.    FROM c_order co
  248.      JOIN c_orderline col ON co.c_order_id = col.c_order_id
  249.      JOIN m_warehouse wh ON wh.m_warehouse_id = co.m_warehouse_id
  250.      JOIN c_bpartner cbp ON co.c_bpartner_id = cbp.c_bpartner_id
  251.      JOIN c_bpartner_location cbpl ON cbpl.c_bpartner_location_id = co.c_bpartner_location_id
  252.      JOIN c_location cl ON cl.c_location_id = cbpl.c_location_id
  253.      JOIN m_product mp ON col.m_product_id = mp.m_product_id
  254.      JOIN pp_product_bom ppb ON ppb.m_product_id = mp.m_product_id AND ppb.pp_product_bom_id = kst_validbomlcdate(ppb.m_product_id, co.kst_lcdate)
  255.      JOIN pp_product_bomline ppbl ON ppb.pp_product_bom_id = ppbl.pp_product_bom_id
  256.      JOIN m_product mp2 ON ppbl.m_product_id = mp2.m_product_id
  257.      JOIN pp_product_bom ppb2 ON ppb2.m_product_id = mp2.m_product_id AND ppb2.pp_product_bom_id = kst_validbomlcdate(ppb2.m_product_id, co.kst_lcdate)
  258.      JOIN pp_product_bomline ppbl2 ON ppb2.pp_product_bom_id = ppbl2.pp_product_bom_id
  259.      JOIN m_product mp3 ON ppbl2.m_product_id = mp3.m_product_id
  260.      JOIN pp_product_bom ppb3 ON ppb3.m_product_id = mp3.m_product_id AND ppb3.pp_product_bom_id = kst_validbomlcdate(ppb3.m_product_id, co.kst_lcdate)
  261.      JOIN pp_product_bomline ppbl3 ON ppb3.pp_product_bom_id = ppbl3.pp_product_bom_id
  262.      JOIN m_product mpc ON ppbl3.m_product_id = mpc.m_product_id
  263.      LEFT JOIN m_product_category ctg ON ppbl3.m_product_category_id = ctg.m_product_category_id
  264.      LEFT JOIN kst_sourcesize ks ON ppbl3.kst_sourcesize_id = ks.kst_sourcesize_id
  265.      LEFT JOIN c_country cc ON ppbl3.c_country_id = cc.c_country_id
  266.      LEFT JOIN c_bpartner cbc ON ppbl3.c_bpartner_id = cbc.c_bpartner_id
  267.      JOIN c_uom cu ON mpc.c_uom_id = cu.c_uom_id
  268.      LEFT JOIN c_bpartner cbco ON cbco.c_bpartner_id = co.c_bpartner_id
  269.      LEFT JOIN kst_sourcesize ksc ON ksc.kst_sourcesize_id = mp3.kst_sourcesize_id
  270.      LEFT JOIN c_country ccc ON ccc.c_country_id = co.c_country_id
  271.      LEFT JOIN c_bpartner cbc2 ON ppbl3.ref_bpartner_id = cbc2.c_bpartner_id
  272.      LEFT JOIN kst_bom_supplier bs ON "right"(co.poreference::text, 9) = "right"(bs.poreference::text, 9) AND ppbl3.m_product_id = bs.m_product_id AND ppbl3.ispiping = bs.ispiping AND bs.isactive = 'Y'::bpchar AND co.kst_joborder::text = bs.kst_joborder::text
  273.      LEFT JOIN c_bpartner cbbs ON bs.c_bpartner_id = cbbs.c_bpartner_id
  274.      LEFT JOIN m_product_category ctgg ON mpc.m_product_category_id = ctgg.m_product_category_id
  275.      LEFT JOIN c_countrygroupcountry cgc ON co.c_country_id = cgc.c_country_id AND co.c_bpartner_id = cgc.c_bpartner_id
  276.      LEFT JOIN c_countrygroup cg ON cgc.c_countrygroup_id = cg.c_countrygroup_id
  277.      LEFT JOIN m_product_category ctggg ON ctggg.m_product_category_id = mp3.m_product_category_id
  278.   WHERE co.issotrx = 'Y'::bpchar AND (co.docstatus = ANY (ARRAY['CO'::bpchar, 'CL'::bpchar])) AND (ppbl3.c_bpartner_id IS NULL OR ppbl3.c_bpartner_id = co.c_bpartner_id) AND (ppbl3.c_country_id IS NULL OR ppbl3.c_country_id = co.c_country_id) AND (ppbl3.poreference IS NULL OR "right"(ppbl3.poreference::text, 9) = "right"(co.poreference::text, 9)) AND ppbl3.isactive = 'Y'::bpchar AND ppbl3.pp_product_bomline_id = getproductbomlinebycountry(ppbl3.pp_product_bomline_id, ppbl3.pp_product_bom_id, mpc.m_product_id, co.c_country_id, co.c_bpartner_id, co.poreference, cgc.c_countrygroup_id, mp.m_product_id, ppbl3.kst_part, co.kst_statisticaldate) AND ctgg.m_product_category_id <> 1000032::numeric;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement