<!---- 
    Author 	: Tagor / Tanggal : 14-08-2014
    Revisi 	: Ferry / 30-10-2104, Cancel button for Reload Form
    Revisi : Fachri / 26/01/2015 , Eror transtatus
-->

	<?php
			//---------Untuk privellege jika dia ada tombol save----------
				if($group_user->SavePrivillage == 1){
					$cek_autority_save  = "";
				}
				else{
					$cek_autority_save 	= "disabled";
				}
				
				if($group_user->DeletePrivillage == 1){
					$cek_autority_delete  = "";
				}
				else{
					$cek_autority_delete 	= "disabled";
				}
				//-------------end----------------------------
	?>

<div class="easyui-layout" data-options="fit:true,border:false">
	<?php foreach($detail as $row) : ?>
    <?php 
		if(($row->TransStatus == 3) || ($row->TransStatus == 4) || ($row->TransStatus == 5)) {
			$disabled_category = "disabled";
			$disabled_type = "";
			$readonly_itemno = "readonly";	
			$readonly_itemdesc = "";
			$disabled_warehouse = "disabled";
			$readonly_unit = "";
			$readonly_merk = "readonly";
			$readonly_design = "readonly";
			$readonly_colour = "readonly";
			$readonly_size = "readonly";
			$readonly_quality = "readonly";
			//$readonly_type = "readonly";
			$readonly_shading = "readonly";
			$readonly_group = "readonly";
			$disabled_suspend = "disabled";	
		} 
		else {
			$disabled_category = "";
			$disabled_type = "";
			$readonly_itemno = "";	
			$readonly_itemdesc = "";
			$disabled_warehouse = "";
			$readonly_unit = "";
			$readonly_merk = "";
			$readonly_design = "";
			$readonly_colour = "";
			$readonly_size = "";
			$readonly_quality = "";
			//$readonly_type = "";
			$readonly_shading = "";
			$readonly_group = "";	
		}
	?>
	<!-- 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">
                    	<input type="checkbox" name="chk_suspended" id="chk_suspended" value="3" onClick="suspend(1)" style="margin-top:0px;margin-right:1px;" <?php if($row->TransStatus == 3){echo"checked disabled";} ?> <?php echo $cek_autority_delete;?>/>
                        <span style="display:inline-block;margin-top:2px;<?=(($row->TransStatus==3)?'color:gray;':'')?>"><?=(($row->TransStatus!=3)?"Suspend":"Un-Suspend")?> Item</span>
                    	<a href="#" class="easyui-linkbutton" id="refresh-linkbutton" data-options="plain:true,iconCls:'icon-reload'" onclick="location.reload();">Refresh</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="width:1180%;height:526px;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_asset" value="<?php echo $row->ItemTypeID; ?>"/>
                 <input type="hidden" id="trans_status" value="<?php echo $row->TransStatus; ?>"/>
            	<input type="hidden" id="cek_kosong" name="cek_kosong" />
               <input type="hidden" id="code_item_hidden" name="code_item_hidden" value="<?php echo $row->ItemCode; ?>"/>
               <input type="hidden" id="id" name="id" value="<?php echo $row->ItemCode;?>" />
            	<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 td_input" name="cmb_category" <?php echo $disabled_category;?>
                                	style="height:20px;width:852px;" 
                                    data-options="
                                    	value:'<?php echo $row->ItemCategoryID; ?>',
                                        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);
                                            var cek_kosong = $('#cek_kosong').val('1');
                                            $('.app-button').linkbutton('disable');
                                            
                                            <!--pas select item kategori langsung get item kategori for item initial new-->
                                            //get_item_categori(row.ItemCategoryID, row.InitialCategory);
                                            <!---------------------end-------------------->
                                        }
                                    " required editable="true" <?php echo $disabled_category; ?> 
                                >
                                </select>
                                
								
                            </td>
                        </tr>
                        <tr>
                        	<td><b>Item Type</b></td>
                            <td style="padding:1px 0px 2px;">
                            <select class="easyui-combobox" name="rdo_itemtype" id="rdo_itemtype"
                                    style="height:20px;width:852px;" 
                                    required="required" editable="true" 
                                     data-options="
                                        value:'<?php echo $row->ItemTypeID; ?>',
                                        panelWidth: 852,
                                        valueField: 'ItemTypeID',
                                        textField: 'ItemTypeName',
                                        url: '<?php echo base_url(); ?>custom/get_data/itemtype_master_edit/<?php echo $row->ItemTypeID; ?>'"
                                   
                                >
                                </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" value="<?php echo $row->ItemCode; ?>" style="width:850px;text-transform:uppercase" 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;" <?php echo $readonly_itemdesc; ?> ><?php echo $row->ItemDesc; ?></textarea>
                            </td>
                        </tr>
                       
                        <tr>
                        	<td><b>Unit</b></td>
                            <td style="padding:1px 0px 2px;">
                            	<input type="text" id="txt_unit" name="txt_unit" value="<?php echo $row->ItemUnit; ?>" style="width:850px;" <?php echo $readonly_unit; ?> /> 
                                <!-- <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;">
                            	<?php if($row->ItemPPhType == 0){ ?>
                                	<input name="rd_pph" type="Radio" value="1" <?php echo $disabled_type; ?> />Pph 22 
                                    <input name="rd_pph" type="Radio" value="0" <?php echo $disabled_type; ?> checked/>None
                         
                                 <?php }else{ ?>
                                 	<input name="rd_pph" type="Radio" value="1" <?php echo $disabled_type; ?> checked/>Pph 22 
                                    <input name="rd_pph" type="Radio" value="0" <?php echo $disabled_type; ?> />None
                                 <?php } ?>
                                <!-- <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;" value="<?php echo $row->ItemMerk; ?>"  />
                            </td>
                        </tr>
                        <tr>
                        	<td><b>Design</b></td>
                            <td style="padding:1px 0px 2px;">
                            	<input type="text" id="" name="txt_customfieldesign" style="width:850px;" value="<?php echo $row->ItemDesign; ?>"  />
                            </td>
                        </tr>
                        <tr>
                        	<td><b>Colour</b></td>
                            <td style="padding:1px 0px 2px;">
                            	<input type="text" id="" name="txt_customfieldcolour" style="width:850px;" value="<?php echo $row->ItemColour; ?>"  />
                            </td>
                        </tr>
                        <tr>
                        	<td><b>Size</b></td>
                            <td style="padding:1px 0px 2px;">
                            	<input type="text" id="" name="txt_customfieldsize" style="width:850px;" value="<?php echo $row->ItemSize; ?>"  />
                            </td>
                        </tr>
                        <tr>
                        	<td><b>Quality</b></td>
                            <td style="padding:1px 0px 2px;">
                            	<input type="text" id="" name="txt_customfieldquality" style="width:850px;" value="<?php echo $row->ItemQuality; ?>"  />
                            </td>
                        </tr>
                        <tr>
                        	<td><b>Type</b></td>
                            <td style="padding:1px 0px 2px;">
                            	<input type="text" id="" name="txt_customfieldtype" style="width:850px;" value="<?php echo $row->ItemType; ?>"  />
                            </td>
                        </tr>
                        <tr>
                        	<td><b>Shading</b></td>
                            <td style="padding:1px 0px 2px;">
                            	<input type="text" id="" name="txt_customfieldshading" style="width:850px;" value="<?php echo $row->ItemShading; ?>"  />
                            </td>
                        </tr>
                        <tr>
                        	<td><b>Group</b></td>
                            <td style="padding:1px 0px 2px;">
                            	<input type="text" id="" name="txt_customfieldgroup" style="width:850px;" value="<?php echo $row->ItemGroup; ?>"  />
                            </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 app-button" iconCls="icon-ok" onclick="custom_data('<?php echo $menu_link?>/approval_dir','#fm_new_item');" <?=($this->session->userdata("jobtitle_status") != 0 || !in_array($row->TransStatus,array(5,6)))?'disabled':''?>> App. Dir</a> 								
					<!--<a href="javascript:void(0)" class="easyui-linkbutton form-button app-button" iconCls="icon-ok" onclick="custom_data('<?php echo $menu_link?>/approval_mgr','#fm_new_item');" <?=($this->session->userdata("jobtitle_status") != 1 || !in_array($row->TransStatus,array(4,6)))?'disabled':''?>>App. Mgr</a>-->
					<a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-save" onclick="update_data()" <?=(!in_array($row->TransStatus,array(1,5)))?'disabled':''?> <?php echo $cek_autority_save;?>>Save</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($row->TransStatus,array(3,9)))?'disabled':''?>>Cancel</a>	    		
                </td>
             </tr>
         </table>
    </div>
    <?php endforeach; ?>
</div>

<script type="text/javascript">
function suspend(type){
	suspend_data_new_master('F',type,'<?php echo "list/items/"?>',$('#id').val(),'Item Master');
}

function cek_as_aset(value){
	if(value == 1){
		var asset = $('#id_asset').val('1');
		$.messager.alert('Error','Item Kategori tidak bisa berubah untuk fix asset','error',function(){
				
		});
	}
	else{
		if($('#id_asset').val() != 1){
			 var asset = $('#id_asset').val('0');
			$('#rdo_itemtype').combobox({
				value:'',
				valueField:'ItemTypeID',
				textField:'ItemTypeName',
				url:'<?php echo base_url(); ?>custom/get_data/itemtype_master_inventori'
			});
		}
	}
}

function update_data(){
	if($('#id_asset').val() == 1){
		if($('#trans_status').val() == 1){
			$.messager.alert('Error','Item Kategori tidak bisa berubah untuk fix asset','error',function(){
					
			});
		}
		else{
			edit_data('<?php echo $menu_link?>','#fm_new_item');
		}
	}
	else{
		edit_data('<?php echo $menu_link?>','#fm_new_item');
	}
}

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 hidefixed(value){
	if(value == 1){
		$('.disableme').css('display','');		
	}
	else{
		$('.disableme').css('display','none');
	}
} */
</script>