<!---- 
    Author 	: Ladur / 14-08-2014
    Revisi 	: Ferry / 30-10-2014 / Cancel for Reload Form
    Revisi 	: Fachri / 25-03-2015 / Cancel for Reload Form
-->

	<?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%" border="0">
                <tr>
                    <td align="left">
                    	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-document" plain="true" onclick="location.reload()">New</a>
                    </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 -->
    
    <div id="form-body" data-options="region:'center',border:false">
    	<div id="form-wrapper" class="easyui-panel" style="padding:5px;" fit="true">
            <form id="fm_new_item" name="fm_new_item" method="post">
                <input type="hidden" id="cek_as_aset" />
            	<input type="hidden" id="id_aset" name="id_aset" value="0"/>
                
            	<div class="easyui-tabs" id="wrapptabs">
                    <!-- General -->
                    <div title="General" style="padding:10px;">
                    	<table width="100%" cellpadding="0" cellspacing="0">
                        <tr>
                            <td><b>Item Category</b></td>
                            <td width="850" style="padding:1px 0px 2px;">
                                <select class="combo-grid" name="cmb_category" id="cmb_category" 
                                	style="height:20px;width:852px;" 
                                    data-options="
                                        panelWidth: 852,
                                        idField: 'ItemCategoryID',
                                        textField: 'ItemCategoryName',
                                        url: '<?php echo base_url(); ?>custom/get_data/itemcategory_add',
                                        method: 'get',
                                        columns: [[
                                        {field:'ItemCategoryName',title:'Item Category Name',width:190}
                                        ]],
                                        fitColumns: true,
                                        onSelect: function(index,row){
                                            var value = row.AssetStatus; 
                                            cek_as_aset(value);
                                           	
                                            <!--pas select item kategori langsung get item kategori for item initial new-->
                                            get_item_categori(row.ItemCategoryID, row.InitialCategory);
                                            <!---------------------end-------------------->
                                           
                                        }
                                    " required editable="true"
                                >
                                </select>
                            </td>
                        </tr>
                        <tr>
                        	<td><b>Item Type</b></td>
                            <td style="padding:1px 0px 2px;">
                            	<select name="rdo_itemtype" id="rdo_itemtype" class="easyui-combobox" editable="true" 
                                	
                                 style="width:852px;height:20px;" required="true" ></select>
                            </td>
                        </tr>
                        <tr>
                        	<td><b>Item No.</b></td>
                            <td style="padding:1px 0px 2px;">
                            	<input type="text" id="txt_itemno" name="txt_itemno" class="easyui-validatebox" data-options="required:true" style="width:850px;text-transform:uppercase" readonly="readonly"/>
                                <!--
                                <input type="checkbox" id="chk_itemno" name="chk_itemno" onclick="showHideLoadItem()" /> Sub Item Of
                                <input type="text" id="txt_codeitem" name="txt_codeitem" style="width:150px;" />
                                <input type="button" id="btn_loaditem" name="btn_loaditem" value="..." onclick="showDialogItem()" />
                                -->
                            </td>
                        </tr>
                        <tr>
                        	<td><b>Description</b></td>
                            <td style="padding:1px 0px 2px;">
                            	<textarea rows="4" id="txa_desctiption" name="txa_desctiption" class="easyui-validatebox" data-options="required:true" style="width:846px;resize:none;white-space:normal;text-transform:uppercase;" ></textarea>
                            </td>
                        </tr>
                        
                        <tr>
                        	<td><b>Unit</b></td>
                            <td style="padding:1px 0px 2px;">
                            	<input type="text" id="txt_unit" name="txt_unit" style="width:850px;" /> 
                                <!-- <input type="button" id="btn_unit" name="btn_unit" value="..." /> -->
                            </td>
                        </tr>
                        <tr>
                        	<td><b>Tax Type</b></td>
                            <td style="padding:1px 0px 2px;">
                            	<input name="rd_pph" type="Radio" value="1" />Pph 22 <input name="rd_pph" type="Radio" value="0" />None
                                <!-- <input type="button" id="btn_unit" name="btn_unit" value="..." /> -->
                            </td>
                        </tr>
                        </table>
                        
                       
                    </div>
                    
                    <!-- Custom Field -->
					<div title="Custom Field" style="padding:10px;">
                    	<table width="100%" cellpadding="0" cellspacing="0">
                        <tr>
                            <td><b>Merk</b></td>
                            <td width="850" style="padding:1px 0px 2px;">
                            	<input type="text" id="" name="txt_customfieldmerk" style="width:850px;" />
                            </td>
                        </tr>
                        <tr>
                        	<td><b>Design</b></td>
                            <td style="padding:1px 0px 2px;">
                            	<input type="text" id="" name="txt_customfieldesign" style="width:850px;" />
                            </td>
                        </tr>
                        <tr>
                        	<td><b>Colour</b></td>
                            <td style="padding:1px 0px 2px;">
                            	<input type="text" id="" name="txt_customfieldcolour" style="width:850px;" />
                            </td>
                        </tr>
                        <tr>
                        	<td><b>Size</b></td>
                            <td style="padding:1px 0px 2px;">
                            	<input type="text" id="" name="txt_customfieldsize" style="width:850px;" />
                            </td>
                        </tr>
                        <tr>
                        	<td><b>Quality</b></td>
                            <td style="padding:1px 0px 2px;">
                            	<input type="text" id="" name="txt_customfieldquality" style="width:850px;" />
                            </td>
                        </tr>
                        <tr>
                        	<td><b>Type</b></td>
                            <td style="padding:1px 0px 2px;">
                            	<input type="text" id="" name="txt_customfieldtype" style="width:850px;" />
                            </td>
                        </tr>
                        <tr>
                        	<td><b>Shading</b></td>
                            <td style="padding:1px 0px 2px;">
                            	<input type="text" id="" name="txt_customfieldshading" style="width:850px;" />
                            </td>
                        </tr>
                        <tr>
                        	<td><b>Group</b></td>
                            <td style="padding:1px 0px 2px;">
                            	<input type="text" id="" name="txt_customfieldgroup" style="width:850px;" />
                            </td>
                        </tr>
                        </table>
                    </div>
                </div>
            </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" iconCls="icon-save" onclick="save_data_item('<?php echo $menu_link?>','#fm_new_item', 1);" <?php echo $cek_autority_save;?>>Save</a> 								
                    <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-cancel" onclick="$('#fm_new_item').form('clear');">Cancel</a>    		
                </td>
             </tr>
         </table>
    </div>
</div>    
    
<script type="text/javascript">

function get_item_categori(item_kategori, InitialCategory){
	url					  = base_url + 'list/items/get_item_initial';                
	var post_item_kategori = item_kategori;
		
	$.post(url, {post_item_kategori:post_item_kategori}, function(result){
		if (result.status === true){
			if(InitialCategory == ""){
				$.messager.alert('Error','Kategori yang anda pilih belum mempunyai initial nama','error',function(){
						$('#txt_itemno').val('');
				})
			}
			else{
				var item_code = InitialCategory+'-'+result.number;
				$('#txt_itemno').val(item_code);
			}
		} 
	},'json');
}

function save_data_item(url,form_id,clear) {
	var item_type = $('#rdo_itemtype').combobox('getValue');
	var as_aset =  $('#cek_as_aset').val();
	
	if(item_type == "1" && as_aset == "0") {
		$.messager.alert('Error','Kategori Yang anda Pilih Bukan Termasuk Aset','error',function(){	
		})
	}
	
	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(){					
					location.reload();							
				});	
				
				if(clear==1){
					$(form_id).form('clear');
				}
			} 
			else {
				$.messager.alert('Unseccessfull',result.message,'info',function(){					
								
				});	
			} 
		},
		statusCode: {
			404: function() {
			  alert("Page Not Found");
			}		
		}
	});
}
	
function cek_as_aset(value){
	if(value == 0){
		 var asset = $('#id_aset').val('0');
		$('#rdo_itemtype').combobox({
			value:'',
			valueField:'ItemTypeID',
			textField:'ItemTypeName',
			url:'<?php echo base_url(); ?>custom/get_data/itemtype_master_inventori'
		});
		
	}
	else{
		 var asset = $('#id_aset').val('1');
		$('#rdo_itemtype').combobox({
			value:'Fixed Asset',
			valueField:'ItemTypeID',
			textField:'ItemTypeName',
			url:'<?php echo base_url(); ?>custom/get_data/itemtype_master_fix_asset/1'
		});
	}
}

/* function hidefixed(value){
	if(value == 1){
		$('.disableme').css('display','');		
	}
	else{
		$('.disableme').css('display','none');
	}
} */
</script>