
<table  id="container_ms_grn" class ="tablefixed"  border="0"  >  
<tr class="trauto" > 
	<td class="tdauto">  
		<table  class ="tablefixed"  border="0"  >  
			<tr class="tr20" > 
				<td class="tdauto"> 
					<div  style="overflow:none;height:100%; margin:0px; padding:0px;overflow:'hidden'; border: 0px solid #cd0a0a">
						<div class="pane-header ui-state-active"  id="ms_grn_bar" >   
							<table width="100%" border="0"  cellspacing="0" cellpadding="0" style="  overflow:none;height:100%; margin:0px; padding:0px;overflow:'hidden'">
							  <tr>
								<td>  
								<label style="margin-right:10px;">PERIODE:</label>
									<input id="txtStartGrn" type="text" value='<?php echo $start_date; ?>' style="margin-right:10px;width:80px" />
									<label style="margin-right:10px;">S/D</label>
									<input id="txtEndGrn" type="text" value='<?php echo $end_date; ?>' style="margin-right:10px;width:80px" />
									 <button id="btnPostGrn">POST GRN</button>
									 <button id="LookupGRN">LOOKUP GRN</button>
									 <button id="CleanGRN">CLEANSING</button>
									 <button id="btnRepostGRN" style="background:red;color:white; " title="UPDATE NO FAKTUR DARI LOCAL PURCHASE">REPOST GRN</button>
									</td>
								<td align="right"><button   id="ms_grn_map_supplier_auto"  >Map Supplier Auto</button> 
								  <button  id="ms_grn_map_supplier_manual"  >Map Supplier Manual</button> </td>
							  </tr>
							</table> 
						</div> 
					</div> 		
				</td>  
			</tr> 
			<tr class="trauto" > 
				<td class="tdauto"> 
					<table  id="ms_grn_tbl"></table> <div id="pms_grn_tbl"></div>
				</td>  
			</tr> 
		</table>  
	</td>  
	
</tr> 
</table> 
 
<script type="text/javascript"> 
 
    $(document).ready(function(){
		$(window).bind('resize', function() {  
			setTimeout(function(){
			setGridHight($("#ms_grn_tbl"),$("#container_ms_grn"),$("#ms_grn_bar")); 
			setGridHight($("#ms_molts_file_tbl"),$("#container_ms_grn"),$("#ms_molts_file_bar")); 
				},10); 
		});  
	   //tambahan cleansing
	   
	   $("#CleanGRN").button(); 
	

	 jQuery("#CleanGRN").click(function(){ 
		var mark_id = $('#ms_grn_tbl').jqGrid('getGridParam','selrow');   
		if(!mark_id){ alert("Pilih header terlebih dahulu");exit;}    
		var row_data = $("#ms_grn_tbl").jqGrid('getRowData',mark_id);
		var cleansing= row_data.r26;
		if(cleansing =="Yes"){ alert("Part sudah ada di data Master");exit;}
		var part_name= row_data.r4;
		var part_code= row_data.r5;
		
		var $dialog = jQuery('<div \>')
			 .load('<?php echo base_url().'ms_master/ct_ms_item/view_new_item_from_grn'; ?>',{part_name:part_name,part_code:part_code})
			 .dialog({
				modal:true,
				width : 550,
				height : 300,
					title :'NEW ITEM',
					buttons: { 
						"CLOSE": function(){
							$dialog.dialog("close");  
						} ,
						"SAVE NEW ITEM": function(){  
							var form_edit = {
								ms_type_id			:$('#ms_item_tipe').val(),
								part_no				:$('#ms_item_part_no').val(),     
								part_name			:$('#ms_item_part_name').val(),     
								base_no				:$('#ms_item_base_no').val(),     
								part_custom_no		:$('#ms_item_part_custom_no').val(),   
								uom					:$('#ms_item_uom').val(),      
								consumable			:$('#ms_item_consumable').is(':checked')==true?'1':'0', 
								min_qty				:$('#ms_item_min_qty').val(),      
								sta_qty				:$('#ms_item_sta_qty').val(),      
								price_qty			:$('#ms_item_sta_price').val(),      
					 	 	}; 
							jQuery('.ui-dialog button:nth-child(2)').button('disable'); 
							$.ajax({    
								url:'<?php echo base_url().'ms_master/ct_ms_item/new_item'; ?>',
								type : 'POST',
									data : form_edit,
									dataType: 'json',
									success: function(msg){
										if (msg.valid){ 
									 
										 	
												$dialog.dialog("close");
											    
										}
									} 
								}).always(function() {
										jQuery('.ui-dialog button:nth-child(2)').button('enable'); 
								});  
						} 
					},
					close : function(){
						$dialog.dialog('destroy').remove();
						$('#ms_grn_tbl').trigger('reloadGrid');
					},
					open: function(){ 
						jQuery('.ui-dialog button:nth-child(1)').attr('tabindex', jQuery('.ui-dialog button:nth-child(2)').attr('tabindex') +1);  
						$("body").unblock(); 
					}
				}); 
	});// end cleansing
	   
	   
	   
		$( "#txtStartGrn" ).datepicker({
		dateFormat:'yy-mm-dd',
		defaultDate: "+1w",
		changeMonth: true,
		changeYear: true,
		numberOfMonths: 4,
		onClose: function( selectedDate ) {
		$( "#txtEndGrn" ).datepicker( "option", "minDate", selectedDate );
		}
    });
	
    $( "#txtEndGrn" ).datepicker({
		dateFormat:'yy-mm-dd',
		defaultDate: "+1w",
		changeMonth: true,
		changeYear: true,
		numberOfMonths: 4,
		onClose: function( selectedDate ) {
		$( "#txtStartGrn" ).datepicker( "option", "maxDate", selectedDate );
		}
    });
	  
	 $("#btnPostGrn").button().click(function(){  
	 
		var	start_date 	=	$.datepicker.formatDate('yy-mm-dd', new Date($("#txtStartGrn").val())) ;
		var end_date	=	$.datepicker.formatDate('yy-mm-dd', new Date($("#txtEndGrn").val())) ; 
	 
		var $dialog =  $('<div />')
				.html(' <div class="ui-layout-content ui-widget-content-panel" style="margin-top:10px"> \
				POST DATA GRN ? <br /><br /> TANGGAL '
 				+ start_date +
				'  S/D  '
				+ end_date +
				'</div>')
			 .dialog({
				modal:true,
				width : 500,
				height : 200,
				title :'POSTING',
				buttons: {
					"CLOSE": function(){
						$dialog.dialog("close");  
					} ,
					
					"POSTING": function(){  
							$.ajax({    
							url:'<?php echo base_url().'ms_molts/ct_ms_grn/postDataGrn'; ?>',
							type : 'POST',
								data : {start_date : start_date,end_date : end_date },
								dataType: 'json',
								success: function(msg){
									if (msg.valid){
										alert(msg.stsmsg);  
										$dialog.dialog("close");  
										$('#ms_grn_tbl').trigger('reloadGrid');
									} else { alert(msg.stsno+msg.stsmsg);  }
								} 
							});
							 
					} , 
				},
				close : function(){
					$dialog.dialog('destroy').remove();
					$('#ms_grn_list_tbl').trigger('reloadGrid');
				},
				open: function(){  
						jQuery('.ui-dialog button:nth-child(1)').attr('tabindex', jQuery('.ui-dialog button:nth-child(2)').attr('tabindex') +1);  
				 
					$("body").unblock(); 
				}
			}); 
	 
	 });
	 
	 
	 $("#LookupGRN").button().click(function(){  
	 
	 	
		var	start_date 	=	$.datepicker.formatDate('yymmdd', new Date($("#txtStartGrn").val())) ;
		var end_date	=	$.datepicker.formatDate('yymmdd', new Date($("#txtEndGrn").val())) ; 
		var source		= 'LP';
		jQuery("#ms_grn_tbl").jqGrid('setGridParam', { postData: {start_date : start_date,end_date : end_date ,source:source }});
		$('#ms_grn_tbl').trigger( 'reloadGrid' );
	 
	 });
	 
	 
	 $("#ms_grn_map_supplier_auto").button().click(function(){   
			 var $dialog =  $('<div />')
				.html(' <div class="ui-layout-content ui-widget-content-panel" style="margin-top:10px"> \
				Auto mapping ? <br /><br />\
 				</div>')
			 .dialog({
				modal:true,
				width : 500,
				height : 200,
				title :'AUTO MAPPING ALL SHIPPER',
				buttons: {
					"CLOSE": function(){
						$dialog.dialog("close");  
					} ,
					
					"MAPPING": function(){  
							$.ajax({    
							url:'<?php echo base_url().'ms_molts/ct_ms_grn/update_mapping_supplier_auto'; ?>',
							type : 'POST',
								data : {a:'1'},
								dataType: 'json',
								success: function(msg){
									if (msg.valid){
										alert(msg.stsmsg);  
										$dialog.dialog("close");  
										$('#ms_grn_tbl').trigger('reloadGrid');
									} else { alert(msg.stsno+msg.stsmsg);  }
								} 
							});
							 
					} , 
				},
				close : function(){
					$dialog.dialog('destroy').remove();
					$('#ms_grn_list_tbl').trigger('reloadGrid');
				},
				open: function(){  
						jQuery('.ui-dialog button:nth-child(1)').attr('tabindex', jQuery('.ui-dialog button:nth-child(2)').attr('tabindex') +1);  
				 
					$("body").unblock(); 
				}
			}); 
	}); 
	
	  
	 $("#ms_grn_map_supplier_manual").button().click(function(){  
	
		var mark_id = $('#ms_grn_tbl').jqGrid('getGridParam','selrow');   
		if(!mark_id){ alert("Pililh header terlebih dahulu");exit;}    
		var row_data = $("#ms_grn_tbl").jqGrid('getRowData',mark_id);  
		var $dialog = $('<div \>')
		 .load('<?php echo base_url().'ms_master/ct_ms_supplier_customer/view_map'; ?>',{mode_view_map_supplier:'<?php echo $mode_view_map_supplier;  ?>',source_name:row_data.r19})
		 .dialog({
			modal:true,
			width : 1024,
			height : 600,
				title :'LIST SUPPLIER',
				buttons: {
						"CLOSE": function(){
							$dialog.dialog("close");  
						} , 
						"MAPPING": function(){  
								var mark_sup_map_id = $('#ms_map_cust_master_<?php echo $mode_view_map_supplier;  ?>map_cust_tbl').jqGrid('getGridParam','selrow');   
								if(!mark_sup_map_id){ alert("Pilih Target Supplier");exit;}    
								var row_data_sup_map = $("#ms_map_cust_master_<?php echo $mode_view_map_supplier;  ?>map_cust_tbl").jqGrid('getRowData',mark_sup_map_id);  
	 
								$('.ui-dialog button:nth-child(2)').button('disable');  
								$.ajax({    
								url:'<?php echo base_url().'ms_molts/ct_ms_grn/update_mapping_supplier_manual'; ?>',
								type : 'POST',
								data : {ms_grn_id:row_data.rID,ms_supplier_customer_id:row_data_sup_map.rID},
								dataType: 'json',
								success: function(msg){
									if (msg.valid){
										alert(msg.stsmsg);  
										$dialog.dialog("close");  
										$('#ms_grn_tbl').trigger('reloadGrid');
									} else { alert(msg.stsno+msg.stsmsg);  }
								} 
								}).always(function() {
										$('.ui-dialog button:nth-child(2)').button('enable'); 
								}); 
							} , 
						
				},
				close : function(){
					$dialog.dialog('destroy').remove();
					$('#ms_grn_tbl').trigger('reloadGrid');
				},
				open: function(){
						jQuery('.ui-dialog button:nth-child(1)').attr('tabindex', jQuery('.ui-dialog button:nth-child(2)').attr('tabindex') +1);  
					$("body").unblock(); 
				}
			}); 
			}); 
	  
	 
	$("#ms_grn_tbl").jqGrid({
			url:'<?php echo base_url().'ms_molts/ct_ms_grn/loaddata'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:[
			'id','USED','C','NUMBER','DATE','CATEGORY','NUMBER','CODE'
			,'UNIT','ETA','QTY','PRICE','NUMBER'
			,'DATE','CODE','TYPE','CAR','DATE'
			,'NO','STATUS MODULE',
			'MAPD','MAPPING','SHIPPING','SHIPPER','DATE'
			,'BY'
			]
			,colModel:[
			{name:'rID',index:'rID', width:80, hidden:true, align :'right'}
			,{name:'r1',index:'r1', width:50, editable: false, formatter:'checkbox',  align: "center",stype: "select", searchoptions: { value: "-100:All;1:Yes;0:No" }}
			,{name:'r26',index:'r26', width:80, editable: false, formatter:'checkbox',  align: "center",stype: "select", searchoptions: { value: "-100:All;1:Yes;0:No" }}
			,{name:'r2',index:'r2', width:80, hidden:false, align :'right'}
			,{name:'r3',index:'r3', width:80, hidden:false, align :'left', searchoptions:{searchhidden: true,dataInit:function(el){$(el).datepicker({onSelect: function(date){jQuery("#ms_grn_tbl")[0].triggerToolbar();},changeMonth: true,changeYear: true,dateFormat:'dd/mm/yy', showButtonPanel: true, beforeShow: function(input) {  setTimeout(function() { var buttonPane = $(input).datepicker("widget").find( ".ui-datepicker-buttonpane" );   var btn = $('<button class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" type="button">Clear</button>');   btn.unbind("click").bind("click", function () {   $.datepicker._clearDate( input );   });   btn.appendTo( buttonPane );  }, 1 );  }  });}}}
			
			,{name:'r27',index:'r27', width:80, hidden:false, align :'left'}
			,{name:'r4',index:'r4', width:80, hidden:false, align :'left'}
			,{name:'r5',index:'r5', width:80, hidden:false, align :'right'}

			,{name:'r6',index:'r6', width:40, hidden:false, align :'center'}
			,{name:'r7',index:'r7', width:80, hidden:false, align :'left', searchoptions:{searchhidden: true,dataInit:function(el){$(el).datepicker({onSelect: function(date){jQuery("#ms_grn_tbl")[0].triggerToolbar();},changeMonth: true,changeYear: true,dateFormat:'dd/mm/yy', showButtonPanel: true, beforeShow: function(input) {  setTimeout(function() { var buttonPane = $(input).datepicker("widget").find( ".ui-datepicker-buttonpane" );   var btn = $('<button class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" type="button">Clear</button>');   btn.unbind("click").bind("click", function () {   $.datepicker._clearDate( input );   });   btn.appendTo( buttonPane );  }, 1 );  }  });}}}
			,{name:'r8',index:'r8', width:80, hidden:false, align :'right'}
			,{name:'r9',index:'r9', width:80, hidden:false, align :'right'}
			,{name:'r10',index:'r10', width:80, hidden:false, align :'right'}

			,{name:'r11',index:'r11', width:80, hidden:false, align :'left', searchoptions:{searchhidden: true,dataInit:function(el){$(el).datepicker({onSelect: function(date){jQuery("#ms_grn_tbl")[0].triggerToolbar();},changeMonth: true,changeYear: true,dateFormat:'dd/mm/yy', showButtonPanel: true, beforeShow: function(input) {  setTimeout(function() { var buttonPane = $(input).datepicker("widget").find( ".ui-datepicker-buttonpane" );   var btn = $('<button class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" type="button">Clear</button>');   btn.unbind("click").bind("click", function () {   $.datepicker._clearDate( input );   });   btn.appendTo( buttonPane );  }, 1 );  }  });}}}
			,{name:'r12',index:'r12', width:80, hidden:false, align :'right'}
			,{name:'r13',index:'r13', width:80, hidden:false, align :'right'}
			,{name:'r14',index:'r14', width:80, hidden:false, align :'right'}
			,{name:'r15',index:'r15', width:80, hidden:false, align :'left', searchoptions:{searchhidden: true,dataInit:function(el){$(el).datepicker({onSelect: function(date){jQuery("#ms_grn_tbl")[0].triggerToolbar();},changeMonth: true,changeYear: true,dateFormat:'dd/mm/yy', showButtonPanel: true, beforeShow: function(input) {  setTimeout(function() { var buttonPane = $(input).datepicker("widget").find( ".ui-datepicker-buttonpane" );   var btn = $('<button class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" type="button">Clear</button>');   btn.unbind("click").bind("click", function () {   $.datepicker._clearDate( input );   });   btn.appendTo( buttonPane );  }, 1 );  }  });}}}

			,{name:'r16',index:'r16', width:80, hidden:false, align :'right'}
			,{name:'r17',index:'r17', width:80, hidden:false, align :'right'}
			
			,{name:'r25',index:'r25', width:50, editable: false, formatter:'checkbox',  align: "center",stype: "select", searchoptions: { value: "-100:All;1:Yes;0:No" }}
			,{name:'r23',index:'r23', width:80, hidden:false, align :'right'}
			,{name:'r18',index:'r18', width:80, hidden:false, align :'right'}
			,{name:'r19',index:'r19', width:80, hidden:false, align :'right'}
			,{name:'r20',index:'r20', width:80, hidden:false, align :'left', searchoptions:{searchhidden: true,dataInit:function(el){$(el).datepicker({onSelect: function(date){jQuery("#ms_grn_tbl")[0].triggerToolbar();},changeMonth: true,changeYear: true,dateFormat:'dd/mm/yy', showButtonPanel: true, beforeShow: function(input) {  setTimeout(function() { var buttonPane = $(input).datepicker("widget").find( ".ui-datepicker-buttonpane" );   var btn = $('<button class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" type="button">Clear</button>');   btn.unbind("click").bind("click", function () {   $.datepicker._clearDate( input );   });   btn.appendTo( buttonPane );  }, 1 );  }  });}}}
			,{name:'r21',index:'r21', width:80, hidden:false, align :'right'}
			
			

			],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#pms_grn_tbl',
			sortname: 'r1',
			viewrecords: true,
			sortorder: "desc",
			width: '',
			height: 100,
			//width: 950,
			//height:300,
			jsonReader: { repeatitems : false },
			caption:"DATA GRN",
			rownumbers: true,
			loadonce: false,
			shrinkToFit: false,
			multiselect: false,
			afterInsertRow: function(rowid, aData){
				/*switch (aData.statusdok) {
					case 'DATA SENT':
						$("#ms_grn_tbl").jqGrid('setCell',rowid,'statusdok','',{color:'green'});
					break;
					case '2':
						$("#ms_grn_tbl").jqGrid('setCell',rowid,'statusdok','',{color:'red'});
					break;
					case '1':
						$("#ms_grn_tbl").jqGrid('setCell',rowid,'statusdok','',{color:'blue'});
					break;
					
				} */
			},
			gridComplete: function(){
				var rowIDs = $("#ms_grn_tbl").getDataIDs(); 
				var rowData = $("#ms_grn_tbl").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = $("#"+ rowIDs[i],$('#ms_grn_tbl'));
				   
					switch (rowData[i].r_s) { 
						case '1':
						   trElement.css({"color":"blue"});
						break;
						case '2':
						   trElement.css({"color":"PURPLE"});
						break;
						case '3':
						   trElement.css({"color":"RED"});
						break;
					}
				}
			},
		}); 
		
		$("#ms_grn_tbl").jqGrid('setGroupHeaders', 
            { useColSpanStyle: true, groupHeaders:[
			{startColumnName: 'r2', numberOfColumns: 2, titleText: '<em><center>GRN</center></em>'},
			{startColumnName: 'r27', numberOfColumns: 7, titleText: '<em><center>PART</center></em>'},
			
			{startColumnName: 'r10', numberOfColumns: 2, titleText: '<em><center>PO</center></em>'},
			{startColumnName: 'r12', numberOfColumns: 6, titleText: '<em><center>BC</center></em>'}, 
			{startColumnName: 'r20', numberOfColumns: 2, titleText: '<em><center>CREATE</center></em>'},
			{startColumnName: 'r25', numberOfColumns: 4, titleText: '<em><center>SUPPLIER</center></em>'},
			
        ] });
			               
		$("#ms_grn_tbl").jqGrid('navGrid','#pms_grn_tbl',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		$("#ms_grn_tbl").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
	
	
		$("#ms_molts_file_add").button();
	$("#ms_molts_file_prosses").button(); 
	$("#ms_molts_file_delete").button(); 
	 
	$("#ms_molts_file_add").button().click(function(){  
		if (window.FormData) {  
			var $dialog =  $('<div />')
							.html(' <div class="ui-layout-content ui-widget-content-panel">\
										<table width="100%" border="0"> \
											<tr>\
												<td>File: </td>\
												<td><div align="center">:</div></td>\
												<td>\
												<input id="pasi_sa_file_name"  name="pasi_sa_file_name"  type="file" style="width:100%" >\
												</td>\
											</tr>\
										</table>\
								   </div>\
									<div class="pane-footer ui-state-default"></div> ') 
								.dialog({
								 modal:true,
									width : 550,
									height : 150,
									title :'UPLOAD FILE MOLTS',
									buttons: {
										"CLOSE": function(){
												$dialog.dialog("close");   
										},
										"UPLOAD": function() {  
											$('.ui-dialog button:nth-child(2)').button('disable');  
											var formData = new FormData();
											formData.append('file', $('input[type=file]')[0].files[0]);  
										 	$.ajax({
												type: 'POST',
												url : '<?php echo base_url().'ms_molts/ct_ms_molts_file/upload_file'; ?>' ,                
												data: formData,
												dataType : 'json',
												async :false,
												processData: false,
												contentType: false,
												success: function(msg){
													if (msg.valid==true){
														alert(msg.stsmsg);
														$dialog.dialog("close");   
													}else{ 
															alert(msg.stsmsg);
													}
												}
											}).always(function() {
											$('.ui-dialog button:nth-child(2)').button('enable'); 
											}); 
										}
									},
									close : function(){
										$dialog.dialog('destroy').remove(); 
										$("#ms_molts_file_tbl").trigger('reloadGrid');
									},
									open: function(){
									jQuery('.ui-dialog button:nth-child(1)').attr('tabindex', jQuery('.ui-dialog button:nth-child(2)').attr('tabindex') +1);  
										$("body").unblock(); 
									}
								}); 
				}else{
					console.log('browser not support or  javascript disable');
				}  
			}); 
	 
	$("#ms_molts_file_prosses").click(function(){
			var mark_id = $('#ms_molts_file_tbl').jqGrid('getGridParam','selrow');   
			if(!mark_id){ alert("Select File ");} 
			else {
				var ret = $("#ms_molts_file_tbl").jqGrid('getRowData',mark_id);    
				var $dialog = $('<div \>')
				 .html(' <div class="ui-layout-content ui-widget-content-panel">\
										 Apakah file akan di prosses ? \
								   </div>\
									<div class="pane-footer ui-state-default"></div> ')
				 .dialog({
					modal:true,
					width : 300,
					height : 150,
						title :'PROSSES FILE',
						buttons: {
										"CLOSE": function(){
											$dialog.dialog("close");  
										},
										"PROSSES": function() {  
								 			var form_data = {
											file_data_id 	: ret.rID
											};
											$('.ui-dialog button:nth-child(2)').button('disable'); 
											$.ajax({    
												url:'<?php echo base_url().'ms_molts/ct_ms_molts_file/prosses_file'; ?>',
												type : 'POST',
													data : form_data,
													dataType: 'json',
													success: function(msg){
														if (msg.valid){
															alert(msg.stsmsg);  
															$dialog.dialog("close");  
															$("#ms_grn_tbl").trigger("reloadGrid"); 															
														} else { alert(msg.stsno+msg.stsmsg);  }
													} 
											}).always(function() {
											$('.ui-dialog button:nth-child(2)').button('enable'); 
											}); 
										}
						}, 
						close : function(){
							$dialog.dialog('destroy').remove();
							$('#ms_molts_file_tbl').trigger('reloadGrid');
						},
						open: function(){
							jQuery('.ui-dialog button:nth-child(1)').attr('tabindex', jQuery('.ui-dialog button:nth-child(2)').attr('tabindex') +1);  
							$("body").unblock(); 
						}
					});
			} 
	});
	 
	$("#ms_molts_file_delete").click(function(){
			var mark_id = $('#ms_molts_file_tbl').jqGrid('getGridParam','selrow');   
			if(!mark_id){ alert("Select File ");} 
			else {
				var ret = $("#ms_molts_file_tbl").jqGrid('getRowData',mark_id);    
				var $dialog = $('<div \>')
				 .html(' <div class="ui-layout-content ui-widget-content-panel">\
										 Apakah file akan di hapus ? \
								   </div>\
									<div class="pane-footer ui-state-default"></div> ')
				 .dialog({
					modal:true,
					width : 300,
					height : 150,
						title :'DELETE FILE',
						buttons: {
										"CLOSE": function(){
											$dialog.dialog("close");  
										},
										"DELETE FILE": function() {  
								 			var form_data = {
											file_data_id 	: ret.rID
											};
											$('.ui-dialog button:nth-child(2)').button('disable'); 
											$.ajax({    
												url:'<?php echo base_url().'ms_molts/ct_ms_molts_file/delete_file'; ?>',
												type : 'POST',
													data : form_data,
													dataType: 'json',
													success: function(msg){
														if (msg.valid){
															alert(msg.stsmsg);  
															$("#ms_grn_tbl").trigger("reloadGrid");
															$dialog.dialog("close");  
														} else { alert(msg.stsno+msg.stsmsg);  }
													} 
												}).always(function() {
												$('.ui-dialog button:nth-child(2)').button('enable'); 
												});  
										}
						}, 
						close : function(){
							$dialog.dialog('destroy').remove();
							$('#ms_molts_file_tbl').trigger('reloadGrid');
						},
						open: function(){
							jQuery('.ui-dialog button:nth-child(1)').attr('tabindex', jQuery('.ui-dialog button:nth-child(2)').attr('tabindex') +1);  
							$("body").unblock(); 
						}
					});
			} 
	});
	 
	$("#ms_molts_file_tbl").jqGrid({
			url:'<?php echo base_url().'ms_molts/ct_ms_molts_file/loaddata'; ?>',
			mtype : "post",
			postData:{'q':'<?php echo base_url().'ms_molts/ct_ms_molts_file/loaddata'; ?>'},
			datatype: "json",
			colNames:[
			'file_data_id','file_type_id','Status','Name','URL'
			,'status_file_id','Date','By'
			,'date','by'
			]
			 
			,colModel:[
			{name:'rID',index:'rID', width:80, hidden:true, align :'right'}
			,{name:'r1',index:'r1', width:80, hidden:true, align :'right'} 
			,{name:'r7',index:'r7', width:80, stype: 'select', search:true, searchoptions:{searchhidden: true, value: '-100:All;0:SUKSES;1:PROCESSED'}}
 			,{name:'r2',index:'r2', width:300, hidden:false, align :'left'}
			,{name:'r3',index:'r3', width:450, hidden:false, align :'left'}
			
			,{name:'r6',index:'r6', width:80, hidden:true, align :'right'}
			,{name:'r8',index:'r8', width:125, hidden:false, align :'left', searchoptions:{searchhidden: true,dataInit:function(el){$(el).datepicker({onSelect: function(date){$("#pasi_dt_file")[0].triggerToolbar();},changeMonth: true,changeYear: true,dateFormat:'dd/mm/yy', showButtonPanel: true, beforeShow: function(input) {  setTimeout(function() { var buttonPane = $(input).datepicker("widget").find( ".ui-datepicker-buttonpane" );   var btn = $('<button class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" type="button">Clear</button>');   btn.unbind("click").bind("click", function () {   $.datepicker._clearDate( input );   });   btn.appendTo( buttonPane );  }, 1 );  }  });}}}
			,{name:'r9',index:'r9', width:80, hidden:false, align :'left'}
	
			,{name:'r4',index:'r4', width:125, hidden:false, align :'left', searchoptions:{searchhidden: true,dataInit:function(el){$(el).datepicker({onSelect: function(date){$("#pasi_dt_file")[0].triggerToolbar();},changeMonth: true,changeYear: true,dateFormat:'dd/mm/yy', showButtonPanel: true, beforeShow: function(input) {  setTimeout(function() { var buttonPane = $(input).datepicker("widget").find( ".ui-datepicker-buttonpane" );   var btn = $('<button class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" type="button">Clear</button>');   btn.unbind("click").bind("click", function () {   $.datepicker._clearDate( input );   });   btn.appendTo( buttonPane );  }, 1 );  }  });}}}
		 	,{name:'r5',index:'r5', width:80, hidden:false, align :'left'}
			
	 
			],
			rowNum:15,
			rowList:[10,15,20,30,50,75,100,200,500],
			pager: '#pms_molts_file_tbl',
			sortname: 'r1',
			viewrecords: true,
			sortorder: "desc",
			width: '',
			height: 100,
			//width: 950,
			//height:300,
			jsonReader: { repeatitems : false },
			caption:"DATA UPLOAD",
			rownumbers: true,
			loadonce: false,
			shrinkToFit: false,
			multiselect: false,
			afterInsertRow: function(rowid, aData){
				/*switch (aData.statusdok) {
					case 'DATA SENT':
						$("#ms_molts_file_tbl").jqGrid('setCell',rowid,'statusdok','',{color:'green'});
					break;
					case '2':
						$("#ms_molts_file_tbl").jqGrid('setCell',rowid,'statusdok','',{color:'red'});
					break;
					case '1':
						$("#ms_molts_file_tbl").jqGrid('setCell',rowid,'statusdok','',{color:'blue'});
					break;
					
				} */
			},
			gridComplete: function(){
				var rowIDs = $("#ms_molts_file_tbl").getDataIDs(); 
				var rowData = $("#ms_molts_file_tbl").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = $("#"+ rowIDs[i],$('#ms_molts_file_tbl'));
				   
					switch (rowData[i].status_2) {
						case 'DATA PROCESSED':
						   trElement.css({"color":"green"});
						break;
						
						case 'SENT TO INVENTORY CANCELED':
						   trElement.css({"color":"green"});
						break;
						
						case 'DATA SENT TO INVENTORY':
						   trElement.css({"color":"purple"});
						break;
						case 'DATA PROCESSED INVENTORY':
						   trElement.css({"color":"blue"});
						break;
						case 'APPROVED INVENTORY':
						   trElement.css({"color":"red"});
						break;
					}
				}
			},
		}); 
		
		$("#ms_molts_file_tbl").jqGrid('setGroupHeaders', 
            { useColSpanStyle: true, groupHeaders:[
			{startColumnName: 'r2', numberOfColumns: 2, titleText: '<em><center>FILE</center></em>'},
			{startColumnName: 'r8', numberOfColumns: 2, titleText: '<em><center>Status</center></em>'},
			{startColumnName: 'r4', numberOfColumns: 2, titleText: '<em><center>Create</center></em>'}, 
        ] });
			               
		$("#ms_molts_file_tbl").jqGrid('navGrid','#pms_molts_file_tbl',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		$("#ms_molts_file_tbl").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
	
	
	setTimeout(function(){
			setGridHight($("#ms_grn_tbl"),$("#container_ms_grn"),$("#ms_grn_bar")); 
			setGridHight($("#ms_molts_file_tbl"),$("#container_ms_grn"),$("#ms_molts_file_bar")); 
		},100); 
	});

	  
	 $("#btnRepostGRN").button().click(function(){  
	 
		var	start_date 	=	$.datepicker.formatDate('yy-mm-dd', new Date($("#txtStartGrn").val())) ;
		var end_date	=	$.datepicker.formatDate('yy-mm-dd', new Date($("#txtEndGrn").val())) ; 
	 
		var $dialog =  $('<div />')
				.html(' <div class="ui-layout-content ui-widget-content-panel" style="margin-top:10px"> \
				RE-POST GRN untuk meng-update no. Faktur ? <br /><br /> PERIODE TANGGAL '
 				+ start_date +
				'  S/D  '
				+ end_date +
				'</div>')
			 .dialog({
				modal:true,
				width : 500,
				height : 200,
				title :'REPOSTING',
				buttons: {
					"CLOSE": function(){
						$dialog.dialog("close");  
					} ,
					
					"REPOSTING": function(){  
							$.ajax({    
							url:'<?php echo base_url().'ms_molts/ct_ms_grn/update_cc_faktur'; ?>',
							type : 'POST',
								data : {start_date : start_date,end_date : end_date },
								dataType: 'json',
								success: function(msg){
									if (msg.valid){
										alert(msg.stsmsg);  
										$dialog.dialog("close");  
										$('#ms_grn_tbl').trigger('reloadGrid');
									} else { alert(msg.stsno+msg.stsmsg);  }
								} 
							});
							 
					} , 
				},
				close : function(){
					$dialog.dialog('destroy').remove();
					$('#ms_grn_list_tbl').trigger('reloadGrid');
				},
				open: function(){  
						jQuery('.ui-dialog button:nth-child(1)').attr('tabindex', jQuery('.ui-dialog button:nth-child(2)').attr('tabindex') +1);  
				 
					$("body").unblock(); 
				}
			}); 
	 
	 });


</script>

	
