diff --git a/AstuteSystem/sql/astute.sql b/AstuteSystem/sql/astute.sql index 33255fa..794abda 100644 --- a/AstuteSystem/sql/astute.sql +++ b/AstuteSystem/sql/astute.sql @@ -29,6 +29,12 @@ CREATE TABLE IF NOT EXISTS `change_order` ( CONSTRAINT `fk_PO_CO_POnum` FOREIGN KEY (`PO_num`) REFERENCES `po` (`PO_num`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +DROP PROCEDURE IF EXISTS astute.update_contract_amt; +CREATE PROCEDURE astute.`update_contract_amt`(PONum varchar(20)) +BEGIN +update po set contract_amt = (SELECT sum(qty*fee) from po_detail where PO_num = PONum) where PO_num = PONum; +END; + -- Dumping data for table astute.change_order: ~0 rows (approximately) /*!40000 ALTER TABLE `change_order` DISABLE KEYS */; /*!40000 ALTER TABLE `change_order` ENABLE KEYS */; diff --git a/AstuteSystem/src/main/java/com/astute/dao/SqlDAO.java b/AstuteSystem/src/main/java/com/astute/dao/SqlDAO.java index d1db438..fca2b15 100644 --- a/AstuteSystem/src/main/java/com/astute/dao/SqlDAO.java +++ b/AstuteSystem/src/main/java/com/astute/dao/SqlDAO.java @@ -161,6 +161,18 @@ public class SqlDAO extends DAO { } + public void updateContractAmount(String PONum) throws AstuteException { + try { + CallableStatement stmt = conn.prepareCall("{call update_contract_amt(?)}"); + stmt.setString(1, PONum); + stmt.executeUpdate(); + } catch (SQLException e) { + e.printStackTrace(); + throw new AstuteException(DB_ERROR,e.getMessage()); + } + } + + public void updatePODetail(String POnum, int lineItemNo, String serviceDesc, int feeTypeId, Double qty, Double fee, int serviceTypeId, Double remainingQuantity) throws AstuteException { try { // remainingQuantity is not used , need to take it out from signature eventually @@ -196,7 +208,9 @@ public class SqlDAO extends DAO { System.out.println(sql); Statement stmt = conn.createStatement(); stmt.executeUpdate(sql); - updateRemainingQty(POnum,null, lineItemNo); } + updateRemainingQty(POnum,null, lineItemNo); + } + updateContractAmount(POnum); } catch (SQLException e) { e.printStackTrace(); throw new AstuteException(DB_ERROR,e.getMessage()); @@ -247,6 +261,7 @@ public class SqlDAO extends DAO { e.printStackTrace(); throw new AstuteException(DB_ERROR,e.getMessage()); } + updateContractAmount(POnum); } public void finalizePO(String PONum) throws AstuteException {