<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>    
	
</head>
 <body> 
<div id="container_st_inv" style="height:100%; margin:0px; padding:0px;overflow:'hidden'; border: 0px solid #cd0a0a">
	<div class="pane-header ui-state-active" id="st_inv_bar" >  
        <button id="btnstloaddata" style="color:#FF0000;" >Load Data</button>
		<button id="btnstviewdetail">View</button>
        <button id="btnstproses">Approval</button>
        <button id="btnstapproveselected">Approve Selected</button>
        <?php if($this->session->userdata('DX_username') == 'ojah' || $this->session->userdata('DX_username') == 'admin'  || $this->session->userdata('DX_username') == 'yayan'  ){ ?>  
			<button id="btndeletedatavgi">Cancel Data</button>	
			<button id="btnexceldatavgi">Export Excel</button>	
		<?php } ?>
    </div> 
<table id="tblsthdr"></table> <!--Grid table-->
<div id="ptblsthdr"></div>  <!--pagination div--> 
</div>
<script>
	$(document).ready(function(){
	
		$(window).bind('resize', function() {  
			setTimeout(function(){
				setGridHight($("#tblsthdr"),$("#container_st_inv"),$("#st_inv_bar")); 
			},10); 
		});

		$("#btndeletedatavgi").button().click(function(){
			var id = jQuery("#tblsthdr").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblsthdr").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};
			
			/* if (ret.status == 'APPROVED' ){
				alert("Ga bisa didelete Sudah APproved ");
				return false;
			} */
			
			var form_data = {
				id_data_out_hdr:ret.id_data_out_hdr,
				id_terkait:ret.id_terkait,
				doc_out_to_id:ret.doc_out_to_id
			};
			
			$("#dlg_st_delete_selected").dialog( "destroy" );
			$(".dlg_st_delete_selected_cl").remove();
			$(".dlg_st_delete_selected_cl").html('');
			$("body").append('<div id="dlg_st_delete_selected" title="Warning" class="dlg_st_delete_selected_cl"><p><b>Mbak...'+ '<?php echo $this->session->userdata('DX_username'); ?>' + '</b> Apakah anda yakin akan melakukan Delete Selected Data  ..? *Data Akan diambil yang belum approved aja..</p><br />Mohon diperiksa kembali datanya.</div>');
			$("#dlg_st_delete_selected").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'inventory/ct_stock_transfer/st_process_delete_selected'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlg_st_delete_selected").dialog("close");
								$('#dlg_st_delete_selected').dialog("destroy"); 
								$(".dlg_st_delete_selected_cl").remove(); 
								$(".dlg_st_delete_selected_cl").html('');
								$("#tblsthdr").trigger('reloadGrid');
								
							} else { 
								alert(msg.sts+msg.desc); 
								$("#dlg_st_delete_selected").dialog("close");
								$('#dlg_st_delete_selected').dialog("destroy"); 
								$(".dlg_st_delete_selected_cl").remove(); 
								
							}
						}
					});
				},
					"CANCEL": function() {
						$( "#dlg_st_delete_selected" ).dialog( "close" );

					}
				},
				close : function(){
					$('#dlg_st_delete_selected').dialog("destroy"); 
					$(".dlg_st_delete_selected_cl").remove(); 
					//$("body").append('<div id="dlg_st_delete_selected" title="Warning" class="dlg_st_delete_selected_cl"><p>Apakah anda yakin akan memproses data mesin sparepart  '+ ret.filename  +'..?</p><br />Mohon diperiksa kembali datanya.</div>.</div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
			
		
		});
		
		$("#btnstapproveselected").button().click(function(){
		
			var ids = $("#tblsthdr").getGridParam('selarrrow');
			var count = ids.length;
			if (count>0) {
				var names = [];
				for (var i=0, il=ids.length; i < il; i++) {
					//var name = $grid.jqGrid('getCell', ids[i], 'invoice_no');
					var rowData = $("#tblsthdr").jqGrid('getRowData', ids[i]);
					//names.push(rowData.invoice_no);	
					names.push(rowData);
					//alert(rowData.invoice_date + '------');
				}
			} else {
				
				return false;
			} 
			
			
			var postData = JSON.stringify(names);
			
						
			
			//var gridData = $grid.getRowData();
			//var postData = JSON.stringify(gridData);
			var form_data;
			form_data = {
				postData:postData
			};
						
			$("#dlg_st_approve_selected").dialog( "destroy" );
			$(".dlg_st_approve_selected_cl").remove();
			$(".dlg_st_approve_selected_cl").html('');
			$("body").append('<div id="dlg_st_approve_selected" title="Warning" class="dlg_st_approve_selected_cl"><p>Apakah anda yakin akan melakukan Approved Selected Data  ..? *Data Akan diambil yang belum approved aja..</p><br />Mohon diperiksa kembali datanya.</div>');
			$("#dlg_st_approve_selected").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'inventory/ct_stock_transfer/st_process_approved_selected'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlg_st_approve_selected").dialog("close");
								$('#dlg_st_approve_selected').dialog("destroy"); 
								$(".dlg_st_approve_selected_cl").remove(); 
								$(".dlg_st_approve_selected_cl").html('');
								$("#tblsthdr").trigger('reloadGrid');
								
							} else { 
								alert(msg.sts+msg.desc); 
								$("#dlg_st_approve_selected").dialog("close");
								$('#dlg_st_approve_selected').dialog("destroy"); 
								$(".dlg_st_approve_selected_cl").remove(); 
								
							}
						}
					});
				},
					"CANCEL": function() {
						$( "#dlg_st_approve_selected" ).dialog( "close" );

					}
				},
				close : function(){
					$('#dlg_st_approve_selected').dialog("destroy"); 
					$(".dlg_st_approve_selected_cl").remove(); 
					//$("body").append('<div id="dlg_st_approve_selected" title="Warning" class="dlg_st_approve_selected_cl"><p>Apakah anda yakin akan memproses data mesin sparepart  '+ ret.filename  +'..?</p><br />Mohon diperiksa kembali datanya.</div>.</div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
			
		
		});
		$("#btnstloaddata").button().click(function(){
			$("#frmstloaddatadlg").load('<?php echo base_url().'inventory/ct_stock_transfer/view_stocktransfer_load_data'; ?>',  {parmeter:'parameter'}, function() {
				$("#frmstloaddatadlg").dialog({
					modal:true,
					width : 1000,
					height : 530,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#frmstloaddatadlg').dialog("destroy"); 
					    $(".frmstloaddatadlg_cl").remove(); 
					    $("body").append('<div id="frmstloaddatadlg" title="LOAD DATA VGI4" class="frmstloaddatadlg_cl"></div>'); 
						$('#tblbc23hdr').trigger('reloadGrid');
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});
		});	
		$("#btnstproses").button().click(function(){
		    var id = jQuery("#tblsthdr").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblsthdr").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};
			var form_data = {
				id_data_out_hdr:ret.id_data_out_hdr,
				id_terkait:ret.id_terkait,
				doc_out_to_id:ret.doc_out_to_id
			};
			
			$("#dlg_st_approvedata").dialog( "destroy" );
			$(".dlg_st_approvedata_cl").remove();
			$(".dlg_st_approvedata_cl").html('');
			$("body").append('<div id="dlg_st_approvedata" title="Warning" class="dlg_st_approvedata_cl"><p>Apakah anda yakin akan memproses data Approved ???</p><br />Mohon diperiksa kembali datanya dengan baik-baik..</div>');
			$("#dlg_st_approvedata").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'inventory/ct_stock_transfer/st_process_approved'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlg_st_approvedata").dialog("close");
								$('#dlg_st_approvedata').dialog("destroy"); 
								$(".dlg_st_approvedata_cl").remove(); 
								$('#tblsthdr').trigger('reloadGrid');
								
							} else { 
								alert(msg.sts+msg.desc); 
								$("#dlg_st_approvedata").dialog("close");
								$('#dlg_st_approvedata').dialog("destroy"); 
								$(".dlg_st_approvedata_cl").remove(); 
								$('#tblsthdr').trigger('reloadGrid');
								
							}
						}
					});
				},
					"CANCEL": function() {
						$( "#dlg_st_approvedata" ).dialog( "close" );

					}
				},
				close : function(){
					$('#dlg_st_approvedata').dialog("destroy"); 
					$(".dlg_st_approvedata_cl").remove(); 
					$("body").append('<div id="dlg_st_approvedata" title="Warning" class="dlg_st_approvedata_cl"><p>Apakah anda yakin akan memproses data Approved.???</p><br />Mohon diperiksa kembali datanya dengan baik-baik..</div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
		});
		
		$("#btnstviewdetail").button().click(function(){
			var id = jQuery("#tblsthdr").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblsthdr").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};
			var form_data = {
				id_data_out_hdr:ret.id_data_out_hdr,
			};	
			
			$("#frmst_dtl_dlg").load('<?php echo base_url().'inventory/ct_stock_transfer/view_stocktransfer_dtl'; ?>', form_data, function() {
				$("#frmst_dtl_dlg").dialog({
					modal:true,
					width : 800,
					height : 500,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#frmst_dtl_dlg').dialog("destroy"); 
					    $(".frmst_dtl_dlg_cl").remove(); 
					    $("body").append('<div id="frmst_dtl_dlg" title="Detil VGI" class="frmst_dtl_dlg_cl"></div>'); 
						$('#tblsthdr').trigger('reloadGrid');
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});
			
		
		});	
		
		var datePick = function (el) {
			$(el).datepicker({
				changeYear: true,
				changeMonth: true,
				showButtonPanel: true,
				onSelect: function () {
					
					if (this.id.substr(0, 3) === "gs_") {
               
					setTimeout(function(){
					jQuery("#tblsthdr").jqGrid()[0].triggerToolbar();
						}, 50);
					} else {
						
						$(this).trigger('change');
					}
				}    
			});
		};
		
		jQuery("#tblsthdr").jqGrid({
			url:'<?php echo base_url().'inventory/ct_stock_transfer/loadDataProdRequest'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:['id_data_out_hdr', 'doc out no','doc out date', 'doc_out_to_id', 'id_data_out_hdr_h_status','id_terkait','approved date', 'status'
			],
			colModel:[
				{name:'id_data_out_hdr',index:'id_data_out_hdr', width:60, hidden:true},
				{name:'doc_out_no',index:'doc_out_no', width:120},
				{name:'doc_out_date',index:'doc_out_date', width:120,stype:"text",searchoptions:{dataInit:datePick, att:{title:'Select Date'}}},
				{name:'doc_out_to_id',index:'doc_out_to_id', width:362, hidden:true},
				{name:'id_data_out_hdr_h_status',index:'id_data_out_hdr_h_status', width:84,hidden:true},
				{name:'id_terkait',index:'id_terkait', width:84, hidden:true},
				{name:'approve_date',index:'approve_date', width:120,stype:"text",searchoptions:{dataInit:datePick, att:{title:'Select Date'}}},
				{name:'status',index:'status', width:247}
				
				],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ptblsthdr',
			sortname: 'tbl_data_out_hdr.id_data_out_hdr',
			viewrecords: true,
			sortorder: "desc",
			width: '',
			height:100,
			jsonReader: { repeatitems : false },
			caption:"Data Stock Transfer",
			rownumbers: true,
			shrinkToFit: false,
			multiselect: true,
			afterInsertRow: function(){
				
				
			},
			gridComplete: function(){
				var rowIDs = jQuery("#tblsthdr").getDataIDs(); 
				var rowData = $("#tblsthdr").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tblsthdr'));
				   
					switch (rowData[i].status) {
						case 'DATA PROCESSED':
						   trElement.css({"color":"green"});
						break;
						
						case 'OUT INVENTORY CANCELED':
						   trElement.css({"color":"green"});
						break;
						
						case 'DATA OUT INVENTORY':
						   trElement.css({"color":"purple"});
						break;
						case 'DATA PROCESSED INVENTORY':
						   trElement.css({"color":"blue"});
						break;
						case 'APPROVED':
						   trElement.css({"color":"red"});
						break;
					}
				}
			},
		}); 
			
                        
		jQuery("#tblsthdr").jqGrid('navGrid','#ptblsthdr',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tblsthdr").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});

		setTimeout(function(){
			setGridHight($("#tblsthdr"),$("#container_st_inv"),$("#st_inv_bar")); 
		},10); 
		
		$("#btnexceldatavgi").button().click(function(){
			$("#search_stock_transfer_dlg").load('<?php echo base_url().'inventory/ct_stock_transfer/view_stocktransfer_search'; ?>',  {parmeter:'parameter'}, function() {
				$("#search_stock_transfer_dlg").dialog({
					modal:true,
					width : 800,
					height : 480,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#search_stock_transfer_dlg').dialog("destroy"); 
					    $(".search_stock_transfer_dlg_cl").remove(); 
					    $("body").append('<div id="search_stock_transfer_dlg" title="PENCARIAN PERIODE TANGGAL" class="search_stock_transfer_dlg_cl"></div>'); 
						
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});	
		
		});
	});
</script>
    <div id="frmstloaddatadlg" title="LOAD DATA VGI4" class="frmstloaddatadlg_cl"></div>
	<div id="frmst_dtl_dlg" title="Detil VGI" class="frmst_dtl_dlg_cl"></div>
	<div id="search_stock_transfer_dlg" title="PENCARIAN PERIODE TANGGAL" class="search_stock_transfer_dlg_cl"></div>
</body>


</html> 
		

