
<div id="container_pasi_ceisa_gudang_in_bc40_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:40px" id="pasi_ceisa_gudang_in_bc40_tbl_item_list_bar" >
	<table style="width:100%">
	<tr>
		
		<td width="400" valign="top">
		<table width="400" border="0">
			<tr>
						<td width="41"  >NO/TANGGAL PENERIMAAN</td>
				  		<td width="7"  >:</td>
					  <td width="182"  ><input id="NOMOR_PENERIMAAN" type="text" value='<?php echo $NOMOR_PENERIMAAN; ?>'style="width:109px"  tabindex="2"/><input id="TANGGAL_PENERIMAAN" type="text" value='<?php echo $TANGGAL_PENERIMAAN; ?>' style="width:65px"  tabindex="2"/></td>
			</tr>
		</table>
		</td>
		<td width="400" valign="top">
		<table width="400" border="0">
			<tr>
						<td width="41"  >NO/TANGGAL SURAT JALAN</td>
				  		<td width="7"  >:</td>
					  <td width="182"  ><input id="NOMOR_SURATJALAN" type="text" value='<?php echo $NOMOR_SURATJALAN; ?>'style="width:109px"  tabindex="2"/><input id="TANGGAL_SURATJALAN" type="text" value='<?php echo $TANGGAL_SURATJALAN; ?>' style="width:65px"  tabindex="2"/></td>
			</tr>
		</table>
		</td>
		<td>
		 <button type="button" id="pasi_ceisa_gudang_in_bc40_item_simpan" style="float: right;" >Simpan Header</button> 
		 
 		</td>
		 <td>
		<button type="button" id="pasi_ceisa_gudang_in_bc40_item_edit" style="float: right;" >Edit QTY</button> 
 		</td>
	</tr>
	</table> 
</div>
<table id="pasi_ceisa_gudang_in_bc40_tbl_item_list"></table> <div id="ppasi_ceisa_gudang_in_bc40_tbl_item_list"></div>
</div> 

<script type="text/javascript">
 	
    $(document).ready(function(){ 
	
	$("#pasi_ceisa_gudang_in_bc40_item_simpan").button(); 
	$("#pasi_ceisa_gudang_in_bc40_item_edit").button(); 
 

	$( "#TANGGAL_PENERIMAAN" ).datepicker({
			changeMonth: true
			,changeYear: true
			,showButtonPanel: true
			,dateFormat: 'dd/mm/yy'
			,onClose: function(dateText, inst){
					var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
					var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
					var day = $("#ui-datepicker-div .ui-datepicker-day :selected").val();
					}
			, onSelect: function (){
				$(this).focus();
			}
		}).keyup(function(e) {
			if(e.keyCode == 8 || e.keyCode == 46) {
				$.datepicker._clearDate(this);
			}
		}).on("input change", function (e) {
				 if ($( "#pasi_ceisa_bc_in_<?php echo $bc_prefix; ?>_hdr_valuta_code" ).val()!=''){ 
					$.ajax({    
					url:'<?php echo base_url() . 'ms_master/ct_ms_find/find_valuta_value'; ?>',
					type : 'POST',
					data : {
						VALUTA		:$( "#pasi_ceisa_bc_in_<?php echo $bc_prefix; ?>_hdr_valuta_code" ).val()
						,DATE_KURS	:getValueDate($("#pasi_ceisa_tanggal_penerimaan"),'yymmdd')
					},
					dataType: 'json',
					success: function(msg){
							if (msg.valid){   
								$('#pasi_ceisa_bc_in_<?php echo $bc_prefix; ?>_valuta_value').val(msg.detail.rv_h);
							} else {  
							}
						} 
					}).always(function() { 
					});  
				} 
		}); 

		$( "#TANGGAL_SURATJALAN" ).datepicker({
			changeMonth: true
			,changeYear: true
			,showButtonPanel: true
			,dateFormat: 'dd/mm/yy'
			,onClose: function(dateText, inst){
					var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
					var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
					var day = $("#ui-datepicker-div .ui-datepicker-day :selected").val();
					}
			, onSelect: function (){
				$(this).focus();
			}
		}).keyup(function(e) {
			if(e.keyCode == 8 || e.keyCode == 46) {
				$.datepicker._clearDate(this);
			}
		}).on("input change", function (e) {
				 if ($( "#pasi_ceisa_bc_in_<?php echo $bc_prefix; ?>_hdr_valuta_code" ).val()!=''){ 
					$.ajax({    
					url:'<?php echo base_url() . 'ms_master/ct_ms_find/find_valuta_value'; ?>',
					type : 'POST',
					data : {
						VALUTA		:$( "#pasi_ceisa_bc_in_<?php echo $bc_prefix; ?>_hdr_valuta_code" ).val()
						,DATE_KURS	:getValueDate($("#pasi_ceisa_tanggal_surat_jalan"),'yymmdd')
					},
					dataType: 'json',
					success: function(msg){
							if (msg.valid){   
								$('#pasi_ceisa_bc_in_<?php echo $bc_prefix; ?>_valuta_value').val(msg.detail.rv_h);
							} else {  
							}
						} 
					}).always(function() { 
					});  
				} 
		}); 
//simpan header
$("#pasi_ceisa_gudang_in_bc40_item_simpan").click(function () { 
			var form_data = { 
				 ID_HEADER					: '<?php echo $id_header;  ?>' //(pasi_ceisa_gudang_in_bc40_tbl_item_list)?pasi_ceisa_gudang_in_bc40_tbl_item_list.r9:'-1'
				,NOMOR_PENERIMAAN 			: $('#NOMOR_PENERIMAAN').val()
				,NOMOR_SURATJALAN 			: $('#NOMOR_SURATJALAN').val()
				,TANGGAL_PENERIMAAN			: getValueDate($("#TANGGAL_PENERIMAAN"),'yymmdd')
				,TANGGAL_SURATJALAN			: getValueDate($("#TANGGAL_SURATJALAN"),'yymmdd')
			};
			 $('#pasi_ceisa_gudang_in_bc40_item_simpan').button( "option", "disabled",true );
		   $.ajax({
				url: "<?php echo base_url() . 'pasi_ceisa_gudang/ct_gudang_save/save_header_bc40'; ?>",
				type: 'POST',
				dataType: 'json',
				data: form_data,
				success: function (msg) {
					if (msg.valid){
							 jQuery('span.ui-dialog-title').text('EDIT HEADER');
							 if (pasi_ceisa_gudang_in_bc40_tbl_item_list){
								 alert(msg.stsmsg);
							 }else{
							    pasi_ceisa_gudang_in_bc40_tbl_item_list=msg.detail;  
	
							    var postData = {ID_HEADER:(pasi_ceisa_gudang_in_bc40_tbl_item_list)?pasi_ceisa_gudang_in_bc40_tbl_item_list.r9:'-1'};
	
								$( "#pasi_ceisa_gudang_in_bc40_item_simpan" ).find('span').text("UPDATE HEADER");
								pasi_ceisa_gudang_in_bc40_tbl_item_listitem_action(0)
							 }
							  
							  	
								
					} else { 
						alert(msg.stsno+msg.stsmsg);    
					} 
				}

			}).always(function() {
							$('#ms_in_<?php echo $bc_prefix; ?>_save_header').button( "option", "disabled", false );
			}); 


		}); 




//simpan qty aktual

jQuery("#pasi_ceisa_gudang_in_bc40_item_edit").click(function(){  
			var $dialog =  $('<div />')
				.html(' <div class="ui-layout-content ui-widget-content-panel" style="margin-top:10px"> \
				Masukkan jumlah aktual \
				</div>\
				 <div class="pane-header ui-state-active" id="pasi_ceisa_beli_bar2" >JUMLAH AKTUAL</div>\
				 <div class="ui-layout-content ui-widget-content-panel">\
			 	 <label class="lbfield55">QTY</label><label class="lbcolon">:</label><input id="pasi_ceisa_beli_qty_actual"name="pasi_ceisa_beli_qty_actual"  style="width:185px"   type="text" /><br \>\
				</div>\
				<div class="pane-footer ui-state-default" />')
			 .dialog({
				modal:true,
				width : 500,
				height : 250,
				title :'EDIT QTY',
				buttons: {
					"CLOSE": function(){
						$dialog.dialog("close");  
					} ,
					"SIMPAN": function(){ 
							var mark_id = jQuery('#pasi_ceisa_gudang_in_bc40_tbl_item_list').jqGrid('getGridParam','selrow');   
						 	if(!mark_id){ alert("Pilih produk yang akan di edit");exit;}    
								var ret = jQuery("#pasi_ceisa_gudang_in_bc40_tbl_item_list").jqGrid('getRowData',mark_id);    
						 	
							var form_edit = {      
									id_header  : ret.rID, 
					 				qty_actual  : $( "#pasi_ceisa_beli_qty_actual" ).val(), 
						 
							}; 
							
							$.ajax({    
							url:'<?php echo base_url().'pasi_ceisa_gudang/ct_gudang_save/edit_qty_actual_bc40'; ?>',
							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_gudang_in_bc40_tbl_item_list').trigger('reloadGrid');
				},
				open: function(){
				 			$.ajax({    
									url:'<?php echo base_url().'pasi_ceisa_bc_in/ct_pasi_ceisa_bc_in_from_po/load_setting_default'; ?>',
									type : 'POST',
										data : {bc_prefix:'<?php echo $bc_prefix;  ?>'},
										dataType: 'json',
										success: function(msg){
											if (msg.valid){
												$( "#pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_tdd_name" ).val(msg.data['TDD_NAME']);
												$( "#pasi_ceisa_bc_in<?php echo $bc_prefix;  ?>_tdd_jabatan" ).val(msg.data['TDD_JABATAN']); 
											}  
										} 
							});
					$("body").unblock(); 
				}
			}); 
	}); 


// mapping otomatis

	jQuery("#pasi_ceisa_gudang_in_bc40_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 PEMBELIAN',
					buttons: {
					"CLOSE": function(){
						$dialog.dialog("close");  
						} ,

					"FINISH": function(){  
						var selRowIds;
							selRowIds =  $("#pasi_ceisa_gudang_in_bc40_tbl_item_list").jqGrid('getGridParam','selarrrow');
						
							var myArray = [];
							for (var i = 0; i < selRowIds.length; i++) 
							{
								var rowId = selRowIds[i];
								var idnya =  $('#pasi_ceisa_gudang_in_bc40_tbl_item_list').getCell(rowId, 'rID'); 
								myArray.push(idnya);
							} 
						
							if (selRowIds.length ==0){
								alert("Minimal pilih 1 data untuk mapping ");
								exit;
							}
							var form_edit = {
								bc_prefix :'gudang_in_bc40',     
					 			replace_if_exists        	: $('#replace_if_existgudang_in_bc40').is(':checked')==true?'1':'0',    
								lstsa  : myArray  
							}; 					
				  
					$.ajax({    			 
					url:'<?php echo base_url().'pasi_ceisa_gudang_in_bc40/ct_gudang_in_bc40_beli_map/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_gudang_in_bc40_tbl_item_list').trigger('reloadGrid');
		  			},
					open: function(){  
				 
						 $("body").unblock(); 
					 }

				}); 	 

  
	}); 	

	//--------------------------load data 
    jQuery("#pasi_ceisa_gudang_in_bc40_tbl_item_list").jqGrid({
			url:'<?php echo base_url().'pasi_ceisa_gudang/ct_gudang_data/loaddata_bc40_item'; ?>',
			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','HS-CODE'
						,'CODE','NAME','DOKUMEN','ACTUAL','UOM'
						,'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:'r4',index:'r4', 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:'r7',index:'r7', width:80, hidden:false, align :'left'} //kode
						,{name:'i4',index:'i4', width:150, hidden:true, align :'left'} // 
						,{name:'r8',index:'r8', width:150, hidden:false, align :'left'} //nama
						,{name:'i3',index:'i3', width:80, hidden:true, align :'left'}
						,{name:'r3',index:'r3', width:80, hidden:true, align :'left'}
						,{name:'r20',index:'r20', width:100, hidden:true, align :'left'}
						
						,{name:'i1',index:'i1', width:80, hidden:false, align :'left'} //kdbrg
						,{name:'i2',index:'i2', width:150, hidden:false, align :'left'} //namabrg
						,{name:'r9',index:'r9', width:80, hidden:false, align :'center'}
						,{name:'r13',index:'r13', width:80, hidden:false, editable:true, formatter:'text', align :'center'} //qty_act
						,{name:'r11',index:'r11', width:60, hidden:true, align :'right'}
						
						,{name:'r12',index:'r12', width:80, hidden:true, align :'right'}
						,{name:'r13',index:'r13', width:40, hidden:true, align :'right'}
						,{name:'r14',index:'r14', width:40, hidden:true, align :'left'}
						,{name:'r26',index:'r26', width:60, hidden:true, align :'right'}
						,{name:'r15',index:'r15', width:80, hidden:true, align :'left'}

						,{name:'r16',index:'r16', width:80, hidden:true, align :'left'}
						,{name:'r17',index:'r17', width:80, hidden:true, align :'left'}
						,{name:'r18',index:'r18', width:80, hidden:true, align :'left'}
						,{name:'r19',index:'r19', width:80, hidden:true, align :'right'}
						,{name:'r20',index:'r20', width:80, hidden:true, align :'right'}

						,{name:'r21',index:'r21', width:80, hidden:true, align :'right'}
						,{name:'r22',index:'r22', 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:'r23',index:'r23', 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_gudang_in_bc40_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, 
			multiselect: false,
			afterInsertRow: function(rowid, aData){
				/*switch (aData.statusdok) {
					case 'DATA SENT':
						jQuery("#pasi_ceisa_gudang_in_bc40_tbl_item_list").jqGrid('setCell',rowid,'statusdok','',{color:'green'});
					break;
					case '2':
						jQuery("#pasi_ceisa_gudang_in_bc40_tbl_item_list").jqGrid('setCell',rowid,'statusdok','',{color:'red'});
					break;
					case '1':
						jQuery("#pasi_ceisa_gudang_in_bc40_tbl_item_list").jqGrid('setCell',rowid,'statusdok','',{color:'blue'});
					break;
					
				} */
			},
		    onSelectRow: function(rowid){ 
				var rowData = $("#pasi_ceisa_gudang_in_bc40_tbl_item_list").getRowData(rowid); 
		 		if (rowData.rg == 'Yes' ){
					$("#pasi_ceisa_gudang_in_bc40_item_manual").show(); 
				}
				else{
			//		$("#pasi_ceisa_gudang_in_bc40_item_manual").hide(); 
			   }
	 
			 //  if( rowData.i5 !==lastSel){ 
			//		jQuery('#pasi_ceisa_gudang_in_bc40_tbl_item_list').restoreRow(lastSel); 
			//		lastSel=id; 
			//	}
				if (rowData.i5 == '0' ){
					jQuery('#pasi_ceisa_gudang_in_bc40_tbl_item_list').editRow(rowData, true); 
				}	
  		 	 },
			gridComplete: function(){
				var rowIDs = jQuery("#pasi_ceisa_gudang_in_bc40_tbl_item_list").getDataIDs(); 
				var rowData = $("#pasi_ceisa_gudang_in_bc40_tbl_item_list").getRowData();
	
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#pasi_ceisa_gudang_in_bc40_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_gudang_in_bc40_tbl_item_list").jqGrid('setGroupHeaders', 
            { useColSpanStyle: true, groupHeaders:[
			{startColumnName: 'r7', numberOfColumns: 3, titleText: '<em><center>ITEM INTERNAL</center></em>'},
			{startColumnName: 'r3', numberOfColumns: 4, titleText: '<em><center>ITEM MODULE </center></em>'},
			{startColumnName: 'r9', numberOfColumns: 2, titleText: '<em><center>QTY </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_gudang_in_bc40_tbl_item_list").jqGrid('navGrid','#ppasi_ceisa_gudang_in_bc40_tbl_item_list',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#pasi_ceisa_gudang_in_bc40_tbl_item_list").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
		 
	 
	
	setTimeout(function(){
	 		setGridHight($("#pasi_ceisa_gudang_in_bc40_tbl_item_list"),$("#container_pasi_ceisa_gudang_in_bc40_tbl_item_list"),$("#pasi_ceisa_gudang_in_bc40_tbl_item_list_bar")); 
	},100); 

	
	});
		  	
</script>

	
	