<!---- 
Author 	: Herpan / Tanggal : 12-08-2014	
Revisi 	: Ferry / Tanggal : 12-01-2015
Revisi 	: Fachri / Tanggal : 20-10-2015
Revisi 	: Dhidhik / Tanggal : 30-01-2016
-->
	<?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 width="100%" cellpadding="0" cellspacing="0">
                <tr>
                    <td align="left">
                        <!--<a href="#" class="easyui-linkbutton" iconCls="icon-document" plain="true" onclick="parent.tab_add('New Purchase Requisition', '<?=$menu_link?>', 'icon-add', 'add');">New</a>-->
                        <a href="#" class="easyui-linkbutton <?php echo $lables['button']['refresh']['classKey'];?>" id="refresh-linkbutton" data-options="plain:true,iconCls:'icon-reload'" onclick="location.reload();"><?php echo $lables['button']['refresh']['lable'];?></a>
                    </td>
                    
                    <td align="right">
                        <span class="form-title"><?=$menu_label?></span>
                    </td>
                </tr>
            </table>		     	
        </div>			
    </div>
    <!-- End of Top View -->
    
    <!-- Center 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_purchase_requisition" name="fm_purchase_requisition" method="post">
                <input type="hidden" name="detail" id="detail"/>
                <input type="hidden" name="status_item_type" id="status_item_type" value="0"/>
                
            	<!-- Form Header -->
                <table width="100%" height="140" cellpadding="0" cellspacing="0">
                    <tr>
                        <td width="50%" valign="top">&nbsp;</td>
                        
                        <td width="50%" valign="top">
                            <table width="100%" cellpadding="0" cellspacing="1" style="margin-top:4px;">
                                <tr height="20">
                                    <td rowspan="7" valign="top">&nbsp;</td>
                                    <td width="190" ></td>
                                    <td width="122" style="background:#333399;text-align:center;color:#FFF;">PR. Date</td>
                                    <td width="122" style="background:#333399;text-align:center;color:#FFF;">Department</td>
                                </tr>
                                
                                <tr height="20">
                                    <td></td>
                                    <td><input type="text" name="txt_preq_date" id="txt_preq_date" class="easyui-datebox validBackward" style="width:122px;height:20px;" value='<?= $pr_date ?>' required editable="false"/></td>
                                    
                                    <td>
                                        <select name="cmb_departement" id="cmb_departement" style="width:122px;height:20px;" class="easyui-combobox" editable="false" required readonly
                                            data-options="
                                                value: '<?=$this->session->userdata('department') ?>',
                                                valueField:'DepartmentCode', 
                                                textField:'DepartmentName', 
                                                url:'<?php echo base_url(); ?>custom/get_data/department'
                                            "/>
                                        </select>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
                <!-- End of form header -->
                
                <!-- Item Grid -->
                <div class="easyui-tabs" data-options="tabHeight:18" style="margin:5px 0px;">
                    <div title="Item">
                        <table toolbar="#tlb_dtg_item" id="dtg_item" class="easyui-edatagrid" title="" idField="id" rownumbers="true" 
                        fitColumns="true" singleSelect="true" style="height:250px;"
                        
                        >
                            <thead>
                                <tr>
                                    <th field="ItemCategoryID"   width="30"  editor="{type:'id_field',options:{readonly:true}}" hidden>Item Category ID</th>
                                    <th field="ItemCode"         width="50"  editor="{type:'item2',options:{required:true}}" data-options="align:'left',halign:'center'"><span id="theader_code">Item Code</span></th>
                                    <th field="ItemDesc"         width="200" editor="description" data-options="align:'left',halign:'center'"><span id="theader_name">Description</span></th>
                                    <th field="ItemQty"          width="30"  editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',groupSeparator:'.',min:0.01,required:true}}" formatter="formatRp" data-options="align:'center',halign:'center'">Qty</th>
                                    <th field="ItemUnit"         width="30"  editor="unit" data-options="align:'center',halign:'center'">Unit</th>
                                    <th field="RequiredDate"     width="35"  editor="{type:'datebox',options:{editable:false}}" data-options="align:'center',halign:'center'" hidden>Required Date</th>
                                    
                                    <th field="ItemType"         width="50"  editor="{type:'item_type',options:{required:true,min:0}}" data-options="align:'center',halign:'center'" hidden>Item Type</th>
                                    <th field="ItemPPh22Status"  width="50"  editor="{type:'pph22_status',options:{min:1}}" data-options="align:'center',halign:'center'" hidden>SVC PPh22 Status</th>
                                    <th field="ItemPPh23Status"  width="50"  editor="{type:'pph23_status',options:{min:1}}" data-options="align:'center',halign:'center'" hidden>SVC PPh23 Status</th>
                                    <th field="ItemAdvNetDueIn"  width="50"  editor="{type:'adv_netduein',options:{min:1}}" data-options="align:'center',halign:'center'" hidden>Net Due In</th>
                                    <th field="ItemCategoryCode" width="30"  editor="{type:'category_code',options:{readonly:true}}" hidden>Item Category Code</th>
                                    <th field="ItemStatus"       width="30"  editor="{type:'item_status',options:{readonly:true}}" hidden>Item Status</th>
                                </tr>
                            </thead>
                        </table>
                        
                        <div id="tlb_dtg_item">
                            <a href="#" class="easyui-linkbutton <?php echo $lables['button']['new']['classKey'];?>" iconCls="icon-add" id="icon-add" plain="true" onclick="addAndFocusDatagrid();" 
                                onKeyDown="if(event.keyCode == 13) {addAndFocusDatagrid();}"><?php echo $lables['button']['new']['lable'];?></a>
                            <a href="#" class="easyui-linkbutton <?php echo $lables['button']['delete']['classKey'];?>" iconCls="icon-remove" id="icon-remove" plain="true" onclick="remove_row();"><?php echo $lables['button']['delete']['lable'];?></a>								
                        </div>
                    </div>
                </div>
                <!-- End of item grid -->
                
                <table width="100%" cellpadding="0" cellspacing="0">
                    <tr>
                	<td width="50%" valign="top">
                            <table width="100%" cellpadding="0" cellspacing="1">
                                <tr>
                                    <td width="120" valign="top" style="padding-top:4px;"><b>Description</b></td>
                                    <td width="10" valign="top" style="padding-top:4px;"><b>:</b></td>

                                    <td>
                                        <textarea name="txa_preq_desc" id="txa_preq_desc" rows="4" style="width:335px;resize:none;"></textarea>
                                    </td>
                                </tr>
                            </table>
                        </td>
                        
                                            
                        <td width="50%" valign="top">&nbsp;</td>
                    </tr>
                </table>
            </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-document" onclick="show_legend();" plain="true">Legend</a>
                    <a href="javascript:void(0)" class="easyui-linkbutton <?php echo $lables['button']['help']['classKey'];?>" id="btn-help" iconCls="icon-help" onclick="" plain="true"><?php echo $lables['button']['help']['lable'];?></a>
                    <a href="javascript:void(0)" class="easyui-linkbutton <?php echo $lables['button']['save']['classKey'];?> form-button save-button" id="btn-save" iconCls="icon-save" onclick="insert_data();" <?php echo $cek_autority_save;?>><?php echo $lables['button']['save']['lable'];?></a>
                    <a href="javascript:void(0)" class="easyui-linkbutton <?php echo $lables['button']['close']['classKey'];?> form-button" id="btn-close" iconCls="icon-cancel" onclick="parent.tab_close('tt');"><?php echo $lables['button']['close']['lable'];?></a>	
                    <!--<a href="javascript:void(0)" class="easyui-linkbutton" onclick="indexSelectedRowDatagrid('dtg_item')"></a>-->
                </td>
            </tr>
        </table>
    </div>
    <?php $data['lables']=$lables; $this->load->view('v_popup_item_pr',$data); ?>
</div>

<?php $this->load->view('v_custom_pop_up');?>
<script type="text/javascript">
    var SavePrivillage 	= '<?php echo $group_user->SavePrivillage;?>';
    
//>>>>>>>>>>>>>>>>>>> TAMBAHAN DHIDHIK , 28/01/2016  <<<<<<<<<<<<<<<<<<<<<<<<<<<//

    var tempIndexEditRow = -1;// Nama variable Local, biarken nama variablenya spt ini, n ni value adlh value default,jd jgn dirubah ye... :D
    function setArrayPageStart(){ // nama function biar tetap seperti ini    , isi VALUE nya aja yang disesuaikan page masing-masing   
        //====== reset keytab ================//
        isArrayTabIndex     = -1;//default, jgn diganti valuenya
        isFormIdDatagrid    = "fm_purchase_requisition"; //nama id tag form yg ngapit grid yg mana grid-nya ada action editable,klo bukan editable ya kosongi saja ("")
        isIdNameDatagrid    = "dtg_item"; //nama id grid
        isFirstFieldName    = "ItemCode"; //nama field pertama yg ga hidden pada grid, atau saat editable yang akan di-focus-kan
        isArrayTab          = ["refresh-linkbutton","btn-close" ]; // urutan destiny tab, isinya value menunjukkan [idAwal, idAkhir]
        //======END reset keytab ==============//
    }
    function addAndFocusDatagrid(){//nama function ini boleh bebas, asal sama yg digunakan utk action di tombol new, isinya biarkan ini aja gpp
        var rstValid    = checkValidDatagrid(isFormIdDatagrid);//cek kevalid'an datagrid , biarken spt ini aja ye,,
        if(rstValid){ //execute apabila datagrid datanya valid
//            if(tempIndexEditRow>-1){//cek terlebih dahulu ada yang sedang diedit ato tidak, -1 berarti tidak ada yang sedang diedit, lbh dari -1 berarti ada yang sedang diedit
//                
//            }else{
//                $('#'+isIdNameDatagrid).edatagrid('addRow');//code dr easyui untuk menambah row 
//                var qtyRow                  = qtyRowDatagrid(isIdNameDatagrid);//untuk mendapatkan jumlah baris pada grid, dengan menggunakan function yang ada pd custom, dan parameter yang digunakan adalah id table grid
//                var dtg_item_last_index     = qtyRow - 1;  // mendapatkan index terakhir
//                $('#'+isIdNameDatagrid).datagrid('focusInvalidField', dtg_item_last_index);//focus ke editor yg blm diisi
//            }
            
            $('#'+isIdNameDatagrid).edatagrid('addRow');//code dr easyui untuk menambah row 
            var qtyRow                  = qtyRowDatagrid(isIdNameDatagrid);//untuk mendapatkan jumlah baris pada grid, dengan menggunakan function yang ada pd custom, dan parameter yang digunakan adalah id table grid
            var dtg_item_last_index     = qtyRow - 1;  // mendapatkan index terakhir
            $('#'+isIdNameDatagrid).datagrid('focusInvalidField', dtg_item_last_index);//focus ke editor yg blm diisi
        }
    }
    function focusFieldQtyDatagrid(){//focus ke field selanjutnya,klo ni function focus ke field qty setelah isi field item, bisa di modif sesuai kebutuhan
        var rowIndex = indexSelectedRowDatagrid(isIdNameDatagrid);//untuk mendapatkan jumlah baris pada grid, dengan menggunakan function yang ada pd custom, dan parameter yang digunakan adalah id table grid
        focusCellDatagrid(rowIndex,isIdNameDatagrid,"ItemQty"); //"ItemQty" adalah nama field setelah field Item,disesuaikan pada page masing-masing..
//        console.log("rowIndex="+rowIndex);
    }    
//>>>>>>>>>>>>>>>>>>>END TAMBAHAN DHIDHIK , 28/01/2016  <<<<<<<<<<<<<<<<<<<<<<<<<<<//

    $(document).ready(function(){
//>>>>>>>>>>>>>>>>>>> TAMBAHAN DHIDHIK , 28/01/2016  <<<<<<<<<<<<<<<<<<<<<<<<<<<//        
        setArrayPageStart(); // nama function biar tetap seperti ini, yg sudah didefinisikan diatas
//>>>>>>>>>>>>>>>>>>>END TAMBAHAN DHIDHIK , 28/01/2016  <<<<<<<<<<<<<<<<<<<<<<<<<<<//
        
	$('#cmb_departement').combobox('select','<?php echo  $this->session->userdata('department'); ?>');
	
	$('#dtg_item').datagrid({
            onBeginEdit:function(rowIndex){
                var editors             = $('#dtg_item').datagrid('getEditors', rowIndex);   
                var item_Code    	= $(editors[1].target);  // ItemType             
                var item_qty_editor     = $(editors[3].target);  // ItemQty
                var item_date_editor    = $(editors[5].target);  // date
                var item_type_editor    = $(editors[6].target);  // ItemType
                
                /*====================on beg in edit saat grid di klik maka tombol save disable===================*/
                save_button_begendedit(SavePrivillage);
                /*=================================end============================================================*/
			
                item_qty_editor.numberbox({
                    onChange:function(){
                        item_type       = item_type_editor.text('getData').val();
                        item_qty        = item_qty_editor.numberbox('getValue');
                      
                        if((item_type == 2) && (item_qty > 1)){
                            messageAlertBiasa('Warning', "Quantity untuk 'Advance Payment' tidak boleh lebih dari satu (1)",'error');
                            item_qty_editor.numberbox('setValue', 1);
                        }
                    }
                });
                
                //======tambahan Dhidhik , 28/01/2016                  
//                $(item_qty_editor).bind('keydown', function (e) { //menambah aksi keydown pada field qty, bisa dimodif sesuai kebutuhan tiap page masing2
//                    var code = e.keyCode || e.which;
//                    if (code == 13) {//tombol enter
//                        focusCellDateDatagrid(rowIndex,isIdNameDatagrid,"RequiredDate");//setelah tombol enter akan fokus ke field "RequiredDate"
//                    }
//                });              
                $(item_date_editor).datebox('textbox').bind('keydown', function (e) {//menambah aksi keydown pada field "RequiredDate", bisa di modif sesuai page masing2
                    var code = e.keyCode || e.which;
                    if (code == 13) {//tombol enter
                        $('#'+isIdNameDatagrid).datagrid('endEdit', rowIndex);//kalo focusnya di "RequiredDate" maka jika ditekan tombol enter akan endEdit ato dengan kata lain akan di saveRow
                    }
                });
                 
                if(tempIndexEditRow==-1){//yang ini biarkan tetap seperti ini, copy paste aje ye,cek ada indexRow yang diediting ga,,
                    tempIndexEditRow=rowIndex; //biarken seperti ini ye,ini untuk mendapatkan nomor indexRowGrid
                }else{ //biarken seperti ini ye
                    $('#'+isIdNameDatagrid).datagrid('endEdit', rowIndex);//biarken seperti ini ye,mengakhiri editing rowGrid
                    $("#"+isIdNameDatagrid).datagrid('selectRow', tempIndexEditRow); //biarken seperti ini ye, men-select rowGrid sesuai indexRownya
                }                 
                //=====end tambahan Dhidhik , 28/01/2016
            },
            
            onEndEdit: function(rowIndex){                
                var selectedrow     = $('#dtg_item').datagrid('getSelected');
                
                /*====================on beg in edit saat grid di klik maka tombol save disable===================*/
                save_button_endedit(SavePrivillage);
                /*=================================end============================================================*/
				
                if(selectedrow.ItemType == 2){
                    $('#tab_purchase_req').tabs('disableTab', 'Item');
					$('#tab_purchase_req').tabs('disableTab', 'Services / Expenses');
                }
                else{
					$('#tab_purchase_req').tabs('disableTab', 'Adv. Payment');
                }
                
                //==tambahan dhidhik, 30/01/2016                
                if(tempIndexEditRow==rowIndex){//yang ini biarkan tetap seperti ini, copy paste aje ye,cek indexRow yang masing editing apa sama dengan indexRow yang sekarang
                    tempIndexEditRow=-1;
                }
                //==end tambahan dhidhik, 30/01/2016
                
            },
            
            //tambahan Dhidhik , 28/01/2016
            onSelect:function(rowIndex){//ini event untuk mengatasi menutup di row lain yg diedit(tidak ada kosong), saat diselect di row lain, isinya event biarkan spt ini
                if(tempIndexEditRow>-1&&tempIndexEditRow!=rowIndex){//yang ini biarkan tetap seperti ini, copy paste aje ye,cek ada editing, indexRow yang select tp bukan indexRow yang diediting
                    $('#'+isIdNameDatagrid).datagrid('endEdit', rowIndex);//menyudahi(save row) editing pada rowGrid
                    $("#"+isIdNameDatagrid).datagrid('selectRow', tempIndexEditRow); //biarken seperti ini ye
                    checkValidDatagrid(isFormIdDatagrid); //biarken seperti ini ye, ngecek ke-valid-an inputan Grid...
                }
            }            
            //end tambahan Dhidhik , 28/01/2016
            
	});
	$('#fm_purchase_requisition').click(function(){//nama element sesuaiken saja di masing2 page...
            //$('#dtg_item').edatagrid('saveRow');
            var rstValid = checkValidDatagrid(isFormIdDatagrid); //biarken seperti ini ye
            if(rstValid){ //biarken seperti ini ye
                if(tempIndexEditRow>-1){ //biarken seperti ini ye
                    $('#'+isIdNameDatagrid).datagrid('endEdit', tempIndexEditRow); //biarken seperti ini ye
                }                    
            }else{ //biarken seperti ini ye
                $("#"+isIdNameDatagrid).datagrid('selectRow', tempIndexEditRow); //biarken seperti ini ye
            }
	});
	datagrid_item_type("dtg_item");//untuk warna grid
    });
    
	function choose_item() {
            if(mustBeChooseRowDatagrid('tt_choose_item')){//<<<<=== ini function dr customJs,value parameternya adalah id tablegrid,fungsinya adalah utk ngecek apakah udah keselect belum row datagrid-nya 
                var selected_data = $('#tt_choose_item').datagrid('getSelected');
		
		flag 				= true;
		item 				= $('#dtg_item').datagrid('getRows');
		$('#status_item_type').val(0);
		
		$.each(item, function(index,value){
			if(selected_data.ItemCode == value.ItemCode){
                            isStatusShortKey = false;
				$.messager.alert('Unseccessfull','Item sudah tersedia.','error',function(){
                                        isStatusShortKey = true;	
					$('#tt_choose_item').datagrid('reload'); 
				});
				flag = false;
			}
		});	
		
		if(flag != false){
			if($('input[name="rdo_ItemToggle"]:checked').val() == 1){
				$('.id').val(selected_data.ItemCategoryID);
			}
			
			$('.id_field').val(selected_data.ItemCategoryID);
			$('.item').val(selected_data.ItemCode);
			$('.description').val(selected_data.ItemDesc);
			$('.unit').val(selected_data.ItemUnit);
			$('.price').val(selected_data.ItemPrice);
			$('.warehouse_id').val(selected_data.ItemWHTypeID);
			$('.item_type').val($('#status_tab').val());
			$('.pph22_status').val(selected_data.ItemPPh22Status);
			$('.pph23_status').val(selected_data.ItemPPh23Status);
			$('.adv_netduein').val(selected_data.ItemAdvNetDueIn);
			$('.category_code').val(selected_data.ItemCategoryCode);
			$('.item_status').val(selected_data.ItemStatus);
		
			modal_close('dialog-item');
                        
                        //>>>>>>>>>>>>>>>>>>> TAMBAHAN DHIDHIK , 28/01/2016  <<<<<<<<<<<<<<<<<<<<<<<<<<<//
                        setArrayPageStart(); // saat modal close, set kembali settingan awal value variable global                 
                        focusFieldQtyDatagrid();//saat close akan terfocus ke field qty, ni function sudah didefinisikan di atas  
                        //>>>>>>>>>>>>>>>>>>>END TAMBAHAN DHIDHIK , 28/01/2016  <<<<<<<<<<<<<<<<<<<<<<<<<<<//
		}
            }
	}
	
	function choose_servis() {
            if(mustBeChooseRowDatagrid('tt_choose_servis')){//<<<<=== ini function dr customJs,value parameternya adalah id tablegrid,fungsinya adalah utk ngecek apakah udah keselect belum row datagrid-nya 
                var selected_data = $('#tt_choose_servis').datagrid('getSelected');
		
		flag 				= true;
		item 				= $('#dtg_item').datagrid('getRows');
		$('#status_item_type').val(0);
		
		$.each(item, function(index,value){
			if(selected_data.ItemCode == value.ItemCode){
                            isStatusShortKey = false;
				$.messager.alert('Unseccessfull','Item sudah tersedia.','error',function(){	
                                    isStatusShortKey = true;
					$('#tt_choose_servis').datagrid('reload'); 	
				});
				flag = false;
			}
		});	
		
		if(flag != false){
			if($('input[name="rdo_ItemToggle"]:checked').val() == 1){
				$('.id').val(selected_data.ItemCategoryID);
			}
			
			$('.id_field').val(selected_data.ItemCategoryID);
			$('.item').val(selected_data.ItemCode);
			$('.description').val(selected_data.ItemDesc);
			$('.unit').val(selected_data.ItemUnit);
			$('.price').val(selected_data.ItemPrice);
			$('.warehouse_id').val(selected_data.ItemWHTypeID);
			$('.item_type').val($('#status_tab').val());
			$('.pph22_status').val(selected_data.ItemPPh22Status);
			$('.pph23_status').val(selected_data.ItemPPh23Status);
			$('.adv_netduein').val(selected_data.ItemAdvNetDueIn);
			$('.category_code').val(selected_data.ItemCategoryCode);
			$('.item_status').val(selected_data.ItemStatus);
		
			modal_close('dialog-item');
                        
                        //>>>>>>>>>>>>>>>>>>> TAMBAHAN DHIDHIK  , 28/01/2016 <<<<<<<<<<<<<<<<<<<<<<<<<<<//
                        setArrayPageStart(); // saat modal close, set kembali settingan awal value variable global                 
                        focusFieldQtyDatagrid();//saat close akan terfocus ke field qty, ni function sudah didefinisikan di atas  
                        //>>>>>>>>>>>>>>>>>>>END  TAMBAHAN DHIDHIK  , 28/01/2016 <<<<<<<<<<<<<<<<<<<<<<<<<<<//
		}
            }
	}
	
	function choose_advance() {
            if(mustBeChooseRowDatagrid('tt_choose_advance')){//<<<<=== ini function dr customJs,value parameternya adalah id tablegrid,fungsinya adalah utk ngecek apakah udah keselect belum row datagrid-nya 
                var selected_data = $('#tt_choose_advance').datagrid('getSelected');
		
		flag 				= true;
		item 				= $('#dtg_item').datagrid('getRows');
		
		$('#status_item_type').val(1);
		
		$.each(item, function(index,value){
			if(selected_data.ItemCode == value.ItemCode){
                            isStatusShortKey = false;
				$.messager.alert('Unseccessfull','Item sudah tersedia.','error',function(){	
                                    isStatusShortKey = true;
					$('#tt_choose_advance').datagrid('reload'); 	
				});
				flag = false;
			}
		});	
		
		if(flag != false){
			if($('input[name="rdo_ItemToggle"]:checked').val() == 1){
				$('.id').val(selected_data.ItemCategoryID);
			}
			
			$('.id_field').val(selected_data.ItemCategoryID);
			$('.item').val(selected_data.ItemCode);
			$('.description').val(selected_data.ItemDesc);
			$('.unit').val(selected_data.ItemUnit);
			$('.price').val(selected_data.ItemPrice);
			$('.warehouse_id').val(selected_data.ItemWHTypeID);
			$('.item_type').val($('#status_tab').val());
			$('.pph22_status').val(selected_data.ItemPPh22Status);
			$('.pph23_status').val(selected_data.ItemPPh23Status);
			$('.adv_netduein').val(selected_data.ItemAdvNetDueIn);
			$('.category_code').val(selected_data.ItemCategoryCode);
			$('.item_status').val(selected_data.ItemStatus);
		
			modal_close('dialog-item');
                        
                        //>>>>>>>>>>>>>>>>>>> TAMBAHAN DHIDHIK , 28/01/2016  <<<<<<<<<<<<<<<<<<<<<<<<<<<//
                        setArrayPageStart(); // saat modal close, set kembali settingan awal value variable global                 
                        focusFieldQtyDatagrid();//saat close akan terfocus ke field qty, ni function sudah didefinisikan di atas  
                        //>>>>>>>>>>>>>>>>>>>END TAMBAHAN DHIDHIK , 28/01/2016  <<<<<<<<<<<<<<<<<<<<<<<<<<<//
		}
            }
	}

    function remove_row(){     
        if(mustBeChooseRowDatagrid('dtg_item')){//<<<<=== ini function dr customJs,value parameternya adalah id tablegrid,fungsinya adalah utk ngecek apakah udah keselect belum row datagrid-nya 
            var selectedrow     = $('#dtg_item').datagrid('getSelected');
            var row_index       = $('#dtg_item').datagrid('getRowIndex', selectedrow);
            isStatusShortKey = false;
            $.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============================================================*/

                        //==== tambah dhidhik,05/02/2016 
                        deleteRowDatagrid(tempIndexEditRow,isIdNameDatagrid);//parameter pertama adalah index yang teredit row nya, parameter kedua adalah id table datagrid                 
                        //====end tambah dhidhik,05/02/2016

                        var item = qtyRowDatagrid(isIdNameDatagrid);//<<<==== dhidhik,05/02/2016             
                        if(item == 0){
                            $('input[value="0"]').attr('disabled',false);
                            $('input[value="1"]').attr('disabled',false);
                            $('input[value="2"]').attr('disabled',false);

                            $('#tab_purchase_req').tabs('enableTab', 'Item');
                            $('#tab_purchase_req').tabs('enableTab', 'Services / Expenses');
                            $('#tab_purchase_req').tabs('enableTab', 'Adv. Payment');        						
                        }     
                    }
                    isStatusShortKey = true;
                }
            ); 
        }
    }
    
    function insert_data(){
		flag = true;
		if($('#status_item_type').val() == 1){
			item 				= $('#dtg_item').datagrid('getRows');
			$.each(item, function(index,value){
				if(value.ItemQty != 1){
					flag = false;
				}
			});	
		}
		
		if(flag == false){
			$.messager.alert('Unseccessfull','Maaf Item Qty Tidak Boleh Lebih/Kurang Dari (1) Satu, Untuk Adv. Payment','error',function(){	
				$('#dtg_item').datagrid('reload'); 	
			});
		}
		else{
			$('#dtg_item').edatagrid('saveRow');		
			var i       = $('#dtg_item').datagrid('getRows');
			var detail  = JSON.stringify(i);
			
			$("#detail").val(detail);
			save_transaction('<?php echo $menu_link?>','#fm_purchase_requisition');	
		}
    } 
</script>