Metadocumentation
open-collective
open-collective
  • Welcome
  • About
    • Introduction
    • Terminology
    • Company
    • Pricing
    • Community Guidelines
    • Values
    • Team
    • Investors
    • Contributing
  • Product
    • Features
    • Roadmap
    • Comparison
    • User Profile
    • Currencies
    • Log-in System
  • Collectives
    • FAQ
    • Creating a Collective
    • Quick Start Guide
    • Customize Collective
    • Change Core Contributors
    • Tiers & Goals
    • Add Fiscal Host
    • Change Fiscal Host
    • Transparent Budget
    • Expense Policy
    • Approving Expenses
    • Updates & Comms
    • Events
    • Funding Options
    • Data Export
    • Buttons & Banners
    • Integrations
    • Zero Collective Balance
    • Closing a Collective
  • Financial Contributors
    • FAQ
    • Payments
    • Website Badge
    • Organizations
      • FAQ
      • Bulk Transfers
      • Gift Cards
      • Sustainer Resources
    • Collectives
      • Collective to Collective donations
  • Expenses & Getting Paid
    • FAQ
    • Submitting Expenses
    • Expense Comments
    • Edit an Expense
    • Tax Information
  • Fiscal Hosts
    • FAQ
    • Becoming a Fiscal Host
    • Create a Fiscal Host
    • Fiscal Host Settings
    • Invoices
    • Payouts
    • Host Dashboard
    • Add Funds Manually
    • Refunds
    • Host Fees
    • Local Tax Support
    • Agreement Templates
    • Open Source Collective
  • Contributing
    • Design
      • Design Workflow
      • Design Contribution Guidelines
    • Development
      • Contribution Guide
      • Best Practice Guidelines
      • Bounties
      • API
        • Members
        • Users / Emails
        • Collectives
        • Events
      • README Integration
      • Architecture
      • Postgres Database
      • PayPal
      • Post-Donation Redirect
      • Custom Tweets
      • Manual Reporting
      • Github Permissions
      • Translations
      • Testing with Cypress
      • Collective's locations
    • Documentation
      • Style guide
      • Suggesting changes
    • Translation
  • Internal
    • Scope
    • Team Retreats
    • Brussels Summer Team Retreat
    • Host Admin Manual
    • Newsletter
    • Support
    • Issue Labels
    • DNS Troubleshooting
    • Developer Guidelines
    • Architecture
    • Testing
    • Queries
      • Gift Cards
      • Transactions
      • Ops
      • Collectives
      • Hosts
      • Analytics
      • Emails
    • Projects
      • Maintainerati Berlin 2019
      • Season of Docs 2019
    • The Open Collective Way
      • Values
      • Community Guidelines
      • Core Contributors Guidelines
      • Core Contributors: Communication
      • Core Contributors: Expenses
      • Core contributors: Leave
      • Core Contributors: Compensation
Powered by GitBook
On this page
  • Revenue
  • Backers
  • Expenses
  • Get the breakdown of host fees per collective
  • US taxes: 1099
  • Hosts and collectives with currency mismatch
  1. Internal
  2. Queries

Hosts

Revenue

Revenue per month (host fees)

SELECT 
  substring(cast(DATE_TRUNC('month', t."createdAt") as text) from 1 for 7) as month,
  -SUM("hostFeeInHostCurrency") / 100 as revenue FROM "Transactions" t
WHERE t."HostCollectiveId"=11004
  AND t.currency='USD'
  AND t."deletedAt" is null
  AND t.type = 'CREDIT'
GROUP BY month
ORDER BY month DESC

Backers

Top backers within a certain time frame. Example with the host "Open Source Collective 501c6" (id: 11004) for 2018:

SELECT
  CONCAT('https://opencollective.com/', max(c.slug)) as "backer",
  SUM(amount) / 100 as "amount",
  max(t.currency) as "currency"
FROM "Transactions" t
LEFT JOIN "Collectives" c ON c.id=t."FromCollectiveId"
WHERE t.type='CREDIT'
  AND (t."HostCollectiveId"=11004)
  AND t."deletedAt" IS NULL
  AND t."createdAt" >= '2018-01-01'
  AND t."createdAt" < '2019-01-01'
GROUP BY t.currency, t."FromCollectiveId"
ORDER BY amount DESC

Expenses

Get all the pending and approved expenses (not PAID) from all the collectives (example with the Open Source Collective Host (id 772))

For each expense, we show the balance available in the collective. Note that the amount of the expense does not include the payment processor fees (so an expense of $100 cannot be paid via PayPal if the balance of the collective is $100). Fees are usually 2.9% + $0.30 but could be higher for international payments.

WITH 
  collectives AS (
    SELECT c.id, c.slug, m."MemberCollectiveId" FROM "Collectives" c
    LEFT JOIN "Members" m ON m."CollectiveId"=c.id
    WHERE m."MemberCollectiveId"=9805 OR m."MemberCollectiveId" = 8674 or m."MemberCollectiveId" = 9807
  ),
  balances AS (
    SELECT "CollectiveId", sum("netAmountInCollectiveCurrency") / 100 as balance
    FROM "Transactions"
    WHERE "deletedAt" IS NULL
    GROUP BY "CollectiveId"
  )
SELECT 
  e."createdAt",
  c."MemberCollectiveId" as hostId, 
  CONCAT('https://opencollective.com/',c.slug,'/expenses') as collective,
  b.balance, e.description, e.amount / 100 as amount, e.currency,
  e.category, e.status, e.attachment, e."payoutMethod", e."privateMessage"
FROM "Expenses" e 
INNER JOIN collectives c ON c.id=e."CollectiveId"
LEFT JOIN "Users" u ON u.id=e."UserId"
LEFT JOIN balances b ON b."CollectiveId" = e."CollectiveId"
WHERE e.status IN ('PENDING', 'APPROVED') AND e."deletedAt" IS NULL

Get the breakdown of host fees per collective

SELECT MAX(c.slug) as collective, SUM("hostFeeInHostCurrency") as "totalHostFeesInCents"
FROM "Transactions" t LEFT JOIN "Collectives" c ON c.id=t."CollectiveId"
WHERE t.type='CREDIT' AND c."HostCollectiveId" = 9802 AND t."createdAt" < '2018-01-01'
GROUP BY c.slug ORDER by "totalHostFeesInCents" DESC

US taxes: 1099

Get all people to whom a host paid more than $600 in a given year in given categories. And get all the expenses from those people.

WITH "totalExpenses" AS (
  SELECT "UserId", (SUM(amount) / 100) as "totalAmount"
  FROM "Expenses" e
  WHERE e."createdAt" >= '2016-01-01' AND e."createdAt" < '2017-01-01'
  AND e.currency = 'USD'
  AND e.status = 'PAID'
  GROUP BY "UserId"
 )

SELECT g.slug, u.username, u."firstName", u."lastName", u."email", e.title, e.category, (e.amount/100) as amount, e.currency, e.attachment
FROM "Expenses" e 
LEFT JOIN "totalExpenses" te ON te."UserId" = e."UserId"
LEFT JOIN "Users" u ON u.id = e."UserId"
LEFT JOIN "Groups" g on g.id = e."GroupId"
WHERE te."totalAmount" >= 600 
AND g.slug NOT LIKE '%wwcode%'
AND e."deletedAt" is NULL
AND e.category IN ('Office', 'Engineering', 'Other')
AND u.username NOT IN ('xdamman', 'piamancini')
ORDER BY u.id

Hosts and collectives with currency mismatch

SELECT
  count(*) as count, max(hc.slug) as "host", max(hc.id) as "HostCollectiveId",
  max(hc.currency) as "host.currency",
  max(c.slug) as "collective", max(c.currency) as "collective.currency",
  max(t.currency) as "transaction.currency",
  max(t."hostCurrency") as "transaction.hostCurrency",
  upper(t.data -> 'balanceTransaction' ->> 'currency') as "stripe.currency",
  min(t."createdAt") as "firstTransactionAt",
  max(t."createdAt") as "lastTransactionAt"
FROM "Transactions" t
LEFT JOIN "Collectives" hc ON hc.id=t."HostCollectiveId"
LEFT JOIN "Collectives" c ON c.id=t."CollectiveId"
WHERE t."hostCurrency" != hc.currency
  AND t."deletedAt" IS NULL
GROUP BY t."HostCollectiveId", t."CollectiveId", "stripe.currency"
ORDER BY count DESC
PreviousCollectivesNextAnalytics

Last updated 5 years ago