linking loan transactions to branches in preparation for inter-branch account transfers

This commit is contained in:
Vishwas Babu A J
2013-08-21 22:14:17 +05:30
parent 81bde6ddad
commit b1d2b42da1
9 changed files with 128 additions and 67 deletions
@@ -0,0 +1,15 @@
ALTER TABLE `m_loan_transaction`
ADD COLUMN `office_id` BIGINT(20) NULL DEFAULT NULL AFTER `loan_id`;
/**update client loans**/
UPDATE m_loan_transaction lt set lt.office_id = (SELECT c.office_id AS officeId FROM m_loan l JOIN m_client c on l.client_id=c.id where l.id=lt.loan_id) where lt.loan_id in (Select l.id from m_loan l where l.client_id is not null);
/**update group loans**/
UPDATE m_loan_transaction lt set lt.office_id = (SELECT g.office_id AS officeId FROM m_loan l JOIN m_group g on l.group_id=g.id where l.id=lt.loan_id) where lt.loan_id in (Select l.id from m_loan l where l.group_id is not null);
/**Add foreign key constraints**/
ALTER TABLE `m_loan_transaction`
CHANGE COLUMN `office_id` `office_id` BIGINT(20) NOT NULL AFTER `loan_id`;
ALTER TABLE `m_loan_transaction`
ADD CONSTRAINT `FK_m_loan_transaction_m_office` FOREIGN KEY (`office_id`) REFERENCES `m_office` (`id`);