<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/* 	
 * 	Author 	: Wahyu
 * 	Tanggal : 22-10-2014	
 * 	Revisi 	: 
 */

class Swift_bank extends CI_Controller {

    public $menu_id = 238;
    public $name = 'Sweep Bank';
    public $trans_data = array();

    public function __construct() {
        parent::__construct();
        $this->load->model('m_swapbank');
        $this->load->model('m_expense_cashbon');
        $this->load->model('m_account_journal');
        $this->load->helper('message');
        $this->load->helper('status');
        $this->load->helper('convert_date');
        $this->load->helper('custom_string_helper');
        $this->load->model('login/m_login');
        $is_login = $this->m_login->get_session_id($this->session->userdata('session_id'),$this->session->userdata('username'));
        if($is_login){

        }else{
            $username       = $this->session->userdata('username');
            $session_id     = $this->session->userdata('session_id');
            $this->m_login->delete_session($username,$session_id);
            $this->session->sess_destroy();

            $uri_func = $this->uri->segment(3);
            if(($uri_func === FALSE) || ($uri_func =='add') || ($uri_func =='edit')){
                redirect(base_url() . 'login', 'refresh');
            }else if(in_array($uri_func,array('approve_data','approved_mgr','approved_dir','approve','approve_transsaction','reverse_data','reversed_data','reverse_transsaction','save','save_data','insert','update','update_data','suspend','suspend_data','suspend_transsaction','suspend_mgr','suspend_dir'))){
                $result['status']   = 'session';
                $result['message']  = get_notification('session_destroy',0);
                echo json_encode($result);
                die();
            }
        }
    }

    //Function Index
    public function index() {
        if ($this->session->userdata("login") == TRUE) {
            $group_menu = $this->session->userdata('group_menu');
            $arr_group_id = $this->m_menu->get_menu_by_group($group_menu, $this->menu_id);
            if (!empty($arr_group_id)) {
                $data['available_menu'] = array_unique($arr_group_id);
                if (!in_array($this->menu_id, $data['available_menu'])) {
                    redirect(base_url() . 'error', 'refresh');
                } else {
                    $group_menu = $this->session->userdata('group_menu');
                    // get link from tbl_menu 
                    $data['menu_link'] = $this->m_menu->get_menulink($this->menu_id);

                    // set data
                    $data['menu_label'] = $this->m_menu->get_menulabel($this->menu_id);

                    //panggil model hak akses untuk autoriti
                    $data['group_user'] = $this->m_menu->group_user_autority($this->menu_id, $group_menu);

                    $this->load->view('v_header');
                    $this->load->view('cash_and_bank/swift_bank/v_swift_bank', $data);
                    $this->load->view('v_footer');
                }
            } else {
                redirect(base_url() . 'error', 'refresh');
            }
        } else {
            redirect(base_url() . 'login', 'refresh');
        }
    }

    // Function Index	
    public function add() {
        if ($this->session->userdata("login") == TRUE) {
            $group_menu = $this->session->userdata('group_menu');
            /*
              untuk di index/list = get_menu_by_group,
              untuk di add = get_menu_by_group_add
              untuk di edit = get_menu_by_group_edit
             */
            $arr_group_id = $this->m_menu->get_menu_by_group_add($group_menu, $this->menu_id);
            //--------------------------end-----------------------------------------------------------
            if (!empty($arr_group_id)) {
                $data['available_menu'] = array_unique($arr_group_id);
                if (!in_array($this->menu_id, $data['available_menu'])) {
                    redirect(base_url() . 'error', 'refresh');
                } else {
                    /*
                      modul untuk akses add masing masing modul berebda
                      jangan lupa copy $data nya (jika dia bener langsung ke add)
                     */
                    $group_menu = $this->session->userdata('group_menu');
                    // get link from tbl_menu 
                    $data['menu_link'] = $this->m_menu->get_menulink($this->menu_id);

                    // set data
                    $data['menu_label'] = $this->m_menu->get_menulabel($this->menu_id);

                    //$data['sweep_number']  	= $this->m_swapbank->create_sweep_number(date('d-m-Y'));
                    $data['date_now'] = date('d-m-Y');

                    //panggil model hak akses untuk autoriti
                    $data['group_user'] = $this->m_menu->group_user_autority($this->menu_id, $group_menu);
                    // set for view
                    $this->load->view('v_header');
                    $this->load->view('cash_and_bank/swift_bank/v_new_swift_bank', $data);
                    $this->load->view('v_footer');
                    //----------------------end--------------------------------------------------------		
                }
            } else {
                redirect(base_url() . 'error', 'refresh');
            }
        } else {
            redirect(base_url() . 'login', 'refresh');
        }
    }

    //Function Menampilkan Data Pada Data Grid View
    public function ajax() {
        $page = ($this->input->post('page')) ? intval($this->input->post('page')) : 1;
        $rows = ($this->input->post('rows')) ? intval($this->input->post('rows')) : 150;

        $hasil = array();
        /* ===========rows*page tidak boleh melebihi dari jumlah data======= */

        /* =================================post dari find di kiri==================================================== */
        $param = $this->input->post('param');
        $Number = isset($param['txt_IDNumber']) ? $param['txt_IDNumber'] : '';
        $Desc = isset($param['txt_Description']) ? $param['txt_Description'] : '';

        $DateFrom = isset($param['txt_DateFrom']) ? $param['txt_DateFrom'] : '';
        $DateTo = isset($param['txt_DateTo']) ? $param['txt_DateTo'] : '';
        $TransStatus = isset($param['chk_TransStatus']) ? $param['chk_TransStatus'] : '';
        $BranchCode = isset($param['cmb_branch']) ? $param['cmb_branch'] : '';
        /* ============================================end============================================================ */
        /* ========================jika kondisi tidak sama dengan kosong di find lakukan proses di if================= */
        if ($BranchCode != "") {
            $this->db->where('BranchCode', $BranchCode);
        } else {
            $this->db->where('BranchCode', $this->session->userdata('branch'));
        }

        if ($Number != "") {
            $this->db->like('BSweepNumber', $Number);
        }
        if ($Desc != "") {
            $this->db->like('BSweepDesc', $Desc);
        }
        if ($TransStatus != '') {
            $this->db->where_in('TransStatus', $TransStatus);
        } else {
            /*
              default adalah 2,6. Finished dan Need Approval
             */
            $this->db->where_in('TransStatus', array(0, 1, 4, 5, 6, 7, 8));
        }


        if ((($DateFrom != '') && ($DateTo != ''))) {
            if ($DateFrom <= $DateTo) {
                $this->db->where('at_banksweep.BSweepDate >=', date("Y-m-d", strtotime($DateFrom)));
                $this->db->where('at_banksweep.BSweepDate <=', date("Y-m-d", strtotime($DateTo)));
            }
        }
        /* ==========================end================================================================= */

        $count_data = $this->db->count_all_results('at_banksweep');
        $offset = $count_data - ($rows * $page);
        if ($offset > 0) {
            $rows = $rows;
        } else {
            $rows = $count_data - ($rows * ($page - 1));
        }
        /* ========================end======================================= */
        $result = $this->m_swapbank->get_all();

        for ($i = 0; $i <= ($rows - 1); $i++) {
            // kalau master ambil dari get_status_master(), kalau transaksi get_status()
            $TransStatus = get_status($result[$i]->TransStatus);

            $hasil[] = array(
                'TransNumber' => $result[$i]->BSweepNumber,
                'BSweepDate' => $result[$i]->BSweepDate,
                'BSweepAmount' => $result[$i]->BSweepAmount,
                'BSweepDesc' => $result[$i]->BSweepDesc,
                'CreatedBy' => $result[$i]->Created,
                'TransStatus' => $TransStatus
            );
        }

        if (empty($hasil)) {
            $emptyVar = array();
            echo json_encode($emptyVar);
        } else {
            $result = array();
            $result['total'] = $count_data;
            $result['rows'] = $hasil;
            echo json_encode($result);
        }
    }

    public function get_akun_bank_cabang_add() {
        $CompanyCode = $this->session->userdata('company');
        $list_bank = $this->m_swapbank->get_coa_bank_cabang_add($CompanyCode);
        //echo $this->db->last_query();

        echo $list_bank;
    }

    public function get_akun_bank_cabang($branch) {
        $CompanyCode = $this->session->userdata('company');
        $branch = str_replace('_', '-', $branch);
        $list_bank = $this->m_swapbank->get_coa_bank_cabang($CompanyCode, $branch);

        echo $list_bank;
    }

    public function get_akun_bank_add() {
        $CompanyCode = $this->session->userdata('company');
        $list_bank = $this->m_swapbank->get_coa_bank_add($CompanyCode);


        echo $list_bank;
    }

    public function get_akun_bank($branch) {
        $branch = str_replace('_', '-', $branch);
        $CompanyCode = $this->session->userdata('company');
        $list_bank = $this->m_swapbank->get_coa_bank($CompanyCode, $branch);


        echo $list_bank;
    }

    public function get_swep_number() {
        $preg_date = $this->input->post('Sweep_date') == '' ? date('d-m-Y') : $this->input->post('Sweep_date');
        $dep_number = $this->m_swapbank->create_sweep_number($preg_date);

//        print_r($data['sq_number1']);

        $result['status'] = true;
        $result['number'] = $dep_number;
        echo json_encode($result);
    }

    public function proses_tutup() {
        $this->db->trans_rollback();
        die();
    }

    public function insert_group($BranchCode, $txt_date, $txt_swapbank_no, $cmb_bank_from, $cmb_bank_to, $txa_memo, $txt_amount, $get_branch_ho, $BranchCode,$cheque_number) {

        $data_swepbank = array(
            'BranchCode' => $BranchCode,
            'BSweepDate' => $txt_date,
            'BSweepNumber' => $txt_swapbank_no,
            'BankTransfer' => $cmb_bank_from,
            'BankReceipt' => $cmb_bank_to,
            'BSweepDesc' => $txa_memo,
            'BSweepAmount' => $txt_amount,
            'TransStatus' => 4,
            'CompRecpCode' => $get_branch_ho,
            'CompTransCode' => $BranchCode,
            'ChequeNumber'  => $cheque_number,
            'CreatedBy' => $this->session->userdata('username'),
            'CreatedAt' => date("Y-m-d H:i:s"),
            'LastUser' => $this->session->userdata('username')
        );

        $this->trans_data['insert_group']['data'] = $data_swepbank;
    }

    public function insert_journal($txt_date, $txt_swapbank_no, $cmb_bank_to, $cmb_bank_from, $txt_amount, $txa_memo, $get_branch_ho, $BranchCode) {
        $journal_debet = array(
            'BSweepDate' => $txt_date,
            'BSweepNumber' => $txt_swapbank_no,
            'BSweepAccountNumber' => $cmb_bank_to,
            'BSweepSaldoDebet' => $txt_amount,
            'BSweepSaldoCredit' => 0,
            'BSweepDesc' => $txa_memo,
            'BranchRecpCode' => $get_branch_ho,
            'BSweepSignStatus' => 0,
            //'BranchCode' 			=> $get_branch_ho,
            'LastUser' => $this->session->userdata('username')
        );

        $this->trans_data['insert_journal']['data'][] = $journal_debet;

        $journal_credit = array(
            'BSweepDate' => $txt_date,
            'BSweepNumber' => $txt_swapbank_no,
            'BSweepAccountNumber' => $cmb_bank_from,
            'BSweepSaldoDebet' => 0,
            'BSweepSaldoCredit' => $txt_amount,
            'BSweepDesc' => $txa_memo,
            'BranchRecpCode' => $BranchCode,
            'BSweepSignStatus' => 1,
            //'BranchCode' 			=> $BranchCode,
            'LastUser' => $this->session->userdata('username')
        );

        $this->trans_data['insert_journal']['data'][] = $journal_credit;
    }

    public function insert() {
        $BranchCode = $this->session->userdata('branch');
        $company = $this->session->userdata('company');
        $get_branch_ho = $this->m_swapbank->get_company($company);

        $bulan = date('m');
        $tahun = date('y');
        $cek_tahun = date('Y');
        $kode = "SB";
        $result_insert = 0;


        $txt_date = date("Y-m-d", strtotime($this->input->post('txt_date')));
        $cmb_bank_from = $this->input->post('cmb_bank_from');
        $cmb_bank_to = $this->input->post('cmb_bank_to');
        $txa_memo = $this->input->post('txa_memo');
        $cheque_number = $this->input->post('cheque_number');
        $txt_amount = $this->input->post('txt_amount');
        $txt_swapbank_no = $this->m_swapbank->create_sb_number($txt_date);

        /* =================== fungsi insert group =================================== */
        $this->insert_group($BranchCode, $txt_date, $txt_swapbank_no, $cmb_bank_from, $cmb_bank_to, $txa_memo, $txt_amount, $get_branch_ho, $BranchCode,$cheque_number);

        /* =================== fungsi insert journal =================================== */
        $this->insert_journal($txt_date, $txt_swapbank_no, $cmb_bank_to, $cmb_bank_from, $txt_amount, $txa_memo, $get_branch_ho, $BranchCode);

        $result_return = $this->m_swapbank->insert_transsaction($this->trans_data);

        $this->trans_data = [];

        if ($result_return) {
            $result['status'] = true;
            $result['message'] = get_notification_transaksi($this->name, 'insert', 1, $txt_swapbank_no);
        } else {
            $result['status'] = false;
            $result['message'] = get_notification_transaksi($this->name, 'insert', 0, $txt_swapbank_no);
        }

        echo json_encode($result);
    }

    public function edit() {
        if ($this->session->userdata("login") == TRUE) {
            $group_menu = $this->session->userdata('group_menu');
            /*
              untuk di index/list = get_menu_by_group,
              untuk di add = get_menu_by_group_add
              untuk di edit = get_menu_by_group_edit
             */
            $arr_group_id = $this->m_menu->get_menu_by_group_edit($group_menu, $this->menu_id);
            //--------------------------end-----------------------------------------------------------
            if (!empty($arr_group_id)) {
                $data['available_menu'] = array_unique($arr_group_id);
                if (!in_array($this->menu_id, $data['available_menu'])) {
                    redirect(base_url() . 'error', 'refresh');
                } else {
                    /*
                      modul untuk akses add masing masing modul berebda
                      jangan lupa copy $data nya (jika dia bener langsung ke add)
                     */
                    $group_menu = $this->session->userdata('group_menu');
                    // get link from tbl_menu 
                    $data['menu_link'] = $this->m_menu->get_menulink($this->menu_id);
                    // set data
                    $data['menu_label'] = $this->m_menu->get_menulabel($this->menu_id);

                    // inisialisasi additional parameter
                    $id = str_replace($data['menu_link'] . '/edit/', "", $this->uri->uri_string());
                    $potongan_id = explode("/", $id);
                    $Var_gabungan = $potongan_id[0];
                    $data['detail'] = $this->m_swapbank->get_detail($id, $Var_gabungan);

                    //panggil model hak akses untuk autoriti
                    $data['group_user'] = $this->m_menu->group_user_autority($this->menu_id, $group_menu);

                    // set for view
                    $this->load->view('v_header');
                    $this->load->view('cash_and_bank/swift_bank/v_edit_swift_bank', $data);
                    $this->load->view('v_footer');
                    //----------------------end--------------------------------------------------------		
                }
            } else {
                redirect(base_url() . 'error', 'refresh');
            }
        } else {
            redirect(base_url() . 'login', 'refresh');
        }
    }

    // Function Update
    public function update() {
        $BranchCode = $this->session->userdata('branch');
        $company = $this->session->userdata('company');
        $get_branch_ho = $this->m_swapbank->get_company($company);

        $txt_swapbank_no = $this->input->post('txt_swapbank_no');
        $txt_date = date("Y-m-d", strtotime($this->input->post('txt_date')));
        $cmb_bank_from = $this->input->post('cmb_bank_from');
        $cmb_bank_to = $this->input->post('cmb_bank_to');
        $txa_memo = $this->input->post('txa_memo');
        $cheque_number = $this->input->post('cheque_number');
        $txt_amount = $this->input->post('txt_amount');
        $chk_suspend = $this->input->post('chk_suspend');

        $id = $txt_swapbank_no;
        $cek_app_mgr = $this->m_swapbank->cek_app_mgr($id);
        $cek_app_dir = $this->m_swapbank->cek_app_dir($id);
        $cek_status = $this->m_swapbank->cek_trans_status($id);
        $result_insert = 0;

        /* ========================== set update group ====================================== */
        $this->update_group($BranchCode, $txt_swapbank_no, $cmb_bank_from, $cmb_bank_to, $txa_memo, $txt_amount,$cheque_number);

        /* ============================= set delete journal ========================================= */
        $this->trans_data['delete_journal']['TransNumber'] = $txt_swapbank_no;

        /* ================================== set insert journal ================================================== */
        $this->insert_journal($txt_date, $txt_swapbank_no, $cmb_bank_to, $cmb_bank_from, $txt_amount, $txa_memo, $get_branch_ho, $BranchCode);

        $result_return = $this->m_swapbank->update_transsaction($this->trans_data);

        $this->trans_data = [];

        if ($result_return) {
            $result['status'] = true;
            $result['message'] = get_notification_transaksi($this->name, 'update', 1, $txt_swapbank_no);
        } else {
            $result['status'] = false;
            $result['message'] = get_notification_transaksi($this->name, 'update', 0, $txt_swapbank_no);
        }

        echo json_encode($result);
    }

    public function update_group($BranchCode, $txt_swapbank_no, $cmb_bank_from, $cmb_bank_to, $txa_memo, $txt_amount,$cheque_number) {
        $data_swapbank = array(
            'BranchCode' => $BranchCode,
            'BankTransfer' => $cmb_bank_from,
            'BankReceipt' => $cmb_bank_to,
            'BSweepDesc' => $txa_memo,
            'BSweepAmount' => $txt_amount,
            'ChequeNumber' => $cheque_number,
            'LastUser' => $this->session->userdata('username')
        );

        $this->trans_data['update_group']['data'] = $data_swapbank;
        $this->trans_data['update_group']['TransNumber'] = $txt_swapbank_no;
    }

    public function suspend_data() {
        $id = $this->input->post('id');
        //$status 	= $this->input->post('trans_status');

        $data = array(
            'TransStatus' => 3,
            'LastUser' => $this->session->userdata('username')
        );

        /* ==================== update suspend data ================== */
        $this->m_swapbank->suspend($data, $id);


        if ($this->db->trans_status() === TRUE) {
            $this->db->trans_commit();
            $result['status'] = true;
            $result['message'] = get_notification('suspend', 1);
        } else {
            $this->db->trans_rollback();
            $result['status'] = false;
            $result['message'] = get_notification('suspend', 0);
        }
        echo json_encode($result);
    }

    public function to_journal() {
        $data['menu_link'] = $this->m_menu->get_menulink($this->menu_id);

        $CompanyCode = $this->session->userdata('company');
        $BranchCode = $this->session->userdata('branch');
        $sweepbank_number = str_replace($data['menu_link'] . '/to_journal/', "", $this->uri->uri_string());
        $potongan_id = explode("/", $sweepbank_number);
        $Branch_id = $potongan_id[0];

        $get_company_from_n_to = $this->m_swapbank->get_branchCode($sweepbank_number);

        $data['date_journal'] = $this->m_swapbank->get_date_journal_sweppbank($sweepbank_number);
        $data['menu_label'] = $this->m_menu->get_menulabel($this->menu_id);

        $data['list_jurnal'] = $this->m_swapbank->get_all_journal_sweppbank($sweepbank_number, $BranchCode);
        // echo $this->db->last_query();

        $this->load->view('v_header');
        $this->load->view('cash_and_bank/swift_bank/v_print_journal_sweep_journal_bank', $data);
        // if($get_company_from_n_to->CompTransCode == $get_company_from_n_to->CompRecpCode){
        // 	$this->load->view('cash_and_bank/swift_bank/v_print_journal_sweep_journal_bank', $data);
        // }
        // else{
        // 	$this->load->view('cash_and_bank/swift_bank/v_print_journal_sweep_journal', $data);	
        // }

        $this->load->view('v_footer');
    }

    public function approval2() {
        if ($this->session->userdata("jobtitle_status") == 1) {
            $sw_number = $this->input->post('id');

            $data_swapbank = array(
                'AppLevel1Status' => 1,
                'TransStatus' => 2,
                'AppLevel1Code' => $this->session->userdata("username"),
                'AppLevel1Date' => date("Y-m-d"),
                'AppFinished' => 1,
                'LastUser' => $this->session->userdata("username")
            );

            $this->trans_data['approve_data']['data'] = $data_swapbank;
            $this->trans_data['approve_data']['TransNumber'] = $sw_number;

            $result_return = $this->m_swapbank->approve_transsaction($this->trans_data);

            $this->trans_data = [];

            if ($result_return) {
                $result['status'] = true;
                $result['message'] = get_notification_transaksi($this->name, 'approve', 1, $sw_number);
            } else {
                $result['status'] = false;
                $result['message'] = get_notification_transaksi($this->name, 'approve', 0, $sw_number);
            }

            echo json_encode($result);
        }
    }

    public function reversed_data() {
        /* ===================================Deklarasi Variabel untuk proses insert atau update=================================== */
        $txt_swapbank_no = $this->input->post('id');

        $arr_no = explode("/", $txt_swapbank_no);
        $no_transaction = substr($arr_no[1], 0, 4);
        $month_transaction = (int) substr($no_transaction, 0, 2);
        $year_transaction = ((int) substr($no_transaction, 2, 2)) + 2000;

        $date_transaction = $year_transaction . $month_transaction;

        $data = array(
            "TransStatus" => 4,
            "AppFinished" => 0
        );

        /* ============================== check period end ======================================== */
        $check_period = $this->m_swapbank->check_period_end($date_transaction);

        if ($check_period == false) {

            /* =============================set data reverse =================================== */
            $this->trans_data['reverse_data']['data'] = $data;
            $this->trans_data['reverse_data']['TransNumber'] = $txt_swapbank_no;

            /* ============================= delete reconcile =============================================== */
            $this->trans_data['delete_reconcile']['TransNumber'] = $txt_swapbank_no;

            $result_return = $this->m_swapbank->reverse_transsaction($this->trans_data);

            $this->trans_data = [];

            if ($result_return) {
                $result['status'] = true;
                $result['message'] = get_notification_transaksi($this->name, 'reverse', 1, $txt_swapbank_no);
            } else {
                $result['status'] = false;
                $result['message'] = get_notification_transaksi($this->name, 'reverse', 0, $txt_swapbank_no);
            }
            echo json_encode($result);
        } else {
            $result['status'] = false;
            $result['message'] = get_notification('reverse_in_period', 0);
            echo json_encode($result);
        }
    }

    public function to_preview($obj_string = null) {
        $branch = $this->session->userdata('branch');
        $data['company'] = $this->m_swapbank->get_company_by_branch($branch);
//        $data['list'] = $this->m_swapbank->get_all_to_print($branch);
        $data['menu_id']        = $this->menu_id;
        $data['menu_label']     = $this->m_menu->get_menulabel($this->menu_id);
        $data['menu_link']      = $this->m_menu->get_menulink($this->menu_id);
        
        $data_filter            = arrayParamInUrlToStr($obj_string);
        $data['list']           = $this->m_swapbank->get_all_to_print($data_filter);
        

        $this->load->view('v_header');
        $this->load->view('cash_and_bank/swift_bank/v_preview_swapbank', $data);
        $this->load->view('v_footer');
    }
    public function to_preview_LAMA() {
        $branch = $this->session->userdata('branch');
        $data['company'] = $this->m_swapbank->get_company_by_branch($branch);
        $data['list'] = $this->m_swapbank->get_all_to_print($branch);

        $this->load->view('v_header');
        $this->load->view('cash_and_bank/swift_bank/v_preview_swapbank', $data);
        $this->load->view('v_footer');
    }

    public function to_print_list() {
        // set data
        $data['list'] = $this->m_swapbank->get_all();

        $this->load->view('v_header');
        $this->load->view('cash_and_bank/swift_bank/v_preview_swapbank', $data);
        $this->load->view('v_footer');
    }

    //Daswan Fungsi untuk print detail
    function to_print_detail() {
        $data['menu_link'] = $this->m_menu->get_menulink($this->menu_id);
        $data['menu_label'] = $this->m_menu->get_menulabel($this->menu_id);

        $id = str_replace($data['menu_link'] . '/to_print_detail/', "", $this->uri->uri_string());

        if ($id != "") {
            $data['detail'] = $this->m_swapbank->get_detail_print($id);
            // echo $this->db->last_query();   
            $this->load->view('v_header');
            $this->load->view('cash_and_bank/swift_bank/v_print_sweep_bank', $data);
            $this->load->view('v_footer');
        }
    }

    function get_bank_balance() {
        $AccountNumber = $this->input->post('AccountNumber');
        $branch = $this->session->userdata('branch');

        $bank_balance = $this->m_account_journal->m_get_bank_balance($branch, $AccountNumber);

        if ($bank_balance == false) {
            $return = array('message' => false, 'value' => 0);
        } else {
            $return = array('message' => true, 'value' => $bank_balance);
        }

        echo json_encode($return);
    }

}
