* 임시전표 데이터 정보 - 부가세나 원천세가 display되지 않음.
CALL FUNCTION 'PRELIMINARY_POSTING_DOC_READ'
EXPORTING
belnr = i_belnr
bukrs = i_bukrs
gjahr = i_gjahr
TABLES
t_vbkpf = lt_vbkpf
t_vbsec = lt_vbsec
t_vbseg = lt_vbseg
t_vbset = lt_vbset
t_vacsplt = lt_vacsplt
t_vspltwt = lt_vspltwt.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
* SAP에서 삭제된 임시전표
DATA : lt_cdhdr LIKE cdhdr OCCURS 0 WITH HEADER LINE.
FREE : lt_cdhdr.
SELECT hdr~objectid
INTO CORRESPONDING FIELDS OF TABLE lt_cdhdr
FROM cdhdr AS hdr
INNER JOIN cdpos AS pos
ON hdr~objectclas EQ pos~objectclas
AND hdr~objectid EQ pos~objectid
AND hdr~changenr EQ pos~changenr
WHERE hdr~objectclas EQ 'BELEGV'
AND hdr~udate BETWEEN i_cpudt_f AND i_cpudt_t
AND pos~tabname EQ 'VBKPF'
AND pos~chngind EQ 'D'.
IF lt_cdhdr[] IS NOT INITIAL.
LOOP AT lt_cdhdr.
CLEAR outtab.
MOVE lt_cdhdr-objectid+7(4) TO outtab-bukrs.
MOVE lt_cdhdr-objectid+11(10) TO outtab-belnr.
MOVE lt_cdhdr-objectid+21(4) TO outtab-gjahr.
MOVE 'Z' TO outtab-bstat.
APPEND outtab. CLEAR outtab.
ENDLOOP.
ENDIF.
* Z_FI_PARK_SIMULATION - 임시전표 정보(부가세/원천세 포함)
FUNCTION z_fi_park_simulation.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(P_BUKRS) LIKE BKPF-BUKRS
*" REFERENCE(P_GJAHR) LIKE BKPF-GJAHR
*" REFERENCE(P_BELNR) LIKE BKPF-BELNR
*" TABLES
*" T_BSEG STRUCTURE BSEG
*" A_BSEG STRUCTURE BSEG
*" EXCEPTIONS
*" NO_DOCUMENT
*"----------------------------------------------------------------------
* Park Document. 상태에서 Taxline을 구성한다.
* => STD Simulatin logic을 구현하기에는 시간/투입M/D 대비 효과 없음..
* T_BSEG 는 빈 상태로 시작해서
* 추가되는 Tax line을 추가해서 T_BSEG table에 넣어 보낸다.
* A_BSEG 는 추가되는 Tax line 만을 포함한다.
*CALCULATE_TAX_FROM_GROSSAMOUNT
*CALCULATE_TAX_FROM_NET_AMOUNT
* => 이상 두개의 Function을 test한다..==> GROSS..
CLEAR : xbkpf,xbseg,xvbsega,xvbsegs,xvbsegd,xvbsegk,tmp_tax,
tax_info,t_bseg,a_bseg.
REFRESH : xbkpf,xbseg,xvbsega,xvbsegs,xvbsegd,xvbsegk,tmp_tax,
tax_info,t_bseg,a_bseg.
* 1. 전표 Header 정보 읽어오기..
SELECT * INTO TABLE xbkpf FROM bkpf
WHERE bukrs = p_bukrs
AND belnr = p_belnr
AND gjahr = p_gjahr.
IF sy-subrc = 0.
READ TABLE xbkpf INDEX 1.
ELSE.
RAISE no_document.
ENDIF.
* 2. 전표 item 정보 읽어오기
SELECT * INTO TABLE xvbsega FROM vbsega
WHERE ausbk = p_bukrs
AND belnr = p_belnr
AND gjahr = p_gjahr.
SELECT * INTO TABLE xvbsegd FROM vbsegd
WHERE ausbk = p_bukrs
AND belnr = p_belnr
AND gjahr = p_gjahr.
SELECT * INTO TABLE xvbsegk FROM vbsegk
WHERE ausbk = p_bukrs
AND belnr = p_belnr
AND gjahr = p_gjahr.
SELECT * INTO TABLE xvbsegs FROM vbsegs
WHERE ausbk = p_bukrs
AND belnr = p_belnr
AND gjahr = p_gjahr.
LOOP AT xvbsega .
CLEAR xbseg.
MOVE-CORRESPONDING xvbsega TO xbseg.
xbseg-koart = 'A'.
APPEND xbseg.
ENDLOOP.
LOOP AT xvbsegd .
CLEAR xbseg.
MOVE-CORRESPONDING xvbsegd TO xbseg.
xbseg-koart = 'D'.
APPEND xbseg.
ENDLOOP.
LOOP AT xvbsegk .
CLEAR xbseg.
MOVE-CORRESPONDING xvbsegk TO xbseg.
xbseg-koart = 'K'.
APPEND xbseg.
ENDLOOP.
LOOP AT xvbsegs .
CLEAR xbseg.
MOVE-CORRESPONDING xvbsegs TO xbseg.
xbseg-koart = 'S'.
APPEND xbseg.
ENDLOOP.
* 2. 우선순위 : 1. 수동으로 입력된 Tax 정보가 있을때는 해당정보를 이용
* ==> BKPF-XMWST = ' '
* 1.1 VBSET 에 있으면 계산한다
* 1.2 VBSET에 없고 VBSEGD 또는 VBSEGK에 세액정보가있을
* 경우 해당세액정보를 추가 Line item으로 구성한다.
* 2. 자동계산으로 되어있을경우 Function 이용해서 정보생성
* ==> BKPF-XMWST = 'X' 일경우..
DESCRIBE TABLE xbseg LINES line_cnt.
new_line = line_cnt + 1.
CLEAR : r_code,n_deduct, n_deduct[]..
* 1. 자동계산이 아닌경우의 계산..
IF xbkpf-xmwst = ' ' .
* 1.1 수동으로 Tax 금액을 입력한경우
PERFORM make_tax_line_from_vbset TABLES a_bseg
USING r_code.
IF r_code = 0.
IF n_deduct[] IS INITIAL."불공제 내역 없음.
t_bseg[] = xbseg[].
ELSE.
PERFORM adjust_gl_line_non_deductible .
t_bseg[] = xbseg[].
ENDIF.
ELSE.
* 1.2 VBSET에 없고 VBSEGD 또는 VBSEGK에 세액정보가있을
* 경우 해당세액정보를 추가 Line item으로 구성한다.
PERFORM make_tax_line_from_arap TABLES t_bseg a_bseg.
ENDIF.
* 2. 자동계산인 경우
ELSEIF xbkpf-xmwst = 'X' . "자동계산 .
PERFORM make_tax_line_by_auto TABLES t_bseg a_bseg.
ENDIF.
** WITH ITEM
PERFORM CREATE_WITH_ITEM TABLES XBKPF
T_BSEG
USING P_BUKRS.
SORT t_bseg BY bukrs gjahr belnr buzei.
SORT a_bseg BY bukrs gjahr belnr buzei.
ENDFUNCTION.
FUNCTION-POOL zfi04. "MESSAGE-ID ..
TABLES: abuz, " Schnittstellensegment RAIN
anbz, " Schnittstellensegment RAIN
avik, " Aviskopf
bkp1, " Belegkopf Zusatzangaben
bkpf,
*bkdf, " Dauerbuchungsdaten
bnka, " Banken
bsee, " Belegzeile Substitution
bseu, " Belegzeile Zusatzinfo Verbuchng
bsid, " Belegindex Debitor
bsik, " Belegindex Kreditor
bsis, " Belegindex Sachkonto
bsix, " Belegindex Wechselobligo
bvor, " Buchungsvorgaenge
kmkpf, " Kopf Kontierungsmuster
knas, " EG-Steuercodes je Kunde
knbk, " Bankverbindungen je Kunde
lfbk, " note 562191
knc3, " Kunde-Sonderhauptbuchstand
lfc3, " Lieferanten-Sonderhauptbuch
rfdt, " RF-Daten ( wie INDX )
sadr, " Adressdaten
seccode, " Section Codes
vbsegs,
vbset,
vbsegd, " Vorerfate Belege: Debi.Zeilen
vbsegk. " Vorerfate Belege: Kred.Zeilen
TABLES: addr1_sel,
ausz1,
ausz2,
bsegl,
ek05a,
f05actrl,
fin1_param,
firevdoc,
fs006,
itxdat,
opayf,
rf05s,
rfops, rfops_jv,
rfopt, rfopt2,
rfradc,
rf022,
rtitl,
sapos,
uf05a,
tmpbl,
*x001.
TABLES: t000,
tfagm,
tfavw,
tfbuf,
thead,
thkon,
treri,
tstc,
tstcp,
tstct,
ttypt,
tvoid,
t001u,
t001w,
t003,
t003a,
t004f,
t008,
t015l,
t019,
t019w,
t021,
t021t,
t021v,
t030d,
t030u, *t030u,
t031,
t041a,
t041b,
t041t,
t042,
t042f,
t043g,
t045p,
t045w,
t046,
t053,
t053r,
t053s,
t054a,
t074t.
TABLES: vf_debi, " View ber KNA1 / KNB1
vf_kred. " View ber LFA1 / LFB1
DATA :
xnegp(1) TYPE c. " Negativbuchungen
DATA : xbkpf LIKE bkpf OCCURS 0 WITH HEADER LINE,
xbseg LIKE bseg OCCURS 0 WITH HEADER LINE,
xvbsegs LIKE vbsegs OCCURS 0 WITH HEADER LINE,
xvbsegd LIKE vbsegd OCCURS 0 WITH HEADER LINE,
xvbsegk LIKE vbsegk OCCURS 0 WITH HEADER LINE,
xvbsega LIKE vbsega OCCURS 0 WITH HEADER LINE,
xvbset LIKE vbset OCCURS 0 WITH HEADER LINE,
xbset LIKE bset OCCURS 0 WITH HEADER LINE.
DATA : t_bseg LIKE bseg OCCURS 0 WITH HEADER LINE,
a_bseg LIKE bseg OCCURS 0 WITH HEADER LINE.
DATA : line_cnt LIKE sy-tabix, "원래 Line 수
new_line LIKE sy-tabix. "최초 추가Line item no
DATA : BEGIN OF tmp_tax OCCURS 0,
bukrs LIKE bset-bukrs,
belnr LIKE bset-belnr,
gjahr LIKE bset-gjahr,
mwskz LIKE bset-mwskz,
hkont LIKE bset-hkont,
shkzg LIKE bset-shkzg,
hwste LIKE bset-hwste,
fwste LIKE bset-fwste,
END OF tmp_tax.
DATA : tax_info LIKE rtax1u15 OCCURS 0 WITH HEADER LINE.
DATA : r_code LIKE sy-subrc.
* 매입세액 불공제 내역 계산위한 internal table..
DATA : BEGIN OF n_deduct OCCURS 0,
mwskz LIKE bset-mwskz,
amt LIKE bset-fwste,
END OF n_deduct.
* ------------------------------------------------------------
*----------------------------------------------------------------------*
***INCLUDE LZFI04F01 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form make_tax_line_from_vbset
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM MAKE_TAX_LINE_FROM_VBSET TABLES TAX_BSEG STRUCTURE BSEG
USING P_R_CODE.
DATA : N_DEDUCT_AMT LIKE BSET-FWSTE. "불공제 금액 total
* 1.1
* VBSET table에는 차/대,세금코드별 금액이 Collect되어있다...
SELECT * FROM VBSET WHERE AUSBK = XBKPF-BUKRS
AND BELNR = XBKPF-BELNR
AND GJAHR = XBKPF-GJAHR.
CHECK VBSET-FWSTE NE 0.
CLEAR N_DEDUCT_AMT.
CALL FUNCTION 'CALCULATE_TAX_FROM_GROSSAMOUNT'
EXPORTING
I_BUKRS = VBSET-AUSBK
I_MWSKZ = VBSET-MWSKZ
I_WAERS = XBKPF-WAERS
I_WRBTR = VBSET-FWSTE "금액은 중요치X
IMPORTING
E_FWNAV = N_DEDUCT_AMT
TABLES
T_MWDAT = TAX_INFO.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* IF sy-subrc = 0.
IF NOT TAX_INFO-HKONT IS INITIAL.
READ TABLE TAX_INFO INDEX 1.
* 새로운 BSEG Line 구성
CLEAR XBSEG.
XBSEG-MANDT = SY-MANDT.
XBSEG-BUKRS = VBSET-AUSBK.
XBSEG-BELNR = VBSET-BELNR.
XBSEG-GJAHR = VBSET-GJAHR.
XBSEG-BUZEI = NEW_LINE.
XBSEG-HKONT = TAX_INFO-HKONT.
XBSEG-WRBTR = VBSET-FWSTE.
XBSEG-DMBTR = VBSET-HWSTE.
XBSEG-SHKZG = VBSET-SHKZG.
XBSEG-MWSKZ = VBSET-MWSKZ.
IF VBSET-SHKZG = 'S'.
XBSEG-BSCHL = '40'.
ELSE.
XBSEG-BSCHL = '50'.
ENDIF.
APPEND XBSEG.
* Tax line만 추가..
CLEAR TAX_BSEG.
TAX_BSEG = XBSEG. APPEND TAX_BSEG.
NEW_LINE = NEW_LINE + 1.
CLEAR TAX_INFO. REFRESH TAX_INFO.
* 매입세액 불공제는 따로 보관해 둔다(비용계정 금액별 안분)
* 위 Function의 E_FWNAV 값이 세액불공제 금액 total 값임..
ELSEIF VBSET-MWSKZ = '43'.
N_DEDUCT-MWSKZ = VBSET-MWSKZ.
N_DEDUCT-AMT = VBSET-HWSTE.
COLLECT N_DEDUCT.
ENDIF.
ENDSELECT .
IF SY-SUBRC NE 0.
P_R_CODE = '4'.
ENDIF.
ENDFORM. " make_tax_line_from_vbset
*&---------------------------------------------------------------------*
*& Form make_tax_line_from_arap
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM MAKE_TAX_LINE_FROM_ARAP TABLES ALL_BSEG STRUCTURE BSEG
TAX_BSEG STRUCTURE BSEG.
* 추가라인으로 구성할수 없는 '매입세액 불공제'는 43 Tax code
* 를 가지고 있는 GL 계정들의 금액에 Tax 금액을 up시켜 주어야함.
CLEAR : N_DEDUCT, N_DEDUCT[].
LOOP AT XBSEG.
IF ( XBSEG-KOART = 'K' OR XBSEG-KOART = 'D' )
AND NOT XBSEG-WMWST IS INITIAL.
* -세금라인 구성(Collect시키기)
CLEAR TAX_INFO. REFRESH TAX_INFO.
CLEAR TMP_TAX.
CALL FUNCTION 'CALCULATE_TAX_FROM_GROSSAMOUNT'
EXPORTING
I_BUKRS = XBSEG-BUKRS
I_MWSKZ = XBSEG-MWSKZ
I_WAERS = XBKPF-WAERS
I_WRBTR = XBSEG-WRBTR "
TABLES
T_MWDAT = TAX_INFO.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
IF NOT TAX_INFO-HKONT IS INITIAL.
READ TABLE TAX_INFO INDEX 1.
TMP_TAX-BUKRS = XBSEG-BUKRS.
TMP_TAX-BELNR = XBSEG-BELNR.
TMP_TAX-GJAHR = XBSEG-GJAHR.
TMP_TAX-MWSKZ = XBSEG-MWSKZ.
TMP_TAX-HKONT = TAX_INFO-HKONT.
IF XBSEG-SHKZG = 'H'."AR/AP의 반대변에..
TMP_TAX-SHKZG = 'S'.
ELSE.
TMP_TAX-SHKZG = 'H'.
ENDIF.
TMP_TAX-FWSTE = XBSEG-WMWST. "전표통화세액(입력값)
* IF xbkpf-waers = 'KRW'.
TMP_TAX-HWSTE = XBSEG-MWSTS . "현지통화세액
* ENDIF.
COLLECT TMP_TAX.
ENDIF.
ENDIF.
* AP,AR line도 Gross금액이므로 그대로 라인추가한다.
ALL_BSEG = XBSEG.
APPEND ALL_BSEG.
* 매입세액 불공제의 경우는 따로 저장해 놓는다..
IF XBSEG-MWSKZ = '43'.
N_DEDUCT-MWSKZ = XBSEG-MWSKZ.
N_DEDUCT-AMT = XBSEG-MWSTS. "LC 세금
COLLECT N_DEDUCT.
ENDIF.
ELSE.
* -일반라인 구성
ALL_BSEG = XBSEG.
APPEND ALL_BSEG.
CONTINUE.
ENDIF.
ENDLOOP.
* Tax line 추가 하기
DESCRIBE TABLE ALL_BSEG LINES LINE_CNT.
NEW_LINE = LINE_CNT + 1.
LOOP AT TMP_TAX.
CLEAR ALL_BSEG.
ALL_BSEG-MANDT = SY-MANDT.
ALL_BSEG-BUKRS = TMP_TAX-BUKRS.
ALL_BSEG-BELNR = TMP_TAX-BELNR.
ALL_BSEG-GJAHR = TMP_TAX-GJAHR.
ALL_BSEG-BUZEI = NEW_LINE.
ALL_BSEG-HKONT = TMP_TAX-HKONT.
ALL_BSEG-WRBTR = TMP_TAX-FWSTE. "전표통화세액
ALL_BSEG-DMBTR = TMP_TAX-HWSTE. "현지통화세액
ALL_BSEG-SHKZG = TMP_TAX-SHKZG.
ALL_BSEG-MWSKZ = TMP_TAX-MWSKZ.
IF ALL_BSEG-SHKZG = 'S'.
ALL_BSEG-BSCHL = '40'.
ELSE.
ALL_BSEG-BSCHL = '50'.
ENDIF.
APPEND ALL_BSEG.
* Tax line만 추가..
CLEAR TAX_BSEG.
TAX_BSEG = XBSEG. APPEND TAX_BSEG.
NEW_LINE = NEW_LINE + 1.
ENDLOOP.
* 매입세액 불공제 금액 보정하기.(GL line item에 금액 up하기)
* all_bseg를 수정해 주면 됨.....
IF NOT N_DEDUCT[] IS INITIAL.
* all_bseg 의 GL line item(tax code=43)에 불공제금액 반영한다.
DATA : TOTAL_AMT LIKE BSEG-DMBTR, "총 불공제 금액
REST_AMT LIKE BSEG-DMBTR, "안분후 남은 금액
TAX_AMT LIKE BSEG-DMBTR, "안분할 불공제 금액
LAST_TABIX LIKE SY-TABIX. "마지막 나머지 금액 조정위해
READ TABLE N_DEDUCT INDEX 1. "43의 경우는 하나의 라인만 존재한다가정.
TOTAL_AMT = N_DEDUCT-AMT.
IF SY-SUBRC = 0.
LOOP AT ALL_BSEG WHERE KOART = 'S'
AND MWSKZ = '43'.
CLEAR : TAX_AMT, TAX_INFO, TAX_INFO[] .
LAST_TABIX = SY-TABIX.
CALL FUNCTION 'CALCULATE_TAX_FROM_NET_AMOUNT'
EXPORTING
I_BUKRS = ALL_BSEG-BUKRS
I_MWSKZ = ALL_BSEG-MWSKZ
* I_TXJCD = ' '
I_WAERS = XBKPF-WAERS
I_WRBTR = ALL_BSEG-DMBTR
IMPORTING
E_FWNAV = TAX_AMT
* E_FWNVV =
* E_FWSTE =
* E_FWAST =
TABLES
T_MWDAT = TAX_INFO
EXCEPTIONS
BUKRS_NOT_FOUND = 1
COUNTRY_NOT_FOUND = 2
MWSKZ_NOT_DEFINED = 3
MWSKZ_NOT_VALID = 4
KTOSL_NOT_FOUND = 5
KALSM_NOT_FOUND = 6
PARAMETER_ERROR = 7
KNUMH_NOT_FOUND = 8
KSCHL_NOT_FOUND = 9
UNKNOWN_ERROR = 10
ACCOUNT_NOT_FOUND = 11
TXJCD_NOT_VALID = 12
OTHERS = 13.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
ALL_BSEG-DMBTR = ALL_BSEG-DMBTR + TAX_AMT .
IF XBKPF-WAERS = 'KRW'.
ALL_BSEG-WRBTR = ALL_BSEG-WRBTR + TAX_AMT.
ENDIF.
MODIFY ALL_BSEG INDEX LAST_TABIX.
TOTAL_AMT = TOTAL_AMT - TAX_AMT.
ENDIF.
ENDLOOP.
* 계산 단수차이로 인한 차이금액을 마지막라인에 보정해 준다.
IF TOTAL_AMT NE 0.
READ TABLE ALL_BSEG INDEX LAST_TABIX.
ALL_BSEG-DMBTR = ALL_BSEG-DMBTR + TOTAL_AMT.
IF XBKPF-WAERS = 'KRW'.
ALL_BSEG-WRBTR = ALL_BSEG-WRBTR + TOTAL_AMT.
ENDIF.
MODIFY ALL_BSEG INDEX LAST_TABIX.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. " make_tax_line_from_arap
*&---------------------------------------------------------------------*
*& Form make_tax_line_by_auto
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM MAKE_TAX_LINE_BY_AUTO
TABLES ALL_BSEG STRUCTURE BSEG
TAX_BSEG STRUCTURE BSEG.
DATA : FWAST LIKE BSET-FWSTE. "Deductible Tax amt..
LOOP AT XBSEG.
IF XBSEG-KOART NE 'S' OR XBSEG-MWSKZ IS INITIAL.
ALL_BSEG = XBSEG.
APPEND ALL_BSEG.
CONTINUE.
* GL 계정을 기준으로 Tax amount 계산한다.
ELSE.
CLEAR TAX_INFO. REFRESH TAX_INFO.
CLEAR TMP_TAX. CLEAR FWAST.
CALL FUNCTION 'CALCULATE_TAX_FROM_GROSSAMOUNT'
EXPORTING
I_BUKRS = XBSEG-BUKRS
I_MWSKZ = XBSEG-MWSKZ
I_WAERS = XBKPF-WAERS
I_WRBTR = XBSEG-WRBTR "
IMPORTING
E_FWAST = FWAST
TABLES
T_MWDAT = TAX_INFO.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
IF NOT TAX_INFO-HKONT IS INITIAL AND
NOT FWAST IS INITIAL.
READ TABLE TAX_INFO INDEX 1.
TMP_TAX-BUKRS = XBSEG-BUKRS.
TMP_TAX-BELNR = XBSEG-BELNR.
TMP_TAX-GJAHR = XBSEG-GJAHR.
TMP_TAX-MWSKZ = XBSEG-MWSKZ.
TMP_TAX-HKONT = TAX_INFO-HKONT.
TMP_TAX-SHKZG = XBSEG-SHKZG."GL계정과 동일하게 한다..
TMP_TAX-FWSTE = TAX_INFO-WMWST. "전표통화세액
IF XBKPF-WAERS = 'KRW'.
TMP_TAX-HWSTE = TAX_INFO-WMWST . "현지통화세액
ENDIF.
COLLECT TMP_TAX.
ENDIF.
ENDIF.
* 원래의 bseg line item금액 수정한다(세액 감하기)=> 계정존재시만..
ALL_BSEG = XBSEG.
IF NOT TAX_INFO-HKONT IS INITIAL AND
NOT FWAST IS INITIAL.
ALL_BSEG-WRBTR = ALL_BSEG-WRBTR - TAX_INFO-WMWST.
IF XBKPF-WAERS = 'KRW'.
ALL_BSEG-DMBTR = ALL_BSEG-DMBTR - TAX_INFO-WMWST.
ENDIF.
ENDIF.
APPEND ALL_BSEG.
ENDIF.
ENDLOOP.
* Tax line 추가 하기
DESCRIBE TABLE ALL_BSEG LINES LINE_CNT.
NEW_LINE = LINE_CNT + 1.
LOOP AT TMP_TAX.
CLEAR ALL_BSEG.
ALL_BSEG-MANDT = SY-MANDT.
ALL_BSEG-BUKRS = TMP_TAX-BUKRS.
ALL_BSEG-BELNR = TMP_TAX-BELNR.
ALL_BSEG-GJAHR = TMP_TAX-GJAHR.
ALL_BSEG-BUZEI = NEW_LINE.
ALL_BSEG-HKONT = TMP_TAX-HKONT.
ALL_BSEG-WRBTR = TMP_TAX-FWSTE. "전표통화세액
ALL_BSEG-DMBTR = TMP_TAX-HWSTE. "현지통화세액
ALL_BSEG-SHKZG = TMP_TAX-SHKZG.
ALL_BSEG-MWSKZ = TMP_TAX-MWSKZ.
IF ALL_BSEG-SHKZG = 'S'.
ALL_BSEG-BSCHL = '40'.
ELSE.
ALL_BSEG-BSCHL = '50'.
ENDIF.
APPEND ALL_BSEG.
* Tax line만 추가..
CLEAR TAX_BSEG.
TAX_BSEG = XBSEG. APPEND TAX_BSEG.
NEW_LINE = NEW_LINE + 1.
ENDLOOP.
ENDFORM. " make_tax_line_by_auto
*&---------------------------------------------------------------------*
*& Form adjust_gl_line_non_deductible
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_T_BSEG text
*----------------------------------------------------------------------*
FORM ADJUST_GL_LINE_NON_DEDUCTIBLE.
* xbseg 의 GL line item(tax code=43)에 불공제금액 반영한다.
DATA : TOTAL_AMT LIKE BSEG-DMBTR, "총 불공제 금액
REST_AMT LIKE BSEG-DMBTR, "안분후 남은 금액
TAX_AMT LIKE BSEG-DMBTR, "안분할 불공제 금액
LAST_TABIX LIKE SY-TABIX. "마지막 나머지 금액 조정위해
READ TABLE N_DEDUCT INDEX 1. "43의 경우는 하나의 라인만 존재한다가정.
TOTAL_AMT = N_DEDUCT-AMT.
IF SY-SUBRC = 0.
LOOP AT XBSEG WHERE KOART = 'S'
AND MWSKZ = '43'.
CLEAR : TAX_AMT, TAX_INFO, TAX_INFO[] .
LAST_TABIX = SY-TABIX.
CALL FUNCTION 'CALCULATE_TAX_FROM_NET_AMOUNT'
EXPORTING
I_BUKRS = XBSEG-BUKRS
I_MWSKZ = XBSEG-MWSKZ
* I_TXJCD = ' '
I_WAERS = XBKPF-WAERS
I_WRBTR = XBSEG-DMBTR
IMPORTING
E_FWNAV = TAX_AMT
* E_FWNVV =
* E_FWSTE =
* E_FWAST =
TABLES
T_MWDAT = TAX_INFO
EXCEPTIONS
BUKRS_NOT_FOUND = 1
COUNTRY_NOT_FOUND = 2
MWSKZ_NOT_DEFINED = 3
MWSKZ_NOT_VALID = 4
KTOSL_NOT_FOUND = 5
KALSM_NOT_FOUND = 6
PARAMETER_ERROR = 7
KNUMH_NOT_FOUND = 8
KSCHL_NOT_FOUND = 9
UNKNOWN_ERROR = 10
ACCOUNT_NOT_FOUND = 11
TXJCD_NOT_VALID = 12
OTHERS = 13.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
XBSEG-DMBTR = XBSEG-DMBTR + TAX_AMT .
IF XBKPF-WAERS = 'KRW'.
XBSEG-WRBTR = XBSEG-WRBTR + TAX_AMT.
ENDIF.
MODIFY XBSEG INDEX LAST_TABIX.
TOTAL_AMT = TOTAL_AMT - TAX_AMT.
ENDIF.
ENDLOOP.
* 계산 단수차이로 인한 차이금액을 마지막라인에 보정해 준다.
IF TOTAL_AMT NE 0.
READ TABLE XBSEG INDEX LAST_TABIX.
XBSEG-DMBTR = XBSEG-DMBTR + TOTAL_AMT.
IF XBKPF-WAERS = 'KRW'.
XBSEG-WRBTR = XBSEG-WRBTR + TOTAL_AMT.
ENDIF.
MODIFY XBSEG INDEX LAST_TABIX.
ENDIF.
ENDIF.
ENDFORM. " adjust_gl_line_non_deductible
*&---------------------------------------------------------------------*
*& Form GET_W1W2
*&---------------------------------------------------------------------*
* K가있는경우 원천세,주민세를 구한다.
*----------------------------------------------------------------------*
FORM CREATE_WITH_ITEM TABLES LT_BKPF STRUCTURE BKPF
LT_BSEG STRUCTURE BSEG
USING P_BUKRS.
DATA BEGIN OF LT_WITH_ITEM OCCURS 1.
INCLUDE STRUCTURE WITH_ITEMX .
DATA END OF LT_WITH_ITEM.
DATA LX_BSEG LIKE BSEG.
DATA LT_BSET LIKE BSET OCCURS 0 WITH HEADER LINE .
DATA : LV_COUNT(3) TYPE N,
LV_TABIX TYPE I.
READ TABLE LT_BSEG WITH KEY KOART = 'K'.
CHECK SY-SUBRC EQ 0.
LV_TABIX = SY-TABIX.
CALL FUNCTION 'FI_CHECK_EXTENDED_WT'
EXPORTING
I_BUKRS = P_BUKRS
EXCEPTIONS
COMPONENT_NOT_ACTIVE = 1
NOT_FOUND = 2
OTHERS = 3.
IF SY-SUBRC = 0.
CALL FUNCTION 'FI_WT_PUT_X_WITH_ITEM'
TABLES
T_WITH_ITEM = LT_WITH_ITEM
EXCEPTIONS
OTHERS = 1.
LOOP AT LT_BSEG WHERE KOART CA 'DK'.
CALL FUNCTION 'FI_WT_RECONSTRUCT_REFERENCEDOC'
EXPORTING
I_BSEG = LT_BSEG
IMPORTING
E_BSEG = LX_BSEG
EXCEPTIONS
OTHERS = 1.
ENDLOOP.
CALL FUNCTION 'FI_WT_FB01_CALCULATE_WT'
EXPORTING
I_AKTYP = 'H'
I_DYNCL = 'V'
TABLES
I_BKPF = LT_BKPF
I_BSEG = LT_BSEG
I_BSET = LT_BSET
EXCEPTIONS
OTHERS = 1.
CALL FUNCTION 'FI_WT_GET_X_WITH_ITEM'
TABLES
T_WITH_ITEM = LT_WITH_ITEM
EXCEPTIONS
OTHERS = 1.
DESCRIBE TABLE LT_BSEG LINES LV_COUNT.
LOOP AT LT_WITH_ITEM WHERE WT_QBSHB NE 0.
CASE LT_WITH_ITEM-WITHT.
WHEN 'K1'.
CLEAR : LT_BSEG-ZTERM.
LT_BSEG-QSSKZ = LT_WITH_ITEM-WT_WITHCD.
LT_BSEG-SAKNR = LT_BSEG-HKONT = '0000214110' .
LT_BSEG-KOART = 'S'.
LT_BSEG-DMBTR = ABS( LT_WITH_ITEM-WT_QBSHH ).
LT_BSEG-WRBTR = ABS( LT_WITH_ITEM-WT_QBSHB ).
LT_BSEG-BUZEI = LV_COUNT + 1.
WHEN 'K2'.
CLEAR : LT_BSEG-ZTERM.
LT_BSEG-QSSKZ = LT_WITH_ITEM-WT_WITHCD.
LT_BSEG-SAKNR = LT_BSEG-HKONT = '0000214120' .
LT_BSEG-KOART = 'S'.
LT_BSEG-DMBTR = ABS( LT_WITH_ITEM-WT_QBSHH ).
LT_BSEG-WRBTR = ABS( LT_WITH_ITEM-WT_QBSHB ).
LT_BSEG-BUZEI = LV_COUNT + 2.
ENDCASE.
IF LT_BSEG-SHKZG = 'H'.
LT_BSEG-BSCHL = '50'.
ELSE.
LT_BSEG-BSCHL = '40'.
ENDIF.
APPEND LT_BSEG.
ENDLOOP.
IF SY-SUBRC EQ 0.
LT_BSEG-QSSKZ = LT_WITH_ITEM-WT_WITHCD.
MODIFY LT_BSEG INDEX LV_TABIX TRANSPORTING QSSKZ.
ENDIF.
ENDIF.
ENDFORM. " GET_W1W2
댓글 없음:
댓글 쓰기