diff --git a/Finance Reports/BudgetCumulativeComparison.py b/Finance Reports/BudgetCumulativeComparison.py index bbba951..b274483 100644 --- a/Finance Reports/BudgetCumulativeComparison.py +++ b/Finance Reports/BudgetCumulativeComparison.py @@ -3,9 +3,10 @@ global model sql = model.SqlContent('BudgetCumulativeGivingYoY') +model.Title = "Cumulative Giving Comparison" # Initialize data structure to store percentages by year and week -weeks = range(1, 54) # Assuming there are 52 weeks +weeks = range(1, 54) # Assuming there are 53 weeks years = [] d = [] # Will store data for each year, where each entry is a list of 52 weeks @@ -31,20 +32,20 @@ d[year_col][52] = row.Percentage # Generate Google Chart script -print """""" -print """") +print("
-""" \ No newline at end of file +""") \ No newline at end of file diff --git a/Finance Reports/BudgetSummary.sql b/Finance Reports/BudgetSummary.sql index d96aa6b..16a87f0 100644 --- a/Finance Reports/BudgetSummary.sql +++ b/Finance Reports/BudgetSummary.sql @@ -53,7 +53,7 @@ FROM #contribs c LEFT JOIN FundSets fs ON fsf.FundSetId = fs.FundSetId GROUP BY c.Month, c.year, fsf.FundSetId, COALESCE(fs.description, cf.FundName); -SELECT TOP 100 * +SELECT * INTO #summed FROM ( SELECT @@ -93,7 +93,8 @@ SELECT c.Fund, p.Giving AS 'Giving PYTD', c.Giving - p.Giving AS 'PY Difference', (c.Giving - p.Giving) * 100 / p.Giving AS 'PY Pct', - CAST(@Today AS DATE) AS 'As Of' + CAST(@Today AS DATE) AS 'As Of', + @year as 'Year' FROM #summed c LEFT JOIN #summed p ON c.Fund = p.Fund AND c.Year = p.Year + 1 WHERE c.Budget > 0 AND c.year = @year @@ -109,7 +110,8 @@ SELECT c.Fund, p.Giving AS 'Giving PYTD', c.Giving - p.Giving AS 'PY Difference', (c.Giving - p.Giving) * 100 / p.Giving AS 'PY Pct', - CAST(@Today AS DATE) AS 'As Of' + CAST(@Today AS DATE) AS 'As Of', + @year as 'Year' FROM #summed c LEFT JOIN #summed p ON c.Fund = p.Fund AND c.Year = p.Year + 1 WHERE c.Budget IS NULL AND c.year = @year diff --git a/Finance Reports/BudgetSummaryChart.py b/Finance Reports/BudgetSummaryChart.py index eab1610..6bcbbea 100644 --- a/Finance Reports/BudgetSummaryChart.py +++ b/Finance Reports/BudgetSummaryChart.py @@ -1,6 +1,9 @@ global model +global Data -sql = model.SqlContent('BudgetSummary').replace('@p1', '1') +y = Data.p1 or '1' + +sql = model.SqlContent('BudgetSummary').replace('@p1', y) d = model.SqlListDynamicData(sql) def formatMoney(num): @@ -13,8 +16,8 @@ def formatMoney(num): labelPositions = [[]] def determineLine(x): - margin = 80 - + margin = 85 + line = 1 while True: c = False @@ -23,7 +26,7 @@ def determineLine(x): for lp in labelPositions[line]: if lp is None: continue - + if lp > x-margin and lp < x+margin: line += 1 c = True @@ -38,12 +41,12 @@ def getMarkedLabel(x, y, label1, label2, textColor="#000", lineStyle="stroke:#99 line = determineLine(x) yBase = y + 10 # top of bar y += line * 50 + 10 # top of the indicator (for line 1, bottom of the bar). - + yTop = yBase - (10 if extendTop else 0) r = "".format(x, lineStyle, yTop, yBase+50) - + r += "".format(x, lineStyle, y, y+10) - + r += "".format(x, y+25, textColor) r += "{1}".format(x, label1) r += "{1}".format(x, label2) @@ -57,7 +60,9 @@ def getMarkedLabel(x, y, label1, label2, textColor="#000", lineStyle="stroke:#99 for f in d: if f['Budget FY'] is not None and f['Budget FY'] > maxBudget: maxBudget = f['Budget FY'] - + if f["Giving YTD"] is not None and f["Giving YTD"] > maxBudget: + maxBudget = f["Giving YTD"] + yCum = 0 for f in d: @@ -65,35 +70,35 @@ def getMarkedLabel(x, y, label1, label2, textColor="#000", lineStyle="stroke:#99 budgetPos = 100 + (500 * f["Budget YTD"] / maxBudget) if f["Budget YTD"] is not None else None prevPos = 100 + (500 * f["Giving PYTD"] / maxBudget) if f["Giving PYTD"] is not None else None barWidth = (500 * f["Budget FY"] / maxBudget) if f["Budget FY"] is not None else None - + chart += "".format(f['Fund']) - + # fund label # chart += "".format(3, yCum+35) # chart += "{1}".format(3, f['Fund']) # chart += "" - + # base bar if barWidth is not None: chart += """""".format(barWidth, yCum+10) - + # giving bar chart += """""".format(givingPos-100, yCum+10) - + chart += getMarkedLabel(givingPos, yCum, "Giving YTD", formatMoney(f["Giving YTD"])) - - if f["Budget YTD"] is not None and f["Budget FY"] is not None and f["Budget YTD"] / f["Budget FY"] < 10.0/12: + + if f["Budget YTD"] is not None and f["Budget FY"] is not None and f["Budget YTD"] / f["Budget FY"] < 11.2/12: chart += getMarkedLabel(budgetPos, yCum, "Budget YTD", formatMoney(f["Budget YTD"]), "#000", "stroke:#000;stroke-width:3", True) - + if f["Budget FY"] is not None: chart += getMarkedLabel(barWidth+100, yCum, "Budget FY", formatMoney(f["Budget FY"])) - + chart += getMarkedLabel(prevPos, yCum, "Giving Last Year", formatMoney(f["Giving PYTD"]), "#999") - + height = len(labelPositions) * 50 + 10 yCum += height labelPositions = [None] - + break print("""