<?php

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

class Ibank_transfer extends CI_Controller {

    public $menu_id = 268;
    public $name = 'IBank Transfer';
    public $trans_data = array();

    public function __construct() {
        parent::__construct();
        $this->load->model('m_ibank_transfer');
        $this->load->model('m_expense_cashbon');
        $this->load->model('m_account_journal');
        $this->load->model('m_payment');
        $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/inter_bank_transfer/v_ibank_transfer', $data);
                    $this->load->view('v_footer');
                }
            } else {
                redirect(base_url() . 'error', 'refresh');
            }
        } else {
            redirect(base_url() . 'login', 'refresh');
        }
    }

    public function get_ibank_number() {
        $preg_date = $this->input->post('Ibank_date') == '' ? date('d-m-Y') : $this->input->post('Ibank_date');

        $ibank_number = $this->m_ibank_transfer->create_ibank_number($preg_date);

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

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

    //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('IBankNumber', $Number);
        }
        if ($Desc != "") {
            $this->db->like('IBankDesc', $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_interbanktransfer.IBankDate >=', date("Y-m-d", strtotime($DateFrom)));
                $this->db->where('at_interbanktransfer.IBankDate <=', date("Y-m-d", strtotime($DateTo)));
            }
        }
        /* ==========================end================================================================= */

        $count_data = $this->db->count_all_results('at_interbanktransfer');
        $offset = $count_data - ($rows * $page);
        if ($offset > 0) {
            $rows = $rows;
        } else {
            $rows = $count_data - ($rows * ($page - 1));
        }
        /* ========================end======================================= */
        $result = $this->m_ibank_transfer->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]->IBankNumber,
                'IBankDate' => $result[$i]->IBankDate,
                'IBankAmount' => $result[$i]->IBankAmount,
                'IBankDesc' => $result[$i]->IBankDesc,
                'TransStatus' => $TransStatus,
                'CompFrom' => $result[$i]->CompFrom,
                'CompTo' => $result[$i]->CompTo,
                'BankFrom' => $result[$i]->BankFrom,
                'BankTo' => $result[$i]->BankTo,
                'CreatedBy' => $result[$i]->Created,
            );
        }

        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_from_add() {
        $CompanyCode = $this->session->userdata('company');
        $list_bank = $this->m_ibank_transfer->get_coa_bank_from_ho_add($CompanyCode);

        echo"$list_bank";
    }

    public function get_akun_bank_to_add($company_code, $currency_idr, $currency_code) {

        $list_bank = $this->m_ibank_transfer->get_coa_bank_to_ho_add($company_code, $currency_idr, $currency_code);
        //echo $this->db->last_query();
        echo $list_bank;
    }

    public function get_akun_bank_from_edit($branch) {
        $CompanyCode = $this->session->userdata('company');
        $replace = str_replace('_', '-', $branch);
        $list_bank = $this->m_ibank_transfer->get_coa_bank_from_ho_edit($CompanyCode, $replace);

        echo"$list_bank";
    }

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

    //proses input ///////////////////////////////////////////////

    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 {

                    $group_menu = $this->session->userdata('group_menu');
                    $data['menu_link'] = $this->m_menu->get_menulink($this->menu_id);
                    $data['menu_label'] = $this->m_menu->get_menulabel($this->menu_id);
                    $sess_brach = $this->session->userdata('branch');

                    //$data['ibank_transfer']  = $this->m_ibank_transfer->create_ibank_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);

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

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

        $txt_date = date("Y-m-d", strtotime($this->input->post('txt_date')));

        /* ==================================== Fungsi Create Ibank Transfer No ==================================== */
        $txt_ibank_no = $this->m_ibank_transfer->create_ib_number($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');
        $txt_amount = $this->input->post('txt_amount');
        $txt_rate = $this->input->post('txt_rate');
        $currency_code = $this->input->post('currency_code');
        $cheque_number = $this->input->post('cheque_number');
        $currency_code_to = $this->input->post('currency_code_to');
        $branch_trans = $this->input->post('branch_trans');

        /* ==================================== Fungsi Count Currency ==================================== */
        $count_currency = $this->count_currency($currency_code, $currency_code_to, $txt_amount, $txt_rate);

        /* ==================================== Fungsi get Cabang ==================================== */
        //$get_branch_cabang  = $this->m_ibank_transfer->get_akun_number($cmb_bank_to, $company);

        $get_branch = $this->m_ibank_transfer->get_branch_by_name($company, $branch_trans);

        /* ==================================== Fungsi Insert Group ==================================== */
        $this->insert_group($BranchCode, $txt_date, $txt_ibank_no, $cmb_bank_from, $cmb_bank_to, $txa_memo, $txt_amount, $get_branch, $currency_code, $currency_code_to, $txt_rate,$cheque_number);

        /* ==================================== Fungsi Insert Journal ==================================== */
        $this->insert_journal($txt_date, $txt_ibank_no, $cmb_bank_to, $cmb_bank_from, $count_currency['total'], $count_currency['total_debet'], $count_currency['total_credit'], $txa_memo, $get_branch, $BranchCode);

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

        $this->trans_data = [];

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

        echo json_encode($result);
    }

    public function count_currency($currency_code, $currency_code_to, $txt_amount, $txt_rate) {

        ///perhitungan usd to usd, idr to idr, idr to usd, sud to idr
        if ($currency_code == $currency_code_to) {
            $total = $txt_amount * $txt_rate;

            $total_debet = $txt_amount;
            $total_credit = $txt_amount;
        } else {
            if ($currency_code_to == "IDR") {
                $total = $txt_amount;
                $total_debet = $txt_amount;
                $total_credit = $txt_amount / $txt_rate;
            } else {
                $total = $txt_amount * $txt_rate;
                $total_debet = $txt_amount;
                $total_credit = $txt_amount * $txt_rate;
            }
        }
        //end////////////////////////////////////////////////

        $result['total'] = $total;
        $result['total_debet'] = $total_debet;
        $result['total_credit'] = $total_credit;

        return $result;
    }

    public function insert_group($BranchCode, $txt_date, $txt_ibank_no, $cmb_bank_from, $cmb_bank_to, $txa_memo, $txt_amount, $branch_cabang, $currency_code, $currency_code_to, $txt_rate,$cheque_number) {

        $data_ibank_transfer = array(
            'BranchCode' => $BranchCode,
            'IBankDate' => $txt_date,
            'IBankNumber' => $txt_ibank_no,
            'BankTransfer' => $cmb_bank_from,
            'BankReceipt' => $cmb_bank_to,
            'IBankDesc' => $txa_memo,
            'IBankAmount' => $txt_amount,
            'TransStatus' => 5,
            'CompRecpCode' => $BranchCode,
            'CompTransCode' => $branch_cabang, //get_branch_cabang->BranchCode,
            'CurrencyCode' => $currency_code,
            'CurrencyCode_to' => $currency_code_to,
            'CurrencyRate' => $txt_rate,
            '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_ibank_transfer;
    }

    public function insert_journal($txt_date, $txt_ibank_no, $cmb_bank_to, $cmb_bank_from, $total, $total_debet, $total_credit, $txa_memo, $branch_cabang, $BranchCode) {

        $journal_debet = array(
            'IBankDate' => $txt_date,
            'IBankNumber' => $txt_ibank_no,
            'IBankAccountNumber' => $cmb_bank_to,
            'IBankSaldoDebet' => $total,
            'IBankSaldoCredit' => 0,
            'AmountCurrency' => $total_debet,
            'IBankDesc' => $txa_memo,
            'IBankSignStatus' => 0,
            'BranchRecpCode' => $branch_cabang, //get_branch_cabang->BranchCode,
            //'BranchCode' 			=> $get_branch_ho,
            'LastUser' => $this->session->userdata('username')
        );

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

        $journal_credit = array(
            'IBankDate' => $txt_date,
            'IBankNumber' => $txt_ibank_no,
            'IBankAccountNumber' => $cmb_bank_from,
            'IBankSaldoDebet' => 0,
            'IBankSaldoCredit' => $total,
            'AmountCurrency' => $total_credit,
            'IBankDesc' => $txa_memo,
            'IBankSignStatus' => 1,
            'BranchRecpCode' => $BranchCode,
            //'BranchCode' 			=> $get_branch_ho,
            'LastUser' => $this->session->userdata('username')
        );

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

    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)
                     */
                    // get link from tbl_menu 
                    $group_menu = $this->session->userdata('group_menu');
                    $data['menu_link'] = $this->m_menu->get_menulink($this->menu_id);
                    // set data
                    $CompanyCode = $this->session->userdata('company');
                    $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_ibank_transfer->get_detail($id, $Var_gabungan);
                    $explode_branch = explode("-", $Var_gabungan);
                    $company_code = $explode_branch[0];

                    $data['company_code'] = $company_code;

                    //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/inter_bank_transfer/v_edit_bank_transfer', $data);
                    $this->load->view('v_footer');
                    //----------------------end--------------------------------------------------------		
                }
            } else {
                redirect(base_url() . 'error', 'refresh');
            }
        } else {
            redirect(base_url() . 'login', 'refresh');
        }
    }

    public function update_group($BranchCode, $txt_date, $txt_ibank_no, $cmb_bank_from, $cmb_bank_to, $txa_memo, $txt_amount, $BranchCode, $branch_cabang, $currency_code, $currency_code_to, $txt_rate,$cheque_number) {

        $data_ibank_transfer = array(
            'BranchCode' => $BranchCode,
            'IBankDate' => $txt_date,
            'IBankNumber' => $txt_ibank_no,
            'BankTransfer' => $cmb_bank_from,
            'BankReceipt' => $cmb_bank_to,
            'IBankDesc' => $txa_memo,
            'IBankAmount' => $txt_amount,
            'CompRecpCode' => $BranchCode,
            'CompTransCode' => $branch_cabang, //get_branch_cabang->BranchCode,
            'CurrencyCode' => $currency_code,
            'CurrencyCode_to' => $currency_code_to,
            'CurrencyRate' => $txt_rate,
            'ChequeNumber' => $cheque_number,
            'LastEdited' => $this->session->userdata('username')
        );

        $this->trans_data['update_group']['data'] = $data_ibank_transfer;
        $this->trans_data['update_group']['TransNumber'] = $txt_ibank_no;
    }

    public function update() {
        $BranchCode = $this->session->userdata('branch');
        $company = $this->session->userdata('company');

        $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');
        $txt_amount = $this->input->post('txt_amount');
        $txt_rate = $this->input->post('txt_rate');
        $txt_ibank_no = $this->input->post('txt_ibank_no');
        $currency_code = $this->input->post('currency_code');
        $cheque_number = $this->input->post('cheque_number');
        $currency_code_to = $this->input->post('currency_code_to');

        $result_update = 0;

        /* ==================================== Fungsi Count Currency ==================================== */
        $count_currency = $this->count_currency($currency_code, $currency_code_to, $txt_amount, $txt_rate);

        /* ==================================== Fungsi Get branch Cabang ==================================== */
        $get_branch_cabang = $this->m_ibank_transfer->get_akun_number($cmb_bank_to, $company);

        /* ==================================== Fungsi Update Group ======================================== */
        $this->update_group($BranchCode, $txt_date, $txt_ibank_no, $cmb_bank_from, $cmb_bank_to, $txa_memo, $txt_amount, $BranchCode, $get_branch_cabang->BranchCode, $currency_code, $currency_code_to, $txt_rate,$cheque_number);

        /* ==================================== Fungsi Delete Journal ======================================== */
        $this->trans_data['delete_journal']['TransNumber'] = $txt_ibank_no;

        /* ==================================== Fungsi Insert Journal ==================================== */
        $this->insert_journal($txt_date, $txt_ibank_no, $cmb_bank_to, $cmb_bank_from, $count_currency['total'], $count_currency['total_debet'], $count_currency['total_credit'], $txa_memo, $get_branch_cabang->BranchCode, $BranchCode);

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

        $this->trans_data = [];

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

        echo json_encode($result);
    }

    public function to_preview($obj_string = null) {
        $data['company'] = $this->m_ibank_transfer->get_company_by_branch($this->session->userdata('branch'));
        //$data['list'] 		= $this->m_ibank_transfer->get_all_to_print($this->session->userdata('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_ibank_transfer->get_all_to_print($data_filter);

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

    public function to_preview_LAMA($data_grid = null) {
        $data['company'] = $this->m_ibank_transfer->get_company_by_branch($this->session->userdata('branch'));
        //$data['list'] 		= $this->m_ibank_transfer->get_all_to_print($this->session->userdata('branch'));
        $data_grid = str_replace('__', '/', $data_grid);
        $data_grid = str_replace('_', '-', $data_grid);
        $data_grid = str_replace('%20', ' ', $data_grid);
        $arr_grid_lv1 = explode('linebaru', $data_grid);

        $obj_string = '[';

        for ($x = 0; $x < count($arr_grid_lv1) - 1; $x++) {
            $arr_data_lv1 = $arr_grid_lv1[$x];
            $arr_grid_lv2 = explode('spasi', $arr_data_lv1);

            $obj_string .= '{';
            for ($i = 0; $i < count($arr_grid_lv2); $i++) {
                $arr_grid_lv3 = explode(':', $arr_grid_lv2[$i]);
                if ($i < count($arr_grid_lv2) - 1) {
                    $obj_string .= '"' . $arr_grid_lv3[0] . '":"' . $arr_grid_lv3[1] . '",';
                } else {
                    $obj_string .= '"' . $arr_grid_lv3[0] . '":"' . $arr_grid_lv3[1] . '"';
                }
            }

            if ($x < count($arr_grid_lv1) - 2) {
                $obj_string .= '},';
            } else {
                $obj_string .= '}';
            }
        }

        $obj_string .= ']';
        $data['list'] = json_decode($obj_string);

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

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

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

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

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

        $get_company_from_n_to = $this->m_ibank_transfer->get_branchCode($ibank_number);

        $data['date_journal'] = $this->m_ibank_transfer->get_date_journal_ibank_transfer($ibank_number);

        //$data['list_jurnal_trans']  = $this->m_ibank_transfer->get_all_journal_ibank_trans($ibank_number, $get_company_from_n_to->CompTransCode);
        //echo $this->db->last_query();
        //$data['list_jurnal']  		= $this->m_ibank_transfer->get_all_journal_ibank($ibank_number, $get_company_from_n_to->CompRecpCode);
        //$data['list_jurnal_trans']  = $this->m_swapbank->get_all_journal_sweppbank_trans($sweepbank_number, $get_company_from_n_to->CompTransCode);
        $data['list_jurnal'] = $this->m_ibank_transfer->get_all_journal_ibank_transfer($ibank_number, $get_company_from_n_to);
        //echo $this->db->last_query();
        $this->load->view('v_header');

        // if($get_company_from_n_to->CompTransCode == $get_company_from_n_to->CompRecpCode){
        // 	$this->load->view('cash_and_bank/inter_bank_transfer/v_print_journal_bank_to_bank', $data);
        // }else{
        // 	$this->load->view('cash_and_bank/inter_bank_transfer/v_print_journal_bank_transfer', $data);
        // }

        $this->load->view('cash_and_bank/inter_bank_transfer/v_print_journal_bank_to_bank', $data);

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

    public function approval2() {
        if ($this->session->userdata("jobtitle_status") == 0) {

            $txt_ibank_no = $this->input->post('txt_ibank_no');

            $data_group = 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_group;
            $this->trans_data['approve_data']['TransNumber'] = trim($txt_ibank_no);

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

            $this->trans_data = [];

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

            echo json_encode($result);
        }
    }

    /* ===================================Fungsi reverse transaksi========================================== */

    public function reversed_data() {

        $txt_ibank_no = $this->input->post('id');

        $arr_no = explode("/", $txt_ibank_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_reversed = array(
            "TransStatus" => 5,
            "AppFinished" => 0
        );

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

        if ($check_period == false) {

            $this->trans_data['reverse_data']['data'] = $data_reversed;
            $this->trans_data['reverse_data']['TransNumber'] = trim($txt_ibank_no);

            $this->trans_data['delete_reconcile']['TransNumber'] = trim($txt_ibank_no);

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

            $this->trans_data = [];

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

    public function suspend_data() {
        $ibank_number = $this->input->post('id');
        $hasil = 0;

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

        $this->trans_data['suspend_data']['data'] = $data;
        $this->trans_data['suspend_data']['TransNumber'] = trim($ibank_number);

        $result_return = $this->m_ibank_transfer->suspend_transsaction($this->trans_data);

        $this->trans_data = [];

        if ($result_return) {
            $result['status'] = true;
            $result['message'] = get_notification('suspend', 1);
        } else {
            $result['status'] = false;
            $result['message'] = get_notification('suspend', 0);
        }

        echo json_encode($result);
    }

    //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_ibank_transfer->get_detail_print($id);
            // echo $this->db->last_query();   
            $this->load->view('v_header');
            $this->load->view('cash_and_bank/inter_bank_transfer/v_print_detail_bank_transfer', $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);
    }

}
