tko_pb

auto po

Apr 29th, 2020
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE OR REPLACE FUNCTION adempiere.tpb_auto_allocation_fabric(p_lc_date timestamp without time zone, p_product_category numeric)
  2.  RETURNS void
  3.  LANGUAGE plpgsql
  4. AS $function$
  5. begin
  6.     TRUNCATE TABLE tpb_populate_auto_po ;
  7. insert into tpb_populate_auto_po
  8.     select  
  9.         concat(co.kst_ordertype,';',mr.m_warehouse_id,
  10.                     ';',mr_line.c_bpartner_id,';',mpc.m_product_category_id,';',mp.upc,';',mr.m_requisition_id) as id,
  11.         '0' as line_id,
  12.         mp.m_product_id,
  13.         mr.m_warehouse_id,
  14.         mr_line.c_bpartner_id,
  15.         mr_line.QtyEntered,
  16.         co.kst_ordertype,
  17.         mr.m_requisition_id,
  18.         mr_line.m_requisitionline_id,
  19.         mpc.m_product_category_id,
  20.         mr.m_pricelist_id,
  21.         mr_line.c_currency_id,
  22.         co.kst_brand,
  23.         co.kst_season,
  24.         co.poreference,
  25.         co.c_order_id as so_id,
  26.         mp.upc
  27.     from m_requisitionline mr_line
  28.     left join m_requisition as mr on mr_line.m_requisition_id = mr.m_requisition_id
  29.     left join c_order as co on mr_line.poreference=co.poreference
  30.     left join m_product as mp on mr_line.m_product_id = mp.m_product_id
  31.     left join m_product_category as mpc on mp.m_product_category_id=mpc.m_product_category_id
  32.     where co.kst_lcdate= p_lc_date --'2020-02-27'::timestamp--'2020-01-16'::timestamp
  33.     and mpc.m_product_category_id = (select m_product_category_id from m_product_category mpc where value = 'FB')
  34.     and mr_line.isactive  = 'Y'
  35.     and co.C_DocTypeTarget_ID <> 1000082
  36.     and mp.kst_isila = 'N'
  37.     group by
  38.         co.kst_ordertype,
  39.         mr.m_warehouse_id,
  40.         mr_line.c_bpartner_id,
  41.         mpc.m_product_category_id,
  42.         mp.upc,
  43.         mp.m_product_id,
  44.         mr_line.QtyEntered,
  45.         mr.m_requisition_id,
  46.         mr_line.m_requisitionline_id,
  47.         mr.m_pricelist_id,
  48.         mr_line.c_currency_id,
  49.         co.kst_brand,
  50.         co.kst_season,
  51.         co.poreference,
  52.         co.c_order_id,
  53.         mp.upc;
  54.      raise NOTICE 'Populate Data Auto Allocate From PO is Completed';
  55. end;
  56. $function$
  57. ;
  58.  
  59. 21,171
  60.  
  61. select * from kst_orderdetail where m_requisitionline_id =3293297
  62.  
  63. select * from tpb_auto_allocation_perpo('2020-02-27'::timestamp,1000050)
  64.  
  65. select * from tpb_populate_auto_po tpap  
  66.  
  67. where id = '0125737260;61034229;1001893;1000002;2020-02-27;CreatedAt:2020-04-24'  
  68.  
  69. -- /////////////////////////////// auto po combine per po buyer.
  70. CREATE OR REPLACE FUNCTION adempiere.tpb_auto_allocation_perpo(p_lc_date timestamp without time zone, p_product_category numeric)
  71.  RETURNS void
  72.  LANGUAGE plpgsql
  73. AS $function$
  74. begin
  75.     TRUNCATE TABLE tpb_populate_auto_po ;
  76. insert into tpb_populate_auto_po
  77. select
  78.     concat(right(so.poreference,10),';',right(mp.upc,8),';',mr_line.c_bpartner_id,';',mr.m_warehouse_id,';',so.kst_lcdate::date,';CreatedAt:',now()::date) as id,
  79.     concat(right(so.poreference,10),';',right(mp.upc,8),';',mr_line.c_bpartner_id,';',mr.m_warehouse_id,';',so.kst_lcdate::date,';CreatedAt:',now()::date) as line_id,
  80.     mp.m_product_id,
  81.     mr.m_warehouse_id,
  82.     mr_line.c_bpartner_id,
  83.     mr_line.QtyEntered,
  84.     so.kst_ordertype,
  85.     mr.m_requisition_id,
  86.     mr_line.m_requisitionline_id,
  87.     mpc.m_product_category_id,
  88.     mr.m_pricelist_id,
  89.     mr_line.c_currency_id,
  90.     so.kst_brand,
  91.     so.kst_season,
  92.     so.poreference,
  93.     0 as so_id,
  94.     mp.upc,
  95.     mr_line.datepromised
  96. from
  97. m_requisitionline mr_line
  98. left join m_requisition as mr on mr.m_requisition_id = mr_line.m_requisition_id
  99. left join c_order as so on mr_line.poreference = so.poreference
  100. left join m_product as mp on mr_line.m_product_id = mp.m_product_id
  101. left join m_product_category as mpc on mp.m_product_category_id = mpc.m_product_category_id
  102. where so.C_DocTypeTarget_ID <> 1000082 and mr_line.isactive  = 'Y' and mp.kst_isila ='N'
  103. and so.kst_lcdate = p_lc_date and mpc.m_product_category_id = p_product_category;
  104. raise NOTICE 'Populate Data Auto Allocate From PO is Completed';
  105. end;
  106. $function$
  107. ;
  108.  
  109. select * from m_pricelist mp where m_pricelist_id =1000005
  110.  
  111.  
  112. select * from tpb_alloc_wh_style_tyord('2020-02-27'::timestamp, 1000050)
  113.  
  114. select * from tpb_populate_auto_po
  115.  
  116. --Per WH/Style/Type Order per UPC (8 digit)
  117. --////////////////////////////////// auto po combine per style/WH/type order
  118. CREATE OR REPLACE FUNCTION adempiere.tpb_alloc_wh_style_tyord(p_lc_date timestamp without time zone, p_product_category numeric)
  119.  RETURNS void
  120.  LANGUAGE plpgsql
  121. AS $function$
  122. begin
  123.     TRUNCATE TABLE tpb_populate_auto_po ;
  124. insert into tpb_populate_auto_po
  125. select
  126.     concat(mr.m_warehouse_id,';',string_agg(DISTINCT "left"(mr_line.kst_joborder::text, strpos(mr_line.kst_joborder::text, '::'::text) - 1), ':'::text),';',right(mp.upc,8),';',so.kst_ordertype,';',mr_line.c_bpartner_id,';',so.kst_lcdate::date,';CreatedAt:',now()::date) as id,
  127.     mr_line.poreference as line_id,
  128.     mp.m_product_id,
  129.     mr.m_warehouse_id,
  130.     mr_line.c_bpartner_id,
  131.     mr_line.QtyEntered,
  132.     so.kst_ordertype,
  133.     mr.m_requisition_id,
  134.     mr_line.m_requisitionline_id,
  135.     mpc.m_product_category_id,
  136.     mr.m_pricelist_id,
  137.     mr_line.c_currency_id,
  138.     so.kst_brand,
  139.     so.kst_season,
  140.     so.poreference,
  141.     0 as so_id,
  142.     mp.upc,
  143.     mr_line.datepromised
  144. from m_requisitionline as mr_line
  145. left join m_requisition as mr on mr_line.m_requisition_id = mr.m_requisition_id
  146. left join c_order as so on mr_line.poreference = so.poreference
  147. left join m_product as mp on mr_line.m_product_id = mp.m_product_id
  148. left join m_product_category as mpc on mp.m_product_category_id = mpc.m_product_category_id
  149. where so.C_DocTypeTarget_ID <> 1000082 and mr_line.isactive  = 'Y' and mp.kst_isila = 'N'
  150. and so.kst_lcdate = p_lc_date and mpc.m_product_category_id = p_product_category
  151. group by mp.m_product_id,
  152.     mr.m_requisition_id,
  153.     mr_line.m_requisitionline_id,
  154.     so.c_order_id,
  155.     mpc.m_product_category_id;
  156. raise NOTICE 'Populate Data Auto Allocate From PO is Completed';
  157. end;
  158. $function$
  159. ;
  160.  
  161. select * from rma_populate_fabric
  162. -- adempiere.rma_populate_fabric source
  163.  
  164. CREATE OR REPLACE VIEW adempiere.rma_populate_fabric
  165. AS SELECT (((((((po.m_warehouse_id || ';'::text) || po.upc::text) || ';'::text) || po.kst_ordertype::text) || ';'::text) ||
  166.         CASE
  167.             WHEN (( SELECT so.c_country_id
  168.                FROM c_order so
  169.               WHERE so.c_order_id = po.so_id
  170.              LIMIT 1)) = ANY (ARRAY[153::numeric, 216::numeric]) THEN 'JPCN'::text
  171.             ELSE 'NonJPCN'::text
  172.         END) || ';'::text) || po.c_bpartner_id AS id,
  173.     (((((((((po.m_warehouse_id || ';'::text) || po.upc::text) || ';'::text) || po.kst_ordertype::text) || ';'::text) ||
  174.         CASE
  175.             WHEN (( SELECT so.c_country_id
  176.                FROM c_order so
  177.               WHERE so.c_order_id = po.so_id
  178.              LIMIT 1)) = ANY (ARRAY[153::numeric, 216::numeric]) THEN 'JPCN'::text
  179.             ELSE 'NonJPCN'::text
  180.         END) || ';'::text) || po.c_bpartner_id) || ';'::text) || po.m_product_id::text AS lineid,
  181.     po.m_product_id,
  182.     po.upc,
  183.     po.m_warehouse_id,
  184.     po.c_bpartner_id,
  185.     po.kst_ordertype,
  186.     po.m_product_category,
  187.     po.m_pricelist_id,
  188.     po.c_currency_id,
  189.     po.kst_brand,
  190.     max(po.kst_season::text) AS kst_season,
  191.         CASE
  192.             WHEN (( SELECT so.c_country_id
  193.                FROM c_order so
  194.               WHERE so.c_order_id = po.so_id
  195.              LIMIT 1)) = ANY (ARRAY[153::numeric, 216::numeric]) THEN 'JPCN'::text
  196.             ELSE 'NonJPCN'::text
  197.         END AS c_country_id,
  198.     sum(po.qtyneed) AS qtyneed,
  199.     po.m_requisitionline_id
  200.    FROM tpb_populate_auto_po po
  201.   GROUP BY po.m_product_id, po.m_warehouse_id, po.c_bpartner_id, po.kst_ordertype, po.m_product_category, po.m_pricelist_id, po.c_currency_id, po.kst_brand, (
  202.         CASE
  203.             WHEN (( SELECT so.c_country_id
  204.                FROM c_order so
  205.               WHERE so.c_order_id = po.so_id
  206.              LIMIT 1)) = ANY (ARRAY[153::numeric, 216::numeric]) THEN 'JPCN'::text
  207.             ELSE 'NonJPCN'::text
  208.         END), po.upc, ((((((((po.m_warehouse_id || ';'::text) || po.upc::text) || ';'::text) || po.kst_ordertype::text) || ';'::text) ||
  209.         CASE
  210.             WHEN (( SELECT so.c_country_id
  211.                FROM c_order so
  212.               WHERE so.c_order_id = po.so_id
  213.              LIMIT 1)) = ANY (ARRAY[153::numeric, 216::numeric]) THEN 'JPCN'::text
  214.             ELSE 'NonJPCN'::text
  215.         END) || ';'::text) || po.c_bpartner_id), ((((((((((po.m_warehouse_id || ';'::text) || po.upc::text) || ';'::text) || po.kst_ordertype::text) || ';'::text) ||
  216.         CASE
  217.             WHEN (( SELECT so.c_country_id
  218.                FROM c_order so
  219.               WHERE so.c_order_id = po.so_id
  220.              LIMIT 1)) = ANY (ARRAY[153::numeric, 216::numeric]) THEN 'JPCN'::text
  221.             ELSE 'NonJPCN'::text
  222.         END) || ';'::text) || po.c_bpartner_id) || ';'::text) || po.m_product_id::text), po.m_requisitionline_id
  223.   ORDER BY ((((((((po.m_warehouse_id || ';'::text) || po.upc::text) || ';'::text) || po.kst_ordertype::text) || ';'::text) ||
  224.         CASE
  225.             WHEN (( SELECT so.c_country_id
  226.                FROM c_order so
  227.               WHERE so.c_order_id = po.so_id
  228.              LIMIT 1)) = ANY (ARRAY[153::numeric, 216::numeric]) THEN 'JPCN'::text
  229.             ELSE 'NonJPCN'::text
  230.         END) || ';'::text) || po.c_bpartner_id);
  231.  
  232.        
  233.        
  234. select * from m_movement mm where m_movement_id =2033109
  235.  
  236. update m_movement set created = '2020-01-07'
  237. where m_movement_id =2033109
  238.  
  239.  
  240. select * from tpb_mapping_po tmp
  241.  
  242. select name,m_product_category_id from m_product_category mpc where lower("name")in (
  243. 'heat transfer',
  244. 'zipper'
  245.  )
  246.        
  247.  
  248. select tpb_mapping_po_id,* from tpb_mapping_po tmp
  249.  -- adempiere.tpb_populate_auto_po definition
  250.  
  251. -- adempiere.tpb_populate_auto_po definition
  252.  
  253. -- Drop table
  254.  
  255. -- DROP TABLE adempiere.tpb_populate_auto_po CASCADE;
  256.  
  257.  
  258. CREATE TABLE adempiere.tpb_populate_auto_po (
  259.     id varchar(255) NULL,
  260.     lineid varchar(255) NULL,
  261.     m_product_id varchar(75) NULL,
  262.     m_warehouse_id numeric NULL,
  263.     c_bpartner_id numeric NULL,
  264.     qtyneed numeric NULL,
  265.     kst_ordertype varchar(50) NULL,
  266.     m_requisition_id numeric NULL,
  267.     m_requisitionline_id numeric NULL,
  268.     m_product_category numeric NULL,
  269.     m_pricelist_id numeric NULL,
  270.     c_currency_id numeric NULL,
  271.     kst_brand varchar(10) NULL,
  272.     kst_season varchar(10) NULL,
  273.     poreference varchar(50) NULL,
  274.     so_id numeric NULL,
  275.     upc varchar(100) null,
  276.     mrd_date timestamp null
  277. );
  278.  
  279. select datepromised,* from c_orderline co limit 1
  280.  
  281. -- adempiere.tpb_mapping_po definition
  282.  
  283. -- Drop table
  284.  
  285. -- DROP TABLE adempiere.tpb_mapping_po;
  286.  
  287. CREATE TABLE adempiere.tpb_mapping_po (
  288.     tpb_mapping_po_id numeric(10) NOT NULL,
  289.     tpb_mapping_po_uu varchar(36) NULL DEFAULT NULL::character varying,
  290.     ad_client_id numeric(10) NULL DEFAULT NULL::numeric,
  291.     ad_org_id numeric(10) NULL DEFAULT NULL::numeric,
  292.     created timestamp NULL DEFAULT statement_timestamp(),
  293.     createdby numeric(10) NULL DEFAULT NULL::numeric,
  294.     isactive bpchar(1) NULL DEFAULT 'Y'::bpchar,
  295.     processed bpchar(1) NULL DEFAULT NULL::bpchar,
  296.     processing bpchar(1) NULL DEFAULT NULL::bpchar,
  297.     m_product_category_id numeric(10) NULL DEFAULT NULL::numeric,
  298.     m_warehouse_id numeric(10) NULL DEFAULT NULL::numeric,
  299.     c_doctypetarget_id numeric(10) NULL DEFAULT NULL::numeric,
  300.     tpb_allocation_type varchar(255) NULL DEFAULT NULL::character varying,
  301.     kst_ordertype varchar(50) NULL DEFAULT NULL::character varying,
  302.     updated timestamp NULL DEFAULT statement_timestamp(),
  303.     updatedby numeric(10) NULL DEFAULT NULL::numeric,
  304.     tpb_allocation_type_grup varchar(255) NULL DEFAULT NULL::character varying,
  305.     tpb_mapping_view_name varchar(40) NULL DEFAULT NULL::character varying,
  306.     CONSTRAINT tpb_mapping_po_isactive_check CHECK ((isactive = ANY (ARRAY['Y'::bpchar, 'N'::bpchar]))),
  307.     CONSTRAINT tpb_mapping_po_key PRIMARY KEY (tpb_mapping_po_id),
  308.     CONSTRAINT tpb_mapping_po_processed_check CHECK ((processed = ANY (ARRAY['Y'::bpchar, 'N'::bpchar]))),
  309.     CONSTRAINT tpb_mapping_po_uu_idx UNIQUE (tpb_mapping_po_uu)
  310. );
  311.  
  312.  
  313. -- adempiere.tpb_mapping_po foreign keys
  314.  
  315. ALTER TABLE adempiere.tpb_mapping_po ADD CONSTRAINT cdoctypetarget_tpbmappingpo FOREIGN KEY (c_doctypetarget_id) REFERENCES c_doctype(c_doctype_id) DEFERRABLE INITIALLY DEFERRED;
  316. ALTER TABLE adempiere.tpb_mapping_po ADD CONSTRAINT mapping_po_product_category_id FOREIGN KEY (m_product_category_id) REFERENCES m_product_category(m_product_category_id) DEFERRABLE INITIALLY DEFERRED;
  317. ALTER TABLE adempiere.tpb_mapping_po ADD CONSTRAINT mwarehouse_tpbmappingpo FOREIGN KEY (m_warehouse_id) REFERENCES m_warehouse(m_warehouse_id) DEFERRABLE INITIALLY DEFERRED;
  318.  
  319. INSERT INTO TPB_MAPPING_PO(tpb_mapping_po_id,ad_client_id,ad_org_id,createdby,isactive,processed,processing,m_product_category_id,m_warehouse_id,c_doctypetarget_id,tpb_allocation_type,kst_ordertype,updatedby,tpb_allocation_type_grup) VALUES(1000000,1000000,1000000,1002292,'Y','N','N',1000003,1000001,1000112,'alloc_5','MTF',1002292,'FABRIC');
  320.  
  321. select * from tpb_populate_auto_po
  322.  
  323. select m_pricelist_id,* from tpb_populate_auto_po tpap where m_product_id = '1469339'
  324.  
  325. select * from m_pricelist mp where m_pricelist_id =1000003
  326.  
  327. select * from m_requisitionline mr where m_requisitionline_id =3302412
Add Comment
Please, Sign In to add comment