<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/* 	
 * 	Author 	: Fachri
 * 	Tanggal : 06-10-2014	
 * 	Revisi 	: Dhidhik, 24 Maret 2016, array in model system
 */

class Fixed_asset_selling extends CI_Controller {

    public $menu_id = 381;
    public $menu_model = 'm_fixed_asset_selling';
    public $name = "Selling Fixed Asset";

    public function __construct() {
        parent::__construct();
        $this->load->model('m_fixed_asset_selling');
        $this->load->model('m_account_journal');
        $this->load->helper('message_helper');
        $this->load->helper('convert_date_helper');
        $this->load->helper('custom_string_helper');
        $this->load->helper('status');
		$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 {
                    //untuk ambil data dari session dan hak akses
                    $group_menu = $this->session->userdata('group_menu');

                    $data['menu_id'] = $this->menu_id;
                    $data['menu_model'] = $this->menu_model;

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

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

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

    //Function Menampilkan Data Pada Data Grid View
    //function get data to grid
    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('FSNumber', $Number);
        } //change
        if ($Desc != "") {
            $this->db->like('FSDesc', $Desc);
        } //change
        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_fixed_asset_selling.FSDate >=', date("Y-m-d", strtotime($DateFrom))); //change
                $this->db->where('at_fixed_asset_selling.FSDate <=', date("Y-m-d", strtotime($DateTo))); //change
            }
        }
        /* ==========================end================================================================= */

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

        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]->FSNumber,
                'FSDate' => $result[$i]->FSDate,
                'FSDesc' => $result[$i]->FSDesc,
                'TotalAmount' => $result[$i]->TotalAmount,
                'TransStatus' => $TransStatus,
                'CreatedBy' => $result[$i]->CreatedBy
            );
        }

        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 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)
                     */
                    //untuk ambil data dari session dan hak akses
                    $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');

                    //panggil model hak akses untuk autoriti
                    $data['group_user'] = $this->m_menu->group_user_autority($this->menu_id, $group_menu);
                    $data['date_now'] = date('d-m-Y');
                    //$data['pay_number']  			= $this->m_payment->create_pay_number(date('d-m-Y'));
                    $this->load->view('v_header');
                    $this->load->view('fixed_asset_selling/v_add_fixed_asset_selling', $data);
                    $this->load->view('v_footer');
                }
            } else {
                redirect(base_url() . 'error', 'refresh');
            }
        } else {
            redirect(base_url() . 'login', 'refresh');
        }
    }

    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)
                     */
                    //untuk ambil data dari session dan hak akses
                    $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');

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

                    $data['detail'] = $this->m_fixed_asset_selling->get_edit_fixed_asset_selling($fs_number, $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('fixed_asset_selling/v_edit_fixed_asset_selling', $data);
                    $this->load->view('v_footer');
                }
            } else {
                redirect(base_url() . 'error', 'refresh');
            }
        } else {
            redirect(base_url() . 'login', 'refresh');
        }
    }

    public function insert() {
        try {
            $branch = $this->session->userdata('branch');
            $user = $this->session->userdata('username');
            $detail = $this->input->post('detail');
            $detail = json_decode($detail);
            $txt_date = date('Y-m-d', strtotime($this->input->post('txt_date')));

            /* ====================== create FSNumber ============================== */
            $FSNumber = $this->m_fixed_asset_selling->create_fs_number($txt_date);

            $acc_selling = $this->input->post('cmb_bank');
            $desc = $this->input->post('txa_description');
            $amount_average = $this->input->post('amount_average');
            $asset_price = $this->input->post('txt_asset_price');
            $acc_gl = $this->input->post('cmb_gl');
            $rate = $this->input->post('txt_rate');
            $currency_code = $this->input->post('txt_currency_code');
            $dataSend = [];
            $dataSend['insert_group'] = [];
            $dataSend['insert_detail'] = [];
            $dataSend['insert_journal'] = [];
            $dataSend['update_inv_details'] = [];
            /* ==================function insert group================================================ */
            $dataSend['insert_group'] = $this->insert_group($branch, $FSNumber, $txt_date, $acc_gl, $acc_selling, $desc, $currency_code, $rate, $amount_average, $asset_price, $user);
//            $this->m_fixed_asset_selling->insert_group($data_group);

            /* ==================function insert detail================================================ */
            $dataSend['insert_detail'] = $this->insert_detail($detail, $FSNumber, $user);
//            $this->m_fixed_asset_selling->insert_detail($detail_data);

            /* ==================function insert journal ================================================ */
            $dataSend['insert_journal'] = $this->insert_journal($branch, $detail, $FSNumber, $txt_date, $desc, $acc_gl, $acc_selling, $asset_price, $rate, $user, false);
//            $this->m_fixed_asset_selling->insert_journal($journal_data_gl);
//            $this->m_fixed_asset_selling->insert_journal($journal_data_acc);
//            $this->m_fixed_asset_selling->insert_journal($journal_data_inv);
//            $this->m_fixed_asset_selling->insert_journal($journal_data_selling);
//            $this->m_fixed_asset_selling->insert_journal($journal_data_revenue);

            /* ===================== update inv detail ========================================== */
            $dataSend['update_inv_details'] = $this->update_inv_detail($branch, $detail, 5);
//            $this->m_fixed_asset_selling->update_soldstatus($Arrassetcode,$data_invent);

            $rstDataSend = $this->m_fixed_asset_selling->datasend_fixedasset_selling_insert($dataSend);
            if ($rstDataSend) {
                $result['status'] = true;
                $result['message'] = get_notification_transaksi($this->name, 'insert', 1, $FSNumber);
            } else {
                $result['status'] = false;
                $result['message'] = get_notification_transaksi($this->name, 'insert', 0, $FSNumber);
            }
            echo json_encode($result);
        } catch (Exception $e) {
            $result['status'] = false;
            $result['message'] = $e->getMessage();
            echo json_encode($result);
        }
    }

    public function insert_LAMA() {

        $branch = $this->session->userdata('branch');
        $user = $this->session->userdata('username');
        $detail = $this->input->post('detail');
        $detail = json_decode($detail);
        $txt_date = date('Y-m-d', strtotime($this->input->post('txt_date')));

        /* ====================== create FSNumber ============================== */
        $FSNumber = $this->m_fixed_asset_selling->create_fs_number($txt_date);

        $acc_selling = $this->input->post('cmb_bank');
        $desc = $this->input->post('txa_description');
        $amount_average = $this->input->post('amount_average');
        $asset_price = $this->input->post('txt_asset_price');
        $acc_gl = $this->input->post('cmb_gl');
        $rate = $this->input->post('txt_rate');
        $currency_code = $this->input->post('txt_currency_code');



        /* ============================ begin transaction =============================== */
        $this->db->trans_begin();

        /* ==================function insert group================================================ */
        $this->insert_group($branch, $FSNumber, $txt_date, $acc_gl, $acc_selling, $desc, $currency_code, $rate, $amount_average, $asset_price, $user);

        /* ==================function insert detail================================================ */
        $this->insert_detail($detail, $FSNumber, $user);

        /* ==================function insert journal ================================================ */
        $this->insert_journal($branch, $detail, $FSNumber, $txt_date, $desc, $acc_gl, $acc_selling, $asset_price, $rate, $user);

        /* ===================== update inv detail ========================================== */
        $this->update_inv_detail($branch, $detail, 5);

        /* =============================trans roll back dan trans commit============================/ */
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $result['status'] = FALSE;
            $result['message'] = get_notification_transaksi($this->name, 'insert', 0, $FSNumber);
        } else {
            $this->db->trans_commit();
            $result['status'] = TRUE;
            $result['message'] = get_notification_transaksi($this->name, 'insert', 1, $FSNumber);
        }

        /* ==================================end transaction ====================================== */

        echo json_encode($result);
    }

    /* ======================================insert grroup=============================================================== */

    function insert_group($branch, $FSNumber, $txt_date, $acc_gl, $acc_selling, $desc, $currency_code, $rate, $amount_average, $asset_price, $user) {

        $data_group = array(
            'BranchCode' => $branch,
            'FSNumber' => $FSNumber,
            'FSDate' => $txt_date,
            'FSDesc' => $desc,
            'GLAccount' => $acc_gl,
            'SLAccount' => $acc_selling,
            'TotalAmount' => $amount_average,
            'AssetPrice' => $asset_price,
            'Rate' => $rate,
            'CurrencyCode' => $currency_code,
            'TransStatus' => 5,
            'CreatedBy' => $user,
            'CreatedAt' => date('Y-m-d H:i:s'),
            'LastUser' => $user
        );
        return $data_group;
//		$this->m_fixed_asset_selling->insert_group($data_group);//masuk ke model
    }

    /* ===================================end=============================================================================== */

    function update_group($branch, $FSNumber, $txt_date, $acc_gl, $acc_selling, $desc, $amount_average, $asset_price, $rate, $currency_code, $user) {

        $data_group = array(
            'BranchCode' => $branch,
            'FSDate' => $txt_date,
            'FSDesc' => $desc,
            'GLAccount' => $acc_gl,
            'SLAccount' => $acc_selling,
            'TotalAmount' => $amount_average,
            'AssetPrice' => $asset_price,
            'Rate' => $rate,
            'CurrencyCode' => $currency_code,
            'TransStatus' => 5,
            'CreatedBy' => $user,
            'CreatedAt' => date('Y-m-d'),
            'LastUser' => $user
        );
        return $data_group;
//		$this->m_fixed_asset_selling->update_group($data_group,$FSNumber);
    }

    /* ================================insert detail================================================= */

    function insert_detail($detail, $FSNumber, $user) {
        $dataRst = [];
        $dataRst['detail_data'] = [];

        foreach ($detail as $row) {
            $ItemCode = $row->ItemCode;
            $AccumAmount = $row->AccumAmount;
            $ReceiptNumber = $row->ReceiptNumber;
            $FixedAssetType = $row->FixedAssetType;
            $AssetCode = $row->AssetCode;
            $ItemAverage = $row->ItemAverage;

            $dataRst['detail_data'][] = array(
                'FSNumber' => $FSNumber,
                'ReceiptNumber' => $ReceiptNumber,
                'FixedAssetType' => $FixedAssetType,
                'AssetCode' => $AssetCode,
                'ItemCode' => $ItemCode,
                'FSAmount' => $AccumAmount === null ? 0 : $AccumAmount,
                'ItemAverage' => $ItemAverage,
                'LastUser' => $user,
                'ItemQty' => 1
            );

//			$this->m_fixed_asset_selling->insert_detail($detail_data);
        }
        return $dataRst;
    }

    /* ====================================end===================================================== */

    function insert_journal($branch, $detail, $FSNumber, $txt_date, $desc, $acc_gl, $acc_selling, $asset_price, $rate, $user, $status_approve) {
        $dataRst = [];
        $dataRst['journal_data_gl'] = [];
        $dataRst['journal_data_acc'] = [];
        $dataRst['journal_data_inv'] = [];
        $dataRst['journal_data_selling'] = [];
        $dataRst['journal_data_revenue'] = [];
        $branch = $this->session->userdata('branch');

        foreach ($detail as $row) {

            $ItemCode = $row->ItemCode;
            $AccumAmount = $row->AccumAmount;
            $ReceiptNumber = $row->ReceiptNumber;
            $FixedAssetType = $row->FixedAssetType;
            $AssetCode = $row->AssetCode;
            $ItemAverage = $row->ItemAverage;
            $ItemCategoryID = $row->ItemCategoryID;

            //$Amount_Accum 			= doubleval($ItemAverage) - doubleval($Amount_GL);

            /* ================== get accumulation account : expense and accumulation ====================== */
            $acc_asset = $this->m_fixed_asset_selling->get_fixed_asset_account($FixedAssetType);

            $accum_account = $acc_asset[0]['AccumAccountNumber'];
            // $exp_account 			= $acc_asset[0]['ExpenseAccountNumber'];

            /* =============================== get inventory account ========================================== */
            $InventoryAccount = $this->m_account_journal->get_cat_item_account('Inventory', $ItemCategoryID, 'IDR');

            /* ======================== journal gaint  or loss ====================== */

            $ItemAverageNew = $this->m_fixed_asset_selling->get_item_average($AssetCode, $branch);

            $AccumAmountNew         = $this->m_fixed_asset_selling->get_total_amount_period($branch, $AssetCode,$accum_account);

            $ItemAverage = $status_approve == true ? $ItemAverageNew : $ItemAverage;
            $AccumAmount = $status_approve == true ? $AccumAmountNew : $AccumAmount;

            if ($AccumAmount == 0) {

                /* ========================== revenue Credit selling journal ================================ */
                $dataRst['journal_data_revenue'][] = array(
                    'FSDate' => $txt_date,
                    'FSNumber' => $FSNumber,
                    'AssetCode' => $AssetCode,
                    'FSAccountNumber' => $acc_gl,
                    'FSSaldoDebet' => $ItemAverage,
                    'FSSaldoCredit' => 0,
                    'AmountCurrency' => $ItemAverage,
                    'FSSignStatus' => 1,
                    'FSDesc' => $desc,
                    'LastUser' => $user
                );

                /* ========================== inventory journal ================================ */
                $dataRst['journal_data_inv'][] = array(
                    'FSDate' => $txt_date,
                    'FSNumber' => $FSNumber,
                    'AssetCode' => $AssetCode,
                    'FSAccountNumber' => $InventoryAccount->AccountNumber,
                    'FSSaldoDebet' => 0,
                    'FSSaldoCredit' => $ItemAverage,
                    'AmountCurrency' => $ItemAverage,
                    'FSSignStatus' => 1,
                    'FSDesc' => $desc,
                    'LastUser' => $user
                );

                /* ========================== deposit selling journal ================================ */
                $dataRst['journal_data_selling'][] = array(
                    'FSDate' => $txt_date,
                    'FSNumber' => $FSNumber,
                    'AssetCode' => $AssetCode,
                    'FSAccountNumber' => $acc_selling,
                    'FSSaldoDebet' => ($asset_price * $rate),
                    'FSSaldoCredit' => 0,
                    'AmountCurrency' => $asset_price,
                    'FSSignStatus' => 0,
                    'FSDesc' => $desc,
                    'LastUser' => $user
                );


                /* ========================== revenue Credit selling journal ================================ */
                $dataRst['journal_data_revenue'][] = array(
                    'FSDate' => $txt_date,
                    'FSNumber' => $FSNumber,
                    'AssetCode' => $AssetCode,
                    'FSAccountNumber' => $acc_gl,
                    'FSSaldoDebet' => 0,
                    'FSSaldoCredit' => ($asset_price * $rate),
                    'AmountCurrency' => $asset_price,
                    'FSSignStatus' => 0,
                    'FSDesc' => $desc,
                    'LastUser' => $user
                );
            } else if ($AccumAmount > 0 and $AccumAmount < $ItemAverage) {
                /* ========================= accumulation journal =========================== */

                /* ========================== revenue Credit selling journal ================================ */
                $dataRst['journal_data_revenue'][] = array(
                    'FSDate' => $txt_date,
                    'FSNumber' => $FSNumber,
                    'AssetCode' => $AssetCode,
                    'FSAccountNumber' => $acc_gl,
                    'FSSaldoDebet' => doubleval($ItemAverage) - doubleval($AccumAmount),
                    'FSSaldoCredit' => 0,
                    'AmountCurrency' => doubleval($ItemAverage) - doubleval($AccumAmount),
                    'FSSignStatus' => 1,
                    'FSDesc' => $desc,
                    'LastUser' => $user
                );

                $dataRst['journal_data_acc'][] = array(
                    'FSDate' => $txt_date,
                    'FSNumber' => $FSNumber,
                    'AssetCode' => $AssetCode,
                    'FSAccountNumber' => $accum_account,
                    'FSSaldoDebet' => $AccumAmount,
                    'FSSaldoCredit' => 0,
                    'AmountCurrency' => $AccumAmount,
                    'FSSignStatus' => 1,
                    'FSDesc' => $desc,
                    'LastUser' => $user
                );

                /* ========================== inventory journal ================================ */
                $dataRst['journal_data_inv'][] = array(
                    'FSDate' => $txt_date,
                    'FSNumber' => $FSNumber,
                    'AssetCode' => $AssetCode,
                    'FSAccountNumber' => $InventoryAccount->AccountNumber,
                    'FSSaldoDebet' => 0,
                    'FSSaldoCredit' => doubleval($ItemAverage),
                    'AmountCurrency' => doubleval($ItemAverage),
                    'FSSignStatus' => 1,
                    'FSDesc' => $desc,
                    'LastUser' => $user
                );

                /* ========================== deposit selling journal ================================ */
                $dataRst['journal_data_selling'][] = array(
                    'FSDate' => $txt_date,
                    'FSNumber' => $FSNumber,
                    'AssetCode' => $AssetCode,
                    'FSAccountNumber' => $acc_selling,
                    'FSSaldoDebet' => ($asset_price * $rate),
                    'FSSaldoCredit' => 0,
                    'AmountCurrency' => $asset_price,
                    'FSSignStatus' => 0,
                    'FSDesc' => $desc,
                    'LastUser' => $user
                );


                /* ========================== revenue Credit selling journal ================================ */
                $dataRst['journal_data_revenue'][] = array(
                    'FSDate' => $txt_date,
                    'FSNumber' => $FSNumber,
                    'AssetCode' => $AssetCode,
                    'FSAccountNumber' => $acc_gl,
                    'FSSaldoDebet' => 0,
                    'FSSaldoCredit' => ($asset_price * $rate),
                    'AmountCurrency' => $asset_price,
                    'FSSignStatus' => 0,
                    'FSDesc' => $desc,
                    'LastUser' => $user
                );
            } else if (round(($AccumAmount - $ItemAverage), 4) == 0) {
                
                /* ========================= accumulation journal =========================== */
                $dataRst['journal_data_acc'][] = array(
                    'FSDate' => $txt_date,
                    'FSNumber' => $FSNumber,
                    'AssetCode' => $AssetCode,
                    'FSAccountNumber' => $accum_account,
                    'FSSaldoDebet' => $AccumAmount,
                    'FSSaldoCredit' => 0,
                    'AmountCurrency' => $AccumAmount,
                    'FSSignStatus' => 1,
                    'FSDesc' => $desc,
                    'LastUser' => $user
                );

                /* ========================== inventory journal ================================ */
                $dataRst['journal_data_inv'][] = array(
                    'FSDate' => $txt_date,
                    'FSNumber' => $FSNumber,
                    'AssetCode' => $AssetCode,
                    'FSAccountNumber' => $InventoryAccount->AccountNumber,
                    'FSSaldoDebet' => 0,
                    'FSSaldoCredit' => $ItemAverage,
                    'AmountCurrency' => $ItemAverage,
                    'FSSignStatus' => 1,
                    'FSDesc' => $desc,
                    'LastUser' => $user
                );

                /* ========================== deposit selling journal ================================ */
                $dataRst['journal_data_selling'][] = array(
                    'FSDate' => $txt_date,
                    'FSNumber' => $FSNumber,
                    'AssetCode' => $AssetCode,
                    'FSAccountNumber' => $acc_selling,
                    'FSSaldoDebet' => ($asset_price * $rate),
                    'FSSaldoCredit' => 0,
                    'AmountCurrency' => $asset_price,
                    'FSSignStatus' => 0,
                    'FSDesc' => $desc,
                    'LastUser' => $user
                );


                /* ========================== revenue Credit selling journal ================================ */
                $dataRst['journal_data_revenue'][] = array(
                    'FSDate' => $txt_date,
                    'FSNumber' => $FSNumber,
                    'AssetCode' => $AssetCode,
                    'FSAccountNumber' => $acc_gl,
                    'FSSaldoDebet' => 0,
                    'FSSaldoCredit' => ($asset_price * $rate),
                    'AmountCurrency' => $asset_price,
                    'FSSignStatus' => 0,
                    'FSDesc' => $desc,
                    'LastUser' => $user
                );
            }
        }

        return $dataRst;
    }

    function update_inv_detail($branch, $detail, $sold_status) {
        $dataRst = [];
        $dataRst['Arrassetcode'] = [];
        $dataRst['data_invent'] = array('SoldStatus' => $sold_status);

        foreach ($detail as $row) {
            $dataRst['Arrassetcode'][] = $row->AssetCode;
        }
        //$this->m_fixed_asset_selling->update_soldstatus($Arrassetcode,$data_invent);
        return $dataRst;
    }

    public function update() {
        try {
            $branch = $this->session->userdata('branch');
            $user = $this->session->userdata('username');
            $detail = $this->input->post('detail');
            $detail = json_decode($detail);
            $txt_date = date('Y-m-d', strtotime($this->input->post('txt_date')));

            /* ====================== create FSNumber ============================== */
            $FSNumber = $this->input->post('txt_fs_no');
            $acc_selling = $this->input->post('cmb_bank');
            $desc = $this->input->post('txa_description');
            $amount_average = $this->input->post('amount_average');
            $asset_price = $this->input->post('txt_asset_price');
            $acc_gl = $this->input->post('cmb_gl');
            $rate = $this->input->post('txt_rate');
            $currency_code = $this->input->post('txt_currency_code');

            $dataSend = [];
            $dataSend['update_group'] = [];
            $dataSend['insert_journal'] = [];
            $dataSend['FSNumber'] = $FSNumber;
            /* ==================function insert group================================================ */
            $dataSend['update_group'] = $this->update_group($branch, $FSNumber, $txt_date, $acc_gl, $acc_selling, $desc, $amount_average, $asset_price, $rate, $currency_code, $user);

            /* ==================function delete journal ================================================ */
//            $this->m_fixed_asset_selling->m_delete_journal($FSNumber);//masuk ke model

            /* ==================function insert journal ================================================ */
            $dataSend['insert_journal'] = $this->insert_journal($branch, $detail, $FSNumber, $txt_date, $desc, $acc_gl, $acc_selling, $asset_price, $rate, $user, false);

            $rstDataSend = $this->m_fixed_asset_selling->datasend_fixedasset_selling_update($dataSend);
            if ($rstDataSend) {
                $result['status'] = true;
                $result['message'] = get_notification_transaksi($this->name, 'update', 1, $FSNumber);
                ;
            } else {
                $result['status'] = false;
                $result['message'] = get_notification_transaksi($this->name, 'update', 0, $FSNumber);
                ;
            }

            echo json_encode($result);
        } catch (Exception $e) {
            $result['status'] = false;
            $result['message'] = $e->getMessage();
            echo json_encode($result);
        }
    }

    public function update_LAMA() {
        $branch = $this->session->userdata('branch');
        $user = $this->session->userdata('username');
        $detail = $this->input->post('detail');
        $detail = json_decode($detail);
        $txt_date = date('Y-m-d', strtotime($this->input->post('txt_date')));

        /* ====================== create FSNumber ============================== */
        $FSNumber = $this->input->post('txt_fs_no');

        $acc_selling = $this->input->post('cmb_bank');
        $desc = $this->input->post('txa_description');
        $amount_average = $this->input->post('amount_average');
        $asset_price = $this->input->post('txt_asset_price');
        $acc_gl = $this->input->post('cmb_gl');
        $rate = $this->input->post('txt_rate');
        $currency_code = $this->input->post('txt_currency_code');


        /* ============================ begin transaction =============================== */
        $this->db->trans_begin();

        /* ==================function insert group================================================ */
        $this->update_group($branch, $FSNumber, $txt_date, $acc_gl, $acc_selling, $desc, $amount_average, $asset_price, $rate, $currency_code, $user);

        /* ==================function delete journal ================================================ */
        $this->m_fixed_asset_selling->m_delete_journal($FSNumber);

        /* ==================function insert journal ================================================ */
        $this->insert_journal($branch, $detail, $FSNumber, $txt_date, $desc, $acc_gl, $acc_selling, $asset_price, $rate, $user);

        /* =============================trans roll back dan trans commit============================/ */
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $result['status'] = FALSE;
            $result['message'] = get_notification_transaksi($this->name, 'insert', 0, $FSNumber);
        } else {
            $this->db->trans_commit();
            $result['status'] = TRUE;
            $result['message'] = get_notification_transaksi($this->name, 'insert', 1, $FSNumber);
        }

        /* ==================================end transaction ====================================== */

        echo json_encode($result);
    }

    public function suspend_data() {
        try {
            $FSNumber = $this->input->post('id');
            $branch = $this->session->userdata('branch');
            $dataSend['data_suspend'] = [];
            $dataSend['data_invent'] = [];
            $dataSend['FSNumber'] = $FSNumber;
            $dataSend['arr_asset_code'] = "";

            $dataSend['data_suspend'] = array(
                'TransStatus' => 3,
                'LastUser' => $this->session->userdata('username')
            );

            $dataSend['data_invent'] = array(
                'SoldStatus' => 0
            );

            /* ===================== update fixed asset group to suspend ========================== */
//            $this->m_fixed_asset_selling->suspend_fixed_asset_selling($data_suspend,$FSNumber);//masuk ke model

            /* ============ get asset code from fixed asset selling by FSNumber ============================== */
            $arr_code = $this->m_fixed_asset_selling->get_asset_code_fixed_asset($FSNumber);
            $dataSend['arr_asset_code'] = $arr_code['arr_asset_code'];

//            $this->m_fixed_asset_selling->update_soldstatus($arr_code['arr_asset_code'],$data_invent);//masuk ke model

            $rstDataSend = $this->m_fixed_asset_selling->datasend_fixedasset_selling_suspend($dataSend);
            if ($rstDataSend) {
                $result['status'] = true;
                $result['message'] = get_notification('suspend', 1);
            } else {
                $result['status'] = false;
                $result['message'] = get_notification('suspend', 0);
            }
            echo json_encode($result);
        } catch (Exception $e) {
            $result['status'] = false;
            $result['message'] = $e->getMessage();
            echo json_encode($result);
        }
    }

    public function suspend_data_LAMA() {

        $FSNumber = $this->input->post('id');
        $branch = $this->session->userdata('branch');

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

        $data_invent = array(
            'SoldStatus' => 0
        );

        $this->db->trans_begin();

        /* ===================== update fixed asset group to suspend ========================== */
        $this->m_fixed_asset_selling->suspend_fixed_asset_selling($data_suspend, $FSNumber);

        /* ============ get asset code from fixed asset selling by FSNumber ============================== */
        $arr_code = $this->m_fixed_asset_selling->get_asset_code_fixed_asset($FSNumber);

        $this->m_fixed_asset_selling->update_soldstatus($arr_code['arr_asset_code'], $data_invent);

        /* =============================trans roll back dan trans commit============================/ */
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $result['status'] = false;
            $result['message'] = get_notification('suspend', 0);
        } else {
            $this->db->trans_commit();
            $result['status'] = true;
            $result['message'] = get_notification('suspend', 1);
        }
        /* ==================================end====================================================== */

        echo json_encode($result);
    }

    public function approved_dir() {
        try {
            $FSNumber = $this->input->post('id');
            $branch = $this->session->userdata('branch');
            $user = $this->session->userdata('username');
            $detail = $this->input->post('detail');
            $detail = json_decode($detail);
            $txt_date = date('Y-m-d', strtotime($this->input->post('txt_date')));

            /* ====================== create FSNumber ============================== */
            $FSNumber = $this->input->post('txt_fs_no');
            $acc_selling = $this->input->post('cmb_bank');
            $desc = $this->input->post('txa_description');
            $amount_average = $this->input->post('amount_average');
            $asset_price = $this->input->post('txt_asset_price');
            $acc_gl = $this->input->post('cmb_gl');
            $rate = $this->input->post('txt_rate');
            $currency_code = $this->input->post('txt_currency_code');


            $dataSend = [];
            $dataSend['data_approval'] = [];
            $dataSend['data_invent'] = [];
            $dataSend['FSNumber'] = $FSNumber;
            $dataSend['arr_asset_code'] = "";
            $dataSend['arr_item_code'] = "";

            $dataSend['data_approval'] = array(
                'AppLevel2Status' => 1,
                'AppLevel2Code' => $this->session->userdata('username'),
                'AppLevel2Date' => date('Y-m-d'),
                'TransStatus' => 2,
                'AppFinished' => 1,
                'LastUser' => $this->session->userdata('username')
            );

            $dataSend['data_invent'] = array(
                'SoldStatus' => 1,
                'ItemQTY' => 0,
                'Description' => 'Selling :' . date('d-m-Y')
            );

            /* ==================function insert journal ================================================ */
            $dataSend['insert_journal'] = $this->insert_journal($branch, $detail, $FSNumber, $txt_date, $desc, $acc_gl, $acc_selling, $asset_price, $rate, $user, true);

            /* ============ get asset code from fixed asset selling by FSNumber ============================== */
            $arr_code = $this->m_fixed_asset_selling->get_asset_code_fixed_asset($FSNumber);
            $dataSend['arr_asset_code'] = $arr_code['arr_asset_code'];
            $dataSend['arr_item_code'] = $arr_code['arr_item_code'];
            $dataSend['arr_item_average'] = $arr_code['arr_item_average'];

            $rstDataSend = $this->m_fixed_asset_selling->datasend_fixedasset_selling_app_dir($dataSend);
            if ($rstDataSend) {
                $result['status'] = true;
                $result['message'] = get_notification('approval', 1);
            } else {
                $result['status'] = false;
                $result['message'] = get_notification('approval', 0);
            }
            echo json_encode($result);
        } catch (Exception $e) {
            $result['status'] = false;
            $result['message'] = $e->getMessage();
            echo json_encode($result);
        }
    }

    public function approved_dir_LAMA() {

        $FSNumber = $this->input->post('id');
        $branch = $this->session->userdata('branch');

        $data_approval = array(
            'AppLevel2Status' => 1,
            'AppLevel2Code' => $this->session->userdata('username'),
            'AppLevel2Date' => date('Y-m-d'),
            'TransStatus' => 2,
            'AppFinished' => 1,
            'LastUser' => $this->session->userdata('username')
        );

        $data_invent = array(
            'SoldStatus' => 1,
            'ItemQTY' => 0,
            'Description' => 'Selling :' . date('d-m-Y')
        );

        /* ======================== begin transaction ====================================== */
        $this->db->trans_begin();

        /* ===================== update fixed asset group to approve ========================== */
        $this->m_fixed_asset_selling->approval_fixed_asset_selling($data_approval, $FSNumber);

        /* ============ get asset code from fixed asset selling by FSNumber ============================== */
        $arr_code = $this->m_fixed_asset_selling->get_asset_code_fixed_asset($FSNumber);

        $this->m_fixed_asset_selling->update_soldstatus($arr_code['arr_asset_code'], $data_invent);

        /* =========================== update inventories qty  =============================== */
        $this->m_fixed_asset_selling->update_quantity_inventory($arr_code['arr_item_code']);

        /* =========================== update inventories value  =============================== */
        $this->m_fixed_asset_selling->update_value_inventory($arr_code['arr_item_code']);

        /* =============================trans roll back dan trans commit============================/ */
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $result['status'] = false;
            $result['message'] = get_notification('approval', 0);
        } else {
            $this->db->trans_commit();
            $result['status'] = true;
            $result['message'] = get_notification('approval', 1);
        }
        /* ==================================end====================================================== */
        echo json_encode($result);
    }

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

    public function reversed_data() {
        try {
            /* ===================================Deklarasi Variabel untuk proses insert atau update=================================== */
            $FSNumber = $this->input->post('id');
            $arr_no = explode("/", $FSNumber);
            $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;
            $dataSend = [];
            $dataSend['data_reverse'] = [];
            $dataSend['data_invent'] = [];
            $dataSend['FSNumber'] = $FSNumber;
            $dataSend['arr_asset_code'] = "";
            $dataSend['arr_item_code'] = "";

            $dataSend['data_reverse'] = array("TransStatus" => 5, "AppFinished" => 0);
            $dataSend['data_invent'] = array('SoldStatus' => 5, 'ItemQTY' => 1, 'Description' => '');

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

            if ($check_period == false) {


                /* ============ get asset code from fixed asset selling by FSNumber ============================== */
                $arr_code = $this->m_fixed_asset_selling->get_asset_code_fixed_asset($FSNumber);
                $dataSend['arr_asset_code'] = $arr_code['arr_asset_code'];
                $dataSend['arr_item_code'] = $arr_code['arr_item_code'];
                $dataSend['arr_item_average'] = $arr_code['arr_item_average'];


                $rstDataSend = $this->m_fixed_asset_selling->datasend_fixedasset_selling_reverse($dataSend);
                if ($rstDataSend) {
                    $result['status'] = true;
                    $result['message'] = get_notification_transaksi($this->name, 'reverse', 1, $FSNumber);
                } else {
                    $result['status'] = false;
                    $result['message'] = get_notification_transaksi($this->name, 'reverse', 0, $FSNumber);
                }
                echo json_encode($result);
            } else {
                throw new Exception(get_notification('reverse_in_period', 0));
            }
        } catch (Exception $e) {
            $result['status'] = false;
            $result['message'] = $e->getMessage();
            echo json_encode($result);
        }
    }

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

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

        $date_transaction = $year_transaction . $month_transaction;

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

        $data_invent = array('SoldStatus' => 5, 'ItemQTY' => 1, 'Description' => '');


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

        if ($check_period == false) {

            /* =============================Transac begin =================================== */
            $this->db->trans_begin();

            /* =============================update fixed asset/ reverse =================================== */
            $this->m_fixed_asset_selling->update_to_reverse_fixed_asset($FSNumber, $data);

            /* ============================= delete reconcile =============================================== */
            $this->m_fixed_asset_selling->delete_reconcile($FSNumber);

            /* ============ get asset code from fixed asset selling by FSNumber ============================== */
            $arr_code = $this->m_fixed_asset_selling->get_asset_code_fixed_asset($FSNumber);

            $this->m_fixed_asset_selling->update_soldstatus($arr_code['arr_asset_code'], $data_invent);

            /* =========================== update inventories qty + 1 =============================== */
            $this->m_fixed_asset_selling->update_inventory_plus($arr_code['arr_item_code']);

            /* =========================== update inventories value  =============================== */
            $this->m_fixed_asset_selling->update_value_inventory($arr_code['arr_item_code']);

            /* =========================== update inventories item average =============================== */
            $this->m_fixed_asset_selling->update_inventory_average($arr_code['arr_item_code']);


            if ($this->db->trans_status() === TRUE) {
                $this->db->trans_commit();
                $result['status'] = true;
                $result['message'] = get_notification_transaksi($this->name, 'reverse', 1, $FSNumber);
            } else {
                $this->db->trans_rollback();
                $result['status'] = false;
                $result['message'] = get_notification_transaksi($this->name, 'reverse', 0, $FSNumber);
            }
            /* ============================= End Transac =================================== */
        } else {
            $result['status'] = false;
            $result['message'] = get_notification('reverse_in_period', 0);
        }

        echo json_encode($result);
    }

    public function to_preview($obj_string=null) {
        $data['company'] = $this->m_fixed_asset_selling->get_company_by_branch($this->session->userdata('branch'));
//        $data['list'] = $this->m_fixed_asset_selling->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_fixed_asset_selling->get_all_to_print($data_filter);
        
        $this->load->view('v_header');
        $this->load->view('fixed_asset_selling/v_print_fixed_asset_selling', $data);
        $this->load->view('v_footer');
    }
    public function to_preview_LAMA() {
        $data['company'] = $this->m_fixed_asset_selling->get_company_by_branch($this->session->userdata('branch'));
        $data['list'] = $this->m_fixed_asset_selling->get_all_to_print($this->session->userdata('branch'));

        $this->load->view('v_header');
        $this->load->view('fixed_asset_selling/v_print_fixed_asset_selling', $data);
        $this->load->view('v_footer');
    }

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

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

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

        $data['detail'] = $this->m_fixed_asset_selling->get_detail_journal($FSNumber);
        // echo $this->db->last_query();

        $list = $this->m_fixed_asset_selling->get_list_journal($branch, $FSNumber);

        $arr_list = array();
        $ind_arr = 0;
        $ind_arr_1 = 0;
        foreach ($list as $row) {

            $AssetCode = $row->AssetCode;
            $FSAccountNumber = $row->FSAccountNumber;
            $AccountName = $row->AccountName;
            $FSSaldoDebet = $row->FSSaldoDebet;
            $FSSaldoCredit = $row->FSSaldoCredit;
            $AmountCurrency = $row->AmountCurrency;

            if (count($arr_list) == 0) {
                $arr_list[0] = array('AssetCode' => $AssetCode,
                    'list' => array(
                        array(
                            'FSAccountNumber' => $FSAccountNumber,
                            'AccountName' => $AccountName,
                            'FSSaldoDebet' => $FSSaldoDebet,
                            'FSSaldoCredit' => $FSSaldoCredit,
                            'AmountCurrency' => $AmountCurrency)));
            } else {

                if ($AssetCode == $arr_list[$ind_arr]['AssetCode']) {

                    $ind_arr_1 += 1;
                    $arr_list[$ind_arr]['list'][$ind_arr_1] = array(
                        'FSAccountNumber' => $FSAccountNumber,
                        'AccountName' => $AccountName,
                        'FSSaldoDebet' => $FSSaldoDebet,
                        'FSSaldoCredit' => $FSSaldoCredit,
                        'AmountCurrency' => $AmountCurrency);
                } else {

                    $ind_arr += 1;
                    $ind_arr_1 = 0;
                    $arr_list[$ind_arr] = array('AssetCode' => $AssetCode,
                        'list' => array(
                            array(
                                'FSAccountNumber' => $FSAccountNumber,
                                'AccountName' => $AccountName,
                                'FSSaldoDebet' => $FSSaldoDebet,
                                'FSSaldoCredit' => $FSSaldoCredit,
                                'AmountCurrency' => $AmountCurrency)));
                }
            }
        }

        $data['list'] = $arr_list;

        $this->load->view('v_header');
        $this->load->view('fixed_asset_selling/v_journal_fixed_asset_selling', $data);
        $this->load->view('v_footer');
    }

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

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

        if ($FSNumber != "") {

            $data['detail'] = $this->m_fixed_asset_selling->get_detail_print($FSNumber);
            $data['list'] = $this->m_fixed_asset_selling->get_detail_item_print($FSNumber);

            $this->load->view('v_header');
            $this->load->view('fixed_asset_selling/v_print_detail_fixed_asset_selling', $data);
            $this->load->view('v_footer');
        }
    }

    public function get_fixed_asset() {
        $branch = $this->session->userdata('branch');
        $fixed_asset = $this->m_fixed_asset_selling->get_fixed_asset($branch);
        // echo $this->db->last_query();
        // die();

        $arrData = array();

        foreach ($fixed_asset as $row) {

            $fixed_asset_account    = $this->m_fixed_asset_selling->get_fixed_asset_account_period($row->FixedAssetType);
            $AccumAccount           = $fixed_asset_account->AccumAccountNumber;
            $AccumAmount            = $this->m_fixed_asset_selling->get_total_amount_period($branch, $row->AssetCode,$AccumAccount);

            $arrData[] = array(
                'ReceiptNumber' => $row->ReceiptNumber,
                'ReceiptDate' => $row->ReceiptDate,
                'ItemCode' => $row->ItemCode,
                'ItemAverage' => $row->ItemAverage,
                'ItemAverageHidden' => $row->ItemAverage,
                'AssetCode' => $row->AssetCode,
                'FixedAssetType' => $row->FixedAssetType,
                'ItemDesc' => $row->ItemDesc,
                'ItemQty' => $row->ItemQty,
                'ItemCategoryID' => $row->ItemCategoryID,
                'AccumAmount' => $AccumAmount,
                'AccumAmountHidden' => $AccumAmount);
        }

        echo json_encode($arrData);
    }

    public function get_fixed_asset_approve($arrAssetCode) {
        $branch = $this->session->userdata('branch');
        $fixed_asset = $this->m_fixed_asset_selling->get_fixed_asset($branch);
        // echo $this->db->last_query();
        // die();

        $arrData = array();

        foreach ($fixed_asset as $row) {

            $arrData[] = array(
                'ReceiptNumber' => $row->ReceiptNumber,
                'ReceiptDate' => $row->ReceiptDate,
                'ItemCode' => $row->ItemCode,
                'ItemAverage' => $row->ItemAverage,
                'AssetCode' => $row->AssetCode,
                'FixedAssetType' => $row->FixedAssetType,
                'ItemDesc' => $row->ItemDesc,
                'ItemQty' => $row->ItemQty,
                'ItemCategoryID' => $row->ItemCategoryID,
                'AccumAmount' => $this->m_fixed_asset_selling->get_total_amount_period($branch, $row->AssetCode));
        }

        return $arrData;
    }

    public function get_gl_account() {
        $branch = $this->session->userdata('branch');
        $gl_account = $this->m_fixed_asset_selling->m_get_gl_account($branch);
        echo json_encode($gl_account);
    }

    public function get_selling_account() {
        $branch = $this->session->userdata('branch');
        $sel_account = $this->m_fixed_asset_selling->m_get_selling_account($branch);
        echo json_encode($sel_account);
    }

    public function get_bank_account() {
        $branch = $this->session->userdata('branch');
        $sel_account = $this->m_fixed_asset_selling->m_get_bank_account($branch);
        echo json_encode($sel_account);
    }

    public function get_detail_fixed_asset($FDNumber) {
        $branch = $this->session->userdata('branch');

        $FDNumber = str_replace('slash', '/', $FDNumber);
        $FDNumber = str_replace('_', '-', $FDNumber);

        $fixed_asset_detail = $this->m_fixed_asset_selling->get_fixed_asset_detail($branch, $FDNumber);

        echo json_encode($fixed_asset_detail);
    }

}
