2009年2月6日星期五

按开票金额拆分开票zz

http://blog.vsharing.com/MilesForce/A638984.html

Symptom

The Chinese tax regulations require that any invoice issued by the Chinese companies complies with the following rules:

* The invoice can not have more than N line items. The invoice has to be printed on a pre-printed paper and the area for describing the invoiced line items is limited by the paper template used for that. The limit for the number of line items in an invoice is varying for different provinces.
* The invoice amount should not exceed a certain max. amount. This amount is different for different provinces too, but depends also on the type of the issuing company, as well as on the type of the issued document. Further information about the applicable limits for each case you can obtain at the local tax bureau.

Solution

DATA: BEGIN OF ZUK906,
MODUL(3) VALUE '906',
VTWEG LIKE VBAK-VTWEG,
SPART LIKE VBAK-SPART,
VGBEL LIKE VBRP-VGBEL,
BILLNO LIKE TVKO-MAXBI,
END OF ZUK906.

DATA: BEGIN OF SIZE_SPLIT OCCURS 0,
KUNRG LIKE VBRK-KUNRG,
KUNAG LIKE VBRK-KUNAG,
ZTERM LIKE VBRK-ZTERM.
INCLUDE STRUCTURE ZUK906.
DATA: ITEMNO LIKE TVKO-MAXBI,
AMOUNT_LEFT LIKE VBRK-NETWR.
DATA: END OF SIZE_SPLIT.

DATA: LAST_BILL_NO LIKE TVKO-MAXBI VALUE 0.

FORM DATEN_KOPIEREN_906.
DATA: MATCH_INDEX LIKE SY-TABIX value 0,
lv_Split_Amount like vbrk-netwr value 0.

* Determine split amount - any specific determination should be
* entered here! Assign value 0 in case no split is necessary.
* IMPORTANT: Split amount value should be the net amount of the billing
* document!!! Please reserve the necessary amount for taxes!!! Example:
* if VBRK-WAERK = 'CNY'.
* case VBRK-BUKRS.
* when 'CN10'. LV_SPLIT_AMOUNT = 10000000000.
* when 'CN11'. LV_SPLIT_AMOUNT = 50000000.
* when others. LV_SPLIT_AMOUNT = 0.
* endcase.
* else.
* LV_SPLIT_AMOUNT = 0.
* endif.

LV_SPLIT_AMOUNT = 200000000.

* Check if appropriate split part already exists
LOOP AT SIZE_SPLIT WHERE
KUNRG = VBRK-KUNRG AND
KUNAG = VBRK-KUNAG AND
ZTERM = VBRK-ZTERM AND
VGBEL = VBRP-VGBEL.
* Check for additional split criteria:
* max amount and max.no. of items in billing document
IF ( lv_Split_Amount is initial or "No split due to max.amount
size_split-Amount_Left >= VBRP-NETWR ) "or limit not reached
AND
( TVKO-MAXBI IS INITIAL OR "No split due to max.numbe
SIZE_SPLIT-ITEMNO < TVKO-MAXBI ). "or limit not reached
MATCH_INDEX = SY-TABIX. EXIT.
ENDIF.
ENDLOOP.
* Appropriate entry not found - load values for a new SIZE_SPLIT recor
IF MATCH_INDEX = 0.
IF LV_SPLIT_AMOUNT > 0 and VBRP-NETWR > LV_SPLIT_AMOUNT.
MESSAGE E220(F5A).
ENDIF.
CLEAR SIZE_SPLIT.
MOVE-CORRESPONDING VBRK TO SIZE_SPLIT.
MOVE-CORRESPONDING VBRP TO SIZE_SPLIT.
ADD 1 TO LAST_BILL_NO.
SIZE_SPLIT-BILLNO = LAST_BILL_NO.
SIZE_SPLIT-AMOUNT_LEFT = LV_SPLIT_AMOUNT.
ENDIF.

IF NOT TVKO-MAXBI IS INITIAL.
ADD 1 TO SIZE_SPLIT-ITEMNO.
ENDIF.
IF NOT lv_Split_Amount IS INITIAL.
SUBTRACT VBRP-NETWR FROM SIZE_SPLIT-AMOUNT_LEFT.
ENDIF.

* Store actual billing document counter and item counter
IF MATCH_INDEX = 0.
APPEND SIZE_SPLIT.
ELSE.
MODIFY SIZE_SPLIT INDEX MATCH_INDEX.
ENDIF.
ZUK906-BILLNO = SIZE_SPLIT-BILLNO.
* End of billing document split by number of allowed items
ZUK906-VTWEG = VBAK-VTWEG.
ZUK906-SPART = VBRP-SPART.
IF KURGV-PERFK = SPACE.
ZUK906-VGBEL = VBRP-VGBEL.
ENDIF.
VBRK-ZUKRI = ZUK906.

ENDFORM.

没有评论:

发表评论

博客归档