
method VENTASSET_GET_ENTITYSET.
DATA: ls_filter_select_options TYPE /iwbep/s_mgw_select_option,
ls_select_option TYPE /iwbep/s_cod_select_option.
DATA: l_it_so_periodo TYPE RANGE OF spmon,
l_wa_so_periodo LIKE LINE OF l_it_so_periodo,
l_it_so_oficina TYPE RANGE OF vkbur,
l_wa_so_oficina LIKE LINE OF l_it_so_oficina,
l_it_so_grupoart TYPE RANGE OF matkl,
l_wa_so_grupoart LIKE LINE OF l_it_so_grupoart,
l_it_so_vrsio TYPE RANGE OF s700-vrsio,
l_wa_so_vrsio LIKE LINE OF l_it_so_vrsio.
LOOP AT it_filter_select_options INTO ls_filter_select_options.
IF ls_filter_select_options-property EQ 'Periodo'.
LOOP AT ls_filter_select_options-select_options INTO ls_select_option.
l_wa_so_periodo-sign = ls_select_option-sign.
l_wa_so_periodo-option = ls_select_option-option.
l_wa_so_periodo-low = ls_select_option-low.
l_wa_so_periodo-high = ls_select_option-high.
APPEND l_wa_so_periodo TO l_it_so_periodo.
ENDLOOP.
ENDIF.
IF ls_filter_select_options-property EQ 'Oficina'.
LOOP AT ls_filter_select_options-select_options INTO ls_select_option.
l_wa_so_oficina-sign = ls_select_option-sign.
l_wa_so_oficina-option = ls_select_option-option.
l_wa_so_oficina-low = ls_select_option-low.
l_wa_so_oficina-high = ls_select_option-high.
APPEND l_wa_so_oficina TO l_it_so_oficina.
ENDLOOP.
ENDIF.
IF ls_filter_select_options-property EQ 'GrupoArticulos'.
LOOP AT ls_filter_select_options-select_options INTO ls_select_option.
l_wa_so_grupoart-sign = ls_select_option-sign.
l_wa_so_grupoart-option = ls_select_option-option.
if ls_select_option-low <> ''.
l_wa_so_grupoart-low = ls_select_option-low.
l_wa_so_grupoart-high = ls_select_option-high.
APPEND l_wa_so_grupoart TO l_it_so_grupoart.
endif.
ENDLOOP.
ENDIF.
IF ls_filter_select_options-property EQ 'Version'.
LOOP AT ls_filter_select_options-select_options INTO ls_select_option.
l_wa_so_vrsio-sign = ls_select_option-sign.
l_wa_so_vrsio-option = ls_select_option-option.
l_wa_so_vrsio-low = ls_select_option-low.
l_wa_so_vrsio-high = ls_select_option-high.
APPEND l_wa_so_vrsio TO l_it_so_vrsio.
ENDLOOP.
ENDIF.
ENDLOOP.
IF l_it_so_vrsio IS INITIAL.
l_wa_so_vrsio-sign = 'I'.
l_wa_so_vrsio-option = 'EQ'.
l_wa_so_vrsio-low = '000'.
APPEND l_wa_so_vrsio TO l_it_so_vrsio.
l_wa_so_vrsio-low = '999'.
APPEND l_wa_so_vrsio TO l_it_so_vrsio.
ENDIF.
IF l_it_so_grupoart IS NOT INITIAL.
SELECT spmon, matkl, vkbur, vrsio, SUM( netwr ) AS netwr, SUM( zzpesoneto ) AS zzpesoneto
FROM s700 INTO CORRESPONDING FIELDS OF TABLE @et_entityset
WHERE spmon IN @l_it_so_periodo
AND vkbur IN @l_it_so_oficina
AND vrsio IN @l_it_so_vrsio
AND matkl IN @l_it_so_grupoart
GROUP BY spmon, matkl, vkbur, vrsio.
ELSE.
SELECT spmon, vkbur, vrsio, SUM( netwr ) AS netwr, SUM( zzpesoneto ) AS zzpesoneto
FROM s700 INTO CORRESPONDING FIELDS OF TABLE @et_entityset
WHERE spmon IN @l_it_so_periodo
AND vkbur IN @l_it_so_oficina
AND vrsio IN @l_it_so_vrsio
GROUP BY spmon, vkbur, vrsio.
ENDIF.
endmethod.
'GetSalesAndBudget': function () {
//delegate to Alexa to collect all the required slot values
var filledSlots = delegateSlotCollection.call(this);
var oficina=this.event.request.intent.slots.oficina.value;
var periodo=this.event.request.intent.slots.periodo.value;
var fieldsRequested=this.event.request.intent.slots.fieldsRequested.value;
var grupoArt = isSlotValid(this.event.request, "grupoArt");
if (this.event.request.dialogState === "COMPLETED"){
oficinaId = this.event.request.intent.slots.oficina.resolutions.resolutionsPerAuthority[0].values[0].value.id;
grupoArtId = "";
if (this.event.request.intent.slots.grupoArt.resolutions){
grupoArtId = this.event.request.intent.slots.grupoArt.resolutions.resolutionsPerAuthority[0].values[0].value.id;
}
fieldsRequestedId = this.event.request.intent.slots.fieldsRequested.resolutions.resolutionsPerAuthority[0].values[0].value.id;
periodoSAP = periodo.substr(0, 4) + periodo.substr(5,2);
getDataFromSAP(oficinaId, periodoSAP, fieldsRequestedId, grupoArtId, function(salesValue, budgetValue){
console.log("Grupo de articulo: " + grupoArt);
if (!grupoArt){
grupoArtPartText = "";
connectorAnd = "";
}else{
connectorAnd = " and ";
grupoArtPartText = " items group " + grupoArt;
}
switch(fieldsRequestedId){
case "1": //Solo ventas
speechOutput = "The total sales value for sales office " + oficina + connectorAnd + grupoArtPartText + " on " + periodo + " is " + salesValue + " millions of colombian pesos";
break;
case "2": //Solo presupuesto
speechOutput = "The total budget value for sales office " + oficina + connectorAnd + grupoArtPartText + " on " + periodo + " is " + budgetValue + " millions of colombian pesos";
break;
case "3": //Ventas y presupuesto
speechOutput = "For sales office " + oficina + ", " + grupoArtPartText + " and month " + periodo + " the total budget value is " + budgetValue + " millions of colombian pesos, and total sales value is " + salesValue + " millions of colombian pesos";
break;
}
this.response.speak(speechOutput);
this.emit(":responseReady");
}.bind(this));
//console.log("Grupo de articulo " + grupoArt);
console.log("Id de la oficina " + this.event.request.intent.slots.oficina.resolutions.resolutionsPerAuthority[0].values[0].value.id);
}
},
function getDataFromSAP(pOficinaId, pPeriodoSAP, pFieldsRequestedId, pGrupoArtId, callback){
var url = "https://gwaas-pXXXXXXtrial.hanatrial.ondemand.com/odata/SAP/ZSD_XXXXXX_SRV;v=1";
var entitySet = "/VentasSet";
var format = "&$format=json";
var version = "";
var args = {
headers: {
"Authorization": "Basic XXXXXXXXXXXXX"
}
};
if (pFieldsRequestedId === "1"){
version = " and Version eq '000'";
} else if (pFieldsRequestedId === "2") {
version = " and Version eq '999'";
} //Si toma valor 3 que significa leer ventas y ppto la version va vacia
console.log("Requested fields " + pFieldsRequestedId + " Version " + version);
var filtro = "/?$filter=" + escape("Periodo eq '" + pPeriodoSAP + "' and Oficina eq '" + pOficinaId + "' and GrupoArticulos eq '" + pGrupoArtId + "'" + version);
client = new Client();
console.log("Url: " + url + entitySet + filtro + format);
client.get(url + entitySet + filtro + format, args, function(data, response){
var totalSales = 0;
var totalBudget = 0;
console.log(data.d.results);
data.d.results.forEach(function(data){
if (data.Version === "000"){
totalSales = (Number(data.ValorNeto) / 1000000).toFixed(0).toString();
} else {
totalBudget = (Number(data.ValorNeto) / 1000000).toFixed(0).toString();
}
});
callback(totalSales,totalBudget);
});
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
7 | |
5 | |
3 | |
3 | |
3 | |
3 | |
2 | |
2 | |
2 |