<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/* 	
 * 	Author 	: Fachri
 * 	Tanggal : 03-07-2015	
 * 	Revisi 	: 
 */

class Other_Income extends CI_Controller {

    public $menu_id = 270;
    public $menu_model = 'm_other_income';
    public $app_level_new = array(0, 1);
    public $name = 'Other Income';
    public $trans_data = array();

    public function __construct() {
        parent::__construct();
        $this->load->model('m_other_income');
        $this->load->model('m_account_journal');
        $this->load->helper('message_helper');
        $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();
            }
        }
    }

    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');
                    $data['menu_id'] = $this->menu_id;
                    $data['menu_model'] = $this->menu_model;

                    $data['menu_link'] = $this->m_menu->get_menulink($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/other_income/v_other_income', $data);
                    $this->load->view('v_footer');
                }
            } else {
                redirect(base_url() . 'error', 'refresh');
            }
        } else {
            redirect(base_url() . 'login', 'refresh');
        }
    }

    //Function Form Edit
    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_label'] = $this->m_menu->get_menulabel($this->menu_id);
                    $data['menu_link'] = $this->m_menu->get_menulink($this->menu_id);

                    $data['oi_date'] = date('d-m-Y');
                    $data['oi_number'] = $this->m_other_income->create_oi_number(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/other_income/v_new_other_income', $data);
                    $this->load->view('v_footer');
                    //----------------------end--------------------------------------------------------		
                }
            } else {
                redirect(base_url() . 'error', 'refresh');
            }
        } else {
            redirect(base_url() . 'login', 'refresh');
        }
    }

    public function ajax_bank_account() {
        echo json_encode($this->m_other_income->get_bank_account());
        //echo $this->db->last_query();
    }

    public function all_accountpembiayaan($company_code) {
        $data = $this->m_other_income->get_account_by_company($company_code);
        echo json_encode($data);
    }

    public function insert() {

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

        $txt_payment_no = $this->m_other_income->create_oi_number($txt_payment_date);

        $cmb_bank_account = $this->input->post('cbg_bank');
        $txa_memo = $this->input->post('txa_memo');
        $txt_amount = $this->input->post('txt_amount');
        $txt_rate = $this->input->post('txt_rate');
        $txt_curr_code = $this->input->post('txt_curr_code');

        $branch_code = $this->session->userdata('branch');
        $user_code = $this->session->userdata("username");
        $detail = $this->input->post('detail');
        $cheque_number = $this->input->post('cheque_number');
        $detail = json_decode($detail);

        $this->insert_group($branch_code, $txt_payment_date, $txt_payment_no, $cmb_bank_account, $txt_amount, $txa_memo, $txt_rate, $txt_curr_code, $user_code,$cheque_number);

        $this->insert_detail($detail, $txt_payment_no);

        $this->insert_journal($detail, $txt_payment_date, $txt_payment_no, $cmb_bank_account, $txt_amount, $txa_memo, $txt_rate);

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

        $this->trans_data = [];

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

        echo json_encode($result);
    }

    public function insert_group($branch_code, $txt_payment_date, $txt_payment_no, $cmb_bank_account, $txt_amount, $txa_memo, $txt_rate, $txt_curr_code, $user_code,$cheque_number) {
        $data_group = array(
            'BranchCode' => $branch_code,
            'OIncomeDate' => date("Y-m-d", strtotime($txt_payment_date)),
            'OIncomeNumber' => $txt_payment_no,
            'BankPayment' => $cmb_bank_account,
            'OIncomeDesc' => $txa_memo,
            'OInTotalAmount' => $txt_amount,
            'CurrencyRate' => $txt_rate,
            'CurrencyCode' => $txt_curr_code,
            'ChequeNumber'  => $cheque_number,
            'LastUser' => $user_code,
            'CreatedAt' => date('Y-m-d H:i:s'),
            'CreatedBy' => $user_code,
            'TransStatus' => 5
        );

        //$this->m_other_income->insert($data_group);
        $this->trans_data['insert_group']['data'] = $data_group;
    }

    public function insert_detail($detail, $txt_payment_no) {

        if (count($detail) > 0) {

            foreach ($detail as $row_detail) {

                $AccountName = $row_detail->AccountName;
                $Amount = $row_detail->Amount;
                $Memo = $row_detail->Memo;
                $user_code = $this->session->userdata("username");

                $AccountNumber = $this->m_other_income->get_accountnumber($AccountName);
                foreach ($AccountNumber as $acc_numb) {
                    $acc = $acc_numb->AccountNumber;
                }

                $data_detail = array(
                    'OIncomeNumber' => $txt_payment_no,
                    'OInAccountNumber' => $acc,
                    'OIncomeAmount' => $Amount,
                    'OIncomeMemo' => $Memo,
                    'LastUser' => $user_code
                );

                //$this->m_other_income->insert_detail($data_detail);
                $this->trans_data['insert_detail']['data'][] = $data_detail;
            }
        }
    }

    public function insert_journal($detail, $txt_payment_date, $txt_payment_no, $cmb_bank_account, $txt_amount, $txa_memo, $txt_rate, $validasi = false) {

        if (count($detail) > 0) {

            foreach ($detail as $row_detail) {

                $AccountName = $row_detail->AccountName;
                $Amount = $validasi == false ? $row_detail->Amount : $row_detail->OIncomeAmount;
                $Memo = $validasi == false ? $row_detail->Memo : $row_detail->OIncomeMemo;

                $AccountNumber = $this->m_other_income->get_accountnumber($AccountName);
                foreach ($AccountNumber as $acc_numb) {
                    $acc = $acc_numb->AccountNumber;
                }

                $data_journal_credit = array(
                    'OIncomeDate' => date("Y-m-d", strtotime($txt_payment_date)),
                    'OIncomeNumber' => $txt_payment_no,
                    'OInAccountNumber' => $acc,
                    'OInSaldoDebet' => 0,
                    'OInSaldoCredit' => $Amount * $txt_rate,
                    'OInSignStatus' => 0,
                    'OIncomeDesc' => $txa_memo,
                    'AmountCurrency' => $Amount,
                    'LastUser' => $this->session->userdata('username')
                );

                //$this->m_other_income->insert_journal($data_journal_credit);
                $this->trans_data['insert_journal']['data'][] = $data_journal_credit;
            }
        }


        $data_journal_debit = array(
            'OIncomeDate' => date("Y-m-d", strtotime($txt_payment_date)),
            'OIncomeNumber' => $txt_payment_no,
            'OInAccountNumber' => $cmb_bank_account,
            'OInSaldoDebet' => $txt_amount * $txt_rate,
            'OInSaldoCredit' => 0,
            'OInSignStatus' => 0,
            'OIncomeDesc' => $txa_memo,
            'AmountCurrency' => $txt_amount,
            'LastUser' => $this->session->userdata('username')
        );

        //$this->m_other_income->insert_journal($data_journal_debit);
        $this->trans_data['insert_journal']['data'][] = $data_journal_debit;
    }

    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');
                    $data['menu_label'] = $this->m_menu->get_menulabel($this->menu_id);
                    $data['menu_link'] = $this->m_menu->get_menulink($this->menu_id);

                    $sess_compay = $this->session->userdata('company');
                    $sess_branch = $this->session->userdata('branch');

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

                    $data['payment'] = $this->m_other_income->get_payment($other_number);
                    //$data['payment_detail'] 	= $this->m_other_income->get_payment_detail($other_number);
                    //$data['account_petty_cash']	= $this->load->m_other_income->account_petty_cash($sess_compay, $sess_branch);
                    //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/other_income/v_edit_other_income', $data);
                    $this->load->view('v_footer');
                    //----------------------end--------------------------------------------------------		
                }
            } else {
                redirect(base_url() . 'error', 'refresh');
            }
        } else {
            redirect(base_url() . 'login', 'refresh');
        }
    }

    public function update() {
        $txt_payment_no = $this->input->post('txt_payment_no');
        $txt_payment_date = $this->input->post('txt_payment_date');
        $cmb_bank_account = $this->input->post('cbg_bank');
        $txa_memo = $this->input->post('txa_memo');
        $txt_amount = $this->input->post('txt_amount');
        $branch_code = $this->session->userdata('branch');
        $user_code = $this->session->userdata("username");
        $txt_rate = $this->input->post('txt_rate');
        $txt_curr_code = $this->input->post('txt_curr_code');
        $cheque_number = $this->input->post('cheque_number');

        $detail = $this->input->post('detail');
        $detail = json_decode($detail);

        $detail_id = $this->input->post('detail_id');
        $detail_id = json_decode($detail_id);


        /* ======================== Fungsi update group ================================================== */
        $this->update_group($branch_code, $txt_payment_date, $txt_payment_no, $cmb_bank_account, $txa_memo, $txt_amount, $txt_rate, $txt_curr_code, $user_code,$cheque_number);

        /* ======================== Fungsi delete detail ================================================== */
        $this->delete_detail($detail_id);

        /* ======================== Fungsi delete journal ================================================== */
        //$this->m_other_income->delete_journal($txt_payment_no);
        $this->trans_data['delete_journal']['TransNumber'] = $txt_payment_no;

        /* ======================== Fungsi update detail ================================================== */
        $this->update_detail($detail);

        /* ======================== FUngsi Insert Journal ================================================== */
        $this->insert_journal($detail, $txt_payment_date, $txt_payment_no, $cmb_bank_account, $txt_amount, $txa_memo, $txt_rate, true);

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

        $this->trans_data = [];

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

        echo json_encode($result);
    }

    public function update_group($branch_code, $txt_payment_date, $txt_payment_no, $cmb_bank_account, $txa_memo, $txt_amount, $txt_rate, $txt_curr_code, $user_code,$cheque_number) {

        $data_group = array(
            'BranchCode' => $branch_code,
            'OIncomeDate' => date("Y-m-d", strtotime($txt_payment_date)),
            'OIncomeNumber' => $txt_payment_no,
            'BankPayment' => $cmb_bank_account,
            'OIncomeDesc' => $txa_memo,
            'OInTotalAmount' => $txt_amount,
            'CurrencyRate' => $txt_rate,
            'CurrencyCode' => $txt_curr_code,
            'ChequeNumber' => $cheque_number,
            'LastUser' => $user_code
        );

        //$this->m_other_income->update($data_group, $txt_payment_no);
        $this->trans_data['update_group']['data'] = $data_group;
        $this->trans_data['update_group']['TransNumber'] = $txt_payment_no;
    }

    public function delete_detail($detail_id) {
        $this->trans_data['delete_detail']['total'] = count($detail_id);
        if (count($detail_id) > 0) {
            for ($x = 0; $x < count($detail_id); $x++) {
                //$this->m_other_income->delete_detail_by_id($detail_id[$x]);
                $this->trans_data['delete_detail']['OIncomDetailID'][] = $detail_id[$x];
            }
        }
    }

    public function update_detail($detail) {
        if (count($detail) > 0) {
            foreach ($detail as $row_detail) {
                $AccountName = $row_detail->AccountName;
                $Amount = $row_detail->OIncomeAmount;
                $Memo = $row_detail->OIncomeMemo;

                $OIncomDetailID = $row_detail->OIncomDetailID;

                $AccountNumber = $this->m_other_income->get_accountnumber($AccountName);
                foreach ($AccountNumber as $acc_numb) {
                    $acc = $acc_numb->AccountNumber;
                }

                $data_detail = array(
                    //'OIncomeNumber' 	=> $txt_payment_no,
                    'OInAccountNumber' => $acc,
                    'OIncomeAmount' => $Amount,
                    'OIncomeMemo' => $Memo,
                    'LastUser' => $this->session->userdata('username')
                );

                //this->m_other_income->update_detail($data_detail, $OIncomDetailID);
                $this->trans_data['update_detail']['data'][] = $data_detail;
                $this->trans_data['update_detail']['OIncomDetailID'][] = $OIncomDetailID;
            }
        }
    }

    public function approved_dir() {

        if ($this->session->userdata("jobtitle_status") == 0) {
            $txt_payment_no = $this->input->post('txt_payment_no');

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

            //$this->m_other_income->update($data_approved,$txt_payment_no); 
            $this->trans_data['approve_data']['data'] = $data_approved;
            $this->trans_data['approve_data']['TransNumber'] = $txt_payment_no;

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

            $this->trans_data = [];

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

            echo json_encode($result);
        }
    }

    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('OIncomeNumber', $Number);
        }
        if ($Desc != "") {
            $this->db->like('OIncomeDesc', $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_otherincome.OIncomeDate >=', date("Y-m-d", strtotime($DateFrom)));
                $this->db->where('at_otherincome.OIncomeDate <=', date("Y-m-d", strtotime($DateTo)));
            }
        }
        /* ==========================end================================================================= */

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

        for ($i = 0; $i < count($result); $i++) {
            // kalau master ambil dari get_status_master(), kalau transaksi get_status()
            $TransStatus = get_status($result[$i]['PaymentStatus']);

            $hasil[] = array(
                'TransNumber' => $result[$i]['OIncomeNumber'],
                'CPayDate' => $result[$i]['OIncomeDate'],
                'CPayTotalAmount' => $result[$i]['OInTotalAmount'],
                'CPayDesc' => $result[$i]['OIncomeDesc'],
                'TransStatus' => $TransStatus,
                'BranchName' => $result[$i]['BranchName'],
                'OIncomeDate' => $result[$i]['OIncomeDate'],
                'AccountName' => $result[$i]['AccountName'],
                '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 trans_rollback($modus) {
        $this->db->trans_rollback();
        $result['status'] = false;

        if ($modus == 'approval') {
            $result['message'] = get_notification($modus, 0);
        } else {
            $result['message'] = get_notification_transaksi($this->name, $modus, 0);
        }

        echo json_encode($result);
        die();
    }

    function detail_payment($payment_number) {
        $uri4 = $this->uri->segment(4);
        $uri5 = $this->uri->segment(5);
        $uri6 = $this->uri->segment(6);
        $id = $uri4 . '/' . $uri5 . '/' . $uri6;

        $detail = $this->m_other_income->get_payment_detail($id);
        echo json_encode($detail);
    }

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

        // set data 
        $id = str_replace($data['menu_link'] . '/to_preview_journal/', "", $this->uri->uri_string());
        $data['detail'] = $this->m_other_income->get_detail($id);
        $data['list'] = $this->m_other_income->get_journal_by_number($id);
        //echo $this->db->last_query();
        $this->load->view('v_header');
        $this->load->view('cash_and_bank/other_income/v_journal_income', $data);
        $this->load->view('v_footer');
    }

    public function to_preview($obj_string = null) {
        $data['company'] = $this->m_other_income->get_company_by_branch($this->session->userdata('branch'));
        //$data['list']	 = $this->m_other_income->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_other_income->get_all_to_print($data_filter);
                
        $this->load->view('v_header');
        $this->load->view('cash_and_bank/other_income/v_preview_other_income', $data);
        $this->load->view('v_footer');
    }
    public function to_preview_LAMA($data_grid = null) {
        $data['company'] = $this->m_other_income->get_company_by_branch($this->session->userdata('branch'));
        //$data['list']	 = $this->m_other_income->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/other_income/v_preview_other_income', $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);
        $companyCode = $this->session->userdata('company');

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

        if ($id != "") {
            $data['detail'] = $this->m_other_income->get_detail_print($id);
            $data['list'] = $this->m_other_income->get_detail_item_print($data['detail']->OIncomeNumber);
            // echo $this->db->last_query();   
            $this->load->view('v_header');
            $this->load->view('cash_and_bank/other_income/v_print_detail_other_income', $data);
            $this->load->view('v_footer');
        }
    }

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

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

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

        $result_return = $this->m_other_income->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);
    }

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

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

        $arr_no = explode("/", $txt_payment_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_other_income->check_period_end($date_transaction);

        if ($check_period == false) {

            /* =============================update pettycash/ reverse =================================== */
            //$this->m_other_income->update_to_reverse_other_income($txt_payment_no,$data_reversed);

            /* ============================= delete reconcile =============================================== */
            //$this->m_other_income->delete_reconcile($txt_payment_no);

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

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

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

            $this->trans_data = [];

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

            echo json_encode($result);

            /* ============================= End Transac =================================== */
        } else {

            $result['status'] = false;
            $result['message'] = get_notification('reverse_in_period', 0);
            echo json_encode($result);
        }
    }

    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);
    }

}
