Advertisement
dchrissandy

Untitled

Oct 31st, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.78 KB | None | 0 0
  1. CREATE OR REPLACE FUNCTION r_report_group_brand_qty_hpp(
  2. character varying,
  3. bigint,
  4. bigint,
  5. bigint,
  6. character varying,
  7. character varying,
  8. character varying)
  9. RETURNS SETOF refcursor AS
  10. $BODY$
  11. DECLARE
  12. pRefHeader REFCURSOR := 'refHeader';
  13. pRefColumn REFCURSOR := 'refColumn';
  14. pRefDetail REFCURSOR := 'refDetail';
  15. pSessionId ALIAS FOR $1;
  16. pTenantId ALIAS FOR $2;
  17. pOuId ALIAS FOR $3;
  18. pWarehouseId ALIAS FOR $4;
  19. pStockDate ALIAS FOR $5;
  20. pDatetime ALIAS FOR $6;
  21. pGroupBrandCodeOrName ALIAS FOR $7;
  22.  
  23. vDocTypeDeliveryOrder bigint;
  24. vDocTypeDeliveryOrderReceipt bigint;
  25. vDocTypePosShop bigint;
  26. vDocTypePosShopInShop bigint;
  27. vDocTypePosVoidShop bigint;
  28. vDocTypePosVoidShopInShop bigint;
  29. vFilterOu text;
  30. vFilterWarehouse text;
  31. vFilterGroupBrandCodeOrName text;
  32. vFilterGroupBrandExcFJS text;
  33.  
  34. vEmptyId bigint;
  35. vEmptyString text;
  36. vMonthRange bigint;
  37. vOuCodeName text;
  38. vWarehouseCodeName text;
  39. vCtgrCode text:='ALL';
  40. vSubCtgrCode text:='ALL';
  41.  
  42. vWarehouse RECORD;
  43. vColumName text[];
  44. vColumNameForCoalesce text := '';
  45. vColumNameWithType text := '';
  46.  
  47. vLatestInvLedgerClosingDate character varying := '';
  48. vNextYearMonth character varying := '';
  49. vStartDateBalanceStock character varying := '';
  50. vLedgerCodeInv character varying := 'INV';
  51.  
  52. BEGIN
  53. vDocTypeDeliveryOrder := 311;
  54. vDocTypeDeliveryOrderReceipt := 526;
  55. vDocTypePosShop := 401;
  56. vDocTypePosShopInShop := 403;
  57. vDocTypePosVoidShop := 405;
  58. vDocTypePosVoidShopInShop := 406;
  59. vFilterOu := '';
  60. vFilterWarehouse := '';
  61. vFilterGroupBrandCodeOrName := '';
  62. vEmptyId := -99;
  63. vEmptyString := '';
  64. vOuCodeName := 'ALL';
  65. vWarehouseCodeName := 'ALL';
  66.  
  67.  
  68. DELETE FROM tt_filter_warehouse WHERE session_id = pSessionId;
  69. DELETE FROM tt_product_for_group_brand_qty_hpp WHERE session_id = pSessionId;
  70. --
  71. -- SELECT (DATE_PART('year', to_date(pYearMonthTo, 'YYYYMM')) - DATE_PART('year', to_date(pYearMonthFrom, 'YYYYMM'))) * 12 +
  72. -- (DATE_PART('month', to_date(pYearMonthTo, 'YYYYMM')) - DATE_PART('month', to_date(pYearMonthFrom, 'YYYYMM'))) + 1 INTO vMonthRange;
  73. --
  74. -- RAISE NOTICE '% vMonthRange', vMonthRange;
  75.  
  76. /* get last closing ledger date */
  77. SELECT MAX(date_year_month)
  78. FROM m_admin_process_ledger
  79. WHERE tenant_id = pTenantId
  80. AND ledger_code = vLedgerCodeInv
  81. AND date_year_month < SUBSTRING(pStockDate,1,6)
  82. AND status_ledger = '1' INTO vLatestInvLedgerClosingDate;
  83. RAISE NOTICE 'vLatestInvLedgerClosingDate : %',vLatestInvLedgerClosingDate;
  84.  
  85. SELECT TO_CHAR(TO_DATE(vLatestInvLedgerClosingDate,'YYYYMM') + interval '1 Month','YYYYMM') INTO vNextYearMonth;
  86. vStartDateBalanceStock = vNextYearMonth || '01';
  87. RAISE NOTICE 'get vStartDateBalanceStock : %',vStartDateBalanceStock;
  88.  
  89. raise notice 'vNextYearMonth %', vNextYearMonth;
  90. raise notice 'vStartDateBalanceStock %', vStartDateBalanceStock;
  91.  
  92. -- filter ou id
  93. IF(pOuId <> vEmptyId) THEN
  94. -- vFilterOu := ' AND A.ou_id = '|| pOuId || '';
  95.  
  96. SELECT ou_code||' - '||ou_name INTO vOuCodeName
  97. FROM t_ou
  98. WHERE ou_id = pOuId;
  99. END IF;
  100.  
  101. -- filter warehouse id
  102. IF(pWarehouseId <> vEmptyId) THEN
  103. vFilterWarehouse := ' AND A.warehouse_id = '|| pWarehouseId || '';
  104.  
  105. SELECT warehouse_code||' - '||warehouse_name INTO vWarehouseCodeName
  106. FROM m_warehouse
  107. WHERE warehouse_id = pWarehouseId;
  108. END IF;
  109.  
  110. -- filter product code/name
  111. IF(pGroupBrandCodeOrName <> vEmptyString) THEN
  112. vFilterGroupBrandCodeOrName := ' AND (G.group_brand_code ILIKE ''%'|| pGroupBrandCodeOrName || '%'' OR G.group_brand_name ILIKE ''%' || pGroupBrandCodeOrName || '%'')';
  113. END IF;
  114.  
  115. RAISE NOTICE '% vFilterOu', vFilterOu;
  116. RAISE NOTICE '% vFilterWarehouse', vFilterWarehouse;
  117.  
  118.  
  119. /**
  120. * bagian query:
  121. * 1. mendapatkan list data warehouse
  122. * 2. looping warehouse untuk penamaan kolom dan data dalam array -> hanya untuk digunakan dalam crosstab
  123. * 3. mendapatkan sumber data
  124. * 3.1 mendapatkan data qty dari begining balance tgl 1 -> identifier 1
  125. * 3.2 mendapatkan data qty dari tanggal 1 sampai stock date -> identifier 2
  126. * 3.3 mengabungkan data qty menjadi 1 identifier -> identifier 3
  127. * 3.4 mendapatkan data total qty per group brand produk -> identifier 4
  128. * 3.5 mendapatkan data hpp dari monthly cogs -> identifier 5
  129. * 3.6 mendapatkan data produk yg belum ada hpp dari montlhy cogs -> identifier 11
  130. * 3.7 mendapatkan data rg id terakhir per produk untuk produk yg belum ada hpp dari montlhy cogs ->identifier 12
  131. * 3.8 mendapatkan data hpp produk yg belum ada hpp dari monthly cogs berdasarkan data rg id terakhir -> identifier 5
  132. * 3.9 menghitung data qty * hpp per produk -> identifier 6
  133. * 3.10 menghitung data hpp per group brand -> identifier 7
  134. * 4. open pRefHeader -> data untuk header pada template seperti ou dari mana, filter apa saja, dkk
  135. * 5. open pRefColumn -> data untuk dynamic gudang digunakan saat looping ke kanan gudang pada template
  136. * 6. oper pRefDetail -> data crosstab untuk isi qty dan amount(hpp) data pada template
  137. */
  138.  
  139. -- 1. mendapatkan list data warehouse
  140. EXECUTE'
  141. INSERT INTO tt_filter_warehouse(
  142. session_id, warehouse_id, warehouse_code, warehouse_name
  143. )
  144. SELECT $2, B.warehouse_id, B.warehouse_code, B.warehouse_name
  145. FROM m_warehouse_ou A
  146. JOIN m_warehouse B ON A.warehouse_id = B.warehouse_id
  147. WHERE B.tenant_id = $1 '||
  148. vFilterWarehouse ||'
  149. 'USING pTenantId, pSessionId;
  150.  
  151. -- LOOPING UNTUK COLUMN
  152. -- looping warehouse untuk penamaan kolom dan data dalam array -> hanya untuk digunakan dalam crosstab
  153. FOR vWarehouse IN
  154. SELECT warehouse_code
  155. FROM tt_filter_warehouse
  156. WHERE session_id = pSessionId
  157. ORDER BY warehouse_code
  158. LOOP
  159. vColumName := array_append(vColumName,CONCAT(vWarehouse.warehouse_code,'_qty')); -- mencatat nama column average sales saja (dalam bentuk array)
  160. vColumName := array_append(vColumName,CONCAT(vWarehouse.warehouse_code,'_qty_amount')); -- mencatat nama column average sales saja (dalam bentuk array)
  161. vColumNameWithType := CONCAT(vColumNameWithType,',"',vWarehouse.warehouse_code,'_qty','" numeric'); -- mencatat nama column beserta tipe data nya
  162. vColumNameWithType := CONCAT(vColumNameWithType,',"',vWarehouse.warehouse_code,'_qty_amount','" numeric'); -- mencatat nama column beserta tipe data nya
  163. vColumNameForCoalesce := CONCAT(vColumNameForCoalesce,', COALESCE("',vWarehouse.warehouse_code,'_qty','", 0) AS "',vWarehouse.warehouse_code,'_qty"');
  164. vColumNameForCoalesce := CONCAT(vColumNameForCoalesce,', COALESCE("',vWarehouse.warehouse_code,'_qty_amount','", 0) AS "',vWarehouse.warehouse_code,'_qty_amount"');
  165.  
  166. END LOOP;
  167.  
  168. raise notice 'vColumName %', vColumName;
  169. raise notice 'vColumNameWithType %', vColumNameWithType;
  170. raise notice 'vColumNameForCoalesce %', vColumNameForCoalesce;
  171.  
  172. -- 3. mendapatkan sumber data
  173. raise notice '--==0==--';
  174. -- 3.1 mendapatkan data qty dari begining balance tgl 1 -> identifier 1
  175. EXECUTE'
  176. INSERT INTO tt_product_for_group_brand_qty_hpp(
  177. session_id,
  178. product_id, product_code, product_name,
  179. group_brand_id, group_brand_code, group_brand_name,
  180. code, qty_or_amount, identifier
  181. )
  182. SELECT $3,
  183. D.product_id, D.product_code, D.product_name,
  184. G.group_brand_id, G.group_brand_code, G.group_brand_name,
  185. BB.warehouse_code||''_qty'' AS code,
  186. SUM(A.qty) AS qty, 1
  187. FROM in_summary_monthly_qty A
  188. INNER JOIN m_warehouse_ou B ON A.warehouse_id=B.warehouse_id
  189. INNER JOIN m_warehouse BB ON B.warehouse_id = BB.warehouse_id
  190. INNER JOIN m_ou_structure C ON B.ou_id = C.ou_id
  191. INNER JOIN m_product D ON D.product_id = A.product_id
  192. INNER JOIN m_uom E ON D.base_uom_id = E.uom_id
  193. INNER JOIN m_product_custom_for_sasa F ON D.product_id = F.product_id
  194. INNER JOIN m_group_brand G ON F.group_brand_id = G.group_brand_id
  195. WHERE A.tenant_id = $1'||
  196. vFilterWarehouse ||
  197. vFilterGroupBrandCodeOrName ||'
  198. AND A.date_year_month = $2
  199. GROUP BY BB.warehouse_code, D.product_id, D.product_code, D.product_name,
  200. G.group_brand_id, G.group_brand_code, G.group_brand_name'
  201. USING pTenantId, vNextYearMonth, pSessionId;
  202. raise notice '--==1==--';
  203.  
  204. -- 3.2 mendapatkan data qty dari tanggal 1 sampai stock date -> identifier 2
  205. EXECUTE '
  206. INSERT INTO tt_product_for_group_brand_qty_hpp(
  207. session_id,
  208. product_id, product_code, product_name,
  209. group_brand_id, group_brand_code, group_brand_name,
  210. code, qty_or_amount, identifier
  211. )
  212. SELECT $1,
  213. D.product_id, D.product_code, D.product_name,
  214. G.group_brand_id, G.group_brand_code, G.group_brand_name,
  215. C.warehouse_code||''_qty'' AS code,
  216. SUM(AA.qty) AS qty, 2
  217. FROM in_log_product_balance_stock AA
  218. INNER JOIN m_warehouse_ou A ON A.warehouse_id = AA.warehouse_id
  219. INNER JOIN t_ou B ON B.ou_id = A.ou_id
  220. INNER JOIN m_warehouse C ON C.warehouse_id = A.warehouse_id
  221. INNER JOIN m_product D ON D.product_id = AA.product_id
  222. INNER JOIN m_uom E ON D.base_uom_id = E.uom_id
  223. INNER JOIN m_product_custom_for_sasa F ON D.product_id = F.product_id
  224. INNER JOIN m_group_brand G ON F.group_brand_id = G.group_brand_id
  225. WHERE AA.tenant_id = $2
  226. AND AA.doc_date BETWEEN $3 AND $4 '||
  227. vFilterWarehouse ||
  228. vFilterGroupBrandCodeOrName ||'
  229. GROUP BY C.warehouse_code, D.product_id, D.product_code, D.product_name,
  230. G.group_brand_id, G.group_brand_code, G.group_brand_name'
  231. USING pSessionId, pTenantId, vStartDateBalanceStock, pStockDate;
  232. raise notice '--==2==--';
  233.  
  234. -- 3.3 mengabungkan data qty menjadi 1 identifier -> identifier 3
  235. INSERT INTO tt_product_for_group_brand_qty_hpp(
  236. session_id,
  237. product_id, product_code, product_name,
  238. group_brand_id, group_brand_code, group_brand_name,
  239. code, qty_or_amount, identifier
  240. )
  241. SELECT pSessionId,
  242. A.product_id, A.product_code, A.product_name,
  243. A.group_brand_id, A.group_brand_code, A.group_brand_name,
  244. A.code As code, SUM(A.qty_or_amount), 3
  245. FROM tt_product_for_group_brand_qty_hpp A
  246. WHERE A.session_id = pSessionId
  247. AND A.identifier IN ( 1, 2 ) -- beginning balance stock, stock from beginning balance to date
  248. GROUP BY A.product_id, A.product_code, A.product_name,
  249. A.group_brand_id, A.group_brand_code, A.group_brand_name, A.code;
  250. raise notice '--==3==--';
  251.  
  252. -- hapus redundant data
  253. DELETE FROM tt_product_for_group_brand_qty_hpp WHERE session_id = pSessionId AND identifier = 1;
  254. DELETE FROM tt_product_for_group_brand_qty_hpp WHERE session_id = pSessionId AND identifier = 2;
  255.  
  256. -- 3.4 mendapatkan data total qty per group brand produk -> identifier 4
  257. INSERT INTO tt_product_for_group_brand_qty_hpp(
  258. session_id,
  259. group_brand_id, group_brand_code, group_brand_name,
  260. code, qty_or_amount, identifier
  261. )
  262. SELECT pSessionId,
  263. A.group_brand_id, A.group_brand_code, A.group_brand_name,
  264. A.code As code, SUM(A.qty_or_amount), 4
  265. FROM tt_product_for_group_brand_qty_hpp A
  266. WHERE A.session_id = pSessionId
  267. AND A.identifier = 3 -- from total stock per product
  268. GROUP BY A.group_brand_id, A.group_brand_code, A.group_brand_name, A.code;
  269.  
  270. -- 3.5 mendapatkan data hpp dari monthly cogs -> identifier 5
  271. EXECUTE'
  272. INSERT INTO tt_product_for_group_brand_qty_hpp(
  273. session_id,
  274. product_id, product_code, product_name,
  275. group_brand_id, group_brand_code, group_brand_name,
  276. code, qty_or_amount, identifier
  277. )
  278. SELECT $4,
  279. D.product_id, D.product_code, D.product_name,
  280. G.group_brand_id, G.group_brand_code, G.group_brand_name,
  281. ''hpp_average'' AS code, A.avg_price AS hpp_avg_price, 5
  282. FROM in_summary_monthly_cogs A
  283. INNER JOIN m_product D ON A.product_id = D.product_id
  284. INNER JOIN m_uom E ON D.base_uom_id = E.uom_id
  285. INNER JOIN m_product_custom_for_sasa F ON D.product_id = F.product_id
  286. INNER JOIN m_group_brand G ON F.group_brand_id = G.group_brand_id
  287. WHERE A.tenant_id = $1'||
  288. vFilterGroupBrandCodeOrName ||'
  289. AND A.date_year_month = $3 '
  290. USING pTenantId, pOuId, vLatestInvLedgerClosingDate, pSessionId;
  291. raise notice '--==5.1==--';
  292.  
  293. -- 3.6 mendapatkan data produk yg belum ada hpp dari montlhy cogs -> identifier 11
  294. INSERT INTO tt_product_for_group_brand_qty_hpp(
  295. session_id,
  296. product_id, product_code, product_name,
  297. group_brand_id, group_brand_code, group_brand_name,
  298. code, identifier
  299. )
  300. SELECT pSessionId,
  301. A.product_id, A.product_code, A.product_name,
  302. A.group_brand_id, A.group_brand_code, A.group_brand_name,
  303. 'product_wo_hpp', 11
  304. FROM (
  305. SELECT A.product_id, A.product_code, A.product_name,
  306. A.group_brand_id, A.group_brand_code, A.group_brand_name
  307. FROM tt_product_for_group_brand_qty_hpp A
  308. WHERE A.session_id = pSessionId
  309. AND A.identifier = 3 -- total qty per product
  310. GROUP BY A.product_id, A.product_code, A.product_name,
  311. A.group_brand_id, A.group_brand_code, A.group_brand_name
  312. ) A
  313. WHERE NOT EXISTS (
  314. SELECT 1
  315. FROM (
  316. SELECT product_id
  317. FROM tt_product_for_group_brand_qty_hpp C
  318. WHERE session_id = pSessionId
  319. AND identifier = 5 -- data hpp
  320. GROUP BY product_id
  321. ) AA
  322. WHERE A.product_id = AA.product_id
  323. );
  324. raise notice '--==5.2==--';
  325.  
  326. -- 3.7 mendapatkan data rg id terakhir per produk untuk produk yg belum ada hpp dari montlhy cogs ->identifier 12
  327. INSERT INTO tt_product_for_group_brand_qty_hpp(
  328. session_id,
  329. product_id, product_code, product_name,
  330. group_brand_id, group_brand_code, group_brand_name,
  331. code, identifier, rg_id
  332. )
  333. SELECT pSessionId,
  334. A.product_id, A.product_code, A.product_name,
  335. A.group_brand_id, a.group_brand_code, A.group_brand_name,
  336. 'last_rg_data', 12,
  337. MAX(C.receive_goods_id) AS id_penerimaan_terakhir
  338. FROM tt_product_for_group_brand_qty_hpp A
  339. JOIN pu_receive_goods_item B ON A.product_id = B.product_id
  340. JOIN pu_receive_goods C ON B.receive_goods_id = C.receive_goods_id AND C.status_doc = 'R'
  341. WHERE A.session_id = pSessionId
  342. AND A.identifier = 11
  343. GROUP BY A.product_id, A.product_code, A.product_name,
  344. A.group_brand_id, a.group_brand_code, A.group_brand_name;
  345. raise notice '--==5.3==--';
  346.  
  347. -- 3.8 mendapatkan data hpp produk yg belum ada hpp dari monthly cogs berdasarkan data rg id terakhir -> identifier 5
  348. INSERT INTO tt_product_for_group_brand_qty_hpp(
  349. session_id,
  350. product_id, product_code, product_name,
  351. group_brand_id, group_brand_code, group_brand_name,
  352. code, qty_or_amount, identifier
  353. )
  354. SELECT pSessionId,
  355. A.product_id, A.product_code, A.product_name,
  356. A.group_brand_id, a.group_brand_code, A.group_brand_name,
  357. 'hpp_average', C.price_po, 5
  358. FROM tt_product_for_group_brand_qty_hpp A
  359. JOIN pu_receive_goods_item B ON A.product_id = B.product_id
  360. JOIN pu_po_balance_invoice C ON C.ref_id = B.receive_goods_id
  361. AND C.ref_item_id = B.receive_goods_item_id
  362. AND C.ref_doc_type_id = 111 -- RG
  363. AND A.rg_id = C.ref_id
  364. WHERE A.session_id = pSessionId
  365. AND A.identifier = 12; -- HARUS DARI id_penerimaan terakhir
  366. raise notice '--==5.4==--';
  367.  
  368. DELETE FROM tt_product_for_group_brand_qty_hpp WHERE session_id = pSessionId AND identifier = 11;
  369. DELETE FROM tt_product_for_group_brand_qty_hpp WHERE session_id = pSessionId AND identifier = 12;
  370.  
  371. -- 3.9 menghitung data qty * hpp per produk -> identifier 6
  372. INSERT INTO tt_product_for_group_brand_qty_hpp(
  373. session_id,
  374. product_id, product_code, product_name,
  375. group_brand_id, group_brand_code, group_brand_name,
  376. code, qty_or_amount, identifier
  377. )
  378. SELECT pSessionId,
  379. A.product_id, A.product_code, A.product_name,
  380. A.group_brand_id, A.group_brand_code, A.group_brand_name,
  381. A.code||'_amount' As code, A.qty_or_amount * COALESCE(B.qty_or_amount,0), 6
  382. FROM tt_product_for_group_brand_qty_hpp A
  383. LEFT JOIN tt_product_for_group_brand_qty_hpp B ON A.session_id = B.session_id AND A.product_id = B.product_id AND B.identifier = 5 -- data hpp satuan per product
  384. WHERE A.session_id = pSessionId
  385. AND A.identifier = 3; -- data total qty per product
  386. raise notice '--==6==--';
  387.  
  388. -- hapus redundant data
  389. DELETE FROM tt_product_for_group_brand_qty_hpp WHERE session_id = pSessionId AND identifier = 3; -- data qty per product
  390. DELETE FROM tt_product_for_group_brand_qty_hpp WHERE session_id = pSessionId AND identifier = 5; -- data hpp satuan per product
  391.  
  392. -- 3.10 menghitung data hpp per group brand -> identifier 7
  393. INSERT INTO tt_product_for_group_brand_qty_hpp(
  394. session_id,
  395. group_brand_id, group_brand_code, group_brand_name,
  396. code, qty_or_amount, identifier
  397. )
  398. SELECT pSessionId,
  399. A.group_brand_id, A.group_brand_code, A.group_brand_name,
  400. A.code as code, SUM(A.qty_or_amount), 7
  401. FROM tt_product_for_group_brand_qty_hpp A
  402. WHERE A.session_id = pSessionId
  403. AND A.identifier = 6 -- data hpp amount per product
  404. GROUP BY A.group_brand_id, A.group_brand_code, A.group_brand_name, A.code;
  405. raise notice '--==7==--';
  406.  
  407. -- hapus redundant data
  408. DELETE FROM tt_product_for_group_brand_qty_hpp WHERE session_id = pSessionId AND identifier = 6; -- data hpp amount per product;
  409. -- DONE insert sumber data --
  410.  
  411. DELETE FROM tt_product_for_group_brand_qty_hpp WHERE session_id = pSessionId AND group_brand_code = 'FJS'; -- hapus data group brand FJS agar tidak tampil (jasa)
  412.  
  413.  
  414. -- 4. open pRefHeader -> data untuk header pada template seperti ou dari mana, filter apa saja, dkk
  415. OPEN pRefHeader FOR
  416. SELECT CASE WHEN pOuId = vEmptyId THEN -99 ELSE pOuId END AS ou_id, vOuCodeName AS ou_code_name,
  417. CASE WHEN pWarehouseId = vEmptyId THEN -99 ELSE pWarehouseId END AS warehouse_id, vWarehouseCodeName AS warehouse_code_name,
  418. pDatetime AS datetime,
  419. pStockDate AS stock_date;
  420. RETURN NEXT pRefHeader;
  421.  
  422. -- 5. open pRefColumn -> data untuk dynamic gudang digunakan saat looping ke kanan gudang pada template
  423. OPEN pRefColumn FOR
  424. SELECT warehouse_id, 'qty' AS header, warehouse_code, warehouse_name, warehouse_code||'_qty' AS code
  425. FROM tt_filter_warehouse A
  426. WHERE A.session_id = pSessionId
  427. UNION
  428. SELECT warehouse_id, 'amount' AS header, warehouse_code, warehouse_name, warehouse_code||'_qty_amount' AS code
  429. FROM tt_filter_warehouse A
  430. WHERE A.session_id = pSessionId
  431. ORDER BY warehouse_code, code;
  432. RETURN NEXT pRefColumn;
  433.  
  434. -- 6. oper pRefDetail -> data crosstab untuk isi qty dan amount(hpp) data pada template
  435. OPEN pRefDetail FOR
  436. EXECUTE'
  437. SELECT group_brand_code, group_brand_name '||
  438. vColumNameForCoalesce ||
  439. '
  440. FROM crosstab(
  441. ''
  442. SELECT group_brand_code, group_brand_name, code, qty_or_amount
  443. FROM tt_product_for_group_brand_qty_hpp
  444. WHERE session_id = '''''|| pSessionId ||'''''
  445. ORDER BY group_brand_code, group_brand_name, code desc
  446. '',$$SELECT unnest('''||vColumName::text||'''::text[])$$
  447. ) AS A ("group_brand_code" character varying, "group_brand_name" character varying
  448. '||vColumNameWithType||
  449. ' )' ;
  450. RETURN NEXT pRefDetail;
  451.  
  452. DELETE FROM tt_filter_warehouse WHERE session_id = pSessionId;
  453. DELETE FROM tt_product_for_group_brand_qty_hpp WHERE session_id = pSessionId;
  454. END;
  455. $BODY$
  456. LANGUAGE plpgsql VOLATILE
  457. COST 100
  458. ROWS 1000;
  459. /
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement