***INCLUDE MV45AFZZ .

 *---------------------------------------------------------------------*
 *       FORM ZZEXAMPLE                                                *
 *---------------------------------------------------------------------*
 *       text......................................                    *
 *---------------------------------------------------------------------*
 *FORM ZZEXAMPLE.

*  ...

*ENDFORM.

*eject
 *---------------------------------------------------------------------*
 *       FORM USEREXIT_DELETE_DOCUMENT                                 *
 *---------------------------------------------------------------------*
 *       This userexit can be used to delete data in additional tables *
 *       when a sales document is deleted.                             *
 *                                                                     *
 *      This form is called in dialog at the end of form BELEG_LOESCHEN*
 *      just before form BELEG_SICHERN is performed to delete the      *
 *      datas on the database.                                         *
 *                                                                     *
 *---------------------------------------------------------------------*
 FORM userexit_delete_document.

ENDFORM.                    "USEREXIT_DELETE_DOCUMENT
 *eject

*---------------------------------------------------------------------*
 *       FORM USEREXIT_FIELD_MODIFICATION                              *
 *---------------------------------------------------------------------*
 *       This userexit can be used to modify the attributes of         *
 *       screen fields.                                                *
 *       This form is processed for each field in the screen.          *
 *                                                                     *
 *       The use of the fields screen-group1 to screen-group4 is:      *
 *                                                                     *
 *       Screen-group1: Automatic modification contolles by transaction*
 *                      MFAW.                                          *
 *       Screen-group2: Contents 'LOO' for steploop-fields.            *
 *       Screen-group3: Used for modififaction, which are dependent on *
 *                      control tables or other fix information.       *
 *       Screen-group4: Unused                                         *
 *                                                                     *
 *       For field mofifications, which are dependent on the document  *
 *       status, you can use the status field in the workareas         *
 *       XVBAP for item status and XVBUK for header status.            *
 *                                                                     *
 *       This form is called from module FELDAUSWAHL.                  *
 *                                                                     *
 *---------------------------------------------------------------------*
 FORM userexit_field_modification.

* CASE SCREEN-GROUP3.
 *   WHEN '.
 *     IF VBAK-VBTYP NE 'A'.
 *       .
 *     ENDIF.
 * ENDCASE.
 *  CASE screen-group2.
 *    WHEN 'LOO'.
 *      '.
 *       '.
 *      ENDIF.
 *  ENDCASE.
 * CASE SCREEN-NAME.
 *   WHEN 'VBAK-VBELN'.
 *     .
 * ENDCASE.
 **    Begin v1.
 ** 以下是免费样品订单(ZFD)对售达方的类型判断,限制售达方只能是内部办事处:账户组为: Susan
   IF sy-tcode = 'VA01'  OR sy-tcode = 'VA02' .
     DATA:zktokd LIKE kna1-ktokd,kunnr LIKE vbak-kunnr.
     IF xvbak-auart = 'ZFD' AND xvbak-kunnr  IS NOT INITIAL.
 *         zktokd = kna1-ktokd while kunnr = xvbak-annr.
       SELECT SINGLE ktokd FROM kna1
         INTO zktokd
         WHERE kunnr = xvbak-kunnr.
       '.
         ) WITH '免费样品订单售达方必须是内部销售办事处'.
         EXIT.
       ENDIF.
     ENDIF.
   ENDIF.
 **   End v1.
   IF sy-tcode = 'VA01'  .

     DATA:jhzq LIKE ymara_sd-jhzq,jhzqmax LIKE ymara_sd-jhzq.
     DATA:matnr LIKE mara-matnr.
     LOOP AT xvbap WHERE matnr IS NOT INITIAL .
       CLEAR jhzq.
       SELECT SINGLE jhzq FROM ymara_sd
       INTO jhzq
       WHERE matnr = xvbap-matnr.
       IF jhzqmax < jhzq.
         jhzqmax = jhzq.
         matnr = xvbap-matnr.
       ENDIF.

    ENDLOOP.
     DATA:dat LIKE sy-datum.
     IF   matnr  IS NOT INITIAL AND jhzqmax IS NOT INITIAL.
       .
       dat = sy-datum .
       WHILE i <= jhzqmax.
         i = i +  .
         dat =   dat  +  .
 *--------------工厂日历的日期---------------------
        CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'
           EXPORTING
             date                = dat
             factory_calendar_id = 'CN'
           IMPORTING
             date                = dat.
       ENDWHILE.
 *------------------end ----------------------------
       vbak-vdatu  =  dat  .
       xvbep-edatu =  dat .
       MODIFY xvbep TRANSPORTING  edatu    WHERE   posnr IS NOT INITIAL .

      ) WITH '该订单最长交货物料为' matnr '天数为:' jhzqmax.
     ENDIF.
   ENDIF.
 ENDFORM.                    "USEREXIT_FIELD_MODIFICATION
 *eject

*---------------------------------------------------------------------*
 *       FORM USEREXIT_MOVE_FIELD_TO_VBAK                              *
 *---------------------------------------------------------------------*
 *       This userexit can be used to move some fields into the sales  *
 *       dokument header workaerea VBAK.                               *
 *                                                                     *
 *       SVBAK-TABIX = :  Create header                               *
 *       SVBAK-TABIX > :  Change header                               *
 *                                                                     *
 *       This form is called at the end of form VBAK_FUELLEN.          *
 *                                                                     *
 *---------------------------------------------------------------------*
 FORM userexit_move_field_to_vbak.
 *DATA:jhzq LIKE ymara_sd-jhzq,jhzqmax LIKE ymara_sd-jhzq.
 *
 *  LOOP AT xvbap WHERE matnr IS NOT INITIAL .
 *    CLEAR jhzq.
 *    select single jhzq FROM ymara_sd
 *    INTO jhzq
 *    where matnr = xvbap-matnr.
 *    IF jhzqmax < jhzq.
 *      jhzqmax = jhzq.
 *    ENDIF.
 *    xvbep-edatu = sy-datum -  jhzq .
 *    xvbep-bddat = sy-datum -  jhzq .
 *    xvbep-tddat = sy-datum -  jhzq .
 *    xvbep-mbdat = sy-datum -  jhzq .
 *    xvbep-lddat = sy-datum -  jhzq .
 *    xvbep-wadat = sy-datum -  jhzq .
 *    MODIFY xvbep TRANSPORTING
 *    edatu
 *    bddat
 *    tddat
 *    mbdat
 *    lddat
 *    wadat
 *    WHERE   posnr = xvbap-posnr. .
 *  ENDLOOP.
 *  vbak-vdatu  = sy-datum -  jhzqmax .

ENDFORM.                    "USEREXIT_MOVE_FIELD_TO_VBAK
 *eject

*---------------------------------------------------------------------*
 *       FORM USEREXIT_MOVE_FIELD_TO_VBAP                              *
 *---------------------------------------------------------------------*
 *       This userexit can be used to move some fields into the sales  *
 *       dokument item workaerea VBAP                                  *
 *                                                                     *
 *       SVBAP-TABIX = :  Create item                                 *
 *       SVBAP-TABIX > :  Change item                                 *
 *                                                                     *
 *       This form is called at the end of form VBAP_FUELLEN.          *
 *                                                                     *
 *---------------------------------------------------------------------*
 FORM userexit_move_field_to_vbap.
 *
 *  DATA:jhzq LIKE ymara_sd-jhzq,jhzqmax LIKE ymara_sd-jhzq.
 *
 *  LOOP AT xvbap WHERE matnr IS NOT INITIAL .
 *    CLEAR jhzq.
 *    select single jhzq FROM ymara_sd
 *    INTO jhzq
 *    where matnr = xvbap-matnr.
 *    IF jhzqmax < jhzq.
 *      jhzqmax = jhzq.
 *    ENDIF.
 **    xvbep-edatu = sy-datum -  jhzq .
 **    xvbep-bddat = sy-datum -  jhzq .
 **    xvbep-tddat = sy-datum -  jhzq .
 **    xvbep-mbdat = sy-datum -  jhzq .
 **    xvbep-lddat = sy-datum -  jhzq .
 **    xvbep-wadat = sy-datum -  jhzq .
 **    MODIFY xvbep TRANSPORTING
 **    edatu
 **    bddat
 **    tddat
 **    mbdat
 **    lddat
 **    wadat
 **    WHERE   posnr = xvbap-posnr. .
 *  ENDLOOP.
 *  vbak-vdatu  = sy-datum -  jhzqmax .
 *
 ENDFORM.                    "USEREXIT_MOVE_FIELD_TO_VBAP
 *eject

*---------------------------------------------------------------------*
 *       FORM USEREXIT_MOVE_FIELD_TO_VBEP                              *
 *---------------------------------------------------------------------*
 *       This userexit can be used to move some fields into the sales  *
 *       dokument schedule line workaerea VBEP                         *
 *                                                                     *
 *       SVBEP-TABIX = :  Create schedule line                        *
 *       SVBEP-TABIX > :  Change schedule line                        *
 *                                                                     *
 *       This form is called at the end of form VBEP_FUELLEN.          *
 *                                                                     *
 *---------------------------------------------------------------------*
 FORM userexit_move_field_to_vbep.
   DATA:jhzq LIKE ymara_sd-jhzq,jhzqmax LIKE ymara_sd-jhzq.
   CLEAR jhzq.
 *
 *  LOOP AT xvbep  .
 *
 **    CLEAR jhzq.
 *    READ TABLE xvbap WITH KEY vbeln = xvbep-vbeln posnr = xvbep-posnr.
 *    SELECT SINGLE jhzq FROM ymara_sd
 *    INTO jhzq
 *    WHERE matnr = xvbap-matnr.
 *    IF jhzqmax < jhzq.
 *      jhzqmax = jhzq.
 *    ENDIF.
 *    xvbep-edatu = sy-datum -  jhzq .
 *    xvbep-bddat = sy-datum -  jhzq .
 *    xvbep-tddat = sy-datum -  jhzq .
 *    xvbep-mbdat = sy-datum -  jhzq .
 *    xvbep-lddat = sy-datum -  jhzq .
 *    xvbep-wadat = sy-datum -  jhzq .
 *    MODIFY xvbep  .
 *  ENDLOOP.
 *  vbak-vdatu  = sy-datum -  jhzqmax .
 *  rv45a-etdat = sy-datum -  jhzqmax .
 ENDFORM.                    "USEREXIT_MOVE_FIELD_TO_VBEP
 *eject

*---------------------------------------------------------------------*
 *       FORM USEREXIT_MOVE_FIELD_TO_VBKD                              *
 *---------------------------------------------------------------------*
 *       This userexit can be used to move some fields into the sales  *
 *       dokument business data workaerea VBKD                         *
 *                                                                     *
 *       SVBKD-TABIX = :  Create data                                 *
 *       SVBKD-TABIX > :  Change data                                 *
 *                                                                     *
 *       This form is called at the end of form VBKD_FUELLEN.          *
 *                                                                     *
 *---------------------------------------------------------------------*
 FORM userexit_move_field_to_vbkd.

*
 *  VBKD-zzfield = xxxx-zzfield2.

ENDFORM.                    "USEREXIT_MOVE_FIELD_TO_VBKD
 *eject

*---------------------------------------------------------------------*
 *       FORM USEREXIT_NUMBER_RANGE                                    *
 *---------------------------------------------------------------------*
 *       This userexit can be used to determine the numberranges for   *
 *       the internal document number.                                 *
 *                                                                     *
 *       US_RANGE_INTERN - internal number range                       *
 *                                                                     *
 *       This form is called from form BELEG_SICHERN                   *
 *                                                                     *
 *---------------------------------------------------------------------*
 FORM userexit_number_range USING us_range_intern.

* Example: Numer range from TVAK like in standard
 * US_RANGE_INTERN = TVAK-NUMKI.
 ENDFORM.                    "USEREXIT_NUMBER_RANGE
 *eject

*---------------------------------------------------------------------*
 *       FORM USEREXIT_PRICING_PREPARE_TKOMK                           *
 *---------------------------------------------------------------------*
 *       This userexit can be used to move additional fields into the  *
 *       communication table which is used for pricing:                *
 *                                                                     *
 *       TKOMK for header fields                                       *
 *                                                                     *
 *       This form is called from form PREISFINDUNG_VORBEREITEN.       *
 *                                                                     *
 *---------------------------------------------------------------------*
 FORM userexit_pricing_prepare_tkomk.
   CLEAR tkomk-vrtnr.
   PERFORM xvbpa_lesen(sapfv45k) USING 'VE'
                                       vbap-posnr
                                       sy-tabix.
   IF xvbpa-updkz <> 'D'.
     tkomk-vrtnr = xvbpa-pernr.
   ENDIF.

*  TKOMK-zzfield = xxxx-zzfield2.

ENDFORM.                    "USEREXIT_PRICING_PREPARE_TKOMK
 *eject

*---------------------------------------------------------------------*
 *       FORM USEREXIT_PRICING_PREPARE_TKOMP                           *
 *---------------------------------------------------------------------*
 *       This userexit can be used to move additional fields into the  *
 *       communication table which is used for pricing:                *
 *                                                                     *
 *       TKOMP for item fields                                         *
 *                                                                     *
 *       This form is called from form PREISFINDUNG_VORBEREITEN.       *
 *                                                                     *
 *---------------------------------------------------------------------*
 FORM userexit_pricing_prepare_tkomp.

*  TKOMP-zzfield = xxxx-zzfield2.

ENDFORM.                    "USEREXIT_PRICING_PREPARE_TKOMP
 *eject

*---------------------------------------------------------------------*
 *       FORM USEREXIT_READ_DOCUMENT                                   *
 *---------------------------------------------------------------------*
 *       This userexit can be used to read data in additional tables   *
 *       when the program reads a sales document.                      *
 *                                                                     *
 *       This form is called at the end of form BELEG_LESEN.           *
 *                                                                     *
 *---------------------------------------------------------------------*
 FORM userexit_read_document.

ENDFORM.                    "USEREXIT_READ_DOCUMENT
 *eject

*---------------------------------------------------------------------*
 *       FORM USEREXIT_SAVE_DOCUMENT                                   *
 *---------------------------------------------------------------------*
 *       This userexit can be used to save data in additional tables   *
 *       when a document is saved.                                     *
 *                                                                     *
 *       If field T180-TRTYP contents 'H', the document will be        *
 *       created, else it will be changed.                             *
 *                                                                     *
 *       This form is called at from form BELEG_SICHERN, before COMMIT *
 *                                                                     *
 *---------------------------------------------------------------------*
 FORM userexit_save_document.

* Example:
 * CALL FUNCTION 'ZZ_EXAMPLE'
 *      IN UPDATE TASK
 *      EXPORTING
 *           ZZTAB = ZZTAB.
 *DATA:jhzq LIKE ymara_sd-jhzq,jhzqmax LIKE ymara_sd-jhzq.
 *  LOOP AT xvbap WHERE matnr IS NOT INITIAL.
 *    CLEAR jhzq.
 *    SELECT SINGLE jhzq FROM ymara_sd
 *    INTO jhzq
 *    WHERE matnr = xvbap-matnr.
 *    IF jhzqmax < jhzq.
 *      jhzqmax = jhzq.
 *    ENDIF.
 *
 *
 *  ENDLOOP.
 *  vbak-vdatu  = sy-datum -  jhzqmax .
 *  rv45a-etdat = sy-datum -  jhzqmax .
 ENDFORM.                    "USEREXIT_SAVE_DOCUMENT
 *eject

*&---------------------------------------------------------------------*
 *&      Form  zcheck_ggdd
 *&---------------------------------------------------------------------*
 *       text 广告物料订单判断
*----------------------------------------------------------------------*
 *      -->EXITFLAG   text 检验是否通过
*----------------------------------------------------------------------*
FORM  zcheck_ggdd USING exitflag.
 * RETURN.
   exitflag = .
   IF sy-tcode <> 'VA01' AND sy-tcode <> 'VA02'.
     RETURN.
   ENDIF.

**  销售凭证订单原因 306 促销赠品 307  广告物料 V1.0 ZHOUXU
   LOOP AT xvbap.
 **  销售凭证类型广告物料凭着
    IF xvbak-auart = 'ZGOR'.
       IF  xvbap-pstyv = 'Z002' ."促销品
*          MESSAGE    '订单原因促销赠品项目类别只能为促销品' TYPE 'E'.
         '.
 **       begin V1.1暂时取消促销品的增强
*          MESSAGE e005(ymess) WITH  '项目类别促销品订单原因只能为促销赠品!'  .
 *          exitflag =  .
 *          RETURN.
 **       end V1.
         ENDIF.
       ENDIF.
       IF  xvbap-pstyv = 'ZGAN' OR  xvbap-pstyv = 'Z001'." ZGAN 宣传品,展示品
        '.
 *          MESSAGE    '订单原因为"广告物料"项目类别只能为宣传品或展示品!' TYPE 'E'.
           MESSAGE e005(ymess) WITH '项目类别宣传品或展示品订单原因只能为广告物料!'.
           exitflag =  .
           RETURN.
         ENDIF.
       ENDIF.
     ENDIF.
 **    Z001 V1. ZHOUXU
     IF xvbak-auart = 'Z001'.
       IF  xvbap-pstyv = 'Z003' OR  xvbap-pstyv = 'Z004'.
         ) <> '.
 *          MESSAGE    '订单原因为"广告物料"项目类别只能为宣传品或展示品!' TYPE 'E'.
           MESSAGE e005(ymess) WITH '项目类型为办公用品或样品领用时不能选此订单原因 !'.
           exitflag =  .
           RETURN.
         ENDIF.

      ENDIF.
     ENDIF .
   ENDLOOP.

ENDFORM.                    "zcheck_ggdd
 *---------------------------------------------------------------------*
 *       FORM USEREXIT_SAVE_DOCUMENT_PREPARE                           *
 *---------------------------------------------------------------------*
 *       This userexit can be used for changes or checks, before a     *
 *       document is saved.                                            *
 *                                                                     *
 *       If field T180-TRTYP contents 'H', the document will be        *
 *       created, else it will be changed.                             *
 *                                                                     *
 *       This form is called at the beginning of form BELEG_SICHERN    *
 *                                                                     *
 *---------------------------------------------------------------------*
 FORM userexit_save_document_prepare.

  IF sy-tcode = 'CO06'.
     EXIT.
   ENDIF.
   DATA:exitflag TYPE i.
 *-----------------V1. ZHOUXU 广告订单判断---------------------------
  PERFORM zcheck_ggdd USING exitflag.
    .
     EXIT.
   ENDIF.
   DATA: lx_vbak LIKE vbak.
   DATA: zkbetr LIKE xkomv-kbetr.
    DECIMALS  VALUE '150.00',
         zprice2  DECIMALS  VALUE '50.00'.
   SELECT SINGLE * INTO lx_vbak
     FROM vbak WHERE vbeln = xvbak-vbeln.
   IF vbak-kvgr1 <> lx_vbak-kvgr1.
     AUTHORITY-CHECK OBJECT 'ZHLSDPR'
      '.
     .
       ) WITH '你没有权限审批价格!'.
       xvbak-kvgr1 = lx_vbak-kvgr1.
       vbak-kvgr1 = lx_vbak-kvgr1.
     ENDIF.
   ENDIF.
   IF vbak-kvgr2 <> lx_vbak-kvgr2.
     AUTHORITY-CHECK OBJECT 'ZHLSDPR'
      '.
     .
       ) WITH '你没有权限审批价格!'.
       xvbak-kvgr2 = lx_vbak-kvgr2.
       vbak-kvgr2 = lx_vbak-kvgr2.
     ENDIF.
   ENDIF.
   IF vbak-kvgr3 <> lx_vbak-kvgr3.
     AUTHORITY-CHECK OBJECT 'ZHLSDPR'
      '.
     .
       ) WITH '你没有权限审批价格!'.
       xvbak-kvgr3 = lx_vbak-kvgr3.
       vbak-kvgr3 = lx_vbak-kvgr3.
     ENDIF.
   ENDIF.
   IF vbak-kvgr4 <> lx_vbak-kvgr4.
     AUTHORITY-CHECK OBJECT 'ZHLSDPR'
      '.
     .
       ) WITH '你没有权限审批价格!'.
       xvbak-kvgr4 = lx_vbak-kvgr4.
       vbak-kvgr4 = lx_vbak-kvgr4.
     ENDIF.
   ENDIF.
   LOOP AT xkomv.
     CASE xkomv-kschl.
       WHEN 'ZK04'.
         IF vbak-kvgr5 IS INITIAL.
           CASE   xvbak-auart.
             WHEN 'OR' OR 'ZTOR' OR 'ZYOR' OR 'ZDOR'.
               MESSAGE e005(ymess) WITH '已维护ZK04和ZK07的折扣,请选择折扣性质!'.
           ENDCASE.
         ENDIF.

        .
           zkbetr = ABS( xkomv-kbetr ).
           IF zkbetr GT zprice1.
             '.
               xvbak-kvgr3 = '.
               vbak-kvgr3 = '.
               ) WITH '订单折扣率高于15%,需要审批 '.
               xvbak-lifsk = '.
               vbak-lifsk = '.
             ENDIF.
             '.
               xvbak-kvgr2 = '.
               vbak-kvgr2 = '.
               ) WITH '订单折扣率高于5%,需要审批 '.
               xvbak-lifsk = '.
               vbak-lifsk = '.
             ENDIF.
             '.
               xvbak-kvgr1 = '.
               vbak-kvgr1 = '.
               ) WITH '订单折扣,需要审批 '.
               xvbak-lifsk = '.
               vbak-lifsk = '.
             ENDIF.

            EXIT.
           ELSEIF zkbetr GT zprice2.
             xvbak-kvgr3 = ' '.
             vbak-kvgr3 = ' '.
             '.
               xvbak-kvgr2 = '.
               vbak-kvgr2 = '.
               ) WITH '订单折扣率高于5%,需要审批 '.
               xvbak-lifsk = '.
               vbak-lifsk = '.
             ENDIF.
             '.
               xvbak-kvgr1 = '.
               vbak-kvgr1 = '.
               ) WITH '订单折扣,需要审批 '.
               xvbak-lifsk = '.
               vbak-lifsk = '.
             ENDIF.
             EXIT.

          ELSE.
             xvbak-kvgr3 = ' '.
             vbak-kvgr3 = ' '.
             xvbak-kvgr2 = ' '.
             vbak-kvgr2 = ' '.
             '.
               xvbak-kvgr1 = '.
               vbak-kvgr1 = '.
               ) WITH '订单折扣率产生,需要审批 '.
               xvbak-lifsk = '.
               vbak-lifsk = '.
             ENDIF.
             EXIT.
           ENDIF.
         ENDIF.
 *----------------------------------------------------20081010ZK07增加
      WHEN 'ZK07'.
         IF vbak-kvgr5 IS INITIAL.
           CASE   xvbak-auart.
             WHEN 'OR' OR 'ZTOR' OR 'ZYOR' OR 'ZDOR'.
               MESSAGE e005(ymess) WITH '已维护ZK04和ZK07的折扣!请选择折扣性质!'.
           ENDCASE.
         ENDIF.

        .
           zkbetr = ABS( xkomv-kbetr ).
           IF zkbetr GT zprice1.
             '.
               xvbak-kvgr3 = '.
               vbak-kvgr3 = '.
               ) WITH '订单折扣率高于15%,需要审批 '.
               xvbak-lifsk = '.
               vbak-lifsk = '.
             ENDIF.
             '.
               xvbak-kvgr2 = '.
               vbak-kvgr2 = '.
               ) WITH '订单折扣率高于5%,需要审批 '.
               xvbak-lifsk = '.
               vbak-lifsk = '.
             ENDIF.
             '.
               xvbak-kvgr1 = '.
               vbak-kvgr1 = '.
               ) WITH '订单折扣,需要审批 '.
               xvbak-lifsk = '.
               vbak-lifsk = '.
             ENDIF.

            EXIT.
           ELSEIF zkbetr GT zprice2.
             xvbak-kvgr3 = ' '.
             vbak-kvgr3 = ' '.
             '.
               xvbak-kvgr2 = '.
               vbak-kvgr2 = '.
               ) WITH '订单折扣率高于5%,需要审批 '.
               xvbak-lifsk = '.
               vbak-lifsk = '.
             ENDIF.
             '.
               xvbak-kvgr1 = '.
               vbak-kvgr1 = '.
               ) WITH '订单折扣,需要审批 '.
               xvbak-lifsk = '.
               vbak-lifsk = '.
             ENDIF.
             EXIT.

          ELSE.
             xvbak-kvgr3 = ' '.
             vbak-kvgr3 = ' '.
             xvbak-kvgr2 = ' '.
             vbak-kvgr2 = ' '.
             '.
               xvbak-kvgr1 = '.
               vbak-kvgr1 = '.
               ) WITH '订单折扣率产生,需要审批 '.
               xvbak-lifsk = '.
               vbak-lifsk = '.
             ENDIF.
             EXIT.
           ENDIF.
         ENDIF.

    ENDCASE.
   ENDLOOP.
 *----------------------------------------------------20081009增加修改订单冻结判断.
   DATA: lx_vbap LIKE vbap.
   DATA  l_vbap LIKE vbap .
   DATA  l_vbap2 LIKE vbap .
   DATA  t_vbap TYPE TABLE OF vbap.
   DATA  t_vbap2 TYPE TABLE OF vbap.
   DATA: lx_vbep LIKE vbep.
   DATA: lx_konv LIKE konv.
   DATA: lx_konv1 LIKE konv.
   DATA: zkbetr1 LIKE xkomv-kbetr.

  DATA: lx_jsto LIKE jsto.
   DATA: lx_tj30 LIKE tj30.
   DATA: lx_jest LIKE jest.

  CLEAR zkbetr1.
   IF sy-tcode = 'VA02'.

    '.
       LOOP AT xvbap.
         SELECT SINGLE *
         INTO lx_vbap
         FROM vbap
         WHERE vbeln = xvbap-vbeln AND posnr = xvbap-posnr.
         .
           xvbak-kvgr4 = '.
           vbak-kvgr4 = '.
           ) WITH '订单折扣率已经审批,修改后需要再次审批 '.
           xvbak-lifsk = '.
           vbak-lifsk = '.
           EXIT.
         ENDIF.
         SELECT SINGLE *
         INTO lx_konv
         FROM konv
         WHERE knumv = xvbak-knumv  AND kposn = xvbap-posnr AND kschl = 'ZK04'.
         SELECT SINGLE *
         INTO lx_konv1
         FROM konv
         WHERE knumv = xvbak-knumv  AND kposn = xvbap-posnr AND kschl = 'ZK07'.
         IF lx_konv-kbetr NE space .
           zkbetr1 = ABS( lx_konv-kbetr ).
           IF xvbap-matnr NE lx_vbap-matnr OR
              xvbap-kwmeng GT lx_vbap-kwmeng OR
              zkbetr GT zkbetr1.
             xvbak-kvgr4 = '.
             vbak-kvgr4 = '.
             ) WITH '订单折扣率已经审批,修改后需要再次审批 '.
             xvbak-lifsk = '.
             vbak-lifsk = '.

            EXIT.
           ENDIF.
         ENDIF.
         IF lx_konv1-kbetr NE space .
           zkbetr1 = ABS( lx_konv1-kbetr ).
           IF xvbap-matnr NE lx_vbap-matnr OR
            xvbap-kwmeng GT lx_vbap-kwmeng OR
            zkbetr GT zkbetr1.
             xvbak-kvgr4 = '.
             vbak-kvgr4 = '.
             ) WITH '订单折扣率已经审批,修改后需要再次审批 '.
             xvbak-lifsk = '.
             vbak-lifsk = '.

            EXIT.
           ENDIF.
         ENDIF.

      ENDLOOP.
     ENDIF.

****增加有条件未审批时,不允许修改订单交货状态 add by LKJ 2009/02/25
     ' ).

      AUTHORITY-CHECK OBJECT 'ZHLSDPR'
          '.
       .
         ) WITH '订单价格、折扣未审批,无权修改状态!'.
         xvbak-lifsk = '.
         vbak-lifsk = '.
       ENDIF.

    ENDIF.
 ***** add end

 **** 订单的对象状态审核
**** 如果未审核,可以修改数据,如果已审核,不能做任何更改 *****
     IF lx_vbak-objnr NE space." AND ( sy-uname = 'E464503' or sy-uname = 'E422038' or sy-uname = 'E422083' or sy-uname = 'E423726').

      DATA role TYPE c VALUE 'Y'.

      SELECT SINGLE * INTO lx_jest
           FROM jest WHERE objnr EQ lx_vbak-objnr AND inact EQ 'X'.

      IF lx_jest-stat EQ 'E0001'.
         AUTHORITY-CHECK OBJECT 'B_USERSTAT'
             ID 'BERSL' FIELD 'ZSDAU001'.

        ."无审核权限,检查已修改的数据条件(刷可用量)
           role = 'N'.
 *        ) WITH '订单对象状态审批通过,无反审核权限!'.
 *        LEAVE TO CURRENT TRANSACTION.
         ELSE.
           role = 'Y'.
         ENDIF.
         DATA:netwr LIKE vbap-netwr .
         DATA:temp TYPE string.
         LOOP AT xvbap INTO l_vbap.

          APPEND l_vbap TO t_vbap2.
           SELECT SINGLE *
              INTO l_vbap2
           FROM vbap
           WHERE vbeln = l_vbap-vbeln AND posnr = l_vbap-posnr.

*      l_vbap2-aedat = sy-datum."del v1.6
           l_vbap2-aedat = l_vbap-aedat.                     "add v1.6
           l_vbap2-klmeng = l_vbap-klmeng.
           l_vbap2-kbmeng = l_vbap-kbmeng.
           l_vbap2-abgru = l_vbap-abgru.
 **
           CLEAR netwr.
           netwr = l_vbap-netwr - l_vbap2-netwr.
           netwr = ABS( netwr ).
           temp =  netwr.
           CONDENSE temp.
           ' .
             l_vbap2-netwr = l_vbap-netwr.
           ENDIF.
 **end v1.
 **begin v1.
           CLEAR netwr.
           netwr = l_vbap-mwsbp - l_vbap2-mwsbp.
           netwr = ABS( netwr ).
           temp =  netwr.
           CONDENSE temp.
           ' .
             l_vbap2-mwsbp = l_vbap-mwsbp.
           ENDIF.

**end v1.5
 **begin v1..
           CLEAR netwr.
           netwr = l_vbap-netpr - l_vbap2-netpr.
           netwr = ABS( netwr ).
           temp =  netwr.
           CONDENSE temp.
           ' .
             l_vbap2-netpr = l_vbap-netpr.
           ENDIF.
 **end v1.
 **    Begin v1.
 **以下是免费样品订单(ZFD),广告物料订单(ZGOR)审核后不允许修改的字段内容:
 **
 **,订单抬头:售达方,送达方,成本中心;
 **,订单明细:物料编码,数量,增删行项目.
           IF xvbak-auart = 'ZGOR' OR  xvbak-auart = 'ZFD'.
             l_vbap2-netwr = l_vbap-netwr.
             l_vbap2-mwsbp = l_vbap-mwsbp.
             l_vbap2-netpr = l_vbap-netpr.
           ENDIF.

**   End v1.8
 **    Begin v1.
 ** 以下是免费样品订单(ZFD)对售达方的类型判断,限制售达方只能是内部办事处:账户组为: Susan 

          DATA:zktokd LIKE kna1-ktokd,kunnr LIKE vbak-kunnr.
           IF xvbak-auart = 'ZFD'.
 *         zktokd = kna1-ktokd while kunnr = xvbak-annr.
             SELECT SINGLE ktokd FROM kna1
               INTO zktokd
               WHERE kunnr = xvbak-kunnr.
             '.
               MESSAGE e005(ymess)  WITH '免费样品订单售达方必须是内部销售办事处'.
               EXIT.
             ENDIF.
           ENDIF.

**   End v1.9
           APPEND l_vbap2 TO t_vbap.

          CLEAR: l_vbap,l_vbap2.

        ENDLOOP.

        lx_vbak-faksk = vbak-faksk .
         xvbak-faksk = vbak-faksk .

**Begin v1.2

        lx_vbak-kvgr1 = vbak-kvgr1.
         lx_vbak-kvgr2 = vbak-kvgr2.
         lx_vbak-kvgr3 = vbak-kvgr3.
         lx_vbak-kvgr4 = vbak-kvgr4.
         lx_vbak-kvgr5 = vbak-kvgr5.
         lx_vbak-lifsk = vbak-lifsk.
 **End v1.

**Begin v1.6
         lx_vbak-aedat = vbak-aedat.
 **End v1.
 **
 *    DATA:netwr LIKE vbak-netwr .
         CLEAR netwr.
         netwr = lx_vbak-netwr - vbak-netwr.
         netwr = ABS( netwr ).
         temp =  netwr.
         CONDENSE temp.
         ' .
           lx_vbak-netwr = vbak-netwr.
         ENDIF.
 **
 **    Begin v1.
 **以下是免费样品订单(ZFD),广告物料订单(ZGOR)审核后不允许修改的字段内容:
 **
 **,订单抬头:售达方,送达方,成本中心;
 **,订单明细:物料编码,数量,增删行项目.
         IF xvbak-auart = 'ZGOR' OR  xvbak-auart = 'ZFD'.
           lx_vbak-netwr = vbak-netwr.
         ENDIF.

**   End v1.8
 *      LOOP AT xvbep.
 *        SELECT SINGLE *
 *        INTO lx_vbep
 *        FROM vbep
 *        WHERE vbeln = xvbep-vbeln AND posnr = xvbep-posnr AND bmeng = xvbep-bmeng AND edatu = sy-datum.
 *      ENDLOOP.

        IF xvbak EQ lx_vbak OR vbak EQ lx_vbak . "如果订单抬头被更改
          IF t_vbap2 EQ t_vbap.
 *               if role = 'N'.
 *                  ) WITH '订单对象状态审批通过,无反审核权限!'.
 *                  LEAVE TO CURRENT TRANSACTION.
 *               else.
 *                 exit.
 *              endif.
             EXIT.
           ELSE.
             ) WITH '订单对象状态审批通过,不允许修改订单行项目数据!'.
             LEAVE TO CURRENT TRANSACTION.
           ENDIF.
           EXIT.
         ELSE.
           ) WITH '订单对象状态审批通过,不允许修改抬头订单数据!'.
           LEAVE TO CURRENT TRANSACTION.
         ENDIF.
         EXIT.
       ENDIF.
     ENDIF.

   ENDIF.
 ENDFORM.                    "USEREXIT_SAVE_DOCUMENT_PREPARE *eject

随机推荐

  1. AppCan认为,移动APP开发不是技术活

    很多粉丝反应,AppCan的文章太专业了,技术大大们毫不费劲,小白看的晕乎乎. 时代变了,5年前,AppCan的受众只有开发者.现在,政府高管.集团董事长.非技术类管理者.中小企业主.各行各业的管理者 ...

  2. The Automated Testing Handbook 自动化测试手册简介

    Learn what works, what doesn't and why. The Automated Testing Handbook is a practical blueprint for ...

  3. Qt入门(7)——QApplication类

    QApplication类管理图形用户界面应用程序的控制流和主要设置.它包含主事件循环,在其中来自窗口系统和其它资源的所有事件被处理和调度.也用于处理应用程序的初始化和结束,并且提供对话管理.它也处理 ...

  4. struts1:(Struts重构)构建一个简单的基于MVC模式的JavaWeb

    在构建一个简单的基于MVC模式的JavaWeb 中,我们使用了JSP+Servlet+JavaBean构建了一个基于MVC模式的简单登录系统,但在其小结中已经指出,这种模式下的Controller 和 ...

  5. C++学习笔记13-类继承

    1.  类模板的 static 成员[不同于C#中的static] 类模板能够像随意其它类一样声明static 成员.下面代码: template <class T> class Foo ...

  6. Ajax验证用户名是否被注册

    Ajax验证用户名是否被注册 var xmlHttp; function createXMLHttpRequest(){ // 创建XMLHttp请求对象 if(window.ActiveXObjec ...

  7. canvas-color的几种设置

    #ffff #642 = #664422 rgb(255,128,0) rgba(100,100,100,0.8) hsl(20,62%,28%) hsla(40,82%,33%,0.6) red

  8. odoo开发笔记 -- context上下文

    字段级别 视图级别 窗口动作级别

  9. QuantLib 金融计算——修复 BatesProcess 中的两个 Bug

    QuantLib 金融计算--修复 BatesProcess 中的两个 Bug 我发现了 BatesProcess 中的两个 Bug: 基类 HestonProcess::factors 的返回值取决 ...

  10. JDK源码分析(五)——HashSet

    目录 HashSet概述 内部字段及构造方法 存储元素 删除元素 包含元素 总结 HashSet概述   从前面开始,已经分析过集合中的List和Map,今天来介绍另一种集合元素:Set.这是JDK对 ...