generate excel worksheets when data is available instead of on-demand
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -637,6 +639,29 @@ func CreateTableReport(logger *slog.Logger, Database db.Database, ctx context.Co
|
||||
return buffer.Bytes(), nil
|
||||
}
|
||||
|
||||
// SaveTableReport renders a table report and writes it to the destination directory with a .xlsx extension.
|
||||
func SaveTableReport(logger *slog.Logger, Database db.Database, ctx context.Context, tableName, destDir string) (string, error) {
|
||||
if err := db.ValidateTableName(tableName); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if strings.TrimSpace(destDir) == "" {
|
||||
return "", fmt.Errorf("destination directory is empty")
|
||||
}
|
||||
if err := os.MkdirAll(destDir, 0o755); err != nil {
|
||||
return "", fmt.Errorf("failed to create reports directory: %w", err)
|
||||
}
|
||||
|
||||
data, err := CreateTableReport(logger, Database, ctx, tableName)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
filename := filepath.Join(destDir, fmt.Sprintf("%s.xlsx", tableName))
|
||||
if err := os.WriteFile(filename, data, 0o644); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return filename, nil
|
||||
}
|
||||
|
||||
func addTotalsChartSheet(logger *slog.Logger, database db.Database, ctx context.Context, xlsx *excelize.File, tableName string) {
|
||||
if strings.HasPrefix(tableName, "inventory_daily_summary_") {
|
||||
suffix := strings.TrimPrefix(tableName, "inventory_daily_summary_")
|
||||
|
||||
Reference in New Issue
Block a user