Simplify finance dashboard overview
This commit is contained in:
@@ -46,3 +46,73 @@ Default source:
|
||||
If the SQL instance or database name differs:
|
||||
|
||||
.\Export-SageSpainSalesCsv.ps1 -ServerInstance "localhost" -Database "Sage" -ExportMode Full -Year 2025
|
||||
|
||||
|
||||
Automatic upload to SharePoint with rclone
|
||||
==========================================
|
||||
|
||||
Target SharePoint folder:
|
||||
|
||||
https://trafagag.sharepoint.com/sites/WorldwideBIPlatform/Shared%20Documents/Import/Finance/Spanien
|
||||
|
||||
Decoded folder path:
|
||||
|
||||
Shared Documents/Import/Finance/Spanien
|
||||
|
||||
Recommended rclone setup on the Spain Sage server:
|
||||
|
||||
1. Install rclone.
|
||||
2. Run:
|
||||
|
||||
rclone config
|
||||
|
||||
3. Create a new remote for the SharePoint document library.
|
||||
|
||||
Recommended remote name:
|
||||
|
||||
trafag-bi
|
||||
|
||||
The remote should point to the document library root "Shared Documents" of:
|
||||
|
||||
https://trafagag.sharepoint.com/sites/WorldwideBIPlatform
|
||||
|
||||
Then this target path is used by the wrapper script:
|
||||
|
||||
trafag-bi:Import/Finance/Spanien
|
||||
|
||||
Test rclone:
|
||||
|
||||
rclone lsd trafag-bi:
|
||||
rclone lsd trafag-bi:"Import/Finance"
|
||||
rclone lsd trafag-bi:"Import/Finance/Spanien"
|
||||
|
||||
Run daily range export and upload, default window yesterday until today:
|
||||
|
||||
.\Run-SpainExportAndUpload.ps1
|
||||
|
||||
Explicit range:
|
||||
|
||||
.\Run-SpainExportAndUpload.ps1 -ExportMode Range -DateFilter LineRegistrationDate -FromDate "2026-06-02" -ToDate "2026-06-03"
|
||||
|
||||
Full export and upload:
|
||||
|
||||
.\Run-SpainExportAndUpload.ps1 -ExportMode Full -Year 2025
|
||||
|
||||
If the rclone remote has another name:
|
||||
|
||||
.\Run-SpainExportAndUpload.ps1 -RcloneRemote "YOUR_REMOTE_NAME"
|
||||
|
||||
If rclone.exe is not in PATH:
|
||||
|
||||
.\Run-SpainExportAndUpload.ps1 -RcloneExe "C:\Tools\rclone\rclone.exe"
|
||||
|
||||
Suggested Windows Task Scheduler command:
|
||||
|
||||
powershell.exe -NoProfile -ExecutionPolicy Bypass -File C:\Trafag\SageSpain\Run-SpainExportAndUpload.ps1
|
||||
|
||||
Important:
|
||||
|
||||
- The export script only reads SQL Server data.
|
||||
- rclone only uploads the generated CSV and matching summary file.
|
||||
- For daily deltas use ExportMode Range with DateFilter LineRegistrationDate.
|
||||
- ToDate is exclusive.
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
param(
|
||||
[string]$ServerInstance = "localhost",
|
||||
[string]$Database = "Sage",
|
||||
[ValidateSet("Full", "Range")]
|
||||
[string]$ExportMode = "Range",
|
||||
[ValidateSet("InvoiceDate", "LineRegistrationDate")]
|
||||
[string]$DateFilter = "LineRegistrationDate",
|
||||
[int]$Year = 2025,
|
||||
[datetime]$FromDate = (Get-Date).Date.AddDays(-1),
|
||||
[datetime]$ToDate = (Get-Date).Date,
|
||||
[string]$BaseDirectory = "C:\Trafag\SageSpain",
|
||||
[string]$RcloneExe = "rclone",
|
||||
[string]$RcloneRemote = "trafag-bi",
|
||||
[string]$RcloneTarget = "Import/Finance/Spanien"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$scriptDirectory = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$exportScript = Join-Path $scriptDirectory "Export-SageSpainSalesCsv.ps1"
|
||||
if (-not (Test-Path -LiteralPath $exportScript)) {
|
||||
throw "Export script not found: $exportScript"
|
||||
}
|
||||
|
||||
$outputDirectory = Join-Path $BaseDirectory "out"
|
||||
$logDirectory = Join-Path $BaseDirectory "logs"
|
||||
New-Item -ItemType Directory -Force -Path $outputDirectory, $logDirectory | Out-Null
|
||||
|
||||
$exportArgs = @(
|
||||
"-ServerInstance", $ServerInstance,
|
||||
"-Database", $Database,
|
||||
"-ExportMode", $ExportMode,
|
||||
"-DateFilter", $DateFilter,
|
||||
"-Year", $Year,
|
||||
"-OutputDirectory", $outputDirectory
|
||||
)
|
||||
|
||||
if ($ExportMode -eq "Range") {
|
||||
$exportArgs += @(
|
||||
"-FromDate", $FromDate.ToString("yyyy-MM-dd"),
|
||||
"-ToDate", $ToDate.ToString("yyyy-MM-dd")
|
||||
)
|
||||
}
|
||||
|
||||
& $exportScript @exportArgs
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Spain Sage export failed with exit code $LASTEXITCODE"
|
||||
}
|
||||
|
||||
$latestRun = Get-ChildItem -LiteralPath $outputDirectory -Directory |
|
||||
Sort-Object LastWriteTime -Descending |
|
||||
Select-Object -First 1
|
||||
if ($null -eq $latestRun) {
|
||||
throw "No export run directory found in $outputDirectory"
|
||||
}
|
||||
|
||||
$rcloneLog = Join-Path $logDirectory ("rclone-spain-" + (Get-Date -Format "yyyyMMdd") + ".log")
|
||||
$target = "${RcloneRemote}:$RcloneTarget"
|
||||
|
||||
& $RcloneExe copy $latestRun.FullName $target `
|
||||
--include "*.csv" `
|
||||
--include "*_summary.txt" `
|
||||
--log-file $rcloneLog `
|
||||
--log-level INFO
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "rclone upload failed with exit code $LASTEXITCODE"
|
||||
}
|
||||
|
||||
Write-Host "Spain export and upload finished."
|
||||
Write-Host "Local export: $($latestRun.FullName)"
|
||||
Write-Host "SharePoint target: $target"
|
||||
Write-Host "rclone log: $rcloneLog"
|
||||
Reference in New Issue
Block a user