From 025f0eeadb6af5ce7fe13445b1e4af8914e6ad49 Mon Sep 17 00:00:00 2001 From: gandhimathi Date: Tue, 13 Mar 2018 17:55:31 +0530 Subject: [PATCH] changes in fees model --- .../application/models/Fees_status_model.php | 95 +++++++++++++------ 1 file changed, 66 insertions(+), 29 deletions(-) diff --git a/Apollo/api/application/models/Fees_status_model.php b/Apollo/api/application/models/Fees_status_model.php index b5164094..99bbb1c9 100755 --- a/Apollo/api/application/models/Fees_status_model.php +++ b/Apollo/api/application/models/Fees_status_model.php @@ -1130,6 +1130,7 @@ class Fees_status_model extends CI_Model $insertArray['CreatedBy'] = $data['CreatedBy']; $insertArray['CreatedOn'] = $data['CreatedOn']; $insertArray['Description'] = $data['InternalComments']; + $insertArray['PaidDescription'] = ""; $insertArray['Amount'] = $data['BillAmount']; $insertArray['Status'] = 'Approved'; $insertArray['PaymentStatus'] = false; @@ -1146,38 +1147,43 @@ class Fees_status_model extends CI_Model if($getIncome){ $insertArray['Name'] = $getIncome->TypeID; $insertArray['Type'] = $getIncome->ID; - $this->db->insert(DAYBOOKMASTER, $insertArray); + $checkInsertIn=$this->add_dayBook($insertArray); + if($checkInsertIn['addDayBookStatus']==true){ + // this is for expense come entry + $now1 = new DateTime(); + $now1->setTimezone(new DateTimezone('Asia/Kolkata')); + + $expenseArray['Date'] = $data['BillDate']; + $expenseArray['CreatedBy'] = $data['CreatedBy']; + $expenseArray['CreatedOn'] = $now1->format('Y-m-d H:i:s');; + $expenseArray['Description'] = $data['InternalComments']; + $expenseArray['PaidDescription'] = ""; + $expenseArray['Amount'] = $data['BillAmount']; + $expenseArray['Status'] = 'Approved'; + $expenseArray['PaymentStatus'] = false; + $expenseArray['FeesPaymentID'] = $paymentID; + $expenseArray['VoucherNumber'] = $data['BillNO']; + $expenseArray['PaidTo'] = $getStudentName[0]->Firstname; + $expenseArray['BranchCode'] = $data['UpdatedBy']; + + $this->db->select('ID,TypeID'); + $this->db->where('TypeID', 'I001'); + $this->db->where('TypeName', 'FEES'); + $getOutcome=$this->db->get(INCOMEOUTCOMEMASTER)->last_row(); + + if($getOutcome){ + $expenseArray['Name'] = $getOutcome->TypeID; + $expenseArray['Type'] = $getOutcome->ID; + /* $this->db->insert(DAYBOOKMASTER, $expenseArray);*/ + $checkInsertOut=$this->add_dayBook($expenseArray); + + } + + } + } - - // this is for expense come entry - $now1 = new DateTime(); - $now1->setTimezone(new DateTimezone('Asia/Kolkata')); - - $expenseArray['Date'] = $data['BillDate']; - $expenseArray['CreatedBy'] = $data['CreatedBy']; - $expenseArray['CreatedOn'] = $now1->format('Y-m-d H:i:s');; - $expenseArray['Description'] = $data['InternalComments']; - $expenseArray['Amount'] = $data['BillAmount']; - $expenseArray['Status'] = 'Approved'; - $expenseArray['PaymentStatus'] = false; - $expenseArray['FeesPaymentID'] = $paymentID; - $expenseArray['VoucherNumber'] = $data['BillNO']; - $expenseArray['PaidTo'] = $getStudentName[0]->Firstname; - $expenseArray['BranchCode'] = $data['UpdatedBy']; - - $this->db->select('ID,TypeID'); - $this->db->where('TypeID', 'I001'); - $this->db->where('TypeName', 'FEES'); - $getOutcome=$this->db->get(INCOMEOUTCOMEMASTER)->last_row(); - - if($getOutcome){ - $expenseArray['Name'] = $getOutcome->TypeID; - $expenseArray['Type'] = $getOutcome->ID; - $this->db->insert(DAYBOOKMASTER, $expenseArray); - - } return true; } else{ @@ -1692,5 +1698,36 @@ class Fees_status_model extends CI_Model } } + // add dayBook + public function add_dayBook($Arr) + { + $branch = $Arr['BranchCode']; + $sql = "SELECT * FROM ".DAYBOOKMASTER." WHERE BranchCode = '$branch' + ORDER BY CreatedOn DESC + LIMIT 1"; + $latestUpdate = $this->db->query($sql); + $latestUpdateDetails = $latestUpdate->result(); + $prevBalance = $latestUpdateDetails[0]->Balance; + if($Arr['Name'] == 'I002') { + //Income + $Arr['Balance'] = $prevBalance + $Arr['Amount']; + }else if ($Arr['Name'] == 'I001') { + //Expense + $Arr['Balance'] = $prevBalance - $Arr['Amount']; + } else { + $Arr['Balance'] = 0; + } + + $this->db->insert(DAYBOOKMASTER, $Arr); + if ($this->db->affected_rows() == '1') { + $result['addDayBookStatus'] = true; + $result['message'] = "Successfully DayBook Details Added"; + } else { + $result['addDayBookStatus'] = false; + $result['message'] = "Something went wrong.please try again"; + } + return $result; + } + } \ No newline at end of file