<!---- 
    Author 	: Herpan / 18-08-2014	
    Revisi 	: Ferry / 20-12-2014
-->
<?php
//---------Untuk privellege jika dia ada tombol save----------
	if($group_user->SavePrivillage == 1){
		$cek_autority_save  = "";
	}
	else{
		$cek_autority_save 	= "disabled";
	}
	
	/*======================jika sub type adalah satu maka dia saldo balance sheet======================*/
	if($detail->AccountBSStatus == 1){
		$gl_saldo_opening 		= abs($detail->GLSaldoBSheet);
	}
	else{
		$total_gl_saldo_balance = $detail->GLSaldoBalance + $detail->GLSaldoOpening;
		$gl_saldo_opening 		= abs($total_gl_saldo_balance);
		
	}
	/*===========================end=====================================================================*/
//-------------end----------------------------
?>
<div class="easyui-layout" data-options="fit:true,border:false">
    <form id="fm_edit_coa" name="fm_edit_coa" method="post" action="">
        <!-- 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" valign="middle" width="30%"><a href="#" class="easyui-linkbutton" id="refresh-linkbutton" data-options="plain:true,iconCls:'icon-reload'" onclick="location.reload();">Refresh</a></td>
                        <td align="center" width="40%"><span id="approval_information">
						<?php
                        if($detail->TransStatus == 5){
                            echo get_status_approval_header($detail->TransStatus);
                        }
                        ?>
                        </span></td>
                        <td height="25" align="right" valign="middle">								
                            <span class="form-title">
                           
                                <?php echo $menu_label; ?>
                            </span>
                        </td>
                    </tr>
                </table>		     	
            </div>		
        </div>
        <!-- end top view -->

        <!-- center view -->
        <div id="form-body-grey" data-options="region:'center',border:false">
            <div id="form-wrapper" class="easyui-panel" style="padding:10px;" fit="true">
                <table width="100%" cellspacing="1" cellpadding="1">
                    <tr>
                        <td width="300"><b>Branch Code</b></td>
                        <td colspan="2">
                            <input type="text" name="txt_branch_code" value="<?php  echo $branch_code ?>" style="width:150px;text-align:center;" editable="false" required="true" readonly/>
                            <input type="text" name="txt_branch_name" value="<?php  echo $branch_name ?>" style="width:694px;" editable="false" required="true" readonly/>
                            <input type="hidden" name="txt_bs_status" value="<?php echo $detail->AccountBSStatus; ?>" style="width:694px;" editable="false" />
                            <input type="hidden" name="txt_company_code" value="<?php echo $detail->CompanyCode; ?>" style="width:694px;" editable="false" />
                            <input type="hidden" name="txt_sub_type_name" value="<?php echo $detail->AccountTypeName; ?>" style="width:694px;" editable="false" />
                            <input type="hidden" name="txt_type_name" value="<?php echo $detail->TypeName; ?>" style="width:694px;" editable="false" />
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td colspan="2"><hr/></td>
                    </tr>
                    <tr><td colspan="3">&nbsp;</td></tr>
                    <tr>
                        <td width="300"><b>Account Type</b></td>
                        <td colspan="2">
                            <select class="easyui-combobox td_input" name="cmb_account_sub_type" id="cmb_account_sub_type" style="width:852px;height:20px;" editable="false" required="true" readonly
                                data-options = "
                                    value:'<?= $detail->AccountSubTypeID ?>',
                                    valueField:'AccountSubTypeID',
                                    textField:'AccountTypeName',
                                    url:'<?php echo base_url(); ?>custom/get_data/accountsubtype'
                                ">                                
                            </select>						

                            <!--<input type="checkbox" id="chk_suspended" name="chk_suspended" value="3" <?php if($detail->TransStatus==3) echo " checked"?> /> Suspended-->
                        </td>
                    </tr>

                    <tr style="height:30px">
                        <td><b>Sub Account of</b></td>                        
                        
                        <td colspan="2">
                            <div id="cmb_sub_account_wrapper" <?php if($detail->AccountParent == "") echo "style='display:none;'"; ?>>
                                <input style="display:none" type="text" name="account_parent_old" value="<?php  echo $detail->AccountParent ?>"/>
                                <select class="easyui-combogrid td_input" name="cmb_account_parent" id="cmb_account_parent" style="width:452px;height:20px;" readonly
                                    data-options="
                                        value:'<?php echo $detail->AccountParent ?>',
                                        idField:'AccountNumber',
                                        textField:'AccountName',
                                        url:'<?php echo base_url(); ?>list/coa/account_gl_for_edit/' + <?= $detail->AccountSubTypeID ?>,
                                        columns:[[
                                                {field:'AccountNumber',title:'Account Number',width:200},
                                                {field:'AccountName',title:'Account Name',width:630}
                                        ]]
                                    ">											
                                </select>
                            </div>
                        </td>
                    </tr>

                    <tr>
                        <td><b>Account No.</b></td>
                        <td colspan="2">
                            <input type="text" name="txt_account_no" id="txt_account_no" style="width:850px;" class="easyui-validatebox td_input" value="<?php echo $detail->AccountNumber ?>" readonly />
                            <!--<input type="hidden" name="account_no_old" value="<?php  echo $detail->AccountNumber ?>" readonly />-->	
                        </td>
                    </tr>
		
                    <tr>
                        <td><b>Account Name</b></td>
                        <td colspan="2">
                            <input type="text" name="txt_account_name" class="easyui-validatebox td_input" style="width:850px;" data-options="required:true" value="<?php echo $detail->AccountName ?>" <?= (($detail->AccountSubTypeID == 6) || ($detail->TransStatus != 6))? "readonly" : '' ?> />
                        </td>
                    </tr>

                    <tr>
                        <td><b>Currency Name</b></td>
                        <td colspan="2">
                            <select class="easyui-combogrid td_input" name="cbg_currency" id="cbg_currency" style="width:852px;height:20px;" editable="false" required readonly
                                data-options = "
                                    value:'<?= $detail->CurrencyCode ?>',
                                    idField:'CurrencyCode',
                                    textField:'CurrencyName',
                                    url:'<?php echo base_url(); ?>custom/get_data/currency',
                                    columns:[[
                                        {field:'CurrencyCode',title:'Currency Code',width:200,halign:'center'},
                                        {field:'CurrencyName',title:'Currency Name',width:630,halign:'center'},
                                    ]]
                                ">                                
                            </select>
                        </td>
                    </tr>

                    <tr><td colspan="3">&nbsp;</td></tr>
                    <tr><td colspan="3">&nbsp;</td></tr>
                    
                    <tr><td colspan="3"><hr/></td></tr>

                    <tr>
                        <td><b>Add Balance</b></td>
                        <td width="50"><b><?= ($detail->CurrencyCode == Null) ? 'IDR' : $detail->CurrencyCode ?></b></td>
                        <td>
                        	<input type="text" name="txt_opening_balance" id="txt_opening_balance" class="easyui-numberbox" style="width:795px;text-align:right" value='<?php echo $gl_saldo_opening; ?>' <?= (($gl_saldo_opening > 0) || ($this->session->userdata('jobtitle_status') > 0) || ($this->session->userdata('jobtitle') != "DIR") || in_array($detail->TransStatus, array(3,5)) || (!in_array($detail->AccountTypeName, array('Bank','Petty Cash','Deposito','Persediaan Barang Dalam Proses','Biaya Pra Operational','Piutang Astek','Jaminan','Biaya Dibayar Di Muka','Pajak di bayar Di Muka','Hutang Pajak','Bank Garansi Customer','Hutang Bank','Hutang Leasing','Kewajiban Pajak Tangguhan','Modal','Prive','Laba (Rugi) Ditahan','Laba (Rugi) Berjalan','Laba (Rugi) Bulan Berjalan','Dividen'))))  ? "readonly" : '' ?>
                                data-options="precision:2,decimalSeparator:',',groupSeparator:'.'" 
                            />
                            
                            <input type="hidden" name="txt_opening_balance_hide" id="txt_opening_balance_hide" class="easyui-numberbox" style="width:795px;text-align:right" value='<?php echo $gl_saldo_opening; ?>'
                                data-options="precision:2,decimalSeparator:',',groupSeparator:'.'" 
                            />
                        </td>
                    </tr>
                    
                    <tr>
                        <td height="24"></td>
                        <td colspan="2">
                            <input type="text" name="txt_opbalance_status" class="easyui-numberbox" style="width:850px;text-align:right" value="<?= ($gl_saldo_opening > 0) ? 1 : 0 ?>" required hidden />
                        </td>                                               
                    </tr>
                </table>			
            </div>	
        </div>
        <!-- end center view -->	
        
        <div id="form-footer" data-options="region:'south',border:false">
            <table width="100%" cellpadding="0" cellspacing="0">
                <tr>
                    <td align="right">
                        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-help" onclick="edit_company();" plain="true">Help</a>
                        <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-ok" <?php if((!in_array($this->session->userdata("jobtitle_status"), $app2)) || $detail->AppLevel2Status == 1){echo " disabled ";} ?>onclick="custom_data('<?php echo $menu_link?>/approval2','#fm_edit_coa');"> App. Dir</a> 								
                        <!--<a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-ok" <?php if((!in_array($this->session->userdata("jobtitle_status"), $app1)) || $detail->AppLevel1Status == 1){echo " disabled ";} ?>onclick="custom_data('<?php echo $menu_link?>/approval1','#fm_edit_coa');"> App. Mgr</a>-->
                        <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-save" <?= (!in_array($this->session->userdata('jobtitle_status'), array(0,1)) || ($this->session->userdata('department') != $this->session->userdata('branch').'-001') || ($gl_saldo_opening > 0) || in_array($detail->TransStatus, array(3))) ? 'disabled' : '' ?> onclick="edit_coa();" <?php echo $cek_autority_save;?>>Save</a>
                        <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-print" onClick="parent.tab_add('Print Chart Of Account', '<?php echo $menu_link; ?>', 'icon-coa', 'to_preview');">Preview & Print</a>      
                        <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-cancel" onclick="location.reload();">Cancel</a>	
                    </td>
                </tr>
            </table>
        </div>        
    </form>	
</div>

<script>    
    function edit_coa(){
		if($('#txt_opening_balance_hide').numberbox('getValue') > 0){
			$.messager.alert('Unseccessfull','Data gagal di proses, Opening Balance sudah tersedia','warning',function(){					
				
			});
		}
		else{
			edit_transaction('<?php echo $menu_link?>','#fm_edit_coa');
		}	
    }

    function edit_transaction(url, form_id) {
        url = base_url + url;	
    
        $(form_id).form('submit',{
            url: url + '/update',
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
                var result = eval('('+result+')');
                
                if (result.status==true){
                    var edit_url=result.menu_link+"/edit/"+result.number;

                    $.messager.alert('Success',result.message,'info',function(){					
                        location.reload();
                    });				
                } 
                else {
                    $.messager.alert('Success',result.message,'info',function(){					
                        
                    });
                }
            },		
        
            statusCode: {
                404: function() {
                  alert("Page Not Found");
                }
            }
        });
    }
</script>