<!---- 
    Author 	: Wahyu
    Tanggal : 16-10-2014	
    Revisi 	:
-->
<?php
//---------Untuk privellege jika dia ada tombol save,suspen,jurnal----------
	if($group_user->SavePrivillage == 1){
		$cek_autority_save  = "";
	}
	else{
		$cek_autority_save 	= "disabled";
	}
	
	if($group_user->JournalPrivillage == 1){
		$cek_autority_journal  = "";
	}
	else{
		$cek_autority_journal 	= "disabled";
	}
	
	if($group_user->DeletePrivillage == 1){
		$cek_autority_delete  = "";
	}
	else{
		$cek_autority_delete 	= "disabled";
	}

    if($group_user->ReversePrivillage == 1){
        $cek_autority_reverse  = "";
    }
    else{
        $cek_autority_reverse    = "display:none";
    }
//-------------end----------------------------
?>
<div class="easyui-layout" data-options="fit:true,border:false">
	<!-- Top view-->
    <div id="form-header" data-options="region:'north',border:false" >
        <div id="form-header-wrapper">
            <table cellpadding="0" cellspacing="0" width="100%" height="100%" border="0">
            <tr>
                <td align="left">
                    <input type="checkbox" name="chk_suspended" id="chk_suspended" value="3" onClick="suspend_transaction(1,'<?=$menu_link?>',$('#txt_exp_cashbon_no').val(),'Expense Cash-Bon')" style="margin-top:0px;margin-right:1px;" <?=(!in_array($detail->TransStatus,array(4,6))) ? 'disabled' : ''?> <?=(in_array($detail->TransStatus,array(3,9))) ? 'checked' : ''?> <?php echo $cek_autority_delete;?>/>
                    <span style="display:inline-block;margin-top:2px;<?=(($detail->TransStatus!=3)?'color:black;':'color:gray')?>">Suspend</span>
                    <a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-currency" onclick="app_payment()" <?=(in_array($detail->TransStatus,array(1)))?'':'disabled'?>>To Payment</a>
                    
                    <a href="#" class="easyui-linkbutton" iconCls="icon-journal" plain="true" onClick="parent.tab_edit('Print Journal', '<?php echo $menu_link; ?>', 'icon-journal', 'to_preview_detail','<?php echo $id = str_replace("/",".", $detail->EBonNumber); ?>')" <?php echo $cek_autority_journal;?>>Journal</a>
                    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="location.reload()">Refresh</a>
                </td>
                <td align="center" width="40%"><span id="approval_information">
                <?php
                if($detail->TransStatus == 4){
                    echo get_status_approval_header($detail->TransStatus);
                }
                ?>
                </span></td>
                <td height="25" align="right" valign="middle">
                    <span class="form-title" style="margin-left:7px;">
                        <?=$menu_label?>
                    </span>
                </td>
            </tr>
            </table>		     	
        </div>			
    </div>
    <!-- End of top view -->
    <?php 
		if($detail->TransStatus ==3 || $detail->TransStatus ==2 || $detail->TransStatus == 1){ 
			$readonly 		= "readonly";
			$disabled 		= "disabled";
		} 
		else { 
			$readonly 		= "";
			$disabled 		= "";
		} 
	?>
    <div id="form-body" data-options="region:'center',border:false">
    <?php if($detail->TransStatus == 2):?>
        <div class="blanket"></div>
        <div class="finished-box"><b>Finished</b></div>
    <?php elseif($detail->TransStatus == 3): ?>
    	 <div class="blanket"></div>
         <div class="suspend-box"><b>Suspended</b></div>
     <?php elseif($detail->TransStatus == 1): ?>
         <div class="blanket"></div>
         <div class="cancel-box"><b>On Progress</b></div>
	<?php endif;?>
         <div id="form-wrapper" class="easyui-panel" style="padding:5px;" fit="true">
        	<form id="fm_purchase_expense_cashbon" name="fm_purchase_expense_cashbon" method="post" action="<?php echo base_url(); ?><?php echo"activities/purchase_expense_cashbon/insert"; ?>">
                <input type="hidden" id="detail_expense_cashbon" name="detail_expense_cashbon" />
                <input type="hidden" id="bank_number" name="bank_number"  value="<?php echo $detail->BankPayment ?>"/>
                <input type="hidden" id="currency_code" name="currency_code" value="<?php echo $detail->CurrencyCode ?>"/>
                <input type="hidden" id="kategoriid" name="kategoriid" />
                <!-- Form Header -->
                <table width="100%" height="141" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="50%" valign="top">
                    	<table width="100%" cellpadding="0" cellspacing="1" style="margin-top:4px;">
                        <tr>
                        	<td width="120"><b>Department</b></td>
                            <td width="10"><b>:</b></td>
                            <td>
                            	<select name="cmb_departement" class="combo-grid" editable="false"  
                                    id="cmb_departement" required="required" 
                                    style="width:302px;height:22px;" readonly
                                    data-options="
                                        value:'<?= $detail->DepartmentCode; ?>', 
                                        panelWidth: 302,
                                        idField: 'DepartmentCode',
                                        textField: 'DepartmentName',
                                        url: '<?= base_url().$menu_link; ?>/get_department_edit/<?= $detail->DepartmentCode; ?>',                
                                        columns: [[
                                            {field:'DepartmentCode',title:'Departement Code',width:110},
                                            {field:'DepartmentName',title:'Departement Name',width:190}
                                        ]],
                                        fitColumns: true,
                                        onSelect: function(rowIndex, rowData){  
                                            var DepCode = rowData.DepartmentCode;
                                            $('#cmb_employee').combogrid({
                                                delay: 300,
                                                url: '<?= base_url().$menu_link; ?>/get_employee/'+DepCode,
                                                idField: 'EmployeeCode',
                                                textField: 'EmployeeName',
                                                columns: [[
                                                    {field:'EmployeeCode',title:'EmployeeCode',width:120,sortable:true},
                                                    {field:'EmployeeName',title:'EmployeeName',width:400,sortable:true}
                                                ]]
                                            });
                                        }
                                    "
                                >
                                </select>
                            </td>
                        </tr>
                        <tr>
                        	<td><b>Employee</b></td>
                            <td><b>:</b></td>
                            <td>
                            	<select name="cmb_employee" class="combo-grid" editable="true"  
                                    id="cmb_employee" required="required" 
                                    style="width:301px; height:20px;" <?= $readonly;?>
                                    data-options="
                                        value:'<?=  $detail->EmployeeCode; ?>', 
                                        panelWidth: 300,
                                        idField: 'EmployeeCode',
                                        textField: 'EmployeeName',
                                        url: '<?= base_url(); ?><?= $menu_link; ?>/get_employee_edit/<?= $detail->DepartmentCode; ?>/<?= $detail->BranchCode; ?>',              
                                        columns: [[
                                        {field:'EmployeeCode',title:'Employee Code',width:110},
                                        {field:'EmployeeName',title:'Employee Name',width:190}
                                        ]],
                                        fitColumns: true,
                                        onSelect:function(){
                                            $('.app-button').linkbutton('disable');
                                        }
                                    "
                                >
                                </select>
                            </td>
                        </tr>
                        </table>
                    </td>
                    <td width="50%" valign="top">
                        <table width="100%" cellpadding="0" cellspacing="1" style="margin-top:4px;">
                        <tr>
                        	<td width="200" rowspan="2">&nbsp;</td>
                        	<td width="140"><b>Exp. Cash-Bon No.</b></td>
                            <td width="10"><b>:</b></td>
                            <td>
                            	<input type="text" name="txt_exp_cashbon_no" id="txt_exp_cashbon_no" class="easyui-validatebox disabled" required="true" value="<?php echo $detail->EBonNumber ?>"  style="width:300px;" readonly />
                            </td>
                        </tr>
                        <tr>
                        	<td width="200"><b>Exp. Cash-Bon Date</b></td>
                            <td><b>:</b></td>
                            <td>
                            	<input name="txt_cashbon_date" id="txt_cashbon_date" <?= $readonly;?> type="text" class="easyui-datebox validBackward" required="required" style="width:302px;height:22px" editable="false" readonly="readonly"/>
                            </td>
                        </tr>
                        </table>
                    </td>
                </tr>
                <tr><td colspan="2"><hr/></td></tr>
                <tr>
                    <td width="50%" valign="top">
                    	<table width="100%" cellpadding="0" cellspacing="1" style="margin-top:4px;">
                        <tr>
                        	<td width="120"><b>Bank</b></td>
                            <td width="10"><b>:</b></td>
                            <td>
                            	<select name="cmb_bank" class="combo-grid" editable="true"  
                                    id="cmb_bank" required="required" 
                                    style="width:302px;height:22px;" <?= $readonly;?>
                                    data-options="
                                        value:'<?= $detail->BankPayment; ?>', 
                                        panelWidth: 302,
                                        idField: 'AccountNumber',
                                        textField: 'AccountName',
                                        url: '<?= base_url().$menu_link; ?>/get_akun',               
                                        columns: [[                  
                                            {field:'AccountName',title:'Account Name',width:190}
                                        ]],
                                        fitColumns: true,
                                        onSelect: function(rowIndex, rowData){  
                                            var AccountNumber = rowData.AccountNumber;

                                            /*==================== clear grid ============================*/
                                            $('#dtg_expensecashbon').datagrid('loadData', {'total':0,'rows':[]});
            
                                            $.ajax({
                                                type: 'POST',
                                                dataType: 'html',
                                                url: '<?= base_url().$menu_link; ?>/get_rate_currency',
                                                data: $.param({ AccountNumber:AccountNumber}),
                                                success: function(data){
                                                    $('#txt_rate').numberbox('setValue',1);
                                                     if(rowData.CurrencyCode == 'IDR'){
                                                        $('#txt_rate').prop('readonly',true);
                                                        $('#txt_rate').numberbox({
                                                            min:1,
                                                        });
                                                    }else{
                                                        $('#txt_rate').prop('readonly',false);
                                                        $('#txt_rate').numberbox({
                                                            min:0.0001,
                                                        });
                                                    }

                                                    /*=============== get data options fields ExpCategoryID ============*/
                                                    var opts = $('#dtg_expensecashbon').datagrid('getColumnOption','ExpCategoryName');

                                                    /*========================== set value url  ==============================*/
                                                    urlAccount = '<?= base_url().$menu_link;?>/cashbon_account/'+rowData.CurrencyCode,
                                                    opts.editor.options.url = urlAccount;

                                                    /*=============== add row for transaction ============================*/
                                                    $('#dtg_expensecashbon').edatagrid('addRow');
                                                }
                                            });

                                            get_master_rate(rowData.CurrencyCode);
                                            get_bank_balance(AccountNumber,rowData.CurrencyCode);
                                            
                                            $('.app-button').linkbutton('disable');
                                            
                                            $('#txt_amountRp').numberbox('setValue',0);
                                            $('#txt_amount').numberbox('setValue',0);
                                            
                                            $('#curren_code').text(rowData.CurrencyCode);
                                            $('#curren_code_grid').text(rowData.CurrencyCode);
                                            $('#curren_code_grid_amount').text(rowData.CurrencyCode);
                                            $('#currency_code').val(rowData.CurrencyCode);
                                        }
                                    "
                                >
                                </select>
                            </td>
                        </tr>
                        <tr>
                        	<td><b>Rate</b></td>
                            <td><b>:</b></td>
                            <td>
                            	<input type="text" style="width:218px;"  <?php echo $readonly;?> name="txt_rate" id="txt_rate" class="easyui-numberbox" data-options="min:0.01,precision:2,decimalSeparator:',',groupSeparator:'.'" value="<?php echo $detail->CurrencyRate; ?>" required="true" /> Currency <span id="curren_code"></span> TO IDR
                            </td>
                        </tr>
                        <tr>
                        	<td valign="top" style="padding-top:4px"><b>Description</b></td>
                            <td valign="top" style="padding-top:4px"><b>:</b></td>
                            <td>
                            	<textarea class="textbox" <?php echo $readonly;?> style="resize:none;width:300px;white-space:normal;" name="txa_description" id="txa_description" rows="4"><?php echo $detail->EBonDesc ?></textarea>
                            </td>
                        </tr>
                        <!--<tr>
                        	<td><b>Amount (<span id="curren_code_grid_amount"></span>)</b></td>
                            <td><b>:</b></td>
                            <td>-->
                            	<input name="txt_amount" id="txt_amount"  type="hidden"  class="easyui-numberbox" data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" value="<?php echo"$amount_cashbon"; ?>" style="width:100px;height:18px" required="required" />
								<input name="txt_amountRp" id="txt_amountRp" type="hidden" class="easyui-numberbox" data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" value="<?php echo"$amount_cashbon"; ?>" style="width:270px;height:18px" required="required" readonly/>
								<!--<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-calculator',size:'small'" onClick="setAmount()" <?php echo $disabled;?>></a>-->
                            <!--</td>
                        </tr>-->
                        </table>
                    </td>
                    <td width="50%" valign="top">
                        <table width="100%" cellpadding="0" cellspacing="1" style="margin-top:4px;">
                        <tr>
                        	<td width="200" rowspan="3">&nbsp;</td>
                        	<td width="140"><b>Cheque No.</b></td>
                            <td width="10"><b>:</b></td>
                            <td>
                            	<input type="text" name="txtcheque_no" id="txtcheque_no" class="easyui-validatebox" value="<?php echo $detail->ChequeNumber ?>" style="width:300px" <?php echo $readonly;?>/>
                            </td>
                        </tr>
                        <!--<tr>
                        	<td><b>Cheque Date</b></td>
                            <td><b>:</b></td>
                            <td>
                            	<input name="txt_cheque_date" id="txt_cheque_date" type="text" class="easyui-datebox validBackward" required="required" style="width:302px;height:22px" />
                            </td>
                        </tr>-->
                        <tr>
                        	<td width="200"><b>Cheque Amount</b></td>
                            <td><b>:</b></td>
                            <td>
                            	<input type="text" name="txt_cheque_amount" id="txt_cheque_amount" data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" class="easyui-numberbox" value="<?php echo $detail->ChequeAmount ?>" style="width:300px;text-align:right" <?php echo $readonly;?>/>
                            </td>
                        </tr>

                         <tr>
                            <td width="200"><b>Available Balance (<span class='bank_balance_currency'><?=$detail->CurrencyCode?></span>)</b></td>
                            <td><b>:</b></td>
                            <td>
                                <input type="text" name="txt_bank_balance" id="txt_bank_balance" data-options="precision:2,decimalSeparator:',',groupSeparator:'.'" class="easyui-numberbox" style="width:300px;text-align:right" readonly/>
                            </td>
                        </tr>
                        </table>
                    </td>
                </tr>
                </table>
                <!-- End of form header -->
                
                <!-- Datagrid -->
				<div class="easyui-tabs" style="height:auto; margin-top:5px" data-options="tabHeight:18">
					<div id="tab_general" title="Items">
                        <table id="dtg_expensecashbon" class="easyui-<?=(in_array($detail->TransStatus,array(0,1,2)))?'datagrid':'edatagrid'?>" url="<?php echo base_url(); ?><?php echo $menu_link; ?>/ajax_detail_item/<?php echo $id = str_replace("/",".", $detail->EBonNumber); ?>" toolbar="#tb_dtg_payment" 
							idField="id"
							rownumbers="true" fitColumns="true" singleSelect="true" style="height:290px;"
                            data-options="
                                    onBeforeLoad:function(){
                                        //$('#dtg_expensecashbon').datagrid('loadData', {'total':0,'rows':[]});
                                    },
                                    onBeginEdit:function(rowIndex){
                                        editors = $('#dtg_expensecashbon').datagrid('getEditors',rowIndex);
                                        EBonAmount      = $(editors[1].target);
                                        //EBonMemo      = $(editors[1].target);
                                    
                                        EBonAmount.numberbox({
                                            onChange:function(){
                                                var amount =  EBonAmount.numberbox('getValue');
                                                $('#txt_amountRp').numberbox('setValue',amount);
                                                $('#txt_amount').numberbox('setValue',amount);
                                            }
                                        });

                                         /*====================on beg in edit saat grid di klik maka tombol save disable===================*/
                                        save_button_begendedit('<?=$group_user->SavePrivillage;?>');
                                        /*=================================end============================================================*/
                                    },
                                    onEndEdit:function(indexRow,row,changes){
                                        /*====================on beg in edit saat grid di klik maka tombol save disable===================*/
                                        save_button_endedit('<?=$group_user->SavePrivillage;?>');
                                        /*=================================end============================================================*/
                                    },
                                    onLoadSuccess:function(data){
                                        if(cek_grid == 0){
                                            // alert(JSON.stringify(data.rows));
                                            $('#kategoriid').val(data.rows[0]['ExpCategoryID']);
                                            
                                            cek_grid = 1;
                                        }
                                    }
                                "
                            >
							<thead>
									<th align="center" valign="middle" data-options="
                                    field:'ExpCategoryName', width:120,align:'center',
                                    editor:{
                                        type:'combobox',
                                        options:{
                                        	value :'<?= $detail->EBonAccountNumber;?>',
                                            valueField:'ExpCategoryName',
                                            textField:'ExpCategoryName',
                                            url:'<?=base_url() . $menu_link?>/cashbon_account/<?php echo $detail->CurrencyCode ?>',
                                            required:true,
                                            onSelect: function(rec){
                                                $('#kategoriid').val(rec.ExpCategoryID);
                                                $('.app-button').linkbutton('disable');
                                            },
                                            editable:false
                                        }
                                    }
                                    "
                                    >Account Name</th>
                                	<!-- <th align="center" valign="middle" data-options="field:'ExpCategoryName',width:400,align:'left'" editor="{type:'Payment_Account_Name',options:{required:true}}">Account Name</th> -->
									<th align="center" valign="middle" formatter="formatRp" data-options="field:'EBonAmount', width:150,align:'center', editor:{type:'numberbox',options:{precision:2,decimalSeparator:',',required:true}}">Amount (<span id="curren_code_grid"><?php echo $detail->CurrencyCode ?></span>)</th>
									<th align="center" valign="middle" data-options="field:'EBonMemo',width:400,align:'left',editor:'text'">Memo</th>
                                    <!-- <th align="center" valign="middle" hidden="true" data-options="field:'AccountNumber',width:400,align:'left',editor:'text'">Akun Number</th> -->
                                    <!-- <th align="center" valign="middle" data-options="field:'ExpCategoryID',width:400,align:'left'" editor="{type:'Payment_Account_ID',options:{required:true}}" hidden="true">Account ID</th> -->							
							  </tr>
							</thead>
						</table>
					</div>
                </div>
                <!-- End of Datagrid -->
			</form>
    	</div>
        

    </div>
    
    <div id="form-footer" data-options="region:'south',border:false">
    	<table width="100%" cellpadding="0" cellspacing="0">
        <tr>
        	<td>&nbsp;</td>
            <td align="right">
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-help" onclick="" plain="true">Help</a>						 
               	 
                <a href="javascript:void(0)" class="easyui-linkbutton form-button app-button" iconCls="icon-ok" onclick="app_mgr()" <?= (($this->session->userdata("jobtitle_status") != 1 || !in_array($detail->TransStatus,array(4,6))) || (date('Y-m-d') < date('Y-m-d', strtotime($detail->EBonDate))))?'disabled':''?>>App. Mgr</a>
                <a href="javascript:void(0)" class="easyui-linkbutton form-button app-button" iconCls="icon-reload" onclick="app_reverse()" <?=(in_array($detail->TransStatus,array(1,2,9)))?'':'disabled'?> style="<?= $cek_autority_reverse;?>" >Reverse</a>
                <a href="javascript:void(0)" id="save_button" class="easyui-linkbutton form-button save-button" iconCls="icon-save" onclick="save_data()" <?=(in_array($detail->TransStatus,array(0,1,2,3)))?'disabled':''?> <?php echo $cek_autority_save;?>>Save</a> 								
                <!-- <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-print" onClick="link_print('<?php echo $menu_link; ?>/to_print/<?php echo $EBonNumber = str_replace("/",".", $detail->EBonNumber); ?>')">Preview & Print</a>  -->
                <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-print" onclick="parent.tab_edit('Print Expense Cashbon', '<?=$menu_link?>', 'icon-print', 'to_print_detail','<?php echo $detail->EBonNumber;?>');" <?=(in_array($detail->TransStatus,array(4,5,6,1,2,3,9)))?'':'disabled'?>>Preview & Print</a>
                <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-cancel" onclick="<?=($this->session->userdata('jobtitle_status')==0)?'suspend(2)':'parent.tab_close(\'tt\')'?>" <?=(!in_array($detail->TransStatus,array(0,4,6)))?'disabled':''?>><?=($this->session->userdata('jobtitle_status')==0)?'Cancel':'Close'?></a>  				
    		</td>
        </tr>
        </table>
    </div>
</div>

<div id="dialog-payment-account" class="easyui-dialog" style="width:850px;height:523px;top:27px;background-color:#F8F8F8;padding:0px;" closed="true" data-options="modal:true, iconCls:'icon-save'" buttons="#dialog-buttons-account-payment">
    <form id="form_payment_account" method="post" novalidate>
        <table width="100%" align="left" border="0">
            <tr>
                <td width="197" align="left" valign="middle"><b>Account ID</b></td>
                <td width="14"><b>:</b></td>

                <td width="625" colspan="2">
                    <input type="text" style="width:608px;height:20px" name="txt_account_number" id="txt_account_number" class="easyui-validatebox" placeholder="< Account Number >" onkeyup="search_payment_account_popup();" />
                </td>
            </tr>

            <tr>
                <td width="197" align="left" valign="middle"><b>Account Name</b></td>
                <td><b>:</b></td>

                <td colspan="2">
                    <input type="text" style="width:608px;height:20px" name="txt_account_name" id="txt_account_name" class="easyui-validatebox" placeholder="< Account Name >" onkeyup="search_payment_account_popup();" />
                </td>
            </tr>

            <tr>
                <td colspan="3">
                    <table id="tt_choose_payment" class="easyui-datagrid" 
                        url="<?=base_url() . $menu_link?>/cashbon_account"
                        
                        singleSelect="true" fitColumns="true" pagesize="50"
                        style="width:828px;height:380px" data-options = "border:false,view:scrollview,autoRowheight:false"
                    >
                        <thead>
                            <tr>
                                <th field="ExpCategoryID" width="150" sortable="true">Account ID</th>
                                <th field="ExpCategoryName" width="460" sortable="true">Name</th>
                            </tr>
                        </thead>
                    </table>
                </td>
            </tr>
        </table>
    </form>
</div>

<!-- Dialog Button -->
<div id="dialog-buttons-account-payment" style="border:none;">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onClick="choose_payment();">OK</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onClick="modal_close('dialog-payment-account');">Cancel</a>
</div>

<script type="text/javascript">

var urlAccount = "";
var cek_grid   = 0;

var SavePrivillage =  '<?=$group_user->SavePrivillage;?>';

$(document).ready(function(){
    
    var Currcode = "<?php echo $detail->CurrencyCode ?>";
    if(Currcode == "IDR"){
        $('#txt_rate').prop('readonly',true);
    }
	
	var currency_code = $('#currency_code').val();
	
	if(currency_code == "IDR"){
		$('#curren_code').text('<?php echo $detail->CurrencyCode;?>');
		$('#curren_code_grid').text('<?php echo $detail->CurrencyCode;?>');
		$('#curren_code_grid_amount').text('<?php echo $detail->CurrencyCode;?>');
	}
	else{
		$('#curren_code').text('<?php echo $detail->CurrencyCode;?>');
		$('#curren_code_grid').text('<?php echo $detail->CurrencyCode;?>');
		$('#curren_code_grid_amount').text('<?php echo $detail->CurrencyCode;?>');
	}
	
	$('#txt_cashbon_date').datebox('setValue', '<?php echo $detail->EBonDate ?>');
	$('#txt_cheque_date').datebox('setValue', '<?php echo $detail->ChequeDate ?>');
	
	/*===================== department select =======================================*/
    var AccountNumber = $("#cmb_bank").combogrid('getValue');
    get_bank_balance(AccountNumber,currency_code);

    $('#fm_purchase_expense_cashbon').click(function(){
        $('#dtg_expensecashbon').edatagrid('saveRow');
    });
	
});
	
function save_data(){
	var total_cek 	= parseFloat($('#txt_amount').numberbox('getValue'));
	var rate_nilai 	= parseFloat($('#txt_rate').numberbox('getValue'));
	var item = $('#dtg_expensecashbon').datagrid('getRows');
		 
	 $.each(item,function(index,value){
		cashbon_amount = parseFloat(value.EBonAmount);
	});
	
	if(total_cek < 1){
		$.messager.alert('Unseccessfull','Transaksi Belum Lengkap','error');
		return false;
	} 
	//else if(total_cek != cashbon_amount){
		//$.messager.alert('Unseccessfull','Amount Tidak Sama Dengan Total Amount.','error');
		//return false;
	//}
	else if(rate_nilai <= 0){
		$.messager.alert('Unseccessfull','Rate Tidak Boleh Kurang Dari Satu (1)','error');
		return false;
	}
	else {

        var login_as        = "<?= $this->session->userdata('username');?>";
        var created_by      = "<?= $detail->CreatedBy;?>";
        var depart_by       = "<?= $detail->DepartmentCode;?>";
        var depart_ses      = "<?= $this->session->userdata('department');?>";
        var jobtitle_status = "<?= $this->session->userdata('jobtitle_status');?>";

        var no_transaksi    = $('#txt_exp_cashbon_no').val();
        var status          = '<?= $detail->TransStatus;?>';

        checking_update(no_transaksi,status,function(check){
        
            if(check.status == true){
                $('#dtg_expensecashbon').edatagrid('saveRow');      
                var i=$('#dtg_expensecashbon').datagrid('getRows');
                var items = JSON.stringify(i);
                $("#detail_expense_cashbon").val(items);        
                edit_data('<?=$menu_link?>','#fm_purchase_expense_cashbon',created_by,login_as,depart_by,depart_ses,jobtitle_status);
            }else{
                $.messager.alert('Unseccessfull',check.message,'error',function(){
                    location.reload();
                });
            }

        });
	}			
}

function setAmount(){
	var total_amount = 0;
	var selected	= $('#dtg_expensecashbon').datagrid('getSelected');
	var index		= $('#dtg_expensecashbon').datagrid('getRowIndex', selected);
	var editor 		= $('#dtg_expensecashbon').datagrid('getEditors', index);
	
	var Amount	= $(editor[0].target);
	rate_val 	= $(Amount).numberbox('getValue');
	
	$('#dtg_expensecashbon').edatagrid('saveRow');		
	/*var rows 	= $('#dtg_expensecashbon').datagrid('getRows');
	for(var i=0; i<rows.length; i++){
		total_amount += parseFloat(rows[i].rate_val);
	}*/
	
	$('#txt_amount').numberbox('setValue',rate_val);
	$('#txt_amountRp').numberbox('setValue',rate_val);
	
}

function suspendTransaksi(){
	var cashbonNumber = $("#txt_exp_cashbon_no").val();
	var rep_1 = cashbonNumber.replace("/", ".");
	var rep_2 = rep_1.replace("/", ".");
	var rep_3 = rep_2.replace("/", ".");
	
	suspend_data_on_new_form('<?php echo $menu_link; ?>', rep_3);
}

function open_payment() { 
   modal_open('Account List','dialog-payment-account');
}

function choose_payment() {
    var selected_data = $('#tt_choose_payment').datagrid('getSelected');

    $('.Payment_Account_Name').val(selected_data.ExpCategoryName);
    $('.Payment_Account_ID').val(selected_data.ExpCategoryID);
    $('#kategoriid').val(selected_data.ExpCategoryID);
    console.log($('.Payment_Account_ID').val());
    modal_close('dialog-payment-account');
}

function app_mgr(){
    var no_transaksi    = $('#txt_exp_cashbon_no').val();

    checking_approval(no_transaksi,function(check){
        
        if(check.status == false){
            $('#code_appdir').val('5');
            approved_data('<?=$menu_link;?>','#fm_purchase_expense_cashbon');
        }else{
            $.messager.alert('Unseccessfull',check.message,'error',function(){
                location.reload();
            });
        }
    });
}

function app_reverse(){
    var no_transaksi    = $('#txt_exp_cashbon_no').val();

    checking_reverse(no_transaksi,function(check){
        
        if(check.status == true){
            reversed_data('F','<?=$menu_link?>', no_transaksi, 'Expense Cashbon');
        }else{
           $.messager.alert('Unseccessfull',check.message,'error',function(){
                location.reload();
            });
        }
    });
}

function app_payment(){

    var isLock          = '<?=$detail->EBonLockStatus;?>';
    var no_transaksi    = $('#txt_exp_cashbon_no').val();

    if(isLock == 0){
       parent.tab_add('New Expense Payment','list/purchases_expense_real','icon-add','add/'+no_transaksi);
    }else{
        $.messager.alert('Unseccessfull','Expense Cashbon is Lock. Tidak bisa melakukan transaksi payment.','error',function(){
            //location.reload();
        });
    }
    
}

function suspend(type){
    var created_by      = '<?php echo $detail->CreatedBy;?>';
    var login_as        = '<?php echo$this->session->userdata('username');?>';
    var job_title       = '<?php echo $this->session->userdata('jobtitle_status');?>';
    var url             = '<?= base_url();?>custom/custom/checking_suspend';
    
    suspend_check_trans('F', type, '<?=$menu_link?>', $('#txt_exp_cashbon_no').val(), '<?=$menu_label;?>', url, created_by, login_as, job_title);
}
</script>