Vous êtes sur la page 1sur 14

*&---------------------------------------------------------------------* *& Form FRM_KONDI_WERT_920 *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM frm_kondi_wert_920.

DATA: xcom_tax LIKE com_tax, xcom_err LIKE com_err, br_komv LIKE komv. "XKOMV also contains Index ! DATA: BEGIN OF xxkomv OCCURS 10. INCLUDE STRUCTURE komv. DATA: END OF xxkomv. DATA: br_konp LIKE konp OCCURS 10 WITH HEADER LINE. DATA: mwskz LIKE komp-mwskz, "Steuerkennzeichen plant LIKE t001w-werks, "Werk save_xkomv LIKE komv_index, posnr LIKE komp-kposn, exempt_flag, copy_flag, counter TYPE i, amount TYPE p, quantity TYPE p. DATA: lv_cbt_active TYPE xfeld. DATA: ls_t001w TYPE t001w, ls_kna1 TYPE kna1. DATA: lv_rounding TYPE boole. * Note 916487 : It's necessary to check if the ICMS value should be updated DATA: lv_tax_data_update TYPE boole.

* Note 904935 : Rounding ICMS value on document header level DATA: lv_base TYPE kawrt, lv_rate TYPE kbetr. *DATA ti_xkomv TYPE STANDARD TABLE OF komv_index * WITH HEADER LINE INITIAL SIZE 50.

DATA: w_netwr TYPE komp-netwr, w_dif TYPE komp-netwr, l_fator TYPE p, l_scale TYPE i. STATICS: j_1bbdata LIKE j_1bbranch, j_1bplant LIKE komp-werks.

* Macros for default handling DEFINE assign_default. if &2 is initial. xcom_tax-&1 = &3. else. xcom_tax-&1 = &2. endif. END-OF-DEFINITION. DEFINE default_on_initial. if xcom_tax-&1 is initial or xcom_tax-&1 = space. xcom_tax-&1 = &2. endif. END-OF-DEFINITION.

* Check if taxes are calculated with the new condition-based logic * or with the old external tax calculation CALL FUNCTION EXPORTING iv_kappl iv_kalsm IMPORTING ev_active 'J_1B_CHECK_CBT_CALC' = komk-kappl = komk-kalsm = lv_cbt_active.

IF lv_cbt_active = 'X'. * Condition-based tax calculation * Note 904935 : Rounding ICMS value on document header level CALL FUNCTION 'J_1B_CBT' EXPORTING is_komk = is_komp = is_komv_frm = it_komv = IMPORTING ev_result = ev_base = ev_rate = ev_rounding = ev_tax_data_update =

komk komp xkomv xkomv[] xkwert lv_base lv_rate lv_rounding lv_tax_data_update.

******************************************************************************** ****** * Alteracao - Felipe Nyitray 09/11/2009 ********************************************************************************

****** IF xkomv-kschl EQ 'ICMI'. * read company code in case not filled yet (to get local currency) IF t001-bukrs <> komk-bukrs. IF NOT komk-bukrs IS INITIAL. CALL FUNCTION 'T001_SINGLE_READ' EXPORTING bukrs = komk-bukrs IMPORTING wt001 = t001 EXCEPTIONS OTHERS = 0. ENDIF. ENDIF. * calculation of conversion factor not required anymore: * this is handled by increasing the rounding scale below * determine rounding correction factor and decimals from Branch IF j_1bplant <> komp-werks. * read branch data to get number of decimals for the price rounding j_1bplant = komp-werks. CALL FUNCTION 'J_1BREAD_PLANT_DATA' EXPORTING plant = j_1bplant IMPORTING branch_data = j_1bbdata EXCEPTIONS OTHERS = 1. IF sy-subrc <> 0. CLEAR j_1bbdata. ENDIF. ENDIF. * if rounding at branch is not defined use maximum level of detail IF j_1bbdata-nfdec IS INITIAL. j_1bbdata-nfdec = 6. ENDIF. CALL FUNCTION 'J_1B_ROUNDING_SCALE_GET' EXPORTING iv_tax_base = komp-netwr iv_nfdec = j_1bbdata-nfdec IMPORTING ev_scale = l_scale ev_factor = l_fator.

w_netwr = 1000000. IF komp-netwr LT w_netwr. w_netwr = komp-netwr * ( 10 ** l_scale ). ELSE. w_netwr = komp-netwr. ENDIF.

w_dif = xkwert - w_netwr. xkwert = xkwert - w_dif. ENDIF. ******************************************************************************** *** * fim FANF ******************************************************************************** *** IF lv_rounding = 'X'. PERFORM j_1b_rounding_brasil. * Note 904935 : Rounding ICMS value on document header level * Only update ICMS tax value. * Note 916487 : This new condition makes sure to only update the ICMS value ELSEIF lv_tax_data_update = 'X'. xkomv-kawrt = lv_base. xkomv-kbetr = lv_rate. ENDIF. ELSE. * Old, external tax calculation * Clear global workfields CLEAR: taxpct0, taxamt0, taxbas0, taxpct1, taxamt1, taxbas1, taxpct2, taxamt2, taxbas2, taxpct3, taxamt3, taxbas3, taxpct4, taxamt4, taxbas4, taxpct5, taxamt5, taxbas5, taxpct6, taxamt6, taxbas6, taxpct7, taxamt7, taxbas7, taxpct8, taxamt8, taxbas8, taxpct9, taxamt9, taxbas9, xcom_tax, xcom_err. CHECK komk-trtyp NE 'A' AND xkomv-ksteu NE 'E' AND komp-prsok = 'X'. * Begin of Pricing Copy Logic copy_flag = space. IF xkomv-ksteu = 'F'. copy_flag = 'X'. save_xkomv = xkomv. "save actual XKOMV-entry counter = 0. LOOP AT xkomv WHERE kntyp CA '1234' AND kappl = 'TX'. CASE xkomv-kntyp. WHEN '1'. amount = xkomv-kwert. xcom_tax-taxamt1 = amount.

quantity = xkomv-kbetr. xcom_tax-taxpct1 = quantity. WHEN '2'. amount = xkomv-kwert. xcom_tax-taxamt2 = amount. quantity = xkomv-kbetr. xcom_tax-taxpct2 = quantity. WHEN '3'. amount = xkomv-kwert. xcom_tax-taxamt3 = amount. quantity = xkomv-kbetr. xcom_tax-taxpct3 = quantity. WHEN '4'. counter = counter + 1. IF counter = 1. amount = xkomv-kwert. xcom_tax-taxamt4 = amount. quantity = xkomv-kbetr. xcom_tax-taxpct4 = quantity. ELSEIF counter = 2. amount = xkomv-kwert. xcom_tax-taxamt5 = amount. quantity = xkomv-kbetr. xcom_tax-taxpct5 = quantity. ELSEIF counter = 3. amount = xkomv-kwert. xcom_tax-taxamt6 = amount. quantity = xkomv-kbetr. xcom_tax-taxpct6 = quantity. ELSEIF counter = 4. amount = xkomv-kwert. xcom_tax-taxamt7 = amount. quantity = xkomv-kbetr. xcom_tax-taxpct7 = quantity. ELSEIF counter = 5. amount = xkomv-kwert. xcom_tax-taxamt8 = amount. quantity = xkomv-kbetr. xcom_tax-taxpct8 = quantity. ELSEIF counter = 6. amount = xkomv-kwert. xcom_tax-taxamt9 = amount. quantity = xkomv-kbetr. xcom_tax-taxpct9 = quantity. ENDIF. ENDCASE. CLEAR: amount, quantity. ENDLOOP. xkomv = save_xkomv. "reset XKOMV entry ENDIF. * End of Pricing Copy Logic posnr = komp-kposn. * Initialize MWSKZ

IF xkomv-mwsk1 IS INITIAL. mwskz = komp-mwskz. "MWSKZ aus Position (MM/FI) ELSE. mwskz = xkomv-mwsk1. "MWSKZ aus Kondition (SD) ENDIF. * Tax Exemptions SELECT SINGLE * FROM t007a WHERE kalsm = t005-kalsm AND mwskz = mwskz. IF t007a-txrel = 2. " Tax Exempt * in case of tax exempt customers skip the call to ext. package exempt_flag = 'X'. ENDIF. * Initialize TTXD ON CHANGE OF t005-kalsm. SELECT SINGLE * FROM ttxd WHERE kalsm = t005-kalsm. CHECK sy-subrc = 0 AND NOT ttxd-xextn IS INITIAL. ENDON. * Read T007A SELECT SINGLE * FROM t007a WHERE kalsm = t005-kalsm AND mwskz = mwskz. IF sy-subrc NE 0. MESSAGE s873(fs) WITH t005-kalsm mwskz. komp-prsok = space. xkomv-kinak = 'X'. xkomv-fxmsg = '899'. CALL FUNCTION 'SET_ERROR_FLAG'. ENDIF. * Populate COM_TAX xcom_tax-client = sy-mandt. " Client xcom_tax-comp_code = komk-bukrs. " Company Code xcom_tax-country = komk-aland. " Country for Tax Determinatio xcom_tax-doc_number = komk-belnr. " Document Reference Number xcom_tax-txjcd_l1 = ttxd-leng1. " Length of the 1th part of Ju xcom_tax-txjcd_l2 = ttxd-leng2. " Length of the 2th part of Ju xcom_tax-txjcd_l3 = ttxd-leng3. " Length of the 3th part of Ju xcom_tax-txjcd_l4 = ttxd-leng4. " Length of the 4th part of Ju xcom_tax-matnr = komp-matnr. " Material xcom_tax-currency = komk-waerk. " Currency Key * MGLME + MEINS belong together / also in LTAX1U02 and LTAX1U07 xcom_tax-unit = komp-meins. IF xcom_tax-unit IS INITIAL. xcom_tax-unit = komp-vrkme.

ENDIF. amount = xkomv-kawrt. IF NOT xkomv-kstat IS INITIAL OR xkomv-kschl IS INITIAL. IF amount IS INITIAL. amount = xkomv-kwert. ENDIF. ENDIF. xcom_tax-amount = amount. " Gross Amount quantity = komp-mglme. xcom_tax-quantity = quantity. " Quantity IF komp-kposn <> '999999'. xcom_tax-pos_no = komp-kposn. ELSE. IF komk-versi IS INITIAL. xcom_tax-pos_no = space. ELSE. xcom_tax-pos_no = komk-versi. posnr(3) = komk-versi. posnr+3(3) = '999'. ENDIF. ENDIF. IF xkomv-kappl(1) = 'V'. assign_default tax_date xkomv-kdatu komk-prsdt. ELSE. assign_default tax_date komk-fbuda komk-prsdt. ENDIF. default_on_initial tax_date sy-datum. * Determine decimals for currency CLEAR tcurx. SELECT SINGLE * FROM tcurx WHERE currkey = xcom_tax-currency. assign_default curr_dec tcurx-currdec '002'. * Determine Jurisdictioncodes for tax calculation plant = t001w-werks. IF plant IS INITIAL. plant = komp-werks. ENDIF. CASE t007a-mwart. WHEN 'A'. * A/R taxes xcom_tax-accnt_no = komk-kunnr." Customer Account Number xcom_tax-apar_ind = 'A'. SELECT SINGLE * FROM t001w WHERE werks = plant. "v_n_596011 "^_n_596011 "n_596011

IF sy-subrc = 0. MOVE: t001w-txjcd TO xcom_tax-txjcd_sf. ELSE. MOVE: komk-txjcd TO xcom_tax-txjcd_sf. ENDIF. default_on_initial txjcd_sf komk-txjcd. MOVE: komk-txjcd TO xcom_tax-txjcd_st. * fill jurisdiction-code for foreign customers IF komk-kunnr <> space. CALL FUNCTION 'J_1BFOREIGN_JURISDICTION' EXPORTING br_country = komk-aland foreign_country = komk-land1 CHANGING tax_jcd = xcom_tax-txjcd_st EXCEPTIONS foreign_region_not_found = 4. IF sy-subrc = 4. MESSAGE s316(8b) WITH komk-land1 RAISING tax_determination_error. EXIT. ENDIF. * ISS 2004, Note 766464 * Fill tax jurisdiction code of service recipient with customer's one * Read customer data IF NOT komk-kunnr IS INITIAL. CALL FUNCTION 'V_KNA1_SINGLE_READ' EXPORTING pi_kunnr = komk-kunnr IMPORTING pe_kna1 = ls_kna1 EXCEPTIONS OTHERS = 3. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. xcom_tax-txjcd_poo = ls_kna1-txjcd. ENDIF. ENDIF. WHEN 'V'. * A/P taxes xcom_tax-accnt_no = komk-lifnr." Vendor Account Number xcom_tax-apar_ind = 'V'. CALL FUNCTION 'WY_LFA1_SINGLE_READ' "new performance EXPORTING pi_lifnr = komk-lifnr IMPORTING po_lfa1 = lfa1 EXCEPTIONS no_records_found = 1 OTHERS = 2.

IF sy-subrc = 0. MOVE: lfa1-txjcd TO xcom_tax-txjcd_sf. ELSE. MOVE: komk-txjcd TO xcom_tax-txjcd_sf. ENDIF. default_on_initial txjcd_sf komk-txjcd. MOVE: komk-txjcd TO xcom_tax-txjcd_st. * fill jurisdiction-code for foreign vendors IF komk-lifnr <> space. CALL FUNCTION 'J_1BFOREIGN_JURISDICTION' EXPORTING br_country = komk-aland foreign_country = lfa1-land1 CHANGING tax_jcd = xcom_tax-txjcd_sf EXCEPTIONS foreign_region_not_found = 4. IF sy-subrc = 4. MESSAGE s316(8b) WITH lfa1-land1 RAISING tax_determination_error. EXIT. ENDIF. ENDIF. * ISS 2004, Note 766464 * Fill tax jurisdiction code of service recipient with plant's one * Read plant data IF NOT plant IS INITIAL. CALL FUNCTION 'AIP01_PLANT_DETERMINE' EXPORTING i_werks = plant IMPORTING es_t001w = ls_t001w EXCEPTIONS OTHERS = 6. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. xcom_tax-txjcd_poo = ls_t001w-txjcd. ENDIF. WHEN OTHERS. MESSAGE s874(fs) WITH t007a-mwart. komp-prsok = space. xkomv-kinak = 'X'. xkomv-fxmsg = '899'. CALL FUNCTION 'SET_ERROR_FLAG'. EXIT. ENDCASE. * check tax jurisdictions

IF xcom_tax-txjcd_sf IS INITIAL. MESSAGE s882(fs) RAISING tax_determination_error. ENDIF. IF xcom_tax-txjcd_st IS INITIAL. MESSAGE s883(fs) RAISING tax_determination_error. ENDIF. * reset calculation buffer of brazil tax calculation CALL FUNCTION 'J_1BNF_TAX_DATA_RESET_PART' EXPORTING knumv = komk-knumv kposn = komp-kposn buzei = komk-versi. * do the calculation, if required IF xcom_tax-amount NE 0 AND exempt_flag <> 'X'. IF komk-hwaer = space. komk-hwaer = t001-waers. ENDIF. * Determine DESTINATION for external system ON CHANGE OF ttxd-xextn. SELECT SINGLE * FROM ttxc WHERE xextn = ttxd-xextn AND event = 'TAX'. IF sy-subrc <> 0. RAISE rfcdest_not_found. ELSE. TRANSLATE ttxc-rfcdest TO UPPER CASE. IF ttxc-funcname IS INITIAL. ttxc-funcname = 'RFC_CALCULATE_TAXES'. ENDIF. ENDIF. ENDON. * Let the external system do the calculation CLEAR: xcom_tax-taxamt1, xcom_tax-taxamt2, xcom_tax-taxamt3, xcom_tax-taxamt4, xcom_tax-taxamt5, xcom_tax-taxamt6, xcom_tax-taxamt7, xcom_tax-taxamt8, xcom_tax-taxamt9, xcom_tax-taxamov, xcom_tax-taxamt0. CLEAR: xcom_tax-taxpct1, xcom_tax-taxpct2, xcom_tax-taxpct3, xcom_tax-taxpct4, xcom_tax-taxpct5, xcom_tax-taxpct6, xcom_tax-taxpct7, xcom_tax-taxpct8, xcom_tax-taxpct9, xcom_tax-taxpcov, xcom_tax-taxpct0. * fill parameters for the calculation br_komv = xkomv. REFRESH xxkomv. save_xkomv = xkomv. LOOP AT xkomv. xxkomv = xkomv.

"#EC SYNTCHAR

APPEND xxkomv. ENDLOOP. xkomv = save_xkomv. * fill BR_KONP REFRESH br_konp. LOOP AT xkonp. br_konp = xkonp-konp. APPEND br_konp. ENDLOOP. CALL FUNCTION EXPORTING i_komk = i_komp = i_t007a = i_komv = TABLES t_komv = t_konp = 'J_1BCOMPLETE_TAX_DATA' komk komp t007a br_komv xxkomv br_konp.

* process external tax calculation CALL FUNCTION ttxc-funcname DESTINATION ttxc-rfcdest EXPORTING tax_data = IMPORTING tax_result = tax_err = EXCEPTIONS communication_failure = system_error =

xcom_tax xcom_tax xcom_err 01 02.

"#EC ENHOK "#EC ENHOK "#EC ENHOK

IF sy-subrc NE 0. MESSAGE s870(fs). komp-prsok = space. xkomv-kinak = 'X'. xkomv-fxmsg = '899'. CALL FUNCTION 'SET_ERROR_FLAG'. EXIT. ELSEIF xcom_err-retcode <> 0. MESSAGE s872(fs) WITH xcom_err-errcode xcom_err-errmsg. komp-prsok = space. xkomv-kinak = 'X'. xkomv-fxmsg = '899'. CALL FUNCTION 'SET_ERROR_FLAG'. EXIT. ENDIF. ELSE. " gross amount is zero xcom_tax-taxamt0 = 0. xcom_tax-taxamt1 = 0. xcom_tax-taxamt2 = 0. xcom_tax-taxamt3 = 0. xcom_tax-taxamt4 = 0. xcom_tax-taxamt5 = 0.

xcom_tax-taxamt6 = 0. xcom_tax-taxamt7 = 0. xcom_tax-taxamt8 = 0. xcom_tax-taxamt9 = 0. xcom_tax-taxpct0 = 0. xcom_tax-taxpct1 = 0. xcom_tax-taxpct2 = 0. xcom_tax-taxpct3 = 0. xcom_tax-taxpct4 = 0. xcom_tax-taxpct5 = 0. xcom_tax-taxpct6 = 0. xcom_tax-taxpct7 = 0. xcom_tax-taxpct8 = 0. xcom_tax-taxpct9 = 0. CALL FUNCTION 'J_1B_CLEAR_GS_COMTAX'. ENDIF. * Fill global workfields from internal structure taxamt0 = xcom_tax-taxamt0. taxamt1 = xcom_tax-taxamt1. taxamt2 = xcom_tax-taxamt2. taxamt3 = xcom_tax-taxamt3. taxamt4 = xcom_tax-taxamt4. taxamt5 = xcom_tax-taxamt5. taxamt6 = xcom_tax-taxamt6. taxamt7 = xcom_tax-taxamt7. taxamt8 = xcom_tax-taxamt8. taxamt9 = xcom_tax-taxamt9. taxpct0 = xcom_tax-taxpct0. taxpct1 = xcom_tax-taxpct1. taxpct2 = xcom_tax-taxpct2. taxpct3 = xcom_tax-taxpct3. taxpct4 = xcom_tax-taxpct4. taxpct5 = xcom_tax-taxpct5. taxpct6 = xcom_tax-taxpct6. taxpct7 = xcom_tax-taxpct7. taxpct8 = xcom_tax-taxpct8. taxpct9 = xcom_tax-taxpct9. taxbas1 = xcom_tax-taxbas1. taxbas2 = xcom_tax-taxbas2. taxbas3 = xcom_tax-taxbas3. taxbas4 = xcom_tax-taxbas4. taxbas5 = xcom_tax-taxbas5. taxbas6 = xcom_tax-taxbas6. taxbas7 = xcom_tax-taxbas7. taxbas8 = xcom_tax-taxbas8. taxbas9 = xcom_tax-taxbas9. ENDIF. ENDFORM. "frm_kondi_wert_950

*&--------------------------------------------------------------------* *& Form j_1b_rounding_brasil *&--------------------------------------------------------------------* * Perform the rounding for CBT *---------------------------------------------------------------------* *FORM j_1b_rounding_brasil. * * STATICS: j_1bbdata LIKE j_1bbranch,

* * * * * ** * * ** * * * * * * ** * * * * * * * * * * * * ** ** * * ** * * ** * * * * * * * * * * * * * ** * * * * * * * * * *

j_1bplant LIKE komp-werks. DATA: tmp_value LIKE komv-kwert, result(16) TYPE p, lv_factor TYPE p, tax_base LIKE xkomv-kawrt, save1_xkomv LIKE xkomv. "10**x of YKPEIN "10**f of correction factor "factor ConditionUnit->SalesUnit "Rounding correction factor "Divide by 'rf'

Data definition for rounding DATA: x TYPE p, f TYPE p, s TYPE f, rf TYPE p, div(1) TYPE c.

read company code in case not filled yet (to get local currency) IF t001-bukrs <> komk-bukrs. IF NOT komk-bukrs IS INITIAL. CALL FUNCTION 'T001_SINGLE_READ' EXPORTING bukrs = komk-bukrs IMPORTING wt001 = t001 EXCEPTIONS OTHERS = 0. ENDIF. ENDIF. calculation of conversion factor not required anymore: this is handled by increasing the rounding scale below determine rounding correction factor and decimals from Branch IF j_1bplant <> komp-werks. read branch data to get number of decimals for the price rounding j_1bplant = komp-werks. CALL FUNCTION 'J_1BREAD_PLANT_DATA' EXPORTING plant = j_1bplant IMPORTING branch_data = j_1bbdata EXCEPTIONS OTHERS = 1. IF sy-subrc <> 0. CLEAR j_1bbdata. ENDIF. ENDIF. if rounding at branch is not defined use maximum level of detail IF j_1bbdata-nfdec IS INITIAL. j_1bbdata-nfdec = 6. ENDIF. CALL FUNCTION 'J_1B_ROUNDING_SCALE_GET' EXPORTING iv_tax_base = komp-netwr iv_nfdec = j_1bbdata-nfdec IMPORTING ev_factor = lv_factor.

* ** perform rounding if currency is CC currency and taxes were calculated ** Note 866790 * tmp_value = xkwert / lv_factor. * * IF xkomv-waers = t001-waers "(Brazilian) company code currency * AND tmp_value NE komp-netwr. " only if taxes were calculated * ** calculate rounding factor * f = j_1bbdata-nfdec - 2. "2=number of standard decimals * rf = 10 ** f. * ** tax base is net price --> result is already calculated per sales unit ** simply divide by sales order amount and rounding factors * result = xkwert. * IF komp-mgame <> 0. * result = 1000 * result * rf * / komp-mgame * / lv_factor . * ELSE. * CLEAR result. * ENDIF. * **... assign the results..for CC currency................................ * * xkomv-kbetr = result * ykpein * / rf. * * xkwert = result * komp-mgame * / 1000 / rf. * * ELSE. **... assign the results..for foreign currency........................ ** Avoid division by zero ** Note: 1007309: correction of the division by zero * IF komp-mgame <> 0. * IF ykmeng <> 0. * xkwert = tmp_value. ** xkomv-kbetr = xkwert * ykpein * 1000 / ykmeng. ** Note 936601 : Display of unit price * xkomv-kbetr = ( xkwert * 1000 ) / komp-mgame. * ENDIF. * ELSE. * CLEAR xkwert. * CLEAR xkomv-kbetr. * ENDIF. * ENDIF. * ** assign other result fields: Required for CBT as well ** xkomv-kmein = ykmein. "Shall be komp-vrkme if anything. ** xkomv-kumza = ykumza. ** xkomv-kumne = ykumne. * xkomv-kpein = ykpein. * xkomv-kawrt = ykmeng. * *ENDFORM. "j_1b_rounding_brasil

Vous aimerez peut-être aussi