diff --git a/db/db.go b/db/db.go index d2af69fb5..ed1fd7e18 100644 --- a/db/db.go +++ b/db/db.go @@ -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 } diff --git a/db/structs.go b/db/structs.go index 7f1bf8ea6..6ab15f38d 100644 --- a/db/structs.go +++ b/db/structs.go @@ -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 { diff --git a/db/workspaces.go b/db/workspaces.go index d1e77b596..f737bdd31 100644 --- a/db/workspaces.go +++ b/db/workspaces.go @@ -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