<!---- 
    Author 	: Wahyu / Tanggal : 12-08-2014	
    Revisi 	: Ferry / Tanggal : 20-03-2015
    Revisi 	: Fachri / Tanggal : 27-08-2015 ()
-->

<?php
//---------Untuk privellege jika dia ada tombol save----------
	if($group_user->SavePrivillage == 1){
		$cek_autority_save  = "";
	}
	else{
		$cek_autority_save 	= "disabled";
	}
//-------------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" valign="middle">
                    	<a href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="location.reload()">Refresh</a>
                        <!--<a href="#" class="easyui-linkbutton" iconCls="icon-document" plain="true" onclick="parent.tab_new('New Bank','<?=$menu_link?>/add','icon-bank');" disabled="true">New</a>-->
                        <!--<input type="checkbox" id="chk_status" name="chk_status" onclick="suspend(1);" value="3" <?=(($detail->TransStatus==3)?'checked':'')?> />Suspend-->
                    </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">
            <form id="fm_currency" name="fm_currency" method="post">
            	<input type="hidden" name="txt_currency_id" id="txt_currency_id" class="easyui-validatebox" value="<?php echo $detail->CurrencyID; ?>" readonly />
                <input type="hidden" name="txt_company_code" id="txt_company_code" class="easyui-validatebox" value="<?php echo $detail->CompanyCode; ?>" readonly />
            	<table width="100%" border="0" cellspacing="1" cellpadding="1">
                    <tr>
                        <td width="300px"><b>Currency Code</b></td>
                        <td>
                            <input type="text" name="txt_currency_code" id="txt_currency_code" class="easyui-validatebox" data-options="required:true" value="<?php echo $detail->CurrencyCode; ?>" style="width:850px;text-transform:uppercase;" readonly />
                            <!--<input type="hidden" name="txt_currency_codeID" class="easyui-validatebox" value="<?php echo $detail->CurrencyCode; ?>" />-->										
                        </td>
                    </tr>

                    <tr>
                        <td><b>Currency Name</b></td>
                        <td>
                            <input type="text" name="txt_currency_name" class="easyui-validatebox" data-options="required:true" value="<?php echo $detail->CurrencyName; ?>" style="width:850px;" />										
                        </td>
                    </tr>

                    <tr>
                        <td><b>Curency Rate</b></td>
                        <td>
                            <input type="text" name="txt_currency_rate" id="txt_currency_rate" class="easyui-validatebox currency" data-options="required:true" value="<?php echo $detail->CurrencyRate; ?>" style="width:850px;"  readonly/>
                            <input type="hidden" name="txt_currency_rate_nilai" id="txt_currency_rate_nilai" class="easyui-validatebox td_input" data-options="required:true" value="<?php echo $detail->CurrencyRate; ?>" />
                        </td>
                    </tr>

                    <tr>
                        <td><b>Description</b></td>
                        <td>
                            <input type="text" name="txt_currency_desc" class="easyui-validatebox" value="<?php echo $detail->CurrencyDesc; ?>" style="width:850px;"/>
                        </td>
                    </tr>

                    <tr>
                        <td><b>Country</b></td>
                        <td>
                            <select name="cmb_country" id="cmb_country" class="combo-grid" style="width:852px;height:20px" required="true" editable="true"
                                data-options="
                                    value:'<?php echo $detail->CurrencyCountry; ?>', 
                                    idField:'CountryCode',
                                    textField:'CountryName',
                                    url:'<?php echo base_url(); ?>custom/get_data/country',
                                    method: 'get',
                                    columns: [[
                                        {field:'CountryCode',title:'Country Code',width:200,halign:'center',align:'left'},
                                        {field:'CountryName',title:'Country Name',width:630,halign:'center',align:'left'}
                                    ]],
                                ">
                            </select>
                        </td>
                    </tr>

                    <tr>
                        <td><b>Symbol</b></td>
                        <td>
                            <input type="text" name="txt_currency_symbol" class="easyui-validatebox" value="<?php echo $detail->CurrencySymbol; ?>" style="width:850px;" />
                        </td>
                    </tr>
                </table>
            </form>
        </div>        
    </div>
    <!-- End of 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="" plain="true">Help</a>			 
                    <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-save" onclick="edit_data('<?php echo $menu_link?>','#fm_currency');" <?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 Currency', '<?php echo $menu_link; ?>', 'preview', '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>
</div>

<script type="text/javascript">
    function toAngka(rp){return parseInt(rp.replace(/,.*|\D/g,''),10);}
    function toRp(a,b,c,d,e){e=function(f){return f.split('').reverse().join('');};b=e(parseInt(a,10).toString());for(c=0,d='';c<b.length;c++){d+=b[c];if((c+1)%3===0&&c!==(b.length-1)){d+='.';}}return'Rp.\t'+e(d)+',00';}

    $(document).ready(function() {
	$('#txt_currency_rate').keyup(function() { 
            var rate_rp= $(this).val();
            var rate_nilai = toAngka(rate_rp);

            if(rate_nilai > 0){
                $('#txt_currency_rate_nilai').val(rate_nilai);
            }
        });
    });
    
    function edit_coa_currency(){
        var url             = base_url + 'list/currency/update_coa_currency';
        var CurrencyCode    = $('#txt_currency_code').val();
        
        $.post(url, {CurrencyCode:CurrencyCode}, function(result){
            if (result.status == true){
                $.messager.alert('Success',result.message,'info',function(){
                    location.reload();						                    
                });				
            } 
            else {
                $.messager.alert('Failed',result.message,'error',function(){
                    location.reload();						                    
                });
            }
        },'json');
    }
</script>