MeMi和MGV数量类型确认逻辑
MeMi和MGV数量类型确认逻辑
1. 原始MeMi document
在类/US4G/CL_MEMI_API的方法 /US4G/IF_MEMI_API_MAIN~CALCULATE_MEMI_DOC 中实现。
1.1 确定MeMi的数量类型
调用类/US4G/CL_MEMI_DETERMINATION的方法/US4G/IF_MEMI_DETERMINATION~DET_MEMI_QUANTITY。
"Determine MeMi quantities
mo_memi_determination->det_memi_quantity(
EXPORTING
is_memi_doc_tp = <ls_memi_doc_tp>
IMPORTING
ev_quantity = <ls_memi_doc_tp>-quantity
ev_quantity_type = <ls_memi_doc_tp>-quantity_type
ev_measure_unit = <ls_memi_doc_tp>-measure_unit
).
-
根据Energy Direction确定MeMI quantity
如果Energy Direction是Feed-in(Z06) ,则用GU Quantity减去Settle Quantity。如果Energy Direction是Supply(Z07) ,则用Settle Quantity减去GU Quantity。
"determine MEMI quantity according to energy direction "energy direction is feed-in IF is_memi_doc_tp-suppl_dir = /us4g/if_constants_gpke=>gc_sup_direct_feeding. ev_quantity = is_memi_doc_tp-gu_quantity - is_memi_doc_tp-settle_quantity. "energy direction is supply ELSEIF is_memi_doc_tp-suppl_dir = /us4g/if_constants_gpke=>gc_sup_direct_supply. ev_quantity = is_memi_doc_tp-settle_quantity - is_memi_doc_tp-gu_quantity. ENDIF. -
根据MeMI Quantity确定Quantity Type
如果MeMi Quantity大于零,则Quantity Type为Overtake,否则Undertake."MeMi quantity type IF is_memi_doc_tp-quantity > 0. ev_quantity_type = /us4g/if_constants_billing=>gc_memi_qty_type_overtake. ELSE. ev_quantity_type = /us4g/if_constants_billing=>gc_memi_qty_type_undertake. ENDIF. ``` -
MeMi Quantity保存正值(取绝对值)
"MeMi quantity should always be positive ev_quantity = abs( ev_quantity ).
1.2 确定MGV的数量类型
如果DIVISION是GAS,则调用BADI /US4G/BADI_MEMI_DET 的fallback class /US4G/CL_DEF_BADI_MEMI_DET的方法/US4G/IF_BADI_MEMI_DET~CALC_SPLIT_MGV_INF。
TRY .
IF /ucom/cl_ap_cross_factory=>get_config_access_acc( )->get_division_category(
iv_sparte = <ls_memi_doc_tp>-division )
= /us4g/if_constants_gpke=>gc_division_cat_gas.
* Calculate quantity of MGV Info for split MeMi document
GET BADI lr_badi_memi_det.
CALL BADI lr_badi_memi_det->calc_split_mgv_info
EXPORTING
is_memi_doc = <ls_memi_doc_tp>
CHANGING
ct_mgv_info = lt_memi_mgv_info_tp.
ENDIF.
CATCH /ucom/cx_general INTO lo_previous.
/us4g/cx_general=>raise_exception_from_msg( ir_previous = lo_previous ).
CATCH cx_badi_not_implemented.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO mv_mtext.
/us4g/cx_general=>raise_exception_from_msg( ).
ENDTRY.
- 根据Energy Direction确定MeMI quantity
如果Energy Direction是Feed-in(Z06) ,则用GU Quantity减去Settle Quantity。
如果Energy Direction是Supply(Z07) ,则用Settle Quantity减去GU Quantity。
CASE is_memi_doc-suppl_dir.
"energy feeding
WHEN /us4g/if_constants_billing=>gc_supply_direct_z06.
ls_mgv_info-quantity = ls_mgv_info-gu_quantity - ls_mgv_info-settle_quantity.
"supply consumption
WHEN /us4g/if_constants_billing=>gc_supply_direct_z07.
ls_mgv_info-quantity = ls_mgv_info-settle_quantity - ls_mgv_info-gu_quantity.
ENDCASE.
- 根据MGV Quantity确定Quantity Type
如果MGV Quantity大于等于零,则Quantity Type为Overtake,否则Undertake.
IF ls_mgv_info-quantity >= 0.
ls_mgv_info-quantity_type = /us4g/if_constants_billing=>gc_memi_qty_type_overtake.
ELSE.
ls_mgv_info-quantity_type = /us4g/if_constants_billing=>gc_memi_qty_type_undertake.
ENDIF.
- MGV Quantity保存正值(取绝对值)
"MeMi quantity should always be positive. The MeMi quantity type shows what kind of quantity it is.
ls_mgv_info-quantity = abs( ls_mgv_info-quantity ).
2. 冲销MeMi Document
主要逻辑在类/US4G/CL_MEMI_API的方法/US4G/IF_MEMI_API_MAIN~REVERSE_MEMI_DOC中实现。
2.1 确定冲销MeMi的数量类型
- 首选程序会根据Original的MeMi document的ID,获取原始的MeMi document数据。
DATA(lo_memi_doc_orig) = /us4g/cl_memi_factory=>get_memi_doc_by_doc_id(
EXPORTING
iv_memi_doc_id = iv_doc_id
iv_memi_doc_act = /us4g/if_constants_billing=>gc_memi_doc_act_update
).
lo_memi_doc_orig->get_memi_doc(
IMPORTING
et_memi_doc_tp = DATA(lt_memidoc_tp_orig)
).
- 根据原始的MeMi document的数量类型设置冲销MeMi document的数量类型。
| Original数量类型 | Original描述 | 冲销数量类型 | 冲销数量类型描述 |
|---|---|---|---|
| OVERTAKE | Overtake Quantities | REV_OT | Reversal Overtake Quantities |
| UNDERTAKE | Undertake Quantities | REV_UT | Reversal Undertake Quantities |
```javascript
"Handle reversal MEMI doc quantity type
CASE ls_memi_doc_tp_orig-quantity_type.
WHEN /us4g/if_constants_billing=>gc_memi_qty_type_overtake.
ls_memi_doc_tp_rev-quantity_type = /us4g/if_constants_billing=>gc_memi_qty_type_rev_ot.
WHEN /us4g/if_constants_billing=>gc_memi_qty_type_undertake.
ls_memi_doc_tp_rev-quantity_type = /us4g/if_constants_billing=>gc_memi_qty_type_rev_ut.
WHEN OTHERS.
ENDCASE.
```
2.2 确定冲销MGV的数量类型
- 如果Division Category是GAS,需要创建MGV信息。
- 程序会先读取原始的MeMi document对应的MGV信息。
- 如果原始的MeMi document的状态是以下状态(即MeMi document还未创建Billable item),则直接将原始MeMi document对应的MGV信息作废(将字段OBSOLETE设置为ABAP_TRUE),Reverse 的MeMi document不需要在报错MGV信息。否则,参照原始的MGV信息创建Reverse的MGV信息,同时根据原始MGV的数量类型确定冲销MGV的数量类型。
| Status | Status Text |
|---|---|
| 10 | New |
| 15 | Obsolete |
| 18 | MeMi Process Triggered |
| 20 | Settlement Info Queried |
| 25 | Settlement Info Received |
| 30 | Settlement Data Validated |
| 35 | MeMi Data Calculated |
详细代码:
IF lv_division_category = /ucom/if_constants_cross=>gc_division_cat_gas.
"Get Original MeMi MGV Detail Information Data
lo_memi_doc_orig->get_mgv_info( IMPORTING et_memi_mgv_info_tp = DATA(lt_mgv_info_orig) ).
* if status is new, just update original MGV Info
IF ls_memi_doc_tp_orig-status EQ /us4g/if_constants_billing=>gc_memi_status_new
OR ls_memi_doc_tp_orig-status EQ /us4g/if_constants_billing=>gc_memi_status_obsolete
OR ls_memi_doc_tp_orig-status EQ /us4g/if_constants_billing=>gc_memi_status_memi_proc_trig
OR ls_memi_doc_tp_orig-status EQ /us4g/if_constants_billing=>gc_memi_status_settle_queried
OR ls_memi_doc_tp_orig-status EQ /us4g/if_constants_billing=>gc_memi_status_settle_received
OR ls_memi_doc_tp_orig-status EQ /us4g/if_constants_billing=>gc_memi_status_settle_validate
OR ls_memi_doc_tp_orig-status EQ /us4g/if_constants_billing=>gc_memi_status_data_calculated.
LOOP AT lt_mgv_info_orig ASSIGNING FIELD-SYMBOL(<fs_mgv_info_orig>) WHERE obsolete IS INITIAL.
<fs_mgv_info_orig>-obsolete = abap_true.
APPEND <fs_mgv_info_orig> TO lt_mgv_info_tp_orig.
ENDLOOP.
ELSE.
LOOP AT lt_mgv_info_orig INTO DATA(ls_mgv_info_orig)
* If MGV detail information of original MeMi document is set to be obsolete, then
* MGV detail information should not be created for its reversal MeMi document.
WHERE obsolete IS INITIAL.
* Initialize consumption item ID and invoicing document number
CLEAR: ls_mgv_info_orig-citid,
ls_mgv_info_orig-invdocno.
ls_mgv_info_orig-key = /bobf/cl_frw_factory=>get_new_key( ).
ls_mgv_info_orig-parent_key = ls_memi_doc_tp_orig-reversal_doc_ref.
IF ls_memi_doc_tp_orig-merged_into_grid_acc_no IS NOT INITIAL.
ls_mgv_info_orig-grid_account_no = ls_memi_doc_tp_orig-merged_into_grid_acc_no.
ENDIF.
* Update Quantity type Overtake->REV_OT
IF ls_mgv_info_orig-quantity_type EQ /us4g/if_constants_billing=>gc_memi_qty_type_overtake.
ls_mgv_info_orig-quantity_type = /us4g/if_constants_billing=>gc_memi_qty_type_rev_ot.
ENDIF.
* Update Quantity type Undertake->REV_UT
IF ls_mgv_info_orig-quantity_type EQ /us4g/if_constants_billing=>gc_memi_qty_type_undertake.
ls_mgv_info_orig-quantity_type = /us4g/if_constants_billing=>gc_memi_qty_type_rev_ut.
ENDIF.
APPEND ls_mgv_info_orig TO lt_mgv_info_tp_rev.
CLEAR: ls_mgv_info_orig.
ENDLOOP.
ENDIF.
ENDIF.

760

被折叠的 条评论
为什么被折叠?



