--
-- ec_shipment_price/1
--
create or replace function ec_shipment_price(
  integer
) returns numeric as $$

DECLARE
	v_shipment_id		alias for $1;
        shipment_price          numeric;
BEGIN
        SELECT into shipment_price coalesce(sum(price_charged),0) - coalesce(sum(price_refunded),0)
        FROM ec_items
        WHERE shipment_id=v_shipment_id
        and item_state <> 'void';

        RETURN shipment_price;
END;$$ language plpgsql;