commit
b8857f1df6
5 changed files with 203 additions and 0 deletions
@ -0,0 +1,4 @@ |
|||
.Rproj.user |
|||
.Rhistory |
|||
.RData |
|||
.Ruserdata |
|||
@ -0,0 +1,101 @@ |
|||
--- |
|||
title: "Analysis" |
|||
format: html |
|||
editor: visual |
|||
--- |
|||
|
|||
## Quarto |
|||
|
|||
```{r} |
|||
knitr::opts_chunk$set(echo = TRUE) |
|||
library('httr') |
|||
library('data.table') |
|||
library('dplyr') |
|||
library(lubridate) |
|||
library(highcharter) |
|||
``` |
|||
|
|||
```{r} |
|||
user=keyring::key_list("odata.dev.shiny")[1,2] |
|||
|
|||
pass=keyring::key_get("odata.dev.shiny", "SHINYAPP_REQUEST") |
|||
|
|||
url<-"https://my355441.crm.ondemand.com/sap/c4c/odata/v1/c4codataapi/OpportunityCollection?$filter=CreationDate%20ge%20datetime'2022-01-01T00:00:00'%20and%20CreationDate%20le%20datetime'2023-07-25T00:00:00'%20and%20SalesOrganisationID%20eq%20'NL01'" |
|||
dt.get<-GET(url, authenticate(user, pass, type = "basic")) |
|||
|
|||
dt.list<-content(dt.get, as="parsed") |
|||
dt.list$d$`__next` |
|||
dat<-data.table::rbindlist(dt.list$d$results,use.names=TRUE, fill=TRUE, idcol="UID") |
|||
|
|||
sort(colnames(dat)) |
|||
df<-unique(dat[, list(ID, ProcessingTypeCodeText, ProspectPartyID, Name, PrimaryContactPartyID, |
|||
PriorityCodeText, OriginTypeCodeText, LifeCycleStatusCodeText, ExternalUserStatusCodeText, SalesCycleCodeText, SalesCyclePhaseCodeText, ProbabilityPercent, ExpectedRevenueAmount, ExpectedRevenueAmountCurrencyCode, |
|||
SalesOrganisationID, SalesTerritoryID, MainEmployeeResponsiblePartyID, |
|||
PhaseProgressEvaluationStatusCodeText, MainEmployeeResponsiblePartyName, |
|||
SalesUnityPartyName, ProspectPartyName, SalesOrganisationName, SalesTerritoryName, CreationDate, Zoppstartdate_KUT, Zopptype_KUTText, Zproductpillar_KUT, Zinterproject_KUT, Zoppclosedate_KUT, |
|||
Zclassification_KUTText, Zprojectcountry_KUTText, Zprojectpostalcode_KUT, Zprojetcity_KUT, Zprojetcity_KUT)]) |
|||
|
|||
|
|||
filename<-paste0(tempdir(), "/", "OppData", ".csv") |
|||
|
|||
write.csv(df, file = filename) |
|||
|
|||
odata.opp.get<-function(user=keyring::key_list("odata.dev.shiny")[1,2], pass=keyring::key_get("odata.dev.shiny", "SHINYAPP_REQUEST"), url="https://my355441.crm.ondemand.com/sap/c4c/odata/v1/c4codataapi/OpportunityCollection?$filter=CreationDate%20ge%20datetime'2022-01-01T00:00:00'%20and%20CreationDate%20le%20datetime'2023-07-25T00:00:00'%20and%20SalesOrganisationID%20eq%20'NL01'"){ |
|||
|
|||
dt.get<-GET(url, authenticate(user, pass, type = "basic")) |
|||
|
|||
if(dt.get$status_code != 200){ |
|||
Sys.sleep(5) |
|||
} |
|||
dt.list<-content(dt.get, as="parsed") |
|||
print("parsed") |
|||
dat<-data.table::rbindlist(dt.list$d$results,use.names=TRUE, fill=TRUE, idcol="UID") |
|||
dt.df<-unique(dat[, list(ID, ProcessingTypeCodeText, ProspectPartyID, Name, PrimaryContactPartyID, |
|||
PriorityCodeText, OriginTypeCodeText, LifeCycleStatusCodeText, ExternalUserStatusCodeText, SalesCycleCodeText, SalesCyclePhaseCodeText, ProbabilityPercent, ExpectedRevenueAmount, ExpectedRevenueAmountCurrencyCode, |
|||
SalesOrganisationID, SalesTerritoryID, MainEmployeeResponsiblePartyID, |
|||
PhaseProgressEvaluationStatusCodeText, MainEmployeeResponsiblePartyName, |
|||
SalesUnityPartyName, ProspectPartyName, SalesOrganisationName, SalesTerritoryName, CreationDate, Zoppstartdate_KUT, Zopptype_KUTText, Zproductpillar_KUT, Zinterproject_KUT, Zoppclosedate_KUT, |
|||
Zclassification_KUTText, Zprojectcountry_KUTText, Zprojectpostalcode_KUT, Zprojetcity_KUT)]) |
|||
rm(dat) |
|||
print("writing file") |
|||
filename<-paste0(tempdir(), "/", "OppData", ".csv") |
|||
data.table::fwrite(dt.df,filename, append = TRUE, row.names = FALSE) |
|||
print("Done") |
|||
print(dt.list$d$`__next`) |
|||
print(names(dt.list$d)) |
|||
if(!c("__next") %in% names(dt.list$d)){ |
|||
r.df<-read.csv(filename) |> |
|||
mutate(CreationDate=as_datetime(as.numeric(gsub("\\D", "", CreationDate))/1000)) |
|||
file.remove(filename) |
|||
return(r.df) |
|||
|
|||
} else { |
|||
return( |
|||
odata.opp.get(url=dt.list$d$`__next`,user=keyring::key_list("odata.dev.shiny")[1,2], pass=keyring::key_get("odata.dev.shiny", "SHINYAPP_REQUEST")) |
|||
) |
|||
} |
|||
|
|||
} |
|||
|
|||
opp.dt<-odata.opp.get() |
|||
colnames(opp.dt) |
|||
|
|||
unique(opp.dt) |
|||
``` |
|||
|
|||
|
|||
```{r} |
|||
opp.dt |> |
|||
mutate(cre_date=floor_date(CreationDate, unit="weeks")) |> |
|||
count(cre_date) |> # SalesTerritoryID, |
|||
# PhaseProgressEvaluationStatusCodeText, |
|||
# MainEmployeeResponsiblePartyName, SalesTerritoryName, Zopptype_KUTText, Zprojetcity_KUT |
|||
gg |
|||
``` |
|||
|
|||
|
|||
```{r} |
|||
opp.dt[opp.dt$SalesTerritoryName=="AT_09 - Kärnten",] |
|||
``` |
|||
|
|||
|
|||
@ -0,0 +1,13 @@ |
|||
Version: 1.0 |
|||
|
|||
RestoreWorkspace: Default |
|||
SaveWorkspace: Default |
|||
AlwaysSaveHistory: Default |
|||
|
|||
EnableCodeIndexing: Yes |
|||
UseSpacesForTab: Yes |
|||
NumSpacesForTab: 2 |
|||
Encoding: UTF-8 |
|||
|
|||
RnwWeave: Sweave |
|||
LaTeX: pdfLaTeX |
|||
@ -0,0 +1,30 @@ |
|||
# |
|||
# This is a Shiny web application. You can run the application by clicking |
|||
# the 'Run App' button above. |
|||
# |
|||
# Developed by LaNubia |
|||
|
|||
library(shiny) |
|||
library(shinydashboard) |
|||
|
|||
source("uihelp.R") |
|||
|
|||
# Define UI for application that draws a histogram |
|||
ui <- dashboardPage( |
|||
dashboardHeader(title = "Opportunity Report NL"), |
|||
dashboardSidebar( |
|||
filters.sidebar |
|||
), |
|||
dashboardBody( |
|||
box( |
|||
radioButtons("Period", "Select Period", choiceNames = c("Daily", "Weekly", "Monthly", "Quarterly", "Yearly"), |
|||
choiceValues = c("day", "week", "month", "quarter", "year"), selected = "week", inline=TRUE, width = "90%"), |
|||
filters.panel, |
|||
width = 5) |
|||
) |
|||
) |
|||
|
|||
server <- function(input, output, session) {} |
|||
|
|||
# Run the application |
|||
shinyApp(ui = ui, server = server) |
|||
@ -0,0 +1,55 @@ |
|||
|
|||
## UI components |
|||
|
|||
|
|||
# Filters |
|||
|
|||
# Sales Territory Options |
|||
|
|||
# Function to convert the vector into list |
|||
|
|||
vector.to.list<- function(x) { |
|||
list( |
|||
key = x, |
|||
text = x |
|||
) |
|||
} |
|||
|
|||
|
|||
# territory.options<- lapply( |
|||
# c("NL_01 - NL_General" ,"Netherlands", |
|||
# "AT_07 - Burgenland" ,"NZ_South Island", |
|||
# "NZ_North Island" ,"AT_02 - Niederösterreich", |
|||
# "AT_05 - Salzburg" ,"CN_05 - Sales Commercial", |
|||
# "AT_09 - Kärnten" ,"DE_BE - DE Belgium" ), |
|||
# vector.to.list |
|||
# ) |
|||
|
|||
territory.options<- c("NL_01 - NL_General" ,"Netherlands", |
|||
"AT_07 - Burgenland" ,"NZ_South Island", |
|||
"NZ_North Island" ,"AT_02 - Niederösterreich", |
|||
"AT_05 - Salzburg" ,"CN_05 - Sales Commercial", |
|||
"AT_09 - Kärnten" ,"DE_BE - DE Belgium" ) |
|||
employee.options<- c( |
|||
"Meerten Siertsema", "Hakan Küçükoğlu", "Mark Lammertink", |
|||
"Leviat 2", "Katja Rustenhoven", "Gerko Gortel, van", |
|||
"Rutger Game", "Bram Aalbers", "Leviat 3", "Rigo Selassa" |
|||
) |
|||
|
|||
filters.sidebar <- tagList( |
|||
dateInput("fromDate", value = as.Date('2023/01/01'), label = "From date"), |
|||
dateInput("toDate", value = today(), label = "To date"), |
|||
actionButton("Extract","(Re-)Extract", icon = icon("download")) |
|||
) |
|||
|
|||
filters.panel <- tagList( |
|||
fluidRow( |
|||
column(width = 6, selectizeInput(inputId="Territory", label= "Territory",choices= territory.options, selected=territory.options[1], multiple = TRUE), |
|||
selectizeInput(inputId="OppType", label= "Opportunity Type",choices= c("Opportunity", "Project", "Subproject"), selected=c("Opportunity", "Project", "Subproject"), multiple = TRUE)), |
|||
column(width = 6, selectizeInput(inputId="Employee", label= "Employee",choices= employee.options, selected=employee.options[1], multiple = TRUE), |
|||
selectizeInput(inputId="Status", label= "Status",choices= c("Open", "In Process", "Won"), selected=c("Open", "In Process", "Won"), multiple = TRUE)) |
|||
) |
|||
|
|||
) |
|||
|
|||
|
|||
Loading…
Reference in new issue