<!---- 
    Author			: Hasan
    Created Date	: 03 Feb 2015
    Revision		: Fachri1) 
-->

	<?php
				//---------Untuk privellege jika dia ada tombol save----------
				if($group_user->SavePrivillage == 1){
					$cek_autority_save 		= "";
				}
				else{
					$cek_autority_save 		= "disabled";
				}
				
				//-------------end----------------------------
	?>	
	
<style>
table td{
	height: 20px;
}
</style>

<div class="easyui-layout" data-options="fit:true,border:false">
    <form id="fm_inv_adjustment" name="fm_inv_adjustment" method="post">
		<input type="hidden" name="detail" id="detail" />
        <!-- top view-->
        <div id="form-header" data-options="region:'north',border:false" >
            <div id="form-header-wrapper">
            <input type="hidden" id="Status_Tab" name="Status_Tab" value="0"/>
                <table cellpadding="0" cellspacing="0" width="100%" border="0">
                <tr>
                    <td align="left">
                        <a href="#" class="easyui-linkbutton" iconCls="icon-document" plain="true" onclick="parent.tab_add('New Adjustment','<?=$menu_link?>','icon-coa','add')">New</a>
						<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 top view -->	

    	<!-- center view -->
		<div id="form-body" data-options="region:'center',border:false">
            <div id="form-wrapper" class="easyui-panel"  style="width:1180px;height:526px;padding:5px;" fit='true'>
                <input type="hidden" name="" id="" value="" />
                <input type="hidden" name="akun_number" id="akun_number" />
                <table width="100%" height="141">
                <tr>
                    <td width="50%" valign="top">
                        <table width="100%" cellpadding="0" cellspacing="1">
                        <tr height="25">
                            <td width="100px"><b>Adj. Account</b></td>
                            <td colspan="3">
                            	<b>:</b>
                                <select name="cmb_adj_account" class="combo-grid" id="cmb_adj_account" required="required" style="width:302px;height:20px" 
										data-options="
											panelWidth: 302,
											idField: 'AccountNumber',
                                            textField: 'AccountName',
                                            
											url: '<?= base_url(); ?>list/adjustment/get_account_bycompany',
											method: 'get',
											columns: [[                
                                                {field:'AccountNumber',title:'AccountNumber',width:100},  
                                                {field:'AccountName',title:'Account Name',width:190}
                                            ]],
                                            
											fitColumns: true,
                                            onSelect: function(ind,rec){
                                                var AccountNumber = rec.AccountNumber;
                                                $('#akun_number').val(AccountNumber);
                                                search_items(AccountNumber);
                                                $('#dtg_adjust').datagrid('load',{
                                                    sq_no: 0
                                                });
                                            }
										">
								</select> 
                                
                            </td>
                            <td width="60"&nbsp;>&nbsp;</td>
                        </tr>
                        <tr height="25">
                            <td><b>Adj. Date</b></td>
                            <td><b> : </b> 
                            	<input name="txt_date" id="txt_date" type="text" value="<?php echo $date_now;?>" class="easyui-datebox validBackward" style="width:302px;height:20px" required editable="false" panelWidth="302"/>
                            </td>
                            <td colspan="2">
                            
                            </td>
                        </tr>
                        <tr>
                            <td valign="top"><b>Description</b></td>
                            <td valign="top"><b> : </b> 
                            	<textarea name="txa_description" id="txa_description" cols="40" rows="4" style="resize:none;margin-left:-0.2px;"></textarea>
                            </td>
                            <td colspan="2">
                            
                            </td>
                        </tr>
                        </table>
                    </td>
                    <td width="50%" valign="top">
                        <table width="100%" cellpadding="0" cellspacing="1">
                        <tr>
                        	<td height="20">&nbsp;</td>
                            <td width="731" align="center" valign="middle"></td>
                            <td width="250" align="center" valign="middle" ></td>
                            <td width="150" align="center" valign="middle" ></td>
                        </tr>
                       
                        <tr>
                            <td height="20">&nbsp;</td>
                            <td width="731" height="20" align="center" valign="middle">&nbsp;</td>
                            <td width="250" align="center" valign="middle">&nbsp;</td>
                            <td width="150" align="center" valign="middle">&nbsp;</td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                            <td height="20" align="left" valign="top">&nbsp;</td>
                            <td align="right" valign="top">&nbsp;</td>
                            <td align="right" valign="top">&nbsp;</td>
                        </tr>
                        <tr>
                            <td width="192" align="center" valign="middle">&nbsp;</td>
                            <td height="20" width="731" align="center" valign="middle">&nbsp;</td>
                            <td width="250" align="center" valign="middle">&nbsp;</td>
                            <td width="150" align="center" valign="middle">&nbsp;</td>
                        </tr>		
                        <tr>
                            <td align="left" valign="top">&nbsp;</td>
                            <td height="20" align="left" valign="top">&nbsp;</td>
                            <td height="20" align="left" valign="top">&nbsp;</td>
                            <td align="right" valign="top">&nbsp;</td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                        </table>
                    </td>
            	</tr>											
                </table>	

                <!--Item Grid -->
                <div class="easyui-tabs" data-options="tabHeight:18" id="tab_adjustment">
                    <div title="Qty Adjustment">
                        <table toolbar="#tb_dg_item" id="dtg_adjust" class="easyui-edatagrid" idField="id"
                            rownumbers="true" fitColumns="true" 
                            singleSelect="true" style="height:330px;" 
                            url="<?=base_url() . $menu_link . "/ajax_item"?>"
                            >
                            <thead>
                            <tr>
                            	<th width="40"  halign='center' field="ItemCode" 	data-options="align:'center'"  			editor="{type:'ItemCode',options:{disabled:true,required:true}}">Item Code</th>
                                <th width="80"  halign='center' field="Description" data-options="align:'left'"  			editor="{type:'description',options:{disabled:true}}">Item Description</th>
                                
                                <th width="40"  halign='center' field="Qty" 		data-options="align:'center'"  			editor="{type:'qty',options:{disabled:true, min:0}}" formatter="formatRp">Item Qty</th>
                                <th width="40"  halign='center' field="ControlQty" 	data-options="align:'center'"  			editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',required:true},min:0}" formatter="formatRp">Control Qty</th>
                            	
                                <th width="20"  halign='center' field="ItemUnit" 		data-options="align:'center'"  		editor="{type:'unit',options:{disabled:true}}">Item Unit</th>
                                
                                <th width="40"	halign="center" field="Hpp"				data-options="align:'left'" 		editor="{type:'Hpp',options:{decimalSeparator:',',
                                formatter:function(v){
                                	return v;
                                },
                                parser:function(s){
                                	var v = parseFloat(s);
                                    return v;
                                }
                                }}" hidden>Hpp</th>
                                
                                <th width="40"  halign='center' field="ItemCategoryID" data-options="align:'left'"  			editor="{type:'ItemCategoryID',options:{disabled:true}}" hidden>Item Category ID</th>
                                
                            </tr>
                            </thead>
                        </table>	
                        <div id="tb_dg_item">
                            <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add_row();">New</a>
                            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="remove_row_qty();">Delete</a>
                        </div>					
                    </div>
                    <div title="Value Adjustment">
                    	<table toolbar="#tb_dg_item_value" id="dtg_adjust_value" class="easyui-edatagrid" idField="id"
                            rownumbers="true" fitColumns="true" 
                            singleSelect="true" style="height:330px;" 
                            url="<?=base_url() . $menu_link . "/ajax_item"?>"
                            >
                            <thead>
                            <tr>
                            	<th width="40"  halign='center' field="ItemCode" 	data-options="align:'center'"  			editor="{type:'ItemCode',options:{disabled:true,required:true}}">Item Code</th>
                                <th width="80"  halign='center' field="Description" data-options="align:'left'"  			editor="{type:'description',options:{disabled:true}}">Item Description</th>
                                
                                <th width="40"  halign='center' field="Value" 			data-options="align:'center'"  		editor="{type:'value',options:{precision:2,decimalSeparator:',',disabled:true, min:0}}" formatter="formatRp">Item Value</th>
                                <th width="40"  halign='center' field="ControlValue" 	data-options="align:'center'"  		editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',required:true, min:0}}" formatter="formatRp">Control Value</th>
                                
                                <th width="20"  halign='center' field="ItemUnit" 		data-options="align:'center'"  		editor="{type:'unit',options:{disabled:true}}">Item Unit</th>
                                
                                <th width="40"	halign="center" field="Hpp"				data-options="align:'left'" 		editor="{type:'Hpp',options:{decimalSeparator:',',
                                formatter:function(v){
                                	return v;
                                },
                                parser:function(s){
                                	var v = parseFloat(s);
                                    return v;
                                }
                                }}" hidden>Hpp</th>
                                
                                <th width="40"  halign='center' field="ItemCategoryID" data-options="align:'left'"  			editor="{type:'ItemCategoryID',options:{disabled:true}}" hidden>Item Category ID</th>
                                
                            </tr>
                            </thead>
                        </table>	
                        <div id="tb_dg_item_value">
                            <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add_row();">New</a>
                            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="remove_row_value();">Delete</a>
                        </div>	
                    </div>
                </div>
                <!-- End Item Grid -->		

                	
            </div>
        </div>
        <div id="form-footer" data-options="region:'south',border:false">
			<table cellpadding="0" cellspacing="0" width="100%" height="100%" border="0">
				 <tr>
					<td align="right">    
                    	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-document" onclick="show_legend();" plain="true">Legend</a>                          
						 <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 save-button" 	iconCls="icon-save" 	onClick="save_me()" <?php echo $cek_autority_save;?>>Save</a> 	
                        <a href="javascript:void(0)" 	class="easyui-linkbutton form-button" 				iconCls="icon-cancel" 	onclick="parent.tab_close('tt');">Cancel</a>	
					</td>
				 </tr>
			</table>				
		</div>
    </form>
</div>

<!-- adjustment pop -->
<div id="dialog-adjustment" class="easyui-dialog" style="width:850px;height:523px;top:27px;background-color:#F8F8F8;padding:0px" closed="true" data-options="modal:true, iconCls:'icon-save'" buttons="#adjustment">
    <form id="form_job_cos" method="post" novalidate>
        <table width="100%" align="left" border="0">
            <!-----------tabel item kategori dari sini------------------------------------------------------------------------------->
            <tr>
                <td width="308"><b>Item Category</b></td>
                <td width="10"><b>:</b></td>

                <td>
                    <select name="cmb_ItemCategoryID" id="cmb_ItemCategoryID" class="easyui-combobox" style="width:502px;" editable="true" 
                        data-options="
                            valueField:'ItemCategoryID',
                            textField:'ItemCategoryName',
                            url:'<?=base_url()?>custom/get_data/itemcategory_adjustment',
                            onSelect: function(rec){
                                var id = rec.ItemCategoryID;
                                var akun_number = $('#akun_number').val();
                                search_all_item_adjust(akun_number);
                            }
                        ">
                    </select>
                </td>
            </tr>
			<!----------------------------end---------------------------------------------------------------------------------------->
            <tr>
                <td><b>Item Code</b></td>
                <td width="10"><b>:</b></td>
                
                <td>
                    <input type="text" style="width:500px;height:20px" name="txt_ItemCode" id="txt_ItemCode" class="easyui-validatebox" placeholder="Item Code" onkeyup="search_item();" />
                </td>
            </tr>
            
            <tr>
                <td><b>Item Name</b></td>
                <td><b>:</b></td>
            
                <td>
                    <input type="text" style="width:500px;height:20px" name="txt_ItemDesc" id="txt_ItemDesc" class="easyui-validatebox" placeholder="Item Name" onkeyup="search_desc();" />
                </td>
            </tr>
            
            <tr>
                <td colspan="3">
                    <table id="grid_pop_up" class="easyui-datagrid" singleSelect="true" remoteSort="false" rownumbers="true" style="width:828px;height:360px;"
                       url="<?Php echo base_url()?>custom/get_data/search_all_item_no_asset"
                        pageSize="50" 
                        data-options = "border:true,view:scrollview,autoRowheight:false"
                    >
                        <thead>
                            <tr bgcolor="">
                            	
                                <th halign="center" field="ItemCode" 			width="150" sortable="true">Item Code</th>
                                <th halign="center" field="ItemDesc" 			width="396" sortable="true">Item Description</th>
                                <th halign="center" field="ItemCategoryName" 	width="205" sortable="true">Item Category Name</th>
                                
                                <th halign="center" field="ItemUnit" 		width="70" sortable="true" 		hidden>Item Unit</th>
                                <th halign="center" field="ItemAverage" 	width="100%" sortable="true" 	hidden>Item Average</th>
                                <th halign="center" field="IsLock" 			width="90" sortable="true" 		hidden>Status</th>
                                <th halign="center" field="ItemCategoryID" 	width="200" sortable="true" 	hidden>ItemCategoryID</th>
                                <th halign="center" field="ItemQty" 		width="200" sortable="true" 	hidden>Item Qty</th>
                                <th halign="center" field="ItemLockId" 		width="200" sortable="true" 	hidden>Item Lock Id</th>
                                <th halign="center" field="ItemValue" 		width="100%" sortable="true" 	hidden>Item Value</th>
                            </tr>
                        </thead>
                    </table>
                </td>
            </tr>
        </table>
    </form>
</div>

<!-- Dialog Button -->
<div id="adjustment">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onClick="choose_adjustment_ok();">OK</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onClick="modal_close('dialog-adjustment');">Cancel</a>
</div>
<?php $this->load->view('v_custom_pop_up');?>
<script type="text/javascript">

var SavePrivillage  = '<?=$group_user->SavePrivillage;?>';

$(document).ready(function(){
	$('#tab_adjustment').tabs({
		border:true,
		onSelect:function(title){
			if(title == "Qty Adjustment"){
				$('#dtg_adjust').edatagrid({
					onBeginEdit:function(rowIndex){
						editors = $('#dtg_adjust').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============================================================*/
					}
				});
				$('#Status_Tab').val(0);
			}
			else{
				$('#dtg_adjust_value').edatagrid({
					onBeginEdit:function(rowIndex){
						editors = $('#dtg_adjust_value').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============================================================*/
					}
				});
				$('#Status_Tab').val(1);
				$('#fm_inv_adjustment').click(function(){
					$('#dtg_adjust_value').edatagrid('saveRow');
				});
			}
		}
	});
	
	if($('#Status_Tab').val() == 0){
		$('#dtg_adjust').datagrid({
			onBeginEdit:function(rowIndex){
				editors = $('#dtg_adjust').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============================================================*/
			}
		});
		
		$('#fm_inv_adjustment').click(function(){
			$('#dtg_adjust').edatagrid('saveRow');
		});
	}
});


function search_item(){
	var akun_number = document.fm_inv_adjustment.akun_number.value;
	search_all_item_adjust(akun_number);
}

function search_desc(){
	var akun_number = document.fm_inv_adjustment.akun_number.value;
	search_all_item_adjust(akun_number);
}

/*===================function save data===================================================*/
function save_me(){
	flag = true;
	
	if($('#Status_Tab').val() == 1){
		var item    = $('#dtg_adjust').datagrid('getRows');
		$.each(item, function( index, value ) {
			if(parseFloat(value.Value) == parseFloat(value.ControlValue)){
				$.messager.alert('Unseccessfull','Current Value tidak boleh sama dengan New Value','error',function(){});
				flag = false;
			}
			else if(value.ControlValue == ""){
				$.messager.alert('Unseccessfull','New Value tidak boleh kosong / tidak di isi','error',function(){});
				flag = false;
			}	
		});
		
		if(flag != false){
			$('#dtg_adjust_value').edatagrid('saveRow');
			var i		=	$('#dtg_adjust_value').datagrid('getRows');
			var items 	= 	JSON.stringify(i);
			$("#detail").val(items);
			
			save_transaction('<?php echo $menu_link?>','#fm_inv_adjustment');
		}
	}
	else{
		var item    = $('#dtg_adjust').datagrid('getRows');
		$.each(item, function( index, value ) {
			if(value.Qty == value.ControlQty){
				$.messager.alert('Unseccessfull','Current Qty tidak boleh sama dengan New Qty','error',function(){});
				flag = false;
			}
			else if(value.ControlQty == ""){
				$.messager.alert('Unseccessfull','New Qty tidak boleh kosong / tidak di isi','error',function(){});
				flag = false;
			}
		});
		
		if(flag != false){
			$('#dtg_adjust').edatagrid('saveRow');
			var i		=	$('#dtg_adjust').datagrid('getRows');
			var items 	= 	JSON.stringify(i);
			$("#detail").val(items);
			
			save_transaction('<?php echo $menu_link?>','#fm_inv_adjustment');
		}
	}
}
/*===============================end=======================================================*/

function search_items(AccounNumber){
   $('#grid_pop_up').datagrid('load',{
		AccounNumber : AccounNumber
	});	
	
	$('#cmb_ItemCategoryID').combobox({
		url: '<?=base_url()?>custom/get_data/itemcategory_adjustment/'+AccounNumber
	});
}


/*====================functiom remove row for adjutment qty========================================================*/
function remove_row_qty(){
	var selectedrow     = $('#dtg_adjust').datagrid('getSelected');
	var row_index       = $('#dtg_adjust').datagrid('getRowIndex', selectedrow);
	
	$.messager.confirm('Confirmation :', 'Anda yakin, Anda ingin menghapus item "' + selectedrow.ItemCode + '"?',  
		function(r){
			if (r){
				/*====================on beg in edit saat grid di klik maka tombol save disable===================*/
				$('.save-button').linkbutton('enable');
				/*=================================end============================================================*/
				var item = $('#dtg_adjust').datagrid('getData').total;
				if(item == 1){
					/*=================================saat button ok di klik maka langsung disable to item di tab=====================*/
					$('#tab_adjustment').tabs('enableTab', 'Value Adjustment');
					/*======================================end========================================================================*/
				}
				$('#dtg_adjust').datagrid('deleteRow', row_index);
			}
		}
	);
}
/*================================end===============================================================*/

/*====================functiom remove row for adjutment qty========================================================*/
function remove_row_value(){
	var selectedrow     = $('#dtg_adjust_value').datagrid('getSelected');
	var row_index       = $('#dtg_adjust_value').datagrid('getRowIndex', selectedrow);
	
	$.messager.confirm('Confirmation :', 'Anda yakin, Anda ingin menghapus item "' + selectedrow.ItemCode + '"?',  
		function(r){
			if (r){
				/*====================on beg in edit saat grid di klik maka tombol save disable===================*/
				$('.save-button').linkbutton('enable');
				/*=================================end============================================================*/
				var item = $('#dtg_adjust_value').datagrid('getData').total;
				if(item == 1){
					/*=================================saat button ok di klik maka langsung disable to item di tab=====================*/
					$('#tab_adjustment').tabs('enableTab', 'Qty Adjustment');
					/*======================================end========================================================================*/
				}
				$('#dtg_adjust_value').datagrid('deleteRow', row_index);
			}
		}
	);
}
/*================================end===============================================================*/

/*=============onclick saat colom item di klik ======================================================*/
$.extend($.fn.datagrid.defaults.editors, {
    ItemCode: {
        init: function(container, options){
            var input = $('<input type="text" class="ItemCode" onClick="open_adjustment()" style="height:18px;" readonly/>').appendTo(container);
            return input.validatebox(options);
        },
        destroy: function(target){
            $(target).remove();
        },
        getValue: function(target){
            return $(target).val();
        },
        setValue: function(target, value){
            $(target).val(value);
        },
        resize: function(target, width){
            $(target)._outerWidth(width);
        }
    },
	qty: {
        init: function(container, options){
            var input = $('<input type="text" class="qty" style="height:18px;" readonly/>').appendTo(container);
            return input.validatebox(options);
        },
        destroy: function(target){
            $(target).remove();
        },
        getValue: function(target){
            return $(target).val();
        },
        setValue: function(target, value){
            $(target).val(value);
        },
        resize: function(target, width){
            $(target)._outerWidth(width);
        }
    },
	value: {
        init: function(container, options){
            var input = $('<input type="text" class="value" style="height:18px;" readonly/>').appendTo(container);
            return input.validatebox(options);
        },
        destroy: function(target){
            $(target).remove();
        },
        getValue: function(target){
            return $(target).val();
        },
        setValue: function(target, value){
            $(target).val(value);
        },
        resize: function(target, width){
            $(target)._outerWidth(width);
        }
    },
	Ctrlvalue: {
        init: function(container, options){
            var input = $('<input type="text" class="value" style="height:18px;" readonly/>').appendTo(container);
            return input.validatebox(options);
        },
        destroy: function(target){
            $(target).remove();
        },
        getValue: function(target){
            return $(target).val();
        },
        setValue: function(target, value){
            $(target).val(value);
        },
        resize: function(target, width){
            $(target)._outerWidth(width);
        }
    },
	Hpp: {
        init: function(container, options){
            var input = $('<input type="text" class="Hpp" style="height:18px;" readonly/>').appendTo(container);
            return input.validatebox(options);
        },
        destroy: function(target){
            $(target).remove();
        },
        getValue: function(target){
            return $(target).val();
        },
        setValue: function(target, value){
            $(target).val(value);
        },
        resize: function(target, width){
            $(target)._outerWidth(width);
        }
    },
	ItemCategoryID: {
        init: function(container, options){
            var input = $('<input type="text" class="ItemCategoryID" style="height:18px;" readonly/>').appendTo(container);
            return input.validatebox(options);
        },
        destroy: function(target){
            $(target).remove();
        },
        getValue: function(target){
            return $(target).val();
        },
        setValue: function(target, value){
            $(target).val(value);
        },
        resize: function(target, width){
            $(target)._outerWidth(width);
        }
    },
	description: {
        init: function(container, options){
            var input = $('<input type="text" class="description" style="height:18px;" readonly/>').appendTo(container);
            return input.validatebox(options);
        },
        destroy: function(target){
            $(target).remove();
        },
        getValue: function(target){
            return $(target).val();
        },
        setValue: function(target, value){
            $(target).val(value);
        },
        resize: function(target, width){
            $(target)._outerWidth(width);
        }
    },
	unit: {
        init: function(container, options){
            var input = $('<input type="text" class="unit" style="height:18px;" readonly/>').appendTo(container);
            return input.validatebox(options);
        },
        destroy: function(target){
            $(target).remove();
        },
        getValue: function(target){
            return $(target).val();
        },
        setValue: function(target, value){
            $(target).val(value);
        },
        resize: function(target, width){
            $(target)._outerWidth(width);
        }
    }
	
});
/*============================================end================================================================*/

function add_row(){
	if($('#cmb_adj_account').combogrid('getValue')  == ""){
		$.messager.alert('Unseccessfull','Silahkan pilih Adjustment Account terlebih dahulu','info',function(){	
		});
	}
	else{
		if($('#Status_Tab').val() == 0){
			$('#dtg_adjust').edatagrid('addRow');
		}
		else{
			$('#dtg_adjust_value').edatagrid('addRow');
		}
	}
}

/*========================open pop up item code=======================================*/
function open_adjustment() { 
   modal_open('Item','dialog-adjustment');
}
/*======================end============================================================*/

/*==================================jika di klik tombol ok di pop up================================*/
function choose_adjustment_ok(){
	var selected_data=$('#grid_pop_up').datagrid('getSelected');
	
	if(selected_data.ItemLockId == 1){
		$.messager.alert('Unseccessfull','Item sedang proses Adjustment','error',function(){	
			$('#grid_pop_up').datagrid('reload'); 
		});
	}
	else{
		if($('#Status_Tab').val() == 0){
			choose_adjusment();
		}
		else{
			choose_adjusment_value();
		}
	}
}
/*============================end===================================================================*/

/*=============saat di pilih pop up ok ambil item code dan item desc=================================*/
function choose_adjusment() {
    var selected_data=$('#grid_pop_up').datagrid('getSelected');	
	
    flag = true;
    item = $('#dtg_adjust').datagrid('getRows');

    $.each(item, function(index,value){
        if(selected_data.ItemCode == value.ItemCode){
            $.messager.alert('Unseccessfull','Item sudah tersedia.','error',function(){	
                $('#grid_pop_up').datagrid('reload'); 	
            });
   
            flag = false;
        }
    });
	
    if(flag != false){
		
		$('.ItemCode').val(selected_data.ItemCode);
		$('.description').val(selected_data.ItemDesc);
		$('.unit').val(selected_data.ItemUnit);
		$('.ItemCategoryID').val(selected_data.ItemCategoryID);
		$('.Hpp').val(selected_data.ItemAverage);
		$('.qty').val(selected_data.ItemQty);
	
        modal_close('dialog-adjustment');
		
		/*=================================saat button ok di klik maka langsung disable to item di tab=====================*/
		$('#tab_adjustment').tabs('disableTab', 'Value Adjustment');
		/*======================================end========================================================================*/
    }
}

/*=====================end===================================================================================*/

/*=============saat di pilih pop up ok ambil item code dan item desc=================================*/
function choose_adjusment_value() {
    var selected_data=$('#grid_pop_up').datagrid('getSelected');	
	
    flag = true;
    item = $('#dtg_adjust_value').datagrid('getRows');

    $.each(item, function(index,value){
        if(selected_data.ItemCode == value.ItemCode){
            $.messager.alert('Unseccessfull','Item sudah tersedia.','error',function(){	
                $('#grid_pop_up').datagrid('reload'); 	
            });
   
            flag = false;
        }
    });
	
    if(flag != false){
		$('.ItemCode').val(selected_data.ItemCode);
		$('.description').val(selected_data.ItemDesc);
		$('.unit').val(selected_data.ItemUnit);
		$('.ItemCategoryID').val(selected_data.ItemCategoryID);
		$('.Hpp').val(selected_data.ItemAverage);
		$('.value').val(selected_data.ItemValue);
	
        modal_close('dialog-adjustment');
		
		/*=================================saat button ok di klik maka langsung disable to item di tab=====================*/
		$('#tab_adjustment').tabs('disableTab', 'Qty Adjustment');
		/*======================================end========================================================================*/
    }
}

/*=====================end===================================================================================*/
</script>