<!---- 
    Author 			: Herpan
    Created Date	: 12/08/2014	
    Revision		: 1) Hasan | 05/02/2015 | Design UI
-->

<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%">
            <tr>
                <td align="left" valign="middle"></td>							
                <td height="25" align="right" valign="middle">								
                    <span class="form-title">
                        <?=$menu_label?>
                    </span>
                </td>
            </tr>
            </table>		     	
		 </div>			
	</div>
	<!-- end top view -->
    
	<!-- center view -->
	<div id="form-body-grey" data-options="region:'center',border:false" style="padding-left:0px;">
		<div class="easyui-panel" style="width:auto;padding:5px;height:582px;" id="tab_company">
			<form id="fm_new_company" name="fm_new_company" method="post">
            <input type="hidden" name="detail" id="detail"/>
            <input type="hidden" id="txt_new_rate" name="txt_new_rate" class="easyui-numberbox" data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" style="width:290px;height:20px" />
				 <div class="easyui-tabs">
                 	<!-- TAB GENERAL -->
					<div id="tab_general" title="General" style="padding:10px;">
						<table width="100%" cellpadding="0" cellspacing="0">
                        <tr>
                            <td><b>Company Code</b></td>
                            <td width="950" style="padding:1px 0px 2px;">
                                <input type="text" id="txt_company_code" name="txt_company_code" class="easyui-validatebox" data-options="required:true" style="width:950px;text-transform:uppercase;" maxlength="5"/>
                            </td>
                        </tr>
                        <tr>
                            <td><b>Company Name</b></td>
                            <td width="950" style="padding:1px 0px 2px;">
                                <input type="text" id="txt_companyname" name="txt_companyname" class="easyui-validatebox" data-options="required:true" style="width:950px;text-transform:uppercase;" />
                            </td>
                        </tr>
                        <tr>
                            <td valign="top"><b>Company Address</b></td>
                            <td width="950" style="padding:1px 0px 2px;"><textarea name="txt_address" class="easyui-validatebox" style="width:945px; height:80px; text-transform:uppercase;" data-options="required:true"></textarea></td>
                        </tr>
                        <tr>
                            <td><b>Company's Date</b></td>
                            <td width="950" style="padding:1px 0px 2px;text-align:left;">
                            	<input type="text" name="txt_company_date" id="txt_company_date" class="easyui-datebox" editable="false" style="width:180px" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>City</b></td>
                            <td width="950" style="padding:1px 0px 2px;">
                                <select name="cmb_city" id="cmb_city" class="combo-grid" style="width:952px;" required="true" editable="true"
                                data-options="
                                    idField:'CityCode',
                                    textField:'CityName',
                                    url:'<?php echo base_url(); ?>custom/get_data/city',
                                    method: 'get',
                                    columns: [[
                                        {field:'CityCode',title:'City Code',width:420,halign:'center',align:'left'},
                                        {field:'CityName',title:'City Name',width:430,halign:'center',align:'left'}
                                    ]],
                                ">
                            </select>
                            </td>
                        </tr>
                        <tr>
                            <td><b>State</b></td>
                            <td width="950" style="padding:1px 0px 2px;">
                                <select name="cmb_state" id="cmb_state" class="easyui-combogrid" style="width:952px;" required="true" editable="false" readonly
                                data-options="
                                    idField:'StateCode',
                                    textField:'StateName',
                                    url:'<?php echo base_url(); ?>custom/get_data/state',
                                    method: 'get',
                                    columns: [[
                                        {field:'StateCode',title:'State Code',width:100,halign:'center',align:'left'},
                                        {field:'StateName',title:'State Name',width:161,halign:'center',align:'left'}
                                    ]],
                                ">
                            </select>
                            </td>
                        </tr>
                        <tr>
                            <td><b>Country</b></td>
                            <td width="950" style="padding:1px 0px 2px;">
                                <select name="cmb_country" id="cmb_country" class="easyui-combogrid" style="width:952px;" required="true" editable="false" readonly
                                data-options="
                                    idField:'CountryCode',
                                    textField:'CountryName',
                                    url:'<?php echo base_url(); ?>custom/get_data/country',
                                    method: 'get',
                                    columns: [[
                                        {field:'CountryCode',title:'Country Code',width:100,halign:'center',align:'left'},
                                        {field:'CountryName',title:'Country Name',width:161,halign:'center',align:'left'}
                                    ]],
                                ">
                            </select>
                            </td>
                        </tr>
                        <tr>
                            <td><b>Zip Code</b></td>
                            <td width="950" style="padding:1px 0px 2px;">
                            	<input class="easyui-numberbox" type="text" name="txt_zipcode" style="width:952px;" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>Phone No.</b></td>
                            <td width="950" style="padding:1px 0px 2px;">
                            	<input type="text" name="txt_phone_left" class="easyui-numberbox" value="62" style="width:30px;" data-options="required:true"/> - <input type="text" name="txt_phoneno" class="easyui-numberbox" style="width:909px;" data-options="required:true"/>
                            </td>
                        </tr>
                        <tr>
                            <td><b>Fax No.</b></td>
                            <td width="950" style="padding:1px 0px 2px;">
                            	<input type="text" name="txt_fax_left" class="easyui-numberbox" value="62" style="width:30px;" data-options="required:true"/> - <input type="text" name="txt_faxno" class="easyui-numberbox" style="width:909px;" data-options="required:true"/>
                            </td>
                        </tr>
                         <tr>
                            <td valign="top"><b>Currency</b></td>
                            <td width="950" style="padding:1px 0px 2px;">
                            	<table id="dtg_currency" idField="CompanyCode" class="easyui-edatagrid" style="width:950px" required
                                    url="<?php echo base_url()?>file/new_company/currency_by_company"
                                    data-options="singleSelect:true" rowNumbers="true" 
                                    >
    
                                    <thead>
                                        <tr>
                                            <th width="220" align="left" halign="center" field="CurrencyCode">Currency Code</th>
                                            <th width="156" align="left" halign="center" field="CurrencyRate" editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',min:0}}" formatter="formatRp">Currency Rate</th>
                                            <th width="500" align="left" halign="center" field="CurrencyDesc">Currency Desc</th>                                            										
                                        </tr>
                                    </thead>
                                </table>
                            </td>
                        </tr>
                        <!--<tr>
                            <td><b>Company Type</b></td>
                            <td width="950" style="padding:1px 0px 2px;">
                            	<input name="rd_comtype" type="Radio" value="1" />Manufacturing <input name="rd_comtype" type="Radio" value="0" />Trading
                            </td>
                        </tr>-->
						</table>
					</div>

					<!-- TAB TAX -->
					<div id="tab_tax" title="Tax" style="padding:10px;">
						<table width="100%" cellpadding="0" cellspacing="0">
                         <tr>
                            <td valign="top"><b>Tax Address</b></td>
                            <td width="950" style="padding:1px 0px 2px;"><textarea name="txt_taxaddress"  style="width:945px; height:80px; text-transform:uppercase;" ></textarea></td>
                        </tr>
                        <tr>
                            <td><b>Form Serial Number</b></td>
                            <td width="950" style="padding:1px 0px 2px;">
                            	<input type="text" name="txt_taxformserialnumber" class="td_generaltaxinput" style="width:950px" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>Tax Registration Number</b></td>
                            <td width="950" style="padding:1px 0px 2px;">
                            	<input type="text" name="txt_taxregistnumber" class="td_generaltaxinput" style="width:950px" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>Taxable Company's Number</b></td>
                            <td width="950" style="padding:1px 0px 2px;">
                            	<input type="text" name="txt_taxablecompanysno" class="td_generaltaxinput" style="width:950px" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>Taxable Company's Date</b></td>
                            <td width="950" style="padding:1px 0px 2px;text-align:left;">
                            	<input type="text" name="txt_taxablecompanysdate" class="easyui-datebox" editable="false" style="width:180px" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>Tax Type</b></td>
                            <td width="950" style="padding:1px 0px 2px;">
                            	<input type="text" name="txt_taxtype" class="td_generaltaxinput" style="width:950px" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>KLU</b></td>
                            <td width="950" style="padding:1px 0px 2px;">
                            	<input type="text" name="txt_taxklu" class="td_generaltaxinput" style="width:950px" />
                            </td>
                        </tr>
						</table>
					</div>
				</div>
                
                <!-- Dialog Import-->
                <div id="dialog-import" class="easyui-dialog" style="width:370px;height:140;padding:10px 20px" closed="true" buttons="#dialog-buttons-group" data-options="modal:true">
                    <div class="fitem">
                        <fieldset style="border:1px solid #CCC;">
                            <legend>Currency Rate</legend>
                                 <input type="text" id="txt_rate" name="txt_rate" class="easyui-numberbox" data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" style="width:290px;height:20px" onkeyup="cek_amount(this.value)" />
                        </fieldset>	
                    </div>
                </div>
                
			</form>
		</div>
        
        <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>
						 <?php
                            //---------Untuk privellege jika dia ada tombol save----------
                            if($group_user->SavePrivillage == 1){
                                $cek_autority = "";
                            }
                            else{
                                $cek_autority = "disabled";
                            }
                            //-------------end----------------------------
                         ?>			 
                         <a href="javascript:void(0)" class="easyui-linkbutton form-button save-button" iconCls="icon-save" onclick="save_data();" <?php echo $cek_autority;?>>Save</a> 								
                         <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-cancel" onclick="location.href='<?php echo base_url() ?>'" <?php echo $cek_autority;?>>Cancel</a>	
                    </td>
                </tr>
            </table>
        </div>
	</div>
</div>
<!-- Dialog Button -->
                <div id="dialog-buttons-group" style="border:none;">
                    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" id="ok_button" onclick="save_data();">Simpan</a>
                    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" id="close_button" onClick="close_dialog();">Batal</a>
                </div>
<script type="text/javascript">
    $(document).ready(function(){
        $('#cmb_city').combogrid({
            onSelect:function(rowIndex, rowData){
                $('#cmb_state').combogrid('setValue', rowData.StateCode);
            }
        });

        $('#cmb_state').combogrid({
            onSelect:function(rowIndex, rowData){
                $('#cmb_country').combogrid('setValue', rowData.CountryCode);
            }
        });
		
		$('#dtg_currency').datagrid({
			onBeginEdit:function(rowIndex){
				var editors = $('#dtg_currency').datagrid('getEditors', rowIndex);
				
				/*====================on beg in edit saat grid di klik maka tombol save disable===================*/
				$('.save-button').linkbutton('disable');
				/*===============================end===========================================================*/
			},
			onEndEdit:function(){
				/*====================on beg in edit saat grid di klik maka tombol save disable===================*/
				$('.save-button').linkbutton('enable');
				/*=================================end============================================================*/
			}
		});
	
		$('#tab_company').click(function(){
			$('#dtg_currency').edatagrid('saveRow');
		});
    });
	
	function modal_open_imp(title, divid){
		 $('#dialog-import').dialog('open').dialog('setTitle',title);
	}
	
	function save_data(){
		var i       = $('#dtg_currency').datagrid('getRows');
		var detail  = JSON.stringify(i);
		
		$("#detail").val(detail);	
			
		save_company('file/new_company','#fm_new_company, 0');
	}
	
	function save_company(url,form_id,clear) {
		url = base_url + url;

		$(form_id).form('submit',{
			url: url + '/insert',
			onSubmit: function(){
				return $(this).form('validate');
			},
			success: function(result){
				var result = eval('('+result+')');
				
				if (result.status==true){
					$.messager.alert('Success',result.message,'info',function(){					
						window.location.href='<?=site_url('login/process_logout')?>';	
					});	

					if(clear==1){
						$(form_id).form('clear');
					}
				} 
				else {
					$.messager.alert('Unseccessfull',result.message,'info',function(){					
											
					});	
				} 
			},

			statusCode: {
				404: function() {
				  alert("Page Not Found");
				}		
			}
		});
	}
	
	function close_dialog(){
		modal_close('dialog-import');
	}
	
	
	function cek_amount(value){
		var total = toAngka(value);
		$("#txt_new_rate").numberbox('setValue',total);
	}
</script>