
<div id="container_pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list" style="height:100%; margin:0px; padding:0px;overflow:'hidden'; border: 0px solid #cd0a0a">
	<div class="pane-header ui-state-active" style="height:25px" id="pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list_bar" >
	<table style="width:100%">
	<tr>
		<td>LIST ITEM</td>
		<td>
		<button type="button" id="pasi_ceisa_bc_<?php echo $bc_prefix;  ?>_in_map_item_auto" style="float: right;" >Map Auto</button> 
		<button type="button" id="pasi_ceisa_bc_<?php echo $bc_prefix;  ?>_in_map_item_manual" style="float: right;" >Map Manual</button> 
		</td>
	</tr>
	</table> 
</div>
<table id="pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list"></table> <div id="ppasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list"></div>
</div> 

<script type="text/javascript">
 	
    $(document).ready(function(){ 
	
	$("#pasi_ceisa_bc_<?php echo $bc_prefix;  ?>_in_map_item_manual").button(); 
	$("#pasi_ceisa_bc_<?php echo $bc_prefix;  ?>_in_map_item_auto").button(); 
	
	$("#pasi_ceisa_bc_<?php echo $bc_prefix;  ?>_in_map_item_manual").hide(); 

		var ceisa_bc_in<?php echo $bc_prefix;  ?>_cust_code='<?php echo $cust_code;  ?>';
		$(window).bind('resize', function() {  
			setTimeout(function(){
	 			setGridHight($("#pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list"),$("#container_pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list"),$("#pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list_bar")); 
			},10); 
		});  
	  
 	
	  jQuery("#pasi_ceisa_bc_<?php echo $bc_prefix;  ?>_in_map_item_manual").click(function(){  
		var mark_id = jQuery('#pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list').jqGrid('getGridParam','selrow');   
		if(!mark_id){ alert("Pililh dokumen yang update status finish");exit;}  
		var ret = jQuery("#pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list").jqGrid('getRowData',mark_id);    
 		var $dialog = jQuery('<div \>')
		 .load('<?php echo base_url().'pasi_ceisa_master/ct_pasi_map_item'; ?>',{bc_prefix:'<?php echo $bc_prefix;  ?>',source_code:ret.r7,source_name:ret.r8})
		 .dialog({
			modal:true,
			width : 970,
			height : 550,
				title :'MAPPING ITEM',
				buttons: {
					"CLOSE": function(){
						$dialog.dialog("close");  
					} ,
					"MAPPING": function(){ 
					var form_edit = {};					
					if ($pasi_ceimap_item_master_<?php echo $bc_prefix;  ?>_map_item_tab_select==0){
						var mark_id_item = jQuery('#pasi_ceimap_item_master_<?php echo $bc_prefix;  ?>map_item_tbl').jqGrid('getGridParam','selrow');   
						if(!mark_id_item){ alert("Pililh Item Mapping");exit;}  
						var ret_item = jQuery("#pasi_ceimap_item_master_<?php echo $bc_prefix;  ?>map_item_tbl").jqGrid('getRowData',mark_id_item);    
						form_edit = {
								tpb_in_barang_id :ret.rID,     
								map_item_id :ret_item.rID,
								map_type_item_id :ret_item.r5
				 		}; 
					}else if ($pasi_ceimap_item_master_<?php echo $bc_prefix;  ?>_map_item_tab_select==1){
						var mark_id_item = jQuery('#pasi_ceimap_item_master_<?php echo $bc_prefix;  ?>map_item_tbl_current').jqGrid('getGridParam','selrow');   
						if(!mark_id_item){ alert("Pililh Item Mapping");exit;}  
						var ret_item = jQuery("#pasi_ceimap_item_master_<?php echo $bc_prefix;  ?>map_item_tbl_current").jqGrid('getRowData',mark_id_item);    
						form_edit = {
								tpb_in_barang_id :ret.rID,     
								map_item_id :ret_item.rID,
								map_type_item_id :ret_item.r5
				 		}; 
					} 
						
						$.ajax({    
						url:'<?php echo base_url().'pasi_ceisa_bc_in/ct_pasi_ceisa_bc_in_from_po/update_mapping_item_manual'; ?>',
						type : 'POST',
							data : form_edit,
							dataType: 'json',
							success: function(msg){
								if (msg.valid){
									alert(msg.stsmsg);  
									$dialog.dialog("close");  
								} else { alert(msg.stsno+msg.stsmsg);  }
							} 
						});
						 
					} , 
				},
				close : function(){
					$dialog.dialog('destroy').remove();
					$('#pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list').trigger('reloadGrid');
				},
				open: function(){
					$("body").unblock(); 
				}
			}); 
	}); 
	
	  jQuery("#pasi_ceisa_bc_<?php echo $bc_prefix;  ?>_in_map_item_auto").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 ITEM BC <?php echo $bc_prefix;  ?>',
				buttons: {
					"CLOSE": function(){
						$dialog.dialog("close");  
					} ,
					
					"FINISH": function(){ 
					
				 		 	var form_edit = {      
									id_header  : '<?php echo $id_header;  ?>' , 
						 	};  
							
							$.ajax({    
							url:'<?php echo base_url().'pasi_ceisa_bc_in/ct_pasi_ceisa_bc_in_from_po/update_mapping_item_auto'; ?>',
							type : 'POST',
								data : form_edit,
								dataType: 'json',
								success: function(msg){
									if (msg.valid){
										alert(msg.stsmsg);  
										$dialog.dialog("close");  
									} else { alert(msg.stsno+msg.stsmsg);  }
								} 
							});
							 
					} , 
				},
				close : function(){
					$dialog.dialog('destroy').remove();
					$('#pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list').trigger('reloadGrid');
				},
				open: function(){  
				 
					$("body").unblock(); 
				}
			}); 
	}); 
	
	
	
	
	

		jQuery("#pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list").jqGrid({
			url:'<?php echo base_url().'pasi_ceisa_bc_in_new/ct_pasi_ceisa_bc_in_data/loaddata_bc23_item_barang'; ?>',
			datatype: "json",
			mtype : "post",
			postData:{	id_header:'<?php echo $id_header;  ?>'  
						},
						colNames:[
							'ID_DETAIL','ID_ORI','SERI','G','type_item_id','TYPE_ITEM'
						,'CODE','ITEM NO','NAME','item_id','tpb_in_barang_KATEGORI_BARANG','BARCODE'
						,'CODE','NAME','QTY','UOM','PRICE'
						,'TOTAL','QTY','CODE','BAHAN','SIZE'
						,'MERK','TIPE','SPESIFIKASI LAIN','tpb_in_barang_ID_HEADER','tpb_in_barang_mode_source'
						,'tpb_in_barang_id_source','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:'r1',index:'r1', width:100, hidden:true, align :'center'}
						,{name:'rg',index:'rg', width:40, hidden:true, editable: true, formatter:'checkbox',  align: "center",stype: "select", searchoptions: { value: "-100:All;1:Yes;0:No" }}
						,{name:'r2',index:'r2', width:80, hidden:true, align :'right'}
						,{name:'r5',index:'r5', width:80, hidden:true, align :'right'}
						
						,{name:'r4',index:'r4', width:80, hidden:false, align :'left'}  //kode
						,{name:'i4',index:'i4', width:150, hidden:true, align :'left'}
						,{name:'r5',index:'r5', width:150, hidden:false, align :'left'} // produk
						,{name:'i3',index:'i3', width:80, hidden:true, align :'left'}
						,{name:'r3',index:'r3', width:80, hidden:true, align :'left'}
						,{name:'r14',index:'r14', width:150, hidden:false, align :'left'} //BARODE
						
						,{name:'i1',index:'i1', width:80, hidden:false, align :'left'}
						,{name:'i2',index:'i2', width:150, hidden:false, align :'left'}
						,{name:'r6',index:'r6', width:80, hidden:false, align :'center'} //qty_delivery
						,{name:'i2',index:'i2', width:150, hidden:false, align :'left'} 
						,{name:'r8',index:'r8', width:60, hidden:false, align :'right'} //price
						
						,{name:'i4',index:'i4', width:80, hidden:false, align :'right'}
						,{name:'r18',index:'r18', width:40, hidden:false, align :'center'} //qty kemasan
						,{name:'r19',index:'r19', width:40, hidden:false, align :'left'}
						,{name:'r26',index:'r26', width:60, hidden:false, align :'right'}
						,{name:'r15',index:'r15', width:80, hidden:false, align :'left'}

						,{name:'r10',index:'r10', width:80, hidden:false, align :'left'} //merk
						,{name:'r11',index:'r11', width:80, hidden:false, align :'left'}  //tipe
						,{name:'r12',index:'r12', width:80, hidden:false, align :'left'} //spesikikasi
						,{name:'r16',index:'r16', width:80, hidden:true, align :'right'} // create date
						,{name:'r17',index:'r17', width:80, hidden:true, align :'right'}  //creatdby

						,{name:'r21',index:'r21', width:80, hidden:true, align :'right'}
						,{name:'r16',index:'r16', width:80, hidden:false, align :'left', searchoptions:{searchhidden: true,dataInit:function(el){$(el).datepicker({onSelect: function(date){jQuery("#table_name")[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:'r17',index:'r17', width:80, hidden:false, align :'left'}
						,{name:'r24',index:'r24', width:80, hidden:false, align :'left', searchoptions:{searchhidden: true,dataInit:function(el){$(el).datepicker({onSelect: function(date){jQuery("#table_name")[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:'r25',index:'r25', width:80, hidden:false, align :'left'}
				

						],
		//	rowNum:-1,
		//	multiselect: true, 
			rowNum:50,
		 	rowList:[10,20,30,50,100,200],
	 		pager: '#ppasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list',
			sortname: 'r4',
			viewrecords: true,
			sortorder: "asc",
			width: '',
			height: 100,
			//width: 950,
			//height:300,
			jsonReader: { repeatitems : false }, 
			rownumbers: true,
			loadonce: false,
			shrinkToFit: false, 
			afterInsertRow: function(rowid, aData){
				/*switch (aData.statusdok) {
					case 'DATA SENT':
						jQuery("#pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list").jqGrid('setCell',rowid,'statusdok','',{color:'green'});
					break;
					case '2':
						jQuery("#pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list").jqGrid('setCell',rowid,'statusdok','',{color:'red'});
					break;
					case '1':
						jQuery("#pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list").jqGrid('setCell',rowid,'statusdok','',{color:'blue'});
					break;
					
				} */
			},
		    onSelectRow: function(rowid){ 
				var rowData = $("#pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list").getRowData(rowid); 
		 		if (rowData.rg == 'Yes' ){
					$("#pasi_ceisa_bc_<?php echo $bc_prefix;  ?>_in_map_item_manual").show(); 
				}
				else{
					$("#pasi_ceisa_bc_<?php echo $bc_prefix;  ?>_in_map_item_manual").hide(); 
			   }
	 
  		 	 },
			gridComplete: function(){
				var rowIDs = jQuery("#pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list").getDataIDs(); 
				var rowData = $("#pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list'));
				   
					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;
					}
				}
			}, 
		}); 
		jQuery("#pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list").jqGrid('setGroupHeaders', 
            { useColSpanStyle: true, groupHeaders:[
			{startColumnName: 'i1', numberOfColumns: 3, titleText: '<em><center>ITEM INTERNAL</center></em>'},
			{startColumnName: 'r3', numberOfColumns: 6, titleText: '<em><center>ITEM MODULE </center></em>'},
			{startColumnName: 'r11', numberOfColumns: 2, titleText: '<em><center>PRICE</center></em>'},  
    		{startColumnName: 'r13', numberOfColumns: 2, titleText: '<em><center>PACKAGE</center></em>'},  
    		{startColumnName: 'r15', numberOfColumns: 4, titleText: '<em><center>DETAIL</center></em>'},  
    		{startColumnName: 'r22', numberOfColumns: 2, titleText: '<em><center>CREATE</center></em>'},  
     		{startColumnName: 'r24', numberOfColumns: 2, titleText: '<em><center>MODIFY</center></em>'},  
         ] });       
		jQuery("#pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list").jqGrid('navGrid','#ppasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
		 
	
	setTimeout(function(){
	 		setGridHight($("#pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list"),$("#container_pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list"),$("#pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_po_tbl_item_list_bar")); 
	},100); 
	});
		  	
</script>

	
	