@EndUserText.label : 'Sales Order Header'
@AbapCatalog.enhancementCategory : #EXTENSIBLE_ANY
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #ALLOWED
define table zsoh {
@AbapCatalog.foreignKey.screenCheck : false
key client : mandt not null
with foreign key [0..*,1] t000
where mandt = zsoh.client;
key sokey : snwd_node_key not null;
soid : snwd_so_id;
bpid : snwd_partner_id;
include /bobf/s_lib_admin_data;
}
@EndUserText.label : 'SO Item Table'
@AbapCatalog.enhancementCategory : #EXTENSIBLE_ANY
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #ALLOWED
define table zsoi {
@AbapCatalog.foreignKey.screenCheck : false
key client : mandt not null
with foreign key [0..*,1] t000
where mandt = zsoi.client;
key soitmkey : snwd_node_key not null;
@AbapCatalog.foreignKey.screenCheck : false
sokey : snwd_node_key
with foreign key [0..*,1] zsoh
where sokey = zsoi.sokey;
soitm : snwd_so_item_pos;
product : snwd_product_id;
@Semantics.amount.currencyCode : 'zsoi.currencycode'
grossamount : snwd_ttl_gross_amount;
currencycode : snwd_curr_code;
quantity : int4;
@Semantics.amount.currencyCode : 'zsoi.currencycode'
addcharge : snwd_ttl_gross_amount;
include /bobf/s_lib_admin_data;
}
@AbapCatalog.sqlViewName: 'ZISOH'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Interface view for BO with Draft'
@ObjectModel: {
createEnabled: true,
updateEnabled: true,
deleteEnabled: true,
draftEnabled: true,
modelCategory:#BUSINESS_OBJECT ,
semanticKey: ['Soid'],
compositionRoot: true,
transactionalProcessingEnabled: true,
writeDraftPersistence: 'ZSOH_DRAFT',
writeActivePersistence: 'ZSOH',
entityChangeStateId: 'Lchg_Date_Time'
}
define view ZI_SOH as select from ZSOH as soh
association [1..*] to ZI_SOI as _itm on $projection.Sokey = _itm.Sokey
association [0..1] to SEPM_I_BusinessPartner as _bpa on $projection.Bpid = _bpa.BusinessPartner
{
@ObjectModel.readOnly: true
key soh.sokey as Sokey,
@Search.defaultSearchElement: true
soh.soid as Soid,
@ObjectModel.foreignKey.association: '_bpa'
soh.bpid as Bpid,
@Semantics.systemDateTime.createdAt: true
soh.crea_date_time as Crea_Date_Time,
@Semantics.user.createdBy: true
soh.crea_uname as Crea_Uname,
@Semantics.systemDateTime.lastChangedAt: true
soh.lchg_date_time as Lchg_Date_Time,
@Semantics.user.lastChangedBy: true
soh.lchg_uname as Lchg_Uname,
@ObjectModel.association.type: [#TO_COMPOSITION_CHILD]
_itm
}
@AbapCatalog.sqlViewName: 'ZISOI'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Sales Item BO Draft'
@ObjectModel: {
createEnabled: true,
updateEnabled: true,
deleteEnabled: true,
semanticKey: ['Sokey','Soitm'],
writeDraftPersistence: 'ZSOI_DRAFT',
writeActivePersistence: 'ZSOI'
}
define view ZI_SOI as select from zsoi as soi
association [1..1] to ZI_SOH as _soh on $projection.Sokey = _soh.Sokey
association [0..1] to SEPM_I_Product_E as _pd on $projection.Product = _pd.Product
association [0..1] to SEPM_I_Currency as _curr on $projection.Currencycode = _curr.Currency
{
key soi.soitmkey as Soitmkey,
soi.sokey as Sokey,
@ObjectModel.readOnly: true
soi.soitm as Soitm,
@ObjectModel.foreignKey.association: '_pd'
soi.product as Product,
@ObjectModel.readOnly: true
@Semantics.amount.currencyCode: 'Currencycode'
soi.grossamount as Grossamount,
@ObjectModel.foreignKey.association: '_curr'
@Semantics.currencyCode: true
soi.currencycode as Currencycode,
soi.quantity as Quantity,
@Semantics.amount.currencyCode: 'Currencycode'
@ObjectModel.readOnly: true
soi.addcharge as AddCharge,
@ObjectModel.association.type: [#TO_COMPOSITION_PARENT,#TO_COMPOSITION_ROOT]
_soh,
_pd,
_curr
}
@AbapCatalog.sqlViewName: 'ZCSOH'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Consumption SO Hdr BO Draft'
@ObjectModel: {
createEnabled: true,
updateEnabled: true,
deleteEnabled: true,
draftEnabled: true,
semanticKey: ['Soid'],
compositionRoot: true,
transactionalProcessingDelegated: true
}
@UI.headerInfo: {
typeName: 'Sales Order',
typeNamePlural: 'Sales Orders',
title: {
type: #STANDARD,
value: 'Bpid'
},
description: {
type: #STANDARD,
value: 'Soid'
}
}
@VDM.viewType: #CONSUMPTION
@OData.publish: true
define view ZC_SOH as select from ZI_SOH
association [0..*] to ZC_SOI as _itm on $projection.Sokey = _itm.Sokey
association [0..1] to SEPM_I_BusinessPartner as _bpa on $projection.Bpid = _bpa.BusinessPartner
{
@UI.facet: [
{
id: 'Hdr',
purpose: #HEADER,
position: 10,
type: #FIELDGROUP_REFERENCE,
targetQualifier: 'HdrInfo'
},
{
id: 'SoHdr',
purpose: #STANDARD,
position: 10,
label: 'Header Details',
type: #IDENTIFICATION_REFERENCE
},
{
id: 'SoItm',
purpose: #STANDARD,
position: 20,
label: 'Item Details',
type: #LINEITEM_REFERENCE,
targetElement: '_itm'
}]
@UI.hidden: true
key Sokey,
@UI: {
lineItem: [ { position: 10, label: 'Sales Order ID', importance: #HIGH } ],
selectionField: [ { position: 10 } ],
identification:[ { position: 10 } ]
}
@UI.fieldGroup: [{ qualifier: 'HdrInfo' , position: 10 }]
@ObjectModel.readOnly: true
Soid,
@UI: {
lineItem: [ { position: 20, label: 'Customer', importance: #HIGH } ],
identification: [{ position: 20 }]
}
Bpid,
Crea_Date_Time,
Crea_Uname,
Lchg_Date_Time,
Lchg_Uname,
/* Associations */
@ObjectModel.association.type: [#TO_COMPOSITION_CHILD]
_itm,
_bpa
}
@AbapCatalog.sqlViewName: 'ZCSOI'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'consumption view for BOD SOI'
@ObjectModel:
{
createEnabled: true,
updateEnabled: true,
deleteEnabled: true,
semanticKey: ['Sokey', 'Soitm']
}
@UI: {
headerInfo: {
typeName: 'Sales Order Item',
typeNamePlural: 'Sales Order Items',
title: { type: #STANDARD, value: '_soh.Bpid' },
description:{ type: #STANDARD, value: '_soh.Soid' }
}
}
define view ZC_SOI as select from ZI_SOI as soi
association [1..1] to ZC_SOH as _soh
on $projection.Sokey = _soh.Sokey
association [0..1] to SEPM_I_Product_E as _pd
on $projection.Product = _pd.Product
association [0..1] to SEPM_I_Currency as _curr
on $projection.Currencycode = _curr.Currency
{
@UI.facet: [{
id: 'Item',
purpose: #STANDARD,
position: 10,
label: 'Item Details',
type: #IDENTIFICATION_REFERENCE
},
{
id: 'IHdr',
purpose: #HEADER,
position: 10,
type: #FIELDGROUP_REFERENCE,
targetQualifier: 'IHdrItm'
}]
@UI.hidden: true
key soi.Soitmkey as Soitmkey,
@UI.hidden: true
soi.Sokey as Sokey,
@UI.fieldGroup: [{ qualifier: 'IHdrItm' , position: 10 }]
@UI.lineItem: [{position: 10 , importance: #HIGH}]
@UI.identification: [{position: 10 }]
@ObjectModel.readOnly: true
soi.Soitm as Soitm,
@UI.lineItem: [{position: 20 , importance: #HIGH}]
@UI.identification: [{position: 20 , importance: #HIGH }]
@ObjectModel.foreignKey.association: '_pd'
soi.Product as Product,
@UI.lineItem: [{position: 40 ,importance: #HIGH}]
@ObjectModel.readOnly: true
@Semantics.amount.currencyCode: 'Currencycode'
soi.Grossamount as Grossamount,
@ObjectModel.foreignKey.association: '_curr'
@Semantics.currencyCode: true
soi.Currencycode as Currencycode,
@UI.lineItem: [{position: 30 , label : 'Quantity', importance: #HIGH}]
@UI.identification: [{position: 40, label : 'Quantity' }]
soi.Quantity as Quantity,
@UI.lineItem: [{position: 40, importance: #HIGH, label: 'Additional Charges' }]
@ObjectModel.readOnly: true
soi.AddCharge,
/* Associations */
_curr,
_pd,
@ObjectModel.association.type: [#TO_COMPOSITION_PARENT,#TO_COMPOSITION_ROOT]
_soh
}
class ZCL_I_D_CALC_SO_ID definition
public
inheriting from /BOBF/CL_LIB_D_SUPERCL_SIMPLE
final
create public .
public section.
methods /BOBF/IF_FRW_DETERMINATION~EXECUTE
redefinition .
protected section.
private section.
ENDCLASS.
CLASS ZCL_I_D_CALC_SO_ID IMPLEMENTATION.
method /BOBF/IF_FRW_DETERMINATION~EXECUTE.
DATA: itab TYPE ZTISOH.
CALL METHOD io_read->retrieve
EXPORTING
iv_node = is_ctx-node_key
it_key = it_key
IMPORTING
et_data = itab.
LOOP AT itab REFERENCE INTO DATA(lr_tab).
IF lr_tab->soid IS INITIAL.
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
nr_range_nr = '01'
object = 'RV_BELEG'
IMPORTING
number = lr_tab->soid
EXCEPTIONS
interval_not_found = 1
number_range_not_intern = 2
object_not_found = 3
quantity_is_0 = 4
quantity_is_not_1 = 5
interval_overflow = 6
buffer_overflow = 7
OTHERS = 8.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL METHOD io_modify->update
EXPORTING
iv_node = is_ctx-node_key
iv_key = lr_tab->key
is_data = lr_tab
it_changed_fields =
VALUE #( ( ZIF_I_SOH_C=>sc_node_attribute-zi_soh-soid ) )
.
* CATCH /bobf/cx_frw_contrct_violation.
ENDIF.
ENDLOOP.
endmethod.
ENDCLASS.
CLASS zcl_i_d_calc_soitm_cal_gross DEFINITION
PUBLIC
INHERITING FROM /bobf/cl_lib_d_supercl_simple
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
METHODS /bobf/if_frw_determination~execute
REDEFINITION .
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_i_d_calc_soitm_cal_gross IMPLEMENTATION.
METHOD /bobf/if_frw_determination~execute.
DATA:
itab TYPE ztisoi,
itab1 TYPE ztisoh,
li_key TYPE /bobf/t_frw_key.
* We Retrive the Items of the Sales Order
CALL METHOD io_read->retrieve
EXPORTING
iv_node = is_ctx-node_key
it_key = it_key
IMPORTING
et_data = itab.
DATA(lw_itm) = VALUE #( itab[ soitm = space ] OPTIONAL ).
READ TABLE itab WITH KEY soitm = space TRANSPORTING NO FIELDS.
* Get the parent node to get the sales order number because Item does not have Sales order number
IF sy-subrc = 0.
CALL METHOD io_read->retrieve_by_association
EXPORTING
iv_node = zif_i_soh_c=>sc_node-zi_soi
it_key = it_key
iv_association = zif_i_soh_c=>sc_association-zi_soi-to_root
iv_fill_data = abap_true
IMPORTING
et_data = itab1
et_target_key = li_key .
READ TABLE itab1 INTO DATA(lw_tab1) INDEX 1.
SELECT SINGLE sokey FROM zsoh INTO @DATA(lv_sokey) WHERE soid = @lw_tab1-soid.
IF sy-subrc <> 0.
SELECT SINGLE sokey FROM ZSOH_draft INTO lv_sokey WHERE soid = lw_tab1-soid.
ENDIF.
WITH +both AS ( SELECT soitm FROM zsoi WHERE sokey = @lv_sokey
UNION ALL
SELECT soitm FROM zsoi_draft WHERE sokey = @lv_sokey )
SELECT SINGLE
FROM +both
FIELDS MAX( soitm ) AS salesorderitem
INTO @DATA(lv_max_salesorderitem).
" If there are no entries, set a start value
IF lv_max_salesorderitem IS INITIAL.
lv_max_salesorderitem = '0000000000'.
ENDIF.
ENDIF.
* Get the Item and also Gross amount
LOOP AT itab REFERENCE INTO DATA(lr_tab).
IF lr_tab->soitm IS INITIAL.
lr_tab->soitm = lv_max_salesorderitem = lv_max_salesorderitem + 10.
lr_tab->soitm = |{ lr_tab->soitm ALPHA = IN }|.
ENDIF.
if lr_tab->quantity IS NOT INITIAL AND lr_tab->product IS NOT INITIAL.
SELECT SINGLE * FROM snwd_pd INTO @Data(lw_snwd_pd) WHERE product_id = @lr_tab->product.
* We add the Add Charge + quantity * price
lr_tab->grossamount = ( lr_tab->quantity * lw_snwd_pd-price ) + lr_tab->addcharge.
lr_tab->currencycode = lw_snwd_pd-currency_code.
ENDIF.
CALL METHOD io_modify->update
EXPORTING
iv_node = is_ctx-node_key
iv_key = lr_tab->key
* iv_root_key =
is_data = lr_tab
it_changed_fields =
VALUE #( ( zif_i_soh_c=>sc_node_attribute-zi_soi-soitm )
( zif_i_soh_c=>sc_node_attribute-zi_soi-grossamount )
( zif_i_soh_c=>sc_node_attribute-zi_soi-currencycode ) ).
* CATCH /bobf/cx_frw_contrct_violation.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
Next We preview the app
Page | Object Page |
Function Name | getAdditionalCharge |
Entity Set | ZC_SOH |
Action Position | Section |
Facets Annotation Term ID | Item Details |
Action ID | idGetAddChrg |
Button Text | Additional Charge |
Row Selection | Yes |
<core:FragmentDefinition xmlns:core="sap.ui.core" xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc"
height="100%">
<Dialog id="idExtraCharges" title="Other Charges" class="sapUiNoContentPadding">
<content>
<VBox id="idChargeVbox" class="sapUiSmallMarginBeginEnd">
<Table id="idChargeTable" inset="false" items="{Charge>/ExtraChrg}" mode="MultiSelect">
<columns>
<Column width="12em">
<Text text="Charge Type"/>
</Column>
<Column minScreenWidth="Tablet" demandPopin="true">
<Text text="Amount"/>
</Column>
<Column minScreenWidth="Desktop" demandPopin="true" hAlign="End">
<Text text="Currency"/>
</Column>
</columns>
<items>
<ColumnListItem vAlign="Middle">
<cells>
<Text text="{Charge>ChargeType}"/>
<Input value="{Charge>Amount}"/>
</cells>
</ColumnListItem>
</items>
</Table>
</VBox>
</content>
<buttons>
<Button id="btncopy" text="Copy" press="onActionCopy" />
<Button id="btncancel" text="Cancel" press="onActionCancel"/>
</buttons>
</Dialog>
</core:FragmentDefinition>
class ZCL_I_A_SET_ADD_CHRG definition
public
inheriting from /BOBF/CL_LIB_A_SUPERCL_SIMPLE
final
create public .
public section.
methods /BOBF/IF_FRW_ACTION~EXECUTE
redefinition .
protected section.
private section.
ENDCLASS.
CLASS ZCL_I_A_SET_ADD_CHRG IMPLEMENTATION.
method /BOBF/IF_FRW_ACTION~EXECUTE.
DATA : ls_parameters TYPE ZADD_CHRG,
lt_key TYPE /bobf/t_frw_key,
ls_key TYPE /bobf/s_frw_key,
itab TYPE ZTISOI.
"Retrive Source data from Frontend
DATA(ls_parameters_ptr) = CAST zadd_chrg( is_parameters ).
MOVE ls_parameters_ptr->* TO ls_parameters.
ls_key-key = ls_parameters-draftuuid.
APPEND ls_key TO lt_key.
call METHOD io_read->retrieve
EXPORTING
iv_node = ZIF_I_SOH_C=>sc_node-zi_soi
it_key = lt_key
IMPORTING
et_data = itab.
loop at itab REFERENCE INTO data(lr_tab).
lr_tab->addcharge = ls_parameters-amount + lr_tab->addcharge.
lr_tab->grossamount = lr_tab->grossamount + ls_parameters-amount.
call METHOD io_modify->update
EXPORTING
iv_node = ZIF_I_SOH_C=>sc_node-zi_soi
iv_key = lr_tab->key
is_data = lr_tab
it_changed_fields =
VALUE #( ( ZIF_I_SOH_C=>sc_node_attribute-zi_soi-grossamount )
( ZIF_I_SOH_C=>sc_node_attribute-zi_soi-addcharge )
( ZIF_I_SOH_C=>sc_node_attribute-zi_soi-currencycode ) ).
ev_static_action_failed = abap_false.
ENDLOOP.
endmethod.
ENDCLASS.
sap.ui.controller("fe.so.fesaleorder.ext.controller.ObjectPageExt", {
onInit: function () {
var oJson = new sap.ui.model.json.JSONModel({
"ExtraChrg": []
});
var oExtraChrg = [];
var oCharges = {
"ChargeType": "Freight",
"Amount": 0,
};
oExtraChrg.push(JSON.parse(JSON.stringify(oCharges)));
oCharges.ChargeType = "Miscellaneous Charge";
oExtraChrg.push(JSON.parse(JSON.stringify(oCharges)));
oCharges.ChargeType = "Other Charge";
oExtraChrg.push(JSON.parse(JSON.stringify(oCharges)));
this.getOwnerComponent().setModel(oJson, "Charge");
this.getOwnerComponent().getModel("Charge").setProperty("/ExtraChrg", oExtraChrg);
},
getAdditionalCharge: function (oEvent) {
debugger;
// Below is how we get the ID of the Item table
this._oTable = this.getView().byId(oEvent.getSource().getParent().getParent().getParent().getId()).getTable();
this._oDetails = this.getView().getModel().getProperty(this._oTable.getSelectedContextPaths()[0]);
var u = oEvent.getSource().getModel("ui").getData();
if (u.editable === true || u.createMode === true) {
if (!this._DialogGenerate) {
this._DialogGenerate = sap.ui.xmlfragment("fe.so.fesaleorder.ext.fragment.extraCharge", this);
this.getView().addDependent(this._DialogGenerate);
}
this._DialogGenerate.open();
} else {
// var i = this._oResourceBundle.getText('@copyInfo');
sap.m.MessageBox.information("Changes Possible only in Create and Edit Mode");
}
},
onActionCancel: function () {
this._DialogGenerate.close();
this._DialogGenerate.destroy();
this.getView().removeDependent(this._DialogGenerate);
this._DialogGenerate = null;
},
onActionCopy: function (oEvent) {
var oPromise;
var that = this;
var oApi = this.extensionAPI;
var oParameter = {};
// Get Selected row in item table
var ochargeDet = sap.ui.getCore().byId("idChargeTable").getSelectedContextPaths();
var oTot = 0;
for (var i = 0; i < ochargeDet.length; i++) {
var oCharges = this.getOwnerComponent().getModel("Charge").getProperty(ochargeDet[i]);
oTot = parseFloat(oCharges.Amount) + oTot;
}
// ***************Implment Invoke Action after Creating Static BOPF Action*********
oParameter = {
"Draftuuid": this._oDetails.Soitmkey,
"Amount": oTot,
"Currency" : 'EUR'
};
oPromise = this.extensionAPI.invokeActions("ZC_SOH_CDS.ZC_SOH_CDS_Entities/ZC_SOISet_add_chrg", [],
oParameter);
oPromise.then(function (r) {
that.getView().getModel().refresh(true, false, "CopyRefresh");
sap.m.MessageToast.show("Charges Added Successfully to Item" + that._oDetails.Soitm);
});
oPromise.catch(function (r) {
var E = jQuery.parseJSON(r[0].error.response.responseText);
sap.m.MessageBox.error(E.error.message.value);
});
this.onActionCancel();
}
});
Click on Addtional Charges Button by selecting item.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 | |
4 | |
4 |