@echo off
setlocal enabledelayedexpansion

title Excel and PDF Reconciliation Utility

echo =======================================================================
echo               EXCEL AND PDF RECONCILIATION UTILITY
echo =======================================================================
echo.

:: Check if Python is installed
python --version >nul 2>&1
if %errorlevel% neq 0 (
    echo [ERROR] Python is not installed or not in your PATH.
    echo Please install Python and try again.
    echo.
    pause
    exit /b 1
)

echo [INFO] Python detected successfully.
echo [INFO] Running reconciliation script...
echo.

:: Run the script
python "%~dp0reconcile_all.py" "%~dp0."

if %errorlevel% neq 0 (
    echo.
    echo [ERROR] Reconciliation script failed. Please check the logs.
    echo.
    pause
    exit /b %errorlevel%
)

echo.
echo =======================================================================
echo                             REPORT SUMMARY
echo =======================================================================
echo.

:: Show the master summary table from the report
:: We will display the last 70 lines of the report which contains the summary table
powershell -Command "if (Test-Path '%~dp0reconciliation_report.txt') { Get-Content '%~dp0reconciliation_report.txt' -Tail 70 } else { Write-Host 'Report not found.' }"

echo.
echo =======================================================================
echo [SUCCESS] Analysis completed successfully.
echo.
echo The full report has been saved to:
echo "%~dp0reconciliation_report.txt"
echo.
echo Press any key to open the full report in Notepad and close this window.
echo =======================================================================
pause >nul

start notepad.exe "%~dp0reconciliation_report.txt"

endlocal
