---
title: "Report"
author: "Data Science Team, LaNubia"
date: "1/11/2022"
output:
  html_document:
    theme: lumen
    highlight: tango
    self_contained: true

---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, error=TRUE, message=FALSE, warning=FALSE)
library(readxl)
library(DT)
library(tidyr)
library(dplyr)

rxl<- function(path,...){
  tryCatch(read_excel(path,...), error= function(c){
    c$message<-"No Data"
    print("No Data")
    stop(c)
  })
}

ltodf<- function(path,...){
  tryCatch(rbind.data.frame(path,...), error= function(c){
    c$message<-"No Data"
    print("No Data")
    stop(c)
  })
}

```

## Status Report


### Input Available



```{r echo=FALSE, message=FALSE, warning=FALSE}
contactinputpath<-list.files("./contacts/raw-data", pattern="*.xlsx", full.names = T)
accountinputpath<-list.files("./accounts/raw-data", pattern="*.xls", full.names = T)
projectinputpath<-list.files("./projects/raw-data", pattern="*.xls", full.names = T)
supportinputpath<-list.files("./support/raw-data", pattern="*.xls", full.names = T)


conta<-lapply(contactinputpath, read_excel)
names(conta)<-gsub("./contacts/raw-data/","",contactinputpath)
c<-lapply(conta, nrow)

Input_data<-"Contact"
#Country<-gsub(".xlsx","",names(conta))
Observations<-c

temp<-data.frame(Input_data,Observations) |> 
   pivot_longer(cols = (-1), names_to = "Country", values_to = "Observations") |> 
  mutate(Country=gsub(".xlsx","",Country))

input.summary<-temp

acco<-lapply(accountinputpath, read_excel)
names(acco)<-gsub("./accounts/raw-data/","",accountinputpath)
a<-lapply(acco, nrow)

Input_data<-"Accounts"
#Country<-gsub(".xlsx","",names(conta))
Observations<-a

temp<-data.frame(Input_data,Observations) |> 
   pivot_longer(cols = (-1), names_to = "Country", values_to = "Observations") |> 
  mutate(Country=gsub(".xls","",Country))

input.summary<-rbind(input.summary,temp)

proja<-lapply(projectinputpath, read_excel)
names(proja)<-gsub("./projects/raw-data/","",projectinputpath)
p<-lapply(proja, nrow)

Input_data<-"Projects"
#Country<-gsub(".xlsx","",names(conta))
Observations<-p

temp<-data.frame(Input_data,Observations) |> 
   pivot_longer(cols = (-1), names_to = "Country", values_to = "Observations") |> 
  mutate(Country=gsub(".xls","",Country))

input.summary<-rbind(input.summary,temp)

suppo<-lapply(supportinputpath, read_excel)
names(suppo)<-gsub("./support/raw-data/","",supportinputpath)
s<-lapply(suppo, nrow)

Input_data<-"Support"
#Country<-gsub(".xlsx","",names(conta))
Observations<-s

temp<-data.frame(Input_data,Observations) |> 
   pivot_longer(cols = (-1), names_to = "Country", values_to = "Observations") |> 
  mutate(Country=gsub(".xls","",Country))

input.summary<-rbind(input.summary,temp)

datatable(input.summary, extensions = "Buttons", 
            options = list(paging = TRUE,
                           scrollX=TRUE, 
                           searching = TRUE,
                           ordering = TRUE,
                           dom = 'Bfrtip',
                           buttons = c('copy', 'csv', 'excel', 'pdf'),
                           pageLength=5, 
                           lengthMenu=c(3,5,10) ))

```




Simplified view



```{r echo=FALSE}
input.summary |> 
  pivot_wider(names_from = Country, values_from = Observations) |> datatable(extensions = "Buttons", 
            options = list(paging = TRUE,
                           scrollX=TRUE, 
                           searching = TRUE,
                           ordering = TRUE,
                           dom = 'Bfrtip',
                           buttons = c('copy', 'csv', 'excel', 'pdf'),
                           pageLength=5, 
                           lengthMenu=c(3,5,10) ))
```



### Contacts



#### Template



SAP templates available:



```{r echo=FALSE}
datatable(data.frame(Templates=unique(rxl("./contacts/template.xlsx", sheet = "Field_Definitions")[,1])), extensions = "Buttons", 
            options = list(paging = TRUE,
                           scrollX=TRUE, 
                           searching = TRUE,
                           ordering = TRUE,
                           dom = 'Bfrtip',
                           buttons = c('copy', 'csv', 'excel', 'pdf'),
                           pageLength=5, 
                           lengthMenu=c(3,5,10) ))
```




#### Summary of Errors



```{r echo=FALSE, message=FALSE, warning=FALSE}
sumerrfilepath<-list.files("./contacts/summary", pattern="*sumerror.csv", full.names = T)
errfilepath<-list.files("./contacts/summary", pattern="*_error.csv", full.names = T)

sumerrfiles<-lapply(sumerrfilepath, read.csv)
datatable(do.call(ltodf, sumerrfiles), extensions = "Buttons", 
            options = list(paging = TRUE,
                           scrollX=TRUE, 
                           searching = TRUE,
                           ordering = TRUE,
                           dom = 'Bfrtip',
                           buttons = c('copy', 'csv', 'excel', 'pdf'),
                           pageLength=5, 
                           lengthMenu=c(3,5,10) ))

```



#### Error by template


```{r echo=FALSE, message=FALSE, warning=FALSE}
errfiles<-lapply(errfilepath, read.csv)
datatable(do.call(ltodf, errfiles), extensions = "Buttons", 
            options = list(paging = TRUE,
                           scrollX=TRUE, 
                           searching = TRUE,
                           ordering = TRUE,
                           dom = 'Bfrtip',
                           buttons = c('copy', 'csv', 'excel', 'pdf'),
                           pageLength=5, 
                           lengthMenu=c(3,5,10) ))
```



### Accounts


#### Template

SAP templates available:

```{r echo=FALSE}
datatable(data.frame(Templates=unique(rxl("./accounts/template.xlsx", sheet = "Field_Definitions")[,1])), extensions = "Buttons", 
            options = list(paging = TRUE,
                           scrollX=TRUE, 
                           searching = TRUE,
                           ordering = TRUE,
                           dom = 'Bfrtip',
                           buttons = c('copy', 'csv', 'excel', 'pdf'),
                           pageLength=5, 
                           lengthMenu=c(3,5,10) ))
```




#### Summary of Errors



```{r echo=FALSE, message=FALSE, warning=FALSE}
sumerrfilepath<-list.files("./accounts/summary", pattern="*sumerror.csv", full.names = T)
errfilepath<-list.files("./accounts/summary", pattern="*_error.csv", full.names = T)

sumerrfiles<-lapply(sumerrfilepath, read.csv)
datatable(do.call(ltodf, sumerrfiles), extensions = "Buttons", 
            options = list(paging = TRUE,
                           scrollX=TRUE, 
                           searching = TRUE,
                           ordering = TRUE,
                           dom = 'Bfrtip',
                           buttons = c('copy', 'csv', 'excel', 'pdf'),
                           pageLength=5, 
                           lengthMenu=c(3,5,10) ))

```



#### Error by template


```{r echo=FALSE, message=FALSE, warning=FALSE}
errfiles<-lapply(errfilepath, read.csv)
datatable(do.call(ltodf, errfiles), extensions = "Buttons", 
            options = list(paging = TRUE,
                           scrollX=TRUE, 
                           searching = TRUE,
                           ordering = TRUE,
                           dom = 'Bfrtip',
                           buttons = c('copy', 'csv', 'excel', 'pdf'),
                           pageLength=5, 
                           lengthMenu=c(3,5,10) ))
```




### Projects


#### Template

SAP templates available:

```{r echo=FALSE}
datatable(data.frame(Templates=unique(rxl("./projects/template.xlsx", sheet = "Field_Definitions")[,1])), extensions = "Buttons", 
            options = list(paging = TRUE,
                           scrollX=TRUE, 
                           searching = TRUE,
                           ordering = TRUE,
                           dom = 'Bfrtip',
                           buttons = c('copy', 'csv', 'excel', 'pdf'),
                           pageLength=5, 
                           lengthMenu=c(3,5,10) ))
```




#### Summary of Errors



```{r echo=FALSE, message=FALSE, warning=FALSE}
sumerrfilepath<-list.files("./projects/summary", pattern="*sumerror.csv", full.names = T)
errfilepath<-list.files("./projects/summary", pattern="*_error.csv", full.names = T)

sumerrfiles<-lapply(sumerrfilepath, read.csv)
datatable(do.call(ltodf, sumerrfiles), extensions = "Buttons", 
            options = list(paging = TRUE,
                           scrollX=TRUE, 
                           searching = TRUE,
                           ordering = TRUE,
                           dom = 'Bfrtip',
                           buttons = c('copy', 'csv', 'excel', 'pdf'),
                           pageLength=5, 
                           lengthMenu=c(3,5,10) ))

```



#### Error by template


```{r echo=FALSE, message=FALSE, warning=FALSE}
errfiles<-lapply(errfilepath, read.csv)
datatable(do.call(ltodf, errfiles), extensions = "Buttons", 
            options = list(paging = TRUE,
                           scrollX=TRUE, 
                           searching = TRUE,
                           ordering = TRUE,
                           dom = 'Bfrtip',
                           buttons = c('copy', 'csv', 'excel', 'pdf'),
                           pageLength=5, 
                           lengthMenu=c(3,5,10) ))
```




### Support


#### Template

SAP templates available:

```{r echo=FALSE}
datatable(data.frame(Templates=unique(rxl("./support/template.xlsx", sheet = "Field_Definitions")[,1])), extensions = "Buttons", 
            options = list(paging = TRUE,
                           scrollX=TRUE, 
                           searching = TRUE,
                           ordering = TRUE,
                           dom = 'Bfrtip',
                           buttons = c('copy', 'csv', 'excel', 'pdf'),
                           pageLength=5, 
                           lengthMenu=c(3,5,10) ))
```




#### Summary of Errors



```{r echo=FALSE, message=FALSE, warning=FALSE}
sumerrfilepath<-list.files("./support/summary", pattern="*sumerror.csv", full.names = T)
errfilepath<-list.files("./support/summary", pattern="*_error.csv", full.names = T)

sumerrfiles<-lapply(sumerrfilepath, read.csv)
datatable(do.call(ltodf, sumerrfiles), extensions = "Buttons", 
            options = list(paging = TRUE,
                           scrollX=TRUE, 
                           searching = TRUE,
                           ordering = TRUE,
                           dom = 'Bfrtip',
                           buttons = c('copy', 'csv', 'excel', 'pdf'),
                           pageLength=5, 
                           lengthMenu=c(3,5,10) ))

```



#### Error by template


```{r echo=FALSE, message=FALSE, warning=FALSE}
errfiles<-lapply(errfilepath, read.csv)
datatable(do.call(ltodf, errfiles), extensions = "Buttons", 
            options = list(paging = TRUE,
                           scrollX=TRUE, 
                           searching = TRUE,
                           ordering = TRUE,
                           dom = 'Bfrtip',
                           buttons = c('copy', 'csv', 'excel', 'pdf'),
                           pageLength=5, 
                           lengthMenu=c(3,5,10) ))
```

