This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3675 from gratipay/charge-in-arrears
Charge in arrears
- Loading branch information
Showing
7 changed files
with
529 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
BEGIN; | ||
|
||
ALTER TABLE payment_instructions ADD COLUMN due numeric(35,2) DEFAULT 0; | ||
|
||
-- Recreate the current_payment_instructions view to pick up due. | ||
DROP VIEW current_payment_instructions; | ||
CREATE VIEW current_payment_instructions AS | ||
SELECT DISTINCT ON (participant, team) * | ||
FROM payment_instructions | ||
ORDER BY participant, team, mtime DESC; | ||
|
||
-- Allow updating is_funded and due via the current_payment_instructions view for convenience. | ||
DROP FUNCTION update_payment_instruction(); | ||
CREATE FUNCTION update_payment_instruction() RETURNS trigger AS $$ | ||
BEGIN | ||
UPDATE payment_instructions | ||
SET is_funded = NEW.is_funded | ||
, due = NEW.due | ||
WHERE id = NEW.id; | ||
RETURN NULL; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
CREATE TRIGGER update_current_payment_instruction | ||
INSTEAD OF UPDATE ON current_payment_instructions | ||
FOR EACH ROW EXECUTE PROCEDURE update_payment_instruction(); | ||
END; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.