Fase 3 Professor: Adriano Lauro Alunos: Murilo Lima/ Rafael Antônio Turma: Eng. Civil 4° período Dados Descritivos do Trabalho
library(readxl)
library(dplyr)
library(ggplot2)
library(knitr)
library(kableExtra)
library(lubridate)
library(forecast)
library(readxl)
Salario <- read_excel("Salario_base.xlsx")
library(readxl)
Vendas <- read_excel("Vendas2024 (1).xlsx")
##1. Carregamento e Preparação dos Dados
vendas_limpo <- Vendas %>%
mutate(
vendedor = as.factor(vendedor),
dias = as.Date(dias),
venda_diaria = as.numeric(venda_diaria)
) %>%
filter(!is.na(venda_diaria))
salarios_limpo <- Salario %>%
rename(vendedor = 'Número de Inscrição') %>%
mutate(
vendedor = as.factor(vendedor)
)
str(vendas_limpo)
## tibble [113,202 × 5] (S3: tbl_df/tbl/data.frame)
## $ vendedor : Factor w/ 12 levels "101101","101102",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ dias : Date[1:113202], format: "2018-01-01" "2018-01-01" ...
## $ venda_diaria: num [1:113202] 372 139 354 241 123 ...
## $ ano : num [1:113202] 2018 2018 2018 2018 2018 ...
## $ mes : num [1:113202] 1 1 1 1 1 1 1 1 1 1 ...
head(vendas_limpo)
## # A tibble: 6 × 5
## vendedor dias venda_diaria ano mes
## <fct> <date> <dbl> <dbl> <dbl>
## 1 101101 2018-01-01 372. 2018 1
## 2 101101 2018-01-01 139. 2018 1
## 3 101101 2018-01-01 354. 2018 1
## 4 101101 2018-01-01 241. 2018 1
## 5 101101 2018-01-01 123. 2018 1
## 6 101101 2018-01-01 165. 2018 1
summary(vendas_limpo)
## vendedor dias venda_diaria ano
## 101102 :14604 Min. :2018-01-01 Min. : 9.79 Min. :2018
## 101101 :13742 1st Qu.:2020-09-19 1st Qu.:133.27 1st Qu.:2020
## 101103 :12779 Median :2022-02-03 Median :254.06 Median :2022
## 101104 :10493 Mean :2021-11-21 Mean :260.38 Mean :2021
## 101105 :10419 3rd Qu.:2023-03-15 3rd Qu.:373.85 3rd Qu.:2023
## 101106 : 9997 Max. :2024-03-30 Max. :838.42 Max. :2024
## (Other):41168
## mes
## Min. : 1.000
## 1st Qu.: 3.000
## Median : 7.000
## Mean : 6.548
## 3rd Qu.:10.000
## Max. :12.000
##
estatisticas_por_vendedor <- vendas_limpo %>%
group_by(vendedor) %>%
summarise(
Venda_Total = sum(venda_diaria),
Media_Diaria = mean(venda_diaria),
Mediana_Diaria = median(venda_diaria),
Desvio_Padrao = sd(venda_diaria),
Total_Registros = n()
) %>%
arrange(desc(Venda_Total))
kable(estatisticas_por_vendedor, caption = "Indicadores de Desempenho por Vendedor", digits = 2)
| vendedor | Venda_Total | Media_Diaria | Mediana_Diaria | Desvio_Padrao | Total_Registros |
|---|---|---|---|---|---|
| 101102 | 4031176 | 276.03 | 268.37 | 160.76 | 14604 |
| 101101 | 3489519 | 253.93 | 249.28 | 146.27 | 13742 |
| 101103 | 3433923 | 268.72 | 264.70 | 155.34 | 12779 |
| 101105 | 2694622 | 258.63 | 250.79 | 150.14 | 10419 |
| 101104 | 2491491 | 237.44 | 232.13 | 137.85 | 10493 |
| 101108 | 2473665 | 271.47 | 265.24 | 157.04 | 9112 |
| 101106 | 2458056 | 245.88 | 240.99 | 143.15 | 9997 |
| 102111 | 2441308 | 244.67 | 240.99 | 140.90 | 9978 |
| 101107 | 2201441 | 250.28 | 243.28 | 146.59 | 8796 |
| 102112 | 1338667 | 289.50 | 282.73 | 166.85 | 4624 |
| 101109 | 1296194 | 304.06 | 297.62 | 173.87 | 4263 |
| 101110 | 1125154 | 256.01 | 252.31 | 145.72 | 4395 |
venda_mensal_total <- vendas_limpo %>%
group_by(ano, mes) %>%
summarise(venda_mensal_total = sum(venda_diaria)) %>%
arrange(ano, mes)
## `summarise()` has regrouped the output.
## ℹ Summaries were computed grouped by ano and mes.
## ℹ Output is grouped by ano.
## ℹ Use `summarise(.groups = "drop_last")` to silence this message.
## ℹ Use `summarise(.by = c(ano, mes))` for per-operation grouping
## (`?dplyr::dplyr_by`) instead.
kable(venda_mensal_total, caption = "Faturamento Mensal Geral da Organização", digits = 2)
| ano | mes | venda_mensal_total |
|---|---|---|
| 2018 | 1 | 101567.93 |
| 2018 | 2 | 84566.85 |
| 2018 | 3 | 85530.13 |
| 2018 | 4 | 98811.06 |
| 2018 | 5 | 120225.68 |
| 2018 | 6 | 97619.83 |
| 2018 | 7 | 83419.18 |
| 2018 | 8 | 124339.31 |
| 2018 | 9 | 120982.09 |
| 2018 | 10 | 127807.90 |
| 2018 | 11 | 155285.26 |
| 2018 | 12 | 187369.81 |
| 2019 | 1 | 136127.00 |
| 2019 | 2 | 98931.27 |
| 2019 | 3 | 114280.20 |
| 2019 | 4 | 126960.42 |
| 2019 | 5 | 171233.06 |
| 2019 | 6 | 149914.75 |
| 2019 | 7 | 107252.77 |
| 2019 | 8 | 141441.62 |
| 2019 | 9 | 129484.14 |
| 2019 | 10 | 288625.81 |
| 2019 | 11 | 355359.75 |
| 2019 | 12 | 468261.28 |
| 2020 | 1 | 271472.65 |
| 2020 | 2 | 222533.09 |
| 2020 | 3 | 382382.08 |
| 2020 | 4 | 421068.32 |
| 2020 | 5 | 517596.70 |
| 2020 | 6 | 416373.11 |
| 2020 | 7 | 351208.06 |
| 2020 | 8 | 331284.75 |
| 2020 | 9 | 400772.74 |
| 2020 | 10 | 387258.35 |
| 2020 | 11 | 505659.62 |
| 2020 | 12 | 595835.98 |
| 2021 | 1 | 360726.31 |
| 2021 | 2 | 301422.03 |
| 2021 | 3 | 385502.04 |
| 2021 | 4 | 430170.60 |
| 2021 | 5 | 483334.28 |
| 2021 | 6 | 476022.42 |
| 2021 | 7 | 400116.30 |
| 2021 | 8 | 392945.07 |
| 2021 | 9 | 375571.56 |
| 2021 | 10 | 441425.94 |
| 2021 | 11 | 503923.84 |
| 2021 | 12 | 608599.31 |
| 2022 | 1 | 398929.02 |
| 2022 | 2 | 344108.08 |
| 2022 | 3 | 366832.24 |
| 2022 | 4 | 479610.28 |
| 2022 | 5 | 669782.26 |
| 2022 | 6 | 616457.44 |
| 2022 | 7 | 540985.75 |
| 2022 | 8 | 530524.87 |
| 2022 | 9 | 510590.58 |
| 2022 | 10 | 614907.36 |
| 2022 | 11 | 736200.89 |
| 2022 | 12 | 817665.03 |
| 2023 | 1 | 568067.46 |
| 2023 | 2 | 477297.07 |
| 2023 | 3 | 577768.37 |
| 2023 | 4 | 608208.92 |
| 2023 | 5 | 699119.04 |
| 2023 | 6 | 682889.59 |
| 2023 | 7 | 574676.55 |
| 2023 | 8 | 571171.72 |
| 2023 | 9 | 572114.63 |
| 2023 | 10 | 651203.73 |
| 2023 | 11 | 757312.16 |
| 2023 | 12 | 898480.62 |
| 2024 | 1 | 549534.22 |
| 2024 | 2 | 468779.94 |
| 2024 | 3 | 553397.54 |
venda_mensal_por_vendedor <- vendas_limpo %>%
group_by(vendedor, ano, mes) %>%
summarise(venda_mensal_por_vendedor = sum(venda_diaria)) %>%
arrange(vendedor , ano, mes)
## `summarise()` has regrouped the output.
## ℹ Summaries were computed grouped by vendedor, ano, and mes.
## ℹ Output is grouped by vendedor and ano.
## ℹ Use `summarise(.groups = "drop_last")` to silence this message.
## ℹ Use `summarise(.by = c(vendedor, ano, mes))` for per-operation grouping
## (`?dplyr::dplyr_by`) instead.
venda_mensal_por_vendedor %>%
head(15) %>%
kable(caption = "Demonstrativo das Vendas Mensais por Vendedor (Amostra)", digits = 2)
| vendedor | ano | mes | venda_mensal_por_vendedor |
|---|---|---|---|
| 101101 | 2018 | 1 | 40681.80 |
| 101101 | 2018 | 2 | 41947.67 |
| 101101 | 2018 | 3 | 39753.13 |
| 101101 | 2018 | 4 | 40270.40 |
| 101101 | 2018 | 5 | 60735.17 |
| 101101 | 2018 | 6 | 37626.92 |
| 101101 | 2018 | 7 | 52441.26 |
| 101101 | 2018 | 8 | 34252.90 |
| 101101 | 2018 | 9 | 30023.94 |
| 101101 | 2018 | 10 | 41341.30 |
| 101101 | 2018 | 11 | 51040.47 |
| 101101 | 2018 | 12 | 39680.91 |
| 101101 | 2019 | 1 | 41224.85 |
| 101101 | 2019 | 2 | 29976.22 |
| 101101 | 2019 | 3 | 39335.37 |
ggplot(estatisticas_por_vendedor, aes(x = reorder(vendedor, venda_mensal_total), y = Venda_Total, fill = vendedor)) +
geom_col(show.legend = FALSE) +
theme_minimal() +
labs(title = "Faturamento Total Acumulado por Vendedor", x = "Vendedor", y = "Total Vendido (R$)") +
scale_y_continuous(labels = scales::dollar_format(prefix = "R$ "))
## Warning in split.default(x = seq_len(nrow(x)), f = f, drop = drop, ...): data
## length is not a multiple of split variable
## Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
## returning NA
## Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
## returning NA
## Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
## returning NA
## Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
## returning NA
## Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
## returning NA
## Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
## returning NA
## Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
## returning NA
## Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
## returning NA
## Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
## returning NA
## Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
## returning NA
## Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
## returning NA
## Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
## returning NA
ggplot(vendas_limpo, aes(x = venda_diaria)) +
geom_histogram(bins = 8, fill = "darkblue", color = "white", alpha = 0.8) +
theme_minimal() +
labs(title = "Distribuição de Frequência das Vendas Diárias", x = "Valor da Venda (R$)", y = "Frequência") +
scale_x_continuous(labels = scales::dollar_format(prefix = "R$ "))
ggplot(vendas_limpo, aes(x = vendedor, y = venda_diaria, fill = vendedor)) +
geom_boxplot(show.legend = FALSE) +
theme_minimal() +
labs(title = "Análise de Outliers e Consistência de Vendas por Vendedor", x = "Vendedor", y = "Valores de Venda Diária (R$)") +
scale_y_continuous(labels = scales::dollar_format(prefix = "R$ "))
vendas_marco_2024 <- vendas_limpo %>%
filter(ano == 2024, mes == 3) %>%
group_by(vendedor) %>%
summarise(Venda_Total_Mes = sum(venda_diaria))
folha_marco_final <- vendas_marco_2024 %>%
left_join(salarios_limpo, by = "vendedor") %>%
filter(Cargo == "Vendedor") %>%
mutate(
Comissao = Venda_Total_Mes * 0.05,
FGTS = (Salario_base + Comissao) * 0.08,
INSS = (Salario_base + Comissao) * 0.11,
Salario_Liquido = Salario_base + Comissao - FGTS - INSS
) %>%
select(vendedor, Nome, Sobrenome, Salario_base, Venda_Total_Mes, Comissao, FGTS, INSS, Salario_Liquido)
kable(folha_marco_final, caption = "Folha de Pagamento com Dados Reais - Março/2024", digits = 2)
| vendedor | Nome | Sobrenome | Salario_base | Venda_Total_Mes | Comissao | FGTS | INSS | Salario_Liquido |
|---|
gerar_folha_dinamica_corporativa <- function(dados_vendas, dados_salarios, ano_alvo, mes_alvo) {
dados_vendas %>%
filter(ano == ano_alvo, mes == mes_alvo) %>%
group_by(vendedor) %>%
summarise(Venda_Total_Mes = sum(venda_diaria)) %>%
left_join(dados_salarios, by = "vendedor") %>%
filter(Cargo == "Vendedor") %>%
mutate(
Ano = ano_alvo, Mes = mes_alvo,
Comissao = Venda_Total_Mes * 0.05,
FGTS = (Salario_base + Comissao) * 0.08,
INSS = (Salario_base + Comissao) * 0.11,
Salario_Liquido = Salario_base + Comissao - FGTS - INSS
) %>%
select(vendedor, Nome, Ano, Mes, Salario_base, Venda_Total_Mes, Comissao, FGTS, INSS, Salario_Liquido)
}
if(!dir.exists("recibos_faturamento_2024")) dir.create("recibos_faturamento_2024")
for(row in 1:nrow(folha_marco_final)) {
recibo <- folha_marco_final[row, ]
estrutura_texto <- paste0(
"==================================================\n",
" BILHETE DE PAGAMENTO \n",
"==================================================\n",
"Funcionario: ", recibo$Nome, " ", recibo$Sobrenome, "\n",
"Codigo Inscricao: ", recibo$vendedor, " Competencia: 03/2024\n",
"--------------------------------------------------\n",
" Proventos:\n",
" (+) Salario Base Real: R$ ", round(recibo$Salario_base, 2), "\n",
" (+) Comissao (5%): R$ ", round(recibo$Comissao, 2), " (Vendas: R$ ", round(recibo$Venda_Total_Mes, 2), ")\n",
" Descontos:\n",
" (-) Retencao FGTS (8%):R$ ", round(recibo$FGTS, 2), "\n",
" (-) Retencao INSS (11%):R$ ", round(recibo$INSS, 2), "\n",
"--------------------------------------------------\n",
" TOTAL LIQUIDO DISPONIVEL: R$ ", round(recibo$Salario_Liquido, 2), "\n",
"==================================================\n"
)
arquivo_saida <- paste0("recibos_faturamento_2024/recibo_vendedor_", recibo$vendedor, ".txt")
writeLines(estrutura_texto, arquivo_saida)
}