 --
 
 CREATE VIEW project_financials_by_services AS
-    SELECT contributions.project_id, contributions.payment_method, (sum((contributions.value - CASE WHEN contributions.payment_service_fee_paid_by_user THEN (0)::numeric ELSE contributions.payment_service_fee END)) - (sum(contributions.value) * (SELECT (configurations.value)::numeric AS value FROM configurations WHERE (configurations.name = 'platform_fee'::text)))) AS net_amount, (sum(contributions.value) * (SELECT (configurations.value)::numeric AS value FROM configurations WHERE (configurations.name = 'platform_fee'::text))) AS platform_fee, sum(contributions.payment_service_fee) AS payment_service_fee, count(*) AS total_contributions FROM (contributions JOIN projects ON ((contributions.project_id = projects.id))) WHERE ((contributions.state)::text = 'confirmed'::text) GROUP BY contributions.project_id, contributions.payment_method HAVING (contributions.payment_method IS NOT NULL);
-
-
---
---
-
+    SELECT contributions.project_id, contributions.payment_method, (contributions_fees.net_payment - (sum(contributions.value) * (SELECT (configurations.value)::numeric AS value FROM configurations WHERE (configurations.name = 'platform_fee'::text)))) AS net_amount, (sum(contributions.value) * (SELECT (configurations.value)::numeric AS value FROM configurations WHERE (configurations.name = 'platform_fee'::text))) AS platform_fee, sum(contributions.payment_service_fee) AS payment_service_fee, count(*) AS total_contributions FROM ((contributions JOIN projects ON ((contributions.project_id = projects.id))) JOIN contributions_fees ON ((contributions.id = contributions_fees.id))) WHERE ((contributions.state)::text = 'confirmed'::text) GROUP BY contributions.project_id, contributions.payment_method, contributions_fees.net_payment HAVING (contributions.payment_method IS NOT NULL);
 
 
 --

    contribution_id integer NOT NULL,
    extra_data text,
    created_at timestamp without time zone NOT NULL,
    updated_at timestamp without time zone NOT NULL
);



--

ALTER SEQUENCE images_id_seq OWNED BY images.id;


--
-- Name: matches_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE matches_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: matches_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE matches_id_seq OWNED BY matches.id;


--
-- Name: matchings_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE matchings_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: matchings_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE matchings_id_seq OWNED BY matchings.id;


--
