Skip to content

Commit

Permalink
added difference in budget
Browse files Browse the repository at this point in the history
  • Loading branch information
elraphty committed Apr 26, 2024
1 parent 709d601 commit 78e3470
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
2 changes: 1 addition & 1 deletion db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ func (db database) GetAllBounties(r *http.Request) []NewBounty {
languageArray := strings.Split(languages, ",")
languageLength := len(languageArray)

if workspaceUuid != "" && orgUuid != "" {
if workspaceUuid == "" && orgUuid != "" {
workspaceUuid = orgUuid
}

Expand Down
21 changes: 12 additions & 9 deletions db/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,15 +581,18 @@ type NewBountyBudget struct {
}

type StatusBudget struct {
OrgUuid string `json:"org_uuid"`
WorkspaceUuid string `json:"workspace_uuid"`
CurrentBudget uint `json:"current_budget"`
OpenBudget uint `json:"open_budget"`
OpenCount int64 `json:"open_count"`
AssignedBudget uint `json:"assigned_budget"`
AssignedCount int64 `json:"assigned_count"`
CompletedBudget uint `json:"completed_budget"`
CompletedCount int64 `json:"completed_count"`
OrgUuid string `json:"org_uuid"`
WorkspaceUuid string `json:"workspace_uuid"`
CurrentBudget uint `json:"current_budget"`
OpenBudget uint `json:"open_budget"`
OpenCount int64 `json:"open_count"`
OpenDifference int `json:"open_difference"`
AssignedBudget uint `json:"assigned_budget"`
AssignedCount int64 `json:"assigned_count"`
AssignedDifference int `json:"assigned_difference"`
CompletedBudget uint `json:"completed_budget"`
CompletedCount int64 `json:"completed_count"`
CompletedDifference int `json:"completed_difference"`
}

type BudgetInvoiceRequest struct {
Expand Down
27 changes: 18 additions & 9 deletions db/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,28 +162,37 @@ func (db database) GetWorkspaceStatusBudget(workspace_uuid string) StatusBudget
var openCount int64
db.db.Model(&Bounty{}).Where("assignee = '' ").Where("paid != true").Count(&openCount)

var openDifference int = int(orgBudget.TotalBudget - openBudget)

var assignedBudget uint
db.db.Model(&Bounty{}).Where("assignee != '' ").Where("paid != true").Select("SUM(price)").Row().Scan(&assignedBudget)

var assignedCount int64
db.db.Model(&Bounty{}).Where("assignee != '' ").Where("paid != true").Count(&assignedCount)

var assignedDifference int = int(orgBudget.TotalBudget - assignedBudget)

var completedBudget uint
db.db.Model(&Bounty{}).Where("completed = true ").Where("paid != true").Select("SUM(price)").Row().Scan(&completedBudget)

var completedCount int64
db.db.Model(&Bounty{}).Where("completed = true ").Where("paid != true").Count(&completedCount)

var completedDifference int = int(orgBudget.TotalBudget - completedBudget)

statusBudget := StatusBudget{
OrgUuid: workspace_uuid,
WorkspaceUuid: workspace_uuid,
CurrentBudget: orgBudget.TotalBudget,
OpenBudget: openBudget,
OpenCount: openCount,
AssignedBudget: assignedBudget,
AssignedCount: assignedCount,
CompletedBudget: completedBudget,
CompletedCount: completedCount,
OrgUuid: workspace_uuid,
WorkspaceUuid: workspace_uuid,
CurrentBudget: orgBudget.TotalBudget,
OpenBudget: openBudget,
OpenCount: openCount,
OpenDifference: openDifference,
AssignedBudget: assignedBudget,
AssignedCount: assignedCount,
AssignedDifference: assignedDifference,
CompletedBudget: completedBudget,
CompletedCount: completedCount,
CompletedDifference: completedDifference,
}

return statusBudget
Expand Down

0 comments on commit 78e3470

Please sign in to comment.