{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e9ac37de",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total de linhas: 875\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UN</th>\n",
       "      <th>PDV</th>\n",
       "      <th>CIDADE</th>\n",
       "      <th>LOCAL DO PDV</th>\n",
       "      <th>RECEITA PERÍODO ANTERIOR</th>\n",
       "      <th>RECEITA PERÍODO ATUAL</th>\n",
       "      <th>META PEF</th>\n",
       "      <th>GAP ACORDADO (R$)</th>\n",
       "      <th>GAP ACORDADO (%)</th>\n",
       "      <th>REALIZADO</th>\n",
       "      <th>arquivo_base</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Quem Disse Berenice</td>\n",
       "      <td>910173</td>\n",
       "      <td>Maceio</td>\n",
       "      <td>Shopping</td>\n",
       "      <td>173913.81</td>\n",
       "      <td>0</td>\n",
       "      <td>167464.53</td>\n",
       "      <td>-167464.53</td>\n",
       "      <td>-1</td>\n",
       "      <td>0</td>\n",
       "      <td>C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistên...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>O Boticário</td>\n",
       "      <td>21381</td>\n",
       "      <td>Capim Grosso</td>\n",
       "      <td>Rua</td>\n",
       "      <td>120594.40</td>\n",
       "      <td>0</td>\n",
       "      <td>155346.60</td>\n",
       "      <td>-155346.60</td>\n",
       "      <td>-1</td>\n",
       "      <td>0</td>\n",
       "      <td>C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistên...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>O Boticário</td>\n",
       "      <td>23707</td>\n",
       "      <td>Vitoria Da Conquista</td>\n",
       "      <td>Rua</td>\n",
       "      <td>131055.70</td>\n",
       "      <td>0</td>\n",
       "      <td>159139.40</td>\n",
       "      <td>-159139.40</td>\n",
       "      <td>-1</td>\n",
       "      <td>0</td>\n",
       "      <td>C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistên...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>O Boticário</td>\n",
       "      <td>21068</td>\n",
       "      <td>Simoes Filho</td>\n",
       "      <td>Cash &amp; Carry</td>\n",
       "      <td>146448.38</td>\n",
       "      <td>0</td>\n",
       "      <td>144695.45</td>\n",
       "      <td>-144695.45</td>\n",
       "      <td>-1</td>\n",
       "      <td>0</td>\n",
       "      <td>C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistên...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>O Boticário</td>\n",
       "      <td>20441</td>\n",
       "      <td>Lagarto</td>\n",
       "      <td>Rua</td>\n",
       "      <td>225341.32</td>\n",
       "      <td>0</td>\n",
       "      <td>311878.51</td>\n",
       "      <td>-311878.51</td>\n",
       "      <td>-1</td>\n",
       "      <td>0</td>\n",
       "      <td>C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistên...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    UN     PDV                CIDADE  LOCAL DO PDV  \\\n",
       "0  Quem Disse Berenice  910173                Maceio      Shopping   \n",
       "1         O Boticário   21381          Capim Grosso           Rua   \n",
       "2         O Boticário   23707  Vitoria Da Conquista           Rua   \n",
       "3         O Boticário   21068          Simoes Filho  Cash & Carry   \n",
       "4         O Boticário   20441               Lagarto           Rua   \n",
       "\n",
       "   RECEITA PERÍODO ANTERIOR  RECEITA PERÍODO ATUAL   META PEF  \\\n",
       "0                 173913.81                      0  167464.53   \n",
       "1                 120594.40                      0  155346.60   \n",
       "2                 131055.70                      0  159139.40   \n",
       "3                 146448.38                      0  144695.45   \n",
       "4                 225341.32                      0  311878.51   \n",
       "\n",
       "   GAP ACORDADO (R$) GAP ACORDADO (%) REALIZADO  \\\n",
       "0         -167464.53               -1         0   \n",
       "1         -155346.60               -1         0   \n",
       "2         -159139.40               -1         0   \n",
       "3         -144695.45               -1         0   \n",
       "4         -311878.51               -1         0   \n",
       "\n",
       "                                        arquivo_base  \n",
       "0  C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistên...  \n",
       "1  C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistên...  \n",
       "2  C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistên...  \n",
       "3  C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistên...  \n",
       "4  C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistên...  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import os\n",
    "import pandas as pd\n",
    "import glob\n",
    "\n",
    "# Caminho da pasta onde estão os arquivos\n",
    "pasta = r'C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistência Suprimentos - 2025\\SUPRIMENTOS\\DB_ORÇAMENTO FIANCEIRO\\meta pef baixada hj'\n",
    "\n",
    "# Lista todos os arquivos .xlsx no diretório\n",
    "arquivos_xlsx = glob.glob(os.path.join(pasta, '*.xlsx'))\n",
    "\n",
    "# Lista para armazenar os DataFrames\n",
    "dfs = []\n",
    "\n",
    "# Loop pelos arquivos encontrados\n",
    "for arquivo in arquivos_xlsx:\n",
    "    try:\n",
    "        df = pd.read_excel(arquivo, sheet_name='PERFORMANCE POR PDV', skiprows=2)\n",
    "        df['arquivo_base'] = arquivo\n",
    "        dfs.append(df)\n",
    "    except Exception as e:\n",
    "        print(f\"Erro ao ler {arquivo}: {e}\")\n",
    "\n",
    "# Concatena todos os DataFrames\n",
    "compilado_pef = pd.concat(dfs, ignore_index=True)\n",
    "\n",
    "# Exibe informações do DataFrame final\n",
    "print(f\"Total de linhas: {len(compilado_pef)}\")\n",
    "compilado_pef.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "40a4ace1",
   "metadata": {},
   "outputs": [],
   "source": [
    "compilado_pef.to_excel(r'C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistência Suprimentos - 2025\\SUPRIMENTOS\\DB_ORÇAMENTO FIANCEIRO\\PEF_ATUALIZADA.xlsx',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "949b7fdc",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
