<!---- 
    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";
				}
				
				if($group_user->JournalPrivillage == 1){
					$cek_autority_journal  = "";
				}
				else{
					$cek_autority_journal	= "disabled";
				}
				
				if($group_user->DeletePrivillage == 1){
					$cek_autority_delete  = "";
				}
				else{
					$cek_autority_delete	= "disabled";
				}
				
				if($group_user->ReversePrivillage == 1){
					$cek_autority_reverse  = "";
				}
				else{
					$cek_autority_reverse	= "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" />
		<input type="hidden" name="detail_item" id="detail_item" />
        <!-- 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" width="30%">
							<?php foreach($adjustment as $row): ?>
                            <input type="checkbox" class="easyui-checkbox" name="chk_suspended" id="chk_suspended" style="margin-top:0px;margin-right:1px;" onClick="suspend(1)" <?php if($row->status == 3){ echo"checked"; } ?> <?=(!in_array($row->status,array(5,6)) || $row->AppLevel2Status == 1) ? 'disabled' : ''?> <?php echo $cek_autority_delete;?>/>
                    		<span style="display:inline-block;margin-top:2px;<?=(($row->AppLevel2Status!=0)?'color:gray;':'')?>"><?=(($row->status!=3)?"Suspend":"Suspend")?></span>
                        	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-journal" plain="true"  id="btn_journal" 
                                onclick="parent.tab_add('Preview Journal <?=$menu_label?>', '<?php echo $menu_link; ?>', 'icon-print', 'to_journal/<?php echo $row->IAdjNumber ?>')" <?php echo $cek_autority_journal;?>>Journal
                            </a>
							<?php endforeach;?>
                            <a href="#" class="easyui-linkbutton" id="refresh-linkbutton" data-options="plain:true,iconCls:'icon-reload'" onclick="location.reload();">Refresh</a>
						</td>
                        <td align="center" width="40%"><span id="approval_information">
						<?php
                        if($row->status==5){
                            echo get_status_approval_header($row->status);
                        }
                        ?>
                        </span></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" data-options="region:'center',border:false">
            <div id="form-wrapper" class="easyui-panel"  style="width:1180px;height:526px;padding:5px;" fit='true'>
            <?php if(in_array($row->status,array(1,2,3,9))){ ?>
                	<div class="blanket"></div>
                	<div class="status-box"><b><?php if($row->status==2){ echo 'Finished'; }elseif($row->status==3){ echo 'Suspended'; }elseif($row->status==1){ echo 'On Progres'; }elseif($row->status==9){ echo 'Canceled by Dir.'; }else{ echo 'Unknown'; } ?></b></div>
            	<?php } ?>
            <?php foreach($adjustment as $row_detail):?>
                <input type="hidden" name="" id="" value="" />
                <input type="hidden" name="branch_code_hidden" id="branch_code_hidden" value="<?php echo $row_detail->BranchCode;?>" />
                <input type="hidden" name="Status_Tab" id="Status_Tab" value="<?php echo $row_detail->StatusCheck;?>" />
                <input type="hidden" name="detail_id" id="detail_id">
                <input type="hidden" name="created_by" id="created_by" value="<?php echo $row_detail->CreatedBy;?>">
                <input type="hidden" name="TransStatus" id="TransStatus" value="<?php echo $row_detail->status;?>">
                <table width="100%" height="141">
                <tr>
                    <td width="50%" valign="top">
                        <table width="100%" cellpadding="0" cellspacing="1">
                        <tr height="25">
                            <td><b>Adj Number</b></td>
                            <td><b> : </b> 
                            	<input type="text" name="txt_adjust_number" id="txt_adjust_number" class="easyui-validatebox" required="required" 
											value="<?php echo $row_detail->IAdjNumber;?>" style="width:302px;background-color:#E3E2E2;" readonly />
                            </td>
                            <td colspan="2">
                            
                            </td>
                        </tr>
                        <tr height="25">
                            <td width="100px"><b>Adj. Account</b></td>
                            <td colspan="3">
                            	<b>:</b>
                                <select name="cmb_adj_account" readonly = 'true' class="easyui-combobox" id="cmb_adj_account" required="required" style="width:302px;height:20px" 
										data-options="
											editable:false,
											panelWidth: 302,
                                            value     :'<?php echo $row_detail->IAdjAccountNumber;?>',
											valueField: 'AccountNumber',
                                         
											textField: 'AccountName',
                                            
											url: '<?php echo base_url(); ?>list/adjustment/get_account_bycompany',
											method: 'get',
											columns: [[
											{field:'AccountName',title:'Account Name',width:190}
											]],
											fitColumns: true
										">
								</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 $row_detail->IAdjDate;?>" class="easyui-datebox validBackward" style="width:302px;height:20px" required editable="false" readonly panelWidth="302"/>
                            </td>
                            <td colspan="2">
                            
                            </td>
                        </tr>
                        <tr>
                            <td valign="top"><b>Description</b></td>
                            <td><b> : </b> 
                            	<textarea name="txa_description" id="txa_description" cols="40" rows="4" style="resize:none;margin-left:-0.2px;"><?php echo $row_detail->IAdjDesc;?></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 align="center" valign="top">&nbsp;</td>
                            <td align="right" valign="top">
                            
                            </td>
                            <td align="left" valign="top">
                            	
                            </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="<?php echo base_url()?>list/adjustment/get_data_grid/<?php echo $row_detail->IAdjNumber;?>"
                            >
                            <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>
                                <th width="40"  halign='center' field="IAdjDetailID" 	data-options="align:'left'"  		editor="{type:'IAdjDetailID',options:{disabled:true}}" hidden>Adj Detail ID</th>
                                <th width="40"	halign="center" field="ValueInv"		data-options="align:'left'" 		editor="{type:'numberbox',options:{decimalSeparator:',',
                                formatter:function(v){
                                	return v;
                                },
                                parser:function(s){
                                	var v = parseFloat(s);
                                    return v;
                                }
                                }}"hidden >Item Value</th>
                            </tr>
                            </thead>
                        </table>	
                        <div id="tb_dg_item">
                            <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="<?php echo base_url()?>list/adjustment/get_data_grid/<?php echo $row_detail->IAdjNumber;?>"
                            >
                            <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>
                                <th width="40"  halign='center' field="IAdjDetailID" data-options="align:'left'"  			editor="{type:'IAdjDetailID',options:{disabled:true}}" hidden>Adj Detail ID</th>
                                <th width="40"	halign="center" field="QtyInv"		data-options="align:'left'" 			editor="{type:'numberbox',options:{decimalSeparator:',',
                                formatter:function(v){
                                	return v;
                                },
                                parser:function(s){
                                	var v = parseFloat(s);
                                    return v;
                                }
                                }}" hidden>Item Qty</th>
                            </tr>
                            </thead>
                        </table>	
                        <div id="tb_dg_item_value">
                            <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="left">
						
				   </td>
					<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 app-button" iconCls="icon-ok" onclick="app_dir()" <?=($this->session->userdata("jobtitle_status") != 0 || !in_array($row_detail->status,array(5,6)))?'disabled':''?>>App. Dir </a>
						
                        <?php
						if(($group_user->ReversePrivillage == 1)){
						?>
						<a href="javascript:void(0)" class="easyui-linkbutton form-button app-button" iconCls="icon-reload" onclick="app_reverse()" <?=(($this->session->userdata("jobtitle_status") == 0) && (in_array($row_detail->status,array(1,2,8))))?'':'disabled'?>>Reverse</a>  
						<?php
						}
						?>
                        <a href="javascript:void(0)" class="easyui-linkbutton form-button save-button" iconCls="icon-save" onclick="update_adjustment()" <?=(in_array($row_detail->status,array(0,1,2,3)))?'disabled':''?> <?php echo $cek_autority_save;?>>Save</a> 								
						<a id="print_button" href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-print" onclick="parent.tab_edit('Print Inventory Adjustment', '<?php echo $menu_link; ?>', 'icon-print', 'to_print_detail','<?php echo $row_detail->IAdjNumber;?>')" <?=(in_array($row_detail->status,array(4,5,6,1,2,3,9)))?'':'disabled'?>>Preview & Print</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_detail->status,array(0,5,6)))?'disabled':''?>><?=($this->session->userdata('jobtitle_status')==0)?'Cancel':'Close'?></a>	
		
					</td>
				 </tr>
			</table>				
		</div>
    </form>
</div>
<?php endforeach;?>		
<?php $this->load->view('v_custom_pop_up');?>
<script type="text/javascript">

/*========================deklar variabel array for remove===================*/
var SavePrivillage      = '<?=$group_user->SavePrivillage;?>';
var array_item          = [];
var array_detail_item   = [];
/*==============================end=========================================*/

$(document).ready(function(){
	if($('#Status_Tab').val() == 0){
		$('#tab_adjustment').tabs('disableTab', 'Value Adjustment');
	   	$('#tab_adjustment').tabs('enableTab', 'Qty Adjustment');
		$('#tab_adjustment').tabs('select', 'Qty Adjustment');
		
		$('#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');
		});
	}
	else{
		$('#tab_adjustment').tabs('disableTab', 'Qty Adjustment');
	   	$('#tab_adjustment').tabs('enableTab', 'Value Adjustment');
		$('#tab_adjustment').tabs('select', 'Value Adjustment');
		
		$('#dtg_adjust_value').datagrid({
			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============================================================*/
			}
		});
		
		$('#fm_inv_adjustment').click(function(){
			$('#dtg_adjust_value').edatagrid('saveRow');
		});
	}
});

/*===================function save data===================================================*/
function update_adjustment(){
	var url             = '<?= base_url();?>custom/custom/checking_update';
	var no_transaksi    = $('#txt_adjust_number').val();
	var trans_status 	= $('#TransStatus').val();
	
	var created_by 		= $('#created_by').val();
	var login_as 		= '<?php echo$this->session->userdata('username');?>';
	var job_title 		= '<?php echo $this->session->userdata('jobtitle_status');?>';
		
	flag = true;
	if($('#Status_Tab').val() == 1){
		var item    = $('#dtg_adjust_value').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);
			
			edit_transaction_check('<?=$menu_link?>','#fm_inv_adjustment', no_transaksi, url, trans_status,created_by, login_as, job_title);
		}
	}
	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);
			
			edit_transaction_check('<?=$menu_link?>','#fm_inv_adjustment', no_transaksi, url, trans_status,created_by, login_as, job_title);
		}
	}
}
/*===============================end=======================================================*/

/*=============onclick saat colom item di klik ======================================================*/
$.extend($.fn.datagrid.defaults.editors, {
    ItemCode: {
        init: function(container, options){
            var input = $('<input type="text" class="ItemCode" 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);
        }
    },
	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);
        }
    }
});
/*============================================end================================================================*/

/*=================suspen data transaksi===========================================================*/
function suspend(type){
	var created_by 		= $('#created_by').val();
	var login_as 		= '<?php echo$this->session->userdata('username');?>';
	var job_title 		= '<?php echo $this->session->userdata('jobtitle_status');?>';
	var url             = '<?= base_url();?>custom/custom/checking_suspend';
	
	suspend_check_trans('F', type, '<?=$menu_link?>', $('#txt_adjust_number').val(), 'Adjustment', url, created_by, login_as, job_title);
}
/*==================================end=====================================================*/

function app_reverse(){
	var no_transaksi    = $('#txt_adjust_number').val();

	checking_reverse(no_transaksi,function(check){
		
		if(check.status == true){
			var i       = $('#dtg_adjust').datagrid('getRows');
			var detail  = JSON.stringify(i);
	
			$("#detail").val(detail);
			reverse_data_by_detail('<?php echo $menu_link?>','#fm_inv_adjustment');
		}else{
		   $.messager.alert('Unseccessfull',check.message,'error',function(){
				location.reload();
			});
		}
	});
}

/*============================function saat app dir======================================================================*/
function app_dir() {
	var url_check           = '<?= base_url();?>custom/custom/checking_approval';
	var no_transaksi    	= $('#txt_adjust_number').val();
	
	checking_approval(no_transaksi,function(check){
		if(check.status == false){
			approval();
		}else{
			$.messager.alert('Unseccessfull',check.message,'error',function(){
				location.reload();
			});
		}
	});
}

function approval(){
	$('#dtg_adjust').edatagrid('saveRow');
	var i=$('#dtg_adjust').datagrid('getRows');
	var items = JSON.stringify(i);
	$("#detail").val(items);
	custom_data('<?php echo $menu_link;?>/approve_dir','#fm_inv_adjustment');
}
/*================================end=====================================================================================*/

function remove_row_qty(){
	var item = $('#dtg_adjust').datagrid('getData').total;

	if(item <= 1){
		$.messager.alert('Warning','Anda tidak dapat menghapus list item, minimum list item adalah satu (1)','error');
		/*====================on beg in edit saat grid di klik maka tombol save disable===================*/
		$('.save-button').linkbutton('enable');
		/*=================================end============================================================*/
	}
	else {
		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){
					array_item.push(selectedrow.IAdjDetailID);
					array_detail_item.push(selectedrow.IAdjDetailID, selectedrow.ItemCode);
					
                   	$("#detail_id").val(JSON.stringify(array_item));
					$("#detail_item").val(JSON.stringify(array_detail_item));
					
                   	$('#dtg_adjust').datagrid('deleteRow', row_index);
					/*====================on beg in edit saat grid di klik maka tombol save disable===================*/
					$('.save-button').linkbutton('enable');
					/*=================================end============================================================*/
				}
			}
		);        
					
	}            
}

function remove_row_value(){
	var item = $('#dtg_adjust_value').datagrid('getData').total;

	if(item <= 1){
		$.messager.alert('Warning','Anda tidak dapat menghapus list item, minimum list item adalah satu (1)','error');
		/*====================on beg in edit saat grid di klik maka tombol save disable===================*/
		$('.save-button').linkbutton('enable');
		/*=================================end============================================================*/
	}
	else {
		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){
					array_item.push(selectedrow.IAdjDetailID);
					array_detail_item.push(selectedrow.IAdjDetailID, selectedrow.ItemCode);
					
                   	$("#detail_id").val(JSON.stringify(array_item));
					$("#detail_item").val(JSON.stringify(array_detail_item));
					
                   	$('#dtg_adjust_value').datagrid('deleteRow', row_index);
					/*====================on beg in edit saat grid di klik maka tombol save disable===================*/
					$('.save-button').linkbutton('enable');
					/*=================================end============================================================*/
				}
			}
		);        
					
	}            
}
</script>