WEB UI 界面打印PDF

时间:2021-06-21 07:01:02

项目上看到的,感觉很厉害的样子,所以要存档。。。

说一下思路:画的SF,然后在WDA里调用SF,产生PDF数据流,然后在WDA里用PDF展示出来,UI调用。。。

COMPONENTCONTROLLER:

NODE:PDF

ATTRBUTE:SOURCE type XSTRING.

NODE:ORDER

ATTR:OBJECT_ID TYPE CRMT_OBJECT_ID

SMARTFORM_NAME TYPE TDSFNAME

wda VIEW:

METHOD wddomodifyview .
* variable declarations
DATA:
w_form_name TYPE tdsfname,
w_fmodule TYPE rs38l_fnam,
w_cparam TYPE ssfctrlop,
w_outoptions TYPE ssfcompop,
w_bin_filesize TYPE i, " Binary File Size
w_bin_file TYPE xstring,
w_filename TYPE string,
w_file_path TYPE string,
w_full_path TYPE string.
DATA:gv_zzafld000018 TYPE zadtel00006a.
DATA:lv_case TYPE c. DATA lo_nd_order TYPE REF TO if_wd_context_node.
DATA lo_el_order TYPE REF TO if_wd_context_element.
DATA ls_order TYPE wd_this->element_order.
DATA lo_nd_pdf TYPE REF TO if_wd_context_node.
DATA lo_el_pdf TYPE REF TO if_wd_context_element.
DATA ls_pdf TYPE wd_this->element_pdf.
DATA lv_source TYPE wd_this->element_pdf-source. lo_nd_order = wd_context->get_child_node( name = wd_this->wdctx_order ).
lo_el_order = lo_nd_order->get_element( ).
lo_el_order->get_static_attributes( IMPORTING static_attributes = ls_order ). "ADD BY LY 20170224
"维修完工报告单打印向用户收费的值为空 case 1 否则弹窗 case 2 3
IF first_time = abap_true AND ls_order-smartform_name = 'ZCRM_SERVICE_03'.
SELECT SINGLE zzafld000018 INTO gv_zzafld000018
FROM crmd_orderadm_h
WHERE object_id = ls_order-object_id.
IF gv_zzafld000018 = ''.
ELSE.
popup( ).
EXIT.
ENDIF.
ELSE.
ENDIF. zcl_crm_attributes=>gv_zcrm_print = abap_true. CALL FUNCTION 'ZSRV_PRINT_TO_PDF'
EXPORTING
iv_samrtform = ls_order-smartform_name "'ZREFUND'
iv_object_id = ls_order-object_id "'0074000104'
iv_zserialno = ls_order-zserialno "'0074000104'
iv_case = ls_order-gv_case "'0074000104'
IMPORTING
file = w_bin_file. CHECK w_bin_file IS NOT INITIAL. lo_nd_pdf = wd_context->get_child_node( name = wd_this->wdctx_pdf ).
lo_el_pdf = lo_nd_pdf->get_element( ).
lv_source = w_bin_file.
lo_el_pdf->set_attribute( name = `SOURCE` value = lv_source ).
ENDMETHOD.

VIEW布局中:

加INTERACTIVE_FORM

pdfsource 绑定source

wda WINDOW:Inbound Plugs(属性中勾选interface)

DEFAULT

WDEVENT type ref to  CL_WD_CUSTOM_EVENT
OBJECT_ID                 CRMT_OBJECT_ID
SMARTFORM_NAME     TDSFNAME

METHOD HANDLEDEFAULT .
DATA LO_ND_ORDER TYPE REF TO IF_WD_CONTEXT_NODE. DATA LO_EL_ORDER TYPE REF TO IF_WD_CONTEXT_ELEMENT.
DATA LS_ORDER TYPE WD_THIS->ELEMENT_ORDER. LO_ND_ORDER = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_ORDER ).
LO_EL_ORDER = LO_ND_ORDER->GET_ELEMENT( ).
LO_EL_ORDER->GET_STATIC_ATTRIBUTES( IMPORTING STATIC_ATTRIBUTES = LS_ORDER ). LS_ORDER-OBJECT_ID = OBJECT_ID.
LS_ORDER-SMARTFORM_NAME = SMARTFORM_NAME.
LS_ORDER-ZSERIALNO = ZSERIALNO."ADD BY LY 20170220
IF SMARTFORM_NAME = 'ZCRM_SERVICE_03'.
LS_ORDER-GV_CASE = ''.
ENDIF. LO_EL_ORDER->SET_STATIC_ATTRIBUTES( STATIC_ATTRIBUTES = LS_ORDER ).
ENDMETHOD.

UI

METHOD IF_BSP_WD_TOOLBAR_CALLBACK~GET_BUTTONS.
DATA: LS_BUTTON TYPE CRMT_THTMLB_BUTTON_EXT.
DATA: LV_URL TYPE STRING,
LV_URL2 TYPE STRING,
LV_OBJECT_ID TYPE CRMT_OBJECT_ID,
LV_SRV_TYPE TYPE ZDTEL00003Y,
LV_SMARTFORM_NAME TYPE TDSFNAME. DATA: LR_ENTITY TYPE REF TO CL_CRM_BOL_ENTITY,
LR_COLL TYPE REF TO IF_BOL_ENTITY_COL,
LR_CURRENT TYPE REF TO IF_BOL_BO_PROPERTY_ACCESS,
LR_ENTITY_ORG TYPE REF TO CL_CRM_BOL_ENTITY,
LV_PROCESS_TYPE TYPE STRING,
LS_ORGSET_BTIL TYPE CRMST_ORGSET_BTIL. FIELD-SYMBOLS: <FS_OBJECT_ID> TYPE CRMT_OBJECT_ID. CALL METHOD SUPER->IF_BSP_WD_TOOLBAR_CALLBACK~GET_BUTTONS
RECEIVING
RT_BUTTONS = RT_BUTTONS. DELETE RT_BUTTONS WHERE ON_CLICK = 'OUTPUT'.
DELETE RT_BUTTONS WHERE ON_CLICK = 'PRINT_PREVIEW'. LR_ENTITY ?= ME->ZTYPED_CONTEXT->BTADMINH->COLLECTION_WRAPPER->GET_CURRENT( ).
IF LR_ENTITY IS BOUND.
TRY.
LV_PROCESS_TYPE = LR_ENTITY->GET_PROPERTY_AS_STRING( IV_ATTR_NAME = 'PROCESS_TYPE').
CALL METHOD LR_ENTITY->IF_BOL_BO_PROPERTY_ACCESS~GET_PROPERTY_AS_VALUE
EXPORTING
IV_ATTR_NAME = 'OBJECT_ID'
IMPORTING
EV_RESULT = LV_OBJECT_ID.
LR_COLL = LR_ENTITY->GET_RELATED_ENTITIES( IV_RELATION_NAME = 'BTHeaderOrgmanSet' ). "
LR_CURRENT = LR_COLL->GET_CURRENT( ).
IF LR_CURRENT IS BOUND.
LR_ENTITY_ORG ?= LR_CURRENT.
LR_ENTITY_ORG->IF_BOL_BO_PROPERTY_ACCESS~GET_PROPERTIES( IMPORTING ES_ATTRIBUTES = LS_ORGSET_BTIL ).
ENDIF.
CATCH CX_CRM_CIC_PARAMETER_ERROR.
ENDTRY.
ENDIF. CHECK LV_OBJECT_ID IS NOT INITIAL. CHECK LV_PROCESS_TYPE = 'ZSR2' OR LV_PROCESS_TYPE = 'ZSR3' OR LV_PROCESS_TYPE = 'ZSV1' OR LV_PROCESS_TYPE = 'ZSV2' OR LV_PROCESS_TYPE = 'ZSV3' OR LV_PROCESS_TYPE = 'ZWO4'. CASE LV_PROCESS_TYPE.
WHEN 'ZSR2'.
LV_SMARTFORM_NAME = 'ZEXCH'.
CONCATENATE 'javascript:window.open( "/sap/bc/webdynpro/sap/ZCRM_PRINT' '?object_id=' LV_OBJECT_ID '&smartform_name=' LV_SMARTFORM_NAME '");' INTO LV_URL. WHEN 'ZSR3'.
LV_SMARTFORM_NAME = 'ZREFUND'.
CONCATENATE 'javascript:window.open( "/sap/bc/webdynpro/sap/ZCRM_PRINT' '?object_id=' LV_OBJECT_ID '&smartform_name=' LV_SMARTFORM_NAME '");' INTO LV_URL. WHEN 'ZSV1'.
IF LS_ORGSET_BTIL-SALES_ORG = 'O 50000178'.
LV_SMARTFORM_NAME = 'ZSRV_ORD'.
ELSEIF LS_ORGSET_BTIL-SALES_ORG = 'O 50000192' OR LS_ORGSET_BTIL-SALES_ORG = 'O 50000194'.
LV_SMARTFORM_NAME = 'ZSRV_ORD_ZA'.
ELSE.
LV_SMARTFORM_NAME = 'ZSRV_ORD_N'.
ENDIF.
* lv_smartform_name = 'ZSERVICE_ORD'.
CONCATENATE 'javascript:window.open( "/sap/bc/webdynpro/sap/ZCRM_PRINT' '?object_id=' LV_OBJECT_ID '&smartform_name=' LV_SMARTFORM_NAME '");' INTO LV_URL. * lv_smartform_name = 'ZSRV_ORD_N'.
* CONCATENATE 'javascript:window.open( "/sap/bc/webdynpro/sap/ZCRM_PRINT' '?object_id=' lv_object_id '&smartform_name=' lv_smartform_name '");' INTO lv_url2. WHEN 'ZSV2'.
IF LS_ORGSET_BTIL-SALES_ORG = 'O 50000192' OR LS_ORGSET_BTIL-SALES_ORG = 'O 50000194'.
LV_SMARTFORM_NAME = 'ZSERVICE_ORD_ZA'.
ELSE.
LV_SMARTFORM_NAME = 'ZSERVICE_ORD'.
ENDIF.
CONCATENATE 'javascript:window.open( "/sap/bc/webdynpro/sap/ZCRM_PRINT' '?object_id=' LV_OBJECT_ID '&smartform_name=' LV_SMARTFORM_NAME '");' INTO LV_URL. WHEN 'ZSV3'.
IF LS_ORGSET_BTIL-SALES_ORG = 'O 50000131'.
LV_SMARTFORM_NAME = 'ZSERVICE_ORD_AU'.
ELSEIF LS_ORGSET_BTIL-SALES_ORG = 'O 50000192' OR LS_ORGSET_BTIL-SALES_ORG = 'O 50000194'.
LV_SMARTFORM_NAME = 'ZSERVICE_ORD_ZA'.
ELSE.
LV_SMARTFORM_NAME = 'ZSERVICE_ORD'.
ENDIF.
CONCATENATE 'javascript:window.open( "/sap/bc/webdynpro/sap/ZCRM_PRINT' '?object_id=' LV_OBJECT_ID '&smartform_name=' LV_SMARTFORM_NAME '");' INTO LV_URL. WHEN 'ZWO4'.
LV_SMARTFORM_NAME = 'ZSERVICE_ORD'.
CONCATENATE 'javascript:window.open( "/sap/bc/webdynpro/sap/ZCRM_PRINT' '?object_id=' LV_OBJECT_ID '&smartform_name=' LV_SMARTFORM_NAME '");' INTO LV_URL. WHEN OTHERS.
ENDCASE. * CONCATENATE 'javascript:window.open( "/sap/bc/webdynpro/sap/ZCRM_PRINT' '?object_id=' lv_object_id '&smartform_name=' lv_smartform_name '");' INTO lv_url.
*
CLEAR LS_BUTTON.
LS_BUTTON-TEXT = CL_WD_UTILITIES=>GET_OTR_TEXT_BY_ALIAS( 'ZCRM/PDFPRINT' ). "#EC NOTEXT
LS_BUTTON-ON_CLIENT_CLICK = LV_URL.
LS_BUTTON-ENABLED = ABAP_TRUE. "#EC NOTEXT
INSERT LS_BUTTON INTO RT_BUTTONS INDEX . CALL METHOD LR_ENTITY->IF_BOL_BO_PROPERTY_ACCESS~GET_PROPERTY_AS_VALUE
EXPORTING
IV_ATTR_NAME = 'ZZFLD00000N'
IMPORTING
EV_RESULT = LV_SRV_TYPE. CLEAR:LV_URL,LS_BUTTON.
"ADD BY LY 20170224
"对于销售组织为O 50000231的维修工单(单据类型为ZSV1),在点击抬头的“Repair Rep Print”按钮时,
"判断如果维修工单抬头的量贩店延保是否向用户收费的值为空,则打印完工报告PDF,取值逻辑为Case 1。
IF LV_PROCESS_TYPE = 'ZSV1' AND LS_ORGSET_BTIL-SALES_ORG = 'O 50000231'..
LV_SMARTFORM_NAME = 'ZCRM_SERVICE_03'.
ELSE.
LV_SMARTFORM_NAME = 'ZREPAIR_REP01'.
ENDIF.
* LV_SMARTFORM_NAME = 'ZREPAIR_REP01'.
CONCATENATE 'javascript:window.open( "/sap/bc/webdynpro/sap/ZCRM_PRINT' '?object_id=' LV_OBJECT_ID '&smartform_name=' LV_SMARTFORM_NAME '");' INTO LV_URL.
LS_BUTTON-TEXT = 'Repair Rep Print'. "#EC NOTEXT
LS_BUTTON-ON_CLIENT_CLICK = LV_URL.
LS_BUTTON-ENABLED = ABAP_TRUE. "#EC NOTEXT
INSERT LS_BUTTON INTO RT_BUTTONS INDEX . IF LV_PROCESS_TYPE = 'ZSV1'.
CLEAR:LV_URL,LS_BUTTON.
LV_SMARTFORM_NAME = 'ZCRM_SERVICE_01'.
CONCATENATE 'javascript:window.open( "/sap/bc/webdynpro/sap/ZCRM_PRINT' '?object_id=' LV_OBJECT_ID '&smartform_name=' LV_SMARTFORM_NAME '");' INTO LV_URL.
LS_BUTTON-TEXT = 'Repair Follow Print'. "#EC NOTEXT
LS_BUTTON-ON_CLIENT_CLICK = LV_URL.
LS_BUTTON-ENABLED = ABAP_TRUE. "#EC NOTEXT
INSERT LS_BUTTON INTO RT_BUTTONS INDEX .
ENDIF. * CLEAR ls_button.
* ls_button-text = cl_wd_utilities=>get_otr_text_by_alias( 'ZCRM/DELIVPRT' ). "#EC NOTEXT
* ls_button-on_client_click = lv_url2.
* ls_button-enabled = abap_true. "#EC NOTEXT
* INSERT ls_button INTO rt_buttons INDEX 10. ENDMETHOD.