Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR REPLACE FUNCTION ingredient_invoices_count(
- _ingredient_id uuid,
- _stock_id uuid,
- _beginning_date timestamp without time zone,
- _end_date timestamp without time zone,
- _no_invoice_id uuid
- )
- RETURNS TABLE(count numeric) AS
- $BODY$
- declare
- begin
- return query
- SELECT coalesce(sum(ii.count), 0)
- FROM invoice_ingredients ii
- Inner Join invoices invo On invo.id = ii.invoice_id
- WHERE ii.is_active = true
- And ii.ingredient_id = _ingredient_id
- And invo.is_active = true
- And invo.draft = false
- And invo.receiver_id = _stock_id
- And invo.date >= _beginning_date
- And invo.date <= _end_date
- And invo.id <> _no_invoice_id;
- end;
- $BODY$
- LANGUAGE plpgsql STABLE
- COST 50
- ROWS 1;
- ALTER FUNCTION ingredient_invoices_count(uuid, uuid, timestamp without time zone, timestamp without time zone, uuid)
- OWNER TO developer;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement