Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed bounty budgets addition #1633

Merged
merged 1 commit into from
May 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions db/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,42 +146,41 @@ func (db database) UpdateWorkspaceBudget(budget NewBountyBudget) NewBountyBudget

func (db database) GetPaymentHistoryByCreated(created *time.Time, workspace_uuid string) NewPaymentHistory {
ms := NewPaymentHistory{}
db.db.Where("created = ?", created).Where("workspace_uuid = ? ", workspace_uuid).Find(&ms)
db.db.Model(&NewPaymentHistory{}).Where("created = ?", created).Where("workspace_uuid = ? ", workspace_uuid).Find(&ms)
return ms
}

func (db database) GetWorkspaceBudget(workspace_uuid string) NewBountyBudget {
ms := NewBountyBudget{}
db.db.Where("workspace_uuid = ?", workspace_uuid).Find(&ms)
db.db.Model(&NewBountyBudget{}).Where("workspace_uuid = ?", workspace_uuid).Find(&ms)

return ms
}

func (db database) GetWorkspaceStatusBudget(workspace_uuid string) StatusBudget {

orgBudget := db.GetWorkspaceBudget(workspace_uuid)

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

var openCount int64
db.db.Model(&Bounty{}).Where("assignee = '' ").Where("paid != true").Count(&openCount)
db.db.Model(&NewBounty{}).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)
db.db.Model(&NewBounty{}).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)
db.db.Model(&NewBounty{}).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)
db.db.Model(&NewBounty{}).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)
db.db.Model(&NewBounty{}).Where("completed = true ").Where("paid != true").Count(&completedCount)

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

Expand Down Expand Up @@ -223,7 +222,7 @@ func (db database) AddAndUpdateBudget(invoice NewInvoiceList) NewPaymentHistory
// get Workspace budget and add payment to total budget
WorkspaceBudget := db.GetWorkspaceBudget(workspace_uuid)

if WorkspaceBudget.OrgUuid == "" {
if WorkspaceBudget.WorkspaceUuid == "" {
now := time.Now()
orgBudget := NewBountyBudget{
WorkspaceUuid: workspace_uuid,
Expand Down
Loading