?
Current Path : /home1/savoy/public_html/savoyglobal.net/sec_old/application/models/ |
Linux gator3171.hostgator.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64 |
Current File : /home1/savoy/public_html/savoyglobal.net/sec_old/application/models/accountingmodel.php |
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Accountingmodel extends CI_Model { function __construct() { // Call the Model constructor parent::__construct(); // $this->load->model('hrmodel'); } function search_currency($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('finance_currency'); $this->db->order_by('currency_id', 'asc'); $data['results'] = $this->db->get(); return $data; } function insert_currency($postdata) { $data = array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); if ($postdata['default_currency'] == 1) { $tblValues = array( 'default_currency' => 0, ); $this->db->update('finance_currency', $tblValues); } $tblValues = array( 'currency_id' => $masterid, 'currency_name' => $postdata['currency_name'], 'currency_code' => $postdata['currency_code'], 'default_currency' => $postdata['default_currency'], ); $this->db->insert('finance_currency', $tblValues); $data['resfunction'] = 'search_currency'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } function update_currency($postdata) { $data = array(); $this->db->trans_begin(); if ($postdata['default_currency'] == 1) { $tblValues = array( 'default_currency' => 0, ); $this->db->update('finance_currency', $tblValues); } $tblValues = array( 'currency_name' => $postdata['currency_name'], 'currency_code' => $postdata['currency_code'], 'default_currency' => $postdata['default_currency'], ); $this->db->where('currency_id', $postdata['currency_id']); $this->db->update('finance_currency', $tblValues); $data['resfunction'] = 'search_currency'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } function search_fiscal_year($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('finance_fiscal_year'); $this->db->join('master', 'master_id=fiscal_year_id'); $this->db->order_by('fiscal_year_id', 'asc'); $data['results'] = $this->db->get(); return $data; } function insert_fiscal_year($postdata) { $data = array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $fromdate = $this->mastermodel->convertdateformat($postdata['fiscal_year_start']); $todate = $this->mastermodel->convertdateformat($postdata['fiscal_year_end']); $tblValues = array( 'fiscal_year_id' => $masterid, 'fiscal_year_start' => $fromdate, 'fiscal_year_end' => $todate, ); $this->db->insert('finance_fiscal_year', $tblValues); $data['resfunction'] = 'search_fiscal_year'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } function update_fiscal_year($postdata) { $data = array(); $this->db->trans_begin(); $fromdate = $this->mastermodel->convertdateformat($postdata['fiscal_year_start']); $todate = $this->mastermodel->convertdateformat($postdata['fiscal_year_end']); $closed = $postdata['closed']; $tblValues = array( 'fiscal_year_start' => $fromdate, 'fiscal_year_end' => $todate, 'closed' => $closed ); $this->db->where('fiscal_year_id', $postdata['fiscal_year_id']); $this->db->update('finance_fiscal_year', $tblValues); $data['resfunction'] = 'search_fiscal_year'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } function set_fiscal_year_current($fiscal_year_id) { $tblValues = array('default' => "1"); $this->db->where('fiscal_year_id', $fiscal_year_id); $this->db->update('finance_fiscal_year', $tblValues); $tblValues = array('default' => "0"); $this->db->where('fiscal_year_id!=', $fiscal_year_id); $this->db->update('finance_fiscal_year', $tblValues); $data = $this->db->query($sql); } function search_sub_ac_settings($pagenum) { $data = array(); $q = $this->db->get('finance_sub_account_settings'); $data['results'] = $q->row(); return $data; } function insert_sub_ac_settings($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( 'employee' => $postdata['employee'], 'profitloss' => $postdata['profitloss'], 'salary' => $postdata['salary'], 'student' => $postdata['student'], 'franchisee' => $postdata['franchisee'], 'bank_account' => $postdata['bank_account'] ); $this->db->insert('finance_sub_account_settings', $tblValues); $data['resfunction'] = 'search_sub_ac_settings'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } function update_sub_ac_settings($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( 'employee' => $postdata['employee'], 'profitloss' => $postdata['profitloss'], 'salary' => $postdata['salary'], 'student' => $postdata['student'], 'franchisee' => $postdata['franchisee'], 'bank_account' => $postdata['bank_account'], 'employee_fee_payable' => $postdata['employee_fee_payable'] ); $this->db->where('sub_account_settings_id', '1'); $this->db->update('finance_sub_account_settings', $tblValues); $data['resfunction'] = 'search_sub_ac_settings'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } function search_transaction_code($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('finance_transaction_code'); $this->db->order_by('transaction_id ', 'asc'); $data['results'] = $this->db->get(); return $data; } function insert_transaction_code($postdata) { $data = array(); $this->db->trans_begin(); // $masterid = $this->mastermodel->insertmasterdata(); $tblValues = array( // 'transaction_id'=>$masterid, 'transaction_code' => $postdata['transaction_code'], 'transaction_name' => $postdata['transaction_name'], ); $this->db->insert('finance_transaction_code', $tblValues); $data['resfunction'] = 'search_transaction_code'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } function update_transaction_code($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( 'transaction_code' => $postdata['transaction_code'], 'transaction_name' => $postdata['transaction_name'], ); $this->db->where('transaction_id', $postdata['transaction_id']); $this->db->update('finance_transaction_code', $tblValues); $data['resfunction'] = 'search_transaction_code'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } function search_main_account($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('finance_chart_master'); $this->db->join('finance_chart_type', 'finance_chart_type.chart_type_id=finance_chart_master.chart_type_id'); $this->db->where('parent', '0'); $this->db->order_by('finance_chart_master.chart_type_id', 'asc'); $data['results'] = $this->db->get(); return $data; } function insert_main_account($postdata) { $data = array(); $this->db->trans_begin(); $chart_type_sort = $this->mastermodel->get_single_field_value('finance_chart_type', 'sort', 'chart_type_id ', $postdata['chart_type_id']); $start = $chart_type_sort * 100000; $max_code = $start + 50000; $code = $this->main_account_code_increment($start, $max_code); $data['resfunction'] = 'search_main_account'; if ($max_code > ($code + 1)) { if ($code == 0) { $acc_code = $start + 1; } else { $acc_code = $code + 1; } $count = $this->mastermodel->get_num_rows('finance_chart_master', 'chart_account_code', $acc_code); if ($count == 0) { $tblValues = array( 'chart_account_code' => $acc_code, 'chart_account_name' => $postdata['chart_account_name'], 'chart_type_id' => $postdata['chart_type_id'], ); $this->db->insert('finance_chart_master', $tblValues); $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } else { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Account Beyond the Limit'; return $data; } } function update_main_account($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( 'chart_account_name' => $postdata['chart_account_name'] ); $this->db->where('chart_master_id', $postdata['chart_master_id']); $this->db->update('finance_chart_master', $tblValues); $data['resfunction'] = 'search_main_account'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } function search_sub_account($pagenum) { $data = array(); $this->db->select('c1.chart_master_id as chart_master_id, c1.chart_account_code as chart_account_code, c1.chart_account_name as chart_account_name, chart_type_name, c2.chart_account_code as main_account_code, c2.chart_account_name as main_account_name'); $this->db->from('finance_chart_master c1'); $this->db->join('finance_chart_type', 'finance_chart_type.chart_type_id=c1.chart_type_id'); $this->db->join('finance_chart_master c2', 'c2.chart_master_id=c1.parent'); $this->db->where('c1.parent !=', '0'); $this->db->order_by('c2.chart_account_name', 'asc'); $data['results'] = $this->db->get(); return $data; } function insert_sub_account($postdata) { $data = array(); $this->db->trans_begin(); $account_name = $postdata['chart_account_name']; $acc_subexp = $postdata['parent_id']; $explode = explode("~", $acc_subexp); $acc_parent = $explode[0]; $acc_type = $explode[1]; $chart_type_sort = $this->mastermodel->get_single_field_value('finance_chart_type', 'sort', 'chart_type_id ', $acc_type); $start = ($chart_type_sort * 100000) + 50000; $max_code = $start + 50000; $code = $this->main_account_code_increment($start, $max_code); $data['resfunction'] = 'search_sub_account'; if ($max_code > ($code + 1)) { if ($code == 0) { $acc_code = $start + 1; } else { $acc_code = $code + 1; } $tblValues = array( 'chart_account_code' => $acc_code, 'chart_account_name' => $account_name, 'chart_type_id' => $acc_type, 'parent' => $acc_parent ); $this->db->insert('finance_chart_master', $tblValues); } else { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Byond Limit'; return $data; } if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } function update_sub_account($postdata) { $data = array(); $this->db->trans_begin(); $account_name = $postdata['chart_account_name']; $tblValues = array( 'chart_account_code' => $postdata['chart_account_code'], 'chart_account_name' => $account_name, ); $this->db->where('chart_master_id', $postdata['chart_master_id']); $this->db->update('finance_chart_master', $tblValues); $data['resfunction'] = 'search_sub_account'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } function search_bank_account($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('finance_bank_account'); $this->db->order_by('bank_account_id', 'asc'); $data['results'] = $this->db->get(); return $data; } function insert_bank_account($postdata) { $data = array(); $this->db->trans_begin(); $account_name = $postdata['chart_account_name']; $acc_subexp = $postdata['parent_id']; $explode = explode("~", $acc_subexp); $acc_parent = $explode[0]; $acc_type = $explode[1]; $start = ($acc_type * 100000) + 50000; $max_code = $start + 50000; $code = $this->main_account_code_increment($start, $max_code); $data['resfunction'] = 'search_bank_account'; if ($max_code > ($code + 1)) { if ($code == 0) { $acc_code = $start + 1; } else { $acc_code = $code + 1; } $tblValues = array( 'chart_account_code' => $acc_code, 'chart_account_name' => $account_name, 'chart_type_id' => $acc_type, 'parent' => $acc_parent ); $this->db->insert('finance_chart_master', $tblValues); $tblValues = array( 'chart_account_code' => $acc_code, 'bank_account_number' => $postdata['bank_account_number'], 'bank_name' => $postdata['bank_name'], 'bank_address' => $postdata['bank_address'], 'currency_id' => $postdata['currency_id'], ); $this->db->insert('finance_bank_account', $tblValues); } else { $data['res'] = 0; $data['msg'] = 'Beyond Limit'; return $data; } if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } function update_bank_account($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( 'bank_account_number' => $postdata['bank_account_number'], 'bank_name' => $postdata['bank_name'], 'bank_address' => $postdata['bank_address'], 'currency_id' => $postdata['currency_id'], ); $this->db->where('bank_account_id', $postdata['bank_account_id']); $this->db->update('finance_bank_account', $tblValues); $data['resfunction'] = 'search_bank_account'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } /* functions for Post Dated Cheque */ function search_post_dated_cheque($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('finance_journal_refs'); $this->db->join('finance_cheque_info', 'finance_cheque_info.journal_id=finance_journal_refs.journal_id'); $this->db->where('tr_type', 'post_dated_cheque'); $this->db->where('posted', '0'); $data['results'] = $this->db->get(); return $data; } function search_post_dated_cheque_posted($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('finance_journal_refs'); $this->db->join('finance_cheque_info', 'finance_cheque_info.journal_id=finance_journal_refs.journal_id'); $this->db->where('tr_type', 'post_dated_cheque'); $this->db->where('posted', '1'); $data['results'] = $this->db->get(); return $data; } function insert_post_dated_cheque($postdata) { $data = array(); $data['resfunction'] = 'search_post_dated_cheque'; $fisc_year_id = $this->accountingmodel->getfiscalyearid(); $default_currency = $this->accountingmodel->getcurrency(); if ($fisc_year_id != 0 && $default_currency != 0) { $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $description = ""; $transaction_id = $postdata['transaction_id']; $payment_type = $postdata['payment_type_id']; // $reference = $this->get_transaction_code($transaction_id, $payment_type); $reference = date('ymdHsi'); $tblValues = array( 'journal_id' => $masterid, // 'journal_date' => $this->mastermodel->convertdateformat($postdata['journal_date']), 'description' => $description, 'reference' => $reference, 'currency_id' => $default_currency, 'payment_type_id' => $payment_type, 'transaction_id' => $transaction_id, 'tr_type' => 'post_dated_cheque' ); $this->db->insert('finance_journal_refs', $tblValues); if ($payment_type == 2) { $tblValues = array( 'journal_id' => $masterid, 'cheque_date' => $this->mastermodel->convertdateformat($postdata['cheque_date']), 'cheque_no ' => $postdata['cheque_no'], 'chart_account_code' => "", 'cheque_info' => $postdata['cheque_info'] ); $this->db->insert('finance_cheque_info', $tblValues); } $total_amount = 0; $i = 1; $charttypes = ""; while (isset($postdata['payment_to_id' . $i])) { if ($postdata['payment_to_id' . $i] != "") { $chart_account = explode("~", $postdata['payment_to_id' . $i]); $chart_account_id = $chart_account[0]; $chart_account_code = $chart_account[1]; $chart_account_name = $chart_account[2]; $total_amount+=$postdata['amount' . $i]; $description = $postdata['description' . $i]; $debit = 0; $credit = 0; if ($transaction_id == 1) { $debit = $postdata['amount' . $i]; $credit = 0; } if ($transaction_id == 2) { $debit = 0; $credit = $postdata['amount' . $i]; } $tblValues = array( 'journal_id' => $masterid, 'chart_account_code' => $chart_account_code, 'debit' => $debit, 'credit' => $credit, 'description' => $description, 'fiscal_year_id' => $fisc_year_id, ); $this->db->insert('finance_journal', $tblValues); $charttypes.=$chart_account_name . ','; } $i++; } if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } else { $data['res'] = 0; if ($fisc_year_id == 0) $data['msg'] = 'Fiscal Year Not Set.'; else if ($default_currency == 0) $data['msg'] = 'Default Currency Not Set.'; else $data['msg'] = 'Fiscal Year and Default Currency Not Set.'; return $data; } } function post_pdc($postdata) { $data = array(); $data['resfunction'] = 'search_post_dated_cheque'; $fisc_year_id = $this->accountingmodel->getfiscalyearid(); $default_currency = $this->accountingmodel->getcurrency(); if ($fisc_year_id != 0 && $default_currency != 0) { $this->db->trans_begin(); $journal_id = $postdata['journal_id']; $account = explode("~", $postdata['bankacc_id']); $transaction_id=$postdata['transaction_id']; $account_to_id = $account[0]; $account_to_code = $account[1]; $account_to_name = $account[2]; if ($transaction_id == 1) { $description = "Post Dated Cheque - Payment Recived From " . $account_to_code . "-" . $account_to_name; } if ($transaction_id == 2) { $description = "Post Dated Cheque - Payment Made to " . $account_to_code . "-" . $account_to_name; } $transaction_id = $postdata['transaction_id']; $payment_type = $postdata['payment_type_id']; $reference = $this->get_transaction_code($transaction_id, $payment_type); //echo $reference;die(); $tblValues = array( 'journal_date' => $this->mastermodel->convertdateformat($postdata['journal_date']), 'description' => $description, 'currency_id' => $default_currency, 'payment_type_id' => $postdata['payment_type_id'], 'reference' => $reference, 'posted' => '1' ); $this->db->where('journal_id', $journal_id); $this->db->update('finance_journal_refs', $tblValues); $tblValues = array( 'chart_account_code' => $account_to_code ); $this->db->where('journal_id', $journal_id); $this->db->update('finance_cheque_info', $tblValues); if ($transaction_id == 2) $journal = $this->mastermodel->get_data_dual('finance_journal', $journal_id, 'journal_id', '0', 'debit', 'journal_id'); if ($transaction_id == 1) $journal = $this->mastermodel->get_data_dual('finance_journal', $journal_id, 'journal_id', '0', 'credit', 'journal_id'); $tot_credit = 0; $tot_debit = 0; $total = 0; $charttypes = ""; foreach ($journal as $row) { if ($row['description'] == "") { $tblValues = array( 'description' => $description ); $this->db->where('id', $row['id']); $this->db->update('finance_journal', $tblValues); } $tot_credit+=$row['credit']; $tot_debit+=$row['debit']; if ($row['debit'] != 0) { $total+=$row['debit']; } else { $total+=$row['credit']; } $charttypes.=$row['chart_account_code'] . ','; } $total_amount = $total; $debit = 0; $credit = 0; if ($transaction_id == 1) { $debit = 0; $credit = $total_amount; $description = "Post Dated Cheque - Payment Made to " . $charttypes; } if ($transaction_id == 2) { $debit = $total_amount; $credit = 0; $description = "Post Dated Cheque - Payment Received From " . $charttypes; } $tblValues = array( 'journal_id' => $journal_id, 'chart_account_code' => $account_to_code, 'credit' => $credit, 'debit' => $debit, 'description' => $description, 'fiscal_year_id' => $fisc_year_id ); $this->db->insert('finance_journal', $tblValues); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } else { $data['res'] = 0; if ($fisc_year_id == 0) $data['msg'] = 'Fiscal Year Not Set.'; else if ($default_currency == 0) $data['msg'] = 'Default Currency Not Set.'; else $data['msg'] = 'Fiscal Year and Default Currency Not Set.'; return $data; } } function update_post_dated_cheque($postdata) { $data = array(); $data['resfunction'] = 'search_post_dated_cheque'; $fisc_year_id = $this->accountingmodel->getfiscalyearid(); $default_currency = $this->accountingmodel->getcurrency(); if ($fisc_year_id != 0 && $default_currency != 0) { $this->db->trans_begin(); $journal_id = $postdata['journal_id']; $description = ""; $reference = $postdata['reference']; $transaction_id = $postdata['transaction_id']; $payment_type = $postdata['payment_type_id']; $tblValues = array( 'description' => $description, 'currency_id' => $default_currency, 'payment_type_id' => 2, 'transaction_id' => $transaction_id, 'tr_type' => 'post_dated_cheque' ); $this->db->where('journal_id', $journal_id); $this->db->update('finance_journal_refs', $tblValues); $tblValues = array( 'cheque_date' => $this->mastermodel->convertdateformat($postdata['cheque_date']), 'cheque_no ' => $postdata['cheque_no'], 'chart_account_code' => "", 'cheque_info' => $postdata['cheque_info'] ); $this->db->where('journal_id', $journal_id); $this->db->update('finance_cheque_info', $tblValues); $this->db->where('journal_id', $journal_id); $this->db->delete('finance_journal'); $this->db->where('journal_id', $journal_id); $this->db->delete('finance_refs'); $total_amount = 0; $i = 1; $charttypes = ""; while (isset($postdata['payment_to_id' . $i])) { if ($postdata['payment_to_id' . $i] != "") { $chart_account = explode("~", $postdata['payment_to_id' . $i]); $chart_account_id = $chart_account[0]; $chart_account_code = $chart_account[1]; $chart_account_name = $chart_account[2]; $total_amount+=$postdata['amount' . $i]; $description = $postdata['description' . $i]; $debit = 0; $credit = 0; if ($transaction_id == 1) { $debit = $postdata['amount' . $i]; $credit = 0; } if ($transaction_id == 2) { $debit = 0; $credit = $postdata['amount' . $i]; } $tblValues = array( 'journal_id' => $journal_id, 'chart_account_code' => $chart_account_code, 'debit' => $debit, 'credit' => $credit, 'description' => $description, 'fiscal_year_id' => $fisc_year_id, ); $this->db->insert('finance_journal', $tblValues); $charttypes.=$chart_account_name . "( $chart_account_code ) ,"; } $i++; } if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } else { $data['res'] = 0; if ($fisc_year_id == 0) $data['msg'] = 'Fiscal Year Not Set.'; else if ($default_currency == 0) $data['msg'] = 'Default Currency Not Set.'; else $data['msg'] = 'Fiscal Year and Default Currency Not Set.'; return $data; } } /* functions for payment voucher */ function search_payment_voucher_posted($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('finance_journal_refs'); $this->db->where('transaction_id', '1'); $this->db->where('posted', '1'); $data['results'] = $this->db->get(); return $data; } function search_payment_voucher($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('finance_journal_refs'); $this->db->where('transaction_id', '1'); $this->db->where('tr_type', 'other'); $this->db->where('posted', '0'); $data['results'] = $this->db->get(); return $data; } function insert_payment_voucher($postdata) { $data = array(); $data['resfunction'] = 'search_payment_voucher'; $fisc_year_id = $this->accountingmodel->getfiscalyearid(); $default_currency = $this->accountingmodel->getcurrency(); if ($fisc_year_id != 0 && $default_currency != 0) { $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $account = explode("~", $postdata['bankacc_id']); $account_to_id = $account[0]; $account_to_code = $account[1]; $account_to_name = $account[2]; $description = "Payment From " . $account_to_code . "-" . $account_to_name; $transaction_id = $postdata['transaction_id']; $payment_type = $postdata['payment_type_id']; $reference = $this->get_transaction_code($transaction_id, $payment_type); $tblValues = array( 'journal_id' => $masterid, 'journal_date' => $this->mastermodel->convertdateformat($postdata['journal_date']), 'description' => $description, 'reference' => $reference, 'currency_id' => $default_currency, 'payment_type_id' => $postdata['payment_type_id'], 'transaction_id' => $postdata['transaction_id'], ); $this->db->insert('finance_journal_refs', $tblValues); if ($postdata['payment_type_id'] == 2) { $tblValues = array( 'journal_id' => $masterid, 'cheque_date' => $this->mastermodel->convertdateformat($postdata['cheque_date']), 'cheque_no ' => $postdata['cheque_no'], 'chart_account_code' => $account_to_code, 'cheque_info' => $postdata['cheque_info'] ); $this->db->insert('finance_cheque_info', $tblValues); } else if ($postdata['payment_type_id'] == 3) { $tblValues = array( 'journal_id' => $masterid, 'wire_info' => $postdata['wire_info'], ); $this->db->insert('finance_wire_info', $tblValues); } $total_amount = 0; $i = 1; $charttypes = ""; while (isset($postdata['payment_to_id' . $i])) { if ($postdata['payment_to_id' . $i] != "") { $chart_account = explode("~", $postdata['payment_to_id' . $i]); $chart_account_id = $chart_account[0]; $chart_account_code = $chart_account[1]; $chart_account_name = $chart_account[2]; $total_amount+=$postdata['amount' . $i]; if (empty($postdata['description' . $i])) $description = "Payment Received From " . $account_to_name . "-" . $account_to_code; else $description = $postdata['description' . $i]; $tblValues = array( 'journal_id' => $masterid, 'chart_account_code' => $chart_account_code, 'debit' => $postdata['amount' . $i], 'credit' => 0, 'description' => $description, 'fiscal_year_id' => $fisc_year_id, ); $this->db->insert('finance_journal', $tblValues); $charttypes.=$chart_account_name . ','; } $i++; } $tblValues = array( 'journal_id' => $masterid, 'chart_account_code' => $account_to_code, 'debit' => 0, 'credit' => $total_amount, 'description' => "Payment Made to " . $charttypes, 'fiscal_year_id' => $fisc_year_id ); $this->db->insert('finance_journal', $tblValues); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } else { $data['res'] = 0; if ($fisc_year_id == 0) $data['msg'] = 'Fiscal Year Not Set.'; else if ($default_currency == 0) $data['msg'] = 'Default Currency Not Set.'; else $data['msg'] = 'Fiscal Year and Default Currency Not Set.'; return $data; } } function update_payment_voucher($postdata) { $data = array(); $data['resfunction'] = 'search_payment_voucher'; $fisc_year_id = $this->accountingmodel->getfiscalyearid(); $default_currency = $this->accountingmodel->getcurrency(); if ($fisc_year_id != 0 && $default_currency != 0) { $this->db->trans_begin(); $journal_id = $postdata['journal_id']; $account = explode("~", $postdata['bankacc_id']); $account_to_id = $account[0]; $account_to_code = $account[1]; $account_to_name = $account[2]; $description = "Payment From " . $account_to_code . "-" . $account_to_name; $reference = $postdata['reference']; $payment_old = $postdata['payment_old']; $payment_new = $postdata['payment_type_id']; if (($payment_new != $payment_old) && ($payment_new == 1 || $payment_old == 1 )) { $transaction_id = $postdata['transaction_id']; $reference = $this->get_transaction_code($transaction_id, $payment_new); } $tblValues = array( 'journal_date' => $this->mastermodel->convertdateformat($postdata['journal_date']), 'description' => $description, 'currency_id' => $default_currency, 'payment_type_id' => $postdata['payment_type_id'], 'reference' => $reference ); $this->db->where('journal_id', $journal_id); $this->db->update('finance_journal_refs', $tblValues); $this->db->where('journal_id', $journal_id); $this->db->delete('finance_cheque_info'); $this->db->where('journal_id', $journal_id); $this->db->delete('finance_wire_info'); if ($postdata['payment_type_id'] == 2) { $tblValues = array( 'journal_id' => $journal_id, 'cheque_date' => $this->mastermodel->convertdateformat($postdata['cheque_date']), 'cheque_no ' => $postdata['cheque_no'], 'chart_account_code' => $account_to_code, 'cheque_info' => $postdata['cheque_info'] ); $this->db->insert('finance_cheque_info', $tblValues); } else if ($postdata['payment_type_id'] == 3) { $tblValues = array( 'journal_id' => $journal_id, 'wire_info' => $postdata['wire_info'], ); $this->db->insert('finance_wire_info', $tblValues); } $this->db->where('journal_id', $journal_id); $this->db->delete('finance_journal'); $this->db->where('journal_id', $journal_id); $this->db->delete('finance_refs'); $total_amount = 0; $i = 1; $charttypes = ""; while (isset($postdata['payment_to_id' . $i])) { if ($postdata['payment_to_id' . $i] != "") { $chart_account = explode("~", $postdata['payment_to_id' . $i]); $chart_account_id = $chart_account[0]; $chart_account_code = $chart_account[1]; $chart_account_name = $chart_account[2]; $total_amount+=$postdata['amount' . $i]; if (empty($postdata['description' . $i])) $description = "Payment Received From " . $account_to_code . "-" . $account_to_name; else $description = $postdata['description' . $i]; $tblValues = array( 'journal_id' => $journal_id, 'chart_account_code' => $chart_account_code, 'debit' => $postdata['amount' . $i], 'credit' => 0, 'description' => $description, 'fiscal_year_id' => $fisc_year_id, ); $this->db->insert('finance_journal', $tblValues); $charttypes.=$chart_account_name . "( $chart_account_code ) ,"; } $i++; } $tblValues = array( 'journal_id' => $journal_id, 'chart_account_code' => $account_to_code, 'credit' => $total_amount, 'debit' => 0, 'description' => "Payment Made to " . $charttypes, 'fiscal_year_id' => $fisc_year_id ); $this->db->insert('finance_journal', $tblValues); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } else { $data['res'] = 0; if ($fisc_year_id == 0) $data['msg'] = 'Fiscal Year Not Set.'; else if ($default_currency == 0) $data['msg'] = 'Default Currency Not Set.'; else $data['msg'] = 'Fiscal Year and Default Currency Not Set.'; return $data; } } /* functions for cost of center */ function search_cost_center_posted($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('finance_journal_refs'); $this->db->join('cost_center', 'cost_journal_id=journal_id'); $this->db->where('transaction_id', '1'); $this->db->where('posted', '1'); $data['results'] = $this->db->get(); return $data; } function search_cost_center($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('finance_journal_refs'); $this->db->join('cost_center', 'cost_journal_id=journal_id'); $this->db->where('transaction_id', '1'); $this->db->where('posted', '0'); $data['results'] = $this->db->get(); return $data; } function insert_cost_center($postdata) { $data = array(); $data['resfunction'] = 'search_cost_center'; $fisc_year_id = $this->accountingmodel->getfiscalyearid(); $default_currency = $this->accountingmodel->getcurrency(); if ($fisc_year_id != 0 && $default_currency != 0) { $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $account = explode("~", $postdata['bankacc_id']); $account_to_id = $account[0]; $account_to_code = $account[1]; $account_to_name = $account[2]; $description = "Payment From " . $account_to_code . "-" . $account_to_name; $transaction_id = $postdata['transaction_id']; $payment_type = $postdata['payment_type_id']; $reference = $this->get_transaction_code($transaction_id, $payment_type); $tblValues = array( 'journal_id' => $masterid, 'journal_date' => $this->mastermodel->convertdateformat($postdata['journal_date']), 'description' => $description, 'reference' => $reference, 'currency_id' => $default_currency, 'payment_type_id' => $postdata['payment_type_id'], 'transaction_id' => $postdata['transaction_id'], ); $this->db->insert('finance_journal_refs', $tblValues); $tblValues = array( 'cost_journal_id' => $masterid ); $this->db->insert('cost_center', $tblValues); if ($postdata['payment_type_id'] == 2) { $tblValues = array( 'journal_id' => $masterid, 'cheque_date' => $this->mastermodel->convertdateformat($postdata['cheque_date']), 'cheque_no ' => $postdata['cheque_no'], 'chart_account_code' => $account_to_code, 'cheque_info' => $postdata['cheque_info'] ); $this->db->insert('finance_cheque_info', $tblValues); } else if ($postdata['payment_type_id'] == 3) { $tblValues = array( 'journal_id' => $masterid, 'wire_info' => $postdata['wire_info'], ); $this->db->insert('finance_wire_info', $tblValues); } $total_amount = 0; $i = 1; $charttypes = ""; while (isset($postdata['payment_to_id' . $i])) { if ($postdata['payment_to_id' . $i] != "") { $chart_account = explode("~", $postdata['payment_to_id' . $i]); $chart_account_id = $chart_account[0]; $chart_account_code = $chart_account[1]; $chart_account_name = $chart_account[2]; $total_amount+=$postdata['amount' . $i]; if (empty($postdata['description' . $i])) $description = "Payment Received From " . $account_to_name . "-" . $account_to_code . ' for expense type - ' . $this->mastermodel->get_single_field_value('expense_type', 'expense_type', 'expense_type_id', $postdata['expense_type' . $i]); else $description = $postdata['description' . $i]; $tblValues = array( 'journal_id' => $masterid, 'chart_account_code' => $chart_account_code, 'debit' => $postdata['amount' . $i], 'credit' => 0, 'description' => $description, 'fiscal_year_id' => $fisc_year_id, ); $this->db->insert('finance_journal', $tblValues); $charttypes.=$chart_account_name . ','; $id = mysql_insert_id(); $tblValues = array( 'finance_journal_id' => $id, 'expense_type_id' => $postdata['expense_type' . $i], ); $this->db->insert('cost_expense_type', $tblValues); } $i++; } $tblValues = array( 'journal_id' => $masterid, 'chart_account_code' => $account_to_code, 'debit' => 0, 'credit' => $total_amount, 'description' => "Payment Made to " . $charttypes, 'fiscal_year_id' => $fisc_year_id ); $this->db->insert('finance_journal', $tblValues); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } else { $data['res'] = 0; if ($fisc_year_id == 0) $data['msg'] = 'Fiscal Year Not Set.'; else if ($default_currency == 0) $data['msg'] = 'Default Currency Not Set.'; else $data['msg'] = 'Fiscal Year and Default Currency Not Set.'; return $data; } } function update_cost_center($postdata) { $data = array(); $data['resfunction'] = 'search_cost_center'; $fisc_year_id = $this->accountingmodel->getfiscalyearid(); $default_currency = $this->accountingmodel->getcurrency(); if ($fisc_year_id != 0 && $default_currency != 0) { $this->db->trans_begin(); $journal_id = $postdata['journal_id']; $account = explode("~", $postdata['bankacc_id']); $account_to_id = $account[0]; $account_to_code = $account[1]; $account_to_name = $account[2]; $description = "Payment From " . $account_to_code . "-" . $account_to_name; $reference = $postdata['reference']; $payment_old = $postdata['payment_old']; $payment_new = $postdata['payment_type_id']; if (($payment_new != $payment_old) && ($payment_new == 1 || $payment_old == 1 )) { $transaction_id = $postdata['transaction_id']; $reference = $this->get_transaction_code($transaction_id, $payment_new); } $tblValues = array( 'journal_date' => $this->mastermodel->convertdateformat($postdata['journal_date']), 'description' => $description, 'currency_id' => $default_currency, 'payment_type_id' => $postdata['payment_type_id'], 'reference' => $reference ); $this->db->where('journal_id', $journal_id); $this->db->update('finance_journal_refs', $tblValues); $this->db->where('journal_id', $journal_id); $this->db->delete('finance_cheque_info'); $this->db->where('journal_id', $journal_id); $this->db->delete('finance_wire_info'); if ($postdata['payment_type_id'] == 2) { $tblValues = array( 'journal_id' => $journal_id, 'cheque_date' => $this->mastermodel->convertdateformat($postdata['cheque_date']), 'cheque_no ' => $postdata['cheque_no'], 'chart_account_code' => $account_to_code, 'cheque_info' => $postdata['cheque_info'] ); $this->db->insert('finance_cheque_info', $tblValues); } else if ($postdata['payment_type_id'] == 3) { $tblValues = array( 'journal_id' => $journal_id, 'wire_info' => $postdata['wire_info'], ); $this->db->insert('finance_wire_info', $tblValues); } $this->db->where('journal_id', $journal_id); $this->db->delete('finance_journal'); $this->db->where('journal_id', $journal_id); $this->db->delete('finance_refs'); $total_amount = 0; $i = 1; $charttypes = ""; while (isset($postdata['payment_to_id' . $i])) { if ($postdata['payment_to_id' . $i] != "") { $chart_account = explode("~", $postdata['payment_to_id' . $i]); $chart_account_id = $chart_account[0]; $chart_account_code = $chart_account[1]; $chart_account_name = $chart_account[2]; $total_amount+=$postdata['amount' . $i]; if (empty($postdata['description' . $i])) $description = "Payment Received From " . $account_to_code . "-" . $account_to_name . ' for expense type - ' . $this->mastermodel->get_single_field_value('expense_type', 'expense_type', 'expense_type_id', $postdata['expense_type' . $i]); else $description = $postdata['description' . $i]; $tblValues = array( 'journal_id' => $journal_id, 'chart_account_code' => $chart_account_code, 'debit' => $postdata['amount' . $i], 'credit' => 0, 'description' => $description, 'fiscal_year_id' => $fisc_year_id, ); $this->db->insert('finance_journal', $tblValues); $charttypes.=$chart_account_name . "( $chart_account_code ) ,"; $id = mysql_insert_id(); $id = mysql_insert_id(); $tblValues = array( 'finance_journal_id' => $id, 'expense_type_id' => $postdata['expense_type' . $i], ); $this->db->insert('cost_expense_type', $tblValues); $tblValues = array( 'finance_journal_id' => $id, 'expense_type_id' => $postdata['expense_type' . $i], ); $this->db->insert('cost_expense_type', $tblValues); } $i++; } $tblValues = array( 'journal_id' => $journal_id, 'chart_account_code' => $account_to_code, 'credit' => $total_amount, 'debit' => 0, 'description' => "Payment Made to " . $charttypes, 'fiscal_year_id' => $fisc_year_id ); $this->db->insert('finance_journal', $tblValues); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } else { $data['res'] = 0; if ($fisc_year_id == 0) $data['msg'] = 'Fiscal Year Not Set.'; else if ($default_currency == 0) $data['msg'] = 'Default Currency Not Set.'; else $data['msg'] = 'Fiscal Year and Default Currency Not Set.'; return $data; } } /* Ends */ /* functions for Receipt voucher */ function search_receipt_voucher($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('finance_journal_refs'); $this->db->where('transaction_id', '2'); $this->db->where('tr_type', 'other'); $this->db->where('posted', '0'); $data['results'] = $this->db->get(); return $data; } function search_receipt_voucher_posted($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('finance_journal_refs'); $this->db->join('finance_journal', 'finance_journal.journal_id=finance_journal_refs.journal_id'); $this->db->where('finance_journal.debit', 0); $this->db->where('transaction_id', '2'); $this->db->where('posted', '1'); $this->db->order_by('finance_journal.id ', 'asc'); $data['results'] = $this->db->get(); return $data; } function insert_receipt_voucher($postdata) { $data = array(); $fisc_year_id = $this->getfiscalyearid(); $default_currency = $this->getcurrency(); $data['resfunction'] = 'search_receipt_voucher'; if ($fisc_year_id != 0 && $default_currency != 0) { $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $account = explode("~", $postdata['bankacc_id']); $account_to_id = $account[0]; $account_to_code = $account[1]; $account_to_name = $account[2]; $description = "Payment to " . $account_to_code . "-" . $account_to_name; $transaction_id = $postdata['transaction_id']; $payment_type = $postdata['payment_type_id']; $reference = $this->get_transaction_code($transaction_id, $payment_type); $tblValues = array( 'journal_id' => $masterid, 'journal_date' => $this->mastermodel->convertdateformat($postdata['journal_date']), 'description' => $description, 'reference' => $reference, 'currency_id' => $default_currency, 'payment_type_id' => $postdata['payment_type_id'], 'transaction_id' => $postdata['transaction_id'], ); $this->db->insert('finance_journal_refs', $tblValues); if ($postdata['payment_type_id'] == 2) { $tblValues = array( 'journal_id' => $masterid, 'cheque_date' => $this->mastermodel->convertdateformat($postdata['cheque_date']), 'cheque_no ' => $postdata['cheque_no'], 'chart_account_code' => $account_to_code, 'cheque_info' => $postdata['cheque_info'] ); $this->db->insert('finance_cheque_info', $tblValues); } else if ($postdata['payment_type_id'] == 3) { $tblValues = array( 'journal_id' => $masterid, 'wire_info' => $postdata['wire_info'], ); $this->db->insert('finance_wire_info', $tblValues); } $total_amount = 0; $i = 1; $charttypes = ""; while (isset($postdata['payment_to_id' . $i])) { if ($postdata['payment_to_id' . $i] != "") { $chart_account = explode("~", $postdata['payment_to_id' . $i]); $chart_account_id = $chart_account[0]; $chart_account_code = $chart_account[1]; $chart_account_name = $chart_account[2]; $total_amount+=$postdata['amount' . $i]; if (empty($postdata['description' . $i])) $description = "Payment made to " . $account_to_name . "-" . $account_to_code; else $description = $postdata['description' . $i]; $tblValues = array( 'journal_id' => $masterid, 'chart_account_code' => $chart_account_code, 'debit' => 0, 'credit' => $postdata['amount' . $i], 'description' => $description, 'fiscal_year_id' => $fisc_year_id, ); $this->db->insert('finance_journal', $tblValues); $charttypes.=$chart_account_name . "( $chart_account_code ) ,"; } $i++; } $tblValues = array( 'journal_id' => $masterid, 'chart_account_code' => $account_to_code, 'debit' => $total_amount, 'credit' => 0, 'description' => "Payment Received From " . $charttypes, 'fiscal_year_id' => $fisc_year_id ); $this->db->insert('finance_journal', $tblValues); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } else { $data['res'] = 0; if ($fisc_year_id == 0) $data['msg'] = 'Fiscal Year Not Set.'; else if ($default_currency == 0) $data['msg'] = 'Default Currency Not Set.'; else $data['msg'] = 'Fiscal Year and Default Currency Not Set.'; return $data; } } function update_receipt_voucher($postdata) { $data = array(); $data['resfunction'] = 'search_receipt_voucher'; $fisc_year_id = $this->accountingmodel->getfiscalyearid(); $default_currency = $this->accountingmodel->getcurrency(); if ($fisc_year_id != 0 && $default_currency != 0) { $this->db->trans_begin(); $journal_id = $postdata['journal_id']; $account = explode("~", $postdata['bankacc_id']); $account_to_id = $account[0]; $account_to_code = $account[1]; $account_to_name = $account[2]; $description = "Payment to " . $account_to_code . "-" . $account_to_name; $reference = $postdata['reference']; $payment_old = $postdata['payment_old']; $payment_new = $postdata['payment_type_id']; if (($payment_new != $payment_old) && ($payment_new == 1 || $payment_old == 1 )) { $transaction_id = $postdata['transaction_id']; $reference = $this->get_transaction_code($transaction_id, $payment_new); } $tblValues = array( 'journal_date' => $this->mastermodel->convertdateformat($postdata['journal_date']), 'description' => $description, 'payment_type_id' => $postdata['payment_type_id'], 'reference' => $reference, 'currency_id' => $default_currency, ); $this->db->where('journal_id', $journal_id); $this->db->update('finance_journal_refs', $tblValues); $this->db->where('journal_id', $journal_id); $this->db->delete('finance_cheque_info'); $this->db->where('journal_id', $journal_id); $this->db->delete('finance_wire_info'); if ($postdata['payment_type_id'] == 2) { $tblValues = array( 'journal_id' => $journal_id, 'cheque_date' => $this->mastermodel->convertdateformat($postdata['cheque_date']), 'cheque_no ' => $postdata['cheque_no'], 'chart_account_code' => $account_to_code, 'cheque_info' => $postdata['cheque_info'] ); $this->db->insert('finance_cheque_info', $tblValues); } else if ($postdata['payment_type_id'] == 3) { $tblValues = array( 'journal_id' => $journal_id, 'wire_info' => $postdata['wire_info'], ); $this->db->insert('finance_wire_info', $tblValues); } $this->db->where('journal_id', $journal_id); $this->db->delete('finance_journal'); $this->db->where('journal_id', $journal_id); $this->db->delete('finance_refs'); $total_amount = 0; $i = 1; $charttypes = ""; while (isset($postdata['payment_to_id' . $i])) { if ($postdata['payment_to_id' . $i] != "") { $chart_account = explode("~", $postdata['payment_to_id' . $i]); $chart_account_id = $chart_account[0]; $chart_account_code = $chart_account[1]; $chart_account_name = $chart_account[2]; $total_amount+=$postdata['amount' . $i]; if (empty($postdata['description' . $i])) { $description = "Payment made to " . $account_to_name . "-" . $account_to_code; } else $description = $postdata['description' . $i]; $tblValues = array( 'journal_id' => $journal_id, 'chart_account_code' => $chart_account_code, 'debit' => 0, 'credit' => $postdata['amount' . $i], 'description' => $description, 'fiscal_year_id' => $fisc_year_id, ); $this->db->insert('finance_journal', $tblValues); $charttypes.=$chart_account_name . ','; } $i++; } $tblValues = array( 'journal_id' => $journal_id, 'chart_account_code' => $account_to_code, 'debit' => $total_amount, 'credit' => 0, 'description' => "Payment Received From " . $charttypes, 'fiscal_year_id' => $fisc_year_id ); $this->db->insert('finance_journal', $tblValues); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } else { $data['res'] = 0; if ($fisc_year_id == 0) $data['msg'] = 'Fiscal Year Not Set.'; else if ($default_currency == 0) $data['msg'] = 'Default Currency Not Set.'; else $data['msg'] = 'Fiscal Year and Default Currency Not Set.'; return $data; } } /* functions for bank journal */ function search_bank_journal($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('finance_journal_refs'); $this->db->where('transaction_id', '4'); $this->db->where('posted', '0'); $data['results'] = $this->db->get(); return $data; } function search_bank_journal_posted($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('finance_journal_refs'); $this->db->where('transaction_id', '4'); $this->db->where('posted', '1'); $data['results'] = $this->db->get(); return $data; } function insert_bank_journal($postdata) { $data = array(); $fisc_year_id = $this->getfiscalyearid(); $default_currency = $this->getcurrency(); $data['resfunction'] = 'search_bank_journal'; if ($fisc_year_id != 0 && $default_currency != 0) { $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $date = $this->mastermodel->convertdateformat($postdata['journal_date']); $from_account = explode("~", $postdata['from_account_id']); $to_account = explode("~", $postdata['to_account_id']); $description = "Transaction From account $from_account[2] - $from_account[1] To account $to_account[2] -$to_account[1] "; $transaction_id = $postdata['transaction_id']; $payment_type = 0; $reference = $this->get_transaction_code($transaction_id, $payment_type); $tblValues = array( 'journal_id' => $masterid, 'journal_date' => $date, 'description' => $description, 'reference' => $reference, 'currency_id' => $default_currency, 'payment_type_id' => '0', 'transaction_id' => '4', 'posted' => '0' ); $this->db->insert('finance_journal_refs', $tblValues); $tblValues = array( 'journal_id' => $masterid, 'chart_account_code' => $from_account[1], 'debit' => '0', 'credit' => $postdata['amount'], 'description' => "Transaction to account $to_account[2] -$to_account[1] ", 'system_date' => date('Y-m-d'), 'fiscal_year_id' => $fisc_year_id ); $this->db->insert('finance_journal', $tblValues); $tblValues = array( 'journal_id' => $masterid, 'chart_account_code' => $to_account[1], 'debit' => $postdata['amount'], 'credit' => '0', 'description' => "Transaction From account $from_account[2] - $from_account[1] ", 'system_date' => date('Y-m-d H:i:s'), 'fiscal_year_id' => $fisc_year_id, ); $this->db->insert('finance_journal', $tblValues); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } else { $data['res'] = 0; if ($fisc_year_id == 0) $data['msg'] = 'Fiscal Year Not Set.'; else if ($default_currency == 0) $data['msg'] = 'Default Currency Not Set.'; else $data['msg'] = 'Fiscal Year and Default Currency Not Set.'; return $data; } } function update_bank_journal($postdata) { $data = array(); $data['resfunction'] = 'search_bank_journal'; $fisc_year_id = $this->getfiscalyearid(); if ($fisc_year_id != 0) { $this->db->trans_begin(); $date = $this->mastermodel->convertdateformat($postdata['journal_date']); $from_account = explode("~", $postdata['from_account_id']); $to_account = explode("~", $postdata['to_account_id']); $description = "Transaction From account $from_account[2] - $from_account[1] To account $to_account[2] -$to_account[1] "; $journal_id = $postdata['journal_id']; $tblValues = array( 'journal_date' => $date, 'description' => $description, 'payment_type_id' => '0', 'transaction_id' => '4', 'posted' => '0' ); $this->db->where('journal_id', $journal_id); $this->db->update('finance_journal_refs', $tblValues); $tblValues = array( 'journal_id' => $journal_id, 'chart_account_code' => $from_account[1], 'credit' => $postdata['amount'], 'description' => "Transaction to account $to_account[2] -$to_account[1]", 'system_date' => date('Y-m-d'), 'fiscal_year_id' => $fisc_year_id ); $this->db->where('debit', '0'); $this->db->where('journal_id', $journal_id); $this->db->update('finance_journal', $tblValues); $tblValues = array( 'journal_id' => $journal_id, 'chart_account_code' => $to_account[1], 'debit' => $postdata['amount'], 'credit' => '0', 'description' => "Transaction From account $from_account[2] - $from_account[1]", 'system_date' => date('Y-m-d H:i:s'), 'fiscal_year_id' => $fisc_year_id ); $this->db->where('credit', '0'); $this->db->where('journal_id', $journal_id); $this->db->update('finance_journal', $tblValues); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } else { $data['res'] = 0; $data['msg'] = 'Fiscal Year Not Set.'; return $data; } } /* functions for journal voucher */ function search_journal_voucher($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('finance_journal_refs'); $this->db->where('transaction_id', '3'); $this->db->where('posted', '0'); $data['results'] = $this->db->get(); return $data; } function search_journal_voucher_posted($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('finance_journal_refs'); $this->db->where('transaction_id', '3'); $this->db->where('posted', '1'); $data['results'] = $this->db->get(); return $data; } function insert_journal_voucher($postdata) { $data = array(); $fisc_year_id = $this->getfiscalyearid(); $default_currency = $this->getcurrency(); $data['resfunction'] = 'search_journal_voucher'; if ($fisc_year_id != 0 && $default_currency != 0) { $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $date = $this->mastermodel->convertdateformat($postdata['journal_voucher_date']); $transaction_id = $postdata['transaction_id']; $payment_type = 0; $reference = $this->get_transaction_code($transaction_id, $payment_type); $tblValues = array( 'journal_id' => $masterid, 'journal_date' => $date, 'description' => '', 'reference' => $reference, 'currency_id' => $default_currency, 'payment_type_id' => '0', 'transaction_id' => '3', 'posted' => '0' ); $this->db->insert('finance_journal_refs', $tblValues); $i = 1; while (isset($postdata['account_id' . $i])) { if ($postdata['account_id' . $i] != "") { $account = explode("~", $postdata['account_id' . $i]); if ($postdata['credit' . $i] > 0) $description = "Transaction From $account[2] - $account[1]"; if ($postdata['debit' . $i] > 0) $description = "Transaction To $account[2] - $account[1]"; $tblValues = array( 'journal_id' => $masterid, 'chart_account_code' => $account[1], 'debit' => $postdata['debit' . $i], 'credit' => $postdata['credit' . $i], 'description' => $description, 'fiscal_year_id' => $fisc_year_id, 'system_date' => date('Y-m-d') ); $this->db->insert('finance_journal', $tblValues); } $i++; } if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } else { $data['res'] = 0; if ($fisc_year_id == 0) $data['msg'] = 'Fiscal Year Not Set.'; else if ($default_currency == 0) $data['msg'] = 'Default Currency Not Set.'; else $data['msg'] = 'Fiscal Year and Default Currency Not Set.'; return $data; } } function update_journal_voucher($postdata) { $data = array(); $fisc_year_id = $this->getfiscalyearid(); $default_currency = $this->getcurrency(); $data['resfunction'] = 'search_journal_voucher'; if ($fisc_year_id != 0 && $default_currency != 0) { $this->db->trans_begin(); $journal_id = $postdata['journal_id']; $date = $this->mastermodel->convertdateformat($postdata['journal_voucher_date']); $transaction_id = $postdata['transaction_id']; $payment_type = 0; $tblValues = array( 'journal_date' => $date, 'description' => '', 'currency_id' => $default_currency, 'payment_type_id' => $payment_type, 'transaction_id' => '3', 'posted' => '0' ); $this->db->where('journal_id', $journal_id); $this->db->update('finance_journal_refs', $tblValues); $this->db->where('journal_id', $journal_id); $this->db->delete('finance_journal'); $i = 1; while (isset($postdata['account_id' . $i])) { if ($postdata['account_id' . $i] != "") { $account = explode("~", $postdata['account_id' . $i]); if ($postdata['credit' . $i] > 0) $description = "From $account[2] - $account[1]"; if ($postdata['debit' . $i] > 0) $description = "To $account[2] - $account[1]"; $tblValues = array( 'journal_id' => $journal_id, 'chart_account_code' => $account[1], 'debit' => $postdata['debit' . $i], 'credit' => $postdata['credit' . $i], 'description' => "Transaction $description", 'fiscal_year_id' => $fisc_year_id, 'system_date' => date('Y-m-d') ); $this->db->insert('finance_journal', $tblValues); } $i++; } if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } else { $data['res'] = 0; if ($fisc_year_id == 0) $data['msg'] = 'Fiscal Year Not Set.'; else if ($default_currency == 0) $data['msg'] = 'Default Currency Not Set.'; else $data['msg'] = 'Fiscal Year and Default Currency Not Set.'; return $data; } } /* functions for auto journal */ function search_auto_journal($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('finance_auto_journal_refs'); $data['results'] = $this->db->get(); return $data; } function insert_auto_journal($postdata) { $data = array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tblValues = array( 'auto_journal_id' => $masterid, 'auto_journal_title' => $postdata['auto_journal_title'], ); $this->db->insert('finance_auto_journal_refs', $tblValues); $i = 1; while (isset($postdata['account_id' . $i])) { if ($postdata['account_id' . $i] != "") { $account = explode("~", $postdata['account_id' . $i]); $tblValues = array( 'auto_journal_id' => $masterid, 'chart_account_code' => $account[1], 'debit' => $postdata['debit' . $i], 'credit' => $postdata['credit' . $i], 'description' => $postdata['description' . $i], ); $this->db->insert('finance_auto_journal', $tblValues); } $i++; } $data['resfunction'] = 'search_auto_journal'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } function update_auto_journal($postdata) { $data = array(); $this->db->trans_begin(); $auto_journal_id = $postdata['auto_journal_id']; $tblValues = array( 'auto_journal_title' => $postdata['auto_journal_title'], ); $this->db->where('auto_journal_id', $auto_journal_id); $this->db->update('finance_auto_journal_refs', $tblValues); $this->db->where('auto_journal_id', $auto_journal_id); $this->db->delete('finance_auto_journal'); $i = 1; while (isset($postdata['account_id' . $i])) { if ($postdata['account_id' . $i] != "") { $account = explode("~", $postdata['account_id' . $i]); $tblValues = array( 'auto_journal_id' => $auto_journal_id, 'chart_account_code' => $account[1], 'debit' => $postdata['debit' . $i], 'credit' => $postdata['credit' . $i], 'description' => $postdata['description' . $i], ); $this->db->insert('finance_auto_journal', $tblValues); } $i++; } $data['resfunction'] = 'search_auto_journal'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } function journal_unpost($postdata) { $data = array(); $fisc_year_id = $this->getfiscalyearid(); $default_currency = $this->getcurrency(); $data['resfunction'] = 'search_auto_journal'; if($postdata['tr_type']=="post_dated_cheque"){ $data['resfunction'] = 'search_post_dated_cheque_posted'; } if ($fisc_year_id != 0 && $default_currency != 0) { $masterid = $this->mastermodel->insertmasterdata(); $date = $this->mastermodel->convertdateformat($postdata['journal_voucher_date']); $year = date("Y"); $transaction_id = $postdata['transaction_id']; $payment_type = 0; $reference = $this->get_transaction_code($transaction_id, $payment_type); $tblValues = array( 'journal_id' => $masterid, 'journal_date' => $date, 'description' => '', 'reference' => $reference, 'currency_id' => $default_currency, 'payment_type_id' => '0', 'transaction_id' => '3', 'posted' => '0' ); $this->db->insert('finance_journal_refs', $tblValues); $i = 1; while (isset($postdata['code' . $i])) { if ($postdata['code' . $i] != "") { $tblValues = array( 'journal_id' => $masterid, 'chart_account_code' => $postdata['code' . $i], 'debit' => $postdata['debit' . $i], 'credit' => $postdata['credit' . $i], 'description' => $postdata['description' . $i], 'fiscal_year_id' => $fisc_year_id, 'system_date' => date('Y-m-d') ); $this->db->insert('finance_journal', $tblValues); } $i++; } if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } else { $data['res'] = 0; if ($fisc_year_id == 0) $data['msg'] = 'Fiscal Year Not Set.'; else if ($default_currency == 0) $data['msg'] = 'Default Currency Not Set.'; else $data['msg'] = 'Fiscal Year and Default Currency Not Set.'; return $data; } } function search_trans($type, $ref, $rtype, $from, $to) { if ($rtype != 'all') { $where = "fjr.transaction_id=$rtype and"; } else { $where = ''; } $from = $this->mastermodel->convdatformat($from); $to = $this->mastermodel->convdatformat($to); //echo "select sum(gt.amount) as amount , gt.type_no as id,tt.transaction,r.type, r.reference as ref,gt.tran_date from gl_trans gt JOIN refs r ON r.id=gt.type_no JOIN transaction_types tt ON tt.id=r.type where $where r.reference like '$ref%' and gt.tran_date between '$from' and '$to' and r.type!=6 and gt.amount>0 group by gt.type_no "; if ($type == 'data') { $data = array(); $res = $this->db->query("select * from finance_journal_refs fjr JOIN finance_transaction_code ftc ON fjr.transaction_id=ftc.transaction_id JOIN master ON master_id=journal_id where $where fjr.reference like '$ref%' and fjr.journal_date between '$from' and '$to' order by fjr.journal_id desc"); foreach ($res->result_array() as $row) { $data[] = $row; } return $data; } else if ($type == 'count') { $res = $this->db->query("select * from finance_journal_refs fjr JOIN finance_transaction_code ftc ON fjr.transaction_id=ftc.transaction_id JOIN master ON master_id=journal_id where $where fjr.reference like '$ref%' and fjr.journal_date between '$from' and '$to' order by fjr.journal_id desc"); return $res->num_rows(); } } function search_student_payment($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('finance_journal_refs'); $this->db->join('finance_journal', 'finance_journal.journal_id=finance_journal_refs.journal_id'); $this->db->join('student', 'student.reg_no=finance_journal.chart_account_code'); $this->db->where('finance_journal.debit', 0); $this->db->where('transaction_id', '2'); $this->db->where('posted', '0'); $data['results'] = $this->db->get(); return $data; } function search_student_payment_posted($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('finance_journal_refs'); $this->db->join('finance_journal', 'finance_journal.journal_id=finance_journal_refs.journal_id'); $this->db->join('student', 'student.reg_no=finance_journal.chart_account_code'); $this->db->where('finance_journal.debit', 0); $this->db->where('transaction_id', '2'); $this->db->where('posted', '1'); $data['results'] = $this->db->get(); return $data; } function main_account_code_increment($start, $max) { $data = "SELECT IFNULL(max(chart_account_code),0) as code FROM finance_chart_master where chart_account_code between " . $start . " and " . $max; $res = $this->db->query($data); return $res->row()->code; } function account_code_generated($start, $max) { $min = $start - 1; $data = "SELECT CAST((@mid:= @mid) as CHAR) as code FROM `finance_chart_master` , (SELECT @mid:=$min ,@midmax:=$max ) t where @mid < @midmax and `chart_account_code` between $start and $max and CAST(@mid:= @mid+1 as CHAR) <> `chart_account_code` order by `chart_account_code` "; $res = $this->db->query($data); $r = $res->result_array(); if ($r) { $code = $r[0]['code']; } else { $data = "SELECT IFNULL(max(chart_account_code),0) as code FROM finance_chart_master where chart_account_code between " . $start . " and " . $max; $res = $this->db->query($data); $code = $res->row()->code; if ($code) $code = $code + 1; else $code = $start; } return $code; } function checkaccountisset() { $this->db->where('closed', 0); $this->db->where('default', 1); $q = $this->db->get('finance_fiscal_year'); $res = $q->row(); if (!isset($res->fiscal_year_id)) $baccount = 0; else { $this->db->where('default_currency', 1); $q = $this->db->get('finance_currency'); $res = $q->row(); if (!isset($res->currency_id)) $baccount = -1; else $baccount = $res->currency_id; } return $baccount; } function get_account_settings($field, $table) { $query = $this->db->query("select $field from $table "); $res = $query->row()->$field; return $res; } function getfiscalyearid() { $fisc_year_id = 0; $fisc_year_id = $this->mastermodel->get_single_field_value_two('finance_fiscal_year', 'fiscal_year_id', 'finance_fiscal_year.closed', '0', 'finance_fiscal_year.default', '1'); return $fisc_year_id; } function getcurrency() { $currencyid = 0; $currencyid = $this->mastermodel->get_single_field_value('finance_currency', 'currency_id', 'default_currency', '1'); return $currencyid; } function get_reference($transaction_code) { $length = strlen($transaction_code) + 1; $data = "SELECT MAX(CONVERT(SUBSTRING(reference," . $length . "),UNSIGNED INTEGER) ) as code FROM finance_journal_refs where reference like '" . $transaction_code . "%' "; $res = $this->db->query($data); if ($res->num_rows() > 0) { $code = $res->row()->code; $ref = $code + 1; } else { $ref = 1; } return $transaction_code . $ref; } function get_transaction_code($transaction_id, $payment_type_id = 0) { $transaction_code = $this->gettransactioncode($transaction_id) . '/'; if ($payment_type_id != 0) { $payment = $this->mastermodel->get_single_field_value('finance_payment_types', 'payment_type', 'payment_type_id', $payment_type_id); if ($payment_type_id == 1) $payment_type = "CASH"; else $payment_type = "BANK"; $transaction_code.=$payment_type . '/'; } $year = date("Y"); $transaction_code.= $year . '/'; $reference = $this->get_reference($transaction_code); return $reference; } function gettransactioncode($tid) { return $this->mastermodel->get_single_field_value('finance_transaction_code', 'transaction_code', 'transaction_id', $tid); } function post_data($id) { $tblvalues = array( 'posted' => '1' ); $this->db->where('journal_id', $id); $this->db->update('finance_journal_refs', $tblvalues); } function get_count_cheque_no($cheque_no, $not_in = "") { $this->db->from('finance_cheque_info'); $this->db->join('finance_journal_refs', 'finance_journal_refs.journal_id=finance_cheque_info.journal_id'); $this->db->where('transaction_id', '1'); $this->db->where("cheque_no", $cheque_no); if ($not_in != "") { $this->db->where('cheque_no !=', $not_in); } $count = $this->db->count_all_results(); return $count; } function insert_student_payment($postdata) { $data = array(); $fisc_year_id = $this->accountingmodel->getfiscalyearid(); $default_currency = $this->accountingmodel->getcurrency(); $student_acc = $this->mastermodel->get_data_srow('finance_chart_master', $postdata['account_code'], 'chart_account_code'); $c_account = $student_acc->chart_master_id . '~' . $student_acc->chart_account_code . '~' . $student_acc->chart_account_name; $data['resfunction'] = 'search_student_payment'; if ($fisc_year_id != 0 && $default_currency != 0) { $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $account = explode("~", $postdata['bankacc_id']); $account_to_id = $account[0]; $account_to_code = $account[1]; $account_to_name = $account[2]; $description = "Payment to " . $account_to_code . "-" . $account_to_name; $transaction_id = $postdata['transaction_id']; $payment_type = $postdata['payment_type_id']; $reference = $this->accountingmodel->get_transaction_code($transaction_id, $payment_type); $tblValues = array( 'journal_id' => $masterid, 'journal_date' => $this->mastermodel->convertdateformat($postdata['journal_date']), 'description' => $postdata['description'], 'reference' => $reference, 'currency_id' => $default_currency, 'payment_type_id' => $postdata['payment_type_id'], 'transaction_id' => $postdata['transaction_id'], ); $this->db->insert('finance_journal_refs', $tblValues); if ($postdata['payment_type_id'] == 2) { $tblValues = array( 'journal_id' => $masterid, 'cheque_date' => $this->mastermodel->convertdateformat($postdata['cheque_date']), 'cheque_no ' => $postdata['cheque_no'], 'chart_account_code' => $account_to_code, 'cheque_info' => $postdata['cheque_info'] ); $this->db->insert('finance_cheque_info', $tblValues); } else if ($postdata['payment_type_id'] == 3) { $tblValues = array( 'journal_id' => $masterid, 'wire_info' => $postdata['wire_info'], ); $this->db->insert('finance_wire_info', $tblValues); } $total_amount = 0; if ($c_account != "") { $chart_account = explode("~", $c_account); $chart_account_id = $chart_account[0]; $chart_account_code = $chart_account[1]; $chart_account_name = $chart_account[2]; $total_amount = $postdata['amount']; if (empty($postdata['description'])) $description = "Payment made to " . $account_to_name . "-" . $account_to_code; else $description = $postdata['description']; $tblValues = array( 'journal_id' => $masterid, 'chart_account_code' => $chart_account_code, 'debit' => 0, 'credit' => $total_amount, 'description' => $postdata['description'], 'fiscal_year_id' => $fisc_year_id, ); $this->db->insert('finance_journal', $tblValues); } $description = "Payment Received From " . $chart_account_name . "-" . $chart_account_code; $tblValues = array( 'journal_id' => $masterid, 'chart_account_code' => $account_to_code, 'debit' => $total_amount, 'credit' => 0, 'description' => $postdata['description'], 'fiscal_year_id' => $fisc_year_id ); $this->db->insert('finance_journal', $tblValues); // $tblValues = array( // 'journal_id' => $masterid, // 'param_id' => $postdata['fee_id'], // 'refs_type' => 'Student Fee Payment', // 'param_table' => 'fee' // ); // $this->db->insert('finance_refs', $tblValues); // // $tblValues = array( // 'journal_id' => $masterid // ); // $this->db->where('fee_id', $postdata['fee_id']); // $this->db->update('fee', $tblValues); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } else { $data['res'] = 0; if ($fisc_year_id == 0) $data['msg'] = 'Fiscal Year Not Set.'; else if ($default_currency == 0) $data['msg'] = 'Default Currency Not Set.'; else $data['msg'] = 'Fiscal Year and Default Currency Not Set.'; return $data; } } function update_student_payment($postdata) { $data = array(); $fisc_year_id = $this->accountingmodel->getfiscalyearid(); $default_currency = $this->accountingmodel->getcurrency(); $student_acc = $this->mastermodel->get_data_srow('finance_chart_master', $postdata['account_code'], 'chart_account_code'); $c_account = $student_acc->chart_master_id . '~' . $student_acc->chart_account_code . '~' . $student_acc->chart_account_name; $data['resfunction'] = 'search_student_payment'; if ($fisc_year_id != 0 && $default_currency != 0) { $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $account = explode("~", $postdata['bankacc_id']); $account_to_id = $account[0]; $account_to_code = $account[1]; $account_to_name = $account[2]; $description = "Payment to " . $account_to_code . "-" . $account_to_name; $journal_id = $postdata['journal_id']; $transaction_id = $postdata['transaction_id']; $payment_type = $postdata['payment_type_id']; $reference = $this->accountingmodel->get_transaction_code($transaction_id, $payment_type); $tblValues = array( 'journal_id' => $postdata['journal_id'], 'journal_date' => $this->mastermodel->convertdateformat($postdata['journal_date']), 'description' => $postdata['description'], 'reference' => $reference, 'currency_id' => $default_currency, 'payment_type_id' => $postdata['payment_type_id'], 'transaction_id' => $postdata['transaction_id'], ); $this->db->where('journal_id', $postdata['journal_id']); $this->db->update('finance_journal_refs', $tblValues); $this->db->where('journal_id', $journal_id); $this->db->delete('finance_cheque_info'); $this->db->where('journal_id', $journal_id); $this->db->delete('finance_wire_info'); $this->db->where('journal_id', $journal_id); $this->db->delete('finance_journal'); if ($postdata['payment_type_id'] == 2) { $tblValues = array( 'journal_id' => $postdata['journal_id'], 'cheque_date' => $this->mastermodel->convertdateformat($postdata['cheque_date']), 'cheque_no ' => $postdata['cheque_no'], 'chart_account_code' => $account_to_code, 'cheque_info' => $postdata['cheque_info'] ); $this->db->insert('finance_cheque_info', $tblValues); } else if ($postdata['payment_type_id'] == 3) { $tblValues = array( 'journal_id' => $postdata['journal_id'], 'wire_info' => $postdata['wire_info'], ); $this->db->insert('finance_wire_info', $tblValues); } $total_amount = 0; if ($c_account != "") { $chart_account = explode("~", $c_account); $chart_account_id = $chart_account[0]; $chart_account_code = $chart_account[1]; $chart_account_name = $chart_account[2]; $total_amount = $postdata['amount']; if (empty($postdata['description'])) $description = "Payment made to " . $account_to_name . "-" . $account_to_code; else $description = $postdata['description']; $tblValues = array( 'journal_id' => $postdata['journal_id'], 'chart_account_code' => $chart_account_code, 'debit' => 0, 'credit' => $total_amount, 'description' => $postdata['description'], 'fiscal_year_id' => $fisc_year_id, ); $this->db->insert('finance_journal', $tblValues); } $description = "Payment Received From " . $chart_account_name . "-" . $chart_account_code; $tblValues = array( 'journal_id' => $postdata['journal_id'], 'chart_account_code' => $account_to_code, 'debit' => $total_amount, 'credit' => 0, 'description' => $postdata['description'], 'fiscal_year_id' => $fisc_year_id ); $this->db->insert('finance_journal', $tblValues); // $tblValues = array( // 'journal_id' => $masterid, // 'param_id' => $postdata['fee_id'], // 'refs_type' => 'Student Fee Payment', // 'param_table' => 'fee' // ); // $this->db->insert('finance_refs', $tblValues); // // $tblValues = array( // 'journal_id' => $masterid // ); // $this->db->where('fee_id', $postdata['fee_id']); // $this->db->update('fee', $tblValues); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } else { $data['res'] = 0; if ($fisc_year_id == 0) $data['msg'] = 'Fiscal Year Not Set.'; else if ($default_currency == 0) $data['msg'] = 'Default Currency Not Set.'; else $data['msg'] = 'Fiscal Year and Default Currency Not Set.'; return $data; } } function search_reconcile($account, $statement, $cheque) { $data = array(); $data['result'] = array(); $data['cheque_info'] = array(); if ($statement != 'new') { $where = "fj.reconcile_date= '$statement' and"; } else { $where = 'fj.reconcile_date IS NULL and'; } $res = $this->db->query("select * from finance_journal fj join finance_journal_refs on finance_journal_refs.journal_id=fj.journal_id where $where chart_account_code = '$account' order by fj.id desc"); $data['count'] = $res->num_rows(); foreach ($res->result_array() as $row) { if ($cheque == 0) { $data['result'][] = $row; } if ($row['payment_type_id'] == 2) { if (!isset($data['cheque_info'][$row['journal_id']])) $data['cheque_info'][$row['journal_id']] = $this->mastermodel->get_data_srow('finance_cheque_info', $row['journal_id'], 'journal_id'); if ($cheque == 1 && count($data['cheque_info'][$row['journal_id']]) > 0) { $data['result'][] = $row; } } } return $data; } function set_reconsile($postdata) { $journal = array(0); $data = array(); $journal = array(); $this->db->trans_begin(); if (isset($postdata['select_for_reconcile'])) $journal = $postdata['select_for_reconcile']; $rec_date = $this->mastermodel->convertdateformat($postdata['rec_date']); $all_journal = explode(",", $postdata['all_journal']); foreach ($all_journal as $key => $value) { if ($value != 0) { if (in_array($value, $journal)) { $tblValues = array( 'reconcile_date' => $rec_date, ); } else { $tblValues = array( 'reconcile_date' => null, ); } $this->db->where('id', (int) $value); $this->db->update('finance_journal', $tblValues); } } if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } function get_bank_reconciliation($postdata) { $data = array(); $from = $this->mastermodel->convdatformat($postdata['rec_from']); $to = $this->mastermodel->convdatformat($postdata['rec_to']); $account = $postdata['account_id']; $where = ''; if ($account != '') { $account_details = explode("~", $postdata['account_id']); $where = "fj.chart_account_code like '$account_details[1]%' and "; } $data = array(); $res = $this->db->query("select * from finance_journal fj join finance_journal_refs on finance_journal_refs.journal_id=fj.journal_id where $where fj.reconcile_date between '$from' and '$to' and reconcile_date is not null "); $data['cheque_info'] = array(); foreach ($res->result_array() as $row) { $data['result'][] = $row; if ($row['payment_type_id'] == 2) { if (!isset($data['cheque_info'][$row['journal_id']])) $data['cheque_info'][$row['journal_id']] = $this->mastermodel->get_data_srow('finance_cheque_info', $row['journal_id'], 'journal_id'); } } return $data; } } ?>