diff --git a/application/models/requistion_model.php b/application/models/requistion_model.php index 0493f820..f7dbd8b2 100644 --- a/application/models/requistion_model.php +++ b/application/models/requistion_model.php @@ -357,21 +357,28 @@ ifnull(Po.Quantity,0) as POQTY,sta.StatusName * This function is used to add the Requistion into the Database * @return array $result : This is result of the query */ - function addRequistion($Requistion) - { + function addRequistion($Requistion){ $this->db->trans_start(); - $this->db->insert('T_Requestion_Master', $Requistion); - $insert_id = $this->db->affected_rows(); + $result = $this->db->insert('T_Requestion_Master', $Requistion); + $insert_id = $this->db->insert_id(); + $affected_rows = $this->db->affected_rows(); $this->db->trans_complete(); - log_message('error','add new Requisition affected rows = '.$insert_id); - if($insert_id>0) - { - // $subQuery = 'select max(ReqNo) as ReqNo from T_Requestion_Master'; - $subQuery = 'select ReqNo from T_Requestion_Master order by CreatedDate desc limit 1'; - $query = $this->db->query($subQuery); - return $query->result_array(); - } + try { + $result = ($result) ? $result : false; + if ($result && $affected_rows > 0) { + $subQuery = 'select ReqNo from T_Requestion_Master order by CreatedDate desc limit 1'; + $query = $this->db->query($subQuery); + log_message('error','add new Requisition insert_id '.$insert_id); + return $query->result_array(); + } else { + throw new Exception("database error occur requisition master details not inserted"); + } + } catch (Exception $e) { + log_message('error',$e->getMessage()); + return false; + } } + /** * This function is used to check the Request is in Draft status * @return array $result : This is result of the query