Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Adrian, June 25, 2018
- * Transfer data calculator_catalog_price dari WSC
- */
- CREATE OR REPLACE FUNCTION f_transfer_calculator_catalog_price(bigint, bigint, character varying)
- RETURNS bigint AS
- $BODY$
- DECLARE
- pTenantId alias for $1;
- pUserId alias for $2;
- pDatetime alias for $3;
- vDbName text;
- vDbUser text;
- vDbPassword text;
- vDbPort text;
- vDbHostAddr text;
- vCount bigint;
- vPrevId bigint;
- vMaxId bigint;
- BEGIN
- SELECT f_get_value_system_config_by_param_code(pTenantId, 'PALOMAWSC.DB.NAME')::text INTO vDbName;
- SELECT f_get_value_system_config_by_param_code(pTenantId, 'PALOMAWSC.DB.USER')::text INTO vDbUser;
- SELECT f_get_value_system_config_by_param_code(pTenantId, 'PALOMAWSC.DB.PASSWORD')::text INTO vDbPassword;
- SELECT f_get_value_system_config_by_param_code(pTenantId, 'PALOMAWSC.DB.PORT')::text INTO vDbPort;
- SELECT f_get_value_system_config_by_param_code(pTenantId, 'PALOMAWSC.DB.HOSTADDR')::text INTO vDbHostAddr;
- vCount := 0;
- /**
- * 1. Ambil id terakhir
- */
- SELECT last_calculator_catalog_price_id FROM tt_last_calculator_catalog_price WHERE tenant_id = pTenantId INTO vPrevId;
- vMaxId := vPrevId;
- /**
- * 2. Ambil data dari WSC, simpan jumlah datanya
- */
- WITH inserted_calculator_catalog_price AS (
- INSERT INTO sp_calculator_catalog_price(
- calculator_catalog_price_id, tenant_id, catalog_code, style_product_code,
- doc_type, merchant_code, status_pkp, brand_code, category_level_1,
- supplier_price, suggestion_retail_price, discount_member, discount_promo,
- margin_internal, margin_supplier, product_value, weight, length,
- width, height, fee_ds, royalty, suggested_ebitda, minimum_ebitda,
- opex_cost, catalog_cost, marketing_cost, bonus_member, fee_reseller,
- fee_tambahan_ds, fee_box_packaging, volume_parameter, faktor_harga_netto,
- faktor_harga_netto_excl_ppn, faktor_gross_profit, faktor_internal_cost,
- faktor_fee_ds, faktor_harga_netto_amount, faktor_harga_netto_excl_ppn_amount,
- faktor_gross_profit_amount, faktor_internal_cost_amount, faktor_fee_ds_amount,
- faktor_fee_ds_percentage, faktor_kinerja_ds_percentage, faktor_operasional_percentage,
- faktor_gross_profit_percentage, supplier_price_excl_ppn, ppn_in_amount,
- catalog_price_suggestion, catalog_price_zone_0, catalog_price_zone_1,
- catalog_price_zone_2, discount_member_amount, discount_member_amount_zone_0,
- discount_member_amount_zone_1, discount_member_amount_zone_2,
- member_price_zone_0, member_price_zone_1, member_price_zone_2,
- fee_ds_amount_zone_0, fee_ds_amount_zone_1, fee_ds_amount_zone_2,
- nett_price_amount_zone_0, nett_price_amount_zone_1, nett_price_amount_zone_2,
- nett_price_excl_ppn_amount_zone_0, nett_price_excl_ppn_amount_zone_1,
- nett_price_excl_ppn_amount_zone_2, ppn_out_amount_zone_0, ppn_out_amount_zone_1,
- ppn_out_amount_zone_2, product_value_amount_zone_0, product_value_amount_zone_1,
- product_value_amount_zone_2, fee_reseller_amount_zone_0, fee_reseller_amount_zone_1,
- fee_reseller_amount_zone_2, fee_tambahan_ds_amount_zone_0, fee_tambahan_ds_amount_zone_1,
- fee_tambahan_ds_amount_zone_2, bonus_member_amount_zone_0, bonus_member_amount_zone_1,
- bonus_member_amount_zone_2, total_volume, weight_kg, shipping_cost_zone_0,
- shipping_cost_zone_1, shipping_cost_zone_2, freight_cost_zone_0,
- freight_cost_zone_1, freight_cost_zone_2, opex_cost_zone_0, opex_cost_zone_1,
- opex_cost_zone_2, catalog_cost_zone_0, catalog_cost_zone_1, catalog_cost_zone_2,
- marketing_cost_zone_0, marketing_cost_zone_1, marketing_cost_zone_2,
- royalty_amount_zone_0, royalty_amount_zone_1, royalty_amount_zone_2,
- ebitda_amount_zone_0, ebitda_amount_zone_1, ebitda_amount_zone_2,
- ebitda_percentage_zone_0, ebitda_percentage_zone_1, ebitda_percentage_zone_2,
- flg_data_change, flg_calculate, create_datetime, create_user_id,
- update_datetime, update_user_id, version, flg_new_product, previous_product_value,
- previous_catalog_price_zone_0, previous_catalog_price_zone_1,
- previous_catalog_price_zone_2, previous_member_price_zone_0,
- previous_member_price_zone_1, previous_member_price_zone_2)
- SELECT A.calculator_catalog_price_id, A.tenant_id, A.catalog_code, A.style_product_code,
- A.doc_type, A.merchant_code, A.status_pkp, A.brand_code, A.category_level_1,
- A.supplier_price, A.suggestion_retail_price, A.discount_member, A.discount_promo,
- A.margin_internal, A.margin_supplier, A.product_value, A.weight, A.length,
- A.width, A.height, A.fee_ds, A.royalty, A.suggested_ebitda, A.minimum_ebitda,
- A.opex_cost, A.catalog_cost, A.marketing_cost, A.bonus_member, A.fee_reseller,
- A.fee_tambahan_ds, A.fee_box_packaging, A.volume_parameter, A.faktor_harga_netto,
- A.faktor_harga_netto_excl_ppn, A.faktor_gross_profit, A.faktor_internal_cost,
- A.faktor_fee_ds, A.faktor_harga_netto_amount, A.faktor_harga_netto_excl_ppn_amount,
- A.faktor_gross_profit_amount, A.faktor_internal_cost_amount, A.faktor_fee_ds_amount,
- A.faktor_fee_ds_percentage, A.faktor_kinerja_ds_percentage, A.faktor_operasional_percentage,
- A.faktor_gross_profit_percentage, A.supplier_price_excl_ppn, A.ppn_in_amount,
- A.catalog_price_suggestion, A.catalog_price_zone_0, A.catalog_price_zone_1,
- A.catalog_price_zone_2, A.discount_member_amount, A.discount_member_amount_zone_0,
- A.discount_member_amount_zone_1, A.discount_member_amount_zone_2,
- A.member_price_zone_0, A.member_price_zone_1, A.member_price_zone_2,
- A.fee_ds_amount_zone_0, A.fee_ds_amount_zone_1, A.fee_ds_amount_zone_2,
- A.nett_price_amount_zone_0, A.nett_price_amount_zone_1, A.nett_price_amount_zone_2,
- A.nett_price_excl_ppn_amount_zone_0, A.nett_price_excl_ppn_amount_zone_1,
- A.nett_price_excl_ppn_amount_zone_2, A.ppn_out_amount_zone_0, A.ppn_out_amount_zone_1,
- A.ppn_out_amount_zone_2, A.product_value_amount_zone_0, A.product_value_amount_zone_1,
- A.product_value_amount_zone_2, A.fee_reseller_amount_zone_0, A.fee_reseller_amount_zone_1,
- A.fee_reseller_amount_zone_2, A.fee_tambahan_ds_amount_zone_0, A.fee_tambahan_ds_amount_zone_1,
- A.fee_tambahan_ds_amount_zone_2, A.bonus_member_amount_zone_0, A.bonus_member_amount_zone_1,
- A.bonus_member_amount_zone_2, A.total_volume, A.weight_kg, A.shipping_cost_zone_0,
- A.shipping_cost_zone_1, A.shipping_cost_zone_2, A.freight_cost_zone_0,
- A.freight_cost_zone_1, A.freight_cost_zone_2, A.opex_cost_zone_0, opex_cost_zone_1,
- A.opex_cost_zone_2, A.catalog_cost_zone_0, A.catalog_cost_zone_1, A.catalog_cost_zone_2,
- A.marketing_cost_zone_0, A.marketing_cost_zone_1, A.marketing_cost_zone_2,
- A.royalty_amount_zone_0, A.royalty_amount_zone_1, A.royalty_amount_zone_2,
- A.ebitda_amount_zone_0, A.ebitda_amount_zone_1, A.ebitda_amount_zone_2,
- A.ebitda_percentage_zone_0, A.ebitda_percentage_zone_1, A.ebitda_percentage_zone_2,
- A.flg_data_change, A.flg_calculate, A.create_datetime, A.create_user_id,
- A.update_datetime, A.update_user_id, A.version, A.flg_new_product, A.previous_product_value,
- A.previous_catalog_price_zone_0, A.previous_catalog_price_zone_1,
- A.previous_catalog_price_zone_2, A.previous_member_price_zone_0,
- A.previous_member_price_zone_1, A.previous_member_price_zone_2
- FROM dblink(
- 'dbname='|| f_get_value_system_config_by_param_code(11, 'PALOMAWSC.DB.NAME')::text || '
- port='||f_get_value_system_config_by_param_code(11, 'PALOMAWSC.DB.PORT')::text||'
- hostaddr='||f_get_value_system_config_by_param_code(11, 'PALOMAWSC.DB.HOSTADDR')::text||'
- user='||f_get_value_system_config_by_param_code(11, 'PALOMAWSC.DB.USER')::text||'
- password='||f_get_value_system_config_by_param_code(11, 'PALOMAWSC.DB.PASSWORD')::text||''::text,
- 'SELECT calculator_catalog_price_id, tenant_id, catalog_code, style_product_code,
- doc_type, merchant_code, status_pkp, brand_code, category_level_1,
- supplier_price, suggestion_retail_price, discount_member, discount_promo,
- margin_internal, margin_supplier, product_value, weight, length,
- width, height, fee_ds, royalty, suggested_ebitda, minimum_ebitda,
- opex_cost, catalog_cost, marketing_cost, bonus_member, fee_reseller,
- fee_tambahan_ds, fee_box_packaging, volume_parameter, faktor_harga_netto,
- faktor_harga_netto_excl_ppn, faktor_gross_profit, faktor_internal_cost,
- faktor_fee_ds, faktor_harga_netto_amount, faktor_harga_netto_excl_ppn_amount,
- faktor_gross_profit_amount, faktor_internal_cost_amount, faktor_fee_ds_amount,
- faktor_fee_ds_percentage, faktor_kinerja_ds_percentage, faktor_operasional_percentage,
- faktor_gross_profit_percentage, supplier_price_excl_ppn, ppn_in_amount,
- catalog_price_suggestion, catalog_price_zone_0, catalog_price_zone_1,
- catalog_price_zone_2, discount_member_amount, discount_member_amount_zone_0,
- discount_member_amount_zone_1, discount_member_amount_zone_2,
- member_price_zone_0, member_price_zone_1, member_price_zone_2,
- fee_ds_amount_zone_0, fee_ds_amount_zone_1, fee_ds_amount_zone_2,
- nett_price_amount_zone_0, nett_price_amount_zone_1, nett_price_amount_zone_2,
- nett_price_excl_ppn_amount_zone_0, nett_price_excl_ppn_amount_zone_1,
- nett_price_excl_ppn_amount_zone_2, ppn_out_amount_zone_0, ppn_out_amount_zone_1,
- ppn_out_amount_zone_2, product_value_amount_zone_0, product_value_amount_zone_1,
- product_value_amount_zone_2, fee_reseller_amount_zone_0, fee_reseller_amount_zone_1,
- fee_reseller_amount_zone_2, fee_tambahan_ds_amount_zone_0, fee_tambahan_ds_amount_zone_1,
- fee_tambahan_ds_amount_zone_2, bonus_member_amount_zone_0, bonus_member_amount_zone_1,
- bonus_member_amount_zone_2, total_volume, weight_kg, shipping_cost_zone_0,
- shipping_cost_zone_1, shipping_cost_zone_2, freight_cost_zone_0,
- freight_cost_zone_1, freight_cost_zone_2, opex_cost_zone_0, opex_cost_zone_1,
- opex_cost_zone_2, catalog_cost_zone_0, catalog_cost_zone_1, catalog_cost_zone_2,
- marketing_cost_zone_0, marketing_cost_zone_1, marketing_cost_zone_2,
- royalty_amount_zone_0, royalty_amount_zone_1, royalty_amount_zone_2,
- ebitda_amount_zone_0, ebitda_amount_zone_1, ebitda_amount_zone_2,
- ebitda_percentage_zone_0, ebitda_percentage_zone_1, ebitda_percentage_zone_2,
- flg_data_change, flg_calculate, create_datetime, create_user_id,
- update_datetime, update_user_id, version, flg_new_product, previous_product_value,
- previous_catalog_price_zone_0, previous_catalog_price_zone_1,
- previous_catalog_price_zone_2, previous_member_price_zone_0,
- previous_member_price_zone_1, previous_member_price_zone_2
- FROM sp_calculator_catalog_price
- WHERE calculator_catalog_price_id > '||vPrevId||''::text ) AS A
- (
- calculator_catalog_price_id bigint,
- tenant_id bigint,
- catalog_code character varying(50),
- style_product_code character varying(20),
- doc_type character varying(10),
- merchant_code character varying(20),
- status_pkp character varying(1),
- brand_code character varying(20),
- category_level_1 character varying(20),
- supplier_price numeric(15,2),
- suggestion_retail_price numeric(15,2),
- discount_member numeric(7,2),
- discount_promo numeric(7,2),
- margin_internal numeric(7,2),
- margin_supplier numeric(7,2),
- product_value numeric(7,2),
- weight numeric(7,2),
- length numeric(7,2),
- width numeric(7,2),
- height numeric(7,2),
- fee_ds numeric(7,2),
- royalty numeric(7,2),
- suggested_ebitda numeric(7,2),
- minimum_ebitda numeric(7,2),
- opex_cost numeric(7,2),
- catalog_cost numeric(7,2),
- marketing_cost numeric(7,2),
- bonus_member numeric(7,2),
- fee_reseller numeric(7,2),
- fee_tambahan_ds numeric(7,2),
- fee_box_packaging numeric(7,2),
- volume_parameter numeric(7,2),
- faktor_harga_netto numeric,
- faktor_harga_netto_excl_ppn numeric,
- faktor_gross_profit numeric,
- faktor_internal_cost numeric,
- faktor_fee_ds numeric,
- faktor_harga_netto_amount numeric(15,2),
- faktor_harga_netto_excl_ppn_amount numeric(15,2),
- faktor_gross_profit_amount numeric(15,2),
- faktor_internal_cost_amount numeric(15,2),
- faktor_fee_ds_amount numeric(15,2),
- faktor_fee_ds_percentage numeric(7,2),
- faktor_kinerja_ds_percentage numeric(7,2),
- faktor_operasional_percentage numeric(7,2),
- faktor_gross_profit_percentage numeric(7,2),
- supplier_price_excl_ppn numeric(15,2),
- ppn_in_amount numeric(15,2),
- catalog_price_suggestion numeric(15,2),
- catalog_price_zone_0 numeric(15,2),
- catalog_price_zone_1 numeric(15,2),
- catalog_price_zone_2 numeric(15,2),
- discount_member_amount numeric(15,2),
- discount_member_amount_zone_0 numeric(15,2),
- discount_member_amount_zone_1 numeric(15,2),
- discount_member_amount_zone_2 numeric(15,2),
- member_price_zone_0 numeric(15,2),
- member_price_zone_1 numeric(15,2),
- member_price_zone_2 numeric(15,2),
- fee_ds_amount_zone_0 numeric(15,2),
- fee_ds_amount_zone_1 numeric(15,2),
- fee_ds_amount_zone_2 numeric(15,2),
- nett_price_amount_zone_0 numeric(15,2),
- nett_price_amount_zone_1 numeric(15,2),
- nett_price_amount_zone_2 numeric(15,2),
- nett_price_excl_ppn_amount_zone_0 numeric(15,2),
- nett_price_excl_ppn_amount_zone_1 numeric(15,2),
- nett_price_excl_ppn_amount_zone_2 numeric(15,2),
- ppn_out_amount_zone_0 numeric(15,2),
- ppn_out_amount_zone_1 numeric(15,2),
- ppn_out_amount_zone_2 numeric(15,2),
- product_value_amount_zone_0 numeric(15,2),
- product_value_amount_zone_1 numeric(15,2),
- product_value_amount_zone_2 numeric(15,2),
- fee_reseller_amount_zone_0 numeric(15,2),
- fee_reseller_amount_zone_1 numeric(15,2),
- fee_reseller_amount_zone_2 numeric(15,2),
- fee_tambahan_ds_amount_zone_0 numeric(15,2),
- fee_tambahan_ds_amount_zone_1 numeric(15,2),
- fee_tambahan_ds_amount_zone_2 numeric(15,2),
- bonus_member_amount_zone_0 numeric(15,2),
- bonus_member_amount_zone_1 numeric(15,2),
- bonus_member_amount_zone_2 numeric(15,2),
- total_volume numeric(7,2),
- weight_kg numeric(7,2),
- shipping_cost_zone_0 numeric(15,2),
- shipping_cost_zone_1 numeric(15,2),
- shipping_cost_zone_2 numeric(15,2),
- freight_cost_zone_0 numeric(15,2),
- freight_cost_zone_1 numeric(15,2),
- freight_cost_zone_2 numeric(15,2),
- opex_cost_zone_0 numeric(15,2),
- opex_cost_zone_1 numeric(15,2),
- opex_cost_zone_2 numeric(15,2),
- catalog_cost_zone_0 numeric(15,2),
- catalog_cost_zone_1 numeric(15,2),
- catalog_cost_zone_2 numeric(15,2),
- marketing_cost_zone_0 numeric(15,2),
- marketing_cost_zone_1 numeric(15,2),
- marketing_cost_zone_2 numeric(15,2),
- royalty_amount_zone_0 numeric(15,2),
- royalty_amount_zone_1 numeric(15,2),
- royalty_amount_zone_2 numeric(15,2),
- ebitda_amount_zone_0 numeric(15,2),
- ebitda_amount_zone_1 numeric(15,2),
- ebitda_amount_zone_2 numeric(15,2),
- ebitda_percentage_zone_0 numeric(7,2),
- ebitda_percentage_zone_1 numeric(7,2),
- ebitda_percentage_zone_2 numeric(7,2),
- flg_data_change character varying(14),
- flg_calculate character varying(14),
- create_datetime character varying(14),
- create_user_id bigint,
- update_datetime character varying(14),
- update_user_id bigint,
- version bigint,
- flg_new_product character varying(1),
- previous_product_value numeric(7,2),
- previous_catalog_price_zone_0 numeric(15,2),
- previous_catalog_price_zone_1 numeric(15,2),
- previous_catalog_price_zone_2 numeric(15,2),
- previous_member_price_zone_0 numeric(15,2),
- previous_member_price_zone_1 numeric(15,2),
- previous_member_price_zone_2 numeric(15,2)
- )
- RETURNING *
- )
- SELECT COUNT(1) FROM inserted_calculator_catalog_price INTO vCount;
- IF(vCount > 0) THEN
- SELECT MAX(calculator_catalog_price_id) FROM sp_calculator_catalog_price INTO vMaxId;
- /**
- * 3. Update id terakhir
- */
- UPDATE tt_last_calculator_catalog_price SET last_calculator_catalog_price_id = vMaxId WHERE tenant_id = pTenantId;
- /**
- * 4. Update nilai sequence terakhir
- */
- PERFORM SETVAL('calculator_catalog_price_seq', vMaxId);
- END IF;
- RETURN vCount;
- END;
- $BODY$
- LANGUAGE plpgsql VOLATILE
- COST 100;
- /
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement