Advertisement
Guest User

Untitled

a guest
Jan 8th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE OR REPLACE FUNCTION ingredient_invoices_count(
  2.     _ingredient_id uuid,
  3.     _stock_id uuid,
  4.     _beginning_date timestamp without time zone,
  5.     _end_date timestamp without time zone,
  6.     _no_invoice_id uuid
  7.   )
  8.   RETURNS TABLE(count numeric) AS
  9. $BODY$
  10. declare
  11.  
  12. begin
  13.   return query
  14.     SELECT coalesce(sum(ii.count), 0)
  15.       FROM invoice_ingredients ii
  16.       Inner Join invoices invo On invo.id = ii.invoice_id
  17.       WHERE ii.is_active = true
  18.         And ii.ingredient_id = _ingredient_id
  19.         And invo.is_active = true
  20.         And invo.draft = false
  21.         And invo.receiver_id = _stock_id
  22.         And invo.date >= _beginning_date
  23.         And invo.date <= _end_date
  24.         And invo.id <> _no_invoice_id;
  25. end;
  26.  
  27. $BODY$
  28.   LANGUAGE plpgsql STABLE
  29.   COST 50
  30.   ROWS 1;
  31. ALTER FUNCTION ingredient_invoices_count(uuid, uuid, timestamp without time zone, timestamp without time zone, uuid)
  32.   OWNER TO developer;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement