#' @title tmsales_parser
#'
#' @description funciton to parse tm sales data
#'
#' @param dp_df dataframe containing raw data of dp sales data
#' @param write Defaults to TRUE. Will write to Excel Workbook.
#' @param xlsxfile Name of file. Defaults to TMSales_DDMMMYYYY.xlsx.
#'
#' @return Returns dataframe of parsed sales data.
#' @export
tmsales_parser <- function(
dp_df,
write = TRUE,
xlsxfile = NA
) {
df <- dp_df[-1, ]
df[5:ncol(df)] %<>% lapply(., as.numeric)
names(df)[1:4] <- c('Product.Code', 'Product.Name', 'Region', 'Time')
names(df)[5:ncol(df)] <- strftime(
as.POSIXct('12-30-1899', format = '%m-%d-%Y') +
lubridate::days(as.integer(names(df)[5:ncol(df)])),
format = '%b-%Y'
)
df %<>%
dplyr::filter(
Time != 'Summary'
) %>%
dplyr::select(
-Region,
-Time
) %>%
dplyr::group_by(
Product.Code,
Product.Name
) %>%
dplyr::summarise_each(
dplyr::funs(sum)
) %>%
dplyr::mutate(
call_subject = gsub('S', '', Product.Code)
) %>%
dplyr::left_join(
y = tmrecat %>%
dplyr::select(
Call.subject,
Dataset,
Category
),
by = c('call_subject' = 'Call.subject')
)
if (write) {
if (is.na(xlsxfile)) {
time <- time_vals()
xlsxfile <- paste0(
'TM_Sales_',
time$day,
lubridate::month(as.numeric(time$month), label = TRUE),
time$year,
'.xlsx'
)
}
openxlsx::write.xlsx(
x = df,
file = xlsxfile
)
}
return(df)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.